Skip to content

Commit dab3208

Browse files
authored
Fixed updating schema when moving todos to synced table (#176)
* Fixed updating schema when moving todos to synced table * Minor comments.
1 parent 79aaecf commit dab3208

File tree

1 file changed

+4
-1
lines changed
  • demos/supabase-todolist-optional-sync/lib/models

1 file changed

+4
-1
lines changed

demos/supabase-todolist-optional-sync/lib/models/schema.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ switchToSyncedSchema(PowerSyncDatabase db, String userId) async {
7979
await db.writeTransaction((tx) async {
8080
// Copy local-only data to the sync-enabled views.
8181
// This records each operation in the upload queue.
82+
// Overwrites the local-only owner_id value with the logged-in user's id.
8283
await tx.execute(
8384
'INSERT INTO $listsTable(id, name, created_at, owner_id) SELECT id, name, created_at, ? FROM inactive_local_$listsTable',
8485
[userId]);
8586

87+
// Overwrites the local-only created_by value with the logged-in user's id.
8688
await tx.execute(
87-
'INSERT INTO $todosTable SELECT * FROM inactive_local_$todosTable');
89+
'INSERT INTO $todosTable(id, list_id, created_at, completed_at, description, completed, created_by) SELECT id, list_id, created_at, completed_at, description, completed, ? FROM inactive_local_$todosTable',
90+
[userId]);
8891

8992
// Delete the local-only data.
9093
await tx.execute('DELETE FROM inactive_local_$todosTable');

0 commit comments

Comments
 (0)