Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
feat: cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
NotHydra committed Feb 18, 2024
1 parent 81da52e commit 69789be
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
35 changes: 35 additions & 0 deletions apps/api/prisma/migrations/20240218011237_cascade/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- DropForeignKey
ALTER TABLE "Feedback" DROP CONSTRAINT "Feedback_reportId_fkey";

-- DropForeignKey
ALTER TABLE "History" DROP CONSTRAINT "History_subTrashBinId_fkey";

-- DropForeignKey
ALTER TABLE "Report" DROP CONSTRAINT "Report_trashBinId_fkey";

-- DropForeignKey
ALTER TABLE "Report" DROP CONSTRAINT "Report_userId_fkey";

-- DropForeignKey
ALTER TABLE "SubTrashBin" DROP CONSTRAINT "SubTrashBin_trashBinId_fkey";

-- DropForeignKey
ALTER TABLE "Trash" DROP CONSTRAINT "Trash_subTrashBinId_fkey";

-- AddForeignKey
ALTER TABLE "SubTrashBin" ADD CONSTRAINT "SubTrashBin_trashBinId_fkey" FOREIGN KEY ("trashBinId") REFERENCES "TrashBin"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Trash" ADD CONSTRAINT "Trash_subTrashBinId_fkey" FOREIGN KEY ("subTrashBinId") REFERENCES "SubTrashBin"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "History" ADD CONSTRAINT "History_subTrashBinId_fkey" FOREIGN KEY ("subTrashBinId") REFERENCES "SubTrashBin"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Report" ADD CONSTRAINT "Report_trashBinId_fkey" FOREIGN KEY ("trashBinId") REFERENCES "TrashBin"("id") ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "Feedback" ADD CONSTRAINT "Feedback_reportId_fkey" FOREIGN KEY ("reportId") REFERENCES "Report"("id") ON DELETE CASCADE ON UPDATE CASCADE;
12 changes: 6 additions & 6 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ model TrashBin {
model SubTrashBin {
id Int @id @default(autoincrement())
trashBinId Int
trashBin TrashBin? @relation(fields: [trashBinId], references: [id])
trashBin TrashBin? @relation(fields: [trashBinId], references: [id], onDelete: Cascade)
name String
maxCapacity Float @default(0)
currentCapacity Float @default(0)
Expand All @@ -55,14 +55,14 @@ model SubTrashBin {
model Trash {
id Int @id @default(autoincrement())
subTrashBinId Int
subTrashBin SubTrashBin? @relation(fields: [subTrashBinId], references: [id])
subTrashBin SubTrashBin? @relation(fields: [subTrashBinId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
}

model History {
id Int @id @default(autoincrement())
subTrashBinId Int
subTrashBin SubTrashBin? @relation(fields: [subTrashBinId], references: [id])
subTrashBin SubTrashBin? @relation(fields: [subTrashBinId], references: [id], onDelete: Cascade)
maxCapacity Float
currentCapacity Float
createdAt DateTime @default(now())
Expand All @@ -71,9 +71,9 @@ model History {
model Report {
id Int @id @default(autoincrement())
trashBinId Int
trashBin TrashBin? @relation(fields: [trashBinId], references: [id])
trashBin TrashBin? @relation(fields: [trashBinId], references: [id], onDelete: Cascade)
userId Int?
user User? @relation(fields: [userId], references: [id])
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
nik String
name String
phoneNumber String
Expand All @@ -96,7 +96,7 @@ enum Status {
model Feedback {
id Int @id @default(autoincrement())
reportId Int
report Report? @relation(fields: [reportId], references: [id])
report Report? @relation(fields: [reportId], references: [id], onDelete: Cascade)
title String
description String
createdAt DateTime @default(now())
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/model/trash-bin/trash-bin.rest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@base_url = {{$dotenv URL}}/api
@url={{base_url}}/trash
@url={{base_url}}/trash-bin

GET {{url}}

Expand Down

0 comments on commit 69789be

Please sign in to comment.