This project uses TypeORM migrations to manage schema changes. Follow the steps below to create, verify, and run migrations.
- Generate a migration:
npm run migration:generate -- -n <MigrationName>- Verify the generated migration file appears in
src/database/migrations/and contains the intended SQL changes.
Run the verification script to check for pending migrations without applying them:
npm run migration:verifyExpected output:
✅ No pending migrationswhen up-to-date⚠️ Pending migrations detectedand a non-zero exit code when pending migrations are found
If pending migrations are detected, review and apply them with:
npm run migration:runBefore applying migrations in production or staging:
- Ensure you have a backup of your database.
- Ensure the migration file has both
upanddownimplementations (for rollback). - Run
npm run migration:verifylocally and in CI as a PR gate.
- The application runs a migration validation check during startup and logs whether there are pending migrations.
- Migration scripts should avoid using ES module features directly that cause runtime warnings when executed via
ts-nodeor TypeORM CLI. If you see "ES module" related warnings, ensure the migration files use CommonJS-compatible imports/exports or are run with a TypeScript runner that supports ESM.
- Add a pipeline step that runs
npm run migration:verifyto prevent PRs that introduce missed migrations.
Thanks for contributing! Please follow code style conventions and add tests when applicable.