Commit 38548316 authored by Stan Hu's avatar Stan Hu

Merge branch '256094-fix-copy-indexes-migration-helper-opclass-replication' into 'master'

Fix copy_indexes migration helper failing for indexes with operator classes defined for them

See merge request gitlab-org/gitlab!43471
parents 2d18b08a 1985abb9
---
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