-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task(ardrive-web): increment schema to 10 PE-111 (#182)
- Loading branch information
Showing
1 changed file
with
38 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
import 'package:moor/moor.dart'; | ||
|
||
import '../daos/daos.dart'; | ||
import 'unsupported.dart' | ||
if (dart.library.html) 'web.dart' | ||
if (dart.library.io) 'ffi.dart'; | ||
|
||
part 'database.g.dart'; | ||
|
||
@UseMoor( | ||
include: {'../tables/all.moor'}, | ||
daos: [DriveDao, ProfileDao], | ||
) | ||
class Database extends _$Database { | ||
Database([QueryExecutor e]) : super(e ?? openConnection()); | ||
|
||
@override | ||
int get schemaVersion => 9; | ||
|
||
|
||
@override | ||
MigrationStrategy get migration => MigrationStrategy( | ||
onCreate: (Migrator m) { | ||
return m.createAll(); | ||
}, | ||
onUpgrade: (Migrator m, int from, int to) async { | ||
print('schema changed from $from to $to '); | ||
if (from >= 1 && from <= 8) { | ||
// Reset the database. | ||
for (final table in allTables) { | ||
await m.deleteTable(table.actualTableName); | ||
} | ||
|
||
await m.createAll(); | ||
} | ||
}, | ||
); | ||
} | ||
import 'package:moor/moor.dart'; | ||
|
||
import '../daos/daos.dart'; | ||
import 'unsupported.dart' | ||
if (dart.library.html) 'web.dart' | ||
if (dart.library.io) 'ffi.dart'; | ||
|
||
part 'database.g.dart'; | ||
|
||
@UseMoor( | ||
include: {'../tables/all.moor'}, | ||
daos: [DriveDao, ProfileDao], | ||
) | ||
class Database extends _$Database { | ||
Database([QueryExecutor e]) : super(e ?? openConnection()); | ||
|
||
@override | ||
int get schemaVersion => 10; | ||
|
||
|
||
@override | ||
MigrationStrategy get migration => MigrationStrategy( | ||
onCreate: (Migrator m) { | ||
return m.createAll(); | ||
}, | ||
onUpgrade: (Migrator m, int from, int to) async { | ||
print('schema changed from $from to $to '); | ||
if (from >= 1 && from <= 9) { | ||
// Reset the database. | ||
for (final table in allTables) { | ||
await m.deleteTable(table.actualTableName); | ||
} | ||
|
||
await m.createAll(); | ||
} | ||
}, | ||
); | ||
} |