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:inconst_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:inconstantize’
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:inmigration_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:ineach’
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:inmigration_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:inup’
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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs