Ever got frustrated by looking through your db/migrations folder, searching for a specific migration, to see if it was applied to your database? Or you're afraid of running db:migrate on production, because you're not sure which migrations it will apply? Every had to change a migration while developing, being constantly counting migrations because db:migrate:rollback just isn't handy enough?

There's help via another Rake task, which is not mentioned in the Rails Guides:

db:migrate:status will print the current state of your database to your terminal:

1
2
3
4
5
6
7
8
9
10
database: olymp_development

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20160717173819  Create books
   up     20160923161308  Devise create users
   up     20161020080045  Add available flag to books
   down   20170102123753  Create authors
   up     20170102124214  Add author to books
   up     20170107092840  Add roles to users

Now you can take the migration ID (which is really the timestamp the migration was created, when you're using generators) and plug it into db:migrate:up VERSION=<migration-id> to apply that migration, and only that migration. That's perfect for production.

Similarly, you can also take down a migration with db:migrate:down VERSION=<migration-id>, which I use when adding new fields/tables/indexes to my projects, cause it allows me to undo/redo a migration easily.