Commit b0503b37 authored by Kamil Trzciński's avatar Kamil Trzciński

Add `SKIP_DATABASE_CONFIG_VALIDATION` env

This allows to disable all transformation
and validation of database config.
parent 21f8aace
...@@ -39,7 +39,9 @@ module Gitlab ...@@ -39,7 +39,9 @@ module Gitlab
# This preload is needed to convert legacy `database.yml` # This preload is needed to convert legacy `database.yml`
# from `production: adapter: postgresql` # from `production: adapter: postgresql`
# into a `production: main: adapter: postgresql` # into a `production: main: adapter: postgresql`
config.class.prepend(::Gitlab::Patch::LegacyDatabaseConfig) unless Gitlab::Utils.to_boolean(ENV['SKIP_DATABASE_CONFIG_VALIDATION'], default: false)
config.class.prepend(::Gitlab::Patch::LegacyDatabaseConfig)
end
# 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
......
# frozen_string_literal: true # frozen_string_literal: true
if Gitlab::Utils.to_boolean(ENV['SKIP_DATABASE_CONFIG_VALIDATION'], default: false)
return
end
if Rails.application.config.uses_legacy_database_config if Rails.application.config.uses_legacy_database_config
warn "WARNING: This installation of GitLab uses a deprecated syntax for 'config/database.yml'. " \ 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. " \ "The support for this syntax will be removed in 15.0. " \
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'validate database config' do RSpec.describe 'validate database config' do
include RakeHelpers
include StubENV
let(:rails_configuration) { Rails::Application::Configuration.new(Rails.root) } let(:rails_configuration) { Rails::Application::Configuration.new(Rails.root) }
let(:ar_configurations) { ActiveRecord::DatabaseConfigurations.new(rails_configuration.database_configuration) } let(:ar_configurations) { ActiveRecord::DatabaseConfigurations.new(rails_configuration.database_configuration) }
...@@ -18,8 +21,18 @@ RSpec.describe 'validate database config' do ...@@ -18,8 +21,18 @@ RSpec.describe 'validate database config' do
.to receive(:read).with(Rails.root.join('config/database.yml')).and_return(database_yml) .to receive(:read).with(Rails.root.join('config/database.yml')).and_return(database_yml)
# rubocop:enable RSpec/AnyInstanceOf # rubocop:enable RSpec/AnyInstanceOf
allow(Rails.application).to receive(:configuration) { rails_configuration } allow(Rails.application).to receive(:config).and_return(rails_configuration)
allow(ActiveRecord::Base).to receive(:configurations) { ar_configurations } allow(ActiveRecord::Base).to receive(:configurations).and_return(ar_configurations)
end
shared_examples 'with SKIP_DATABASE_CONFIG_VALIDATION=true' do
before do
stub_env('SKIP_DATABASE_CONFIG_VALIDATION', 'true')
end
it 'does not raise exception' do
expect { subject }.not_to raise_error
end
end end
context 'when config/database.yml is valid' do context 'when config/database.yml is valid' do
...@@ -37,10 +50,12 @@ RSpec.describe 'validate database config' do ...@@ -37,10 +50,12 @@ RSpec.describe 'validate database config' do
end end
it 'validates configuration with a warning' do it 'validates configuration with a warning' do
expect(Kernel).not_to receive(:warn).with /uses a deprecated syntax for/ expect(main_object).to receive(:warn).with /uses a deprecated syntax for/
expect { subject }.not_to raise_error expect { subject }.not_to raise_error
end end
it_behaves_like 'with SKIP_DATABASE_CONFIG_VALIDATION=true'
end end
context 'uses new syntax' do context 'uses new syntax' do
...@@ -58,7 +73,7 @@ RSpec.describe 'validate database config' do ...@@ -58,7 +73,7 @@ RSpec.describe 'validate database config' do
end end
it 'validates configuration without errors and warnings' do it 'validates configuration without errors and warnings' do
expect(Kernel).not_to receive(:warn) expect(main_object).not_to receive(:warn)
expect { subject }.not_to raise_error expect { subject }.not_to raise_error
end end
...@@ -91,6 +106,8 @@ RSpec.describe 'validate database config' do ...@@ -91,6 +106,8 @@ RSpec.describe 'validate database config' do
it 'raises exception' do it 'raises exception' do
expect { subject }.to raise_error /This installation of GitLab uses unsupported database names/ expect { subject }.to raise_error /This installation of GitLab uses unsupported database names/
end end
it_behaves_like 'with SKIP_DATABASE_CONFIG_VALIDATION=true'
end end
context 'uses replica configuration' do context 'uses replica configuration' do
...@@ -111,6 +128,8 @@ RSpec.describe 'validate database config' do ...@@ -111,6 +128,8 @@ RSpec.describe 'validate database config' do
it 'raises exception' do it 'raises exception' do
expect { subject }.to raise_error /with 'replica: true' parameter in/ expect { subject }.to raise_error /with 'replica: true' parameter in/
end end
it_behaves_like 'with SKIP_DATABASE_CONFIG_VALIDATION=true'
end end
context 'main is not a first entry' do context 'main is not a first entry' do
...@@ -140,6 +159,8 @@ RSpec.describe 'validate database config' do ...@@ -140,6 +159,8 @@ RSpec.describe 'validate database config' do
it 'raises exception' do it 'raises exception' do
expect { subject }.to raise_error /The `main:` database needs to be defined as a first configuration item/ expect { subject }.to raise_error /The `main:` database needs to be defined as a first configuration item/
end end
it_behaves_like 'with SKIP_DATABASE_CONFIG_VALIDATION=true'
end end
end end
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