Files
agent-park/prisma/schema.prisma
T
mzaxdandClaude ab82de3af3 refactor: Prisma schema 添加显式 ProjectTag 关联表并优化索引
- 将 Project-Tag 多对多关系改为显式 ProjectTag 中间表
- 为 ExternalLink 添加 url 索引和 type+url 复合索引
- 添加 projectId+url 唯一约束防止重复链接

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-04 15:16:22 +08:00

104 lines
2.3 KiB
Plaintext

// 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"
previewFeatures = ["postgresqlExtensions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// ================================
// Enums
// ================================
enum ProjectStatus {
ACTIVE
ARCHIVED
}
enum LinkType {
WEBSITE
GITHUB
HUGGINGFACE
PAPER
}
// ================================
// Models
// ================================
model Project {
id String @id @default(cuid())
name String
nameEn String?
slug String @unique
description String
descriptionEn String?
content String? @db.Text
contentEn String? @db.Text
status ProjectStatus @default(ACTIVE)
source String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
tags ProjectTag[]
links ExternalLink[]
// Indexes
@@index([status, createdAt], map: "idx_project_status_createdAt")
@@index([slug], map: "idx_project_slug")
@@map("projects")
}
model Tag {
id String @id @default(cuid())
name String @unique
nameEn String?
slug String @unique
createdAt DateTime @default(now())
// Relations
projects ProjectTag[]
// Indexes
@@index([slug], map: "idx_tag_slug")
@@map("tags")
}
model ExternalLink {
id String @id @default(cuid())
type LinkType
url String
title String?
projectId String
// Relations
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
// Indexes
@@index([projectId], map: "idx_link_projectId")
@@index([type], map: "idx_link_type")
@@index([url], map: "idx_link_url")
@@index([type, url], map: "idx_link_type_url")
@@unique([projectId, url])
@@map("external_links")
}
// Project-Tag many-to-many relationship table
model ProjectTag {
projectId String
tagId String
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
@@id([projectId, tagId])
@@index([tagId])
@@map("project_tags")
}