Show pending migrations in rails

Is there a rake task that shows the pending migrations in a rails app?


rake db:migrate:status (Rails 3 to 5) or rails db:migrate:status (Rails 5) will accomplish this. See this commit.

up means the migration has been run. down means the migration has not been run.


There is rake db:abort_if_pending_migrations (at least in Rails 2.3.3, not sure when it was introduced). The description says 'Raises an error if there are pending migrations'. This seems to be used more as a prerequisite for other tasks, but I'm guessing you could use it for your purposes.

EDIT: Here is an example of the output after having just generated and not run a 'test' migration

rails_project theIV$ rake db:abort_if_pending_migrations
(in /Users/theIV/Sites/rails_project/)
You have 1 pending migrations:
  20090828200602 Test
Run "rake db:migrate" to update your database then try again.

This command will list all migrations with their status (UP or DOWN)

Rails 3 and 4

rake db:migrate:status

Rails 5

rake db:migrate:status

# Or

rails db:migrate:status

rake db:version will accomplish this on Rails 2.


This works for rails 5.2

ActiveRecord::Base.connection.migration_context.needs_migration?