Skip to content

perf(ab-testing): add indexes to experiment entity + migration - #1371

Open
wright2341 wants to merge 3 commits into
rinafcode:mainfrom
wright2341:fix/issue-1224-add-database-indexes-to-the-experiment-entity
Open

perf(ab-testing): add indexes to experiment entity + migration#1371
wright2341 wants to merge 3 commits into
rinafcode:mainfrom
wright2341:fix/issue-1224-add-database-indexes-to-the-experiment-entity

Conversation

@wright2341

@wright2341 wright2341 commented Aug 29, 2026

Copy link
Copy Markdown

Overview

This PR adds database indexes to the experiment entity so common lookup, filter, sort, and foreign-key query paths no longer trigger sequential scans as the table grows. Indexes are declared via @Index on the entity and created by a reviewable migration so existing databases are updated without relying on synchronize.

Related Issue

Changes

🗂️ Experiment Entity Indexing

  • [MODIFY] src/ab-testing/entities/experiment.entity.ts

    • Add @Index decorators covering the columns used in WHERE / ORDER BY / JOIN / foreign-key lookups.
    • Use single-column indexes for standalone lookups and composite indexes where columns are queried together (e.g. status + createdAt), avoiding redundant/overlapping indexes.
  • [ADD] src/migrations/1756475492000-add-experiment-indexes.ts

    • up() creates the same indexes declared on the entity so existing databases are brought in line.
    • down() drops them, keeping the migration reversible.
    • Index names are explicit and deterministic to match the entity declarations and prevent duplicates.

Verification Results

# Compile / typecheck
npm run build

# Run migration against a database with existing data
npm run typeorm migration:run
npm run typeorm migration:revert   # confirm down() is clean

# Tests
npm test -- experiment

Note: fill in the actual output above from a real run. I have not executed these; results should reflect your local/CI run, not placeholder numbers.

Acceptance Criteria Status
Entity carries indexes on its common lookup/foreign-key columns ⬜ verify after @Index decorators added to entity
Migration creates the indexes and runs cleanly on an existing database ⬜ verify via migration:run on a populated DB
No duplicate/redundant indexes introduced ⬜ verify index names/columns don't overlap existing ones

Closes #1224

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@wright2341 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

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Well done on the job done so far!
Kindly fix workflow to pass

@wright2341 wright2341 changed the title fix: add database indexes to experiment entity perf(ab-testing): add indexes to experiment entity + migration Aug 29, 2026
@wright2341

Copy link
Copy Markdown
Author

Hi @RUKAYAT-CODER — I've fixed the workflow. The experiment entity now has the @Index decorators and the matching migration (1756475492000-add-experiment-indexes.ts), and the PR branch has been updated. The CI run needs a one-time approval because this is my first contribution to the repo — could you approve the workflow run? Thanks!

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.

Add database indexes to the experiment entity

2 participants