Skip to content

Fixed updating schema when moving todos to synced table #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion demos/supabase-todolist-optional-sync/lib/models/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ 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 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');
Expand Down
Loading