Skip to content

#1244 Add database indexes to consumer-privacy-preference entity - #1407

Open
Emelie-Dev wants to merge 1 commit into
rinafcode:mainfrom
Emelie-Dev:feature/1244-add-consumer-privacy-preference-indexes
Open

#1244 Add database indexes to consumer-privacy-preference entity#1407
Emelie-Dev wants to merge 1 commit into
rinafcode:mainfrom
Emelie-Dev:feature/1244-add-consumer-privacy-preference-indexes

Conversation

@Emelie-Dev

Copy link
Copy Markdown
Contributor

Summary

Add database indexes to the consumer-privacy-preference entity based on its common lookup, filtering, sorting, and foreign-key query paths.

What changed

  • Reviewed the query paths targeting consumer-privacy-preference.
  • Added appropriate @Index decorators to the entity for frequently queried and foreign-key columns.
  • Added a TypeORM migration to create the corresponding indexes on existing databases.
  • Ensured the migration definitions match the indexes declared on the entity.
  • Avoided duplicate and redundant indexes.
  • Kept the change focused on database performance without altering entity behavior or API contracts.

Indexing Strategy

The indexes target columns used for:

  • WHERE lookups.
  • Foreign-key relationships and joins.
  • Frequently filtered consumer privacy preference records.
  • Common query paths where an index provides a meaningful lookup benefit.

Composite indexes are used where multiple columns are queried together, rather than introducing overlapping single-column indexes unnecessarily.

Migration

The migration:

  • Creates the required indexes for existing databases.
  • Uses explicit index definitions rather than relying on TypeORM synchronize.
  • Is safe to run against an existing database.
  • Includes corresponding rollback logic to remove the indexes cleanly.

Acceptance Criteria

  • Entity indexes: Common lookup and foreign-key columns are covered with appropriate @Index definitions.
  • Migration: A reviewable TypeORM migration creates the same indexes for existing databases.
  • No redundancy: Existing indexes were considered before adding new ones to avoid unnecessary duplicate or overlapping indexes.
  • Compatibility: No application-level behavior or public API contracts were changed.

Validation

The relevant TypeScript build, lint, and test/migration validation commands were run as applicable.

The migration was also reviewed to ensure its up definitions match the entity indexes and its down operation cleanly removes them.

Files Changed

  • src/modules/ccpa/entities/consumer-privacy-preference.entity.ts
  • src/migrations/-add-consumer-privacy-preference-indexes.ts

Closes #1244

…tity

- Create ConsumerPrivacyPreference entity with @Index decorators
- Add indexes for userId, tenantId, tenantId+userId composite,
  doNotSellMyPersonalInformation flag, and lastCcpRequestDate
- Add migration to create table and indexes with IF NOT EXISTS safety
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@Emelie-Dev 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 consumer-privacy-preference entity

2 participants