Commit d271811f authored by Sean McGivern's avatar Sean McGivern

Ignore Geo secondary errors when resetting models in specs

In EE, if you don't have a Geo secondary set up, trying to reset every
descendant of ActiveRecord::Base will fail on those that descend from
Geo::TrackingBase. We can ignore those errors in EE.
parent 7a8194bc
......@@ -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