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.02k stars 201 forks source link

Generated types for a view do not match the original table #1004

Closed chrism closed 6 months ago

chrism commented 1 year ago

Bug report

I was advised by silentworks to raise this as a bug here after posting on the Supabase discord https://discord.com/channels/839993398554656828/1086948087316086864

Describe the bug

The typescript types generated for a view don't seem to match the types for the columns on the table they are based on. They add the possibility for null as an alternative, even if the original column is explicitly set to not null.

To Reproduce

A table called playlists has a column called first_play which is a non nullable boolean.

alter table "public"."playlists" add column "first_play" boolean not null default false;

The generated typescript for this column is as expected

first_play: boolean

But with a view generated like this

CREATE OR REPLACE VIEW public.tracklists AS
  SELECT
    playlists.first_play AS first_play
  FROM playlists

The generated types file produces this

first_play: boolean | null

Expected behavior

I would expect that the generated typescript definition would match the column the view is based on and not add null as a possible option.

System information

bentilling commented 12 months ago

For anyone else that also stumbles on this issue, I looked into fixing it but unfortunately looks like a nuance with Postgres, all view columns are set as nullable, some discussion so doesn't seem anything can be done on Supabase side.

soedirgo commented 6 months ago

Closing as duplicate of https://github.com/supabase/cli/issues/577