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.
This commit is contained in:
Christian Pauly 2021-07-08 12:22:46 +02:00 committed by Krille Fear
parent 36a9b53de1
commit aeb808b5dc
1 changed files with 8 additions and 2 deletions

View File

@ -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;
}