Skip to content

Commit

Permalink
squash? Use a better alternative to accessing the delegates
Browse files Browse the repository at this point in the history
  • Loading branch information
PIG208 committed Feb 20, 2025
1 parent 7a00e3c commit 96ab32a
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions test/model/database_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<SchemaMismatch>();
// 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();
});
Expand Down

0 comments on commit 96ab32a

Please sign in to comment.