Migrations don't run with Sequel::Model
Reported by Farrel | May 14th, 2008 @ 11:51 AM | in 1.0
Running a migration in Sequel::Model based app it seems that there is an issue with classes not being correctly loaded. Here's the abbreviated ouput from 'rake sequel:db:migrate':
farrel@nicodemus ~/Projects/blue_mars/app/models $ rake sequel:db:migrate
(in /home/farrel/Projects/blue_mars)
~ Loaded DEVELOPMENT Environment...
~ loading gem 'merb_sequel' ...
~ loading gem 'merb_sequel' ...
~ Connecting to the 'blue_mars_dev' database on 'localhost' using 'postgres' ...
~ SELECT * FROM customers LIMIT 1
~ SELECT * FROM organisations LIMIT 1
~ SELECT * FROM users LIMIT 1
~ Compiling routes...
~ SELECT * FROM users LIMIT 1
~ SELECT * FROM customers LIMIT 1
~ Could not load /home/farrel/Projects/blue_mars/app/models/customer.rb:
uninitialized constant Customer::Organisation - (NameError)
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:478:in `const_missing_before_generators'
/usr/lib/ruby/gems/1.8/gems/rubigen-1.3.1/lib/rubigen/lookup.rb:13:in `const_missing'
/home/farrel/Projects/blue_mars/app/models/customer.rb:3
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/usr/lib/ruby/gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:333:in `load_file'
*snip*
Running "merb -i" works as does "rake spec" so the model code itself is fine:
farrel@nicodemus ~/Projects/blue_mars $ merb -i
~ Loaded DEVELOPMENT Environment...
~ loading gem 'merb_sequel' ...
~ Connecting to the 'blue_mars_dev' database on 'localhost' using 'postgres' ...
~ Compiling routes...
~ SELECT * FROM customers LIMIT 1
~ SELECT * FROM organisations LIMIT 1
~ SELECT * FROM users LIMIT 1
~ Using 'share-nothing' cookie sessions (4kb limit per client)
irb(main):001:0>
I'm unsure if this is a Merb problem although I did notice activesupport in the trace from "rake sequel:db:migrate" and wonder if the problem is from there?
Farrel
Comments and changes to this ticket
-
Michael Klishin (antares) May 14th, 2008 @ 04:11 PM
- → Milestone changed from to 1.0
- → State changed from new to open
Farrel,
Missing constant is probably coming from your application. Could you check it up?
ActiveSupport comes from Rubigen which Merb gen is built on.
-

Farrel May 14th, 2008 @ 04:23 PM
I don't think that's the problem. As I mentioned before "rake specs" and "merb -i" load up fine:
farrel@nicodemus ~/Projects/blue_mars $ ruby spec/models/customer_spec.rb .................. Finished in 0.237206 seconds 18 examples, 0 failuresThe offending line of code is this association in my model/customer.rb file
@@ruby
belongs_to( :organisation, :class => Organisation, :key => :organisation_id )
Customer and Organisation are two top level objects yet during migration the model/orgnisation.rb file looks like it isn't loaded before model/customer.orb so the Organisation class is not found Ruby assumes that Organisation is subclass of Customer which is not the case. I've run the rake task with the --trace option but I get no extra information. One thing I do notice is that during migrations everything seems to be loaded twice (two "loading gem 'merb_sequel'", two "SELECT *...")farrel@nicodemus ~/Projects/blue_mars/app/models $ rake sequel:db:migrate
(in /home/farrel/Projects/blue_mars)
~ Loaded DEVELOPMENT Environment...
~ loading gem 'merb_sequel' ...
~ loading gem 'merb_sequel' ...
~ Connecting to the 'blue_mars_dev' database on 'localhost' using 'postgres' ...
~ SELECT * FROM customers LIMIT 1
~ SELECT * FROM organisations LIMIT 1
~ SELECT * FROM users LIMIT 1
~ Compiling routes...
~ SELECT * FROM users LIMIT 1
~ SELECT * FROM customers LIMIT 1
-
Michael Klishin (antares) May 14th, 2008 @ 04:38 PM
Yeah, this proves this is plugin issue. Unfortunately I never used Sequel plugin. If you contribute a fix, I'll apply it shortly.
-

Farrel May 14th, 2008 @ 10:27 PM
I dunno. From the traces I've got it doesn't touch merb_sequel. The error seems to occur in merb-core. I'm putting in some puts code to try and suss out what's happening.
-
Michael Klishin (antares) May 14th, 2008 @ 10:36 PM
Merb::Sequel plugin just hooks into Merb boot. Try adding $DEBUG = true in your init file and running merb with --verbose.
-

Farrel May 15th, 2008 @ 12:08 AM
- no changes were found...
-

Farrel May 15th, 2008 @ 12:09 AM
- no changes were found...
-

-

-

Farrel May 15th, 2008 @ 09:06 AM
I managed to get this working by changing
belongs_to( :organisation, :class => Organisation, :key => :organisation_id )to
belongs_to( :organisation, :class => :Organisation, :key => :organisation_id )Could there have been a circular dependency issue? Although that wouldn't explain why 'rake spec' and 'merb -i' ran correctly.
-
Michael Klishin (antares) May 15th, 2008 @ 10:04 AM
Does it work if you load up merb -i and try to access this association on some model instance?
-

Farrel May 15th, 2008 @ 10:12 AM
farrel@nicodemus ~/Projects/blue_mars $ merb -i ~ Loaded DEVELOPMENT Environment... ~ loading gem 'merb_sequel' ... ~ Connecting to the 'blue_mars_dev' database on 'localhost' using 'postgres' ... ~ Compiling routes... ~ SELECT * FROM customers LIMIT 1 ~ SELECT * FROM organisations LIMIT 1 ~ SELECT * FROM users LIMIT 1 ~ Using 'share-nothing' cookie sessions (4kb limit per client) irb(main):001:0> org = Organisation.create( :name => "Test Org" ) ~ INSERT INTO organisations ("created_at", "name", "updated_at", "active", "uuid") VALUES (TIMESTAMP '2008-05-15 09:09:06.624877', 'Test Org', TIMESTAMP '2008-05-15 09:09:06.624877', true, 'cd3ed059-fb5e-4a2d-95d7-c5cbf31260c2') ~ SELECT * FROM organisations WHERE ("id" = 2) LIMIT 1 => #<Organisation @values={:created_at=>Thu May 15 09:09:06 +0200 2008, :postal_address=>nil, :admin_user_id=>nil, :name=>"Test Org", :updated_at=>Thu May 15 09:09:06 +0200 2008, :street_address=>nil, :email_address=>nil, :active=>true, :uuid=>"cd3ed059-fb5e-4a2d-95d7-c5cbf31260c2", :phone_number=>nil, :id=>2, :fax_number=>nil}> irb(main):002:0> customer = Customer.create( :name => "Customer", irb(main):003:1* :organisation => org ) ~ INSERT INTO customers ("created_at", "name", "organisation_id", "updated_at", "active", "uuid") VALUES (TIMESTAMP '2008-05-15 09:10:10.878138', 'Customer', 2, TIMESTAMP '2008-05-15 09:10:10.878138', true, '9e0c6b29-4f1a-4773-89d5-f70970526ff3') ~ SELECT * FROM customers WHERE ("id" = 1) LIMIT 1 => #<Customer @values={:mobile_number=>nil, :created_at=>Thu May 15 09:10:10 +0200 2008, :postal_address=>nil, :organisation_id=>2, :name=>"Customer", :updated_at=>Thu May 15 09:10:10 +0200 2008, :street_address=>nil, :email_address=>nil, :active=>true, :internal_reference=>nil, :phone_number=>nil, :uuid=>"9e0c6b29-4f1a-4773-89d5-f70970526ff3", :id=>1, :fax_number=>nil}> irb(main):004:0> customer.organisation.name ~ SELECT organisations.* FROM organisations WHERE ("id" = 2) LIMIT 1 => "Test Org" irb(main):005:0> -

Farrel May 15th, 2008 @ 11:18 PM
I discussed the problem briefly with Jeremy Evans the maintainer of Sequel (thread at http://groups.google.com/group/s...). He also thinks it could be a circular dependency in the migration boo t process. How does the boot process between migrations and specs differ?
-
Michael Klishin (antares) October 5th, 2008 @ 03:58 PM
- → Tag changed from to "merb-core" merb_sequel migrations
- → State changed from open to resolved
- → Assigned user changed from to Michael Klishin (antares)
I tried to generate a fresh app that uses Merb::Sequel and 2 associated top level models and it works for me: here are files. I also created a removed a few instances in merb -i console.
What was fixed during this triage is migration number that did not distinguish between generation and removing of files.
Please leave a comment if you have some specific settings in your app that I did not have in mine.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
