What if your database could update itself perfectly every time you change your app?
Why Migrations in NestJS? - Purpose & Use Cases
Imagine you have a growing app and you need to change your database structure by hand every time you add a new feature.
You open your database tool and manually add or remove columns, tables, or indexes for each update.
Manually changing the database is slow and risky.
You might forget a step, make a typo, or apply changes in the wrong order.
This can break your app or cause data loss, especially when working with a team.
Migrations automate database changes in a safe, repeatable way.
They keep track of what changes were made and apply them in order.
This means your database stays in sync with your app code without manual errors.
ALTER TABLE users ADD COLUMN age INT;
await queryRunner.addColumn('users', new TableColumn({ name: 'age', type: 'int' }));
Migrations let you evolve your database confidently as your app grows, even with multiple developers.
When your team adds a new feature that needs a new table, migrations let everyone update their databases with one command, avoiding confusion and errors.
Manual database changes are error-prone and hard to track.
Migrations automate and organize database updates safely.
This keeps your app and database in sync as you develop.