From a64177a2eab08acf0dbfb943bbf5258e21996792 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Thu, 14 Mar 2024 15:19:04 +0100 Subject: [PATCH] fix: only migrate if db version matches v3 --- lib/constants.dart | 1 + lib/util/storage/database/database_service.dart | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/constants.dart b/lib/constants.dart index e9d27c26..f77a126c 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -134,6 +134,7 @@ const Map SUPPORTED_LOCALES = { "en": const Locale("en"), // "es": const Locale("es"), }; +const int DB_VERSION = 3; const String INSUFFICIENT_FUNDS_ERROR = "Insufficient funds"; const String APP_TITLE = "myWitWallet"; const String WINDOWS_FILE_NAME = "myWitWallet-windows.zip"; diff --git a/lib/util/storage/database/database_service.dart b/lib/util/storage/database/database_service.dart index f9f800d3..87edf80e 100644 --- a/lib/util/storage/database/database_service.dart +++ b/lib/util/storage/database/database_service.dart @@ -90,10 +90,13 @@ class DatabaseService { } else { mode = DatabaseMode.create; } - _dbService._database = await dbFactory - .openDatabase(_dbService._dbConfig!.path, version: 3, mode: mode, - onVersionChanged: (db, oldVersion, newVersion) async { - await migrateDB(db); + _dbService._database = await dbFactory.openDatabase( + _dbService._dbConfig!.path, + version: DB_VERSION, + mode: mode, onVersionChanged: (db, oldVersion, newVersion) async { + if (newVersion == DB_VERSION) { + await migrateDB(db); + } }); }