Files
awesome-chatgpt-prompts-pro…/prisma/schema.prisma
Fatih Kadir Akın 85a5f3bed7 Initialize v2 work
2025-12-10 15:41:23 +03:00

314 lines
7.9 KiB
Plaintext

// Prisma schema for prompts.chat
// https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// ============================================
// User & Authentication
// ============================================
enum UserRole {
ADMIN
USER
}
model User {
id String @id @default(cuid())
email String @unique
username String @unique
name String?
password String? // For credentials auth
avatar String?
role UserRole @default(USER)
locale String @default("en")
emailVerified DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
prompts Prompt[] @relation("PromptAuthor")
contributions Prompt[] @relation("PromptContributors")
promptVersions PromptVersion[]
changeRequests ChangeRequest[]
accounts Account[]
sessions Session[]
subscriptions CategorySubscription[]
votes PromptVote[]
pinnedPrompts PinnedPrompt[]
@@map("users")
}
model Account {
id String @id @default(cuid())
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?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map("accounts")
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("sessions")
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
@@map("verification_tokens")
}
// ============================================
// Prompts & Content
// ============================================
enum PromptType {
TEXT
IMAGE
VIDEO
AUDIO
STRUCTURED
}
enum StructuredFormat {
JSON
YAML
}
enum ChangeRequestStatus {
PENDING
APPROVED
REJECTED
}
enum RequiredMediaType {
IMAGE
VIDEO
DOCUMENT
}
model Prompt {
id String @id @default(cuid())
title String
description String?
content String @db.Text
type PromptType @default(TEXT)
structuredFormat StructuredFormat? // For STRUCTURED type: JSON or YAML
isPrivate Boolean @default(false)
mediaUrl String? // For non-text prompts
// Media requirements (user needs to upload media to use this prompt)
requiresMediaUpload Boolean @default(false)
requiredMediaType RequiredMediaType?
requiredMediaCount Int?
// Metadata
viewCount Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
authorId String
author User @relation("PromptAuthor", fields: [authorId], references: [id], onDelete: Cascade)
categoryId String?
category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
versions PromptVersion[]
changeRequests ChangeRequest[]
tags PromptTag[]
votes PromptVote[]
contributors User[] @relation("PromptContributors")
pinnedBy PinnedPrompt[]
@@index([authorId])
@@index([categoryId])
@@index([type])
@@index([isPrivate])
@@map("prompts")
}
model PromptVersion {
id String @id @default(cuid())
version Int
content String @db.Text
changeNote String?
createdAt DateTime @default(now())
// Relations
promptId String
prompt Prompt @relation(fields: [promptId], references: [id], onDelete: Cascade)
createdBy String
author User @relation(fields: [createdBy], references: [id], onDelete: Cascade)
@@unique([promptId, version])
@@index([promptId])
@@map("prompt_versions")
}
model ChangeRequest {
id String @id @default(cuid())
originalContent String @db.Text
originalTitle String
proposedContent String @db.Text
proposedTitle String?
reason String?
status ChangeRequestStatus @default(PENDING)
reviewNote String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
promptId String
prompt Prompt @relation(fields: [promptId], references: [id], onDelete: Cascade)
authorId String
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
@@index([promptId])
@@index([authorId])
@@index([status])
@@map("change_requests")
}
// ============================================
// Categories & Tags
// ============================================
model Category {
id String @id @default(cuid())
name String
slug String @unique
description String?
icon String?
order Int @default(0)
// Self-referential for hierarchy
parentId String?
parent Category? @relation("CategoryHierarchy", fields: [parentId], references: [id], onDelete: SetNull)
children Category[] @relation("CategoryHierarchy")
prompts Prompt[]
subscribers CategorySubscription[]
@@index([parentId])
@@map("categories")
}
model Tag {
id String @id @default(cuid())
name String @unique
slug String @unique
color String @default("#6366f1")
prompts PromptTag[]
@@map("tags")
}
model PromptTag {
promptId String
tagId String
prompt Prompt @relation(fields: [promptId], references: [id], onDelete: Cascade)
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
@@id([promptId, tagId])
@@map("prompt_tags")
}
// ============================================
// Subscriptions
// ============================================
model CategorySubscription {
userId String
categoryId String
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
@@id([userId, categoryId])
@@index([userId])
@@index([categoryId])
@@map("category_subscriptions")
}
model PromptVote {
userId String
promptId String
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
prompt Prompt @relation(fields: [promptId], references: [id], onDelete: Cascade)
@@id([userId, promptId])
@@index([userId])
@@index([promptId])
@@map("prompt_votes")
}
model PinnedPrompt {
userId String
promptId String
order Int @default(0)
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
prompt Prompt @relation(fields: [promptId], references: [id], onDelete: Cascade)
@@id([userId, promptId])
@@index([userId])
@@map("pinned_prompts")
}
// ============================================
// Webhook Integration
// ============================================
enum WebhookEvent {
PROMPT_CREATED
PROMPT_UPDATED
PROMPT_DELETED
}
model WebhookConfig {
id String @id @default(cuid())
name String // e.g. "Slack Notifications"
url String // Webhook URL
method String @default("POST") // HTTP method
headers Json? // Custom headers as JSON object
payload String @db.Text // JSON template with placeholders
events WebhookEvent[] // Which events trigger this webhook
isEnabled Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("webhook_configs")
}