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
Open
fix(powersync-db-collection): "id" in trigger WHEN clauses breaks DELETE for on-demand PowerSync collections#1470Chriztiaan wants to merge 2 commits intoTanStack:mainfrom
Chriztiaan wants to merge 2 commits intoTanStack:mainfrom
Conversation
…here clause would never be added to the PowerSync upload queue.
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Changes
Addresses #1458.
When
compileSQLitebuilds WHEN clauses for diff-tracking triggers on on-demand sync collections, it correctly emitsjson_extract(OLD.data, '$.column_name')for regular columns but falls through to a bare "id" for the id column - missing the requiredOLD./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
pnpm test.🚀 Release Impact