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 ...@@ -4,12 +4,16 @@ module Geo
class TrackingBase < ActiveRecord::Base class TrackingBase < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
SecondaryNotConfigured = Class.new(StandardError)
if ::Gitlab::Geo.geo_database_configured? if ::Gitlab::Geo.geo_database_configured?
establish_connection Rails.configuration.geo_database establish_connection Rails.configuration.geo_database
end end
def self.connection 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 super
end 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 module MigrationsHelpers
prepend EE::MigrationsHelpers
def table(name) def table(name)
Class.new(ActiveRecord::Base) { self.table_name = name } Class.new(ActiveRecord::Base) { self.table_name = name }
end end
...@@ -25,14 +27,19 @@ module MigrationsHelpers ...@@ -25,14 +27,19 @@ module MigrationsHelpers
clear_schema_cache! clear_schema_cache!
# Reset column information for the most offending classes **after** we # Reset column information for the most offending classes **after** we
# migrated the schema up, otherwise, column information could be outdated # migrated the schema up, otherwise, column information could be
ActiveRecord::Base.descendants.each { |klass| klass.reset_column_information } # 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. # Without that, we get errors because of missing attributes, e.g.
# super: no superclass method `elasticsearch_indexing' for #<ApplicationSetting:0x00007f85628508d8> # super: no superclass method `elasticsearch_indexing' for #<ApplicationSetting:0x00007f85628508d8>
ApplicationSetting.define_attribute_methods ApplicationSetting.define_attribute_methods
end end
def reset_column_information(klass)
klass.reset_column_information
end
def previous_migration def previous_migration
migrations.each_cons(2) do |previous, migration| migrations.each_cons(2) do |previous, migration|
break previous if migration.name == described_class.name 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