Skip to content

Commit 098b81b

Browse files
authored
Add Subpost model and one-to-many relation to Post in Prisma schema (#18)
* feat: Add Subpost model and update Post model to include subposts * refactor: Simplify Post and Subpost models by removing redundant fields and restructuring * feat: Update Post and Subpost models by dropping redundant columns and adding new fields
1 parent b9abda0 commit 098b81b

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- CreateTable
2+
CREATE TABLE "public"."Subpost" (
3+
"id" TEXT NOT NULL,
4+
"content" TEXT NOT NULL,
5+
"postId" TEXT NOT NULL,
6+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
7+
"updatedAt" TIMESTAMP(3) NOT NULL,
8+
9+
CONSTRAINT "Subpost_pkey" PRIMARY KEY ("id")
10+
);
11+
12+
-- AddForeignKey
13+
ALTER TABLE "public"."Subpost" ADD CONSTRAINT "Subpost_postId_fkey" FOREIGN KEY ("postId") REFERENCES "public"."Post"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `categories` on the `Post` table. All the data in the column will be lost.
5+
- You are about to drop the column `content` on the `Post` table. All the data in the column will be lost.
6+
- You are about to drop the column `createdAt` on the `Post` table. All the data in the column will be lost.
7+
- You are about to drop the column `sentiment` on the `Post` table. All the data in the column will be lost.
8+
- You are about to drop the column `source` on the `Post` table. All the data in the column will be lost.
9+
- You are about to drop the column `subcategories` on the `Post` table. All the data in the column will be lost.
10+
- You are about to drop the column `updatedAt` on the `Post` table. All the data in the column will be lost.
11+
- Added the required column `sentiment` to the `Subpost` table without a default value. This is not possible if the table is not empty.
12+
- Added the required column `source` to the `Subpost` table without a default value. This is not possible if the table is not empty.
13+
14+
*/
15+
-- DropIndex
16+
DROP INDEX "public"."Post_categories_idx";
17+
18+
-- DropIndex
19+
DROP INDEX "public"."Post_subcategories_idx";
20+
21+
-- AlterTable
22+
ALTER TABLE "public"."Post" DROP COLUMN "categories",
23+
DROP COLUMN "content",
24+
DROP COLUMN "createdAt",
25+
DROP COLUMN "sentiment",
26+
DROP COLUMN "source",
27+
DROP COLUMN "subcategories",
28+
DROP COLUMN "updatedAt",
29+
ADD COLUMN "bearishSummary" TEXT,
30+
ADD COLUMN "bullishSummary" TEXT,
31+
ADD COLUMN "neutralSummary" TEXT,
32+
ADD COLUMN "totalSubposts" INTEGER NOT NULL DEFAULT 0;
33+
34+
-- AlterTable
35+
ALTER TABLE "public"."Subpost" ADD COLUMN "categories" TEXT[] DEFAULT ARRAY[]::TEXT[],
36+
ADD COLUMN "link" TEXT,
37+
ADD COLUMN "sentiment" "public"."Sentiment" NOT NULL,
38+
ADD COLUMN "source" "public"."Source" NOT NULL,
39+
ADD COLUMN "subcategories" TEXT[] DEFAULT ARRAY[]::TEXT[];

prisma/schema.prisma

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ datasource db {
1616
model User {
1717
id String @id @default(uuid())
1818
walletAddress String? @unique
19-
email String? @unique
19+
email String? @unique
2020
name String?
2121
password String?
2222
role Role @default(USER)
@@ -49,16 +49,25 @@ enum Source {
4949
}
5050

5151
model Post {
52+
id String @id @default(uuid())
53+
title String
54+
subposts Subpost[]
55+
totalSubposts Int @default(0)
56+
bullishSummary String?
57+
bearishSummary String?
58+
neutralSummary String?
59+
}
60+
61+
model Subpost {
5262
id String @id @default(uuid())
53-
title String
5463
content String
5564
sentiment Sentiment
5665
source Source
5766
categories String[] @default([])
5867
subcategories String[] @default([])
68+
link String?
69+
postId String
70+
post Post @relation(fields: [postId], references: [id])
5971
createdAt DateTime @default(now())
6072
updatedAt DateTime @updatedAt
61-
62-
@@index([categories], type: Gin)
63-
@@index([subcategories], type: Gin)
6473
}

0 commit comments

Comments
 (0)