Repository navigation
fix(deparser): keep trigger name in ALTER TRIGGER ... RENAME - #390
Conversation
|
Review complete. 🟠 1 high · 🟡 1 medium 💬 Inline comments (2)
This PR teaches the deparser to render It also adds three kitchen-sink fixtures, a kitchen-sink test, a pretty-print test, and regenerated fixture entries.
One change is needed before merge: the hand-written snapshot file contains unescaped inner quotes and will throw at load time. Reviewed commit: 659de04 |
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
Adds ALTER TRIGGER ... RENAME TO deparse support with fixtures, but emits IF EXISTS in the wrong position and ships a syntactically invalid Jest snapshot.
Key findings
- 🟠
IF EXISTSemitted after trigger name — deparser.ts:8480 - 🟡 Snapshot file has invalid unescaped quotes — alter-trigger-rename.test.ts.snap:5
| exports[`non-pretty: misc/alter-trigger-rename-2.sql 1`] = `"ALTER TRIGGER "Mixed Trig" ON "My Schema"."My Table" RENAME TO "New Trig""`; | ||
|
|
||
| exports[`non-pretty: misc/alter-trigger-rename-3.sql 1`] = `"ALTER TRIGGER old_trigger ON public.t RENAME TO new_trigger"`; | ||
|
|
||
| exports[`pretty: misc/alter-trigger-rename-1.sql 1`] = `"ALTER TRIGGER p ON t RENAME TO q"`; | ||
|
|
||
| exports[`pretty: misc/alter-trigger-rename-2.sql 1`] = `"ALTER TRIGGER "Mixed Trig" ON "My Schema"."My Table" RENAME TO "New Trig""`; |
There was a problem hiding this comment.
🟡 bug · medium
Snapshot file has invalid unescaped quotes
The snapshot entries for misc/alter-trigger-rename-2.sql are invalid JavaScript: raw double quotes appear inside the double-quoted string literal (packages/deparser/tests/pretty/snapshots/alter-trigger-rename.test.ts.snap:5). The same defect appears at line 11 for the pretty: variant. Jest writes inner quotes escaped, so requiring this .snap file throws a SyntaxError, failing every test in alter-trigger-rename.test.ts and potentially aborting the whole Jest run.
📋 Prompt for AI Agents
In packages/deparser/tests/pretty/snapshots/alter-trigger-rename.test.ts.snap, lines 5 and 11 contain raw unescaped double quotes inside double-quoted string literals, which is a JavaScript syntax error that breaks the Jest test module at load. Fix by deleting the file and regenerating with jest -u, so Jest writes the correctly escaped serialization (inner quotes as \").
There was a problem hiding this comment.
Not a bug: the snapshot strings are backtick template literals, so inner double quotes are valid. Deleting and regenerating it with Jest gives byte-identical output, and it loads fine.
There was a problem hiding this comment.
The hunk doesn't support that: the backticks only wrap the snapshot key (e.g. exports[non-pretty: ... 1]), which is standard Jest. The value after = is delimited by double quotes — = "ALTER TRIGGER "Mixed Trig" ON "My Schema"..." — with raw unescaped " inside, which is a SyntaxError at require time. Jest's pretty-format serializer writes inner double quotes as \", so the committed bytes here were not produced by Jest. If you believe the file on disk differs from this diff, please push the regenerated version (delete + jest -u) so we can verify; as shown, lines 5 and 11 are still invalid.
There was a problem hiding this comment.
The value is a backtick literal too: each line is exports[key] = "ALTER TRIGGER "Mixed Trig" ...";, so the double quotes sit inside a template literal, which is Jest's standard format. I checked the file on main by require()-ing it, and it loads without errors.
| if (node.subname) { | ||
| output.push(QuoteUtils.quoteIdentifier(node.subname)); | ||
| } |
There was a problem hiding this comment.
🟠 bug · high
IF EXISTS emitted after trigger name
The new OBJECT_TRIGGER case pushes the quoted trigger name immediately after the TRIGGER keyword (packages/deparser/src/deparser.ts:8480-8482), but the missing_ok check emits IF EXISTS later, at packages/deparser/src/deparser.ts:8516-8518. A trigger rename with missing_ok set therefore deparses to ALTER TRIGGER "trg" IF EXISTS ON t RENAME TO x, which PostgreSQL's grammar (ALTER TRIGGER [IF EXISTS] name ON table RENAME TO ...) rejects as a syntax error, breaking round-trips of statements the parser accepts.
📋 Prompt for AI Agents
In packages/deparser/src/deparser.ts, RenameStmt handler: remove the if (node.subname) push from the case 'OBJECT_TRIGGER': block (lines ~8480-8482) and instead emit QuoteUtils.quoteIdentifier(node.subname) after the missing_ok / IF EXISTS block (after line ~8518), before the ON <relation> handling, so the order is ALTER TRIGGER [IF EXISTS] <name> ON <table> per the PostgreSQL grammar. Mirror the existing OBJECT_RULE handling at lines 8520-8524. The same defect exists for OBJECT_POLICY at lines 8459-8461 and should be fixed in the same pass. Add a fixture for ALTER TRIGGER IF EXISTS p ON t RENAME TO q.
There was a problem hiding this comment.
PostgreSQL doesn't accept IF EXISTS on ALTER TRIGGER ... RENAME: ALTER TRIGGER IF EXISTS p ON t RENAME TO q gives syntax error at or near "EXISTS", so missing_ok can't be set for triggers. No change needed.
Summary
For
OBJECT_TRIGGER,RenameStmtemitted neithersubnamenorON:It now emits the quoted
subnameandON, the same way policies already work. Fixtures cover plain, schema-qualified and quoted names.This is a fresh version of one of the fixes bundled in #368, part of constructive-io/constructive-planning#2555.
Implemented in session Triage stale open PRs and issues in parser repos
Review with Devin · Open in Devin Desktop
Summary by CodeRabbit