Is it possible to configure Rails so that after running rails g migration name_of_migration
, it automatically opens that file in TextMate?
If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run rake db:migrate.
A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.
To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.
Rails creates a table in your database called schema_migrations to keep track of which migrations have run. The table contains a single column, version . When Rails runs a migration, it takes the leading digits in the migration's file name and inserts a row for that "version", indicating it has been run.
You could create an alias with this:
alias last_migration='ls db/migrate/* | tail -n1 | xargs open -a "Textmate"'
and then run it from your terminal:
last_migration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With