Skip to content

Commit dac0772

Browse files
authored
Merge pull request #499 from xch-dev/stub-migration-handler
Stub migration handler
2 parents 462b3aa + 97b05de commit dac0772

3 files changed

Lines changed: 350 additions & 360 deletions

File tree

crates/sage/src/sage.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,23 +409,14 @@ impl Sage {
409409
)
410410
.await?;
411411

412-
let version = Self::database_version(&pool).await?;
413-
414-
if version < 2 {
412+
if let Err(_error) = sqlx::migrate!("../../migrations").run(&pool).await {
413+
// TODO: Handle migration error
415414
return Err(Error::DatabaseVersionTooOld);
416415
}
417-
sqlx::migrate!("../../migrations").run(&pool).await?;
418416

419417
Ok(pool)
420418
}
421419

422-
async fn database_version(pool: &SqlitePool) -> Result<i32> {
423-
let row: (i32,) = sqlx::query_as("PRAGMA user_version")
424-
.fetch_one(pool)
425-
.await?;
426-
Ok(row.0)
427-
}
428-
429420
pub fn wallet_db_path(&self, fingerprint: u32) -> Result<PathBuf> {
430421
let path = self.path.join("wallets").join(fingerprint.to_string());
431422
fs::create_dir_all(&path)?;

migrations/0000_pragmas.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
PRAGMA journal_mode = WAL;
22
PRAGMA foreign_keys = ON;
3-
PRAGMA user_version = 2;

0 commit comments

Comments
 (0)