Skip to content

Commit

Permalink
Optional Sync Demo: Fixed updating schema when moving todos to synced…
Browse files Browse the repository at this point in the history
… table (#320)
  • Loading branch information
Chriztiaan authored Sep 26, 2024
1 parent 9dea1b9 commit f7db401
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,17 @@ export async function switchToSyncedSchema(db: AbstractPowerSyncDatabase, userId
await db.writeTransaction(async (tx) => {
// 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 lists(id, name, created_at, owner_id) SELECT id, name, created_at, ? FROM inactive_local_lists',
[userId]
);

await tx.execute('INSERT INTO todos SELECT * FROM inactive_local_todos');
// Overwrites the local-only created_by value with the logged-in user's id.
await tx.execute(
'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',
[userId]
);

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

0 comments on commit f7db401

Please sign in to comment.