Skip to content

Commit 04e451c

Browse files
committed
fix migrations tests
1 parent 3fee25e commit 04e451c

File tree

5 files changed

+12
-508
lines changed

5 files changed

+12
-508
lines changed

examples/app/test/drift/default/migration_test.dart

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
77
import 'generated/schema.dart';
88

99
import 'generated/schema_v1.dart' as v1;
10-
import 'generated/schema_v2.dart' as v2;
10+
import 'generated/schema_v3.dart' as v3;
1111

1212
void main() {
1313
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
@@ -36,51 +36,38 @@ void main() {
3636
}
3737
});
3838

39-
// The following template shows how to write tests ensuring your migrations
40-
// preserve existing data.
41-
// Testing this can be useful for migrations that change existing columns
42-
// (e.g. by alterating their type or constraints). Migrations that only add
43-
// tables or columns typically don't need these advanced tests. For more
44-
// information, see https://drift.simonbinder.eu/migrations/tests/#verifying-data-integrity
45-
// TODO: This generated template shows how these tests could be written. Adopt
46-
// it to your own needs when testing migrations with data integrity.
47-
test("migration from v1 to v2 does not corrupt data", () async {
48-
// Add data to insert into the old database, and the expected rows after the
49-
// migration.
50-
// TODO: Fill these lists
39+
test("migration from v1 to v3 does not corrupt data", () async {
5140
final oldCategoriesData = <v1.CategoriesData>[];
52-
final expectedNewCategoriesData = <v2.CategoriesData>[];
41+
final expectedNewCategoriesData = <v3.CategoriesData>[];
5342

5443
final oldTodoEntriesData = <v1.TodoEntriesData>[
55-
const v1.TodoEntriesData(
56-
description: 'My manually added entry', id: 1, category: null)
44+
const v1.TodoEntriesData(description: 'My manually added entry', id: 1)
5745
];
58-
final expectedNewTodoEntriesData = <v2.TodoEntriesData>[
59-
const v2.TodoEntriesData(
60-
description: 'My manually added entry', id: 1, category: null)
46+
final expectedNewTodoEntriesData = <v3.TodoEntriesData>[
47+
const v3.TodoEntriesData(
48+
description: 'My manually added entry',
49+
id: 1,
50+
)
6151
];
6252

6353
final oldTextEntriesData = <v1.TextEntriesData>[];
64-
final expectedNewTextEntriesData = <v2.TextEntriesData>[];
54+
final expectedNewTextEntriesData = <v3.TextEntriesData>[];
6555

6656
await verifier.testWithDataIntegrity(
6757
oldVersion: 1,
68-
newVersion: 2,
58+
newVersion: 3,
6959
createOld: v1.DatabaseAtV1.new,
70-
createNew: v2.DatabaseAtV2.new,
60+
createNew: v3.DatabaseAtV3.new,
7161
openTestedDatabase: AppDatabase.new,
7262
createItems: (batch, oldDb) {
7363
batch.insertAll(oldDb.categories, oldCategoriesData);
7464
batch.insertAll(oldDb.todoEntries, oldTodoEntriesData);
75-
batch.insertAll(oldDb.textEntries, oldTextEntriesData);
7665
},
7766
validateItems: (newDb) async {
7867
expect(expectedNewCategoriesData,
7968
await newDb.select(newDb.categories).get());
8069
expect(expectedNewTodoEntriesData,
8170
await newDb.select(newDb.todoEntries).get());
82-
expect(expectedNewTextEntriesData,
83-
await newDb.select(newDb.textEntries).get());
8471
},
8572
);
8673
});

examples/app/test/generated_migrations/schema.dart

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/app/test/generated_migrations/schema_v1.dart

Lines changed: 0 additions & 142 deletions
This file was deleted.

examples/app/test/generated_migrations/schema_v2.dart

Lines changed: 0 additions & 145 deletions
This file was deleted.

0 commit comments

Comments
 (0)