Skip to content

Commit 96ab32a

Browse files
committed
squash? Use a better alternative to accessing the delegates
This proposes an alternative way to set the schema version to the parent commit, by utilizing some more implementation details. References: https://github.com/simolus3/drift/blob/18cede15/drift/lib/src/runtime/executor/helpers/engines.dart#L459-L495 https://github.com/simolus3/drift/blob/18cede15/drift/lib/src/sqlite3/database.dart#L198-L211 https://github.com/simolus3/sqlite3.dart/blob/4de46afd/sqlite3/lib/src/implementation/database.dart#L69-L85 Signed-off-by: Zixuan James Li <[email protected]>
1 parent 7a00e3c commit 96ab32a

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

test/model/database_test.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,15 @@ void main() {
111111
await before.customStatement('ALTER TABLE accounts ADD extra_column int');
112112
await check(verifier.migrateAndValidate(
113113
before, 2, validateDropped: true)).throws<SchemaMismatch>();
114+
// Override the schema version.
115+
// TODO(upstream): Expose a better interface for testing this.
116+
await before.customStatement('PRAGMA user_version = 999;');
114117
await before.close();
115118

116119
// We need a new connection because migrations are only run when the
117120
// database is first opened (see [DelegatedDatabase.ensureOpen]), and
118121
// running custom statements opens it.
119122
final after = AppDatabase(schema.newConnection());
120-
// Trick the drift into believing that the schema version is
121-
// higher than it actually is, so that a downgrade migration is triggered.
122-
// This relies on some relevant implementation details:
123-
// - [DelegatedDatabase._runMigrations]
124-
// - [VerifierImplementation.migrateAndValidate]
125-
// TODO(upstream): Expose a better interface for testing this.
126-
await ((after.executor as DelegatedDatabase)
127-
.delegate.versionDelegate as DynamicVersionDelegate).setSchemaVersion(999);
128-
129123
await verifier.migrateAndValidate(after, 2, validateDropped: true);
130124
await after.close();
131125
});

0 commit comments

Comments
 (0)