Skip to content

Commit e4edead

Browse files
committed
db [nfc]: Document _dropAll; move creation step to caller
1 parent 4d8a667 commit e4edead

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/model/database.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ class AppDatabase extends _$AppDatabase {
8686
@override
8787
int get schemaVersion => latestSchemaVersion;
8888

89-
static Future<void> _dropAndCreateAll(Migrator m) async {
89+
/// Drop all tables, indexes, etc., in the database.
90+
///
91+
/// This includes tables that aren't known to the schema, for example because
92+
/// they were defined by a future (perhaps experimental) version of the app
93+
/// before switching back to the version currently running.
94+
static Future<void> _dropAll(Migrator m) async {
9095
final query = m.database.customSelect(
9196
"SELECT name FROM sqlite_master WHERE type='table'");
9297
for (final row in await query.get()) {
@@ -101,7 +106,6 @@ class AppDatabase extends _$AppDatabase {
101106
// that should be affected by user data.
102107
await m.database.customStatement('DROP TABLE $tableName');
103108
}
104-
await m.createAll();
105109
}
106110

107111
static final MigrationStepWithVersion _migrationSteps = migrationSteps(
@@ -152,7 +156,8 @@ class AppDatabase extends _$AppDatabase {
152156
// in migration tests; we can forego that for testing downgrades.
153157
assert(to == latestSchemaVersion);
154158

155-
await _dropAndCreateAll(m);
159+
await _dropAll(m);
160+
await m.createAll();
156161
return;
157162
}
158163
assert(1 <= from && from <= to && to <= latestSchemaVersion);

0 commit comments

Comments
 (0)