diff --git a/config/initializers/validate_database_config.rb b/config/initializers/validate_database_config.rb index d5e73cdc1ee730ef6f3e9f6c3ca0eee42696b39a..d381dbac2ed4aec06baba93319c822f47fd90840 100644 --- a/config/initializers/validate_database_config.rb +++ b/config/initializers/validate_database_config.rb @@ -4,12 +4,6 @@ return end -if Rails.application.config.uses_legacy_database_config - warn "WARNING: This installation of GitLab uses a deprecated syntax for 'config/database.yml'. " \ - "The support for this syntax will be removed in 15.0. " \ - "More information can be found here: https://gitlab.com/gitlab-org/gitlab/-/issues/338182" -end - if configurations = ActiveRecord::Base.configurations.configurations if configurations.first.name != Gitlab::Database::MAIN_DATABASE_NAME raise "ERROR: This installation of GitLab uses unsupported 'config/database.yml'. " \ diff --git a/ee/spec/lib/gitlab/patch/database_config_spec.rb b/ee/spec/lib/gitlab/patch/database_config_spec.rb index 5095a20d4b69cb05fd381a8ceca53f1396abadd5..34223cf07b05bd722ce2cb92b7d022ec6a1be75a 100644 --- a/ee/spec/lib/gitlab/patch/database_config_spec.rb +++ b/ee/spec/lib/gitlab/patch/database_config_spec.rb @@ -38,50 +38,10 @@ .and_return(instance_double('Pathname', read: database_geo_yml)) end - context 'when config/database_geo.yml use a new syntax' do - let(:database_geo_yml) do - <<-EOS - production: - geo: - adapter: postgresql - encoding: unicode - database: gitlabhq_geo_production - username: git - password: "secure password" - host: localhost - - development: - geo: - adapter: postgresql - encoding: unicode - database: gitlabhq_geo_development - username: postgres - password: "secure password" - host: localhost - variables: - statement_timeout: 15s - - test: &test - geo: - adapter: postgresql - encoding: unicode - database: gitlabhq_geo_test - username: postgres - password: - host: localhost - prepared_statements: false - variables: - statement_timeout: 15s - EOS - end - - include_examples 'hash containing geo: connection name' - end - - context 'when config/database_geo.yml use a legacy syntax' do - let(:database_geo_yml) do - <<-EOS - production: + let(:database_geo_yml) do + <<-EOS + production: + geo: adapter: postgresql encoding: unicode database: gitlabhq_geo_production @@ -89,7 +49,8 @@ password: "secure password" host: localhost - development: + development: + geo: adapter: postgresql encoding: unicode database: gitlabhq_geo_development @@ -99,7 +60,8 @@ variables: statement_timeout: 15s - test: &test + test: &test + geo: adapter: postgresql encoding: unicode database: gitlabhq_geo_test @@ -109,11 +71,10 @@ prepared_statements: false variables: statement_timeout: 15s - EOS - end - - include_examples 'hash containing geo: connection name' + EOS end + + include_examples 'hash containing geo: connection name' end end @@ -175,10 +136,9 @@ allow(File).to receive(:exist?).with(Rails.root.join("config/database_geo.yml")).and_return(false) end - context 'when config/database.yml use a new syntax' do - context 'and does not contain Geo settings' do - let(:database_yml) do - <<-EOS + context 'and does not contain Geo settings' do + let(:database_yml) do + <<-EOS production: main: adapter: postgresql @@ -210,15 +170,15 @@ prepared_statements: false variables: statement_timeout: 15s - EOS - end - - include_examples 'hash containing main: connection name' + EOS end - context 'contains Geo settings' do - let(:database_yml) do - <<-EOS + include_examples 'hash containing main: connection name' + end + + context 'contains Geo settings' do + let(:database_yml) do + <<-EOS production: main: adapter: postgresql @@ -276,54 +236,10 @@ prepared_statements: false variables: statement_timeout: 15s - EOS - end - - include_examples 'hash containing both main: and geo: connection names' - end - end - - context 'when config/database.yml use a legacy syntax' do - let(:database_yml) do - <<-EOS - production: - adapter: postgresql - encoding: unicode - database: gitlabhq_production - username: git - password: "secure password" - host: localhost - - development: - adapter: postgresql - encoding: unicode - database: gitlabhq_development - username: postgres - password: "secure password" - host: localhost - variables: - statement_timeout: 15s - - test: &test - adapter: postgresql - encoding: unicode - database: gitlabhq_test - username: postgres - password: - host: localhost - prepared_statements: false - variables: - statement_timeout: 15s EOS end - include_examples 'hash containing main: connection name' - - it 'configuration is legacy' do - configuration.database_configuration - - expect(configuration.uses_legacy_database_config).to eq(true) - end + include_examples 'hash containing both main: and geo: connection names' end end @@ -373,10 +289,9 @@ # rubocop:enable RSpec/AnyInstanceOf end - context 'when config/database.yml use a new syntax' do - context 'and does not contain Geo setting' do - let(:database_yml) do - <<-EOS + context 'and does not contain Geo setting' do + let(:database_yml) do + <<-EOS production: main: adapter: postgresql @@ -408,15 +323,15 @@ prepared_statements: false variables: statement_timeout: 15s - EOS - end - - include_examples 'hash containing both main: and geo: connection names' + EOS end - context 'contains Geo setting' do - let(:database_yml) do - <<-EOS + include_examples 'hash containing both main: and geo: connection names' + end + + context 'contains Geo setting' do + let(:database_yml) do + <<-EOS production: main: adapter: postgresql @@ -474,44 +389,6 @@ prepared_statements: false variables: statement_timeout: 15s - EOS - end - - include_examples 'hash containing both main: and geo: connection names' - end - end - - context 'when config/database.yml use a legacy syntax' do - let(:database_yml) do - <<-EOS - production: - adapter: postgresql - encoding: unicode - database: gitlabhq_production - username: git - password: "secure password" - host: localhost - - development: - adapter: postgresql - encoding: unicode - database: gitlabhq_development - username: postgres - password: "secure password" - host: localhost - variables: - statement_timeout: 15s - - test: &test - adapter: postgresql - encoding: unicode - database: gitlabhq_test - username: postgres - password: - host: localhost - prepared_statements: false - variables: - statement_timeout: 15s EOS end diff --git a/lib/gitlab/patch/database_config.rb b/lib/gitlab/patch/database_config.rb index 702e8d404b12839ea1138ba035f4ae4fa8cbe206..c5c73d505187ba79e8a66cc2702b3b27ee3e8b22 100644 --- a/lib/gitlab/patch/database_config.rb +++ b/lib/gitlab/patch/database_config.rb @@ -31,10 +31,6 @@ module Patch module DatabaseConfig extend ActiveSupport::Concern - prepended do - attr_reader :uses_legacy_database_config - end - def load_database_yaml return super unless Gitlab.ee? @@ -70,24 +66,7 @@ def load_geo_database_yaml end def database_configuration - @uses_legacy_database_config = false # rubocop:disable Gitlab/ModuleWithInstanceVariables - super.to_h do |env, configs| - # TODO: To be removed in 15.0. See https://gitlab.com/gitlab-org/gitlab/-/issues/338182 - # This preload is needed to convert legacy `database.yml` - # from `production: adapter: postgresql` - # into a `production: main: adapter: postgresql` - unless Gitlab::Utils.to_boolean(ENV['SKIP_DATABASE_CONFIG_VALIDATION'], default: false) - # This check is taken from Rails where the transformation - # 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 - if Gitlab.ee? if !configs.key?("geo") && File.exist?(Rails.root.join("config/database_geo.yml")) configs["geo"] = Rails.application.config_for(:database_geo).stringify_keys diff --git a/spec/initializers/validate_database_config_spec.rb b/spec/initializers/validate_database_config_spec.rb index 209d96913507be5fc400839a4f6c03b54fa636d7..5f3f950a852cc41e7079211726cd27df100a0957 100644 --- a/spec/initializers/validate_database_config_spec.rb +++ b/spec/initializers/validate_database_config_spec.rb @@ -39,47 +39,23 @@ end context 'when config/database.yml is valid' do - context 'uses legacy syntax' do - let(:database_yml) do - <<-EOS - production: + let(:database_yml) do + <<-EOS + production: + main: adapter: postgresql encoding: unicode database: gitlabhq_production username: git password: "secure password" host: localhost - EOS - end - - it 'validates configuration with a warning' do - expect(main_object).to receive(:warn).with /uses a deprecated syntax for/ - - expect { subject }.not_to raise_error - end - - it_behaves_like 'with SKIP_DATABASE_CONFIG_VALIDATION=true' + EOS end - context 'uses new syntax' do - let(:database_yml) do - <<-EOS - production: - main: - adapter: postgresql - encoding: unicode - database: gitlabhq_production - username: git - password: "secure password" - host: localhost - EOS - end + it 'validates configuration without errors and warnings' do + expect(main_object).not_to receive(:warn) - it 'validates configuration without errors and warnings' do - expect(main_object).not_to receive(:warn) - - expect { subject }.not_to raise_error - end + expect { subject }.not_to raise_error end end diff --git a/spec/lib/gitlab/patch/database_config_spec.rb b/spec/lib/gitlab/patch/database_config_spec.rb index d6f36ab86d500a023946a6367a54ec348fe9a565..73dc84bb2ef293f3986ae0d3ac057bc7301403ee 100644 --- a/spec/lib/gitlab/patch/database_config_spec.rb +++ b/spec/lib/gitlab/patch/database_config_spec.rb @@ -34,9 +34,8 @@ end end - context 'when a new syntax is used' do - let(:database_yml) do - <<-EOS + let(:database_yml) do + <<-EOS production: main: adapter: postgresql @@ -68,59 +67,9 @@ prepared_statements: false variables: statement_timeout: 15s - EOS - end - - include_examples 'hash containing main: connection name' - - it 'configuration is not legacy one' do - configuration.database_configuration - - expect(configuration.uses_legacy_database_config).to eq(false) - end + EOS end - context 'when a legacy syntax is used' do - let(:database_yml) do - <<-EOS - production: - adapter: postgresql - encoding: unicode - database: gitlabhq_production - username: git - password: "secure password" - host: localhost - - development: - adapter: postgresql - encoding: unicode - database: gitlabhq_development - username: postgres - password: "secure password" - host: localhost - variables: - statement_timeout: 15s - - test: &test - adapter: postgresql - encoding: unicode - database: gitlabhq_test - username: postgres - password: - host: localhost - prepared_statements: false - variables: - statement_timeout: 15s - EOS - end - - include_examples 'hash containing main: connection name' - - it 'configuration is legacy' do - configuration.database_configuration - - expect(configuration.uses_legacy_database_config).to eq(true) - end - end + include_examples 'hash containing main: connection name' end end