summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 15:07:52 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 15:07:52 +0000
commitafe2b984524ae4b0c8a0636db7ec5b2c452f0734 (patch)
tree3de39f954c7239e09a9afe84263a64e7042b2b60 /db
parent5a6b36b60502c50ab59c0bc3c345793b70a3d548 (diff)
downloadgitlab-ce-afe2b984524ae4b0c8a0636db7ec5b2c452f0734.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20200304160801_delete_template_services_duplicated_by_type.rb25
-rw-r--r--db/migrate/20200304160823_add_index_to_service_unique_template_per_type.rb17
-rw-r--r--db/schema.rb3
3 files changed, 44 insertions, 1 deletions
diff --git a/db/migrate/20200304160801_delete_template_services_duplicated_by_type.rb b/db/migrate/20200304160801_delete_template_services_duplicated_by_type.rb
new file mode 100644
index 00000000000..a1c5161aea0
--- /dev/null
+++ b/db/migrate/20200304160801_delete_template_services_duplicated_by_type.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class DeleteTemplateServicesDuplicatedByType < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ # Delete service templates with duplicated types. Keep the service
+ # template with the lowest `id` because that is the service template used:
+ # https://gitlab.com/gitlab-org/gitlab/-/blob/v12.8.1-ee/app/controllers/admin/services_controller.rb#L37
+ execute <<~SQL
+ DELETE
+ FROM services
+ WHERE TEMPLATE = TRUE
+ AND id NOT IN
+ (SELECT MIN(id)
+ FROM services
+ WHERE TEMPLATE = TRUE
+ GROUP BY TYPE);
+ SQL
+ end
+
+ def down
+ # This migration cannot be reversed.
+ end
+end
diff --git a/db/migrate/20200304160823_add_index_to_service_unique_template_per_type.rb b/db/migrate/20200304160823_add_index_to_service_unique_template_per_type.rb
new file mode 100644
index 00000000000..b81e5acf67f
--- /dev/null
+++ b/db/migrate/20200304160823_add_index_to_service_unique_template_per_type.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexToServiceUniqueTemplatePerType < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(:services, [:type, :template], unique: true, where: 'template IS TRUE')
+ end
+
+ def down
+ remove_concurrent_index(:services, [:type, :template])
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a42d31160d2..2360c0f4025 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2020_03_04_090155) do
+ActiveRecord::Schema.define(version: 2020_03_04_160823) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@@ -3898,6 +3898,7 @@ ActiveRecord::Schema.define(version: 2020_03_04_090155) do
t.boolean "template", default: false
t.index ["project_id"], name: "index_services_on_project_id"
t.index ["template"], name: "index_services_on_template"
+ t.index ["type", "template"], name: "index_services_on_type_and_template", unique: true, where: "(template IS TRUE)"
t.index ["type"], name: "index_services_on_type"
end