Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

automatically open Rails generate migration file in editor

Is it possible to configure Rails so that after running rails g migration name_of_migration, it automatically opens that file in TextMate?

like image 488
ma11hew28 Avatar asked Dec 15 '10 22:12

ma11hew28


People also ask

Can you edit a migration file rails?

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.

What does rails generate migration do?

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.

How do I run a migration file in rails?

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.

How does rails know which migrations to run?

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.


1 Answers

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
like image 101
adantj Avatar answered Sep 28 '22 09:09

adantj