Skip to content

Commit 2a72b71

Browse files
authored
Merge branch 'main' into pg/create-view-281
2 parents caee212 + d8838c5 commit 2a72b71

File tree

19 files changed

+179
-479
lines changed

19 files changed

+179
-479
lines changed

β€ŽAGENTS.mdβ€Ž

Lines changed: 0 additions & 224 deletions
This file was deleted.

β€ŽREADME.mdβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ await deparse(stmt);
132132
| [**@pgsql/cli**](./packages/pgsql-cli) | Unified CLI for all PostgreSQL AST operations | β€’ Parse SQL to AST<br>β€’ Deparse AST to SQL<br>β€’ Generate TypeScript from protobuf<br>β€’ Single tool for all operations |
133133
| [**@pgsql/utils**](./packages/utils) | Type-safe AST node creation utilities | β€’ Programmatic AST construction<br>β€’ Runtime Schema<br>β€’ Seamless integration with types |
134134
| [**pg-proto-parser**](./packages/proto-parser) | PostgreSQL protobuf parser and code generator | β€’ Generate TypeScript interfaces from protobuf<br>β€’ Create enum mappings and utilities<br>β€’ AST helper generation |
135+
| [**@pgsql/transform**](./packages/transform) | Multi-version PostgreSQL AST transformer | β€’ Transform ASTs between PostgreSQL versions (13β†’17)<br>β€’ Single source of truth deparser pipeline<br>β€’ Backward compatibility for legacy SQL |
135136

136137

137138
## πŸ› οΈ Development
@@ -232,4 +233,4 @@ console.log(await deparse(query));
232233

233234
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
234235

235-
No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
236+
No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

β€Ž__fixtures__/generated/generated.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21619,7 +21619,7 @@
2161921619
"latest/postgres/create_view-278.sql": "select pg_get_viewdef('tt19v', true)",
2162021620
"latest/postgres/create_view-279.sql": "create view tt20v as\nselect * from\n coalesce(1,2) as c,\n collation for ('x'::text) col,\n current_date as d,\n localtimestamp(3) as t,\n cast(1+2 as int4) as i4,\n cast(1+2 as int8) as i8",
2162121621
"latest/postgres/create_view-280.sql": "select pg_get_viewdef('tt20v', true)",
21622-
"latest/postgres/create_view-281.sql": "create view tt201v as\nselect\n ('2022-12-01'::date + '1 day'::interval) at time zone 'UTC' as atz,\n extract(day from now()) as extr,\n (now(), '1 day'::interval) overlaps\n (current_timestamp(2), '1 day'::interval) as o,\n 'foo' is normalized isn,\n 'foo' is nfkc normalized isnn,\n normalize('foo') as n,\n normalize('foo', nfkd) as nfkd,\n overlay('foo' placing 'bar' from 2) as ovl,\n overlay('foo' placing 'bar' from 2 for 3) as ovl2,\n position('foo' in 'foobar') as p,\n substring('foo' from 2 for 3) as s,\n substring('foo' similar 'f' escape '#') as ss,\n substring('foo' from 'oo') as ssf, -- historically-permitted abuse\n trim(' ' from ' foo ') as bt,\n trim(leading ' ' from ' foo ') as lt,\n trim(trailing ' foo ') as rt,\n trim(E'\\\\000'::bytea from E'\\\\000Tom\\\\000'::bytea) as btb,\n trim(leading E'\\\\000'::bytea from E'\\\\000Tom\\\\000'::bytea) as ltb,\n trim(trailing E'\\\\000'::bytea from E'\\\\000Tom\\\\000'::bytea) as rtb,\n CURRENT_DATE as cd,\n (select * from CURRENT_DATE) as cd2,\n CURRENT_TIME as ct,\n (select * from CURRENT_TIME) as ct2,\n CURRENT_TIME (1) as ct3,\n (select * from CURRENT_TIME (1)) as ct4,\n CURRENT_TIMESTAMP as ct5,\n (select * from CURRENT_TIMESTAMP) as ct6,\n CURRENT_TIMESTAMP (1) as ct7,\n (select * from CURRENT_TIMESTAMP (1)) as ct8,\n LOCALTIME as lt1,\n (select * from LOCALTIME) as lt2,\n LOCALTIME (1) as lt3,\n (select * from LOCALTIME (1)) as lt4,\n LOCALTIMESTAMP as lt5,\n (select * from LOCALTIMESTAMP) as lt6,\n LOCALTIMESTAMP (1) as lt7,\n (select * from LOCALTIMESTAMP (1)) as lt8,\n CURRENT_CATALOG as ca,\n (select * from CURRENT_CATALOG) as ca2,\n CURRENT_ROLE as cr,\n (select * from CURRENT_ROLE) as cr2,\n CURRENT_SCHEMA as cs,\n (select * from CURRENT_SCHEMA) as cs2,\n CURRENT_USER as cu,\n (select * from CURRENT_USER) as cu2,\n USER as us,\n (select * from USER) as us2,\n SESSION_USER seu,\n (select * from SESSION_USER) as seu2,\n SYSTEM_USER as su,\n (select * from SYSTEM_USER) as su2",
21622+
"latest/postgres/create_view-281.sql": "create view tt201v as\nselect\n ('2022-12-01'::date + '1 day'::interval) at time zone 'UTC' as atz,\n extract(day from now()) as extr,\n (now(), '1 day'::interval) overlaps\n (current_timestamp(2), '1 day'::interval) as o,\n 'foo' is normalized isn,\n 'foo' is nfkc normalized isnn,\n normalize('foo') as n,\n normalize('foo', nfkd) as nfkd,\n overlay('foo' placing 'bar' from 2) as ovl,\n overlay('foo' placing 'bar' from 2 for 3) as ovl2,\n position('foo' in 'foobar') as p,\n substring('foo' from 2 for 3) as s,\n substring('foo' from '%o%') as ss, -- if you're extracting using a pattern \n substring('foo' from 'oo') as ssf, -- historically-permitted abuse\n trim(' ' from ' foo ') as bt,\n trim(leading ' ' from ' foo ') as lt,\n trim(trailing ' foo ') as rt,\n trim(E'\\\\000'::bytea from E'\\\\000Tom\\\\000'::bytea) as btb,\n trim(leading E'\\\\000'::bytea from E'\\\\000Tom\\\\000'::bytea) as ltb,\n trim(trailing E'\\\\000'::bytea from E'\\\\000Tom\\\\000'::bytea) as rtb,\n CURRENT_DATE as cd,\n (select * from CURRENT_DATE) as cd2,\n CURRENT_TIME as ct,\n (select * from CURRENT_TIME) as ct2,\n CURRENT_TIME (1) as ct3,\n (select * from CURRENT_TIME (1)) as ct4,\n CURRENT_TIMESTAMP as ct5,\n (select * from CURRENT_TIMESTAMP) as ct6,\n CURRENT_TIMESTAMP (1) as ct7,\n (select * from CURRENT_TIMESTAMP (1)) as ct8,\n LOCALTIME as lt1,\n (select * from LOCALTIME) as lt2,\n LOCALTIME (1) as lt3,\n (select * from LOCALTIME (1)) as lt4,\n LOCALTIMESTAMP as lt5,\n (select * from LOCALTIMESTAMP) as lt6,\n LOCALTIMESTAMP (1) as lt7,\n (select * from LOCALTIMESTAMP (1)) as lt8,\n CURRENT_CATALOG as ca,\n (select * from CURRENT_CATALOG) as ca2,\n CURRENT_ROLE as cr,\n (select * from CURRENT_ROLE) as cr2,\n CURRENT_SCHEMA as cs,\n (select * from CURRENT_SCHEMA) as cs2,\n CURRENT_USER as cu,\n (select * from CURRENT_USER) as cu2,\n USER as us,\n (select * from USER) as us2,\n SESSION_USER seu,\n (select * from SESSION_USER) as seu2,\n SYSTEM_USER as su,\n (select * from SYSTEM_USER) as su2",
2162321623
"latest/postgres/create_view-282.sql": "select pg_get_viewdef('tt201v', true)",
2162421624
"latest/postgres/create_view-283.sql": "create view tt21v as\nselect * from tt5 natural inner join tt6",
2162521625
"latest/postgres/create_view-284.sql": "select pg_get_viewdef('tt21v', true)",

