5

I am hoping rails.vim has some migration support.

I'm looking for something like: generate migration and jump to that file, and then a way to fire the migration.

Does this exist or am I dreaming? :)

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

3 Answers3

13

You definitely can!

As mentioned, you can run the following to generate a migration:

:Rgenerate migration migration_name ...

Then this will switch to the latest migration:

:Rmigration

And then finally:

:Rake db:migrate

will actually migrate it for you.

Also I shouldn't forget to add that running

:Rinvert

in a migration file, will try to create the down portion of your migration (or visa versa).

GitNick
  • 311
  • 2
  • 14
3

With regard to running a migration:

When in migration file, e.g. 123456789_my_migration.rb:

  • :Rake will call rake db:migrate VERSION=123456789.

    Note the . preceeding Rake in the following (this sends the line number to the command):

  • :.Rake on line 1, or inside the down method, will call
    rake db:migrate:down VERSION=123456789.

  • :.Rake on the last line, or inside the up method, will call
    rake db:migrate:up VERSION=123456789.

  • :.Rake anywhere else in the file will call
    rake db:migrate:down db:migrate:up VERSION=123456789.

I don't know of any documentation for this, I figured it out from looking at the appropriate part of rails.vim.

davetapley
  • 17,000
  • 12
  • 60
  • 86
0

Jeje definitaly not dreaming. I should warn you that is a bit slow.

To generate the migration

:Rgenerate migration migration_name table_attributes

To run rake db:migrate

:Rake db:migrate

You can run an specific migration passing along VERSION="xxx". For more information on how to do this, you can go to :help rails-rake

e3matheus
  • 2,112
  • 1
  • 20
  • 28