Repository navigation
fix(deparser): keep schema qualification on GRANT ON TYPE/DOMAIN, COMMENT ON TRIGGER/RULE/OPERATOR/CAST and CREATE OPERATOR commutator - #375
Conversation
…OMAIN, COMMENT ON TRIGGER/RULE/OPERATOR/CAST and CREATE OPERATOR commutator
…MENT ON TRIGGER/RULE/OPERATOR/CAST and CREATE OPERATOR commutator/negator
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (2) — 🟢 2 low
The deparser gains a
Reviewed commit: b030b3a |
There was a problem hiding this comment.
This PR adds schema-qualified object reference support (operators, triggers, rules, types, domains) to the deparser with ten new kitchen-sink fixtures, but qualified OPERATOR() commutators still round-trip incorrectly in the ALTER OPERATOR path.
Key findings
- 🟡 Qualified
OPERATOR()commutator support is incomplete — deparser.ts:10142
| if (listItems.length > 1 && listItems.every(item => item.String)) { | ||
| return `${preservedDefName} = OPERATOR(${this.qualifiedOperatorName(listItems)})`; | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Qualified OPERATOR() commutator support is incomplete
The new multi-item OPERATOR(schema.op) emission for COMMUTATOR/NEGATOR was added only to the DefineStmt OBJECT_OPERATOR inline handler (packages/deparser/src/deparser.ts:10142). Sibling handlers were not extended, so ALTER OPERATOR fx.### (int, int) SET (COMMUTATOR = OPERATOR(fx.!!!)) round-trips to the invalid SQL commutator = 'fx, !!!' (verified by running the deparser). Users deparsing qualified commutator changes get non-reparseable output.
📋 Prompt for AI Agents
In packages/deparser/src/deparser.ts, the AlterOperatorStmt branch of the DefElem handler (around line 6045) and the DefineStmt-context branches in DefElem (~line 5941) and formatOptionValue (~line 6421) only handle single-item commutator/negator lists; a schema-qualified list such as OPERATOR(fx.!!!) falls through and renders as the invalid SQL commutator = 'fx, !!!'. Extend those branches to emit OPERATOR(<qualified name>) for multi-item all-String lists, mirroring the handling added in the DefineStmt OBJECT_OPERATOR inline path at lines 10142-10144. Verified reproduction: ALTER OPERATOR fx.### (int, int) SET (COMMUTATOR = OPERATOR(fx.!!!));.
…op)) keeps the qualified operator
…(schema.op) in ALTER OPERATOR and DefElem paths too
Summary
Found while round-tripping
pgpm diffmigrations (constructive) through the deparser: several schema-qualified object references deparsed to SQL that Postgres rejects. Each case is a name list that was either joined as aList(fx, e) or had only its first element read.GRANT USAGE ON TYPE fx.e TO r1(alsoDOMAIN,REVOKE)GRANT USAGE ON TYPE fx, e TO r1GRANT USAGE ON TYPE fx.e TO r1COMMENT ON TRIGGER t_tg ON fx.t IS 'x'COMMENT ON TRIGGER fx.t.t_tg IS 'x'COMMENT ON RULE r ON fx.t IS 'x'COMMENT ON RULE fx.t.r IS 'x'COMMENT ON OPERATOR fx.### (int, int) IS 'x'COMMENT ON OPERATOR fx(int, int) IS 'x'COMMENT ON CAST (int AS text) IS 'x'COMMENT ON CAST int.text IS 'x'CREATE OPERATOR fx.### (..., COMMUTATOR = OPERATOR(fx.###))Commutator = fx, "###"Commutator = OPERATOR(fx.###)Changes in
deparser.ts:GrantStmt(both object-list branches): forOBJECT_TYPE/OBJECT_DOMAIN, aListobject is joined with.instead of visited as a list.CommentStmt:OBJECT_TRIGGER/OBJECT_RULEtake the last name as the trigger/rule and the rest as the (possibly schema-qualified) table;OBJECT_CASTrenders(source AS target); operator names use allobjnameparts via a newqualifiedOperatorNamehelper (schema parts quoted, operator symbol verbatim).DefineStmt(CREATE OPERATOR): multi-partCOMMUTATOR/NEGATORlists render asOPERATOR(schema.op).Fixture
__fixtures__/kitchen-sink/misc/qualified-object-refs.sql+ regeneratedgenerated.json/test file, committed first so the test fails onmain. Full deparser suite: 750/750.The constructive side (
pgpm diffe2e cases for comments/grants on every object kind) depends on this being published and bumped there.Link to Devin session: https://app.devin.ai/sessions/5cfb0f837b8849969154e1b17a38803d
Open in Devin Desktop: https://app.devin.ai/desktop/session/5cfb0f837b8849969154e1b17a38803d?variant=devin
Requested by: @pyramation