// 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") } enum RepoIndexingStatus { NEW IN_INDEX_QUEUE INDEXING INDEXED FAILED } enum ConfigSyncStatus { SYNC_NEEDED IN_SYNC_QUEUE SYNCING SYNCED FAILED } model Repo { id Int @id @default(autoincrement()) name String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt indexedAt DateTime? isFork Boolean isArchived Boolean metadata Json cloneUrl String tenantId Int repoIndexingStatus RepoIndexingStatus @default(NEW) // 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 org Org? @relation(fields: [orgId], references: [id], onDelete: Cascade) orgId Int? @@unique([external_id, external_codeHostUrl]) } model Config { id Int @id @default(autoincrement()) data Json createdAt DateTime @default(now()) updatedAt DateTime @updatedAt syncedAt DateTime? syncStatus ConfigSyncStatus @default(SYNC_NEEDED) // The organization that owns this config org Org @relation(fields: [orgId], references: [id], onDelete: Cascade) orgId Int } model Org { id Int @id @default(autoincrement()) name String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt members UserToOrg[] configs Config[] repos Repo[] } enum OrgRole { OWNER MEMBER } 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) @@id([orgId, userId]) } // @see : https://authjs.dev/concepts/database-models#user model User { id String @id @default(cuid()) name String? email String? @unique emailVerified DateTime? image String? accounts Account[] orgs UserToOrg[] activeOrgId Int? 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]) }