Commit 2ddfd434 authored by Andreas Brandl's avatar Andreas Brandl

Add PostgresIndex.not_match scope

parent 4d761683
......@@ -21,6 +21,8 @@ module Gitlab
limit(how_many).order(Arel.sql('RANDOM()'))
end
scope :not_match, ->(regex) { where("name !~ ?", regex)}
def to_s
name
end
......
......@@ -30,7 +30,7 @@ RSpec.describe Gitlab::Database::PostgresIndex do
end
end
describe '#regular' do
describe '.regular' do
it 'only non-unique indexes' do
expect(described_class.regular).to all(have_attributes(unique: false))
end
......@@ -44,7 +44,17 @@ RSpec.describe Gitlab::Database::PostgresIndex do
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
expect(described_class.random_few(2).size).to eq(2)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment