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

Enforce `gitlab:db:validate_config` in production

This is required to ensure that if migrations are "skipped"
are correctly skipped.
parent 8e8d3bdf
......@@ -85,9 +85,13 @@ namespace :gitlab do
warnings.unshift("Database config validation failure:")
# Warn (for now) by default in production environment
if Gitlab::Utils.to_boolean(ENV['GITLAB_VALIDATE_DATABASE_CONFIG'], default: Gitlab.dev_or_test_env?)
if Gitlab::Utils.to_boolean(ENV['GITLAB_VALIDATE_DATABASE_CONFIG'], default: true)
warnings << "Use `export GITLAB_VALIDATE_DATABASE_CONFIG=0` to ignore this validation."
raise warnings.join("\n")
else
warnings << "Use `export GITLAB_VALIDATE_DATABASE_CONFIG=1` to enforce this validation."
warn warnings.join("\n")
end
end
......
......@@ -270,9 +270,6 @@ RSpec.describe Gitlab::Database do
before do
skip_if_multiple_databases_not_setup
# This is currently required as otherwise the `Ci::Build.connection` == `Project.connection`
# ENV due to lib/gitlab/database/load_balancing/setup.rb:93
stub_env('GITLAB_USE_MODEL_LOAD_BALANCING', '1')
# FF due to lib/gitlab/database/load_balancing/configuration.rb:92
# Requires usage of `:request_store`
stub_feature_flags(force_no_sharing_primary_model: true)
......
......@@ -72,18 +72,23 @@ RSpec.describe 'gitlab:db:validate_config', :silence_stdout do
expect { run_rake_task('gitlab:db:validate_config') }.to raise_error(match)
end
it 'to stderr instead of exception for production' do
it 'for production' do
allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
expect { run_rake_task('gitlab:db:validate_config') }.to output(match).to_stderr
expect { run_rake_task('gitlab:db:validate_config') }.to raise_error(match)
end
it 'if GITLAB_VALIDATE_DATABASE_CONFIG is set' do
it 'if GITLAB_VALIDATE_DATABASE_CONFIG=1' do
stub_env('GITLAB_VALIDATE_DATABASE_CONFIG', '1')
allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
expect { run_rake_task('gitlab:db:validate_config') }.to raise_error(match)
end
it 'to stderr if GITLAB_VALIDATE_DATABASE_CONFIG=0' do
stub_env('GITLAB_VALIDATE_DATABASE_CONFIG', '0')
expect { run_rake_task('gitlab:db:validate_config') }.to output(match).to_stderr
end
end
context 'when only main: is specified' do
......
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