Skip to content

Updates schema validation index query

What does this MR do and why?

Updates schema validation index query to exclude indexes that were created by constraints

How to set up and validate locally

  1. Switch to master

git checkout master

  1. Create some constraints. One contype x (EXCLUDE) and the other contype u (UNIQUE)
ALTER TABLE ONLY sprints ADD CONSTRAINT constraint_one EXCLUDE USING gist (iterations_cadence_id WITH =, daterange(start_date, due_date, '[]'::text) WITH &&) WHERE ((group_id IS NOT NULL)) DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE ONLY sprints ADD CONSTRAINT constraint_two UNIQUE (iterations_cadence_id, sequence) DEFERRABLE INITIALLY DEFERRED;
  1. In a rails console session, get the indexes
connection = Gitlab::Database.database_base_models[Gitlab::Database::MAIN_DATABASE_NAME].connection
database = Gitlab::Schema::Validation::Sources::Database.new(connection)

database.fetch_index_by_name('constraint_one')
=> #<Gitlab::Schema::Validation::SchemaObjects::Index:0x000000013d347518

database.fetch_index_by_name('constraint_two')
=> #<Gitlab::Schema::Validation::SchemaObjects::Index:0x000000013d346528
  1. Switch to this branch git checkout 390667-table-constraint-creates-a-new-index

  2. In a rails console session, .fetch_index_by_name should return nil

connection = Gitlab::Database.database_base_models[Gitlab::Database::MAIN_DATABASE_NAME].connection
database = Gitlab::Schema::Validation::Sources::Database.new(connection)

database.fetch_index_by_name('constraint_one')
=> nil

database.fetch_index_by_name('constraint_two')
=> nil

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #390667 (closed)

Edited by Leonardo da Rosa

Merge request reports

Loading