debian-mirror-gitlab/config/initializers/validate_database_config.rb

32 lines
1.5 KiB
Ruby
Raw Normal View History

2021-11-11 11:23:49 +05:30
# 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
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'. " \
"The `main:` database needs to be defined as a first configuration item instead of `#{configurations.first.name}`."
end
2022-01-26 12:08:38 +05:30
rejected_config_names = configurations.map(&:name).to_set - Gitlab::Database.all_database_names
2021-11-11 11:23:49 +05:30
if rejected_config_names.any?
raise "ERROR: This installation of GitLab uses unsupported database names " \
"in 'config/database.yml': #{rejected_config_names.to_a.join(", ")}. The only supported ones are " \
2022-01-26 12:08:38 +05:30
"#{Gitlab::Database.all_database_names.join(", ")}."
2021-11-11 11:23:49 +05:30
end
replicas_config_names = configurations.select(&:replica?).map(&:name)
if replicas_config_names.any?
raise "ERROR: This installation of GitLab uses unsupported database configuration " \
"with 'replica: true' parameter in 'config/database.yml' for: #{replicas_config_names.join(", ")}"
end
end