From fd2ea94f60cb7ed81a666f321a8449449611bd2e Mon Sep 17 00:00:00 2001 From: Brett Walker Date: Fri, 6 Jul 2018 17:07:49 +0000 Subject: Ability to check if underlying database is read only --- lib/gitlab/database.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/gitlab') 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 -- cgit v1.2.1