Skip to content

fix(powersync-db-collection): "id" in trigger WHEN clauses breaks DELETE for on-demand PowerSync collections#1470

Open
Chriztiaan wants to merge 2 commits intoTanStack:mainfrom
Chriztiaan:fix/where-id
Open

fix(powersync-db-collection): "id" in trigger WHEN clauses breaks DELETE for on-demand PowerSync collections#1470
Chriztiaan wants to merge 2 commits intoTanStack:mainfrom
Chriztiaan:fix/where-id

Conversation

@Chriztiaan
Copy link
Copy Markdown
Contributor

🎯 Changes

Addresses #1458.

When compileSQLite builds WHEN clauses for diff-tracking triggers on on-demand sync collections, it correctly emits json_extract(OLD.data, '$.column_name') for regular columns but falls through to a bare "id" for the id column - missing the required OLD./NEW. prefix. SQLite can't resolve an unqualified column reference inside a trigger body, so the diff-tracking triggers silently fail and DELETE operations never reach the PowerSync CRUD queue.

Because no error is thrown, the failure is invisible. Deleted rows disappear from TanStack DB's in-memory state as expected, but since the delete isn't persisted to SQLite, the rows reappear after the next sync cycle. This affects any on-demand collection whose stream WHERE clause references id.

As mentioned in the original issue, the minimal fix is to extract the OLD/NEW prefix from jsonColumn when falling through for the id column. I have also added a few tests to verify that the data correctly enters the upload queue.

The issue touches on making the prefixes configurable, but I don't think that is needed at the moment.

✅ Checklist

  • I have tested this code locally with pnpm test.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.

…here clause would never be added to the PowerSync upload queue.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 13, 2026

More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@1470

@tanstack/browser-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@1470

@tanstack/capacitor-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@1470

@tanstack/cloudflare-durable-objects-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@1470

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@1470

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@1470

@tanstack/db-sqlite-persistence-core

npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@1470

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@1470

@tanstack/electron-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@1470

@tanstack/expo-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@1470

@tanstack/node-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@1470

@tanstack/offline-transactions

npm i https://pkg.pr.new/@tanstack/offline-transactions@1470

@tanstack/powersync-db-collection

npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1470

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@1470

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@1470

@tanstack/react-native-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@1470

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1470

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@1470

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@1470

@tanstack/tauri-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@1470

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1470

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@1470

commit: 53bd45f

@Chriztiaan Chriztiaan changed the title fix: "id" in trigger WHEN clauses breaks DELETE for on-demand PowerSync collections fix(powersync-db-collection): "id" in trigger WHEN clauses breaks DELETE for on-demand PowerSync collections Apr 13, 2026
@Chriztiaan Chriztiaan marked this pull request as ready for review April 13, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant