supabase/postgres-meta

supabase gen types generates duplicate identifiers

monodop opened this issue · 3 comments

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

running supabase gen types typescript generates an invalid typescript typing:

To Reproduce

create table
  public.users (
    id uuid not null,
    name character varying(255) not null,
    role public.role not null default 'unapproved'::role,
    constraint users_pkey primary key (id),
    constraint id foreign key (id) references auth.users (id),
    constraint name_length check ((length((name)::text) > 3)),
    constraint name_valid_whitespace check (((name)::text !~ '(^\s)|(\s$)|(\s\s)'::text))
  ) tablespace pg_default;

create type
  public.role as enum ('admin', 'approved', 'unapproved');
npx supabase gen types typescript --local --schema public > $PROJECT_PATH/types/supabase_gen.ts
export type Json =
  | string
  | number
  | boolean
  | null
  | { [key: string]: Json }
  | Json[]

export interface Database {
  public: {
    Tables: {
      users: {
        Row: {
          id: string
          name: string
          name: string
          role: Database["public"]["Enums"]["role"]
        }
        Insert: {
          id: string
          name: string
          name: string
          role?: Database["public"]["Enums"]["role"]
        }
        Update: {
          id?: string
          name?: string
          name?: string
          role?: Database["public"]["Enums"]["role"]
        }
        Relationships: [
          {
            foreignKeyName: "id"
            columns: ["id"]
            referencedRelation: "users"
            referencedColumns: ["id"]
          }
        ]
      }
    }
    Views: {
      [_ in never]: never
    }
    Functions: {
      [_ in never]: never
    }
    Enums: {
      role: "admin" | "approved" | "unapproved"
    }
    CompositeTypes: {
      [_ in never]: never
    }
  }
}

Expected behavior

the name field should not be duplicated in the output ts

image

System information

  • OS: Ubuntu 20.04.5 LTS (wsl2)
  • Version of supabase-js: 1.68.6
  • Version of Node.js: tested on v14.19.0 and v18.16.0

I believe it has to do specifically with this constraint. If I remove it, the issue goes away.

constraint name_valid_whitespace check (((name)::text !~ '(^\s)|(\s$)|(\s\s)'::text))

It looks like this same issue is also happening in the local table editor
image

Thanks for reporting @monodop! Going to transfer this to supabase/postgres-meta for further discussion.