mirror of https://github.com/AMT-Cheif/drift.git
Fix schema verifier around virtual tables
This commit is contained in:
parent
c844c86af4
commit
2999df449d
|
@ -16,15 +16,21 @@ class VerifierImplementation implements SchemaVerifier {
|
|||
@override
|
||||
Future<void> migrateAndValidate(GeneratedDatabase db, int expectedVersion,
|
||||
{bool validateDropped = false}) async {
|
||||
final virtualTables = <String>[
|
||||
for (final table in db.allTables)
|
||||
if (table is VirtualTableInfo) table.entityName,
|
||||
];
|
||||
|
||||
// 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();
|
||||
final actualSchema = await db.executor.collectSchemaInput(virtualTables);
|
||||
|
||||
// Open another connection to instantiate and extract the reference schema.
|
||||
final otherConnection = await startAt(expectedVersion);
|
||||
await otherConnection.executor.ensureOpen(_DelegatingUser(expectedVersion));
|
||||
final referenceSchema = await otherConnection.executor.collectSchemaInput();
|
||||
final referenceSchema =
|
||||
await otherConnection.executor.collectSchemaInput(virtualTables);
|
||||
await otherConnection.executor.close();
|
||||
|
||||
final result =
|
||||
|
@ -80,13 +86,16 @@ class VerifierImplementation implements SchemaVerifier {
|
|||
}
|
||||
|
||||
extension on QueryExecutor {
|
||||
Future<List<Input>> collectSchemaInput() async {
|
||||
Future<List<Input>> collectSchemaInput(List<String> virtualTables) async {
|
||||
final result = await runSelect('SELECT * FROM sqlite_master;', const []);
|
||||
|
||||
final inputs = <Input>[];
|
||||
for (final row in result) {
|
||||
final name = row['name'] as String;
|
||||
|
||||
// Skip sqlite-internal tables
|
||||
if (name.startsWith('sqlite_autoindex')) continue;
|
||||
if (virtualTables.any((v) => name.startsWith('${v}_'))) continue;
|
||||
|
||||
inputs.add(Input(name, row['sql'] as String));
|
||||
}
|
||||
|
|
|
@ -19,5 +19,5 @@ Replace `_v2` with the current `schemaVersion`.
|
|||
Run
|
||||
|
||||
```
|
||||
dart run drift_dev schema generate moor_migrations/ test/generated/ --data-classes --companions
|
||||
dart run drift_dev schema generate drift_migrations/ test/generated/ --data-classes --companions
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue