Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Warnings:

- You are about to drop the column `bearishSummary` on the `Post` table. All the data in the column will be lost.
- You are about to drop the column `bullishSummary` on the `Post` table. All the data in the column will be lost.
- You are about to drop the column `neutralSummary` on the `Post` table. All the data in the column will be lost.
- You are about to drop the column `title` on the `Post` table. All the data in the column will be lost.
- You are about to drop the column `totalSubposts` on the `Post` table. All the data in the column will be lost.
- You are about to drop the `Subpost` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `content` to the `Post` table without a default value. This is not possible if the table is not empty.
- Added the required column `postGroupId` to the `Post` table without a default value. This is not possible if the table is not empty.
- Added the required column `sentiment` to the `Post` table without a default value. This is not possible if the table is not empty.
- Added the required column `source` to the `Post` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `Post` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "public"."Subpost" DROP CONSTRAINT "Subpost_postId_fkey";

-- AlterTable - Step 1: Add new columns as nullable first
ALTER TABLE "public"."Post"
ADD COLUMN "categories" TEXT[] DEFAULT ARRAY[]::TEXT[],
ADD COLUMN "content" TEXT,
ADD COLUMN "createdAt" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "link" TEXT,
ADD COLUMN "postGroupId" TEXT,
ADD COLUMN "sentiment" "public"."Sentiment",
ADD COLUMN "source" "public"."Source",
ADD COLUMN "subcategories" TEXT[] DEFAULT ARRAY[]::TEXT[],
ADD COLUMN "updatedAt" TIMESTAMP(3);

-- Step 2: Backfill data for new columns
UPDATE "public"."Post" SET
"content" = COALESCE("title", 'Migrated content'),
"sentiment" = 'NEUTRAL',
"source" = 'REDDIT',
"updatedAt" = CURRENT_TIMESTAMP,
"createdAt" = COALESCE("createdAt", CURRENT_TIMESTAMP)
WHERE "content" IS NULL;

-- Step 3: Set NOT NULL constraints after backfill
ALTER TABLE "public"."Post"
ALTER COLUMN "content" SET NOT NULL,
ALTER COLUMN "createdAt" SET NOT NULL,
ALTER COLUMN "sentiment" SET NOT NULL,
ALTER COLUMN "source" SET NOT NULL,
ALTER COLUMN "updatedAt" SET NOT NULL;

-- Step 4: Drop old columns
ALTER TABLE "public"."Post"
DROP COLUMN "bearishSummary",
DROP COLUMN "bullishSummary",
DROP COLUMN "neutralSummary",
DROP COLUMN "title",
DROP COLUMN "totalSubposts";

-- DropTable
DROP TABLE "public"."Subpost";

-- CreateTable
CREATE TABLE "public"."PostGroup" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"totalSubposts" INTEGER NOT NULL DEFAULT 0,
"bullishSummary" TEXT,
"bearishSummary" TEXT,
"neutralSummary" TEXT,

CONSTRAINT "PostGroup_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "public"."Post" ADD CONSTRAINT "Post_postGroupId_fkey" FOREIGN KEY ("postGroupId") REFERENCES "public"."PostGroup"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:

- You are about to drop the column `totalSubposts` on the `PostGroup` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "public"."PostGroup" DROP COLUMN "totalSubposts",
ADD COLUMN "totalposts" INTEGER NOT NULL DEFAULT 0;
14 changes: 7 additions & 7 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ enum Source {
FARCASTER
}

model Post {
id String @id @default(uuid())
model PostGroup {
id String @id @default(uuid())
title String
subposts Subpost[]
totalSubposts Int @default(0)
posts Post[]
totalposts Int @default(0)
bullishSummary String?
bearishSummary String?
neutralSummary String?
}

model Subpost {
model Post {
id String @id @default(uuid())
content String
sentiment Sentiment
source Source
categories String[] @default([])
subcategories String[] @default([])
link String?
postId String
post Post @relation(fields: [postId], references: [id])
postGroupId String
postGroup PostGroup @relation(fields: [postGroupId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
22 changes: 11 additions & 11 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const prisma = new PrismaClient();

async function main() {
// Delete existing data to prevent stacking
await prisma.subpost.deleteMany({});
await prisma.post.deleteMany({});
await prisma.postGroup.deleteMany({});
await prisma.user.deleteMany({});
// Seed Users

const MAX_USERS = 5;
const MAX_POSTS = 10;
const MIN_SUBPOSTS = 5;
const MAX_SUBPOSTS = 20;
const MAX_POSTGROUP = 10;
const MIN_POSTS = 5;
const MAX_POSTS = 20;

for (let i = 0; i < MAX_USERS; i++) {
await prisma.user.create({
Expand All @@ -31,19 +31,19 @@ async function main() {
});
}

// Seed Posts with Subposts
for (let i = 0; i < MAX_POSTS; i++) {
const subpostCount = faker.number.int({ min: MIN_SUBPOSTS, max: MAX_SUBPOSTS });
await prisma.post.create({
// Seed PostGroups with Posts
for (let i = 0; i < MAX_POSTGROUP; i++) {
const postCount = faker.number.int({ min: MIN_POSTS, max: MAX_POSTS });
await prisma.postGroup.create({
data: {
title: faker.lorem.sentence(),
bullishSummary: faker.helpers.maybe(() => faker.lorem.paragraph(), { probability: 0.7 }),
bearishSummary: faker.helpers.maybe(() => faker.lorem.paragraph(), { probability: 0.7 }),
neutralSummary: faker.helpers.maybe(() => faker.lorem.paragraph(), { probability: 0.7 }),
totalSubposts: subpostCount,
subposts: {
totalposts: postCount,
posts: {
createMany: {
data: Array.from({ length: subpostCount }).map(() => ({
data: Array.from({ length: postCount }).map(() => ({
content: faker.lorem.paragraph({ min: 3, max: 5 }),
sentiment: faker.helpers.arrayElement([
Sentiment.BULLISH,
Expand Down
Loading