Skip to content

(feat): Added manageDestinationExternally option to diff trigger creation. #881

Closed
Chriztiaan wants to merge 14 commits intomainfrom
feature/persisted-diff-trigger-destination
Closed

(feat): Added manageDestinationExternally option to diff trigger creation. #881
Chriztiaan wants to merge 14 commits intomainfrom
feature/persisted-diff-trigger-destination

Conversation

@Chriztiaan
Copy link
Contributor

@Chriztiaan Chriztiaan commented Mar 5, 2026

Problem

The first version of the TanstackDB on-demand sync mode (temp-tanstack-db#6) repeatedly recreates diff triggers on the same destination table as the target WHERE clause changes. Each cycle (dispose old trigger and create new trigger) drops and recreates the destination table, this raises a potential issues with pending mutations and creates gaps that would need to be covered with locks.

Solution

Add a manageDestinationExternally option to createDiffTrigger(). When enabled:

The SDK no longer creates or drops the destination table and the caller owns the full lifecycle (create before first trigger, drop when done). Since the SDK isn't managing the table, it shouldn't be part of the the TriggerClaimManager claim/release flow. Lastly, triggers created with this option use a different naming pattern
so that the periodic cleanupResources regex (/^_ps_temp_trigger…/) skips them. This avoids the cleanup process from dropping externally-managed tables it doesn't own.


A createDiffDestinationTable helper is also exposed so callers don't need to replicate the create table destination table query themselves.

…e destination table to be persisted beyond cleanup of a trigger, also allows the creation to complete even if the destination table already exists.
@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: 3ccc8e3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@powersync/common Minor
@powersync/adapter-sql-js Patch
@powersync/node Patch
@powersync/op-sqlite Patch
@powersync/react-native Patch
@powersync/tanstack-react-query Patch
@powersync/web Patch
@powersync/diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Chriztiaan Chriztiaan changed the title Added persistDestination option to diff trigger creation. Added manageDestinationExternally option to diff trigger creation. Mar 5, 2026
@Chriztiaan Chriztiaan force-pushed the feature/persisted-diff-trigger-destination branch from aff4d8b to 49f564f Compare March 5, 2026 12:30
…l internal management of the destination table.
@Chriztiaan Chriztiaan force-pushed the feature/persisted-diff-trigger-destination branch from 49f564f to 8e501da Compare March 5, 2026 12:32
@Chriztiaan Chriztiaan marked this pull request as ready for review March 5, 2026 13:45
@Chriztiaan
Copy link
Contributor Author

Closing this PR in favour of #888.

@Chriztiaan Chriztiaan closed this Mar 12, 2026
@Chriztiaan Chriztiaan changed the title Added manageDestinationExternally option to diff trigger creation. (feat): Added manageDestinationExternally option to diff trigger creation. Mar 12, 2026
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.

2 participants