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

Add column descriptions to generated typescript types docstring #1713

Closed d9k closed 7 months ago

d9k commented 9 months ago

There must be fields descriptions (comments)

1) in dumps in form of

COMMENT ON COLUMN public.authors.birth_town IS 'town of birth (test description)';

2) in generated typescript types as docstrings before corresponding field names.

Selection_2023-12-05_14-34-25

Selection_2023-12-05_14-33-29

SQL to get descriptions manually

select
    c.table_schema,
    c.table_name,
    c.column_name,
    pgd.description
from pg_catalog.pg_statio_all_tables as st
inner join pg_catalog.pg_description pgd on (
    pgd.objoid = st.relid
)
inner join information_schema.columns c on (
    pgd.objsubid   = c.ordinal_position and
    c.table_schema = st.schemaname and
    c.table_name   = st.relname
);

(thanks to https://stackoverflow.com/a/4946306/1760643)

d9k commented 9 months ago

Adding description in Supabase admin UI: Selection_2023-12-05_14-39-39

d9k commented 9 months ago

I was able to write script which grabs description info using SQL query via PostgreSQL connection to Supabase.

Supabase as single source of truth for fields descriptions can be very useful to construct form fields, for example.

sweatybridge commented 7 months ago

We will support dumping of comments in this PR https://github.com/supabase/cli/pull/1981

Typegen comments are tracked in this issue https://github.com/supabase/cli/issues/412