Commit 1985abb9 authored by Yannis Roussos's avatar Yannis Roussos

Fix copy_indexes helper when an index has opclass

Fix the Fix copy_indexes migration helper failing to
properly set the opclass of the new index when the old
index has opclasses like gin_trgm_ops defined for it
parent 53fe3d8d
---
title: Fix copy_indexes migration helper skipping the opclass for indexes
with operator classes defined for them
merge_request: 43471
author:
type: fixed
......@@ -882,7 +882,7 @@ module Gitlab
# column.
opclasses[new] = opclasses.delete(old) if opclasses[old]
options[:opclasses] = opclasses
options[:opclass] = opclasses
end
add_concurrent_index(table, new_columns, options)
......
......@@ -1128,7 +1128,65 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
name: 'index_on_issues_gl_project_id',
length: [],
order: [],
opclasses: { 'gl_project_id' => 'bar' })
opclass: { 'gl_project_id' => 'bar' })
model.copy_indexes(:issues, :project_id, :gl_project_id)
end
end
context 'using an index with multiple columns and custom operator classes' do
it 'copies the index' do
index = double(:index,
columns: %w(project_id foobar),
name: 'index_on_issues_project_id_foobar',
using: :gin,
where: nil,
opclasses: { 'project_id' => 'bar', 'foobar' => :gin_trgm_ops },
unique: false,
lengths: [],
orders: [])
allow(model).to receive(:indexes_for).with(:issues, 'project_id')
.and_return([index])
expect(model).to receive(:add_concurrent_index)
.with(:issues,
%w(gl_project_id foobar),
unique: false,
name: 'index_on_issues_gl_project_id_foobar',
length: [],
order: [],
opclass: { 'gl_project_id' => 'bar', 'foobar' => :gin_trgm_ops },
using: :gin)
model.copy_indexes(:issues, :project_id, :gl_project_id)
end
end
context 'using an index with multiple columns and a custom operator class on the non affected column' do
it 'copies the index' do
index = double(:index,
columns: %w(project_id foobar),
name: 'index_on_issues_project_id_foobar',
using: :gin,
where: nil,
opclasses: { 'foobar' => :gin_trgm_ops },
unique: false,
lengths: [],
orders: [])
allow(model).to receive(:indexes_for).with(:issues, 'project_id')
.and_return([index])
expect(model).to receive(:add_concurrent_index)
.with(:issues,
%w(gl_project_id foobar),
unique: false,
name: 'index_on_issues_gl_project_id_foobar',
length: [],
order: [],
opclass: { 'foobar' => :gin_trgm_ops },
using: :gin)
model.copy_indexes(:issues, :project_id, :gl_project_id)
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