Move migration logic in settings_page into databasse
This commit is contained in:
parent
0eaac20e7e
commit
4097a79205
|
@ -22,12 +22,18 @@ class MyDatabase extends _$MyDatabase {
|
|||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
onCreate: (Migrator m) async {
|
||||
print('Creating...');
|
||||
await m.createAll();
|
||||
var data = await (db.select(db.settings)..limit(1)).get();
|
||||
if (data.isEmpty) await db.into(db.settings).insert(defaultSettings);
|
||||
},
|
||||
onUpgrade: (Migrator m, int from, int to) async {
|
||||
if (from == 1) {
|
||||
await m.create(db.gymSets);
|
||||
await db.customInsert('''
|
||||
INSERT INTO gym_sets(id, name, reps, weight, created, unit, hidden, image, sets, minutes, seconds, steps)
|
||||
SELECT id, name, reps, weight, created, unit, hidden, image, sets, minutes, seconds, steps FROM sets
|
||||
''');
|
||||
await m.addColumn(settings, settings.darkColor);
|
||||
await db.customStatement('''
|
||||
UPDATE settings SET dark_color = darkColor
|
||||
|
|
|
@ -95,11 +95,9 @@ class _SettingsPageState extends State<_SettingsPage> {
|
|||
await file.copy(to);
|
||||
print('Migrating...');
|
||||
db = MyDatabase();
|
||||
// ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
|
||||
final migrator = db.createMigrator();
|
||||
await migrator.createAll();
|
||||
await db.customInsert('''
|
||||
INSERT INTO gym_sets(id, name, reps, weight, created, unit, hidden, image, sets, minutes, seconds, steps)
|
||||
SELECT id, name, reps, weight, created, unit, hidden, image, sets, minutes, seconds, steps FROM sets''');
|
||||
print('Migrated.');
|
||||
},
|
||||
child: const Text("Import")));
|
||||
|
|
Loading…
Reference in New Issue
Block a user