DEV Community

Discussion on: Rails Migration Hacks !! Things You should know if you are a ROR Developer .

Collapse
 
olivierjm profile image
Olivier JM Maniraho

Nicely written article, I wish I saw this just a fee days ago.

I am new in a rails world and I recently messed up my migrations, I didnt know that you have to migrate up on a specific migration version after doing a migration down.

Quick question, the irreversible on Active record, does that mean I can still rollback to previous versions?
What is the most recommended way of cleaning up issues with migrations especially when you have rolled back already?
Looking forward to more of these articles

Collapse
 
sambitmohanty954 profile image
Sambit Mohanty • Edited

in api.rubyonrails.org/classes/Active... website written:-

"Some transformations are destructive in a manner that cannot be reversed. Migrations of that kind should raise an ActiveRecord::IrreversibleMigration exception in their down method."

But there is way you can reverse it????

you can reverse it by using "Reversible" , basically this method allow you to specify up and down behavior for part of the migration. so in Reversible part you can write your your own method

class MigartionFileName < ActiveRecord::Migration[6.0]
  def change

    reversible do |var|
      var.up do
        --------your up method------
      end

      var.down do
       -------your down method-----
      end

    end
  end
end

thanks for your comment , stay tuned for more interesting topic . if you want something that i cover on my ruby on rails blog then please do let me know . _^

Some comments have been hidden by the post's author - find out more