diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /lib/gitlab/database.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'lib/gitlab/database.rb')
-rw-r--r-- | lib/gitlab/database.rb | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index aa419d75df2..a269b8d0366 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -2,15 +2,15 @@ module Gitlab module Database + CI_DATABASE_NAME = 'ci' + # This constant is used when renaming tables concurrently. # If you plan to rename a table using the `rename_table_safely` method, add your table here one milestone before the rename. # Example: # TABLES_TO_BE_RENAMED = { # 'old_name' => 'new_name' # }.freeze - TABLES_TO_BE_RENAMED = { - 'services' => 'integrations' - }.freeze + TABLES_TO_BE_RENAMED = {}.freeze # Minimum PostgreSQL version requirement per documentation: # https://docs.gitlab.com/ee/install/requirements.html#postgresql-requirements @@ -68,6 +68,25 @@ module Gitlab end end + def self.has_config?(database_name) + Gitlab::Application.config.database_configuration[Rails.env].include?(database_name.to_s) + end + + def self.main_database?(name) + # The database is `main` if it is a first entry in `database.yml` + # Rails internally names them `primary` to avoid confusion + # with broad `primary` usage we use `main` instead + # + # TODO: The explicit `== 'main'` is needed in a transition period till + # the `database.yml` is not migrated into `main:` syntax + # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65243 + ActiveRecord::Base.configurations.primary?(name.to_s) || name.to_s == 'main' + end + + def self.ci_database?(name) + name.to_s == CI_DATABASE_NAME + end + def self.username config['username'] || ENV['USER'] end @@ -333,6 +352,16 @@ module Gitlab end end + def self.dbname(ar_connection) + if ar_connection.respond_to?(:pool) && + ar_connection.pool.respond_to?(:db_config) && + ar_connection.pool.db_config.respond_to?(:database) + return ar_connection.pool.db_config.database + end + + 'unknown' + end + # inside_transaction? will return true if the caller is running within a transaction. Handles special cases # when running inside a test environment, where tests may be wrapped in transactions def self.inside_transaction? |