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
1e536581
Commit
1e536581
authored
Apr 02, 2021
by
Igor Drozdov
Committed by
Thong Kuah
May 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use symbols to access db config
DB configs keys are now represented as symbols, not strings
parent
74da7a21
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
22 deletions
+23
-22
ee/lib/ee/gitlab/database.rb
ee/lib/ee/gitlab/database.rb
+1
-3
ee/lib/gitlab/database/load_balancing.rb
ee/lib/gitlab/database/load_balancing.rb
+2
-2
ee/spec/lib/gitlab/database/load_balancing_spec.rb
ee/spec/lib/gitlab/database/load_balancing_spec.rb
+12
-11
lib/gitlab/database.rb
lib/gitlab/database.rb
+6
-4
spec/lib/gitlab/database_spec.rb
spec/lib/gitlab/database_spec.rb
+2
-2
No files found.
ee/lib/ee/gitlab/database.rb
View file @
1e536581
...
...
@@ -19,9 +19,7 @@ module EE
# Disables prepared statements for the current database connection.
def
disable_prepared_statements
config
=
ActiveRecord
::
Base
.
configurations
[
Rails
.
env
]
config
[
'prepared_statements'
]
=
false
config
=
::
Gitlab
::
Database
.
config
.
merge
(
prepared_statements:
false
)
ActiveRecord
::
Base
.
establish_connection
(
config
)
end
...
...
ee/lib/gitlab/database/load_balancing.rb
View file @
1e536581
...
...
@@ -36,7 +36,7 @@ module Gitlab
# Returns a Hash containing the load balancing configuration.
def
self
.
configuration
ActiveRecord
::
Base
.
configurations
[
Rails
.
env
][
'load_balancing'
]
||
{}
Gitlab
::
Database
.
config
[
:load_balancing
]
||
{}
end
# Returns the maximum replica lag size in bytes.
...
...
@@ -79,7 +79,7 @@ module Gitlab
end
def
self
.
pool_size
ActiveRecord
::
Base
.
configurations
[
Rails
.
env
][
'pool'
]
Gitlab
::
Database
.
config
[
:pool
]
end
# Returns true if load balancing is to be enabled.
...
...
ee/spec/lib/gitlab/database/load_balancing_spec.rb
View file @
1e536581
...
...
@@ -34,14 +34,13 @@ RSpec.describe Gitlab::Database::LoadBalancing do
describe
'.configuration'
do
it
'returns a Hash'
do
config
=
{
'hosts'
=>
%w(foo)
}
lb_
config
=
{
'hosts'
=>
%w(foo)
}
allow
(
ActiveRecord
::
Base
.
configurations
[
Rails
.
env
])
.
to
receive
(
:[]
)
.
with
(
'load_balancing'
)
.
and_return
(
config
)
original_db_config
=
Gitlab
::
Database
.
config
modified_db_config
=
original_db_config
.
merge
(
load_balancing:
lb_config
)
expect
(
Gitlab
::
Database
).
to
receive
(
:config
).
and_return
(
modified_db_config
)
expect
(
described_class
.
configuration
).
to
eq
(
config
)
expect
(
described_class
.
configuration
).
to
eq
(
lb_
config
)
end
end
...
...
@@ -436,7 +435,8 @@ RSpec.describe Gitlab::Database::LoadBalancing do
end
shared_context
'LoadBalancing setup'
do
let
(
:hosts
)
{
[
ActiveRecord
::
Base
.
configurations
[
"development"
][
'host'
]]
}
let
(
:development_db_config
)
{
ActiveRecord
::
Base
.
configurations
.
default_hash
(
"development"
).
with_indifferent_access
}
let
(
:hosts
)
{
[
development_db_config
[
:host
]]
}
let
(
:model
)
do
Class
.
new
(
ApplicationRecord
)
do
self
.
table_name
=
"load_balancing_test"
...
...
@@ -452,10 +452,11 @@ RSpec.describe Gitlab::Database::LoadBalancing do
clear_load_balancing_configuration
allow
(
ActiveRecord
::
Base
.
singleton_class
).
to
receive
(
:prepend
)
subject
.
configure_proxy
(
::
Gitlab
::
Database
::
LoadBalancing
::
ConnectionProxy
.
new
(
hosts
))
allow
(
ActiveRecord
::
Base
.
configurations
[
Rails
.
env
])
.
to
receive
(
:[]
)
.
with
(
'load_balancing'
)
.
and_return
(
'hosts'
=>
hosts
)
original_db_config
=
Gitlab
::
Database
.
config
modified_db_config
=
original_db_config
.
merge
(
load_balancing:
{
hosts:
hosts
})
allow
(
Gitlab
::
Database
).
to
receive
(
:config
).
and_return
(
modified_db_config
)
::
Gitlab
::
Database
::
LoadBalancing
::
Session
.
clear_session
end
end
...
...
lib/gitlab/database.rb
View file @
1e536581
...
...
@@ -44,7 +44,9 @@ module Gitlab
EXTRA_SCHEMAS
=
[
DYNAMIC_PARTITIONS_SCHEMA
,
STATIC_PARTITIONS_SCHEMA
].
freeze
def
self
.
config
ActiveRecord
::
Base
.
configurations
[
Rails
.
env
]
default_config_hash
=
ActiveRecord
::
Base
.
configurations
.
find_db_config
(
Rails
.
env
)
&
.
config
||
{}
default_config_hash
.
with_indifferent_access
end
def
self
.
username
...
...
@@ -225,9 +227,9 @@ module Gitlab
env
=
Rails
.
env
original_config
=
ActiveRecord
::
Base
.
configurations
.
to_h
env_config
=
original_config
[
env
].
merge
(
'pool'
=>
pool_size
)
env_config
[
'host'
]
=
host
if
host
env_config
[
'port'
]
=
port
if
port
env_config
=
original_config
[
env
].
with_indifferent_access
.
merge
(
pool:
pool_size
)
env_config
[
:host
]
=
host
if
host
env_config
[
:port
]
=
port
if
port
config
=
ActiveRecord
::
DatabaseConfigurations
.
new
(
original_config
.
merge
(
env
=>
env_config
)
...
...
spec/lib/gitlab/database_spec.rb
View file @
1e536581
...
...
@@ -16,8 +16,8 @@ RSpec.describe Gitlab::Database do
end
describe
'.config'
do
it
'returns a Hash'
do
expect
(
described_class
.
config
).
to
be_an_instance_of
(
Hash
)
it
'returns a Hash
WithIndifferentAccess
'
do
expect
(
described_class
.
config
).
to
be_an_instance_of
(
Hash
WithIndifferentAccess
)
end
end
...
...
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