From 786eec8ec5bcfcdfebc32be5972b249dc97abb6c Mon Sep 17 00:00:00 2001 From: Christiaan Landman Date: Thu, 26 Sep 2024 09:03:28 +0200 Subject: [PATCH 1/2] Fixed updating schema when moving todos to synced table --- demos/supabase-todolist-optional-sync/lib/models/schema.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demos/supabase-todolist-optional-sync/lib/models/schema.dart b/demos/supabase-todolist-optional-sync/lib/models/schema.dart index aedec86b..4ec36900 100644 --- a/demos/supabase-todolist-optional-sync/lib/models/schema.dart +++ b/demos/supabase-todolist-optional-sync/lib/models/schema.dart @@ -84,7 +84,8 @@ switchToSyncedSchema(PowerSyncDatabase db, String userId) async { [userId]); await tx.execute( - 'INSERT INTO $todosTable SELECT * FROM inactive_local_$todosTable'); + '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', + [userId]); // Delete the local-only data. await tx.execute('DELETE FROM inactive_local_$todosTable'); From 572974f051125631c7494bce2a34cf71f60329ee Mon Sep 17 00:00:00 2001 From: Christiaan Landman Date: Thu, 26 Sep 2024 09:14:11 +0200 Subject: [PATCH 2/2] Minor comments. --- demos/supabase-todolist-optional-sync/lib/models/schema.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/demos/supabase-todolist-optional-sync/lib/models/schema.dart b/demos/supabase-todolist-optional-sync/lib/models/schema.dart index 4ec36900..de0887b3 100644 --- a/demos/supabase-todolist-optional-sync/lib/models/schema.dart +++ b/demos/supabase-todolist-optional-sync/lib/models/schema.dart @@ -79,10 +79,12 @@ switchToSyncedSchema(PowerSyncDatabase db, String userId) async { await db.writeTransaction((tx) async { // Copy local-only data to the sync-enabled views. // This records each operation in the upload queue. + // Overwrites the local-only owner_id value with the logged-in user's id. await tx.execute( 'INSERT INTO $listsTable(id, name, created_at, owner_id) SELECT id, name, created_at, ? FROM inactive_local_$listsTable', [userId]); + // Overwrites the local-only created_by value with the logged-in user's id. await tx.execute( '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', [userId]);