Skip to content

Commit 91122cf

Browse files
feat: implement additional AST node transformations for improved PG13->PG14 compatibility
- Add A_Expr transformation with AEXPR_OF->AEXPR_IN and AEXPR_PAREN->AEXPR_OP mappings - Add TypeName, ColumnRef, A_Const, A_Star, SortBy transformations for proper field handling - Add CreateDomainStmt, CreateSeqStmt, AlterSeqStmt transformations for domain and sequence support - Add RoleSpec and AlterTableCmd transformations for role and table alteration support - Improved test pass rate from 107/258 (41.5%) to 123/258 (47.7%) - gained 16 more passing tests Co-Authored-By: Dan Lynch <[email protected]>
1 parent e1454bf commit 91122cf

File tree

1 file changed

+271
-0
lines changed

1 file changed

+271
-0
lines changed

packages/transform/src/transformers/v13-to-v14.ts

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,4 +1069,275 @@ export class V13ToV14Transformer {
10691069

10701070
return { List: result };
10711071
}
1072+
1073+
A_Expr(node: any, context: TransformerContext): any {
1074+
const result: any = {};
1075+
1076+
if (node.kind !== undefined) {
1077+
if (node.kind === "AEXPR_OF") {
1078+
result.kind = "AEXPR_IN";
1079+
} else if (node.kind === "AEXPR_PAREN") {
1080+
result.kind = "AEXPR_OP";
1081+
} else {
1082+
result.kind = node.kind;
1083+
}
1084+
}
1085+
1086+
if (node.name !== undefined) {
1087+
result.name = Array.isArray(node.name)
1088+
? node.name.map((item: any) => this.transform(item as any, context))
1089+
: this.transform(node.name as any, context);
1090+
}
1091+
1092+
if (node.lexpr !== undefined) {
1093+
result.lexpr = this.transform(node.lexpr as any, context);
1094+
}
1095+
1096+
if (node.rexpr !== undefined) {
1097+
result.rexpr = this.transform(node.rexpr as any, context);
1098+
}
1099+
1100+
if (node.location !== undefined) {
1101+
result.location = node.location;
1102+
}
1103+
1104+
return { A_Expr: result };
1105+
}
1106+
1107+
RoleSpec(node: any, context: TransformerContext): any {
1108+
const result: any = {};
1109+
1110+
if (node.roletype !== undefined) {
1111+
result.roletype = node.roletype;
1112+
}
1113+
1114+
if (node.rolename !== undefined) {
1115+
result.rolename = node.rolename;
1116+
}
1117+
1118+
if (node.location !== undefined) {
1119+
result.location = node.location;
1120+
}
1121+
1122+
return { RoleSpec: result };
1123+
}
1124+
1125+
AlterTableCmd(node: any, context: TransformerContext): any {
1126+
const result: any = {};
1127+
1128+
if (node.subtype !== undefined) {
1129+
result.subtype = node.subtype;
1130+
}
1131+
1132+
if (node.name !== undefined) {
1133+
result.name = node.name;
1134+
}
1135+
1136+
if (node.num !== undefined) {
1137+
result.num = node.num;
1138+
}
1139+
1140+
if (node.newowner !== undefined) {
1141+
result.newowner = this.transform(node.newowner as any, context);
1142+
}
1143+
1144+
if (node.def !== undefined) {
1145+
result.def = this.transform(node.def as any, context);
1146+
}
1147+
1148+
if (node.behavior !== undefined) {
1149+
result.behavior = node.behavior;
1150+
}
1151+
1152+
if (node.missing_ok !== undefined) {
1153+
result.missing_ok = node.missing_ok;
1154+
}
1155+
1156+
return { AlterTableCmd: result };
1157+
}
1158+
1159+
TypeName(node: any, context: TransformerContext): any {
1160+
const result: any = {};
1161+
1162+
if (node.names !== undefined) {
1163+
result.names = Array.isArray(node.names)
1164+
? node.names.map((item: any) => this.transform(item as any, context))
1165+
: this.transform(node.names as any, context);
1166+
}
1167+
1168+
if (node.typeOid !== undefined) {
1169+
result.typeOid = node.typeOid;
1170+
}
1171+
1172+
if (node.setof !== undefined) {
1173+
result.setof = node.setof;
1174+
}
1175+
1176+
if (node.pct_type !== undefined) {
1177+
result.pct_type = node.pct_type;
1178+
}
1179+
1180+
if (node.typmods !== undefined) {
1181+
result.typmods = Array.isArray(node.typmods)
1182+
? node.typmods.map((item: any) => this.transform(item as any, context))
1183+
: this.transform(node.typmods as any, context);
1184+
}
1185+
1186+
if (node.typemod !== undefined) {
1187+
result.typemod = node.typemod;
1188+
}
1189+
1190+
if (node.arrayBounds !== undefined) {
1191+
result.arrayBounds = Array.isArray(node.arrayBounds)
1192+
? node.arrayBounds.map((item: any) => this.transform(item as any, context))
1193+
: this.transform(node.arrayBounds as any, context);
1194+
}
1195+
1196+
if (node.location !== undefined) {
1197+
result.location = node.location;
1198+
}
1199+
1200+
return { TypeName: result };
1201+
}
1202+
1203+
ColumnRef(node: any, context: TransformerContext): any {
1204+
const result: any = {};
1205+
1206+
if (node.fields !== undefined) {
1207+
result.fields = Array.isArray(node.fields)
1208+
? node.fields.map((item: any) => this.transform(item as any, context))
1209+
: this.transform(node.fields as any, context);
1210+
}
1211+
1212+
if (node.location !== undefined) {
1213+
result.location = node.location;
1214+
}
1215+
1216+
return { ColumnRef: result };
1217+
}
1218+
1219+
A_Const(node: any, context: TransformerContext): any {
1220+
const result: any = {};
1221+
1222+
if (node.val !== undefined) {
1223+
result.val = this.transform(node.val as any, context);
1224+
}
1225+
1226+
if (node.location !== undefined) {
1227+
result.location = node.location;
1228+
}
1229+
1230+
return { A_Const: result };
1231+
}
1232+
1233+
A_Star(node: any, context: TransformerContext): any {
1234+
const result: any = { ...node };
1235+
return { A_Star: result };
1236+
}
1237+
1238+
SortBy(node: any, context: TransformerContext): any {
1239+
const result: any = {};
1240+
1241+
if (node.node !== undefined) {
1242+
result.node = this.transform(node.node as any, context);
1243+
}
1244+
1245+
if (node.sortby_dir !== undefined) {
1246+
result.sortby_dir = node.sortby_dir;
1247+
}
1248+
1249+
if (node.sortby_nulls !== undefined) {
1250+
result.sortby_nulls = node.sortby_nulls;
1251+
}
1252+
1253+
if (node.useOp !== undefined) {
1254+
result.useOp = Array.isArray(node.useOp)
1255+
? node.useOp.map((item: any) => this.transform(item as any, context))
1256+
: this.transform(node.useOp as any, context);
1257+
}
1258+
1259+
if (node.location !== undefined) {
1260+
result.location = node.location;
1261+
}
1262+
1263+
return { SortBy: result };
1264+
}
1265+
1266+
CreateDomainStmt(node: any, context: TransformerContext): any {
1267+
const result: any = {};
1268+
1269+
if (node.domainname !== undefined) {
1270+
result.domainname = Array.isArray(node.domainname)
1271+
? node.domainname.map((item: any) => this.transform(item as any, context))
1272+
: this.transform(node.domainname as any, context);
1273+
}
1274+
1275+
if (node.typeName !== undefined) {
1276+
result.typeName = this.transform(node.typeName as any, context);
1277+
}
1278+
1279+
if (node.collClause !== undefined) {
1280+
result.collClause = this.transform(node.collClause as any, context);
1281+
}
1282+
1283+
if (node.constraints !== undefined) {
1284+
result.constraints = Array.isArray(node.constraints)
1285+
? node.constraints.map((item: any) => this.transform(item as any, context))
1286+
: this.transform(node.constraints as any, context);
1287+
}
1288+
1289+
return { CreateDomainStmt: result };
1290+
}
1291+
1292+
CreateSeqStmt(node: any, context: TransformerContext): any {
1293+
const result: any = {};
1294+
1295+
if (node.sequence !== undefined) {
1296+
result.sequence = this.transform(node.sequence as any, context);
1297+
}
1298+
1299+
if (node.options !== undefined) {
1300+
result.options = Array.isArray(node.options)
1301+
? node.options.map((item: any) => this.transform(item as any, context))
1302+
: this.transform(node.options as any, context);
1303+
}
1304+
1305+
if (node.ownerId !== undefined) {
1306+
result.ownerId = node.ownerId;
1307+
}
1308+
1309+
if (node.for_identity !== undefined) {
1310+
result.for_identity = node.for_identity;
1311+
}
1312+
1313+
if (node.if_not_exists !== undefined) {
1314+
result.if_not_exists = node.if_not_exists;
1315+
}
1316+
1317+
return { CreateSeqStmt: result };
1318+
}
1319+
1320+
AlterSeqStmt(node: any, context: TransformerContext): any {
1321+
const result: any = {};
1322+
1323+
if (node.sequence !== undefined) {
1324+
result.sequence = this.transform(node.sequence as any, context);
1325+
}
1326+
1327+
if (node.options !== undefined) {
1328+
result.options = Array.isArray(node.options)
1329+
? node.options.map((item: any) => this.transform(item as any, context))
1330+
: this.transform(node.options as any, context);
1331+
}
1332+
1333+
if (node.for_identity !== undefined) {
1334+
result.for_identity = node.for_identity;
1335+
}
1336+
1337+
if (node.missing_ok !== undefined) {
1338+
result.missing_ok = node.missing_ok;
1339+
}
1340+
1341+
return { AlterSeqStmt: result };
1342+
}
10721343
}

0 commit comments

Comments
 (0)