I'm using Rails 2.2.2 and Ruby 1.8.6 with a legacy app, with MySQL. (please don't tell me that I need to upgrade ruby/rails).
I have backups of our live database installed as different databases within my local MySql. This is useful sometimes for querying historical data, as this doesn't always get preserved within our active database.
What I'd like to be able to do is something like this
school_ids = [123, 456, 789]
signin_counts = {}
#collect current data
school_ids.each do |school_id|
signin_counts[school_id] ||= {}
signin_counts[school_id][:now] = ActiveRecord::Base.connection.select_value("select count(*) from sign_ins where school_id = #{school.id}").to_i
end
#switch to the old database - how to do this?
CURRENT_DB = "my_old_backup_db_name"
school_ids.each do |school_id|
signin_counts[school_id] ||= {}
signin_counts[school_id][:then] = ActiveRecord::Base.connection.select_value("select count(*) from sign_ins where school_id = #{school.id}").to_i
end
#switch back
CURRENT_DB = "my_regular_db_name"
Does anyone know how to do the CURRENT_DB =
part? Thanks