Skip to content

fix: add database indexes to segment-destination-config entity - #1368

Open
MRTEEworld02 wants to merge 3 commits into
rinafcode:mainfrom
MRTEEworld02:fix/issue-1227-add-database-indexes-to-the-segment-destination
Open

fix: add database indexes to segment-destination-config entity#1368
MRTEEworld02 wants to merge 3 commits into
rinafcode:mainfrom
MRTEEworld02:fix/issue-1227-add-database-indexes-to-the-segment-destination

Conversation

@MRTEEworld02

Copy link
Copy Markdown

Overview

This PR adds database indexes to the segment-destination-config entity so common lookup, filtering, sorting, and foreign-key query paths remain performant as the table grows. The indexes are added directly to the entity and also created through a reviewable migration, avoiding reliance on synchronize for existing databases.

Related Issue

Closes the reported segment-destination-config indexing issue.

Changes

🗄️ Database Indexes

  • [ADD] src/analytics/segment/segment-destination-config.entity.ts

    • Adds a composite @Index on segmentId + destinationId to cover segment-scoped lookups and combined segment/destination lookups.
    • Adds a single-column @Index on destinationId to cover destination foreign-key lookups.
    • Avoids a standalone segmentId index because the composite index prefix already covers that query path.
  • [ADD] src/migrations/1715000000000-add-segment-destination-config-indexes.ts

    • Creates IDX_segment_destination_config_segment_destination on (segment_id, destination_id).
    • Creates IDX_segment_destination_config_destination_id on (destination_id).
    • Runs cleanly against existing databases without requiring synchronize.

Verification Results

Migration check:
✅ 1715000000000-add-segment-destination-config-indexes applied cleanly

Schema check:
✅ Composite index (segment_id, destination_id) present
✅ Destination_id index present
✅ No duplicate/redundant segment_id-only index

Query plan check:
✅ Index scan for WHERE segment_id = $1
✅ Index scan for WHERE segment_id = $1 AND destination_id = $2
✅ Index scan for WHERE destination_id = $1
Acceptance Criteria Status
Entity carries indexes covering common lookup/foreign-key columns ✅ Composite (segmentId, destinationId) plus destinationId index added
Migration creates indexes and runs cleanly on existing database 1715000000000-add-segment-destination-config-indexes runs cleanly
No duplicate/redundant indexes are introduced ✅ Only two non-overlapping indexes; segmentId lookups use the composite prefix

Closes #1227

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

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

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 segment-destination-config entity

2 participants