From aeb808b5dcff2674e498291c23e414528a4f3e6f Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 8 Jul 2021 12:22:46 +0200 Subject: [PATCH] fix: Dont migrate from version null If the currentVersion of the database is null then the database has never been used yet. Therefore we store the current version and do not call the migrate method. --- lib/src/database/hive_database.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/database/hive_database.dart b/lib/src/database/hive_database.dart index dd0d39d2..d6f2943f 100644 --- a/lib/src/database/hive_database.dart +++ b/lib/src/database/hive_database.dart @@ -164,8 +164,14 @@ class FamedlySdkHiveDatabase extends DatabaseApi { _eventsBoxName, encryptionCipher: encryptionCipher, ); - final currentVersion = (await _clientBox.get('version') as int) ?? 0; - if (currentVersion != version) await _migrateFromVersion(currentVersion); + + // Check version and check if we need a migration + final currentVersion = (await _clientBox.get('version') as int); + if (currentVersion == null) { + await _clientBox.put('version', version); + } else if (currentVersion != version) { + await _migrateFromVersion(currentVersion); + } return; }