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

Prisma complains when enum types are not declared in alphabetical order #16225

Closed
ekwoka opened this issue Nov 10, 2022 · 2 comments
Closed

Prisma complains when enum types are not declared in alphabetical order #16225

ekwoka opened this issue Nov 10, 2022 · 2 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. topic: enum "type"/block `enum` topic: migrate topic: prisma migrate diff CLI: prisma migrate diff
Milestone

Comments

@ekwoka
Copy link

ekwoka commented Nov 10, 2022

Bug description

No changes have been made to the DB other than in the migrations present that match, but if I do migrate dev to make a new migration it wants to drop and re-add 3 of the columns that are linked to enums, though the new settings match what the migrations have (and on a fresh deployment this happens).

After some digging, it seems to complain differently just based on moving the enum declarations around within the file, and putting them in alphabetical order in the schema file solves the issue of prisma thinking there is a difference.

That's a VERY strange issue for sure.

How to reproduce

See provided schema, push that to a db.

Do prisma migrate diff

change order of enums

do prisma migrate diff

Expected behavior

That the order of the enums doesn't matter

Prisma information

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider      = "prisma-client-js"
}

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

model User {
  id                 Int             @id @default(autoincrement())
  email              String          @unique
  username           String
  hash               String
  role               UserRole        @default(USER)
  avatar             String?
  tickets            Int             @default(0)
  DiscordUser        DiscordUser?
  ActivityLog        PlaySession[]
  AcceptedChallenges UserChallenge[]
  Inventory          Inventory[]
}

model DiscordUser {
  id            String  @unique
  username      String
  discriminator String
  avatar        String?
  User          User    @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId        Int     @unique
}

model Application {
  id             Int           @id @default(autoincrement())
  richPresenceId String?       @unique
  name           String
  description    String?
  tracked        Boolean       @default(false)
  accessCount    Int           @default(0)
  url            String?       @unique
  Image          Image?        @relation(fields: [imageId], references: [id])
  imageId        Int?
  ActivityLog    PlaySession[]
  Challenge      Challenge[]
}

model PlaySession {
  id            Int            @id @default(autoincrement())
  started_at    DateTime       @default(now())
  ended_at      DateTime?
  User          User           @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId        Int
  Application   Application    @relation(fields: [applicationId], references: [id])
  applicationId Int
  Activities    PlayActivity[]

  @@index([ended_at])
}

model PlayActivity {
  id        Int         @id @default(autoincrement())
  timestamp DateTime    @default(now())
  partySize Int         @default(1)
  state     String
  Log       PlaySession @relation(fields: [LogId], references: [id], onDelete: Cascade)
  LogId     Int
}

model Challenge {
  id              Int             @id @default(autoincrement())
  name            String
  description     String
  type            ChallengeType
  stateMatch      String?
  start_time      DateTime        @default(now())
  end_time        DateTime?
  count           Int             @default(1)
  reward          Int             @default(1)
  icon            String?
  Image           Image?          @relation(fields: [imageId], references: [id])
  imageId         Int?
  Application     Application     @relation(fields: [applicationId], references: [id], onDelete: Cascade)
  applicationId   Int
  UsersChallenged UserChallenge[]

  @@index([applicationId], type: Hash)
  @@index([start_time])
  @@index([end_time])
}

model UserChallenge {
  id           Int             @id @default(autoincrement())
  status       ChallengeStatus
  progress     Int             @default(0)
  updated_at   DateTime        @default(now())
  completed_at DateTime?
  User         User            @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId       Int
  Challenge    Challenge       @relation(fields: [challengeId], references: [id], onDelete: Cascade)
  challengeId  Int

  @@index([userId], type: Hash)
}

model Item {
  id                 Int            @id @default(autoincrement())
  name               String
  description        String?
  Image              Image          @relation(fields: [imageId], references: [id])
  imageId            Int
  type               ItemType
  rarity             ItemRarity
  create_on_purchase Boolean        @default(true)
  is_unique          Boolean        @default(false)
  StoreListing       StoreListing[]
  Inventory          Inventory[]
}

model StoreListing {
  id          Int     @id @default(autoincrement())
  name        String?
  description String?
  price       Int
  quantity    Int?
  Image       Image?  @relation(fields: [imageId], references: [id])
  imageId     Int?
  Item        Item    @relation(fields: [itemId], references: [id], onDelete: Cascade)
  itemId      Int
}

model Inventory {
  id         Int      @id @default(autoincrement())
  User       User?    @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId     Int?
  Item       Item     @relation(fields: [itemId], references: [id], onDelete: Cascade)
  itemId     Int
  count      Int      @default(1)
  created_at DateTime @default(now())
  unique_key String?

  @@index([userId], type: Hash)
}

model Image {
  id           Int            @id @default(autoincrement())
  url          String         @unique
  alt          String
  size         Int
  width        Int
  height       Int
  StoreListing StoreListing[]
  Item         Item[]
  Challenge    Challenge[]
  Application  Application[]
}

enum ChallengeStatus {
  ACTIVE
  EXPIRED
  COMPLETED
}

enum ChallengeType {
  TIME
  ACTIVITY
  PARTY
}

enum ItemRarity {
  COMMON
  UNCOMMON
  RARE
  LEGENDARY
  EXOTIC
}

enum ItemType {
  KEY
  GENERIC
}

enum UserRole {
  ADMIN
  USER
}

Environment & setup

  • OS: MacOSVentura
  • Database: PostgreSQL
  • Node.js version: 19.0.1

Prisma Version

prisma                  : 4.6.0
@prisma/client          : 4.6.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 2e719efb80b56a3f32d18a62489de95bb9c130e3 (at node_modules/.pnpm/@prisma+engines@4.6.0/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 2e719efb80b56a3f32d18a62489de95bb9c130e3 (at node_modules/.pnpm/@prisma+engines@4.6.0/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 2e719efb80b56a3f32d18a62489de95bb9c130e3 (at node_modules/.pnpm/@prisma+engines@4.6.0/node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 2e719efb80b56a3f32d18a62489de95bb9c130e3 (at node_modules/.pnpm/@prisma+engines@4.6.0/node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.6.0-53.2e719efb80b56a3f32d18a62489de95bb9c130e3
Default Engines Hash    : 2e719efb80b56a3f32d18a62489de95bb9c130e3
Studio                  : 0.476.0
@ekwoka ekwoka added the kind/bug A reported bug. label Nov 10, 2022
@Jolg42 Jolg42 added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: migrate team/schema Issue for team Schema. topic: enum "type"/block `enum` topic: prisma migrate diff CLI: prisma migrate diff labels Nov 10, 2022
@Jolg42
Copy link
Member

Jolg42 commented Nov 10, 2022

Hi @ekwoka, I think this is a duplicate of #16180

Could you try the patch release version 4.6.1 and let us know if that fixes it?

@ekwoka
Copy link
Author

ekwoka commented Nov 10, 2022

@Jolg42 That does solve the issue. Thank you

@ekwoka ekwoka closed this as completed Nov 10, 2022
@janpio janpio added this to the 4.7.0 milestone Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. topic: enum "type"/block `enum` topic: migrate topic: prisma migrate diff CLI: prisma migrate diff
Projects
None yet
Development

No branches or pull requests

3 participants