Skip to content

Database Migrations

The concept of migrations is a more modern way to manage the evolutions of a database schema. The core concept is to treat the changes to a database schema the same as you treat your application code. All changes are tracked in version control. You can apply changes to the database as well as roll them back. If you add tables and fields manually to your database there is no track record of those changes and their dependency on application code.

StarterStack uses Sequelize database ORM which includes the ability create and execute database migrations. Additionally, you can create associated model classes (code) to interact with those tables. The end result is that all of this is code that is checked into your repo.

There is a lot of good information out there on the internet on this topic. If you're not familiar with it, I encourage you to read about it.

Here is a look at all the migration related commands Sequelize offers:

sh
sequelize-cli <command>

Commands:
  sequelize-cli db:migrate                        Run pending migrations
  sequelize-cli db:migrate:schema:timestamps:add  Update migration table to have timestamps
  sequelize-cli db:migrate:status                 List the status of all migrations
  sequelize-cli db:migrate:undo                   Reverts a migration
  sequelize-cli db:migrate:undo:all               Revert all migrations ran
  sequelize-cli db:seed                           Run specified seeder
  sequelize-cli db:seed:undo                      Deletes data from the database
  sequelize-cli db:seed:all                       Run every seeder
  sequelize-cli db:seed:undo:all                  Deletes data from the database
  sequelize-cli db:create                         Create database specified by configuration
  sequelize-cli db:drop                           Drop database specified by configuration
  sequelize-cli init                              Initializes project
  sequelize-cli init:config                       Initializes configuration
  sequelize-cli init:migrations                   Initializes migrations
  sequelize-cli init:models                       Initializes models
  sequelize-cli init:seeders                      Initializes seeders
  sequelize-cli migration:generate                Generates a new migration file
  sequelize-cli migration:create                  Generates a new migration file
  sequelize-cli model:generate                    Generates a model and its migration
  sequelize-cli model:create                      Generates a model and its migration
  sequelize-cli seed:generate                     Generates a new seed file
  sequelize-cli seed:create                       Generates a new seed file

Options:
  --version  Show version number                                                                                                                             [boolean]
  --help     Show help