diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /db/migrate/20220907115806_add_security_orchestration_policy_configuration_id.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'db/migrate/20220907115806_add_security_orchestration_policy_configuration_id.rb')
-rw-r--r-- | db/migrate/20220907115806_add_security_orchestration_policy_configuration_id.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/db/migrate/20220907115806_add_security_orchestration_policy_configuration_id.rb b/db/migrate/20220907115806_add_security_orchestration_policy_configuration_id.rb new file mode 100644 index 00000000000..de83288a0ca --- /dev/null +++ b/db/migrate/20220907115806_add_security_orchestration_policy_configuration_id.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +class AddSecurityOrchestrationPolicyConfigurationId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + PROJECT_INDEX_NAME = 'idx_approval_project_rules_on_sec_orchestration_config_id' + MERGE_REQUEST_INDEX_NAME = 'idx_approval_merge_request_rules_on_sec_orchestration_config_id' + + def up + with_lock_retries do + unless column_exists?(:approval_project_rules, :security_orchestration_policy_configuration_id) + add_column :approval_project_rules, :security_orchestration_policy_configuration_id, :bigint + end + end + + with_lock_retries do + unless column_exists?(:approval_merge_request_rules, :security_orchestration_policy_configuration_id) + add_column :approval_merge_request_rules, :security_orchestration_policy_configuration_id, :bigint + end + end + + add_concurrent_index :approval_project_rules, + :security_orchestration_policy_configuration_id, + name: PROJECT_INDEX_NAME + add_concurrent_index :approval_merge_request_rules, + :security_orchestration_policy_configuration_id, + name: MERGE_REQUEST_INDEX_NAME + + add_concurrent_foreign_key :approval_project_rules, + :security_orchestration_policy_configurations, + column: :security_orchestration_policy_configuration_id, + on_delete: :cascade + add_concurrent_foreign_key :approval_merge_request_rules, + :security_orchestration_policy_configurations, + column: :security_orchestration_policy_configuration_id, + on_delete: :cascade + end + + def down + with_lock_retries do + if column_exists?(:approval_project_rules, :security_orchestration_policy_configuration_id) + remove_column :approval_project_rules, :security_orchestration_policy_configuration_id + end + end + + with_lock_retries do + if column_exists?(:approval_merge_request_rules, :security_orchestration_policy_configuration_id) + remove_column :approval_merge_request_rules, :security_orchestration_policy_configuration_id + end + end + + remove_foreign_key_if_exists :approval_project_rules, column: :security_orchestration_policy_configuration_id + remove_foreign_key_if_exists :approval_merge_request_rules, column: :security_orchestration_policy_configuration_id + + remove_concurrent_index_by_name :approval_project_rules, name: PROJECT_INDEX_NAME + remove_concurrent_index_by_name :approval_merge_request_rules, name: MERGE_REQUEST_INDEX_NAME + end +end |