Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introspection removes enums and replaces with DB column type #4770

Closed
robertcoopercode opened this issue Dec 23, 2020 · 2 comments
Closed

Introspection removes enums and replaces with DB column type #4770

robertcoopercode opened this issue Dec 23, 2020 · 2 comments
Labels
kind/feature A request for a new feature. team/client Issue for team Client. tech/engines/introspection engine Issue in the Introspection Engine

Comments

@robertcoopercode
Copy link

robertcoopercode commented Dec 23, 2020

Bug description

When specifying enums as the values on a prisma model, those enums get replaced with a String type after running introspection.

Before introspection:

model Goal {
  id              Int            @id @default(autoincrement()) @db.Integer
  type            GoalType       @db.Text
  @@map("goals")
}

enum GoalType {
  DEBT
  SAVING
}

After introspection:

model Goal {
  id              Int            @id @default(autoincrement()) @db.Integer
  type            String         @db.Text
  @@map("goals")
}

Here is the CREATE TABLE expression for the goals table. Take special note that the type column is not a PostgreSQL enum, but rather a text column with a CHECK constraint.

CREATE TABLE "public"."goals" (
    "id" int4 NOT NULL DEFAULT nextval('goals_id_seq'::regclass),
    "type" text NOT NULL CHECK (type = ANY (ARRAY['DEBT'::text, 'SAVING'::text])),
    CONSTRAINT PRIMARY KEY ("id")
);

Expected behavior

I would expect that if running introspection on a column that is already defined by the prisma schema and the column type is defined by a custom enum (the enum being specified in the prisma schema), that the introspection would not replace the enum type to a String type.

Environment & setup

  • Prisma CLI v2.13.0
  • Prisma Client v2.13.1
  • PostgreSQL v12.2
@pantharshit00 pantharshit00 added tech/engines/introspection engine Issue in the Introspection Engine kind/feature A request for a new feature. team/client Issue for team Client. labels Dec 24, 2020
@pantharshit00
Copy link
Contributor

Hey @robertcoopercode

I can reproduce this but this is expected. The type of text is not an enum but text in the schema with a check constraint.

Postgres enums generates a new type on the schema: https://www.postgresql.org/docs/9.1/datatype-enum.html. We support introspecting them as enums.

Issue tracking check constraints: #3388

So I think this is expected and maybe we can even close this if you add your comment in the above mentioned issue.

@robertcoopercode
Copy link
Author

Fair enough. Perhaps I will migrate over to use native Postgres enums instead of check constraints then. I'll add a comment to #3388 as you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature. team/client Issue for team Client. tech/engines/introspection engine Issue in the Introspection Engine
Projects
None yet
Development

No branches or pull requests

2 participants