Commit 631cfa7e authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'update-state-events-constraint-to-support-epic-id' into 'master'

Add constraint to resource_state_events table to check for valid issuable setup

See merge request gitlab-org/gitlab!32517
parents 09be9304 d3d4d020
# 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_epic'
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
...@@ -5895,7 +5895,7 @@ CREATE TABLE public.resource_state_events ( ...@@ -5895,7 +5895,7 @@ CREATE TABLE public.resource_state_events (
created_at timestamp with time zone NOT NULL, created_at timestamp with time zone NOT NULL,
state smallint NOT NULL, state smallint NOT NULL,
epic_id integer, epic_id integer,
CONSTRAINT resource_state_events_must_belong_to_issue_or_merge_request CHECK ((((issue_id <> NULL::bigint) AND (merge_request_id IS NULL)) OR ((merge_request_id <> NULL::bigint) AND (issue_id IS NULL)))) CONSTRAINT resource_state_events_must_belong_to_issue_or_merge_request_or_ CHECK ((((issue_id <> NULL::bigint) AND (merge_request_id IS NULL) AND (epic_id IS NULL)) OR ((issue_id IS NULL) AND (merge_request_id <> NULL::bigint) AND (epic_id IS NULL)) OR ((issue_id IS NULL) AND (merge_request_id IS NULL) AND (epic_id <> NULL::integer))))
); );
CREATE SEQUENCE public.resource_state_events_id_seq CREATE SEQUENCE public.resource_state_events_id_seq
...@@ -14026,6 +14026,7 @@ COPY "schema_migrations" (version) FROM STDIN; ...@@ -14026,6 +14026,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200515155620 20200515155620
20200518091745 20200518091745
20200518133123 20200518133123
20200519074709
20200519101002 20200519101002
20200519115908 20200519115908
20200519171058 20200519171058
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment