@@ -127,25 +127,26 @@ void main() {
127
127
});
128
128
129
129
test ('downgrading' , () async {
130
- final schema = await verifier.schemaAt (2 );
130
+ final toVersion = AppDatabase .latestSchemaVersion;
131
+ final schema = await verifier.schemaAt (toVersion);
131
132
132
133
// This simulates the scenario during development when running the app
133
134
// with a future schema version that has additional tables and columns.
134
135
final before = AppDatabase (schema.newConnection ());
135
136
await before.customStatement ('CREATE TABLE test_extra (num int)' );
136
137
await before.customStatement ('ALTER TABLE accounts ADD extra_column int' );
137
138
await check (verifier.migrateAndValidate (
138
- before, 2 , validateDropped: true )).throws <SchemaMismatch >();
139
+ before, toVersion , validateDropped: true )).throws <SchemaMismatch >();
139
140
// Override the schema version by modifying the underlying value
140
141
// drift internally keeps track of in the database.
141
142
// TODO(drift): Expose a better interface for testing this.
142
- await before.customStatement ('PRAGMA user_version = 999 ;' );
143
+ await before.customStatement ('PRAGMA user_version = ${ toVersion + 1 } ;' );
143
144
await before.close ();
144
145
145
146
// Simulate starting up the app, with an older schema version that
146
147
// does not have the extra tables and columns.
147
148
final after = AppDatabase (schema.newConnection ());
148
- await verifier.migrateAndValidate (after, 2 , validateDropped: true );
149
+ await verifier.migrateAndValidate (after, toVersion , validateDropped: true );
149
150
await after.close ();
150
151
});
151
152
0 commit comments