Commit daaacbdc authored by Patrick Derichs's avatar Patrick Derichs Committed by Adam Hegyi

Add epic_id to resource_state_events

With foreign key to epics and index on epic_id
parent bd056f74
---
title: Add epic_id to resource_state_events
merge_request: 31587
author:
type: other
# frozen_string_literal: true
class AddEpicIdToResourceStateEvents < ActiveRecord::Migration[6.0]
DOWNTIME = false
INDEX_NAME = 'index_resource_state_events_on_epic_id'
def up
add_column :resource_state_events, :epic_id, :integer
add_index :resource_state_events, :epic_id, name: INDEX_NAME # rubocop:disable Migration/AddIndex
end
def down
remove_index :resource_state_events, name: INDEX_NAME # rubocop:disable Migration/RemoveIndex
remove_column :resource_state_events, :epic_id, :integer
end
end
# frozen_string_literal: true
class AddForeignKeyToEpicIdOnResourceStateEvents < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_foreign_key :resource_state_events, :epics, column: :epic_id, on_delete: :cascade # rubocop:disable Migration/AddConcurrentForeignKey
end
end
def down
with_lock_retries do
remove_foreign_key :resource_state_events, column: :epic_id
end
end
end
......@@ -5812,6 +5812,7 @@ CREATE TABLE public.resource_state_events (
merge_request_id bigint,
created_at timestamp with time zone NOT NULL,
state smallint NOT NULL,
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))))
);
......@@ -10521,6 +10522,8 @@ CREATE INDEX index_resource_milestone_events_on_milestone_id ON public.resource_
CREATE INDEX index_resource_milestone_events_on_user_id ON public.resource_milestone_events USING btree (user_id);
CREATE INDEX index_resource_state_events_on_epic_id ON public.resource_state_events USING btree (epic_id);
CREATE INDEX index_resource_state_events_on_issue_id_and_created_at ON public.resource_state_events USING btree (issue_id, created_at);
CREATE INDEX index_resource_state_events_on_merge_request_id ON public.resource_state_events USING btree (merge_request_id);
......@@ -12412,6 +12415,9 @@ ALTER TABLE ONLY public.vulnerability_occurrences
ALTER TABLE ONLY public.project_export_jobs
ADD CONSTRAINT fk_rails_c88d8db2e1 FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.resource_state_events
ADD CONSTRAINT fk_rails_c913c64977 FOREIGN KEY (epic_id) REFERENCES public.epics(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.resource_milestone_events
ADD CONSTRAINT fk_rails_c940fb9fc5 FOREIGN KEY (milestone_id) REFERENCES public.milestones(id) ON DELETE CASCADE;
......@@ -13809,6 +13815,8 @@ COPY "schema_migrations" (version) FROM STDIN;
20200506154421
20200507221434
20200508091106
20200511092246
20200511092505
20200511092714
20200511115430
20200511115431
......
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