diff --git a/lib/database.dart b/lib/database.dart index e100058..ffa4bb8 100644 --- a/lib/database.dart +++ b/lib/database.dart @@ -17,7 +17,7 @@ class MyDatabase extends _$MyDatabase { MyDatabase() : super(_openConnection()); @override - int get schemaVersion => 1; + int get schemaVersion => 2; @override MigrationStrategy get migration => MigrationStrategy( @@ -27,7 +27,28 @@ class MyDatabase extends _$MyDatabase { if (data.isEmpty) await db.into(db.settings).insert(defaultSettings); }, onUpgrade: (Migrator m, int from, int to) async { - // no migrations yet + if (from == 1) { + await m.addColumn(settings, settings.darkColor); + await db.customStatement(''' + UPDATE settings SET dark_color = darkColor + '''); + await m.addColumn(settings, settings.lightColor); + await db.customStatement(''' + UPDATE settings SET light_color = lightColor + '''); + await m.addColumn(settings, settings.showDate); + await db.customStatement(''' + UPDATE settings SET show_date = showDate + '''); + await m.addColumn(settings, settings.showSets); + await db.customStatement(''' + UPDATE settings SET show_sets = showSets + '''); + await m.addColumn(settings, settings.showUnit); + await db.customStatement(''' + UPDATE settings SET show_unit = showUnit + '''); + } }, ); } diff --git a/lib/settings_page.dart b/lib/settings_page.dart index 8feb287..f630660 100644 --- a/lib/settings_page.dart +++ b/lib/settings_page.dart @@ -99,7 +99,7 @@ class _SettingsPageState extends State<_SettingsPage> { 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'''); + SELECT id, name, reps, weight, created, unit, hidden, image, sets, minutes, seconds, steps FROM sets'''); print('Migrated.'); }, child: const Text("Import")));