Skip to content

Commit 91fec5b

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 91fec5b

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

Diff for: test/model/database_test.dart

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:checks/checks.dart';
2-
import 'package:drift/backends.dart';
32
import 'package:drift/drift.dart';
43
import 'package:drift/native.dart';
54
import 'package:drift_dev/api/migrations_native.dart';
@@ -111,21 +110,15 @@ void main() {
111110
await before.customStatement('ALTER TABLE accounts ADD extra_column int');
112111
await check(verifier.migrateAndValidate(
113112
before, 2, validateDropped: true)).throws<SchemaMismatch>();
113+
// Override the schema version.
114+
// TODO(upstream): Expose a better interface for testing this.
115+
await before.customStatement('PRAGMA user_version = 999;');
114116
await before.close();
115117

116118
// We need a new connection because migrations are only run when the
117119
// database is first opened (see [DelegatedDatabase.ensureOpen]), and
118120
// running custom statements opens it.
119121
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-
129122
await verifier.migrateAndValidate(after, 2, validateDropped: true);
130123
await after.close();
131124
});

0 commit comments

Comments
 (0)