评论与评分系统

This commit is contained in:
2025-09-19 22:59:34 +08:00
parent c2d5948301
commit 65e483b626
10 changed files with 279 additions and 11 deletions
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "public"."CircuitModel" ADD COLUMN "brief" TEXT;
@@ -0,0 +1,53 @@
-- CreateTable
CREATE TABLE "public"."Comment" (
"id" TEXT NOT NULL,
"modelId" TEXT NOT NULL,
"authorId" TEXT NOT NULL,
"content" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Comment_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Rating" (
"id" TEXT NOT NULL,
"modelId" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"value" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Rating_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "Comment_modelId_idx" ON "public"."Comment"("modelId");
-- CreateIndex
CREATE INDEX "Comment_authorId_idx" ON "public"."Comment"("authorId");
-- CreateIndex
CREATE INDEX "Comment_createdAt_idx" ON "public"."Comment"("createdAt");
-- CreateIndex
CREATE INDEX "Rating_modelId_idx" ON "public"."Rating"("modelId");
-- CreateIndex
CREATE INDEX "Rating_userId_idx" ON "public"."Rating"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "Rating_modelId_userId_key" ON "public"."Rating"("modelId", "userId");
-- AddForeignKey
ALTER TABLE "public"."Comment" ADD CONSTRAINT "Comment_modelId_fkey" FOREIGN KEY ("modelId") REFERENCES "public"."CircuitModel"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Comment" ADD CONSTRAINT "Comment_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Rating" ADD CONSTRAINT "Rating_modelId_fkey" FOREIGN KEY ("modelId") REFERENCES "public"."CircuitModel"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Rating" ADD CONSTRAINT "Rating_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+36
View File
@@ -19,6 +19,8 @@ model User {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
models CircuitModel[]
comments Comment[]
ratings Rating[]
}
model CircuitModel {
@@ -27,12 +29,46 @@ model CircuitModel {
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId String
desc String // markdown
brief String? // short summary for listings
model Json // JSON model data
preview Bytes? // binary preview image
previewMime String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
comments Comment[]
ratings Rating[]
@@index([authorId])
@@index([createdAt])
}
model Comment {
id String @id @default(cuid())
model CircuitModel @relation(fields: [modelId], references: [id], onDelete: Cascade)
modelId String
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([modelId])
@@index([authorId])
@@index([createdAt])
}
model Rating {
id String @id @default(cuid())
model CircuitModel @relation(fields: [modelId], references: [id], onDelete: Cascade)
modelId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
value Int // 1-5
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([modelId, userId])
@@index([modelId])
@@index([userId])
}
+1 -1
View File
@@ -37,7 +37,7 @@ async function main() {
data: {
title: s.title,
desc: s.desc,
model: s.model as any,
model: s.model,
preview: tinyPng,
previewMime: 'image/png',
authorId: user.id,