Sounds Like Weird
07 April 2006
Sometimes, you want ActiveRecord to do all the heavy lifting of data conversion. Plus, then you can use all the stuff you want during the conversion.
#!/usr/local/bin/ruby
require ‘rubygems’
require_gem ‘activerecord’
require ‘../app/models/survey.rb’
require ‘../app/models/topic.rb’
@dbs = YAML::load(ERB.new(IO.read(“../config/database.yml”)).result)
curr_db = @dbs[‘production-mysql’]
ActiveRecord::Base.establishconnection(:adapter => currdb[“adapter”],
:database => curr_db[“database”],
:host => curr_db[“host”],
:username => curr_db[“username”],
:password => curr_db[“password”])
@surveys = Survey.find(:all)
ActiveRecord::Base.remove_connection
curr_db = @dbs[‘production’]
ActiveRecord::Base.establishconnection(:adapter => currdb[“adapter”],
:database => curr_db[“database”],
:host => curr_db[“host”],
:username => curr_db[“username”],
:password => curr_db[“password”])
for survey in @surveys
s = survey.clone
s.save
end
ActiveRecord::Base.remove_connection