forked from wishonia/wishonia
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add comprehensive article management schema
This migration introduces a new schema for managing articles, categories, tags, sources, search results, generation options, and comments. It includes enums for status, visibility, and comment status, along with necessary foreign key constraints and indexes for efficient querying.
- Loading branch information
Showing
3 changed files
with
306 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
prisma/migrations/20240905205856_articles/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
-- CreateEnum | ||
CREATE TYPE "ArticleStatus" AS ENUM ('DRAFT', 'PENDING', 'PRIVATE', 'PUBLISH'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "ArticleVisibility" AS ENUM ('PUBLIC', 'PASSWORD_PROTECTED', 'PRIVATE'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "ArticleCommentStatus" AS ENUM ('OPEN', 'CLOSED'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Article" ( | ||
"id" SERIAL NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"slug" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"content" TEXT NOT NULL, | ||
"status" "ArticleStatus" NOT NULL DEFAULT 'DRAFT', | ||
"visibility" "ArticleVisibility" NOT NULL DEFAULT 'PUBLIC', | ||
"password" TEXT, | ||
"publishedAt" TIMESTAMP(3), | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"deletedAt" TIMESTAMP(3), | ||
"commentStatus" "ArticleCommentStatus" NOT NULL DEFAULT 'OPEN', | ||
"sticky" BOOLEAN NOT NULL DEFAULT false, | ||
"featuredImage" TEXT, | ||
"promptedTopic" TEXT, | ||
"userId" TEXT NOT NULL, | ||
"categoryId" TEXT NOT NULL, | ||
|
||
CONSTRAINT "Article_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ArticleCategory" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"slug" TEXT NOT NULL, | ||
"description" TEXT, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"deletedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "ArticleCategory_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ArticleTag" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"slug" TEXT NOT NULL, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"deletedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "ArticleTag_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ArticleSource" ( | ||
"id" TEXT NOT NULL, | ||
"url" TEXT NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"description" TEXT, | ||
"articleId" INTEGER NOT NULL, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"deletedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "ArticleSource_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ArticleSearchResult" ( | ||
"id" TEXT NOT NULL, | ||
"score" DOUBLE PRECISION NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"url" TEXT NOT NULL, | ||
"publishedDate" TIMESTAMP(3), | ||
"author" TEXT, | ||
"text" TEXT NOT NULL, | ||
"articleId" INTEGER NOT NULL, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"deletedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "ArticleSearchResult_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ArticleGenerationOptions" ( | ||
"id" TEXT NOT NULL, | ||
"numberOfSearchQueryVariations" INTEGER NOT NULL, | ||
"numberOfWebResultsToInclude" INTEGER NOT NULL, | ||
"audience" TEXT NOT NULL, | ||
"purpose" TEXT NOT NULL, | ||
"maxCharactersOfSearchContentToUse" INTEGER NOT NULL, | ||
"tone" TEXT NOT NULL, | ||
"format" TEXT NOT NULL, | ||
"articleId" INTEGER NOT NULL, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"deletedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "ArticleGenerationOptions_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ArticleComment" ( | ||
"id" TEXT NOT NULL, | ||
"content" TEXT NOT NULL, | ||
"articleId" INTEGER NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"deletedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "ArticleComment_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "_ArticleToArticleTag" ( | ||
"A" INTEGER NOT NULL, | ||
"B" TEXT NOT NULL | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Article_slug_key" ON "Article"("slug"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ArticleCategory_name_key" ON "ArticleCategory"("name"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ArticleCategory_slug_key" ON "ArticleCategory"("slug"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ArticleTag_name_key" ON "ArticleTag"("name"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ArticleTag_slug_key" ON "ArticleTag"("slug"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ArticleGenerationOptions_articleId_key" ON "ArticleGenerationOptions"("articleId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "_ArticleToArticleTag_AB_unique" ON "_ArticleToArticleTag"("A", "B"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "_ArticleToArticleTag_B_index" ON "_ArticleToArticleTag"("B"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Article" ADD CONSTRAINT "Article_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Article" ADD CONSTRAINT "Article_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "ArticleCategory"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ArticleSource" ADD CONSTRAINT "ArticleSource_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "Article"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ArticleSearchResult" ADD CONSTRAINT "ArticleSearchResult_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "Article"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ArticleGenerationOptions" ADD CONSTRAINT "ArticleGenerationOptions_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "Article"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ArticleComment" ADD CONSTRAINT "ArticleComment_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "Article"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ArticleComment" ADD CONSTRAINT "ArticleComment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_ArticleToArticleTag" ADD CONSTRAINT "_ArticleToArticleTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Article"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_ArticleToArticleTag" ADD CONSTRAINT "_ArticleToArticleTag_B_fkey" FOREIGN KEY ("B") REFERENCES "ArticleTag"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters