Brandon Presley
0a7675797b
Still need to make sure we move across sets -> gym_sets since moor won't let me use sets as a table name. Moor doesnt like me having a class called sets with a property called sets.
42 lines
1.1 KiB
Dart
42 lines
1.1 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:fmassive/gym_set.dart';
|
|
import 'package:fmassive/main.dart';
|
|
import 'package:fmassive/plans.dart';
|
|
import 'package:moor/ffi.dart';
|
|
import 'package:moor/moor.dart';
|
|
import 'package:path/path.dart';
|
|
import 'package:sqflite/sqflite.dart';
|
|
|
|
import 'settings.dart';
|
|
|
|
part 'database.g.dart';
|
|
|
|
@UseMoor(tables: [Settings, GymSets, Plans])
|
|
class MyDatabase extends _$MyDatabase {
|
|
MyDatabase() : super(_openConnection());
|
|
|
|
@override
|
|
int get schemaVersion => 1;
|
|
|
|
@override
|
|
MigrationStrategy get migration => MigrationStrategy(
|
|
onCreate: (Migrator m) async {
|
|
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 {
|
|
// no migrations yet
|
|
},
|
|
);
|
|
}
|
|
|
|
LazyDatabase _openConnection() {
|
|
return LazyDatabase(() async {
|
|
final dbFolder = await getDatabasesPath();
|
|
final file = File(join(dbFolder, 'massive.db'));
|
|
return VmDatabase(file, logStatements: true);
|
|
});
|
|
}
|