Introducing automatic database migrations

Let's take the final step in automation by setting up database migrations. A migration is a change to the database structure of our application. For example, if we change our code and it now expects a new field in one of our tables, the migration would be the code that alters the table structure and adds the missing field. Making these migrations part of our code base allows us to automate this – when the tests or the application is started, all migrations that are not yet applied to the database are applied automatically; we no longer need to ensure manually that our code and our database structures are in sync.

The Node.js module that takes care of this for us is db-migrate. We already installed ...

Get The Node Craftsman Book now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.