Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-02 06:09:04 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-02 06:09:04 +0300
commitceb0c326ae57bac76fe40ca3471b0ee5d152f58e (patch)
treeb13351e5e59f6275608b6715ed4afc98ec3c6227 /lib/gitlab/patch
parent61a1ecc5e9a8fba5c8cfa37a67905fb71ccf4fd0 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/patch')
-rw-r--r--lib/gitlab/patch/legacy_database_config.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/gitlab/patch/legacy_database_config.rb b/lib/gitlab/patch/legacy_database_config.rb
new file mode 100644
index 00000000000..a7d4fdf7490
--- /dev/null
+++ b/lib/gitlab/patch/legacy_database_config.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+# The purpose of this code is to transform legacy `database.yml`
+# into a `database.yml` containing `main:` as a name of a first database
+#
+# This should be removed once all places using legacy `database.yml`
+# are fixed. The likely moment to remove this check is the %14.0.
+#
+# This converts the following syntax:
+#
+# production:
+# adapter: postgresql
+# database: gitlabhq_production
+# username: git
+# password: "secure password"
+# host: localhost
+#
+# Into:
+#
+# production:
+# main:
+# adapter: postgresql
+# database: gitlabhq_production
+# username: git
+# password: "secure password"
+# host: localhost
+#
+
+module Gitlab
+ module Patch
+ module LegacyDatabaseConfig
+ extend ActiveSupport::Concern
+
+ prepended do
+ attr_reader :uses_legacy_database_config
+ end
+
+ def database_configuration
+ @uses_legacy_database_config = false # rubocop:disable Gitlab/ModuleWithInstanceVariables
+
+ super.to_h do |env, configs|
+ # 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
+
+ [env, configs]
+ end
+ end
+ end
+ end
+end