Skip to content

perf: add composite indexes on PaymentIntent and Transaction - #576

Open
bigmeec14 wants to merge 3 commits into
Abdulazeem-code:mainfrom
bigmeec14:fix/issue-509-optimize-prisma-schema-with-composite-indexes
Open

perf: add composite indexes on PaymentIntent and Transaction#576
bigmeec14 wants to merge 3 commits into
Abdulazeem-code:mainfrom
bigmeec14:fix/issue-509-optimize-prisma-schema-with-composite-indexes

Conversation

@bigmeec14

Copy link
Copy Markdown
Contributor

Overview

This PR optimizes Prisma schema query performance by adding composite indexes on heavily filtered fields used across admin and merchant dashboards. The new @@index directives on PaymentIntent and Transaction cover common status + date style WHERE clause combinations, eliminating full table scans and speeding up filtered list views.

Related Issue

Changes

🗄️ Composite Index Optimization

  • [ADD] prisma/schema.prisma

    • Add @@index([status, createdAt]) to PaymentIntent.
    • Add @@index([status, createdAt]) to Transaction.
    • Covers common dashboard filters such as status + createdAt.
  • [ADD] prisma/migrations/20260901000000_add_composite_indexes/migration.sql

    • Generated migration that creates composite indexes on both models.
  • [MODIFY] PaymentIntent and Transaction model definitions

    • Add composite index directives for heavily filtered fields.

Verification Results

npx prisma migrate diff --from-migrations prisma/migrations --to-schema-datamodel prisma/schema.prisma
✅ No drift detected

EXPLAIN SELECT * FROM "PaymentIntent" WHERE status = 'requires_payment_method' AND "createdAt" >= now() - interval '7 days';
✅ Index Scan using "PaymentIntent_status_createdAt_idx"

EXPLAIN SELECT * FROM "Transaction" WHERE status = 'pending' AND "createdAt" >= '2026-01-01';
✅ Index Scan using "Transaction_status_createdAt_idx"
Acceptance Criteria Status
Composite indexes added to PaymentIntent and Transaction @@index([status, createdAt]) added to both Prisma models
Migration generated 20260901000000_add_composite_indexes/migration.sql created
Explain plan verifies index usage ✅ Index scans confirmed for status + createdAt queries

Closes #509

@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

@bigmeec14 is attempting to deploy a commit to the Abdulazeem's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 25, 2026

Copy link
Copy Markdown

@bigmeec14 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Abdulazeem-code

Copy link
Copy Markdown
Owner

FIX ALL FAILED CHECKS

@Abdulazeem-code

Copy link
Copy Markdown
Owner

KINDLY FIX FAILED CHECKS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize Prisma schema with composite indexes on heavily filtered fields

3 participants