summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2018-07-06 17:07:49 +0000
committerRobert Speicher <robert@gitlab.com>2018-07-06 17:07:49 +0000
commitfd2ea94f60cb7ed81a666f321a8449449611bd2e (patch)
tree9f340ba9e375c1e49c5a1bd23971185fa73af794 /lib
parent0b1543e1c9b850ec35a6dfc0586f6b9588e9b953 (diff)
downloadgitlab-ce-fd2ea94f60cb7ed81a666f321a8449449611bd2e.tar.gz
Ability to check if underlying database is read only
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/database.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb
index 4ad106e7b0a..872e70f9a5d 100644
--- a/lib/gitlab/database.rb
+++ b/lib/gitlab/database.rb
@@ -42,6 +42,21 @@ module Gitlab
!self.read_only?
end
+ # check whether the underlying database is in read-only mode
+ def self.db_read_only?
+ if postgresql?
+ ActiveRecord::Base.connection.execute('SELECT pg_is_in_recovery()')
+ .first
+ .fetch('pg_is_in_recovery') == 't'
+ else
+ false
+ end
+ end
+
+ def self.db_read_write?
+ !self.db_read_only?
+ end
+
def self.version
@version ||= database_version.match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1]
end