Skip to content

fix(deparser): keep the constraint name on EXCLUDE constraints - #331

Merged
pyramation merged 1 commit into
mainfrom
fix/named-exclude-constraint
Aug 1, 2026
Merged

fix(deparser): keep the constraint name on EXCLUDE constraints#331
pyramation merged 1 commit into
mainfrom
fix/named-exclude-constraint

Conversation

@pyramation

Copy link
Copy Markdown
Collaborator

Summary

Constraint() only emitted CONSTRAINT <name> for a whitelist of contypes, and CONSTR_EXCLUSION was missing — so a named exclusion constraint silently lost its name on deparse:

-- in
CONSTRAINT one_pending_per_database EXCLUDE USING btree (database_id WITH =) WHERE (status = 'pending')
-- out (before)
EXCLUDE USING btree (database_id WITH =) WHERE (status = 'pending')

That's a real semantic loss: the constraint gets an auto-generated name, so ALTER TABLE ... DROP CONSTRAINT one_pending_per_database and migration diffs break. Found while chasing the ⚠️ AST round-trip diff detected! warning during pgpm package in constructive-db (metaschema_public.database_transfer).

-if (node.conname && (… || node.contype === 'CONSTR_NOTNULL')) {
+if (node.conname && (… || node.contype === 'CONSTR_NOTNULL' || node.contype === 'CONSTR_EXCLUSION')) {

Fixture added to __fixtures__/kitchen-sink/misc/issues.sql (inline named EXCLUDE + ALTER TABLE ADD CONSTRAINT ... EXCLUDE USING gist), regenerated via npm run kitchen-sink. Full deparser suite passes (295 suites / 715 tests).

Link to Devin session: https://app.devin.ai/sessions/5cfcc6690b574cdd96de080ee3b94b4e
Requested by: @pyramation

@pyramation pyramation self-assigned this Aug 1, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation
pyramation merged commit 904248c into main Aug 1, 2026
13 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.

1 participant