Skip to content

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

Merged
samwillis merged 3 commits into
TanStack:mainfrom
Chriztiaan:fix/where-id
May 12, 2026
Merged

fix(powersync-db-collection): "id" in trigger WHEN clauses breaks DELETE for on-demand PowerSync collections#1470
samwillis merged 3 commits into
TanStack: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.

@pkg-pr-new

pkg-pr-newBot commented Apr 13, 2026

Copy link
Copy Markdown
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: fc3e440

@ChriztiaanChriztiaan changed the title fix: "id" in trigger WHEN clauses breaks DELETE for on-demand PowerSync collectionsfix(powersync-db-collection): "id" in trigger WHEN clauses breaks DELETE for on-demand PowerSync collectionsApr 13, 2026
@Chriztiaan
Chriztiaan marked this pull request as ready for review April 13, 2026 12:55
@Chriztiaan

Copy link
Copy Markdown
ContributorAuthor

Hey @samwillis , could I possibly get eyes on this?
We have already tested and reviewed it internally :)

@samwillis
samwillis merged commit 06849ef into TanStack:mainMay 12, 2026
7 checks passed
@github-actionsgithub-actionsBot mentioned this pull request May 12, 2026
Sign up for freeto 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.

2 participants

@Chriztiaan@samwillis