@@ -29,35 +29,57 @@ Future<void> migrateDatabase(DatabaseService service, Database db,
2929 await service.userGroup.create (db);
3030 await db.execute ("ALTER TABLE places RENAME TO resources" );
3131 await db.execute ("PRAGMA foreign_keys=off" );
32+
33+ // Migrate events
3234 await db.transaction ((txn) async {
3335 await service.event.create (txn, 'events_temp' );
3436 await txn.execute (
35- "INSERT INTO events_temp SELECT id, parentId, blocked, name, description, location, extra FROM events" );
37+ "INSERT INTO events_temp SELECT id, parentId, blocked, name, description, location, extra FROM events" ,
38+ );
3639 await txn.execute (
37- "INSERT INTO eventResources(eventId, resourceId) SELECT id, placeId FROM events" );
40+ "INSERT INTO eventResources(eventId, resourceId) "
41+ "SELECT id, placeId FROM events WHERE placeId IS NOT NULL" ,
42+ );
3843 await txn.execute (
39- "INSERT INTO eventGroups(eventId, groupId) SELECT id, groupId FROM events" );
44+ "INSERT INTO eventGroups(eventId, groupId) "
45+ "SELECT id, groupId FROM events WHERE groupId IS NOT NULL" ,
46+ );
4047 await txn.execute ("DROP TABLE events" );
4148 await txn.execute ("ALTER TABLE events_temp RENAME TO events" );
4249 });
50+
51+ // Migrate calendarItems
4352 await db.transaction ((txn) async {
4453 await service.calendarItem.create (txn, 'calendarItems_temp' );
4554 await txn.execute (
46- "INSERT INTO calendarItems_temp SELECT id, parentId, blocked, name, description, location, extra FROM calendarItems" );
55+ "INSERT INTO calendarItems_temp "
56+ "SELECT id, parentId, blocked, name, description, location, extra "
57+ "FROM calendarItems" ,
58+ );
4759 await txn.execute (
48- "INSERT INTO calendarItemResources(itemId, resourceId) SELECT id, placeId FROM calendarItems" );
60+ "INSERT INTO calendarItemResources(itemId, resourceId) "
61+ "SELECT id, placeId FROM calendarItems WHERE placeId IS NOT NULL" ,
62+ );
4963 await txn.execute (
50- "INSERT INTO calendarItemGroups(itemId, groupId) SELECT id, groupId FROM calendarItems" );
64+ "INSERT INTO calendarItemGroups(itemId, groupId) "
65+ "SELECT id, groupId FROM calendarItems WHERE groupId IS NOT NULL" ,
66+ );
5167 await txn.execute ("DROP TABLE calendarItems" );
5268 await txn
5369 .execute ("ALTER TABLE calendarItems_temp RENAME TO calendarItems" );
5470 });
71+
72+ // Migrate users
5573 await db.transaction ((txn) async {
5674 await service.user.create (txn, 'users_temp' );
5775 await txn.execute (
58- "INSERT INTO users_temp SELECT id, name, email, description, phone, image FROM users" );
76+ "INSERT INTO users_temp "
77+ "SELECT id, name, email, description, phone, image FROM users" ,
78+ );
5979 await txn.execute (
60- "INSERT INTO userGroups(userId, groupId) SELECT id, groupId FROM users" );
80+ "INSERT INTO userGroups(userId, groupId) "
81+ "SELECT id, groupId FROM users WHERE groupId IS NOT NULL" ,
82+ );
6183 await txn.execute ("DROP TABLE users" );
6284 await txn.execute ("ALTER TABLE users_temp RENAME TO users" );
6385 });
0 commit comments