0

I have different migrations file

20120205111326_change_users_login_limit.rb
20120223110929_change_attachments_container_defaults.rb
20120223110300_change_locals_container_defaults.rb 20120223110301_change_position_tracs.rb

I want to run up migration of 20120205111326, 20120223110929, 20120223110300 just before the last migration but condition is that it should not point its migration VERSION numbers...

Is there any ways to do it...please suggest me..

Thank you in advance

Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74
  • AFAIK, no. Not in a sense that it is a functionality in Rails. However, you could run a specific migration http://stackoverflow.com/a/6635407/832759 then comment out the code in migration file and rollback… sound silly I know but it should work the way you want – j03w Aug 29 '13 at 13:23
  • first of all Thank you @j03w....yes this is really problematic as my files are in deployed server and there is no permission to open a file and comment the line.....I am in trouble – Rajarshi Das Aug 29 '13 at 13:26
  • Well, you can always fallback to pure SQL solution as in write some sql statement and run it on your DB. You even run your migration somewhere and copy the create table statement from `structure.sql` if you are not sure you can replicate the commands rails would use – j03w Aug 29 '13 at 13:29
  • hmmm.... this is the last solution...by the way thank you – Rajarshi Das Aug 29 '13 at 13:30

1 Answers1

1

There is one way, Run your migration via rails console

require "db/migrate/20120205111326_change_users_login_limit.rb"
ChangeUsersLoginLimit.change # or 'up' or 'down' whatever method of that migration you want to run.

And do the same for all migration (don't forget to do it in sequence)

EDIT:

Rails actually don't provide a way to run migration skipping some. or run them by changing order. But the migration files are actually a ruby programs containing a single class. So you can always create a rake task and require migration in to rake task and run them in the custom logical order. After all migrations are the classes with methods.

Hardik
  • 3,815
  • 3
  • 35
  • 45
  • I do not want in rails console .............this is some kind of hard coded by assign file name can we do `rake db:migrate_last3` by creating a task and it will generic – Rajarshi Das Apr 15 '15 at 14:22