Skip to content

Fix applying changeset to DB with constraints on Postgres#235

Merged
wonder-sk merged 6 commits intoMerginMaps:masterfrom
dvdkon:constraint-conflicts-pg
Dec 18, 2025
Merged

Fix applying changeset to DB with constraints on Postgres#235
wonder-sk merged 6 commits intoMerginMaps:masterfrom
dvdkon:constraint-conflicts-pg

Conversation

@dvdkon
Copy link
Contributor

@dvdkon dvdkon commented Dec 11, 2025

This PR is a follow-up to #232, which fixed this issue (#210) for SQLite only. This Postgres version follows roughly the same formula, where we first try to apply all changeset entries, then select those which failed due to constraint conflicts and then try to apply them in a loop until they all apply or we get stuck.

Postgres can defer constraints, but those constraints have to be made deferrable in the first place. This has performance implications (per the documentation), but also deferrable constraints can't be made targets of FOREIGN KEY constraints, so our hacky looping is still sadly necessary.

By default any error rolls back the whole transaction. Since we need statement-level feedback, we have to create a new SAVEPOINT around each statement.

@dvdkon dvdkon force-pushed the constraint-conflicts-pg branch from 7a209a4 to 230ead3 Compare December 11, 2025 09:14
@dvdkon dvdkon changed the title Fix applying changeset to DB with constraints on SQLite Fix applying changeset to DB with constraints on Postgres Dec 11, 2025
@dvdkon dvdkon force-pushed the constraint-conflicts-pg branch 2 times, most recently from 44b0141 to 1cbc5ff Compare December 18, 2025 10:22
@dvdkon dvdkon force-pushed the constraint-conflicts-pg branch from 1cbc5ff to 262d9dd Compare December 18, 2025 12:19
@wonder-sk wonder-sk merged commit 69dcb4c into MerginMaps:master Dec 18, 2025
7 checks passed
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