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

Generating types not working for enums: Field name 'request_status' works fine in the UI, but when the types are generated, it uses other values ("PENDING" | "SUCCESS" | "ERROR") #1689

Open victordelajarte opened 9 months ago

victordelajarte commented 9 months ago

Bug report

Describe the bug

Field name 'request_status' works fine in the UI, but when the types are generated, it uses other values ("PENDING" | "SUCCESS" | "ERROR")

To Reproduce

In a Nuxt app with supabase, I created 2 enum types as such, then when generating the types, I get statusA: "PENDING" | "SUCCESS" | "ERROR" for toto_bug instead of the correct statusA: Database["public"]["Enums"]["my_custom_status"] for toto_fine. But it works as expected for both tables in the UI editor (I can use 'approved' for instance).

CREATE TYPE "public"."request_status" AS ENUM (
    'pending',
    'approved',
    'refused',
    'cancelled'
);

CREATE TABLE IF NOT EXISTS "public"."toto_bug" (
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    "statusP" "public"."request_status" DEFAULT 'pending'::"public"."request_status" NOT NULL,
    "statusA" "public"."request_status" DEFAULT 'approved'::"public"."request_status" NOT NULL,
    "statusR" "public"."request_status" DEFAULT 'refused'::"public"."request_status" NOT NULL,
    "statusC" "public"."request_status" DEFAULT 'cancelled'::"public"."request_status" NOT NULL
);

CREATE TYPE "public"."my_custom_status" AS ENUM (
    'pending',
    'approved',
    'refused',
    'cancelled'
);

CREATE TABLE IF NOT EXISTS "public"."toto_fine" (
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    "statusP" "public"."my_custom_status" DEFAULT 'pending'::"public"."my_custom_status" NOT NULL,
    "statusA" "public"."my_custom_status" DEFAULT 'approved'::"public"."my_custom_status" NOT NULL,
    "statusR" "public"."my_custom_status" DEFAULT 'refused'::"public"."my_custom_status" NOT NULL,
    "statusC" "public"."my_custom_status" DEFAULT 'cancelled'::"public"."my_custom_status" NOT NULL
);

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

Capture d’écran 2023-11-27 à 18 37 13

System information

Additional context

Add any other context about the problem here.

amerryma commented 8 months ago

Guessing it has to do with this? I'm thinking it is clashing somehow.

https://github.com/supabase/pg_net/blob/master/sql/pg_net.sql#L259