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
478a6dc6
Commit
478a6dc6
authored
Dec 15, 2020
by
Andreas Brandl
Committed by
Yannis Roussos
Dec 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the gitlab:db:reindex rake task
- Fix single-index invocation - Add console logging
parent
604e8d44
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
8 deletions
+22
-8
lib/tasks/gitlab/db.rake
lib/tasks/gitlab/db.rake
+11
-5
spec/tasks/gitlab/db_rake_spec.rb
spec/tasks/gitlab/db_rake_spec.rb
+11
-3
No files found.
lib/tasks/gitlab/db.rake
View file @
478a6dc6
...
@@ -192,11 +192,17 @@ namespace :gitlab do
...
@@ -192,11 +192,17 @@ namespace :gitlab do
exit
exit
end
end
indexes
=
if
args
[
:index_name
]
indexes
=
Gitlab
::
Database
::
Reindexing
.
candidate_indexes
[
Gitlab
::
Database
::
PostgresIndex
.
by_identifier
(
args
[
:index_name
])]
else
if
identifier
=
args
[
:index_name
]
Gitlab
::
Database
::
Reindexing
.
candidate_indexes
raise
ArgumentError
,
"Index name is not fully qualified with a schema:
#{
identifier
}
"
unless
identifier
=~
/^\w+\.\w+$/
end
indexes
=
indexes
.
where
(
identifier:
identifier
)
raise
"Index not found or not supported:
#{
args
[
:index_name
]
}
"
if
indexes
.
empty?
end
ActiveRecord
::
Base
.
logger
=
Logger
.
new
(
STDOUT
)
if
Gitlab
::
Utils
.
to_boolean
(
ENV
[
'LOG_QUERIES_TO_CONSOLE'
],
default:
false
)
Gitlab
::
Database
::
Reindexing
.
perform
(
indexes
)
Gitlab
::
Database
::
Reindexing
.
perform
(
indexes
)
rescue
=>
e
rescue
=>
e
...
...
spec/tasks/gitlab/db_rake_spec.rb
View file @
478a6dc6
...
@@ -246,17 +246,25 @@ RSpec.describe 'gitlab:db namespace rake task' do
...
@@ -246,17 +246,25 @@ RSpec.describe 'gitlab:db namespace rake task' do
context
'with index name given'
do
context
'with index name given'
do
let
(
:index
)
{
double
(
'index'
)
}
let
(
:index
)
{
double
(
'index'
)
}
before
do
allow
(
Gitlab
::
Database
::
Reindexing
).
to
receive
(
:candidate_indexes
).
and_return
(
indexes
)
end
it
'calls the index rebuilder with the proper arguments'
do
it
'calls the index rebuilder with the proper arguments'
do
expect
(
Gitlab
::
Database
::
PostgresIndex
).
to
receive
(
:by_identifier
).
with
(
'public.foo_idx'
).
and_return
(
index
)
allow
(
indexes
).
to
receive
(
:where
).
with
(
identifier:
'public.foo_idx'
).
and_return
([
index
]
)
expect
(
Gitlab
::
Database
::
Reindexing
).
to
receive
(
:perform
).
with
([
index
])
expect
(
Gitlab
::
Database
::
Reindexing
).
to
receive
(
:perform
).
with
([
index
])
run_rake_task
(
'gitlab:db:reindex'
,
'[public.foo_idx]'
)
run_rake_task
(
'gitlab:db:reindex'
,
'[public.foo_idx]'
)
end
end
it
'raises an error if the index does not exist'
do
it
'raises an error if the index does not exist'
do
expect
(
Gitlab
::
Database
::
PostgresIndex
).
to
receive
(
:by_identifier
).
with
(
'public.absent_index'
).
and_raise
(
ActiveRecord
::
RecordNotFound
)
allow
(
indexes
).
to
receive
(
:where
).
with
(
identifier:
'public.absent_index'
).
and_return
([])
expect
{
run_rake_task
(
'gitlab:db:reindex'
,
'[public.absent_index]'
)
}.
to
raise_error
(
/Index not found/
)
end
expect
{
run_rake_task
(
'gitlab:db:reindex'
,
'[public.absent_index]'
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
it
'raises an error if the index is not fully qualified with a schema'
do
expect
{
run_rake_task
(
'gitlab:db:reindex'
,
'[foo_idx]'
)
}.
to
raise_error
(
/Index name is not fully qualified/
)
end
end
end
end
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