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
2ddfd434
Commit
2ddfd434
authored
Oct 01, 2020
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PostgresIndex.not_match scope
parent
4d761683
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
lib/gitlab/database/postgres_index.rb
lib/gitlab/database/postgres_index.rb
+2
-0
spec/lib/gitlab/database/postgres_index_spec.rb
spec/lib/gitlab/database/postgres_index_spec.rb
+12
-2
No files found.
lib/gitlab/database/postgres_index.rb
View file @
2ddfd434
...
@@ -21,6 +21,8 @@ module Gitlab
...
@@ -21,6 +21,8 @@ module Gitlab
limit
(
how_many
).
order
(
Arel
.
sql
(
'RANDOM()'
))
limit
(
how_many
).
order
(
Arel
.
sql
(
'RANDOM()'
))
end
end
scope
:not_match
,
->
(
regex
)
{
where
(
"name !~ ?"
,
regex
)}
def
to_s
def
to_s
name
name
end
end
...
...
spec/lib/gitlab/database/postgres_index_spec.rb
View file @
2ddfd434
...
@@ -30,7 +30,7 @@ RSpec.describe Gitlab::Database::PostgresIndex do
...
@@ -30,7 +30,7 @@ RSpec.describe Gitlab::Database::PostgresIndex do
end
end
end
end
describe
'
#
regular'
do
describe
'
.
regular'
do
it
'only non-unique indexes'
do
it
'only non-unique indexes'
do
expect
(
described_class
.
regular
).
to
all
(
have_attributes
(
unique:
false
))
expect
(
described_class
.
regular
).
to
all
(
have_attributes
(
unique:
false
))
end
end
...
@@ -44,7 +44,17 @@ RSpec.describe Gitlab::Database::PostgresIndex do
...
@@ -44,7 +44,17 @@ RSpec.describe Gitlab::Database::PostgresIndex do
end
end
end
end
describe
'#random_few'
do
describe
'.not_match'
do
it
'excludes indexes matching the given regex'
do
expect
(
described_class
.
not_match
(
'^bar_k'
).
map
(
&
:name
)).
to
all
(
match
(
/^(?!bar_k).*/
))
end
it
'matches indexes without this prefix regex'
do
expect
(
described_class
.
not_match
(
'^bar_k'
)).
not_to
be_empty
end
end
describe
'.random_few'
do
it
'limits to two records by default'
do
it
'limits to two records by default'
do
expect
(
described_class
.
random_few
(
2
).
size
).
to
eq
(
2
)
expect
(
described_class
.
random_few
(
2
).
size
).
to
eq
(
2
)
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