mirror of https://github.com/AMT-Cheif/drift.git
Support schema downgrades (#2336)
This commit is contained in:
parent
adc2e22c46
commit
4db8f19a43
|
@ -5,6 +5,8 @@
|
|||
statements.
|
||||
- Add `rowid` parameter to companions for tables with rowids that don't have a
|
||||
visible alias for the rowid.
|
||||
- After opening a database with a higher schema version than the current one set
|
||||
in the database class, the schema version in the database will now be downgraded.
|
||||
|
||||
## 2.5.0
|
||||
|
||||
|
|
|
@ -458,7 +458,7 @@ class DelegatedDatabase extends _BaseExecutor {
|
|||
await user.beforeOpen(_BeforeOpeningExecutor(this), openingDetails);
|
||||
|
||||
if (versionDelegate is DynamicVersionDelegate &&
|
||||
(oldVersion == null || oldVersion < currentVersion)) {
|
||||
oldVersion != currentVersion) {
|
||||
// set version now, after migrations ran successfully
|
||||
await versionDelegate.setSchemaVersion(currentVersion);
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ void main() {
|
|||
verify(delegate.open(userDb));
|
||||
verifyNever(delegate.runCustom(any, any));
|
||||
verify(version.schemaVersion);
|
||||
// Running migrations from version 3 to 3
|
||||
// Not running migrations from version 3 to 3
|
||||
verifyNever(version.setSchemaVersion(3));
|
||||
|
||||
when(version.schemaVersion).thenAnswer((_) => Future.value(2));
|
||||
|
@ -127,6 +127,17 @@ void main() {
|
|||
|
||||
verify(delegate.runCustom('updated', argThat(equals([1, 3]))));
|
||||
});
|
||||
|
||||
test('handles database downgrades', () async {
|
||||
final version = MockDynamicVersionDelegate();
|
||||
when(version.schemaVersion).thenAnswer((_) => Future.value(4));
|
||||
when(delegate.versionDelegate).thenReturn(version);
|
||||
await db.ensureOpen(userDb);
|
||||
|
||||
verify(delegate.open(userDb));
|
||||
verify(delegate.runCustom('updated', argThat(equals([4, 3]))));
|
||||
verify(version.setSchemaVersion(3));
|
||||
});
|
||||
});
|
||||
|
||||
group('transactions', () {
|
||||
|
|
Loading…
Reference in New Issue