Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions crates/sage/src/sage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,23 +409,14 @@ impl Sage {
)
.await?;

let version = Self::database_version(&pool).await?;

if version < 2 {
if let Err(_error) = sqlx::migrate!("../../migrations").run(&pool).await {
// TODO: Handle migration error
return Err(Error::DatabaseVersionTooOld);
}
sqlx::migrate!("../../migrations").run(&pool).await?;

Ok(pool)
}

async fn database_version(pool: &SqlitePool) -> Result<i32> {
let row: (i32,) = sqlx::query_as("PRAGMA user_version")
.fetch_one(pool)
.await?;
Ok(row.0)
}

pub fn wallet_db_path(&self, fingerprint: u32) -> Result<PathBuf> {
let path = self.path.join("wallets").join(fingerprint.to_string());
fs::create_dir_all(&path)?;
Expand Down
1 change: 0 additions & 1 deletion migrations/0000_pragmas.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
PRAGMA journal_mode = WAL;
PRAGMA foreign_keys = ON;
PRAGMA user_version = 2;
Loading