From e5aeb8a09e8e673248f637e0ce932dc4c1e827b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20H=C3=BCbelbauer?= Date: Sun, 29 Jan 2023 23:48:38 +0100 Subject: [PATCH 1/2] Skip over dropped attributes when enumerating types `pg_attribute` may contain records for attributes that were dropped but Postgres kept them around and instead of deleting them, renamed them to `........pg.dropped.#........` and set their `attisdropped` to `true`. This ends up generating these dropped attributes as `unknown` fields in the TypeScript types. In this commit I updated the `types` query to not return these. Maybe it would be preferrable to instead keep these but skip them only when generating the TypeScript types? --- README.md | 2 ++ src/lib/sql/types.sql | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 573b8c77..d468b0d1 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,8 @@ To start developing, run `npm run dev`. It will set up the database with Docker If you are fixing a bug, you should create a new test case. To test your changes, add the `-u/--updateSnapshot` flag to `jest` on the `test:run` script, run `npm run test`, and then review the git diff of the snapshots. Depending on your change, you may see `id` fields being changed - this is expected and you are free to commit it, as long as it passes the CI. Don't forget to remove the `-u/--updateSnapshot` flag when committing. To make changes to the TypeScript type generation, run `npm run gen:types:typescript` while you have `npm run dev` running. +To use your own database connection string instead of the provided test database, run: +`PG_META_DB_URL=postgresql://postgres:postgres@localhost:5432/postgres npm run gen:types:typescript` ## Licence diff --git a/src/lib/sql/types.sql b/src/lib/sql/types.sql index 1f1fe22c..47af6521 100644 --- a/src/lib/sql/types.sql +++ b/src/lib/sql/types.sql @@ -29,7 +29,7 @@ from pg_class c join pg_attribute a on a.attrelid = c.oid where - c.relkind = 'c' + c.relkind = 'c' and a.attisdropped = false group by c.oid ) as t_attributes on t_attributes.oid = t.typrelid From 6f388836e87edf55b01a1ef5e33b00693ad7ba8d Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Tue, 31 Jan 2023 11:34:45 +0800 Subject: [PATCH 2/2] use `not` --- src/lib/sql/types.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/sql/types.sql b/src/lib/sql/types.sql index 47af6521..d0974012 100644 --- a/src/lib/sql/types.sql +++ b/src/lib/sql/types.sql @@ -29,7 +29,7 @@ from pg_class c join pg_attribute a on a.attrelid = c.oid where - c.relkind = 'c' and a.attisdropped = false + c.relkind = 'c' and not a.attisdropped group by c.oid ) as t_attributes on t_attributes.oid = t.typrelid