diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20201119031515_add_iteration_id_to_lists.rb | 9 | ||||
-rw-r--r-- | db/migrate/20201119053603_add_iteration_lists_foreign_key.rb | 21 | ||||
-rw-r--r-- | db/post_migrate/20201130103926_schedule_populate_dismissed_state_for_vulnerabilities.rb | 62 | ||||
-rw-r--r-- | db/schema_migrations/20201119031515 | 1 | ||||
-rw-r--r-- | db/schema_migrations/20201119053603 | 1 | ||||
-rw-r--r-- | db/schema_migrations/20201130103926 | 1 | ||||
-rw-r--r-- | db/structure.sql | 10 |
7 files changed, 104 insertions, 1 deletions
diff --git a/db/migrate/20201119031515_add_iteration_id_to_lists.rb b/db/migrate/20201119031515_add_iteration_id_to_lists.rb new file mode 100644 index 00000000000..62e13f53e92 --- /dev/null +++ b/db/migrate/20201119031515_add_iteration_id_to_lists.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddIterationIdToLists < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :lists, :iteration_id, :bigint + end +end diff --git a/db/migrate/20201119053603_add_iteration_lists_foreign_key.rb b/db/migrate/20201119053603_add_iteration_lists_foreign_key.rb new file mode 100644 index 00000000000..8d9ec1f2e59 --- /dev/null +++ b/db/migrate/20201119053603_add_iteration_lists_foreign_key.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddIterationListsForeignKey < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_NAME = 'index_lists_on_iteration_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :lists, :iteration_id, name: INDEX_NAME + add_concurrent_foreign_key :lists, :sprints, column: :iteration_id, on_delete: :cascade + end + + def down + remove_foreign_key_if_exists :lists, :sprints, column: :iteration_id + remove_concurrent_index_by_name :lists, INDEX_NAME + end +end diff --git a/db/post_migrate/20201130103926_schedule_populate_dismissed_state_for_vulnerabilities.rb b/db/post_migrate/20201130103926_schedule_populate_dismissed_state_for_vulnerabilities.rb new file mode 100644 index 00000000000..5e8da532251 --- /dev/null +++ b/db/post_migrate/20201130103926_schedule_populate_dismissed_state_for_vulnerabilities.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class SchedulePopulateDismissedStateForVulnerabilities < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TMP_INDEX_NAME = 'tmp_index_on_vulnerabilities_non_dismissed' + + DOWNTIME = false + BATCH_SIZE = 1_000 + VULNERABILITY_BATCH_SIZE = 5_000 + DELAY_INTERVAL = 3.minutes.to_i + MIGRATION_CLASS = 'PopulateDismissedStateForVulnerabilities' + + VULNERABILITY_JOIN_CONDITION = 'JOIN "vulnerability_occurrences" ON "vulnerability_occurrences"."vulnerability_id" = "vulnerabilities"."id"' + FEEDBACK_WHERE_CONDITION = <<~SQL + EXISTS (SELECT 1 FROM vulnerability_feedback + WHERE "vulnerability_occurrences"."project_id" = "vulnerability_feedback"."project_id" + AND "vulnerability_occurrences"."report_type" = "vulnerability_feedback"."category" + AND ENCODE("vulnerability_occurrences"."project_fingerprint", 'hex') = "vulnerability_feedback"."project_fingerprint" + AND "vulnerability_feedback"."feedback_type" = 0 + ) + SQL + + class Vulnerability < ActiveRecord::Base # rubocop:disable Style/Documentation + include EachBatch + + self.table_name = 'vulnerabilities' + end + + disable_ddl_transaction! + + def up + add_concurrent_index(:vulnerabilities, :id, where: 'state <> 2', name: TMP_INDEX_NAME) + + batch = [] + index = 1 + + Vulnerability.where('state <> 2').each_batch(of: VULNERABILITY_BATCH_SIZE) do |relation| + ids = relation + .joins(VULNERABILITY_JOIN_CONDITION) + .where(FEEDBACK_WHERE_CONDITION) + .pluck('vulnerabilities.id') + + ids.each do |id| + batch << id + + if batch.size == BATCH_SIZE + migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, batch) + index += 1 + + batch.clear + end + end + end + + migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, batch) unless batch.empty? + end + + def down + remove_concurrent_index_by_name(:vulnerabilities, TMP_INDEX_NAME) + end +end diff --git a/db/schema_migrations/20201119031515 b/db/schema_migrations/20201119031515 new file mode 100644 index 00000000000..3abfe9de238 --- /dev/null +++ b/db/schema_migrations/20201119031515 @@ -0,0 +1 @@ +6d2e6937c9e41975b1fd402bf2985796792a1e5f8e4f4f98bc76b65ff73c4e02
\ No newline at end of file diff --git a/db/schema_migrations/20201119053603 b/db/schema_migrations/20201119053603 new file mode 100644 index 00000000000..7555dbfb2ca --- /dev/null +++ b/db/schema_migrations/20201119053603 @@ -0,0 +1 @@ +c7567489156bbc047cf9f7827f060ad507fd5d328179f2796566a7dc54806e3e
\ No newline at end of file diff --git a/db/schema_migrations/20201130103926 b/db/schema_migrations/20201130103926 new file mode 100644 index 00000000000..518d58860af --- /dev/null +++ b/db/schema_migrations/20201130103926 @@ -0,0 +1 @@ +27cd7e7cd01175c157e6aa666b2263bf29210277d5acd997a0619cee67870345
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 76af8d848c3..b757355ca22 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -13652,7 +13652,8 @@ CREATE TABLE lists ( milestone_id integer, max_issue_count integer DEFAULT 0 NOT NULL, max_issue_weight integer DEFAULT 0 NOT NULL, - limit_metric character varying(20) + limit_metric character varying(20), + iteration_id bigint ); CREATE SEQUENCE lists_id_seq @@ -21617,6 +21618,8 @@ CREATE UNIQUE INDEX index_list_user_preferences_on_user_id_and_list_id ON list_u CREATE UNIQUE INDEX index_lists_on_board_id_and_label_id ON lists USING btree (board_id, label_id); +CREATE INDEX index_lists_on_iteration_id ON lists USING btree (iteration_id); + CREATE INDEX index_lists_on_label_id ON lists USING btree (label_id); CREATE INDEX index_lists_on_list_type ON lists USING btree (list_type); @@ -22873,6 +22876,8 @@ CREATE INDEX tmp_build_stage_position_index ON ci_builds USING btree (stage_id, CREATE INDEX tmp_index_for_email_unconfirmation_migration ON emails USING btree (id) WHERE (confirmed_at IS NOT NULL); +CREATE INDEX tmp_index_on_vulnerabilities_non_dismissed ON vulnerabilities USING btree (id) WHERE (state <> 2); + CREATE UNIQUE INDEX unique_merge_request_metrics_by_merge_request_id ON merge_request_metrics USING btree (merge_request_id); CREATE UNIQUE INDEX vulnerability_feedback_unique_idx ON vulnerability_feedback USING btree (project_id, category, feedback_type, project_fingerprint); @@ -23263,6 +23268,9 @@ ALTER TABLE ONLY notes ALTER TABLE ONLY members ADD CONSTRAINT fk_2e88fb7ce9 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; +ALTER TABLE ONLY lists + ADD CONSTRAINT fk_30f2a831f4 FOREIGN KEY (iteration_id) REFERENCES sprints(id) ON DELETE CASCADE; + ALTER TABLE ONLY approvals ADD CONSTRAINT fk_310d714958 FOREIGN KEY (merge_request_id) REFERENCES merge_requests(id) ON DELETE CASCADE; |