enum in prisma instead of table

Viewed 20

I have two tables in my Prisma db. One is for admins and the other is for users, and since they differ a lot from each other I decided not to create an isAdmin field. They have both in common the establishment that is described as a table (one-to-many relation), but it has only one field (name). I'd like to know whether it is a good idea to create an Enum to represent this field. My only doubt is that, since the values of the enums can change (adding more fields dynamically), it is not as good as creating a table

model Admin {
    id              String @id @default(uuid())
    pin             Int
    establishment   Establishment @relation(fields: [establishmentId], references: [id])
    establishmentId Int
}

model User {
    id String @id @default(uuid())
    name            String
    balance         Float @default(0)
    establishment   Establishment @relation(fields: [establishmentId], references: [id])
    establishmentId Int
}

model Establishment {
    id Int @id @default(autoincrement())
    name String
}

This is how I've imagined the new data source to be like

model Admin {
    id              String @id @default(uuid())
    pin             Int
    establishment   Establishment
}

model User {
    id String @id @default(uuid())
    name            String
    balance         Float @default(0)
    establishment   Establishment
}

enum Establishment {
    ESTABLISHMENT1
    ESTABLISHMENT2
}
0 Answers
Related