Migration script, improvements in expenses list

This commit is contained in:
Sebastien Castiel
2023-12-08 14:56:51 -05:00
parent 9cc819b0c9
commit 92a21ff4c5
10 changed files with 511 additions and 37 deletions

View File

@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Expense" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "Group" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

View File

@@ -0,0 +1,17 @@
-- DropForeignKey
ALTER TABLE "Expense" DROP CONSTRAINT "Expense_groupId_fkey";
-- DropForeignKey
ALTER TABLE "Expense" DROP CONSTRAINT "Expense_paidById_fkey";
-- DropForeignKey
ALTER TABLE "ExpensePaidFor" DROP CONSTRAINT "ExpensePaidFor_participantId_fkey";
-- AddForeignKey
ALTER TABLE "Expense" ADD CONSTRAINT "Expense_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "Group"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Expense" ADD CONSTRAINT "Expense_paidById_fkey" FOREIGN KEY ("paidById") REFERENCES "Participant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ExpensePaidFor" ADD CONSTRAINT "ExpensePaidFor_participantId_fkey" FOREIGN KEY ("participantId") REFERENCES "Participant"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -17,6 +17,7 @@ model Group {
currency String @default("$")
participants Participant[]
expenses Expense[]
createdAt DateTime @default(now())
}
model Participant {
@@ -30,19 +31,20 @@ model Participant {
model Expense {
id String @id
group Group @relation(fields: [groupId], references: [id])
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade)
title String
amount Int
paidBy Participant @relation(fields: [paidById], references: [id])
paidBy Participant @relation(fields: [paidById], references: [id], onDelete: Cascade)
paidById String
paidFor ExpensePaidFor[]
groupId String
isReimbursement Boolean @default(false)
createdAt DateTime @default(now())
}
model ExpensePaidFor {
expense Expense @relation(fields: [expenseId], references: [id], onDelete: Cascade)
participant Participant @relation(fields: [participantId], references: [id])
participant Participant @relation(fields: [participantId], references: [id], onDelete: Cascade)
expenseId String
participantId String