From 7de5f7ce28c4ed4fad5a6e9bbb8bcb752a1372aa Mon Sep 17 00:00:00 2001 From: Michael Becker <11881043-wandering_person@users.noreply.gitlab.com> Date: Tue, 19 Dec 2023 15:48:16 +0700 Subject: [PATCH] Drop `last_edited_by_id` Column From Vulnerabilities `last_edited_by_id` is an ignored column ([source][0]) This commit drops the column for step 2 of the [3-MR drop column process][1] Using the command `\d+ vulnerabilities` on [postgres.ai][2] indicates **there ARE indexes and constraints** As such, this migration includes adding back the index and FK constraint in the `down` method Related to https://gitlab.com/gitlab-org/gitlab/-/issues/268154 [0]:https://gitlab.com/gitlab-org/gitlab/-/blob/0ef7ab245a0952c68232b3a3418b673b912b5115/app/models/vulnerability.rb#L8-11 [1]:https://docs.gitlab.com/ee/development/database/avoiding_downtime_in_migrations.html#the-removed-column-has-an-index-or-constraint-that-belongs-to-it [2]:https://console.postgres.ai Changelog: removed --- ...dited_by_id_column_from_vulnerabilities.rb | 21 +++++++++++++++++++ db/schema_migrations/20231224083824 | 1 + db/structure.sql | 6 ------ ee/spec/models/ee/vulnerability_spec.rb | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 db/post_migrate/20231224083824_remove_last_edited_by_id_column_from_vulnerabilities.rb create mode 100644 db/schema_migrations/20231224083824 diff --git a/db/post_migrate/20231224083824_remove_last_edited_by_id_column_from_vulnerabilities.rb b/db/post_migrate/20231224083824_remove_last_edited_by_id_column_from_vulnerabilities.rb new file mode 100644 index 00000000000000..3df182db156155 --- /dev/null +++ b/db/post_migrate/20231224083824_remove_last_edited_by_id_column_from_vulnerabilities.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveLastEditedByIdColumnFromVulnerabilities < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + + milestone '16.8' + + def up + with_lock_retries do + remove_column :vulnerabilities, :last_edited_by_id + end + end + + def down + add_column :vulnerabilities, :last_edited_by_id, :bigint unless column_exists?(:vulnerabilities, :last_edited_by_id) + + # Add back index and constraint that were dropped in `up` + add_concurrent_index(:vulnerabilities, :last_edited_by_id) + add_concurrent_foreign_key(:vulnerabilities, :users, column: :last_edited_by_id, on_delete: :nullify) + end +end diff --git a/db/schema_migrations/20231224083824 b/db/schema_migrations/20231224083824 new file mode 100644 index 00000000000000..bd514723679625 --- /dev/null +++ b/db/schema_migrations/20231224083824 @@ -0,0 +1 @@ +d8cfd6b59da7a32b86aedaf1f6780774f7b70bc6a8cf675d91a63c4cc6dd94ea \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index dae7ce151c1bf5..3182561d4bfac7 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -24896,7 +24896,6 @@ CREATE TABLE vulnerabilities ( project_id bigint NOT NULL, author_id bigint NOT NULL, updated_by_id bigint, - last_edited_by_id bigint, start_date date, created_at timestamp with time zone NOT NULL, updated_at timestamp with time zone NOT NULL, @@ -35135,8 +35134,6 @@ CREATE INDEX index_vulnerabilities_on_epic_id ON vulnerabilities USING btree (ep CREATE INDEX index_vulnerabilities_on_finding_id ON vulnerabilities USING btree (finding_id); -CREATE INDEX index_vulnerabilities_on_last_edited_by_id ON vulnerabilities USING btree (last_edited_by_id); - CREATE INDEX index_vulnerabilities_on_milestone_id ON vulnerabilities USING btree (milestone_id); CREATE INDEX index_vulnerabilities_on_project_id_and_id ON vulnerabilities USING btree (project_id, id); @@ -37378,9 +37375,6 @@ ALTER TABLE ONLY project_pages_metadata ALTER TABLE ONLY group_deletion_schedules ADD CONSTRAINT fk_11e3ebfcdd FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; -ALTER TABLE ONLY vulnerabilities - ADD CONSTRAINT fk_1302949740 FOREIGN KEY (last_edited_by_id) REFERENCES users(id) ON DELETE SET NULL; - ALTER TABLE ONLY vulnerabilities ADD CONSTRAINT fk_131d289c65 FOREIGN KEY (milestone_id) REFERENCES milestones(id) ON DELETE SET NULL; diff --git a/ee/spec/models/ee/vulnerability_spec.rb b/ee/spec/models/ee/vulnerability_spec.rb index 6330ba9e7a5f47..162d0422ed63e1 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('cb13c5ef1e2f527aa7af69b2d8613551b6ec048628f4c10f65217657454b0bbb').reference('https://gitlab.com/gitlab-org/gitlab/-/issues/349315') } + it { is_expected.to have_locked_schema('af31520c7b44d816a185881ad7ca05728b8da3a3b0c5f55ca00b9c047e6e066f').reference('https://gitlab.com/gitlab-org/gitlab/-/issues/349315') } it_behaves_like 'vulnerability and finding shared examples' do let(:transformer_method) { :itself } -- GitLab