Skip to content

Commit 9d90f5c

Browse files
fix: Skip over dropped attributes when enumerating types (#492)
* 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? * use `not` --------- Co-authored-by: Bobbie Soedirgo <[email protected]>
1 parent fdae4fa commit 9d90f5c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ To start developing, run `npm run dev`. It will set up the database with Docker
101101
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.
102102

103103
To make changes to the TypeScript type generation, run `npm run gen:types:typescript` while you have `npm run dev` running.
104+
To use your own database connection string instead of the provided test database, run:
105+
`PG_META_DB_URL=postgresql://postgres:postgres@localhost:5432/postgres npm run gen:types:typescript`
104106

105107
## Licence
106108

src/lib/sql/types.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ from
2929
pg_class c
3030
join pg_attribute a on a.attrelid = c.oid
3131
where
32-
c.relkind = 'c'
32+
c.relkind = 'c' and not a.attisdropped
3333
group by
3434
c.oid
3535
) as t_attributes on t_attributes.oid = t.typrelid

0 commit comments

Comments
 (0)