From cb08762e7c878e3dd0a1ca9f922f387f8b8e453a Mon Sep 17 00:00:00 2001 From: Mathieu Parent <math.parent@gmail.com> Date: Mon, 14 Jun 2021 14:41:31 +0200 Subject: [PATCH] Add unique index for Helm packages Changelog: added --- ...43954_add_unique_index_for_helm_packages.rb | 18 ++++++++++++++++++ db/schema_migrations/20210614143954 | 1 + db/structure.sql | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 db/migrate/20210614143954_add_unique_index_for_helm_packages.rb create mode 100644 db/schema_migrations/20210614143954 diff --git a/db/migrate/20210614143954_add_unique_index_for_helm_packages.rb b/db/migrate/20210614143954_add_unique_index_for_helm_packages.rb new file mode 100644 index 0000000000000..e6b7ba7616d7a --- /dev/null +++ b/db/migrate/20210614143954_add_unique_index_for_helm_packages.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddUniqueIndexForHelmPackages < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_packages_on_project_id_name_version_unique_when_helm' + PACKAGE_TYPE_HELM = 11 + + disable_ddl_transaction! + + def up + add_concurrent_index :packages_packages, [:project_id, :name, :version], unique: true, where: "package_type = #{PACKAGE_TYPE_HELM}", name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :packages_packages, INDEX_NAME + end +end diff --git a/db/schema_migrations/20210614143954 b/db/schema_migrations/20210614143954 new file mode 100644 index 0000000000000..7fd3ce9b49eee --- /dev/null +++ b/db/schema_migrations/20210614143954 @@ -0,0 +1 @@ +b958d65f1b3b43d7bcd2a703489132ba9a2ba1e0374d45533399355ce6be9365 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index fa72d72cb9da5..6de556b602f7b 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -24117,6 +24117,8 @@ CREATE UNIQUE INDEX index_packages_on_project_id_name_version_unique_when_generi CREATE UNIQUE INDEX index_packages_on_project_id_name_version_unique_when_golang ON packages_packages USING btree (project_id, name, version) WHERE (package_type = 8); +CREATE UNIQUE INDEX index_packages_on_project_id_name_version_unique_when_helm ON packages_packages USING btree (project_id, name, version) WHERE (package_type = 11); + CREATE INDEX index_packages_package_file_build_infos_on_package_file_id ON packages_package_file_build_infos USING btree (package_file_id); CREATE INDEX index_packages_package_file_build_infos_on_pipeline_id ON packages_package_file_build_infos USING btree (pipeline_id); -- GitLab