From 900592020fbaa6f31470cf2767f6c707ba1aaa17 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Wed, 25 Oct 2023 01:04:46 +0200 Subject: [PATCH] Add Upload.paid boolean column One item can have multiple images linked to it, but an image can also be used in multiple items (many-to-many relation). Since we don't really care to which item an image is linked and vice versa, we just use a boolean column to mark if an image was already paid for. This makes fee calculation easier since no JOINs are required. --- .../migration.sql | 8 -------- .../20231025000727_upload_paid/migration.sql | 18 ++++++++++++++++++ prisma/schema.prisma | 5 +---- 3 files changed, 19 insertions(+), 12 deletions(-) delete mode 100644 prisma/migrations/20231019162233_item_multiple_uploads/migration.sql create mode 100644 prisma/migrations/20231025000727_upload_paid/migration.sql diff --git a/prisma/migrations/20231019162233_item_multiple_uploads/migration.sql b/prisma/migrations/20231019162233_item_multiple_uploads/migration.sql deleted file mode 100644 index f6cf973b..00000000 --- a/prisma/migrations/20231019162233_item_multiple_uploads/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `uploadId` on the `Item` table. All the data in the column will be lost. - -*/ --- DropIndex -DROP INDEX "Upload.itemId_unique"; diff --git a/prisma/migrations/20231025000727_upload_paid/migration.sql b/prisma/migrations/20231025000727_upload_paid/migration.sql new file mode 100644 index 00000000..fb8976f6 --- /dev/null +++ b/prisma/migrations/20231025000727_upload_paid/migration.sql @@ -0,0 +1,18 @@ +/* + Warnings: + + - You are about to drop the column `itemId` on the `Upload` table. All the data in the column will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "Upload" DROP CONSTRAINT "Upload_itemId_fkey"; + +-- DropIndex +DROP INDEX "Upload.itemId_index"; + +-- DropIndex +DROP INDEX "Upload.itemId_unique"; + +-- AlterTable +ALTER TABLE "Upload" DROP COLUMN "itemId", +ADD COLUMN "paid" BOOLEAN; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 28bb4359..f18acb37 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -176,14 +176,12 @@ model Upload { size Int width Int? height Int? - itemId Int? userId Int - item Item? @relation(fields: [itemId], references: [id]) user User @relation("Uploads", fields: [userId], references: [id], onDelete: Cascade) User User[] + paid Boolean? @@index([createdAt], map: "Upload.created_at_index") - @@index([itemId], map: "Upload.itemId_index") @@index([userId], map: "Upload.userId_index") } @@ -299,7 +297,6 @@ model Item { PollOption PollOption[] PollVote PollVote[] ThreadSubscription ThreadSubscription[] - uploads Upload[] User User[] itemForwards ItemForward[]