diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-15 18:14:39 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-15 18:14:39 +0000 |
commit | 0f50c47cd7f7b88cc61e954d601b90fe7d12aac3 (patch) | |
tree | 8f376caa478ba32e57b665307970769ad7eecc34 /lib/gitlab/database.rb | |
parent | 78cfc7cf4afe0c7ffb72b8a9522b07873cd36820 (diff) | |
download | gitlab-ce-0f50c47cd7f7b88cc61e954d601b90fe7d12aac3.tar.gz |
Add latest changes from gitlab-org/gitlab@master
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? |