Create a separate datasource.ts file for the TypeORM CLI that does not depend on the NestJS app module. Generate migrations with migration:generate, apply with migration:run, and roll back with migration:revert. Never use synchronize: true in production — use migrations exclusively.
Never use synchronize: true in production — it can drop columns and tables destructively.
Keep a separate datasource.ts for the TypeORM CLI so it works independently of the NestJS app module.
Always implement down() — rollbacks are critical for safe deployments and hotfixes.
Commit all migration files to version control — they are the source of truth for schema history.
Use migrationsRun: true in the NestJS TypeORM config to auto-apply pending migrations on startup.
You need to add a new column to an existing User entity. Walk me through the steps you’d take to create and apply a TypeORM migration in a NestJS project.
If you run npm run migration:run and it reports 'No pending migrations', but you know you added a new entity field, what could be causing that and how would you fix it?
During a feature rollout, a migration fails halfway on production because of a NOT NULL constraint. How would you diagnose and resolve the issue without causing downtime?
Explain why you might choose to write a migration manually instead of letting TypeORM generate it automatically, and give an example where the generated migration would be problematic.
Our service runs in a zero‑downtime deployment pipeline and serves traffic from multiple instances. How would you design a migration strategy using TypeORM in NestJS to ensure schema changes are applied safely across all instances?
We have a multi‑tenant database where each tenant has its own schema. How would you manage TypeORM migrations to handle schema versioning per tenant while keeping the codebase maintainable?
Across several microservices that share a common database, how would you coordinate TypeORM migrations to avoid version drift and ensure consistent schema evolution across teams?
Describe a long‑term migration governance process you’d put in place for a large organization using NestJS and TypeORM, covering CI/CD integration, rollback procedures, and documentation.