Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to know what all migrations have been applied to Rails database?

Is there a way to know what all migrations have been applied to Rails database?

I am looking for a command-line option, rather than checking the schema_migrations table in the database.

like image 933
Tabrez Avatar asked Sep 06 '25 03:09

Tabrez


2 Answers

rake db:version will give you the current "schema version number" which should match the filename of the last migration that was executed.

like image 115
Dylan Markow Avatar answered Sep 07 '25 22:09

Dylan Markow


To check the status of specific migrations, you can use the following Rake task:

rails db:migrate:status

This will output a table with the status of up or down for each migration:

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     migration_id    migration_name

In your case, you can check if you have any migration not applied:

rails db:migrate:status | grep down
like image 24
Arturo Herrero Avatar answered Sep 07 '25 21:09

Arturo Herrero