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.07k stars 208 forks source link

TypeScript type generation for custom schema #2823

Open dbhathena opened 4 days ago

dbhathena commented 4 days ago

Describe the bug When using a custom schema that I have successfully exposed to the data API, the gen types typescript script generates a file that still defaults to "public" for the Tables<'row'> shorthand.

To Reproduce Steps to reproduce the behavior:

  1. Create custom schema and expose it to the data API following instructions here
  2. In JS client, run npx --yes supabase gen types typescript --project-id "<ID>" --schema custom_schema > ./path/to/db/index.ts
  3. Observe the line type PublicSchema = Database[Extract<keyof Database, 'public'>];

Expected behavior Line type PublicSchema = Database[Extract<keyof Database, 'public'>]; should be type PublicSchema = Database[Extract<keyof Database, 'custom_schema'>];

Screenshots N/A

System information Rerun the failing command with --create-ticket flag.

Additional context If applicable, add any other context about the problem here. N/A

sweatybridge commented 18 hours ago

The shorthand will always default to public schema. You will have to pass in the schema name to the generic type to use the custom schema.