Skip to content

Add group_id column to the services table

Arturo Herrero requested to merge 209824-add-group-id-to-services into master

What does this MR do?

In order to support group-level integrations &2543, we need to add a new column group_id to the services table.

This merge request adds group_id column to the services table which references the namespace table.

There are also some validations in place to check:

  • A service can belong to a project.
  • A service can belong to a group.
  • A service could be an instance-level integration.
  • A service could be a template integration.
  • Validate only one service type per group.

Migration script output

$ rails db:migrate
== 20200803111512 AddGroupIdToServices: migrating =============================
-- add_column(:services, :group_id, :bigint)
   -> 0.0012s
== 20200803111512 AddGroupIdToServices: migrated (0.0013s) ====================

== 20200803112806 AddIndexGroupIdToServices: migrating ========================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:services, [:group_id, :type], {:unique=>true, :name=>"index_services_on_unique_group_id_and_type", :algorithm=>:concurrently})
   -> 0.0039s
-- add_index(:services, [:group_id, :type], {:unique=>true, :name=>"index_services_on_unique_group_id_and_type", :algorithm=>:concurrently})
   -> 0.0029s
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:services)
   -> 0.0025s
-- execute("ALTER TABLE services\nADD CONSTRAINT fk_e8fe908a34\nFOREIGN KEY (group_id)\nREFERENCES namespaces (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0014s
-- execute("ALTER TABLE services VALIDATE CONSTRAINT fk_e8fe908a34;")
   -> 0.0024s
== 20200803112806 AddIndexGroupIdToServices: migrated (0.0210s) ===============
$ rails db:migrate:down VERSION=20200803112806
== 20200803112806 AddIndexGroupIdToServices: reverting ========================
-- foreign_keys(:services)
   -> 0.0033s
-- remove_foreign_key(:services, {:column=>:group_id})
   -> 0.0027s
-- transaction_open?()
   -> 0.0000s
-- indexes(:services)
   -> 0.0038s
-- remove_index(:services, {:algorithm=>:concurrently, :name=>"index_services_on_unique_group_id_and_type"})
   -> 0.0015s
== 20200803112806 AddIndexGroupIdToServices: reverted (0.0117s) ===============

$ rails db:migrate:down VERSION=20200803111512
== 20200803111512 AddGroupIdToServices: reverting =============================
-- remove_column(:services, :group_id, :bigint)
   -> 0.0013s
== 20200803111512 AddGroupIdToServices: reverted (0.0040s) ====================

Related to #209824 (closed)

Edited by Arturo Herrero

Merge request reports