fix: make SMS retry side effects idempotent
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
ALTER TABLE "SmsSubmitRecord"
|
||||
ADD COLUMN "retryOfSubmitRecordId" TEXT;
|
||||
|
||||
CREATE UNIQUE INDEX "SmsSubmitRecord_retryOfSubmitRecordId_key"
|
||||
ON "SmsSubmitRecord"("retryOfSubmitRecordId");
|
||||
|
||||
ALTER TABLE "SmsSubmitRecord"
|
||||
ADD CONSTRAINT "SmsSubmitRecord_retryOfSubmitRecordId_fkey"
|
||||
FOREIGN KEY ("retryOfSubmitRecordId") REFERENCES "SmsSubmitRecord"("id")
|
||||
ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "AccountTransaction"
|
||||
ADD COLUMN "idempotencyKey" TEXT;
|
||||
|
||||
CREATE UNIQUE INDEX "AccountTransaction_idempotencyKey_key"
|
||||
ON "AccountTransaction"("idempotencyKey");
|
||||
|
||||
ALTER TABLE "CmppDownstreamDelivery"
|
||||
ADD COLUMN "dedupeKey" TEXT;
|
||||
|
||||
WITH ranked_receipts AS (
|
||||
SELECT id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY "messageRecordId", "deliveryType"
|
||||
ORDER BY "createdAt", id
|
||||
) AS row_number
|
||||
FROM "CmppDownstreamDelivery"
|
||||
WHERE "messageRecordId" IS NOT NULL
|
||||
AND "deliveryType" = 'receipt'
|
||||
)
|
||||
UPDATE "CmppDownstreamDelivery" AS delivery
|
||||
SET "dedupeKey" = 'receipt:' || delivery."messageRecordId"
|
||||
FROM ranked_receipts
|
||||
WHERE delivery.id = ranked_receipts.id
|
||||
AND ranked_receipts.row_number = 1;
|
||||
|
||||
CREATE UNIQUE INDEX "CmppDownstreamDelivery_dedupeKey_key"
|
||||
ON "CmppDownstreamDelivery"("dedupeKey");
|
||||
Reference in New Issue
Block a user