Skip to content

Confirm and generate all missing database migrations #103

@phertyameen

Description

@phertyameen

Summary

The SDK README documents npm run migration:run as a required setup step, but the state of the actual migration files in the repository is unconfirmed. Several changes across the issue backlog add new columns, new enum values, and new tables that each require a migration. Without confirmed, complete migrations, a fresh environment setup will either fail silently with missing columns or require manual schema intervention. This issue audits existing migrations and generates all missing ones.

How to audit the current migration state

Run npm run migration:run in a clean environment and observe whether it succeeds without errors. Then run the application and attempt POST /accounts - if TypeORM throws column-not-found errors, migrations are incomplete. TypeORM can also generate a migration diff with

npm run migration:generate -- -n AuditCheck 

against a fresh database - the generated file will show what the ORM thinks is missing.

Enum migration note

PostgreSQL enum changes are particularly fragile. Adding INITIALIZING to the AccountStatus enum requires:
sqlALTER TYPE account_status_enum ADD VALUE 'initializing' BEFORE 'pending_payment';
TypeORM's auto-generated migrations do not always handle enum additions correctly: verify the generated SQL manually before running it in any shared environment.

Environment considerations

Migrations should be safe to run multiple times (idempotent where possible). Each migration should have both an up and a down method: the down method is critical for rolling back during testing without manual database intervention.

Where to look

  • src/database/: existing migration files and the TypeORM data source config
  • src/modules/accounts/entities/account.entity.ts: source of truth for the accounts schema
  • src/modules/claims/entities/claim.entity.ts: source of truth for the claims schema
  • TypeORM migration documentation: specifically migration:generate and migration:run

Acceptance Criteria

  • All existing migrations are audited and confirmed to run successfully on a clean database
  • A migration exists for adding INITIALIZING to the account_status enum
  • A migration exists for the webhooks table from Issue Implement WebhooksService and restore commented-out webhook triggers #102
  • metadata (jsonb, nullable) is confirmed present on accounts table in migrations
  • expiredAt is confirmed present on accounts table in migrations
  • Every migration has both up and down methods
  • npm run migration:run completes without errors on a fresh PostgreSQL instance
  • The README setup instructions are updated if the migration command or sequence has changed

Metadata

Metadata

Assignees

No one assigned

    Labels

    criticalVery important for the project to function.nestjsBackend frameworktypescriptPrograming language

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions