diff --git a/drift_dev/lib/src/services/schema/verifier_impl.dart b/drift_dev/lib/src/services/schema/verifier_impl.dart index 4b8d3664..4a7b551e 100644 --- a/drift_dev/lib/src/services/schema/verifier_impl.dart +++ b/drift_dev/lib/src/services/schema/verifier_impl.dart @@ -83,8 +83,8 @@ Input? _parseInputFromSchemaRow( Map row, List virtualTables) { final name = row['name'] as String; - // Skip sqlite-internal tables - if (name.startsWith('sqlite_autoindex')) return null; + // Skip sqlite-internal tables, https://www.sqlite.org/fileformat2.html#intschema + if (name.startsWith('sqlite_')) return null; if (virtualTables.any((v) => name.startsWith('${v}_'))) return null; return Input(name, row['sql'] as String); diff --git a/drift_dev/test/services/schema/verifier_impl_test.dart b/drift_dev/test/services/schema/verifier_impl_test.dart index b420b640..94979ba3 100644 --- a/drift_dev/test/services/schema/verifier_impl_test.dart +++ b/drift_dev/test/services/schema/verifier_impl_test.dart @@ -1,5 +1,7 @@ import 'package:drift/drift.dart'; +import 'package:drift/native.dart'; import 'package:drift_dev/api/migrations.dart'; +import 'package:drift_dev/src/services/schema/verifier_impl.dart'; import 'package:test/test.dart'; void main() { @@ -33,6 +35,35 @@ void main() { driftRuntimeOptions.dontWarnAboutMultipleDatabases = false; }); }); + + group('collectSchemaInput', () { + test('contains only user-defined entities', () async { + final db = _TestDatabase(NativeDatabase.memory(), 1); + addTearDown(db.close); + + await db.customStatement('CREATE TABLE x1 (bar UNIQUE);'); + await db.customStatement('CREATE VIEW x2 AS SELECT * FROM x1;'); + await db.customStatement('CREATE INDEX x3 ON x1 (bar);'); + await db.customStatement('CREATE TRIGGER x4 AFTER INSERT ON x1 BEGIN ' + 'DELETE FROM x1;' + 'END;'); + + final inputs = await db.collectSchemaInput(const []); + expect(inputs.map((e) => e.name), ['x1', 'x2', 'x3', 'x4']); + }); + + test('does not contain shadow tables', () async { + final db = _TestDatabase(NativeDatabase.memory(), 1); + addTearDown(db.close); + + await db.customStatement('CREATE VIRTUAL TABLE x USING fts5(foo, bar);'); + await db + .customStatement('INSERT INTO x VALUES (?, ?)', ['test', 'another']); + + final inputs = await db.collectSchemaInput(const ['x']); + expect(inputs.map((e) => e.name), ['x']); + }); + }); } class _TestHelper implements SchemaInstantiationHelper {