Geo should use Rails 6 many databases support
**Promoted from https://gitlab.com/gitlab-org/gitlab/-/issues/331499** ## 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. ```ruby 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 ``` Use single `database.yml` instead of `database_geo.yml`: ```yaml production: main: host: postgres database: gitlabhq_production ... geo: host: postgres database: gitlabhq_geo_production ... development: ``` ## References - https://guides.rubyonrails.org/active_record_multiple_databases.html - https://tomkadwill.com/multiple-databases-in-rails
epic