Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
fd2ea94f
Commit
fd2ea94f
authored
Jul 06, 2018
by
Brett Walker
Committed by
Robert Speicher
Jul 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ability to check if underlying database is read only
parent
0b1543e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
lib/gitlab/database.rb
lib/gitlab/database.rb
+15
-0
spec/lib/gitlab/database_spec.rb
spec/lib/gitlab/database_spec.rb
+29
-0
No files found.
lib/gitlab/database.rb
View file @
fd2ea94f
...
...
@@ -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
...
...
spec/lib/gitlab/database_spec.rb
View file @
fd2ea94f
...
...
@@ -357,6 +357,35 @@ describe Gitlab::Database do
end
end
describe
'.db_read_only?'
do
context
'when using PostgreSQL'
do
before
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:execute
).
and_call_original
expect
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
end
it
'detects a read only database'
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:execute
).
with
(
'SELECT pg_is_in_recovery()'
).
and_return
([{
"pg_is_in_recovery"
=>
"t"
}])
expect
(
described_class
.
db_read_only?
).
to
be_truthy
end
it
'detects a read write database'
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:execute
).
with
(
'SELECT pg_is_in_recovery()'
).
and_return
([{
"pg_is_in_recovery"
=>
"f"
}])
expect
(
described_class
.
db_read_only?
).
to
be_falsey
end
end
context
'when using MySQL'
do
before
do
expect
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
false
)
end
it
{
expect
(
described_class
.
db_read_only?
).
to
be_falsey
}
end
end
describe
'#sanitize_timestamp'
do
let
(
:max_timestamp
)
{
Time
.
at
((
1
<<
31
)
-
1
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment