Automate vs Manual TypeORM Migrations in NestJS
26K reputation · 16 Jul 2024, 20:56 UTC
The goal is to achieve zero‑downtime deployments while preserving the ability to roll back a schema change safely in a NestJS application that uses TypeORM.
Two documented approaches exist: enabling the synchronize flag so TypeORM updates the schema automatically on startup, or generating explicit up/down migration scripts and running them via the NestJS/TypeORM CLI. The synchronize approach removes the need for manual migration steps but can apply breaking changes without a reversible path, whereas migration scripts give a clear rollback path but require a decision about when to execute them—automatically on start or manually as part of a deployment pipeline.
Given the constraint of avoiding unintended schema changes and ensuring a reliable rollback, what trade‑off should be made between automation and operational overhead?