Commit 861f5285 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'da-migrate-geo-tracking-database-configuration-into-database-yml' into 'master'

Geo migrations settings are included by default if database settings is present

See merge request gitlab-org/gitlab!83350
parents 2337789f b31d0afe
...@@ -69,18 +69,19 @@ module Gitlab ...@@ -69,18 +69,19 @@ module Gitlab
require_dependency Rails.root.join('lib/gitlab/middleware/handle_malformed_strings') require_dependency Rails.root.join('lib/gitlab/middleware/handle_malformed_strings')
require_dependency Rails.root.join('lib/gitlab/middleware/rack_multipart_tempfile_factory') require_dependency Rails.root.join('lib/gitlab/middleware/rack_multipart_tempfile_factory')
require_dependency Rails.root.join('lib/gitlab/runtime') require_dependency Rails.root.join('lib/gitlab/runtime')
require_dependency Rails.root.join('lib/gitlab/patch/legacy_database_config') require_dependency Rails.root.join('lib/gitlab/patch/database_config')
require_dependency Rails.root.join('lib/gitlab/exceptions_app') require_dependency Rails.root.join('lib/gitlab/exceptions_app')
config.exceptions_app = Gitlab::ExceptionsApp.new(Rails.public_path) config.exceptions_app = Gitlab::ExceptionsApp.new(Rails.public_path)
# To be removed in 15.0 # This preload is required to:
# This preload is needed to convert legacy `database.yml` #
# from `production: adapter: postgresql` # 1. Convert legacy `database.yml`;
# into a `production: main: adapter: postgresql` # 2. Include Geo post-deployment migrations settings;
unless Gitlab::Utils.to_boolean(ENV['SKIP_DATABASE_CONFIG_VALIDATION'], default: false) #
config.class.prepend(::Gitlab::Patch::LegacyDatabaseConfig) # TODO: In 15.0, this preload can be wrapped in a Gitlab.ee block
end # since we don't need to convert legacy `database.yml` anymore.
config.class.prepend(::Gitlab::Patch::DatabaseConfig)
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
module Gitlab module Gitlab
module Patch module Patch
module LegacyDatabaseConfig module DatabaseConfig
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
...@@ -73,23 +73,34 @@ module Gitlab ...@@ -73,23 +73,34 @@ module Gitlab
@uses_legacy_database_config = false # rubocop:disable Gitlab/ModuleWithInstanceVariables @uses_legacy_database_config = false # rubocop:disable Gitlab/ModuleWithInstanceVariables
super.to_h do |env, configs| super.to_h do |env, configs|
# This check is taken from Rails where the transformation # TODO: To be removed in 15.0. See https://gitlab.com/gitlab-org/gitlab/-/issues/338182
# of a flat database.yml is done into `primary:` # This preload is needed to convert legacy `database.yml`
# https://github.com/rails/rails/blob/v6.1.4/activerecord/lib/active_record/database_configurations.rb#L169 # from `production: adapter: postgresql`
if configs.is_a?(Hash) && !configs.all? { |_, v| v.is_a?(Hash) } # into a `production: main: adapter: postgresql`
configs = { "main" => configs } unless Gitlab::Utils.to_boolean(ENV['SKIP_DATABASE_CONFIG_VALIDATION'], default: false)
# This check is taken from Rails where the transformation
@uses_legacy_database_config = true # rubocop:disable Gitlab/ModuleWithInstanceVariables # of a flat database.yml is done into `primary:`
# https://github.com/rails/rails/blob/v6.1.4/activerecord/lib/active_record/database_configurations.rb#L169
if configs.is_a?(Hash) && !configs.all? { |_, v| v.is_a?(Hash) }
configs = { "main" => configs }
@uses_legacy_database_config = true # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
end end
if Gitlab.ee? && File.exist?(Rails.root.join("config/database_geo.yml")) if Gitlab.ee?
migrations_paths = ["ee/db/geo/migrate"] if !configs.key?("geo") && File.exist?(Rails.root.join("config/database_geo.yml"))
migrations_paths << "ee/db/geo/post_migrate" unless ENV['SKIP_POST_DEPLOYMENT_MIGRATIONS'] configs["geo"] = Rails.application.config_for(:database_geo).stringify_keys
end
if configs.key?("geo")
migrations_paths = Array(configs["geo"]["migrations_paths"])
migrations_paths << "ee/db/geo/migrate" if migrations_paths.empty?
migrations_paths << "ee/db/geo/post_migrate" unless ENV['SKIP_POST_DEPLOYMENT_MIGRATIONS']
configs["geo"] = configs["geo"]["migrations_paths"] = migrations_paths.uniq
Rails.application.config_for(:database_geo) configs["geo"]["schema_migrations_path"] = "ee/db/geo/schema_migrations" if configs["geo"]["schema_migrations_path"].blank?
.merge(migrations_paths: migrations_paths, schema_migrations_path: "ee/db/geo/schema_migrations") end
.stringify_keys
end end
[env, configs] [env, configs]
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Patch::LegacyDatabaseConfig do RSpec.describe Gitlab::Patch::DatabaseConfig do
it 'module is included' do it 'module is included' do
expect(Rails::Application::Configuration).to include(described_class) expect(Rails::Application::Configuration).to include(described_class)
end end
......
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