2026-07-15 18:06:20 +08:00

42 lines
1.7 KiB
SQL

-- CreateTable
CREATE TABLE "NotificationDelivery" (
"id" TEXT NOT NULL PRIMARY KEY,
"projectCode" TEXT NOT NULL,
"idempotencyKey" TEXT NOT NULL,
"requestHash" TEXT NOT NULL,
"recipientUserId" TEXT NOT NULL,
"businessTitle" TEXT NOT NULL,
"renderedTitle" TEXT NOT NULL,
"content" TEXT NOT NULL,
"actionTitle" TEXT NOT NULL,
"actionUrl" TEXT NOT NULL,
"status" TEXT NOT NULL DEFAULT 'pending',
"attemptCount" INTEGER NOT NULL DEFAULT 0,
"maxAttempts" INTEGER NOT NULL DEFAULT 4,
"nextAttemptAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"leaseOwner" TEXT,
"leaseExpiresAt" DATETIME,
"processQueryKey" TEXT,
"lastErrorCode" TEXT,
"lastErrorMessage" TEXT,
"sentAt" DATETIME,
"readAt" DATETIME,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
CREATE TABLE "RequestNonce" (
"id" TEXT NOT NULL PRIMARY KEY,
"projectCode" TEXT NOT NULL,
"nonce" TEXT NOT NULL,
"expiresAt" DATETIME NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX "NotificationDelivery_projectCode_idempotencyKey_key" ON "NotificationDelivery"("projectCode", "idempotencyKey");
CREATE INDEX "NotificationDelivery_status_nextAttemptAt_idx" ON "NotificationDelivery"("status", "nextAttemptAt");
CREATE INDEX "NotificationDelivery_leaseExpiresAt_idx" ON "NotificationDelivery"("leaseExpiresAt");
CREATE INDEX "NotificationDelivery_processQueryKey_idx" ON "NotificationDelivery"("processQueryKey");
CREATE UNIQUE INDEX "RequestNonce_projectCode_nonce_key" ON "RequestNonce"("projectCode", "nonce");
CREATE INDEX "RequestNonce_expiresAt_idx" ON "RequestNonce"("expiresAt");