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

Adding @@ignore to a model that references an enum fails to generate enhanced client #1835

Closed
wmartins opened this issue Nov 6, 2024 · 3 comments
Milestone

Comments

@wmartins
Copy link

wmartins commented Nov 6, 2024

Description and expected behavior

Ignoring a model with @@ignore causes the enhanced client generation to fail if said model references an enum.

For example, this schema.zmodel:

datasource db {
  provider          = "postgresql"
  url               = env("DATABASE_URL")
}

generator js {
  provider = "prisma-client-js"
  output   = "../node_modules/@prisma-app/client"
}

enum Enum {
    SOME_VALUE
    ANOTHER_VALUE
}

model Model {
    id String @id @default(cuid())
    value Enum
    @@ignore
}

model AnotherModel {
    id String @id @default(cuid())
}

Causes the following error when running zenstack generate:

⌛️ ZenStack CLI v2.8.0, running plugins
✔ Generating Prisma schema
✔ Generating PrismaClient enhancer
Error compiling generated code:
node_modules/.zenstack/policy.ts:5:10 - error TS2305: Module '"../@prisma-app/client"' has no exported member 'Enum'.

5 import { Enum } from "../@prisma-app/client";
           ~~~~

: Error compiling generated code
error: "zenstack" exited with code 1

Screenshots

N/A.

Environment (please complete the following information):

  • ZenStack version: 2.8.0
  • Prisma version: 5.18.0
  • Database type: PostgreSQL

Additional context

We're currently investigating a better process for dropping tables/columns with no downtime. Part of this process uses @ignore/@@ignore to first remove the table/column reference from the Prisma client, and then, in a subsquent work, we actually drop the table/column. While doing that, we stumbled upon this issue where, if we ignore a model with an enum, we can't generate the enhanced client due to the compilation error sent up there.

Prisma doesn't seem to support @ignore for enums (https://www.prisma.io/docs/orm/prisma-schema/data-model/models#defining-enums), so we weren't able to explore that.

@ymc9
Copy link
Member

ymc9 commented Nov 7, 2024

Hi @wmartins , the cause is Prisma's ts code generation doesn't generate an Enum type if it's not referenced by any model. I think a temp workaround could be to create a temp model to keep the reference (but exclude it from migration), and remove it afterwards.

I'll see how we can detect this situation in zenstack to avoid the error.

@ymc9 ymc9 added this to the v2.8.x milestone Nov 7, 2024
@wmartins
Copy link
Author

wmartins commented Nov 8, 2024

Hi @ymc9 thanks for looking into it and taking the time to respond!

I think the temp workaround could work, I'll try that next time we need it. Hopefully we can get it sorted in a new version.

@ymc9
Copy link
Member

ymc9 commented Nov 19, 2024

Fixed in 2.9.0

@ymc9 ymc9 closed this as completed Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants