@@ -8,6 +8,8 @@ import 'generated/schema.dart';
88
99import 'generated/schema_v1.dart' as v1;
1010import 'generated/schema_v2.dart' as v2;
11+ import 'generated/schema_v3.dart' as v3;
12+ import 'generated/schema_v4.dart' as v4;
1113
1214void main () {
1315 driftRuntimeOptions.dontWarnAboutMultipleDatabases = true ;
@@ -68,4 +70,62 @@ void main() {
6870 },
6971 );
7072 });
73+
74+ group ('_columnExists-backed migrations' , () {
75+ test ('migration from v3 to v4 adds test_url when missing' , () async {
76+ final schema = await verifier.schemaAt (3 );
77+ addTearDown (() => schema.rawDatabase.dispose ());
78+
79+ final oldDb = v3.DatabaseAtV3 (schema.newConnection ());
80+ final oldColumns = await oldDb
81+ .customSelect ('PRAGMA table_info(profile_entries);' )
82+ .get ();
83+
84+ expect (
85+ oldColumns.where ((row) => row.data['name' ] == 'test_url' ),
86+ isEmpty,
87+ );
88+ await oldDb.close ();
89+
90+ final migratedDb = Db (schema.newConnection ());
91+ await verifier.migrateAndValidate (migratedDb, 4 );
92+ await migratedDb.close ();
93+
94+ final newDb = v4.DatabaseAtV4 (schema.newConnection ());
95+ final newColumns = await newDb
96+ .customSelect ('PRAGMA table_info(profile_entries);' )
97+ .get ();
98+ expect (
99+ newColumns.where ((row) => row.data['name' ] == 'test_url' ),
100+ hasLength (1 ),
101+ );
102+ await newDb.close ();
103+ });
104+
105+ test (
106+ 'migration from v3 to v4 skips adding test_url when it already exists' ,
107+ () async {
108+ final schema = await verifier.schemaAt (3 );
109+ addTearDown (() => schema.rawDatabase.dispose ());
110+
111+ schema.rawDatabase.execute (
112+ 'ALTER TABLE profile_entries ADD COLUMN test_url TEXT NULL;' ,
113+ );
114+
115+ final migratedDb = Db (schema.newConnection ());
116+ await verifier.migrateAndValidate (migratedDb, 4 );
117+ await migratedDb.close ();
118+
119+ final newDb = v4.DatabaseAtV4 (schema.newConnection ());
120+ final newColumns = await newDb
121+ .customSelect ('PRAGMA table_info(profile_entries);' )
122+ .get ();
123+ expect (
124+ newColumns.where ((row) => row.data['name' ] == 'test_url' ),
125+ hasLength (1 ),
126+ );
127+ await newDb.close ();
128+ },
129+ );
130+ });
71131}
0 commit comments