If you've been sticking with the migration naming conventions, you could just pass the output of rake db:migrate:status
through grep
:
rake db:migrate:status | grep 'compan'
This isn't perfect, though - migration names aren't required to have anything to do with what they actually do - a migration might add the column 'name' to the 'companies' table and be named EvacuateWeaselTubes
and still run just fine.
If you wanted to build a task that could overcome this problem, it would have to parse each of the migration files to see what it changed. Since there's many ways to specify a change in a migration (add_column
, a create_table
block, or calling execute('CREATE whatever')
, for instance), you'd probably want to search for mentions of Model.table_name
, then check the schema_migrations
table to see if it had been run.