refactor: invoice relation (#2)

* refactor: update database table

* refactor: update invoice to have relation with installments

* chore: add migration
This commit is contained in:
Methapon Metanipat 2024-10-30 17:32:46 +07:00 committed by GitHub
parent ba41bf45cb
commit 824727582d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 106 additions and 163 deletions

View file

@ -0,0 +1,77 @@
/*
Warnings:
- You are about to drop the column `invoice` on the `QuotationPaySplit` table. All the data in the column will be lost.
- You are about to drop the column `invoiceId` on the `QuotationProductServiceList` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "QuotationProductServiceList" DROP CONSTRAINT "QuotationProductServiceList_invoiceId_fkey";
-- AlterTable
ALTER TABLE "QuotationPaySplit" DROP COLUMN "invoice",
ADD COLUMN "invoiceId" TEXT;
-- AlterTable
ALTER TABLE "QuotationProductServiceList" DROP COLUMN "invoiceId";
-- CreateTable
CREATE TABLE "Notification" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"detail" TEXT NOT NULL,
"receiverId" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Notification_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "NotificationGroup" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
CONSTRAINT "NotificationGroup_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "_NotificationToNotificationGroup" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL
);
-- CreateTable
CREATE TABLE "_NotificationToUser" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "_NotificationToNotificationGroup_AB_unique" ON "_NotificationToNotificationGroup"("A", "B");
-- CreateIndex
CREATE INDEX "_NotificationToNotificationGroup_B_index" ON "_NotificationToNotificationGroup"("B");
-- CreateIndex
CREATE UNIQUE INDEX "_NotificationToUser_AB_unique" ON "_NotificationToUser"("A", "B");
-- CreateIndex
CREATE INDEX "_NotificationToUser_B_index" ON "_NotificationToUser"("B");
-- AddForeignKey
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_receiverId_fkey" FOREIGN KEY ("receiverId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "QuotationPaySplit" ADD CONSTRAINT "QuotationPaySplit_invoiceId_fkey" FOREIGN KEY ("invoiceId") REFERENCES "Invoice"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_NotificationToNotificationGroup" ADD CONSTRAINT "_NotificationToNotificationGroup_A_fkey" FOREIGN KEY ("A") REFERENCES "Notification"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_NotificationToNotificationGroup" ADD CONSTRAINT "_NotificationToNotificationGroup_B_fkey" FOREIGN KEY ("B") REFERENCES "NotificationGroup"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_NotificationToUser" ADD CONSTRAINT "_NotificationToUser_A_fkey" FOREIGN KEY ("A") REFERENCES "Notification"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_NotificationToUser" ADD CONSTRAINT "_NotificationToUser_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View file

@ -1194,12 +1194,14 @@ model Quotation {
model QuotationPaySplit {
id String @id @default(cuid())
no Int
amount Float
invoice Boolean @default(false)
no Int
amount Float
quotation Quotation? @relation(fields: [quotationId], references: [id], onDelete: Cascade)
quotationId String?
invoice Invoice? @relation(fields: [invoiceId], references: [id])
invoiceId String?
}
model QuotationWorker {
@ -1238,9 +1240,6 @@ model QuotationProductServiceList {
worker QuotationProductServiceWorker[]
requestWork RequestWork[]
invoice Invoice? @relation(fields: [invoiceId], references: [id])
invoiceId String?
}
model QuotationProductServiceWorker {
@ -1259,7 +1258,7 @@ model Invoice {
quotation Quotation @relation(fields: [quotationId], references: [id])
quotationId String
productServiceList QuotationProductServiceList[]
installments QuotationPaySplit[]
amount Float?