Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace :db do
- desc "Migrate all the databases found in sitesdb through scripts in db/migrate. Target specific version with VERSION=x"
- task :migrate_all => :environment do
- adapter = "mysql"
- host = "mysql_host"
- username = "mysql_user"
- password = "mysql_pass"
- sitesdb = "projects"
- prefix = "project_"
- # there is a #{sitesdb}.sites table with string column database
- class Site < ActiveRecord::Base
- end
- ActiveRecord::Base.establish_connection :adapter => adapter,
- :host => host,
- :username => username,
- :password => password,
- :database => sitesdb
- sites = Site.find(:all)
- sites.each do |site|
- ActiveRecord::Base.establish_connection :adapter => adapter,
- :host => host,
- :username => username,
- :password => password,
- :database => "#{prefix}#{site.database}"
- ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
- Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
- end
- end
- end
Add Comment
Please, Sign In to add comment