Skip to content

Commit f7db401

Browse files
authored
Optional Sync Demo: Fixed updating schema when moving todos to synced table (#320)
1 parent 9dea1b9 commit f7db401

File tree

1 file changed

+6
-1
lines changed
  • demos/react-supabase-todolist-optional-sync/src/library/powersync

1 file changed

+6
-1
lines changed

demos/react-supabase-todolist-optional-sync/src/library/powersync/AppSchema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,17 @@ export async function switchToSyncedSchema(db: AbstractPowerSyncDatabase, userId
9090
await db.writeTransaction(async (tx) => {
9191
// Copy local-only data to the sync-enabled views.
9292
// This records each operation in the upload queue.
93+
// Overwrites the local-only owner_id value with the logged-in user's id.
9394
await tx.execute(
9495
'INSERT INTO lists(id, name, created_at, owner_id) SELECT id, name, created_at, ? FROM inactive_local_lists',
9596
[userId]
9697
);
9798

98-
await tx.execute('INSERT INTO todos SELECT * FROM inactive_local_todos');
99+
// Overwrites the local-only created_by value with the logged-in user's id.
100+
await tx.execute(
101+
'INSERT INTO todos(id, list_id, created_at, completed_at, description, completed, created_by) SELECT id, list_id, created_at, completed_at, description, completed, ? FROM inactive_local_todos',
102+
[userId]
103+
);
99104

100105
// Delete the local-only data.
101106
await tx.execute('DELETE FROM inactive_local_todos');

0 commit comments

Comments
 (0)