Created
May 22, 2013 17:16
-
-
Save djburdick/5629250 to your computer and use it in GitHub Desktop.
make schema_migrations work over multiple databases. #rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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