Migrations & Why are they important?

tech
migrations
database
schema
workflow

What are Migrations?

Migrations are files that help manage transitions between current database schemas and future database schemas. These could involve adding tables and columns, removing fields, changing types and constraints.

Why are they important?

Code Review

They help in Code Review, as the reviewer exactly know what is happening in the database and can then identify any problems that can occur in production. Reviewers can catch issues like:

Are there libraries that help implementing migrations?

What is a development workflow with migrations?

There are many workflows that one can follow while implementing migration files when adding a new feature. Here’s a basic one:

  1. During development - Develop your feature first and ensure that you have arrived at a decent version of your feature. Then create migration and commit it to your feature branch.
  2. During staging or production, you make sure to pull in the migrations and run it. This could be two steps as sometimes migrations dont get applied automatically, as there might be issue with the database state before the migration can be applied.
  3. So testing in staging is important to ensure that there are no issues with the migration files.

Your production should have automatic backups. And it’s a good idea to do a manual backup before a major migration, if you think there might be an issue.

Have you implemented migrations in your project? What are the challenges you faced?