Commit 4c827fd1 authored by Sean McGivern's avatar Sean McGivern

Merge branch '4852-migration-specs-fail-locally-if-no-geo-db-is-configured' into 'master'

Resolve "Migration specs fail locally if no Geo DB is configured"

Closes #4852

See merge request gitlab-org/gitlab-ee!4442
parents 5b30af6e d271811f
......@@ -4,12 +4,16 @@ module Geo
class TrackingBase < ActiveRecord::Base
self.abstract_class = true
SecondaryNotConfigured = Class.new(StandardError)
if ::Gitlab::Geo.geo_database_configured?
establish_connection Rails.configuration.geo_database
end
def self.connection
raise 'Geo secondary database is not configured' unless ::Gitlab::Geo.geo_database_configured?
unless ::Gitlab::Geo.geo_database_configured?
raise SecondaryNotConfigured.new('Geo secondary database is not configured')
end
super
end
......
module EE
module MigrationsHelpers
extend ::Gitlab::Utils::Override
override :reset_column_information
def reset_column_information(klass)
super
rescue Geo::TrackingBase::SecondaryNotConfigured
end
end
end
module MigrationsHelpers
prepend EE::MigrationsHelpers
def table(name)
Class.new(ActiveRecord::Base) { self.table_name = name }
end
......@@ -25,14 +27,19 @@ module MigrationsHelpers
clear_schema_cache!
# Reset column information for the most offending classes **after** we
# migrated the schema up, otherwise, column information could be outdated
ActiveRecord::Base.descendants.each { |klass| klass.reset_column_information }
# migrated the schema up, otherwise, column information could be
# outdated. We have a separate method for this so we can override it in EE.
ActiveRecord::Base.descendants.each(&method(:reset_column_information))
# Without that, we get errors because of missing attributes, e.g.
# super: no superclass method `elasticsearch_indexing' for #<ApplicationSetting:0x00007f85628508d8>
ApplicationSetting.define_attribute_methods
end
def reset_column_information(klass)
klass.reset_column_information
end
def previous_migration
migrations.each_cons(2) do |previous, migration|
break previous if migration.name == described_class.name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment