Hey there, I was hoping someone might review my sc...
# orm-help
l
Hey there, I was hoping someone might review my schema. I'm fairly new to Prisma. The goal is to allow a user to have their own projects that only they can access, users can also be a part of a group which will have projects that anyone in the group can access, and to allow there to be a manager user that can access multiple groups and their projects. Any feedback would be much appreciated!
Copy code
generator client {
  provider = "prisma-client-js"
}

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

// -------------------------------------- //

enum Role {
  NONE
  GROUP
  MANAGER
}

enum ProjectStatus {
  TEMPLATE
  IN_PROGRESS
  COMPLETED
}

enum TaskStatus {
  IDLE
  DOING
  DONE
}

// -------------------------------------- //

model User {
  id    Int    @id @default(autoincrement())
  name  String
  email String @unique
  role  Role

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  projects Project[]

  Group   Group? @relation(fields: [groupId], references: [id])
  groupId Int?
}

model Group {
  id    Int    @id @default(autoincrement())
  name  String
  email String @unique

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  members  User[]
  projects Project[]

  Manager   Manager? @relation(fields: [managerId], references: [id])
  managerId Int?
}

model Manager {
  id     Int    @id @default(autoincrement())
  userId String @unique
  name   String
  email  String @unique

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  groups Group[]
}

// -------------------------------------- //

model Project {
  id            Int           @id @default(autoincrement())
  createdAt     DateTime      @default(now())
  updatedAt     DateTime      @updatedAt
  projectStatus ProjectStatus
  archived      Boolean       @default(false)
  starred       Boolean       @default(false)
  name          String
  description   String
  tag           String
  deadline      DateTime
  links         String[]

  stories Story[]

  User    User?  @relation(fields: [userId], references: [id])
  userId  Int?

  Group   Group? @relation(fields: [groupId], references: [id])
  groupId Int?
}

model Story {
  id          Int      @id @default(autoincrement())
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
  description String

  tasks Task[]

  Project   Project? @relation(fields: [projectId], references: [id])
  projectId Int?
}

model Task {
  id        Int        @id @default(autoincrement())
  createdAt DateTime   @default(now())
  updatedAt DateTime   @updatedAt
  name      String
  status    TaskStatus

  Story   Story? @relation(fields: [storyId], references: [id])
  storyId Int?
}