Skip to content

Commit 3c08ffa

Browse files
committed
docs: add enums package usage documentation to RULES.md for op codes and enum handling
Co-Authored-By: Dan Lynch <[email protected]>
1 parent fa6f942 commit 3c08ffa

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/transform/RULES.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,39 @@ const result = await parser.parse(sql, { version: '13' }); // With await
173173
- Visitor pattern appears broken but works with mock data
174174
- Tests fail because transformations aren't applied
175175

176+
## Using Enums Package for Op Codes and Enum Handling
177+
178+
When working with PG13->PG14 transformations, the enums packages in `src/13/` and `src/14/` directories are essential for handling op codes and enum value differences:
179+
180+
### Key Enum Differences Between PG13 and PG14
181+
182+
- **FunctionParameterMode**: PG14 added `FUNC_PARAM_DEFAULT`
183+
- **CoercionForm**: PG14 added `COERCE_SQL_SYNTAX`
184+
- **TableLikeOption**: PG14 added `CREATE_TABLE_LIKE_COMPRESSION` at position 1, shifting other values
185+
- **RoleSpecType**: PG14 added `ROLESPEC_CURRENT_ROLE` at position 1, shifting other values
186+
187+
### Using Enum Utilities
188+
189+
```typescript
190+
import * as PG13Enums from '../13/enums';
191+
import * as PG14Enums from '../14/enums';
192+
193+
// When you see integers or strings shifting that look like op codes or enums,
194+
// check the enum definitions to understand the mapping:
195+
const pg13TableLikeOptions = PG13Enums.TableLikeOption;
196+
const pg14TableLikeOptions = PG14Enums.TableLikeOption;
197+
198+
// Use enum-to-int.ts and enum-to-str.ts utilities for conversion if needed
199+
```
200+
201+
### Common Enum-Related Test Failures
202+
203+
- **TableLikeOption values**: PG13 value 6 maps to PG14 value 12 due to compression option insertion
204+
- **Function parameter modes**: `FUNC_PARAM_VARIADIC` vs `FUNC_PARAM_DEFAULT` differences
205+
- **Function formats**: `COERCE_EXPLICIT_CALL` vs `COERCE_SQL_SYNTAX` handling
206+
207+
Always consult the enum files when debugging transformation issues involving numeric or string values that appear to be op codes or enum constants.
208+
176209
## Summary
177210

178211
Always use `@pgsql/parser` for multi-version PostgreSQL AST parsing in the transform package. This is the only way to get accurate version-specific results and build working transformers. Remember that all parser methods are async and must be awaited.

0 commit comments

Comments
 (0)