Skip to content

Add unique index on services project_id and type

Markus Koller requested to merge 207385-services-unique-constraint-on-type into master

What does this MR do?

This replaces the previous non-unique index on the same columns.

We don't expect any non-unique records after:

  • We enforced this for new records with a validation at the AR layer in !26308 (merged)
  • We cleaned up existing records with a data migration in #290008 (closed)

Verified in #database-lab that the new unique index can still be used for querying:

Related to #207385 (closed)

Migration Output

up

$ rake db:migrate:up VERSION=20210126091713
== 20210126091713 AddUniqueIndexServicesProjectIdAndType: migrating ===========
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:services, [:project_id, :type], {:name=>"index_services_on_project_id_and_type_unique", :unique=>true, :algorithm=>:concurrently})
   -> 0.0045s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- add_index(:services, [:project_id, :type], {:name=>"index_services_on_project_id_and_type_unique", :unique=>true, :algorithm=>:concurrently})
   -> 0.0140s
-- execute("RESET ALL")
   -> 0.0002s
== 20210126091713 AddUniqueIndexServicesProjectIdAndType: migrated (0.0194s) ==

$ rake db:migrate:up VERSION=20210126092102
== 20210126092102 RemoveIndexServicesProjectIdAndType: migrating ==============
-- transaction_open?()
   -> 0.0000s
-- indexes(:services)
   -> 0.0046s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- remove_index(:services, {:algorithm=>:concurrently, :name=>"index_services_on_project_id_and_type"})
   -> 0.0105s
-- execute("RESET ALL")
   -> 0.0003s
== 20210126092102 RemoveIndexServicesProjectIdAndType: migrated (0.0160s) =====

down

$ rake db:migrate:down VERSION=20210126092102
== 20210126092102 RemoveIndexServicesProjectIdAndType: reverting ==============
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:services, [:project_id, :type], {:name=>"index_services_on_project_id_and_type", :algorithm=>:concurrently})
   -> 0.0063s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- add_index(:services, [:project_id, :type], {:name=>"index_services_on_project_id_and_type", :algorithm=>:concurrently})
   -> 0.0055s
-- execute("RESET ALL")
   -> 0.0003s
== 20210126092102 RemoveIndexServicesProjectIdAndType: reverted (0.0130s) =====

$ rake db:migrate:down VERSION=20210126091713
== 20210126091713 AddUniqueIndexServicesProjectIdAndType: reverting ===========
-- transaction_open?()
   -> 0.0000s
-- indexes(:services)
   -> 0.0142s
-- execute("SET statement_timeout TO 0")
   -> 0.0008s
-- remove_index(:services, {:algorithm=>:concurrently, :name=>"index_services_on_project_id_and_type_unique"})
   -> 0.0043s
-- execute("RESET ALL")
   -> 0.0007s
== 20210126091713 AddUniqueIndexServicesProjectIdAndType: reverted (0.0216s) ==

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
Edited by Markus Koller

Merge request reports

Loading