krsgoss-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-13 21:01 UTC
Standalone AR Migrations
Hi, I''m trying to utilize AR migrations outside of a rails application as this sort of thing is valuable in just about any application using a versioned database. I have seen examples (http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Ruby/MigrationsOutsideRails.rdoc) of calling AR standalone, however; I would like to leverage the up/back support that you get with AR::Migration instances. In peeking around the AR source, I saw that the default rake task calls ActiveRecord::Migrator.migrate and passed in the scripts directory and optional version number. I created the following simple script: require "rubygems" require_gem "activerecord" ActiveRecord::Base.establish_connection( :adapter => "sqlserver", :host => "DBI:ADO:Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=migrate_demo;User Id=someuser;Password=itsasecret;", :username => "someuser", :password => "itsasecret", :database => "migrate_demo") ActiveRecord::Migrator.migrate("db/", ARGV[0] ? ARGV[0].to_i : nil I verified the connectivity in IRB (having patched the DBI''s ado.rb) and all is well. When I run the script I get the following (long stack trace below). I''m hoping someone can with setting up AR properly. The stack trace is below... Thanks! ----------------------------------------------------------------------------- C:\projects\spike\migrations\migrations>migrate.rb c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in `const_missing'': unini tialized constant Setup (NameError) from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:131:in `const_missing'' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:161:in `constantize '' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/string/inflections.rb:5 9:in `constantize'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:364:in `migration_class'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:344:in `migration_classes'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adap ter.rb:120:in `inject'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:340:in `each'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:340:in `inject'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:340:in `migration_classes'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:328:in `migrate'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:295:in `up'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:286:in `migrate'' from C:/projects/spike/migrations/migrations/migrate.rb:18 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---