Skip to content

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

What does this MR do?

The copy_indexes migration helper is failing to properly copy indexes with one or more operator classes defined for them.

The root cause of the issue was identified by @pbair and stems from a discrepancy between the indexes ActiveRecord method and the add_index one:

  1. indexes(table_name) returns the operator classes for all indexed columns through opclasses

  2. add_index(table_name, column_name, options = {}) accepts the operator classes for all indexed columns through the opclass hash key for options

    add_index(:developers, :name, using: 'gist', opclass: :gist_trgm_ops)
    add_index(:developers, [:name, :city], using: 'gist', opclass: { city: :gist_trgm_ops })

In the copy_indexes migration helper, we are using for both calls opclasses, so even though we are properly fetching the operator classes, we do not set them correctly when creating the new index.

This MR fixes that issue and adds additional specs to check for all the possible types of indexes with operator classes defined for them:

  • Index over one column with an operator class defined (existing spec which was updated)
  • Index over multiple columns all having an operator class
  • Index over multiple columns with only the second column having an operator class. I picked to the non affected column (not the one that was used with copy_indexes) to additionally test that case at the same time

Related issue: #256094 (closed)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Merge request reports