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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
692646e1
Commit
692646e1
authored
Nov 26, 2018
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rails5: Fix the check whether the database is in read-only mode
Rails 5 returns true/false instead of a string 't' or 'f'.
parent
3cd52365
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
4 deletions
+25
-4
ee/changelogs/unreleased/8581-geo-the-geo-nodes-admin-page-display-secondary-database-state-incorrectly.yml
...min-page-display-secondary-database-state-incorrectly.yml
+5
-0
lib/gitlab/database.rb
lib/gitlab/database.rb
+5
-3
spec/lib/gitlab/database_spec.rb
spec/lib/gitlab/database_spec.rb
+15
-1
No files found.
ee/changelogs/unreleased/8581-geo-the-geo-nodes-admin-page-display-secondary-database-state-incorrectly.yml
0 → 100644
View file @
692646e1
---
title
:
'
Rails
5:
Fix
the
check
whether
the
database
is
in
read-only
mode'
merge_request
:
8594
author
:
type
:
fixed
lib/gitlab/database.rb
View file @
692646e1
...
...
@@ -51,9 +51,11 @@ module Gitlab
# 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'
pg_is_in_recovery
=
ActiveRecord
::
Base
.
connection
.
execute
(
'SELECT pg_is_in_recovery()'
)
.
first
.
fetch
(
'pg_is_in_recovery'
)
Gitlab
::
Utils
.
to_boolean
(
pg_is_in_recovery
)
else
false
end
...
...
spec/lib/gitlab/database_spec.rb
View file @
692646e1
...
...
@@ -495,7 +495,7 @@ describe Gitlab::Database 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
)
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
end
it
'detects a read only database'
do
...
...
@@ -504,11 +504,25 @@ describe Gitlab::Database do
expect
(
described_class
.
db_read_only?
).
to
be_truthy
end
# TODO: remove rails5-only tag after removing rails4 tests
it
'detects a read only database'
,
:rails5
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:execute
).
with
(
'SELECT pg_is_in_recovery()'
).
and_return
([{
"pg_is_in_recovery"
=>
true
}])
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
# TODO: remove rails5-only tag after removing rails4 tests
it
'detects a read write database'
,
:rails5
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:execute
).
with
(
'SELECT pg_is_in_recovery()'
).
and_return
([{
"pg_is_in_recovery"
=>
false
}])
expect
(
described_class
.
db_read_only?
).
to
be_falsey
end
end
context
'when using MySQL'
do
...
...
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