isaacharrisholt / supawright

A Playwright test harness for E2E testing with Supabase
MIT License
47 stars 2 forks source link

Use `udt_name` for `USER-DEFINED` data types as the generator key #5

Closed 0xBigBoss closed 7 months ago

0xBigBoss commented 9 months ago

Our database uses quite a large number of USER-DEFINED data types in postgres such as enum and citext. This forces all of them to be handled by one USER-DEFINED generator function.

Consider using the udt_name when building the tree and using that as the key for the generator function. Reference..)

https://github.com/isaacharrisholt/supawright/blob/main/src/tree.ts#L42

That will also allow you to join on the possible enum values.

select table_name, column_name, data_type, udt_name
from information_schema.columns
where table_schema in (${schemasString});
-- pull all enum values in a schema
select n.nspname as enum_schema,
       t.typname as enum_name,
       e.enumlabel as enum_value
from pg_type t
         join pg_enum e on t.oid = e.enumtypid
         join pg_catalog.pg_namespace n ON n.oid = t.typnamespace
where n.nspname in (${schemasString});
isaacharrisholt commented 9 months ago

I'd be happy for a change like this to be made! Unfortunately, I don't have huge amounts of time at the minute, but I'd be open to reviewing a PR.

It would have to be backwards-compatible though - I don't fancy a new version number just yet.

isaacharrisholt commented 7 months ago

Hey @0xBigBoss this should now be much easier. Supawright 0.2.0 can automatically infer enums from the DB, and if your USER-DEFINED generator returns null or undefined, this is the behaviour it'll fall back to.