Migrations with TypeORM in NestJs
Migrations with TypeORM in NestJs Why Do We Need Migrations in NestJs? NestJs provides an auto-sync feature that automatically updates the database when entity changes occur. Given this, you might wonder why migrations are necessary. The reason is that while auto-sync can be convenient, it can become risky in production environments. When your application is live and contains actual data, direct modifications to the database could lead to issues. This is why relying on synchronization in production is considered unsafe. Advantages of Using Migrations You can control when migrations are applied. Reduces the risk of errors in production environments. Migration files can be automatically generated from entity changes, so you don’t need to manually write them. Disadvantages of Migrations You need to generate and run migration files every time you make changes to your entities. Example Suppose you have an entity named Student : import { BaseEntity , Column , Entity , PrimaryGeneratedColumn...