keep item ids on uploads
This commit is contained in:
parent
17b39d9982
commit
4688962abc
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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[]
|
||||
|
||||
|
|
Loading…
Reference in New Issue