β€Ž__fixtures__/kitchen-sink/latest/postgres/create_view.sqlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ select
686686
overlay('foo' placing 'bar' from 2 for 3) as ovl2,
687687
position('foo' in 'foobar') as p,
688688
substring('foo' from 2 for 3) as s,
689-
substring('foo' similar 'f' escape '#') as ss,
689+
substring('foo' from '%o%') as ss, -- if you're extracting using a pattern
690690
substring('foo' from 'oo') as ssf, -- historically-permitted abuse
691691
trim(' ' from ' foo ') as bt,
692692
trim(leading ' ' from ' foo ') as lt,

β€Ž__fixtures__/postgres/create_view.sqlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ select
731731
overlay('foo' placing 'bar' from 2 for 3) as ovl2,
732732
position('foo' in 'foobar') as p,
733733
substring('foo' from 2 for 3) as s,
734-
substring('foo' similar 'f' escape '#') as ss,
734+
substring('foo' from '%o%') as ss, -- if you're extracting using a pattern
735735
substring('foo' from 'oo') as ssf, -- historically-permitted abuse
736736
trim(' ' from ' foo ') as bt,
737737
trim(leading ' ' from ' foo ') as lt,
File renamed without changes.

β€Žpackages/deparser/TESTING.mdβ€Ž

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Custom testing strategy
2+
3+
Parse the any deparsed or pretty-formatted SQL back and verify the AST matches the original. This ensures the formatting doesn't break the SQL semantics.
4+
5+
Please review the test utilities β€” note that exact SQL string equality is not required. The focus is on comparing the resulting ASTs.
6+
7+
Refer to `expectAstMatch` to understand how correctness is validated.
8+
9+
The pipeline is:
10+
parse(sql1) β†’ ast β†’ deparse(ast) β†’ sql2
11+
While sql2 !== sql1 (textually), a correct round-trip means:
12+
parse(sql1) === parse(sql2) (AST-level equality).
13+
14+
You can see `expectAstMatch` here: packages/deparser/test-utils/index.ts
15+
16+
## Testing Process & Workflow
17+
18+
**Our systematic approach to fixing deparser issues:**
19+
20+
1. **One test at a time**: Focus on individual failing tests using `yarn test --testNamePattern="specific-test"`
21+
2. **Always check for regressions**: After each fix, run full `yarn test` to ensure no previously passing tests broke
22+
3. **Track progress**: Update this file with current pass/fail counts after each significant change
23+
4. **Build before testing**: Always run `yarn build` after code changes before testing
24+
5. **Clean commits**: Stage files explicitly with `git add <file>`, never use `git add .`
25+
6. **Tight feedback loops**: Use isolated debug scripts for complex issues, but don't commit them
26+
27+
**Workflow**: Make changes β†’ `yarn test --testNamePattern="target-test"` β†’ `yarn test` (check regressions) β†’ Update this file β†’ Commit & push
28+
29+
**When committing to TESTS.md, always run all tests β€” do not use testNamePattern, only `yarn test`**

0 commit comments

Comments
Β (0)