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

Improve handling of invalid Prisma schemas #805

Open
vincanger opened this issue Nov 8, 2022 · 4 comments
Open

Improve handling of invalid Prisma schemas #805

vincanger opened this issue Nov 8, 2022 · 4 comments
Assignees

Comments

@vincanger
Copy link
Contributor

vincanger commented Nov 8, 2022

Describe the bug
I've already spoken with @shayneczyzewski about something I've been noticing with Prisma Entities.

It seems some fields aren't being recognized/compiled by Wasp depending on where they are within the entity object:

image

For example, I didn't notice these two properties in Prisma Studio until I bumped them up to the top of the Entity object (see screenshot). I'm also quite sure I created these properties when I initially created the Entity. After bumping them up to the top of the entity object, I finally get the migrate DB message: 👀 ---- Your Prisma schema has changed, please run wasp db migrate-dev when ready.

If I migrate the DB and then move the fields back down again, I get a drop tables warning. Maybe fields after a field with the "?" are affected? 🤷‍♂️

image

@vincanger
Copy link
Contributor Author

app HiveMind {
  title: "HiveMind",
  db: {
    system: PostgreSQL
  },
  dependencies: [
    ("nodemailer", "^6.8.0")
  ]
}

job emailSender {
  executor: PgBoss, 
  perform: {
    fn: import { workerFunction } from "@ext/workers/emailSender.js"
  },
  schedule: {
    cron: "* * * * *" // every minute
  },
  entities: [Task]
}

entity Task {=psl
    id          Int       @id @default(autoincrement())
    createdAt   DateTime  @default(now())
    updatedAt   DateTime? @updatedAt  
    name        String    @unique
    status      String    @default("pending")
    message     String
    email       String
    deadline    String
    recurring   Int[]?
psl=}

route RootRoute { path: "/", to: MainPage }
page MainPage {
  component: import Main from "@ext/MainPage.js"
}

@shayneczyzewski
Copy link
Sponsor Contributor

I was able to reproduce this bug @vincanger, nice find! Will look into if this is a regression or something we never actually supported next. 👍🏻

@shayneczyzewski
Copy link
Sponsor Contributor

Ok, so it turns out this is not actually a Wasp or Prisma bug per se. Wasp does support optional modifiers (they are used in some sample apps, and even in this example for updatedAt). However, neither Wasp nor Prisma supports both [] and ? simultaneously: https://www.prisma.io/docs/concepts/components/prisma-schema/data-model#type-modifiers

| Note: You cannot combine type modifiers - optional lists are not supported.

So I guess the correct behavior would be for us to show an error to the user, ideally, instead of just skipping whatever follows it. I will leave this open so we can improve this behavior in the future. 👍🏻

@shayneczyzewski shayneczyzewski added enhancement New feature or request and removed bug Something isn't working labels Nov 8, 2022
@shayneczyzewski
Copy link
Sponsor Contributor

@vincanger noted VS Code will give a warning if it was just a Prisma schema file.
unknown

This is a good use case for extending our psql support in some way.

@shayneczyzewski shayneczyzewski changed the title Entity fields not recognized by Wasp Improve handling of invalid Prisma schemas Nov 8, 2022
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

3 participants