Skip to content

Commit c5cdac6

Browse files
authored
Merge pull request #30 from DevKor-github/24-db-new
2 parents a467b0f + 6ac904e commit c5cdac6

22 files changed

+2887
-360
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ app.*.map.json
4141
/android/app/debug
4242
/android/app/profile
4343
/android/app/release
44+
45+
*.g.dart

lib/config/database.dart

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,56 @@
11
import 'package:drift/drift.dart';
22
import 'package:drift_flutter/drift_flutter.dart';
3+
import 'package:on_time_front/data/daos/place_dao.dart';
4+
import 'package:on_time_front/data/daos/preparation_schedule_dao.dart';
5+
import 'package:on_time_front/data/daos/preparation_user_dao.dart';
6+
37
import 'package:on_time_front/data/daos/schedule_dao.dart';
8+
import 'package:on_time_front/data/daos/user_dao.dart';
9+
410
import '../data/tables/places_table.dart';
511
import '../data/tables/schedules_table.dart';
12+
import '../data/tables/user_table.dart';
13+
import '../data/tables/preparation_schedule_table.dart';
14+
import '../data/tables/preparation_user_table.dart';
615

716
part 'database.g.dart';
817

9-
@DriftDatabase(tables: [Places, Schedules], daos: [ScheduleDao])
18+
@DriftDatabase(tables: [
19+
Places,
20+
Schedules,
21+
Users,
22+
PreparationSchedules,
23+
PreparationUsers
24+
], daos: [
25+
ScheduleDao,
26+
PlaceDao,
27+
UserDao,
28+
PreparationScheduleDao,
29+
PreparationUserDao
30+
])
1031
class AppDatabase extends _$AppDatabase {
11-
// After generating code, this class needs to define a schemaVersion getter
12-
// and a constructor telling drift where the database should be stored.
13-
// These are described in the getting started guide: https://drift.simonbinder.eu/getting-started/#open
1432
AppDatabase() : super(_openConnection());
1533

1634
@override
17-
int get schemaVersion => 1;
35+
int get schemaVersion => 3;
36+
37+
@override
38+
MigrationStrategy get migration => MigrationStrategy(
39+
onCreate: (Migrator m) async {
40+
await m.createAll();
41+
},
42+
onUpgrade: (Migrator m, int from, int to) async {
43+
if (from == 1) {
44+
await m.createTable(preparationUsers);
45+
await m.createTable(preparationSchedules);
46+
}
47+
},
48+
beforeOpen: (details) async {
49+
await customStatement('PRAGMA foreign_keys = ON');
50+
},
51+
);
1852

1953
static QueryExecutor _openConnection() {
20-
// driftDatabase from package:drift_flutter stores the database in
21-
// getApplicationDocumentsDirectory().
2254
return driftDatabase(name: 'my_database');
2355
}
2456
}

0 commit comments

Comments
 (0)