# Irreversible Migrations

**URL:** <https://www.ruby-forum.com/t/irreversible-migrations/57023>\
**Category:** Rails\
**Created:** [April 6, 2006, 4:47pm UTC](https://www.ruby-forum.com/t/irreversible-migrations/57023 "2006-04-06T16:47:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![halfgaar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ea666f/32.png) [@halfgaar](https://www.ruby-forum.com/u/halfgaar)\
**Post date:** [April 6, 2006, 4:47pm UTC](https://www.ruby-forum.com/t/irreversible-migrations/57023/1 "2006-04-06T16:47:38Z")

</div>

Hi,

To make a migration irreversable, one has to execute “raise  
IrreversibleMigration”. This is how it’s documented everywhere. However,  
when I do that, I get this:

rake aborted!  
uninitialized constant IrreversibleMigration

This is the migration (the file is called 022\_ldap\_fix.rb):

class LdapFix \< ActiveRecord::Migration  
def self.up  
execute File.open( **FILE**.gsub(/.rb$/, ‘.pgsql’) ).read  
end

def self.down  
raise IrreversibleMigration  
end  
end

I’m using a frozen gem of Rails 1.1.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![halfgaar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ea666f/32.png) [@halfgaar](https://www.ruby-forum.com/u/halfgaar)\
**Post date:** [April 6, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/irreversible-migrations/57023/2 "2006-04-06T17:47:48Z")

</div>

But what’s wrong ? it seems that your db have been rolled back to this  
version+1 migration and then : rake stops…

Thus, your migration is reversible as the previous versions can’t be  
executed

---

<div class="post-metadata">

**Author:** ![halfgaar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ea666f/32.png) [@halfgaar](https://www.ruby-forum.com/u/halfgaar)\
**Post date:** [April 6, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/irreversible-migrations/57023/3 "2006-04-06T18:01:33Z")

</div>

Nuno wrote:

> But what’s wrong ? it seems that your db have been rolled back to this  
> version+1 migration and then : rake stops…
> 
> Thus, your migration is reversible as the previous versions can’t be  
> executed

In practice yes, but that would mean you could just execute  
“adsflkjadslfk  
asldfkj asdflk” for every irreversable migration… Not very eloquent.  
In  
fact, downright ugly…

Rails has methods like ActiveRecord::Base.reload just to avoid doing  
ActiveRecord::Base.find(sameobject.id), or a :first modifier on the find  
method to avoid having to lookup result 0 in the resultset yourself.  
Programming isn’t just about making things work, the programming itself  
should be clean and intuitive.

---

<div class="post-metadata">

**Author:** ![halfgaar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ea666f/32.png) [@halfgaar](https://www.ruby-forum.com/u/halfgaar)\
**Post date:** [April 13, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/irreversible-migrations/57023/4 "2006-04-13T17:41:01Z")

</div>

On Thursday 06 April 2006 16:43, Wiebe C. wrote:

> What am I doing wrong?

To answer my own question, you have to do:

raise ActiveRecord::IrreversibleMigration
