sourcebot/packages/db/prisma/schema.prisma

217 lines
5.2 KiB
Text
Raw Normal View History

2025-01-14 21:37:31 +00:00
// 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"
2025-01-14 21:37:31 +00:00
url = env("DATABASE_URL")
}
enum RepoIndexingStatus {
NEW
IN_INDEX_QUEUE
INDEXING
INDEXED
FAILED
}
2025-01-24 21:16:08 +00:00
enum ConnectionSyncStatus {
SYNC_NEEDED
IN_SYNC_QUEUE
SYNCING
SYNCED
FAILED
}
enum StripeSubscriptionStatus {
ACTIVE
INACTIVE
}
2025-01-14 21:37:31 +00:00
model Repo {
2025-02-04 20:04:05 +00:00
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
indexedAt DateTime?
isFork Boolean
isArchived Boolean
metadata Json
cloneUrl String
connections RepoToConnection[]
imageUrl String?
repoIndexingStatus RepoIndexingStatus @default(NEW)
2025-01-14 21:37:31 +00:00
// The id of the repo in the external service
external_id String
// The type of the external service (e.g., github, gitlab, etc.)
external_codeHostType String
// The base url of the external service (e.g., https://github.com)
external_codeHostUrl String
2025-01-24 21:16:08 +00:00
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
orgId Int
2025-02-20 02:53:49 +00:00
@@unique([external_id, external_codeHostUrl, orgId])
2025-01-14 21:37:31 +00:00
}
2025-01-16 23:24:13 +00:00
2025-01-24 21:16:08 +00:00
model Connection {
2025-02-21 18:42:53 +00:00
id Int @id @default(autoincrement())
name String
config Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
syncedAt DateTime?
repos RepoToConnection[]
syncStatus ConnectionSyncStatus @default(SYNC_NEEDED)
syncStatusMetadata Json?
2025-01-24 21:16:08 +00:00
2025-02-04 20:04:05 +00:00
// The type of connection (e.g., github, gitlab, etc.)
2025-02-21 18:42:53 +00:00
connectionType String
2025-02-04 20:04:05 +00:00
2025-01-24 21:16:08 +00:00
// The organization that owns this connection
2025-02-21 18:42:53 +00:00
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
orgId Int
2025-01-24 21:16:08 +00:00
}
model RepoToConnection {
addedAt DateTime @default(now())
2025-02-04 20:04:05 +00:00
connection Connection @relation(fields: [connectionId], references: [id], onDelete: Cascade)
2025-01-24 21:16:08 +00:00
connectionId Int
2025-02-04 20:04:05 +00:00
repo Repo @relation(fields: [repoId], references: [id], onDelete: Cascade)
2025-01-24 21:16:08 +00:00
repoId Int
2025-01-24 21:16:08 +00:00
@@id([connectionId, repoId])
}
model Invite {
/// The globally unique invite id
id String @id @default(cuid())
/// Time of invite creation
createdAt DateTime @default(now())
/// The email of the recipient of the invite
recipientEmail String
/// The user that created the invite
host User @relation(fields: [hostUserId], references: [id], onDelete: Cascade)
hostUserId String
/// The organization the invite is for
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
orgId Int
@@unique([recipientEmail, orgId])
}
2025-01-17 00:18:16 +00:00
model Org {
id Int @id @default(autoincrement())
name String
domain String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
members UserToOrg[]
connections Connection[]
repos Repo[]
secrets Secret[]
2025-02-21 18:32:10 +00:00
isOnboarded Boolean @default(false)
2025-02-21 18:42:53 +00:00
imageUrl String?
2025-02-21 18:32:10 +00:00
stripeCustomerId String?
stripeSubscriptionStatus StripeSubscriptionStatus?
stripeLastUpdatedAt DateTime?
2025-02-12 02:40:42 +00:00
/// List of pending invites to this organization
invites Invite[]
}
enum OrgRole {
OWNER
MEMBER
2025-01-17 00:18:16 +00:00
}
model UserToOrg {
joinedAt DateTime @default(now())
/// The linked organization
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
orgId Int
/// The linked user
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
role OrgRole @default(MEMBER)
2025-01-17 00:18:16 +00:00
@@id([orgId, userId])
}
model Secret {
2025-02-04 20:04:05 +00:00
orgId Int
key String
encryptedValue String
iv String
2025-02-04 20:04:05 +00:00
createdAt DateTime @default(now())
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
@@id([orgId, key])
}
2025-01-16 23:24:13 +00:00
// @see : https://authjs.dev/concepts/database-models#user
model User {
2025-02-21 18:32:10 +00:00
id String @id @default(cuid())
name String?
email String? @unique
hashedPassword String?
emailVerified DateTime?
image String?
accounts Account[]
orgs UserToOrg[]
2025-01-16 23:24:13 +00:00
/// List of pending invites that the user has created
invites Invite[]
2025-01-16 23:24:13 +00:00
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
// @see : https://authjs.dev/concepts/database-models#account
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String?
session_state String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
// @see : https://authjs.dev/concepts/database-models#verificationtoken
model VerificationToken {
identifier String
token String
expires DateTime
@@unique([identifier, token])
}