Fix verifier migrating to the latest version

This commit is contained in:
Simon Binder 2020-11-12 21:41:45 +01:00
parent 08470abd47
commit 708033c88c
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 8 additions and 6 deletions

View File

@ -16,13 +16,14 @@ class VerifierImplementation implements SchemaVerifier {
@override
Future<void> migrateAndValidate(GeneratedDatabase db, int expectedVersion,
{bool validateDropped = false}) async {
// Open the database to collect its schema.
await db.executor.ensureOpen(db);
// Open the database to collect its schema. Put a delegate in between
// claiming that the actual version is what we expect.
await db.executor.ensureOpen(_DelegatingUser(expectedVersion, db));
final actualSchema = await db.executor.collectSchemaInput();
// Open another connection to instantiate and extract the reference schema.
final otherConnection = await startAt(expectedVersion);
await otherConnection.executor.ensureOpen(_SimpleUser(expectedVersion));
await otherConnection.executor.ensureOpen(_DelegatingUser(expectedVersion));
final referenceSchema = await otherConnection.executor.collectSchemaInput();
await otherConnection.executor.close();
@ -86,14 +87,15 @@ extension on QueryExecutor {
}
}
class _SimpleUser extends QueryExecutorUser {
class _DelegatingUser extends QueryExecutorUser {
@override
final int schemaVersion;
final QueryExecutorUser inner;
_SimpleUser(this.schemaVersion);
_DelegatingUser(this.schemaVersion, [this.inner]);
@override
Future<void> beforeOpen(QueryExecutor executor, OpeningDetails details) {
return Future.value();
return inner?.beforeOpen(executor, details) ?? Future.value();
}
}