schema.prisma 1.52 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("")
  username       String
  email          String          @unique
  password       String
  phoneNum       String          @default("") @unique
  emailSecret    String?         @default("")
  phoneSecret    String?         @default("")
  bio            String?         @default("")
  groups         Group[]         @relation(references: [id])
  messages       Message[]
  directMessages DirectMessage[]
  createdAt      DateTime?       @default(now())
}

model Group {
  id           Int       @default(autoincrement()) @id
  name         String    @unique
  participants User[]
  messages     Message[]
  files        String?   @default("")
  createdAt    DateTime? @default(now())
}

model DirectMessage {
  id        Int       @default(autoincrement()) @id
  text      String    @default("")
  sender    User      @relation(fields: [senderId], references: [id])
  senderId  Int
  createdAt DateTime? @default(now())
}

model Message {
  id        Int       @default(autoincrement()) @id
  text      String    @default("")
  sender    User      @relation(fields: [senderId], references: [id])
  senderId  Int
  group     Group     @relation(fields: [groupId], references: [id])
  groupId   Int
  createdAt DateTime? @default(now())
}