diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-17 13:07:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-17 13:07:47 +0300 |
commit | d670c3006e6e44901bce0d53cc4768d1d80ffa92 (patch) | |
tree | 8f65743c232e5b76850c4cc264ba15e1185815ff /db/migrate/20210608110760_add_requirement_test_reports_foreign_key.rb | |
parent | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-ee
Diffstat (limited to 'db/migrate/20210608110760_add_requirement_test_reports_foreign_key.rb')
-rw-r--r-- | db/migrate/20210608110760_add_requirement_test_reports_foreign_key.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/db/migrate/20210608110760_add_requirement_test_reports_foreign_key.rb b/db/migrate/20210608110760_add_requirement_test_reports_foreign_key.rb new file mode 100644 index 00000000000..e256bce6ae0 --- /dev/null +++ b/db/migrate/20210608110760_add_requirement_test_reports_foreign_key.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddRequirementTestReportsForeignKey < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + TARGET_TABLE = :requirements_management_test_reports + CONSTRAINT_NAME = 'requirements_test_reports_requirement_id_xor_issue_id' + + def up + add_concurrent_foreign_key TARGET_TABLE, :issues, column: :issue_id + + add_check_constraint(TARGET_TABLE, 'num_nonnulls(requirement_id, issue_id) = 1', CONSTRAINT_NAME) + end + + def down + remove_check_constraint TARGET_TABLE, CONSTRAINT_NAME + + with_lock_retries do + remove_foreign_key_if_exists(TARGET_TABLE, column: :issue_id) + end + end +end |