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>
This commit is contained in:
2026-01-04 15:16:22 +08:00
co-authored by Claude
parent cb667b7321
commit ab82de3af3
+22 -6
View File
@@ -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")
}