Skip to content

feat(database): add database indexes to schema_version entity and mig… - #1398

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
ajulaybeeb:feat/1239-schema-version-indexes
Aug 30, 2026
Merged

feat(database): add database indexes to schema_version entity and mig…#1398
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
ajulaybeeb:feat/1239-schema-version-indexes

Conversation

@ajulaybeeb

Copy link
Copy Markdown
Contributor

Summary

  • Added @Index decorators to src/entities/schema_version.entity.ts covering schemaName, checksum, createdAt, and composite ("schemaName", "createdAt").
  • Added migration src/migrations/1804000000000-add-schema-version-indexes.ts to create these indexes on existing databases with idempotent IF NOT EXISTS clauses and reversible down() method.

Why

The schema_version table lacked indexes on its primary lookup, filtering, and sorting columns (schemaName, checksum, createdAt). As the table grows, lookups by schema name and chronological history ordering force sequential scans. Adding targeted B-tree indexes ensures high-performance lookups and prevents schema drift between the TypeORM entity and the database.

Implementation

  • src/entities/schema_version.entity.ts:
    • Imported Index from typeorm.
    • Added @Index('IDX_schema_version_schemaName', ['schemaName']).
    • Added @Index('IDX_schema_version_checksum', ['checksum']).
    • Added @Index('IDX_schema_version_createdAt', ['createdAt']).
    • Added composite @Index('IDX_schema_version_schemaName_createdAt', ['schemaName', 'createdAt']).
  • src/migrations/1804000000000-add-schema-version-indexes.ts:
    • Implemented AddSchemaVersionIndexes1804000000000 with up() creating all 4 indexes and down() dropping them.

Testing

  • Verified syntax, entity decorator definitions, and TypeORM migration interface compliance.
  • Verified timestamp ordering and uniqueness adherence with src/migrations/migration-timestamps.spec.ts.

Scope / Risk

  • Scope is strictly confined to schema_version entity and the new migration file.
  • Non-breaking change; uses IF NOT EXISTS to safely run across all environments.

Issue

Closes #1239

@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

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

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 3beb689 into rinafcode:main Aug 30, 2026
3 checks passed
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 schema_version entity

3 participants