From ab82de3af39754b7d39d0ccc8360e339b4aa600b Mon Sep 17 00:00:00 2001 From: Caihaohan Date: Sun, 4 Jan 2026 15:16:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20Prisma=20schema=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=98=BE=E5=BC=8F=20ProjectTag=20=E5=85=B3=E8=81=94?= =?UTF-8?q?=E8=A1=A8=E5=B9=B6=E4=BC=98=E5=8C=96=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 Project-Tag 多对多关系改为显式 ProjectTag 中间表 - 为 ExternalLink 添加 url 索引和 type+url 复合索引 - 添加 projectId+url 唯一约束防止重复链接 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- prisma/schema.prisma | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 64a759e..8f2aedf 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -46,7 +46,7 @@ model Project { updatedAt DateTime @updatedAt // Relations - tags Tag[] + tags ProjectTag[] links ExternalLink[] // Indexes @@ -56,14 +56,14 @@ model Project { } model Tag { - id String @id @default(cuid()) - name String @unique + id String @id @default(cuid()) + name String @unique nameEn String? - slug String @unique - createdAt DateTime @default(now()) + slug String @unique + createdAt DateTime @default(now()) // Relations - projects Project[] + projects ProjectTag[] // Indexes @@index([slug], map: "idx_tag_slug") @@ -83,5 +83,21 @@ model ExternalLink { // 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") +}