Skip to content

Validates only one service template per type

Arturo Herrero requested to merge unique-service-template-per-type into master

What does this MR do?

We want to make sure that we always have the correct state in the database.

This merge request validates that we only have one service template per type.

This is a follow-up from a recent incident gitlab-com/gl-infra/production#1651 (closed) and https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/9176 (internal).

== 20200303160801 DeleteTemplateServicesDuplicatedByType: migrating ===========
-- execute("DELETE\nFROM services\nWHERE TEMPLATE = TRUE\n  AND id NOT IN\n    (SELECT MIN(id)\n     FROM services\n     WHERE TEMPLATE = TRUE\n     GROUP BY TYPE);\n")
   -> 0.0033s
== 20200303160801 DeleteTemplateServicesDuplicatedByType: migrated (0.0034s) ==

== 20200303160823 AddIndexToServiceUniqueTemplatePerType: migrating ===========
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:services, [:type, :template], {:unique=>true, :where=>"template IS TRUE", :algorithm=>:concurrently})
   -> 0.0026s
-- execute("SET statement_timeout TO 0")
   -> 0.0008s
-- add_index(:services, [:type, :template], {:unique=>true, :where=>"template IS TRUE", :algorithm=>:concurrently})
   -> 0.0041s
-- execute("RESET ALL")
   -> 0.0006s
== 20200303160823 AddIndexToServiceUniqueTemplatePerType: migrated (0.0083s) ==

Related to #205419 (closed) and #207385 (closed).

Merge request reports