fix: decduck's code review

This commit is contained in:
DecDuck
2025-03-10 11:39:45 +11:00
parent 31aaec74af
commit 1ce707788d
17 changed files with 274 additions and 94 deletions

View File

@ -0,0 +1,52 @@
/*
Warnings:
- You are about to drop the `news` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "news" DROP CONSTRAINT "news_authorId_fkey";
-- DropTable
DROP TABLE "news";
-- CreateTable
CREATE TABLE "Tag" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
CONSTRAINT "Tag_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Article" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT NOT NULL,
"content" TEXT NOT NULL,
"image" TEXT,
"publishedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"authorId" TEXT,
CONSTRAINT "Article_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "_ArticleToTag" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_ArticleToTag_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE INDEX "_ArticleToTag_B_index" ON "_ArticleToTag"("B");
-- AddForeignKey
ALTER TABLE "Article" ADD CONSTRAINT "Article_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_ArticleToTag" ADD CONSTRAINT "_ArticleToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Article"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_ArticleToTag" ADD CONSTRAINT "_ArticleToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "Tag"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[name]` on the table `Tag` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "Tag_name_key" ON "Tag"("name");

View File

@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[token]` on the table `APIToken` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "APIToken_token_key" ON "APIToken"("token");

View File

@ -29,7 +29,7 @@ enum APITokenMode {
model APIToken {
id String @id @default(uuid())
token String @default(uuid())
token String @default(uuid()) @unique
mode APITokenMode
name String

View File

@ -1,13 +1,21 @@
model News {
id String @id @default(uuid())
title String
content String @db.Text
excerpt String
tags String[]
image String?
publishedAt DateTime @default(now())
author User @relation(fields: [authorId], references: [id])
authorId String
model Tag {
id String @id @default(uuid())
name String @unique
@@map("news")
}
articles Article[]
}
model Article {
id String @id @default(uuid())
title String
description String
content String @db.Text
tags Tag[]
image String? // Object ID
publishedAt DateTime @default(now())
author User? @relation(fields: [authorId], references: [id]) // Optional, if no user, it's a system post
authorId String?
}

View File

@ -6,7 +6,7 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["prismaSchemaFolder", "omitApi"]
previewFeatures = ["prismaSchemaFolder", "omitApi", "fullTextSearchPostgres"]
}
datasource db {

View File

@ -11,7 +11,7 @@ model User {
clients Client[]
notifications Notification[]
collections Collection[]
news News[]
articles Article[]
tokens APIToken[]
}