Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save djburdick/5629250 to your computer and use it in GitHub Desktop.
Save djburdick/5629250 to your computer and use it in GitHub Desktop.
make schema_migrations work over multiple databases. #rails
module ActiveRecord
class Migrator
class << self
def get_all_versions
table = Arel::Table.new(schema_migrations_table_name)
# must not be Base.establish_connection b/c that'll drop the mysql2
# adapter connection and blow up rake db:schema:dump
SchemaMigration.establish_connection(ActiveRecord::Base.configurations['cluster'][Rails.env])
cluster_migrations = SchemaMigration.connection.select_values(table.project(table['version'])).map{ |v| v.to_i }
SchemaMigration.establish_connection(ActiveRecord::Base.configurations[Rails.env])
global_migrations = SchemaMigration.connection.select_values(table.project(table['version'])).map{ |v| v.to_i }
(cluster_migrations + global_migrations).sort
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment