summaryrefslogtreecommitdiff
path: root/db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb')
-rw-r--r--db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb b/db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb
new file mode 100644
index 00000000000..58b2471a96a
--- /dev/null
+++ b/db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class CreateForeignKeyOnContactsGroupId < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_customer_relations_contacts_on_group_id'
+
+ def up
+ add_concurrent_index :customer_relations_contacts, :group_id, name: INDEX_NAME
+ add_concurrent_foreign_key :customer_relations_contacts, :namespaces, column: :group_id
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :customer_relations_contacts, column: :group_id
+ end
+
+ remove_concurrent_index_by_name :customer_relations_contacts, INDEX_NAME
+ end
+end