summaryrefslogtreecommitdiff
path: root/db/migrate/20200519074709_update_resource_state_events_constraint_to_support_epic_id.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20200519074709_update_resource_state_events_constraint_to_support_epic_id.rb')
-rw-r--r--db/migrate/20200519074709_update_resource_state_events_constraint_to_support_epic_id.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/db/migrate/20200519074709_update_resource_state_events_constraint_to_support_epic_id.rb b/db/migrate/20200519074709_update_resource_state_events_constraint_to_support_epic_id.rb
new file mode 100644
index 00000000000..ff60e3bdac1
--- /dev/null
+++ b/db/migrate/20200519074709_update_resource_state_events_constraint_to_support_epic_id.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class UpdateResourceStateEventsConstraintToSupportEpicId < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ OLD_CONSTRAINT = 'resource_state_events_must_belong_to_issue_or_merge_request'
+ CONSTRAINT_NAME = 'resource_state_events_must_belong_to_issue_or_merge_request_or_'
+
+ def up
+ remove_check_constraint :resource_state_events, OLD_CONSTRAINT
+ add_check_constraint :resource_state_events, "(issue_id != NULL AND merge_request_id IS NULL AND epic_id IS NULL) OR " \
+ "(issue_id IS NULL AND merge_request_id != NULL AND epic_id IS NULL) OR" \
+ "(issue_id IS NULL AND merge_request_id IS NULL AND epic_id != NULL)", CONSTRAINT_NAME
+ end
+
+ def down
+ remove_check_constraint :resource_state_events, CONSTRAINT_NAME
+ add_check_constraint :resource_state_events, '(issue_id != NULL AND merge_request_id IS NULL) OR (merge_request_id != NULL AND issue_id IS NULL)', OLD_CONSTRAINT
+ end
+end