diff --git a/backend/prisma/migrations/20260830000000_add_webhook_overdue_invoice_indexes/migration.sql b/backend/prisma/migrations/20260830000000_add_webhook_overdue_invoice_indexes/migration.sql new file mode 100644 index 0000000..4fc00f1 --- /dev/null +++ b/backend/prisma/migrations/20260830000000_add_webhook_overdue_invoice_indexes/migration.sql @@ -0,0 +1,12 @@ +-- Add missing database indexes for the webhook queue, overdue sweep, and +-- merchant invoice list queries. + +-- Webhook queue: the worker polls pending deliveries whose next attempt is due. +CREATE INDEX "webhook_deliveries_status_next_attempt_at_idx" ON "webhook_deliveries"("status", "next_attempt_at"); + +-- Overdue sweep: the daily cron marks pending invoices past their due date as overdue. +CREATE INDEX "invoices_status_due_date_idx" ON "invoices"("status", "due_date"); + +-- Merchant invoice list: the dashboard lists a merchant's non-draft invoices by +-- status, ordered by creation date. +CREATE INDEX "invoices_merchant_id_is_draft_status_created_at_idx" ON "invoices"("merchant_id", "is_draft", "status", "created_at"); diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 45b2042..4e133bd 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -128,6 +128,7 @@ model WebhookDelivery { createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") + @@index([status, nextAttemptAt]) @@map("webhook_deliveries") } @@ -246,6 +247,8 @@ model Invoice { @@index([merchantId]) @@index([isDraft, merchantId]) @@index([lastAutoSavedAt]) + @@index([status, dueDate]) + @@index([merchantId, isDraft, status, createdAt]) @@map("invoices") }