2021-09-01 23:09:04 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
if Gitlab::Utils.to_boolean(ENV['SKIP_DATABASE_CONFIG_VALIDATION'], default: false)
|
|
|
|
return
|
|
|
|
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
|
|
|
|
|
2021-12-10 13:14:42 -05:00
|
|
|
rejected_config_names = configurations.map(&:name).to_set - Gitlab::Database.all_database_names
|
2021-09-01 23:09:04 -04:00
|
|
|
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 " \
|
2021-12-10 13:14:42 -05:00
|
|
|
"#{Gitlab::Database.all_database_names.join(", ")}."
|
2021-09-01 23:09:04 -04:00
|
|
|
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
|