Discord-InterChat/InterChat

View on GitHub
prisma/schema.prisma

Summary

Maintainability
Test Coverage
generator client {
  provider = "prisma-client-js"
}

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

enum HubModeratorPosition {
  network_mod
  manager
}

type HubRating {
  userId String
  rating Int    @default(0)
}

type HubModerator {
  userId   String
  position HubModeratorPosition @default(network_mod)
}

type hubLogChannelAndRole {
  channelId String
  roleId    String?
}

type userBan {
  reason String
}

type RecentLobbyData {
  lobbyId   String
  timestamp Int
}

enum BlockWordAction {
  BLOCK_MESSAGE
  BLACKLIST
  SEND_ALERT
}

enum InfractionType {
  BLACKLIST
  WARNING
}

enum InfractionStatus {
  ACTIVE
  REVOKED
  APPEALED
}

model UserInfraction {
  id          String           @id @default(nanoid(10)) @map("_id")
  userId      String           @db.String
  hubId       String           @db.ObjectId
  reason      String
  status      InfractionStatus @default(ACTIVE)
  type        InfractionType   @default(BLACKLIST)
  dateIssued  DateTime         @default(now()) // Date when the infraction was issued
  expiresAt   DateTime?
  appealedAt  DateTime?
  moderatorId String?
  userData    UserData         @relation(fields: [userId], references: [id])
  hub         Hub              @relation(fields: [hubId], references: [id])

  @@index([userId, hubId, status])
}

model ServerInfraction {
  id             String           @id @default(nanoid(10)) @map("_id")
  serverName     String
  serverId       String
  hubId          String           @db.ObjectId
  reason         String
  status         InfractionStatus @default(ACTIVE)
  type           InfractionType   @default(BLACKLIST)
  dateIssued     DateTime         @default(now()) // Date when the infraction was issued
  expiresAt      DateTime?
  appealedAt     DateTime?
  appealerUserId String?
  moderatorId    String?
  hub            Hub              @relation(fields: [hubId], references: [id])

  @@index([serverId, hubId, status])
}

model connectedList {
  id         String   @id @default(auto()) @map("_id") @db.ObjectId
  channelId  String   @unique // channel can be thread, or a normal channel
  parentId   String? // ID of the parent channel, if it's a thread @map("parentChannelId")
  serverId   String
  connected  Boolean
  compact    Boolean
  invite     String?
  profFilter Boolean
  embedColor String?
  webhookURL String
  lastActive DateTime @default(now())
  date       DateTime @default(now())
  hub        Hub?     @relation(fields: [hubId], references: [id])
  hubId      String   @db.ObjectId

  @@index(fields: [channelId, serverId])
}

model Hub {
  id                  String             @id @default(auto()) @map("_id") @db.ObjectId
  name                String             @unique
  description         String
  rating              HubRating[]
  ownerId             String
  iconUrl             String
  bannerUrl           String?
  private             Boolean            @default(true)
  locked              Boolean            @default(false)
  appealCooldownHours Int                @default(168) // 7 days
  createdAt           DateTime           @default(now())
  settings            Int // each bit is a setting
  // relations
  invites             HubInvite[]
  moderators          HubModerator[]
  connections         connectedList[]
  logConfig           HubLogConfig[]
  msgBlockList        MessageBlockList[]
  userInfractions     UserInfraction[]
  serverInfractions   ServerInfraction[]

  @@index([id, name, ownerId])
}

model MessageBlockList {
  id        String            @id @default(auto()) @map("_id") @db.ObjectId
  name      String
  words     String
  createdBy String
  createdAt DateTime          @default(now())
  updatedAt DateTime          @updatedAt
  actions   BlockWordAction[] @default([])
  hub       Hub               @relation(fields: [hubId], references: [id])
  hubId     String            @db.ObjectId

  @@index([id, words])
}

model HubLogConfig {
  id            String                @id @default(auto()) @map("_id") @db.ObjectId
  modLogs       String?
  joinLeaves    String?
  profanity     String?
  appeals       hubLogChannelAndRole?
  reports       hubLogChannelAndRole?
  networkAlerts hubLogChannelAndRole?
  hub           Hub                   @relation(fields: [hubId], references: [id])
  hubId         String                @unique @db.ObjectId

  @@index([id, hubId])
}

model HubInvite {
  code    String   @id @default(nanoid(10)) @map("_id")
  expires DateTime
  hub     Hub      @relation(fields: [hubId], references: [id])
  hubId   String   @db.ObjectId

  @@index([code, hubId])
}

model UserData {
  id             String           @id @map("_id") @db.String
  voteCount      Int              @default(0)
  username       String?
  locale         String?
  lastVoted      DateTime?
  banMeta        userBan?
  mentionOnReply Boolean          @default(true)
  acceptedRules  Boolean          @default(false)
  infractions    UserInfraction[]
}

model LobbyChatHistory {
  id        String   @id @default(auto()) @map("_id") @db.ObjectId
  serverId  String
  channelId String
  users     String[]
  lobbyId   String
  date      DateTime @default(now())

  @@index([serverId, channelId, lobbyId])
}

model ServerHistory {
  id            String            @id @default(auto()) @map("_id") @db.ObjectId
  serverId      String            @unique
  recentLobbies RecentLobbyData[]
  createdAt     DateTime          @default(now())
  updatedAt     DateTime          @updatedAt
}

model ServerPreference {
  id                String   @id @default(auto()) @map("_id") @db.ObjectId
  serverId          String   @unique
  premiumStatus     Boolean  @default(false)
  maxServersInLobby Int      @default(3)
  createdAt         DateTime @default(now())
  updatedAt         DateTime @updatedAt
}