supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
1.08k stars 209 forks source link

Generated types are incorrect for enum arrays #413

Closed mrmattrc closed 2 years ago

mrmattrc commented 2 years ago

Bug report

Describe the bug

When running supabase gen types typescript, enum array type definitions are incorrect. Rather than wrapping the possible values in an array and declaring that it is an array of those types, it puts the array on the last item in the type.

To Reproduce

  1. Create a table with a column specifying an enum array.
  2. Run supabase gen types typescript.
  3. Look at the type output.

Expected behavior

Enum arrays are correctly typed when running supabase gen types typescript.

Screenshots

Supabase enum array definition

Supabase enum array

Generated types (code removed for example)

Generated types

Expected type output (code removed for example)

Expected type output

System information

mrmattrc commented 2 years ago

@soedirgo, thanks for the quick fix! Just out of curiosity, how does supabase/postgres-meta affect supabase/cli? In other words, is there a rough ETA for when I can update the CLI to include this fix?

soedirgo commented 2 years ago

We use postgres-meta to do the actual typegen - it's running in Docker through the CLI.

is there a rough ETA

I'd say a few days - there are some changes I'd like to do at the same time. If it's urgent for you we can just do it now though, it's a pretty quick task.

mrmattrc commented 2 years ago

Thanks for the explanation. It's not an urgent issue. Thanks for being willing to prioritize it though! I look forward to getting the new update soon.

mrmattrc commented 2 years ago

@soedirgo, I updated the CLI to v1.3.0 and reran the typegen command, but I am experiencing the same behavior as before.

Generated types (code removed for example)

Supabase Typegen v1.3.0 Output

soedirgo commented 2 years ago

Was this run with --local? You might need to supabase stop && supabase start for the change to take effect

mrmattrc commented 2 years ago

@soedirgo, that worked! I was running locally, so I stopped and restarted supabase, reran the command, and it output it correctly. Thank you for the help!