MemberRole
enum MemberRole {
  MEMBER
  ADMIN
  OWNER
}
User
model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  firstName String
  lastName  String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  teams   TeamMember[]
  invites Invitation[]
}
Team
model Team {
  id        Int      @id @default(autoincrement())
  name      String
  slug      String   @unique
  logo      String?
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  members TeamMember[]
  invites Invitation[]
}
TeamMember
model TeamMember {
  id        Int      @id @default(autoincrement())
  teamId    Int
  userId    Int
  role      MemberRole
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
  user User @relation(fields: [userId], references: [id])

  @@unique([teamId, userId])
}
Invitation
model Invitation {
  id        Int      @id @default(autoincrement())
  teamId    Int
  email     String
  role      MemberRole
  InvitedBy Int
  token     String   @unique
  expiresAt DateTime
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
  user User @relation(fields: [InvitedBy], references: [id], onDelete: Cascade)

  @@unique([teamId, email])
}