Why do we need database migrations?

I knew keeping migrations is something you wanna do when managing databases. But I’ve always had an hard time justifying their importance with other fellow engineers.

Even I wasn’t 100% sure on why they’re valuable.

Answer: You need migrations as soon as you have more than one database instance.

This happens really fast as you always have at least prod and your local dev environment. You can’t dump the whole prod db and load it on your laptop. Instead, you need to create the tables from scratch and load data into those tables.

If the database and the application were written in stone you could setup a create_tables.sql andinsert_data.sql scripts.

But they’re not. They keep on changing because you’ll need new feature or find bugs.

The realistic alternative is to write a series of SQL scripts to execute in order. And you’ve just invented migrations.

Software Engineer