Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(db): refactor database schema #217

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
358 changes: 0 additions & 358 deletions locales/af.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/ar.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/ca.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/cs.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/da.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/de.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/el.yml

This file was deleted.

2 changes: 1 addition & 1 deletion locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ hub:
invalidImgurUrl: '{emoji} Invalid image URL for icon or banner. Please make sure you have entered a valid Imgur image URL that is not a gallery or album.'
join:
success: |
Successfully joined hub **{hub}** from {channel}! You can now chat with members from other servers in this hub.
Successfully joined hub **{hub}** from {channel}! You can now chat with members from other servers from this channel.
- Use `/connection` to explore various customizations for this connection.
- Use `/hub leave` to stop receiving messages from this hub.
- Use **`/connection edit`** to change channels.
Expand Down
358 changes: 0 additions & 358 deletions locales/fi.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/fr.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/he.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/hu.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/it.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/ja.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/ko.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/nl.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/no.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/pl.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/pt.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/ro.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/ru.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/sr.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/sv.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/tr.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/uk.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/vi.yml

This file was deleted.

358 changes: 0 additions & 358 deletions locales/zh.yml

This file was deleted.

19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,43 @@
},
"type": "module",
"dependencies": {
"@prisma/client": "^5.22.0",
"@sentry/node": "^8.38.0",
"@prisma/client": "^6.0.0",
"@sentry/node": "^8.41.0",
"common-tags": "^1.8.2",
"discord-hybrid-sharding": "^2.2.3",
"discord.js": "^14.16.3",
"dotenv": "^16.4.5",
"express": "^5.0.1",
"google-translate-api-x": "^10.7.1",
"husky": "^9.1.6",
"husky": "^9.1.7",
"ioredis": "^5.4.1",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"lz-string": "^1.5.0",
"ms": "^2.1.3",
"parse-duration": "^1.1.0",
"reflect-metadata": "^0.2.2",
"source-map-support": "^0.5.21",
"uuid": "^11.0.3",
"winston": "^3.17.0"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^2.10.1",
"@stylistic/eslint-plugin": "^2.11.0",
"@types/common-tags": "^1.8.4",
"@types/express": "^5.0.0",
"@types/js-yaml": "^4.0.9",
"@types/lodash": "^4.17.13",
"@types/ms": "^0.7.34",
"@types/node": "^22.9.0",
"@types/node": "^22.10.1",
"@types/source-map-support": "^0.5.10",
"cz-conventional-changelog": "^3.3.0",
"eslint": "9.14.0",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"prisma": "^5.22.0",
"prettier": "^3.4.1",
"prisma": "^6.0.0",
"release-it": "^17.10.0",
"tsc-watch": "^6.2.1",
"typescript": "^5.6.3",
"typescript-eslint": "^8.14.0"
"typescript": "^5.7.2",
"typescript-eslint": "^8.16.0"
},
"config": {
"commitizen": {
Expand Down
584 changes: 289 additions & 295 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

233 changes: 114 additions & 119 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,22 @@ datasource db {
url = env("DATABASE_URL")
}

enum HubModeratorPosition {
network_mod
manager
// Enums moved to top for better organization
enum Role {
MODERATOR
MANAGER
OWNER
}

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
enum InfractionType {
BLACKLIST
WARNING
}

type RecentLobbyData {
lobbyId String
timestamp Int
enum InfractionStatus {
ACTIVE
REVOKED
APPEALED
}

enum BlockWordAction {
Expand All @@ -42,154 +31,160 @@ enum BlockWordAction {
SEND_ALERT
}

enum InfractionType {
BLACKLIST
WARNING
type LogChannel {
channelId String
roleId String?
}

enum InfractionStatus {
ACTIVE
REVOKED
APPEALED
type RecentLobbyData {
lobbyId String
timestamp Int
}

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])
// Models
model Hub {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
description String
ownerId String
iconUrl String
bannerUrl String?
private Boolean @default(true)
locked Boolean @default(false)
appealCooldownHours Int @default(168)
settings Int
moderators HubModerator[]
connections Connection[]
logConfig HubLogConfig?
blockWords BlockWord[]
infractions Infraction[] // Combined user and server infractions
invites HubInvite[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@index([userId, hubId, status])
@@unique([name])
@@index([ownerId])
}

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])
model HubModerator {
id String @id @default(auto()) @map("_id") @db.ObjectId
hubId String @db.ObjectId
userId String @db.String
role Role
hub Hub @relation(fields: [hubId], references: [id])
user UserData @relation(fields: [userId], references: [id])

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

model connectedList {
model Connection {
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")
channelId String @unique
parentId String? // Parent channel ID for threads
serverId String
connected Boolean
compact Boolean
hubId String @db.ObjectId
connected Boolean @default(true)
compact Boolean @default(false)
invite String?
profFilter Boolean
profFilter Boolean @default(false)
createdAt DateTime @default(now())
embedColor String?
webhookURL String
lastActive DateTime @default(now())
date DateTime @default(now())
hub Hub? @relation(fields: [hubId], references: [id])
hubId String @db.ObjectId
hub Hub @relation(fields: [hubId], references: [id])

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

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[]
model Infraction {
id String @id @default(nanoid(10)) @map("_id")
hubId String @db.ObjectId
type InfractionType @default(BLACKLIST)
status InfractionStatus @default(ACTIVE)
moderatorId String
reason String
expiresAt DateTime?
appealedAt DateTime?
appealedBy String? // User ID

// For user infractions
userId String? @db.String
user UserData? @relation(fields: [userId], references: [id])

// For server infractions
serverId String?
serverName String?

hub Hub @relation(fields: [hubId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

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

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

@@index([id, words])
hub Hub @relation(fields: [hubId], references: [id])

@@index([hubId])
@@index([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])
id String @id @default(auto()) @map("_id") @db.ObjectId
hubId String @unique @db.ObjectId
modLogs LogChannel?
joinLeaves LogChannel?
profanity LogChannel?
appeals LogChannel?
reports LogChannel?
networkAlerts LogChannel?
hub Hub @relation(fields: [hubId], references: [id])
}

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

@@index([code, hubId])
@@index([hubId])
}

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

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

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

model ServerHistory {
Expand Down
Loading
Loading