schema.prisma 1.44 KB
generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "debian-openssl-1.1.x", "darwin"]
}

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

model User {
  id          Int       @default(autoincrement()) @id
  avatarUrl   String?   @default("")
  email       String    @unique
  password    String
  name        String
  phoneNum    String    @default("") @unique
  emailSecret String?   @default("")
  phoneSecret String?   @default("")
  bio         String?   @default("")
  rooms       Room[]    @relation(references: [id])
  messages    Message[]
  sender      Message   @relation("Sender")
  receiver    Message[] @relation("Receiver")
  createdAt   DateTime? @default(now())
}

model Room {
  id           Int        @default(autoincrement()) @id
  participants User[]     @relation(references: [id])
  categories   Category[] @relation(references: [id])
}

model Category {
  id    Int     @default(autoincrement()) @id
  name  String? @default("")
  rooms Room[]  @relation(references: [id])
}

model Message {
  id        Int       @default(autoincrement()) @id
  text      String?   @default("")
  from      User      @relation("Sender", fields: [fromId], references: [id])
  fromId    Int
  to        User      @relation("Receiver", fields: [toId], references: [id])
  toId      Int
  room      Room      @relation(fields: [roomId], references: [id])
  roomId    Int
  createdAt DateTime?
  userId    Int?
}