Fix applying changeset to DB with constraints on Postgres#235
Merged
wonder-sk merged 6 commits intoMerginMaps:masterfrom Dec 18, 2025
Merged
Fix applying changeset to DB with constraints on Postgres#235wonder-sk merged 6 commits intoMerginMaps:masterfrom
wonder-sk merged 6 commits intoMerginMaps:masterfrom
Conversation
7a209a4 to
230ead3
Compare
wonder-sk
approved these changes
Dec 18, 2025
44b0141 to
1cbc5ff
Compare
Previously some code would leak the PGresult, wrapping it with our PostgresResult right away means the destructor will take care of that.
1cbc5ff to
262d9dd
Compare
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.
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.