seed update, action prep, titleization
This commit is contained in:
@ -1,11 +1,62 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift_flutter/drift_flutter.dart';
|
||||
import 'package:sendtrain/daos/actions_dao.dart';
|
||||
import 'package:sendtrain/daos/activities_dao.dart';
|
||||
import 'package:sendtrain/daos/activity_actions_dao.dart';
|
||||
import 'package:sendtrain/daos/media_items_dao.dart';
|
||||
import 'package:sendtrain/daos/session_activities_dao.dart';
|
||||
import 'package:sendtrain/daos/sessions_dao.dart';
|
||||
import 'package:sendtrain/database/seed.dart';
|
||||
|
||||
part 'database.g.dart';
|
||||
|
||||
@DriftDatabase(tables: [
|
||||
Sessions,
|
||||
SessionActivities,
|
||||
Activities,
|
||||
ActivityActions,
|
||||
Actions,
|
||||
ObjectMediaItems,
|
||||
MediaItems
|
||||
], daos: [
|
||||
SessionsDao,
|
||||
ActivitiesDao,
|
||||
MediaItemsDao,
|
||||
SessionActivitiesDao,
|
||||
ActivityActionsDao,
|
||||
ActionsDao
|
||||
])
|
||||
class AppDatabase extends _$AppDatabase {
|
||||
// After generating code, this class needs to define a `schemaVersion` getter
|
||||
// and a constructor telling drift where the database should be stored.
|
||||
// These are described in the getting started guide: https://drift.simonbinder.eu/setup/
|
||||
AppDatabase() : super(_openConnection());
|
||||
|
||||
@override
|
||||
int get schemaVersion => 4;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration {
|
||||
return MigrationStrategy(
|
||||
onCreate: (m) async {
|
||||
await m.createAll().then((r) async {
|
||||
await seedDb(this);
|
||||
}); // create all tables
|
||||
},
|
||||
beforeOpen: (details) async {
|
||||
/// Enable foreign_keys
|
||||
await customStatement('PRAGMA foreign_keys = ON');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static QueryExecutor _openConnection() {
|
||||
// `driftDatabase` from `package:drift_flutter` stores the database in
|
||||
// `getApplicationDocumentsDirectory()`.
|
||||
return driftDatabase(name: 'sendtrain');
|
||||
}
|
||||
}
|
||||
|
||||
enum SessionStatus { pending, started, completed, missed }
|
||||
|
||||
class Sessions extends Table {
|
||||
@ -22,6 +73,7 @@ class SessionActivities extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
IntColumn get sessionId => integer().references(Sessions, #id)();
|
||||
IntColumn get activityId => integer().references(Activities, #id)();
|
||||
IntColumn get position => integer()();
|
||||
TextColumn get results => text().nullable()();
|
||||
TextColumn get achievements => text().nullable()();
|
||||
DateTimeColumn get createdAt =>
|
||||
@ -57,6 +109,7 @@ class ActivityActions extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
IntColumn get activityId => integer().references(Activities, #id)();
|
||||
IntColumn get actionId => integer().references(Actions, #id)();
|
||||
IntColumn get position => integer()();
|
||||
DateTimeColumn get createdAt =>
|
||||
dateTime().withDefault(Variable(DateTime.now()))();
|
||||
}
|
||||
@ -96,47 +149,3 @@ class MediaItems extends Table {
|
||||
DateTimeColumn get createdAt =>
|
||||
dateTime().withDefault(Variable(DateTime.now()))();
|
||||
}
|
||||
|
||||
@DriftDatabase(tables: [
|
||||
Sessions,
|
||||
SessionActivities,
|
||||
Activities,
|
||||
ActivityActions,
|
||||
Actions,
|
||||
ObjectMediaItems,
|
||||
MediaItems
|
||||
], daos: [
|
||||
SessionsDao,
|
||||
ActivitiesDao,
|
||||
MediaItems
|
||||
])
|
||||
class AppDatabase extends _$AppDatabase {
|
||||
// After generating code, this class needs to define a `schemaVersion` getter
|
||||
// and a constructor telling drift where the database should be stored.
|
||||
// These are described in the getting started guide: https://drift.simonbinder.eu/setup/
|
||||
AppDatabase() : super(_openConnection());
|
||||
|
||||
@override
|
||||
int get schemaVersion => 2;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration {
|
||||
return MigrationStrategy(
|
||||
onCreate: (m) async {
|
||||
await m.createAll().then((r) async {
|
||||
await seedDb(this);
|
||||
}); // create all tablesables
|
||||
},
|
||||
beforeOpen: (details) async {
|
||||
/// Enable foreign_keys
|
||||
await customStatement('PRAGMA foreign_keys = ON');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static QueryExecutor _openConnection() {
|
||||
// `driftDatabase` from `package:drift_flutter` stores the database in
|
||||
// `getApplicationDocumentsDirectory()`.
|
||||
return driftDatabase(name: 'sendtrain');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user