sourcebot/packages/db/prisma/schema.prisma

177 lines
4.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
}
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-01-14 21:37:31 +00:00
@@unique([external_id, external_codeHostUrl])
}
2025-01-16 23:24:13 +00:00
2025-01-24 21:16:08 +00:00
model Connection {
2025-02-04 20:04:05 +00:00
id Int @id @default(autoincrement())
name String
config Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
syncedAt DateTime?
repos RepoToConnection[]
2025-01-24 21:16:08 +00:00
syncStatus ConnectionSyncStatus @default(SYNC_NEEDED)
2025-02-04 20:04:05 +00:00
// The type of connection (e.g., github, gitlab, etc.)
connectionType String
2025-01-24 21:16:08 +00:00
// The organization that owns this connection
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
orgId Int
}
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])
}
2025-01-17 00:18:16 +00:00
model Org {
2025-01-24 21:16:08 +00:00
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
members UserToOrg[]
connections Connection[]
repos Repo[]
secrets Secret[]
}
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 {
id String @id @default(cuid())
2025-01-16 23:24:13 +00:00
name String?
email String? @unique
2025-01-16 23:24:13 +00:00
emailVerified DateTime?
image String?
accounts Account[]
2025-01-17 00:18:16 +00:00
orgs UserToOrg[]
activeOrgId Int?
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])
}