diff --git a/prisma/migrations/20231025000727_upload_paid/migration.sql b/prisma/migrations/20231025000727_upload_paid/migration.sql index fb8976f6..e772e5f5 100644 --- a/prisma/migrations/20231025000727_upload_paid/migration.sql +++ b/prisma/migrations/20231025000727_upload_paid/migration.sql @@ -1,18 +1,2 @@ -/* - 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; +ALTER TABLE "Upload" ADD COLUMN "paid" BOOLEAN; diff --git a/prisma/migrations/20231026154807_image_fees_info/migration.sql b/prisma/migrations/20231026154807_image_fees_info/migration.sql index e06fcc3d..c1497a27 100644 --- a/prisma/migrations/20231026154807_image_fees_info/migration.sql +++ b/prisma/migrations/20231026154807_image_fees_info/migration.sql @@ -68,7 +68,6 @@ BEGIN -- add image fees IF upload_ids IS NOT NULL THEN cost_msats := cost_msats + (SELECT "nUnpaid" * "imageFeeMsats" FROM image_fees_info(item."userId", upload_ids)); - UPDATE "Upload" SET paid = 't' WHERE id = ANY(upload_ids); END IF; -- it's only a freebie if it's a 1 sat cost, they have < 1 sat, and boost = 0 @@ -142,6 +141,11 @@ BEGIN UPDATE users SET "bioId" = item.id WHERE id = item."userId"; END IF; + -- we paid for the image fees, so mark them as paid + IF upload_ids IS NOT NULL THEN + UPDATE "Upload" SET paid = 't', "itemId" = item.id WHERE id = ANY(upload_ids); + END IF; + -- schedule imgproxy job INSERT INTO pgboss.job (name, data, retrylimit, retrybackoff, startafter) VALUES ('imgproxy', jsonb_build_object('id', item.id), 21, true, now() + interval '5 seconds'); @@ -172,7 +176,7 @@ BEGIN -- add image fees IF upload_ids IS NOT NULL THEN cost_msats := cost_msats + (SELECT "nUnpaid" * "imageFeeMsats" FROM image_fees_info(item."userId", upload_ids)); - UPDATE "Upload" SET paid = 't' WHERE id = ANY(upload_ids); + UPDATE "Upload" SET paid = 't', "itemId" = item.id WHERE id = ANY(upload_ids); END IF; IF cost_msats > 0 AND cost_msats > user_msats THEN diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f18acb37..f93d3b09 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -176,12 +176,15 @@ model Upload { size Int width Int? height Int? + itemId Int? @unique(map: "Upload.itemId_unique") userId Int + paid Boolean? + 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") } @@ -297,6 +300,7 @@ model Item { PollOption PollOption[] PollVote PollVote[] ThreadSubscription ThreadSubscription[] + upload Upload? User User[] itemForwards ItemForward[]