Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[강대원] sprint7 #20

Open
wants to merge 12 commits into
base: express-강대원
Choose a base branch
from
80 changes: 78 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
"author": "KDW",
"license": "ISC",
"dependencies": {
"@prisma/client": "^5.22.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.1",
"mongoose": "^8.7.3"
"mongoose": "^8.7.3",
"prisma": "^5.22.0"
},
"devDependencies": {
"@types/cors": "^2.8.17",
Expand Down
10 changes: 10 additions & 0 deletions prisma/migrations/20241110130539_add_article/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- CreateTable
CREATE TABLE "Article" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"content" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Article_pkey" PRIMARY KEY ("id")
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- CreateTable
CREATE TABLE "MarketComment" (
"id" TEXT NOT NULL,
"content" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "BoardComment" (
"id" TEXT NOT NULL,
"content" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "BoardComment_pkey" PRIMARY KEY ("id")
);
47 changes: 47 additions & 0 deletions prisma/migrations/20241112142438_add_comment_schema/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Warnings:

- Added the required column `articleId` to the `BoardComment` table without a default value. This is not possible if the table is not empty.
- Added the required column `userId` to the `BoardComment` table without a default value. This is not possible if the table is not empty.
- Added the required column `articleId` to the `MarketComment` table without a default value. This is not possible if the table is not empty.
- Added the required column `userId` to the `MarketComment` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "BoardComment" ADD COLUMN "articleId" TEXT NOT NULL,
ADD COLUMN "userId" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "MarketComment" ADD COLUMN "articleId" TEXT NOT NULL,
ADD COLUMN "userId" TEXT NOT NULL;

-- CreateTable
CREATE TABLE "BoardArticle" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"content" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
"nickname" TEXT NOT NULL,

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

-- AddForeignKey
ALTER TABLE "MarketComment" ADD CONSTRAINT "MarketComment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MarketComment" ADD CONSTRAINT "MarketComment_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "Article"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "BoardComment" ADD CONSTRAINT "BoardComment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "BoardComment" ADD CONSTRAINT "BoardComment_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "BoardArticle"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
62 changes: 62 additions & 0 deletions prisma/migrations/20241112150723_fix_comment/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Warnings:

- You are about to drop the `BoardArticle` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `BoardComment` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "BoardComment" DROP CONSTRAINT "BoardComment_articleId_fkey";

-- DropForeignKey
ALTER TABLE "BoardComment" DROP CONSTRAINT "BoardComment_userId_fkey";

-- DropForeignKey
ALTER TABLE "MarketComment" DROP CONSTRAINT "MarketComment_articleId_fkey";

-- DropForeignKey
ALTER TABLE "MarketComment" DROP CONSTRAINT "MarketComment_userId_fkey";

-- AlterTable
ALTER TABLE "MarketComment" ALTER COLUMN "userId" DROP NOT NULL;

-- DropTable
DROP TABLE "BoardArticle";

-- DropTable
DROP TABLE "BoardComment";

-- CreateTable
CREATE TABLE "MarketArticle" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"content" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "ArticleComment" (
"id" TEXT NOT NULL,
"content" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"userId" TEXT,
"articleId" TEXT NOT NULL DEFAULT 'default',

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

-- AddForeignKey
ALTER TABLE "ArticleComment" ADD CONSTRAINT "ArticleComment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ArticleComment" ADD CONSTRAINT "ArticleComment_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "Article"("id") ON DELETE SET DEFAULT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MarketComment" ADD CONSTRAINT "MarketComment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MarketComment" ADD CONSTRAINT "MarketComment_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "MarketArticle"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
18 changes: 18 additions & 0 deletions prisma/migrations/20241112151009_fix_comment/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Warnings:

- Made the column `userId` on table `ArticleComment` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `MarketComment` required. This step will fail if there are existing NULL values in that column.

*/
-- DropForeignKey
ALTER TABLE "MarketComment" DROP CONSTRAINT "MarketComment_userId_fkey";

-- AlterTable
ALTER TABLE "ArticleComment" ALTER COLUMN "userId" SET NOT NULL;

-- AlterTable
ALTER TABLE "MarketComment" ALTER COLUMN "userId" SET NOT NULL;

-- AddForeignKey
ALTER TABLE "MarketComment" ADD CONSTRAINT "MarketComment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
26 changes: 26 additions & 0 deletions prisma/migrations/20241112153016_fix_on_delete/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- DropForeignKey
ALTER TABLE "ArticleComment" DROP CONSTRAINT "ArticleComment_articleId_fkey";

-- DropForeignKey
ALTER TABLE "ArticleComment" DROP CONSTRAINT "ArticleComment_userId_fkey";

-- DropForeignKey
ALTER TABLE "MarketComment" DROP CONSTRAINT "MarketComment_articleId_fkey";

-- DropForeignKey
ALTER TABLE "MarketComment" DROP CONSTRAINT "MarketComment_userId_fkey";

-- AlterTable
ALTER TABLE "ArticleComment" ALTER COLUMN "articleId" DROP DEFAULT;

-- AddForeignKey
ALTER TABLE "ArticleComment" ADD CONSTRAINT "ArticleComment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ArticleComment" ADD CONSTRAINT "ArticleComment_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "Article"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MarketComment" ADD CONSTRAINT "MarketComment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MarketComment" ADD CONSTRAINT "MarketComment_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "MarketArticle"("id") ON DELETE CASCADE ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
72 changes: 72 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Article {
id String @id @default(uuid())
title String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

ArticleComment ArticleComment[]
}

model MarketArticle {
id String @id @default(uuid())
title String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

MarketComment MarketComment[]
}


model User {
id String @id @default(uuid())
nickname String

ArticleComment ArticleComment[]
MarketComment MarketComment[]
}

model ArticleComment {
id String @id @default(uuid())
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String


article Article @relation(fields: [articleId], references: [id], onDelete: Cascade)
articleId String
}


model MarketComment {
id String @id @default(uuid())
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String

marketArticle MarketArticle @relation(fields: [articleId], references: [id], onDelete: Cascade)
articleId String
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모델을 잘 구성해주신것 같아요. 테스트하실때 필요한 시딩이 필요할 수도 있을것 같아요

Loading