Geo should use Rails 6 many databases support
Problem
Currently, Geo manually manages additional DB connections. This results in a number of overwrites to provide this kind of support.
It should rather depend on Rails 6 many databases support to reduce complexity of the implementation. This conflicts to some extent with many databases support and causes additional complexity on dealing with Geo doing something unique.
module Geo
class TrackingBase < ApplicationRecord
self.abstract_class = true
NOT_CONFIGURED_MSG = 'Geo secondary database is not configured'
SecondaryNotConfigured = Class.new(StandardError)
if ::Gitlab::Geo.geo_database_configured?
establish_connection Rails.configuration.geo_database
end
def self.connected?
return false unless ::Gitlab::Geo.geo_database_configured?
connection_handler.connected?(connection_specification_name)
end
def self.connection
unless ::Gitlab::Geo.geo_database_configured?
message = NOT_CONFIGURED_MSG
message = "#{message}\nIn the GDK root, try running `make geo-setup`" if Rails.env.development?
raise SecondaryNotConfigured, message
end
# Don't call super because LoadBalancing::ActiveRecordProxy will intercept it
retrieve_connection
rescue ActiveRecord::NoDatabaseError
raise SecondaryNotConfigured, NOT_CONFIGURED_MSG
end
end
end
Proposal
This needs subissues, in particular since it needs changes to omnibus-gitlab and charts.
-
Configure tracking database in database.yml
instead of customdatabase_geo.yml
-
Use connects_to
to make Geo models use the tracking database instead ofdef self.connection
override inGeo::TrackingBase
-
Use connected_to
block to manually use the tracking database instead ofGitlab::Geo::DatabaseTasks#set_db_env
-
Deprecate custom rake geo:db:*
rake tasks in favor of built-in tasksrake db:*:geo
-
Make sure the changes are backwards compatible across updates
References
Edited by Michael Kozono