diff --git a/db/post_migrate/20231219132423_remove_epic_id_column_from_vulnerabilities.rb b/db/post_migrate/20231219132423_remove_epic_id_column_from_vulnerabilities.rb new file mode 100644 index 0000000000000000000000000000000000000000..fa6379a409a3ad79f2b3bc2e3bdde215f15ce18e --- /dev/null +++ b/db/post_migrate/20231219132423_remove_epic_id_column_from_vulnerabilities.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveEpicIdColumnFromVulnerabilities < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + + milestone '16.8' + + def up + with_lock_retries do + remove_column :vulnerabilities, :epic_id + end + end + + def down + add_column :vulnerabilities, :epic_id, :bigint unless column_exists?(:vulnerabilities, :epic_id) + + # Add back index and constraint that were dropped in `up` + add_concurrent_index(:vulnerabilities, :epic_id) + add_concurrent_foreign_key(:vulnerabilities, :epics, column: :epic_id, on_delete: :nullify) + end +end diff --git a/db/schema_migrations/20231219132423 b/db/schema_migrations/20231219132423 new file mode 100644 index 0000000000000000000000000000000000000000..82fb1923c917acbcf2b010bbbeb8da91e56cf7d6 --- /dev/null +++ b/db/schema_migrations/20231219132423 @@ -0,0 +1 @@ +ed2b44c085d02dfb5e361f3f33dd62b9b5fed0e3ae570ff79936feadad66561a \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 37f769f427fcf048ea54975af960bafb3af39aab..98b874b69513ddbede4ba584a7ccad868221c091 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -25200,7 +25200,6 @@ ALTER SEQUENCE vs_code_settings_id_seq OWNED BY vs_code_settings.id; CREATE TABLE vulnerabilities ( id bigint NOT NULL, - epic_id bigint, project_id bigint NOT NULL, author_id bigint NOT NULL, created_at timestamp with time zone NOT NULL, @@ -35682,8 +35681,6 @@ CREATE INDEX index_vulnerabilities_on_detected_at_and_id ON vulnerabilities USIN CREATE INDEX index_vulnerabilities_on_dismissed_by_id ON vulnerabilities USING btree (dismissed_by_id); -CREATE INDEX index_vulnerabilities_on_epic_id ON vulnerabilities USING btree (epic_id); - CREATE INDEX index_vulnerabilities_on_finding_id ON vulnerabilities USING btree (finding_id); CREATE INDEX index_vulnerabilities_on_project_id_and_id ON vulnerabilities USING btree (project_id, id); @@ -38095,9 +38092,6 @@ ALTER TABLE ONLY project_statistics ALTER TABLE ONLY agent_project_authorizations ADD CONSTRAINT fk_1d30bb4987 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; -ALTER TABLE ONLY vulnerabilities - ADD CONSTRAINT fk_1d37cddf91 FOREIGN KEY (epic_id) REFERENCES epics(id) ON DELETE SET NULL; - ALTER TABLE ONLY boards ADD CONSTRAINT fk_1e9a074a35 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE; diff --git a/ee/spec/models/ee/vulnerability_spec.rb b/ee/spec/models/ee/vulnerability_spec.rb index d49fba31689548fed5a6108653709d81ea804317..2a3fc59a13f841bba2cec175ee976fcaf6924da7 100644 --- a/ee/spec/models/ee/vulnerability_spec.rb +++ b/ee/spec/models/ee/vulnerability_spec.rb @@ -29,7 +29,7 @@ let_it_be(:vulnerability) { create(:vulnerability, :sast, :confirmed, :low, :with_state_transition, project: project) } let_it_be(:finding) { create(:vulnerabilities_finding, vulnerability: vulnerability) } - it { is_expected.to have_locked_schema('a23fdde3fd14fefb7b51dd9bb5cdb0da62e0250d94c60f6b4e6576b223a8dffe').reference('https://gitlab.com/gitlab-org/gitlab/-/issues/349315') } + it { is_expected.to have_locked_schema('25e469a4d319ca5f4d0fd1511150028ba05509e55c8592922f9ce8f0c0e4df6f').reference('https://gitlab.com/gitlab-org/gitlab/-/issues/349315') } it_behaves_like 'vulnerability and finding shared examples' do let(:transformer_method) { :itself }