initial commit: fork
This commit is contained in:
16
packages/db/index.ts
Normal file
16
packages/db/index.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
export * from '@prisma/client';
|
||||
|
||||
const globalForPrisma = globalThis as { prisma?: PrismaClient };
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ||
|
||||
new PrismaClient({
|
||||
log:
|
||||
process.env.NODE_ENV === 'development'
|
||||
? ['query', 'error', 'warn']
|
||||
: ['error']
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
|
||||
23
packages/db/package.json
Normal file
23
packages/db/package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "@master-bot/db",
|
||||
"version": "0.1.0",
|
||||
"main": "./index.ts",
|
||||
"types": "./index.ts",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"clean": "rm -rf .turbo node_modules",
|
||||
"db:generate": "pnpm with-env prisma generate",
|
||||
"db:push": "pnpm with-env prisma db push --skip-generate",
|
||||
"db:reset": "pnpm with-env prisma db push --force-reset",
|
||||
"with-env": "dotenv -e ../../.env --"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^5.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.4.6",
|
||||
"dotenv-cli": "^7.2.1",
|
||||
"prisma": "^5.1.1",
|
||||
"typescript": "^5.1.6"
|
||||
}
|
||||
}
|
||||
133
packages/db/prisma/schema.prisma
Normal file
133
packages/db/prisma/schema.prisma
Normal file
@@ -0,0 +1,133 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
shadowDatabaseUrl = env("SHADOW_DB_URL")
|
||||
}
|
||||
|
||||
// Necessary for Next auth
|
||||
model Account {
|
||||
id String @id @default(cuid())
|
||||
userId String @unique
|
||||
type String
|
||||
provider String
|
||||
providerAccountId String
|
||||
refresh_token String? // @db.Text
|
||||
access_token String? // @db.Text
|
||||
expires_at Int?
|
||||
token_type String?
|
||||
scope String?
|
||||
id_token String? // @db.Text
|
||||
session_state String?
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
|
||||
@@unique([provider, providerAccountId])
|
||||
}
|
||||
|
||||
model Session {
|
||||
id String @id @default(cuid())
|
||||
sessionToken String @unique
|
||||
userId String
|
||||
expires DateTime
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
name String?
|
||||
discordId String @unique
|
||||
email String? @unique
|
||||
emailVerified DateTime?
|
||||
image String?
|
||||
account Account?
|
||||
sessions Session[]
|
||||
playlists Playlist[]
|
||||
guilds Guild[]
|
||||
reminders Reminder[]
|
||||
timeOffset Int?
|
||||
}
|
||||
|
||||
model VerificationToken {
|
||||
identifier String
|
||||
token String @unique
|
||||
expires DateTime
|
||||
|
||||
@@unique([identifier, token])
|
||||
}
|
||||
|
||||
model Song {
|
||||
id Int @id @default(autoincrement())
|
||||
length Int
|
||||
track String
|
||||
identifier String
|
||||
author String
|
||||
isStream Boolean
|
||||
position Int
|
||||
title String
|
||||
uri String
|
||||
isSeekable Boolean
|
||||
sourceName String
|
||||
thumbnail String
|
||||
added Int
|
||||
playlistId Int
|
||||
playlist Playlist @relation(fields: [playlistId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model Playlist {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
name String
|
||||
userId String?
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
songs Song[]
|
||||
}
|
||||
|
||||
model Guild {
|
||||
id String @id
|
||||
name String
|
||||
added DateTime @default(now())
|
||||
volume Int @default(100)
|
||||
notifyList String[]
|
||||
ownerId String
|
||||
owner User @relation(fields: [ownerId], references: [discordId])
|
||||
// Settings
|
||||
disabledCommands String[] @map("disabled_commands")
|
||||
logChannel String? @map("log_channel")
|
||||
welcomeMessageChannel String? @map("welcome_message_channel")
|
||||
welcomeMessage String? @map("welcome_message")
|
||||
welcomeMessageEnabled Boolean @default(false) @map("welcome_message_enabled")
|
||||
// Temp Channels
|
||||
hub String?
|
||||
hubChannel String? @map("hub_channel") // The channel that users enter to get redirected
|
||||
tempChannels TempChannel[]
|
||||
}
|
||||
|
||||
model TempChannel {
|
||||
id String @id
|
||||
guildId String
|
||||
guild Guild @relation(fields: [guildId], references: [id])
|
||||
ownerId String @unique
|
||||
}
|
||||
|
||||
model TwitchNotify {
|
||||
twitchId String @id
|
||||
logo String
|
||||
live Boolean @default(false)
|
||||
channelIds String[]
|
||||
sent Boolean
|
||||
}
|
||||
|
||||
model Reminder {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
repeat String?
|
||||
event String
|
||||
description String?
|
||||
dateTime String
|
||||
userId String
|
||||
user User? @relation(fields: [userId], references: [discordId])
|
||||
timeOffset Int
|
||||
}
|
||||
4
packages/db/tsconfig.json
Normal file
4
packages/db/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["index.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user