Harris Rothaermel
09/23/2022, 3:17 AM// This is your Prisma schema file,
// learn more about it in the docs: <https://pris.ly/d/prisma-schema>
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// The User model is for information such as the user's name and email address.
// Email address is optional, but if one is specified for a User then it must be unique.
model User {
id String @id @default(uuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
bots Bot[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
Character Character?
}
// The Account model is for information about OAuth accounts associated with a User.
// It will usually contain access_token, id_token and other OAuth specific data.
// TokenSet from openid-client might give you an idea of all the fields.
model Account {
id String @id @default(uuid())
userId String
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?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
// The Session model is used for database sessions. It is not used if JSON Web Tokens are enabled.
// Keep in mind, that you can use a database to persist Users and Accounts, and still use JWT for sessions.
// See the session.strategy option. A single User can have multiple Sessions, each Session can only have one User.
// When a Session is read, we check if it's expires field indicates an invalid session, and delete it from the database.
model Session {
id String @id @default(uuid())
sessionToken String @unique
userId String
expires DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
// The Verification Token model is used to store tokens for passwordless sign in.
// A single User can have multiple open Verification Tokens (e.g. to sign in to different devices).
// It has been designed to be extendable for other verification purposes in the future (e.g. 2FA / short codes).
// NextAuth.js makes sure that every token is usable only once, and by default has a short (1 day, can be configured by maxAge) lifetime.
// If your user did not manage to finish the sign-in flow in time, they will have to start the sign-in process again.
model VerificationToken {
identifier String
token String @unique
expires DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([identifier, token])
}
model Conversation {
id String @id @default(uuid())
channelId String
active Boolean @default(true)
botId String
messages Message[]
participants Participant[]
summary String? @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
channel Channel @relation(fields: [channelId], references: [id])
bot Bot @relation(fields: [botId], references: [id])
}
// Channels represent the different modalities in which a conversation can be held in
// discord, slack, etc.
// The channel model is acting as an intermediate "base class" for all channels
// hopefully allowing for a more flexible and extensible design in the future
model Channel {
id String @id @default(uuid())
discordChannelId String? @unique
// slackChannelId String? @unique
// websiteChannelId String? @unique
conversations Conversation[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
discordChannel DiscordChannel?
}
model DiscordChannel {
id String @id @default(uuid())
channelid String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
channel Channel? @relation(fields: [channelid], references: [discordChannelId])
}
model Message {
id String @id @default(uuid())
botId String? // The message would only ever have one of these. It's the owner of the message.
participantId String?
conversationId String
content String @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
conversation Conversation @relation(fields: [conversationId], references: [id])
bot Bot? @relation(fields: [botId], references: [id])
participant Participant? @relation(fields: [participantId], references: [id])
@@index([botId])
@@index([participantId])
@@index([conversationId])
}
// Bots are the main entity in the system. They are the ones that are created by a user and are the ones that carry
// ongoing conversations with participants.
// The bot model is acting as an intermediate "base class" for all bots
// hopefully allowing for a more flexible and extensible design in the future
model Bot {
id String @id @default(uuid())
userId String @unique
characterId String?
discordBotId String? @unique // create as many interfaces as needed for different platforms (discord, slack, website, etc)
// slackBotId String? @unique
// websiteBotId String? @unique
active Boolean @default(true)
character Character? @relation(fields: [characterId], references: [id])
messages Message[]
conversations Conversation[]
generations MeteredEvent[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
user User @relation(fields: [userId], references: [id])
discordBot DiscordBot? @relation(fields: [discordBotId], references: [id])
}
model DiscordBot {
id String @id @default(uuid())
botId String
discordId String @unique
discordSecret String @unique
username String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
bot Bot?
}
// Participants are non-registered users of the application that interact with bots. e.g. discord users in your server
// The participant model is acting as an intermediate "base class" for all participants
// hopefully allowing for a more flexible and extensible design in the future.
model Participant {
id String @id @default(uuid())
discordUserId String? @unique // create as many interfaces as needed for different platforms (discord, slack, website, etc)
// slackUserId String? @unique
// websiteUserId String? @unique
conversations Conversation[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
discordUser DiscordUser? @relation(fields: [discordUserId], references: [id])
Message Message[]
MeteredEvent MeteredEvent[]
}
model DiscordUser {
id String @id @default(uuid())
discordId String @unique
username String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
Participant Participant?
}
// Metered events are events that are metered by the system. e.g. messages sent, characters generated, etc.
// that will than be used to calculate the cost of the bot to the end user
model MeteredEvent {
id String @id @default(uuid())
botId String
participantId String? // Null for summarization events since it's not triggered by a user
promptTokens Int
completionTokens Int
totalTokens Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
participant Participant? @relation(fields: [participantId], references: [id])
bot Bot @relation(fields: [botId], references: [id])
@@index([botId])
@@index([participantId])
}
// Characters hold all the information about a character that is provided by the user.
// It is the "persona" of the bot.
model Character {
id String @id @default(uuid())
userId String @unique
name String
pronoun String
background String @db.Text
traits PersonalityTrait[]
worldLore WorldLore[]
examplePhrases ExamplePhrase[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
user User @relation(fields: [userId], references: [id])
Bot Bot[]
@@index([userId])
}
model ExamplePhrase {
id String @id @default(uuid())
characterId String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
character Character @relation(fields: [characterId], references: [id])
@@index([characterId])
}
model PersonalityTrait {
id String @id @default(uuid())
characterId String?
content String @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
character Character? @relation(fields: [characterId], references: [id])
@@index([characterId])
}
model WorldLore {
id String @id @default(uuid())
characterId String?
content String @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
character Character? @relation(fields: [characterId], references: [id])
@@index([characterId])
}
Jarupong
09/23/2022, 3:20 AMHarris Rothaermel
09/23/2022, 3:25 AMJarupong
09/23/2022, 3:30 AMHarris Rothaermel
09/23/2022, 3:39 AMJarupong
09/23/2022, 3:42 AMHarris Rothaermel
09/23/2022, 3:54 AMJarupong
09/23/2022, 3:57 AMHarris Rothaermel
09/23/2022, 4:00 AMJarupong
09/23/2022, 4:02 AMHarris Rothaermel
09/23/2022, 4:08 AMJarupong
09/23/2022, 4:10 AM