Posted By

sgtrock on 12/24/09


Tagged

rails ruby activerecord migrations monkeypatch


Versions (?)

Monkeypatch for easier to read migrations


 / Published in: Rails
 

I never can remember the exact name of the exception to call in self.down for a migration that cannot be undone. So I decided to come up with something easier to remember. This feels more "ruby-ish" and "rails-ish" to me, and so far it works just fine. It also displays a message that is easier to pick out amongst all the other migration output on the screen so you can see at a glance that it failed.

  1. module ActiveRecord
  2. module ConnectionAdapters
  3. module SchemaStatements
  4. def cannot_undo!
  5. raise ActiveRecord::IrreversibleMigration.new("********** This migration cannot be undone ***********************************")
  6. end
  7. end
  8. end
  9. end

Report this snippet  

You need to login to post a comment.