generator client { provider = "prisma-client" output = "../src/generated/prisma" binaryTargets = ["native", "linux-musl-openssl-3.0.x"] previewFeatures = ["postgresqlExtensions"] } generator json { provider = "prisma-json-types-generator" allowAny = false } datasource db { provider = "postgresql" extensions = [vector] } // ---------------------------------------------------------------------- // Enums // ---------------------------------------------------------------------- enum UserType { human agent } enum AssetType { folder file share root attachment version_stack share_root symlink } enum AssetStatus { uploading uploaded processing processed trashed pending_purge } enum StorageKeyStatus { active purging } enum InviteRole { editor reviewer } enum MetadataFieldScope { SYSTEM TEAM PROJECT } enum NotificationType { comment_created reply_created mention successful_file_uploaded metadata_field_updated_status new_user_join_team new_user_join_project } enum ProjectMemberRole { owner editor reviewer } enum TaskType { upload } enum TaskStatus { pending uploading completed failed } enum TeamMemberRole { owner editor reviewer } enum TeamMemberScope { team project } enum WorkflowTaskType { transcode ai_metadata_autofill chat ai_embedding query_embedding_for_search agent_tool_call } enum WorkflowTaskStatus { pending processing completed failed } // ---------------------------------------------------------------------- // Models // ---------------------------------------------------------------------- model User { id String @id @default(ulid()) type UserType @default(human) name String email String @unique emailVerified Boolean @default(false) @map("email_verified") image String? password String? /// [AgentSettings] agentSettings Json? @map("agent_settings") guestEmail String? @map("guest_email") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") assets Asset[] @relation("UserToAsset") authTokens AuthToken[] @relation("UserToAuthToken") tasks Task[] @relation("UserToTask") teamMembers TeamMember[] @relation("UserToTeamMember") comments AssetComment[] @relation("UserToAssetComment") createdInvites Invite[] @relation("UserToInvite") createdNotifications Notification[] @relation("UserToCreatedNotification") notifications Notification[] @relation("UserToNotification") sessions Session[] accounts Account[] agent Agent? agentSessions AgentSession[] userMetadata UserMetadata[] @relation("UserToUserMetadata") collections Collection[] @relation("UserToCollection") shareLinks ShareLink[] @relation("UserToShareLink") @@map("users") } model Session { id String @id @default(ulid()) expiresAt DateTime @map("expires_at") token String @unique createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") ipAddress String? @map("ip_address") userAgent String? @map("user_agent") userId String @map("user_id") user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@map("sessions") } model Account { id String @id @default(ulid()) accountId String @map("account_id") providerId String @map("provider_id") userId String @map("user_id") user User @relation(fields: [userId], references: [id], onDelete: Cascade) accessToken String? @map("access_token") refreshToken String? @map("refresh_token") idToken String? @map("id_token") accessTokenExpiresAt DateTime? @map("access_token_expires_at") refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at") scope String? password String? createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@map("accounts") } model Verification { id String @id @default(ulid()) identifier String value String expiresAt DateTime @map("expires_at") createdAt DateTime? @default(now()) @map("created_at") updatedAt DateTime? @updatedAt @map("updated_at") @@map("verifications") } model AuthToken { id String @id @default(ulid()) accessToken String @unique @map("access_token") refreshToken String @unique @map("refresh_token") accessTokenExpiresAt DateTime @map("access_token_expires_at") refreshTokenExpiresAt DateTime @map("refresh_token_expires_at") userId String @map("user_id") user User @relation("UserToAuthToken", fields: [userId], references: [id]) @@map("auth_tokens") } model Team { id String @id @default(ulid()) name String /// [Settings] settings Json? @default("{}") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") rootFolderId String? @unique @map("root_folder_id") rootFolder Asset? @relation("TeamToRootFolder", fields: [rootFolderId], references: [id]) members TeamMember[] @relation("TeamToTeamMember") projects Project[] @relation("TeamToProject") metadataFields MetadataField[] @relation("TeamToMetadataField") invites Invite[] @relation("TeamToInvite") notifications Notification[] @relation("TeamToNotification") userMetadata UserMetadata[] @relation("TeamToUserMetadata") providers Provider[] @relation("TeamToProvider") skills Skill[] @relation("TeamToSkill") sandbox Sandbox? @relation("TeamToSandbox") agents Agent[] @relation("TeamToAgent") @@map("teams") } model Sandbox { id String @id @default(ulid()) allowedDomains String[] @default(["npmjs.org", "*.npmjs.org", "registry.npmjs.org", "registry.yarnpkg.com", "pypi.org", "*.pypi.org", "github.com", "*.github.com", "api.github.com", "raw.githubusercontent.com"]) pendingDomains String[] @default([]) @map("pending_domains") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") teamId String @unique @map("team_id") team Team @relation("TeamToSandbox", fields: [teamId], references: [id], onDelete: Cascade) @@map("sandboxes") } model Skill { id String @id @default(ulid()) name String description String? /// [SkillConfig] config Json? @default("{}") assetId String @map("asset_id") hash String @map("hash") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") teamId String @map("team_id") team Team @relation("TeamToSkill", fields: [teamId], references: [id], onDelete: Cascade) agentSkills AgentSkill[] @@unique([teamId, name]) @@map("skills") } model TeamMember { id String @id @default(ulid()) role TeamMemberRole scope TeamMemberScope @default(team) teamId String @map("team_id") team Team @relation("TeamToTeamMember", fields: [teamId], references: [id]) userId String @map("user_id") user User @relation("UserToTeamMember", fields: [userId], references: [id], onDelete: Cascade) projectMembers ProjectMember[] @relation("TeamMemberToProjectMember") lastReadNotificationId String? @unique @map("last_read_notification_id") lastReadNotification Notification? @relation("TeamMemberToLastReadNotification", fields: [lastReadNotificationId], references: [id]) @@map("team_members") @@unique([teamId, userId], name: "teamIdUserId") } model Project { id String @id @default(ulid()) name String coverImageKey String? @map("cover_image_key") /// [MetadataOverrides] metadataOverrides Json? @map("metadata_overrides") enableNotification Boolean @default(true) @map("enable_notification") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") teamId String @map("team_id") team Team @relation("TeamToProject", fields: [teamId], references: [id]) rootFolderId String? @unique @map("root_folder_id") rootFolder Asset? @relation("ProjectToRootFolder", fields: [rootFolderId], references: [id]) shareRootId String? @unique @map("share_root_id") shareRoot Asset? @relation("ProjectToShareRoot", fields: [shareRootId], references: [id]) members ProjectMember[] @relation("ProjectToProjectMember") assets Asset[] @relation("ProjectToAsset") metadataFields MetadataField[] @relation("ProjectToMetadataField") invites Invite[] @relation("ProjectToInvite") notifications Notification[] @relation("ProjectToNotification") shareLinks ShareLink[] @relation("ProjectToShareLink") collections Collection[] @relation("ProjectToCollection") @@map("projects") @@index([createdAt]) @@index([updatedAt]) } model ProjectMember { id String @id @default(ulid()) role ProjectMemberRole projectId String @map("project_id") project Project @relation("ProjectToProjectMember", fields: [projectId], references: [id], onDelete: Cascade) teamMemberId String @map("team_member_id") teamMember TeamMember @relation("TeamMemberToProjectMember", fields: [teamMemberId], references: [id]) @@map("project_members") @@unique([projectId, teamMemberId], name: "projectIdTeamMemberId") } model ShareLink { id String @id @default(ulid()) name String expireAt DateTime? @map("expire_at") password String? isDisabled Boolean @default(false) @map("is_disabled") defaultSortOrder String? @map("default_sort_order") /// [ShareLinkFieldVisibility] fieldVisibility Json? @map("field_visibility") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") projectId String @map("project_id") project Project @relation("ProjectToShareLink", fields: [projectId], references: [id], onDelete: Cascade) rootFolderId String @unique @map("root_folder_id") rootFolder Asset @relation("ShareLinkToRootFolder", fields: [rootFolderId], references: [id]) creatorId String? @map("creator_id") creator User? @relation("UserToShareLink", fields: [creatorId], references: [id]) @@map("share_links") } model Asset { id String @id @default(ulid()) name String @default("") nameNgram String[] @default([]) @map("name_ngram") type AssetType mediaType String? @map("media_type") fileCount Int @default(0) @map("file_count") sizeByte Int @default(0) @map("size_byte") status AssetStatus transcodeTaskId String? @map("transcode_task_id") /// [MediaInfo] media Json? isDeleted Boolean @default(false) @map("is_deleted") deletedAt DateTime? @map("deleted_at") sortIndex String? @map("sort_index") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") parentId String? @map("parent_id") parent Asset? @relation("AssetChildren", fields: [parentId], references: [id]) children Asset[] @relation("AssetChildren") targetId String? @map("target_id") target Asset? @relation("SymlinkTarget", fields: [targetId], references: [id]) symlinks Asset[] @relation("SymlinkTarget") storageKeyId String? @map("storage_key_id") storageKey StorageKey? @relation(fields: [storageKeyId], references: [id]) metadataValues AssetMetadataValue[] @relation("AssetToMetadataValues") creatorId String? @map("creator_id") creator User? @relation("UserToAsset", fields: [creatorId], references: [id]) taskId String? @map("task_id") task Task? @relation("TaskToAsset", fields: [taskId], references: [id]) projectId String? @map("project_id") project Project? @relation("ProjectToAsset", fields: [projectId], references: [id]) comments AssetComment[] @relation("AssetToComment") commentAttachments AssetCommentAttachment[] @relation("AssetToCommentAttachment") notifications Notification[] @relation("AssetToNotification") embeddings AssetEmbedding[] @relation("AssetToEmbedding") teamRootFolder Team? @relation("TeamToRootFolder") projectRootFolder Project? @relation("ProjectToRootFolder") projectShareRoot Project? @relation("ProjectToShareRoot") shareLinkRootFolder ShareLink? @relation("ShareLinkToRootFolder") agentSessions AgentSession[] @relation("AssetToAgentSession") @@map("assets") @@index([type]) @@index([status]) @@index([createdAt]) @@index([updatedAt]) @@index([sortIndex]) @@index([isDeleted]) @@index([deletedAt]) @@index([name], name: "assets_name_idx") @@index([nameNgram], type: Gin) @@unique([parentId, targetId], name: "parentIdTargetId") } model StorageKey { id String @id @default(ulid()) key String @unique status StorageKeyStatus @default(active) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") assets Asset[] @@map("storage_keys") } model AssetMetadataValue { id String @id @default(ulid()) assetId String @map("asset_id") fieldKey String @map("field_key") // key from MetadataField stringValue String? @map("string_value") numberValue Float? @map("number_value") booleanValue Boolean? @map("boolean_value") jsonValue Json? @map("json_value") dateValue DateTime? @map("date_value") asset Asset @relation("AssetToMetadataValues", fields: [assetId], references: [id], onDelete: Cascade) @@unique([assetId, fieldKey]) @@index([numberValue]) @@index([stringValue]) @@index([booleanValue]) @@index([dateValue]) @@index([jsonValue], type: Gin) @@map("asset_metadata_values") } model AssetComment { id String @id @default(ulid()) message String? /// [AnnotationList] annotation Json? second Float? sessionId String? @map("session_id") session AgentSession? @relation(fields: [sessionId], references: [id], onDelete: SetNull) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") assetId String @map("asset_id") asset Asset @relation("AssetToComment", fields: [assetId], references: [id], onDelete: Cascade) creatorId String? @map("creator_id") creator User? @relation("UserToAssetComment", fields: [creatorId], references: [id]) replyToId String? @map("reply_to_id") replyTo AssetComment? @relation("CommentReplies", fields: [replyToId], references: [id], onDelete: Cascade) replies AssetComment[] @relation("CommentReplies") attachments AssetCommentAttachment[] @relation("CommentToAttachment") @@map("asset_comments") } model AssetCommentAttachment { id String @id @default(ulid()) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") commentId String @map("comment_id") comment AssetComment @relation("CommentToAttachment", fields: [commentId], references: [id], onDelete: Cascade) assetId String @map("asset_id") asset Asset @relation("AssetToCommentAttachment", fields: [assetId], references: [id], onDelete: Cascade) @@map("asset_comment_attachments") } model AssetEmbedding { id String @id @default(ulid()) embedding Unsupported("vector(1536)")? startTime Float? @map("start_time") endTime Float? @map("end_time") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") assetId String @map("asset_id") asset Asset @relation("AssetToEmbedding", fields: [assetId], references: [id], onDelete: Cascade) @@index([embedding], name: "AssetEmbedding_embedding_idx") @@map("asset_embeddings") } model Invite { id String @id @default(ulid()) code String @unique role InviteRole? used Boolean @default(false) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") teamId String @map("team_id") team Team @relation("TeamToInvite", fields: [teamId], references: [id]) projectId String? @map("project_id") project Project? @relation("ProjectToInvite", fields: [projectId], references: [id], onDelete: Cascade) inviterId String @map("inviter_id") inviter User @relation("UserToInvite", fields: [inviterId], references: [id]) @@map("invites") } model MetadataField { id String @id @default(ulid()) key String @unique scope MetadataFieldScope? /// [FieldConfig] config Json? readOnly Boolean @default(false) @map("read_only") aiAutofill Boolean @default(false) @map("ai_autofill") description String @default("") teamId String? @map("team_id") team Team? @relation("TeamToMetadataField", fields: [teamId], references: [id]) projectId String? @map("project_id") project Project? @relation("ProjectToMetadataField", fields: [projectId], references: [id], onDelete: Cascade) @@map("metadata_fields") } model Notification { id String @id @default(ulid()) type NotificationType? createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") teamId String @map("team_id") team Team @relation("TeamToNotification", fields: [teamId], references: [id]) projectId String? @map("project_id") project Project? @relation("ProjectToNotification", fields: [projectId], references: [id], onDelete: Cascade) creatorId String? @map("creator_id") creator User? @relation("UserToCreatedNotification", fields: [creatorId], references: [id]) assetId String? @map("asset_id") asset Asset? @relation("AssetToNotification", fields: [assetId], references: [id], onDelete: Cascade) taskId String? @map("task_id") task Task? @relation("TaskToNotification", fields: [taskId], references: [id]) userId String? @map("user_id") user User? @relation("UserToNotification", fields: [userId], references: [id]) readByMembers TeamMember? @relation("TeamMemberToLastReadNotification") @@map("notifications") } model SystemSettings { id String @id @default(ulid()) key String @unique /// [SystemSettingsValue] value Json? createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@map("system_settings") @@index([key]) } model Task { id String @id @default(ulid()) type TaskType? status TaskStatus @default(pending) name String? total Int? uploaded Int @default(0) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") creatorId String? @map("creator_id") creator User? @relation("UserToTask", fields: [creatorId], references: [id]) assets Asset[] @relation("TaskToAsset") notifications Notification[] @relation("TaskToNotification") @@map("tasks") } model WorkflowTask { id String @id @default(ulid()) uid String @default(uuid()) @db.Uuid teamId String? @map("team_id") projectId String? @map("project_id") assetId String @map("asset_id") type WorkflowTaskType? status WorkflowTaskStatus? /// [WorkflowTaskPayload] payload Json? /// [WorkflowTaskOutput] output Json? heartbeat DateTime? inputTokens Int @default(0) @map("input_tokens") outputTokens Int @default(0) @map("output_tokens") model String? createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@map("workflow_tasks") @@index([status, heartbeat]) @@index([assetId, type]) @@index([teamId]) @@index([projectId]) @@index([type]) } enum AgentType { chat autofill embedding } model Agent { id String @id user User @relation(fields: [id], references: [id], onDelete: Cascade) type AgentType enabled Boolean @default(true) soul String? @db.Text providerId String? @map("provider_id") provider Provider? @relation("ProviderToAgent", fields: [providerId], references: [id], onDelete: SetNull) modelId String? @map("model_id") modelRef Model? @relation("ModelToAgent", fields: [modelId], references: [id], onDelete: SetNull) teamId String @map("team_id") team Team @relation("TeamToAgent", fields: [teamId], references: [id], onDelete: Cascade) /// [AgentConfig] config Json createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") agentSessions AgentSession[] skills AgentSkill[] @@map("agents") } model AgentSkill { id String @id @default(ulid()) agentId String @map("agent_id") agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade) skillId String @map("skill_id") skill Skill @relation(fields: [skillId], references: [id], onDelete: Cascade) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@unique([agentId, skillId]) @@map("agent_skills") } model AgentSession { id String @id @default(ulid()) agentId String @map("agent_id") agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade) userId String? @map("user_id") user User? @relation(fields: [userId], references: [id], onDelete: SetNull) cwd String leafId String? @map("leaf_id") assetId String? @map("asset_id") asset Asset? @relation("AssetToAgentSession", fields: [assetId], references: [id], onDelete: Cascade) userCommentId String? @map("user_comment_id") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") entries AgentSessionEntry[] comments AssetComment[] @@map("agent_sessions") } model AgentSessionEntry { id String @id // Uses ULID generated by pi-coding-agent sessionId String @map("session_id") session AgentSession @relation(fields: [sessionId], references: [id], onDelete: Cascade) /// [PiSessionEntry] entry Json @@map("agent_session_entries") @@index([sessionId]) } model UserMetadata { id String @id @default(ulid()) key String /// [UserMetadataValue] value Json createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") userId String @map("user_id") user User @relation("UserToUserMetadata", fields: [userId], references: [id], onDelete: Cascade) teamId String @map("team_id") team Team @relation("TeamToUserMetadata", fields: [teamId], references: [id], onDelete: Cascade) @@unique([userId, teamId, key], name: "userIdTeamIdKey") @@map("user_metadata") } model Model { id String @id @default(ulid()) modelId String @map("model_id") name String @default("") /// [ModelConfig] config Json createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") providerId String @map("provider_id") provider Provider @relation("ProviderToModel", fields: [providerId], references: [id], onDelete: Cascade) agents Agent[] @relation("ModelToAgent") @@unique([providerId, modelId]) @@map("models") } model Provider { id String @id @default(ulid()) name String isBuiltin Boolean @default(false) @map("is_builtin") /// [ProviderConfig] config Json createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") teamId String @map("team_id") team Team @relation("TeamToProvider", fields: [teamId], references: [id], onDelete: Cascade) models Model[] @relation("ProviderToModel") agents Agent[] @relation("ProviderToAgent") @@unique([teamId, name]) @@map("providers") } model Collection { id String @id @default(ulid()) name String /// [CollectionFilter] filter Json createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") projectId String @map("project_id") project Project @relation("ProjectToCollection", fields: [projectId], references: [id], onDelete: Cascade) creatorId String? @map("creator_id") creator User? @relation("UserToCollection", fields: [creatorId], references: [id]) @@index([projectId, createdAt(sort: Desc)]) @@map("collections") }