Repository navigation
fix: make the pg13–17 lanes round-trip every statement valid for their major #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a9c9fc0
9745051
0137863
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1001,8 +1001,21 @@ export class V14ToV15Transformer { | |
| return { StatsElem: result }; | ||
| } | ||
|
|
||
| // PG15 replaced the publication's list of tables with a list of PublicationObjSpec | ||
| private publicationTablesToObjects(result: any): void { | ||
| if (result.tables === undefined) return; | ||
| result.pubobjects = (Array.isArray(result.tables) ? result.tables : [result.tables]).map((table: any) => ({ | ||
| PublicationObjSpec: { | ||
| pubobjtype: 'PUBLICATIONOBJ_TABLE', | ||
| pubtable: { relation: table.RangeVar ?? table } | ||
| } | ||
| })); | ||
| delete result.tables; | ||
| } | ||
|
|
||
| CreatePublicationStmt(node: PG14.CreatePublicationStmt, context: TransformerContext): { CreatePublicationStmt: PG15.CreatePublicationStmt } { | ||
| const result = this.transformGenericNode(node, context); | ||
| this.publicationTablesToObjects(result); | ||
| return { CreatePublicationStmt: result }; | ||
| } | ||
|
|
||
|
|
@@ -1013,11 +1026,31 @@ export class V14ToV15Transformer { | |
|
|
||
| AlterPublicationStmt(node: PG14.AlterPublicationStmt, context: TransformerContext): { AlterPublicationStmt: PG15.AlterPublicationStmt } { | ||
| const result = this.transformGenericNode(node, context); | ||
| this.publicationTablesToObjects(result); | ||
| if (result.tableAction !== undefined) { | ||
| const actions: Record<string, string> = { | ||
| DEFELEM_ADD: 'AP_AddObjects', | ||
| DEFELEM_DROP: 'AP_DropObjects', | ||
| DEFELEM_SET: 'AP_SetObjects' | ||
| }; | ||
| if (actions[result.tableAction]) { | ||
| result.action = actions[result.tableAction]; | ||
| } | ||
| delete result.tableAction; | ||
| } | ||
| return { AlterPublicationStmt: result }; | ||
| } | ||
|
|
||
| AlterSubscriptionStmt(node: PG14.AlterSubscriptionStmt, context: TransformerContext): { AlterSubscriptionStmt: PG15.AlterSubscriptionStmt } { | ||
| const result = this.transformGenericNode(node, context); | ||
| // ENABLE / DISABLE carried an Integer before PG15 introduced the Boolean node | ||
| if (result.kind === 'ALTER_SUBSCRIPTION_ENABLED' && Array.isArray(result.options)) { | ||
| result.options = result.options.map((option: any) => { | ||
| const ival = option?.DefElem?.arg?.Integer; | ||
| if (option?.DefElem?.defname !== 'enabled' || !ival) return option; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 bug · medium
In 📋 Prompt for AI AgentsIn packages/transform-ast/src/transformers/v14-to-v15.ts at line 1050, inside AlterSubscriptionStmt, replace the guard |
||
| return { DefElem: { ...option.DefElem, arg: { Boolean: { boolval: ival.ival === 1 } } } }; | ||
| }); | ||
| } | ||
| return { AlterSubscriptionStmt: result }; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 bug · medium
Publication table-list flag breaks interleaved object kinds
The generated
PublicationObjSpecoverride strips the leadingTABLEfrom every object after the firstPUBLICATIONOBJ_TABLE, keyed on a state flag that is only reset atCreatePublicationStmt/AlterPublicationStmtentry (packages/deparser/scripts/generate-version-deparsers.ts:128-132). For a publication whose objects interleave kinds,FOR TABLE a, TABLES IN SCHEMA s, TABLE b, the flag set by the first object is never reset, so the third is deparsed as bareb. PG13/14 grammar only acceptsTABLE <list>orTABLES IN SCHEMA ...per object, so the round-trip silently emits SQL those servers reject.📋 Prompt for AI Agents
In packages/deparser/scripts/generate-version-deparsers.ts, in the PUBLICATION_TABLE_LIST template (lines 115-135), inside
PublicationObjSpec, whennode.pubobjtype !== 'PUBLICATIONOBJ_TABLE', setthis.publicationTableListed = falsebefore returningsql. This ensures a bare table name is emitted only when the previous object in the list was also a TABLE object; otherwise PG13/14 output likeFOR TABLE a, TABLES IN SCHEMA s, bis unparseable.