Forum: Ruby on Rails Irreversible Migrations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Wiebe C. (Guest)
on 2006-04-06 18:47
(Received via mailing list)
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?
Nuno (Guest)
on 2006-04-06 19:47
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
Wiebe C. (Guest)
on 2006-04-06 20:01
(Received via mailing list)
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.
Wiebe C. (Guest)
on 2006-04-13 19:41
(Received via mailing list)
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
This topic is locked and can not be replied to.