Conflicting updates

Jim G. wrote:

I’m testing things out for our eventual rollout of 0.6 and I’m
receiving this error when running rake db:migrate (or rake db:migrate
production)
"undefinded local variable of method ‘class_name’ for #<Page:
0x27a850>’

0.5.2 was installed and working OK on mysql (pulled the source, not
from the gem)
But the MergeBehaviorsAndPages migration seems to fail every time.

The error exists because the migration calls save!, which attempts to
validate, which uses the class_name column which is created in
migration 11 (app/models/page.rb:199). I don’t know an easy way to
fix that. It works on an empty database because there are no pages
to call save on. If I can get it to work, I’ll let the list know.

~~ Brian

Uh-oh. I’m really hoping there’s some better advice out there, but
thanks Nancy.

I’m migrating from a fresh directory with only the appropriate config
information changed. I’m not using any but the default behaviors, and
all of my gems are up to date.

Brian,

I apologize for this problem. It comes up because of a recent change I
made to mental. I’ll work with John to find a solution.

Sean

On Mar 21, 2007, at 2:53 PM, Brian G. wrote:

The error exists because the migration calls save!, which attempts to
validate, which uses the class_name column which is created in
migration 11 (app/models/page.rb:199). I don’t know an easy way to
fix that. It works on an empty database because there are no pages
to call save on. If I can get it to work, I’ll let the list know.

Horrible hack follows. But it works.

Index: 010_merge_behaviors_and_pages.rb

— 010_merge_behaviors_and_pages.rb (revision 355)
+++ 010_merge_behaviors_and_pages.rb (working copy)
@@ -7,6 +7,7 @@

def self.up
  announce "converting behavior names to class names"
  • add_column :pages, :class_name, :string
    Page.find(:all).each do |page|
    unless page.behavior_id.blank?
    page.behavior_id = page_name(page.behavior_id)
    @@ -14,6 +15,7 @@
    end
    end
    rename_column :pages, :behavior_id, :type
  • remove_column :pages, :class_name
    end
    def self.down

I normally fix migration validation problems by supplying a basic
implementation within the migration itself - usually just

class Page < ActiveRecord::Base
end

with maybe an association or two. Using the actual models for migrations
tends to lead to problems down the road.


From: [email protected]
[mailto:[email protected]] On Behalf Of Sean C.
Sent: Thursday, 22 March 2007 6:48 AM
To: [email protected]
Subject: Re: [Radiant] migrating from 0.5.2 to 0.6rc2

Brian,

I apologize for this problem. It comes up because of a recent change I
made to mental. I’ll work with John to find a solution.

Sean