moor_ffi: Only update schema version after migrations

This commit is contained in:
Simon Binder 2020-03-15 15:20:44 +01:00
parent bc1f347498
commit d1332ff1be
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 6 additions and 2 deletions

View File

@ -260,9 +260,8 @@ class DelegatedDatabase extends QueryExecutor with _ExecutorWithQueryDelegate {
// version has already been set during open
oldVersion = await versionDelegate.loadSchemaVersion();
} else if (versionDelegate is DynamicVersionDelegate) {
// set version now
oldVersion = await versionDelegate.schemaVersion;
await versionDelegate.setSchemaVersion(currentVersion);
// Note: We only update the schema version after migrations ran
} else {
throw Exception('Invalid delegate: $delegate. The versionDelegate getter '
'must not subclass DBVersionDelegate directly');
@ -277,6 +276,11 @@ class DelegatedDatabase extends QueryExecutor with _ExecutorWithQueryDelegate {
final openingDetails = OpeningDetails(oldVersion, currentVersion);
await user.beforeOpen(_BeforeOpeningExecutor(this), openingDetails);
if (versionDelegate is DynamicVersionDelegate) {
// set version now, after migrations ran successfully
await versionDelegate.setSchemaVersion(currentVersion);
}
delegate.notifyDatabaseOpened(openingDetails);
}