From 96ab32a40d0a08b720c9967c82fcfa375dd08faf Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Wed, 19 Feb 2025 23:33:35 -0500 Subject: [PATCH] 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 --- test/model/database_test.dart | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/test/model/database_test.dart b/test/model/database_test.dart index ff6fd69245..1c22b62100 100644 --- a/test/model/database_test.dart +++ b/test/model/database_test.dart @@ -111,21 +111,15 @@ void main() { await before.customStatement('ALTER TABLE accounts ADD extra_column int'); await check(verifier.migrateAndValidate( before, 2, validateDropped: true)).throws(); + // Override the schema version. + // TODO(upstream): Expose a better interface for testing this. + await before.customStatement('PRAGMA user_version = 999;'); await before.close(); // We need a new connection because migrations are only run when the // database is first opened (see [DelegatedDatabase.ensureOpen]), and // running custom statements opens it. final after = AppDatabase(schema.newConnection()); - // Trick the drift into believing that the schema version is - // higher than it actually is, so that a downgrade migration is triggered. - // This relies on some relevant implementation details: - // - [DelegatedDatabase._runMigrations] - // - [VerifierImplementation.migrateAndValidate] - // TODO(upstream): Expose a better interface for testing this. - await ((after.executor as DelegatedDatabase) - .delegate.versionDelegate as DynamicVersionDelegate).setSchemaVersion(999); - await verifier.migrateAndValidate(after, 2, validateDropped: true); await after.close(); });