Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ Example failure:

Fix: prevent accidental nested `FuncCall` by inspecting and unwrapping recursively.

## Custom testing strategy

Please review the test utilities — note that exact SQL string equality is not required. The focus is on comparing the resulting ASTs.

Refer to `expectAstMatch` to understand how correctness is validated.

The pipeline is:
parse(sql1) → ast → deparse(ast) → sql2
While sql2 !== sql1 (textually), a correct round-trip means:
parse(sql1) === parse(sql2) (AST-level equality).

You can see `expectAstMatch` here: packages/deparser/test-utils/index.ts

---

### Development Setup
Expand Down
6 changes: 5 additions & 1 deletion __fixtures__/generated/generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -21090,7 +21090,11 @@
"misc/issues-4.sql": "CREATE TABLE new_style (\n id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,\n val1 TEXT NOT NULL,\n val2 TEXT NULL\n)",
"misc/issues-5.sql": "ALTER TABLE new_style ADD CONSTRAINT uq_val1_val2_new UNIQUE NULLS NOT DISTINCT (val1, val2)",
"misc/issues-6.sql": "INSERT INTO\n public.people (id, name, epithet, is_great, gender, type_id, date_of_birth, date_of_death, place_of_birth, place_of_death, biography, canonical_status_id, image_url, source_url)\nVALUES\n (1, 'Asterius', 'of Amasea', FALSE, 'M', 1, '0350-01-01', '0410-01-01', 'Cappadocia', 'Amasea', NULL, 1, NULL, NULL),\n (2, 'Ausonius', NULL, FALSE, 'M', 1, '0310-01-01', '0395-01-01', 'Burdigala', NULL, NULL, NULL, NULL, NULL)\nON CONFLICT DO NOTHING",
"misc/issues-7.sql": "COMMENT ON COLUMN \"foo\".\"whatever\" IS $$\nSomething blah, this data may have chars like '\\n' and '\\r' in it.\n$$",
"misc/issues-7.sql": "CREATE TABLE public.ci_builds_runner_session (\n id bigint NOT NULL,\n build_id integer NOT NULL,\n url character varying NOT NULL,\n certificate character varying,\n \"authorization\" character varying\n)",
"misc/issues-8.sql": "COMMENT ON COLUMN public.posts.reply_to_post_number IS 'If this post is a reply to another, this column is the post_number of the post it''s replying to. [FKEY posts.topic_id, posts.post_number]'",
"misc/issues-9.sql": "CREATE TABLE \"Album\"\n(\n \"AlbumId\" INT NOT NULL,\n \"Title\" VARCHAR(160) NOT NULL,\n \"ArtistId\" INT NOT NULL,\n CONSTRAINT \"PK_Album\" PRIMARY KEY (\"AlbumId\")\n)",
"misc/issues-10.sql": "CREATE INDEX \"existing_undispatched_message\" ON public.messages USING btree (\"context_id\", context_type, notification_name, \"to\", user_id)",
"misc/issues-11.sql": "COMMENT ON COLUMN \"foo\".\"whatever\" IS $$\nSomething blah, this data may have chars like '\\n' and '\\r' in it.\n$$",
"misc/inflection-1.sql": "CREATE SCHEMA inflection",
"misc/inflection-2.sql": "GRANT USAGE ON SCHEMA inflection TO PUBLIC",
"misc/inflection-3.sql": "ALTER DEFAULT PRIVILEGES IN SCHEMA inflection \n GRANT EXECUTE ON FUNCTIONS TO PUBLIC",
Expand Down
26 changes: 25 additions & 1 deletion __fixtures__/kitchen-sink/misc/issues.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,31 @@ VALUES
(2, 'Ausonius', NULL, FALSE, 'M', 1, '0310-01-01', '0395-01-01', 'Burdigala', NULL, NULL, NULL, NULL, NULL)
ON CONFLICT DO NOTHING;

-- https://github.com/launchql/pgsql-parser/issues/52
CREATE TABLE public.ci_builds_runner_session (
id bigint NOT NULL,
build_id integer NOT NULL,
url character varying NOT NULL,
certificate character varying,
"authorization" character varying
);

-- https://github.com/launchql/pgsql-parser/issues/50
COMMENT ON COLUMN public.posts.reply_to_post_number IS 'If this post is a reply to another, this column is the post_number of the post it''s replying to. [FKEY posts.topic_id, posts.post_number]';

-- https://github.com/launchql/pgsql-parser/issues/48
CREATE TABLE "Album"
(
"AlbumId" INT NOT NULL,
"Title" VARCHAR(160) NOT NULL,
"ArtistId" INT NOT NULL,
CONSTRAINT "PK_Album" PRIMARY KEY ("AlbumId")
);

-- https://github.com/launchql/pgsql-parser/issues/47
CREATE INDEX "existing_undispatched_message" ON public.messages USING btree ("context_id", context_type, notification_name, "to", user_id);

-- https://github.com/launchql/pgsql-parser/issues/124
COMMENT ON COLUMN "foo"."whatever" IS $$
Something blah, this data may have chars like '\n' and '\r' in it.
$$;
$$;
6 changes: 5 additions & 1 deletion packages/deparser/__tests__/kitchen-sink/misc-issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ it('misc-issues', async () => {
"misc/issues-4.sql",
"misc/issues-5.sql",
"misc/issues-6.sql",
"misc/issues-7.sql"
"misc/issues-7.sql",
"misc/issues-8.sql",
"misc/issues-9.sql",
"misc/issues-10.sql",
"misc/issues-11.sql"
]);
});