Rails 3.2: call up / down from another migration

I want to trigger another migration similarly to generation. Basically, if you have a table creation, then at some point in the future you will no longer use the table, and you want them to migration caused upand downexactly opposite to those established for the initial migration. If possible, I would create a generator similar to

rails g reverse_migration CreateModel

and then the result will look like

class ReverseCreateModel < ActiveRecord::Migration
  def up
    #call to create model down
  end
  def down
    #call to create model up
  end
end

I don’t need any way to get around the path and, rather, explicitly duplicating the code and retaining the ability for pure migration and role.

Any help would be greatly appreciated!

+5
source share
1 answer

- Ruby, require :

require "./db/migrate/20120117195557_create_model.rb"

class ReverseCreateModel < ActiveRecord::Migration
  def up
    CreateModel.new.down
  end

  def down
    CreateModel.new.up
  end
end

change, CreateModel.new.migrate(:down) CreateModel.new.migrate(:up).

migrate(direction) :

==  ReverseCreateModel: migrating ======================================
==  CreateModel: reverting =============================================
(...)
==  CreateModel: reverted (0.0018s) ====================================

==  ReverseCreateModel: migrated (0.0019s) =============================

:

==  ReverseCreateModel: migrating ======================================
(...)
==  ReverseCreateModel: migrated (0.0019s) =============================

fooobar.com/questions/13989/...

+12

All Articles