diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /lib/gitlab/database.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'lib/gitlab/database.rb')
-rw-r--r-- | lib/gitlab/database.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index f9c346a272f..9b32d285ec0 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -109,6 +109,26 @@ module Gitlab name.to_s == CI_DATABASE_NAME end + class PgUser < ApplicationRecord + self.table_name = 'pg_user' + self.primary_key = :usename + end + + # rubocop: disable CodeReuse/ActiveRecord + def self.check_for_non_superuser + user = PgUser.find_by('usename = CURRENT_USER') + am_i_superuser = user.usesuper + + Gitlab::AppLogger.info( + "Account details: User: \"#{user.usename}\", UseSuper: (#{am_i_superuser})" + ) + + raise 'Error: detected superuser' if am_i_superuser + rescue ActiveRecord::StatementInvalid + raise 'User CURRENT_USER not found' + end + # rubocop: enable CodeReuse/ActiveRecord + def self.check_postgres_version_and_print_warning return if Gitlab::Runtime.rails_runner? |