diff --git a/db/docs/batched_background_migrations/update_owasp_top10_default_of_vulnerability_reads.yml b/db/docs/batched_background_migrations/update_owasp_top10_default_of_vulnerability_reads.yml index 783b8e0612a01fa6268bc11ed5a335fde45d4bc3..5bd217c585808730d18e759a5c35ca1668562beb 100644 --- a/db/docs/batched_background_migrations/update_owasp_top10_default_of_vulnerability_reads.yml +++ b/db/docs/batched_background_migrations/update_owasp_top10_default_of_vulnerability_reads.yml @@ -5,4 +5,4 @@ feature_category: vulnerability_management introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/161962 milestone: '17.4' queued_migration_version: 20240806205657 -finalized_by: # version of the migration that finalized this BBM +finalized_by: 20241024183136 diff --git a/db/post_migrate/20241024183136_finalize_update_owasp_top10_default_of_vulnerability_reads.rb b/db/post_migrate/20241024183136_finalize_update_owasp_top10_default_of_vulnerability_reads.rb new file mode 100644 index 0000000000000000000000000000000000000000..16c21575019f7fab1eb2cf34d168c0edd104f414 --- /dev/null +++ b/db/post_migrate/20241024183136_finalize_update_owasp_top10_default_of_vulnerability_reads.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class FinalizeUpdateOwaspTop10DefaultOfVulnerabilityReads < Gitlab::Database::Migration[2.2] + milestone '17.6' + + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + ensure_batched_background_migration_is_finished( + job_class_name: "UpdateOwaspTop10DefaultOfVulnerabilityReads", + table_name: :vulnerability_reads, + column_name: :vulnerability_id, + job_arguments: [] + ) + end + + def down; end +end diff --git a/db/post_migrate/20241024183211_drop_tmp_index_for_owasp_null_on_vulnerability_reads.rb b/db/post_migrate/20241024183211_drop_tmp_index_for_owasp_null_on_vulnerability_reads.rb new file mode 100644 index 0000000000000000000000000000000000000000..e9b82aa9891145bdaa1f3e0c2ca85e06c7507c1d --- /dev/null +++ b/db/post_migrate/20241024183211_drop_tmp_index_for_owasp_null_on_vulnerability_reads.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DropTmpIndexForOwaspNullOnVulnerabilityReads < Gitlab::Database::Migration[2.2] + milestone '17.6' + + disable_ddl_transaction! + + TABLE_NAME = 'vulnerability_reads' + INDEX_NAME = 'tmp_index_for_owasp_null_on_vulnerability_reads' + + def up + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, [:vulnerability_id], name: INDEX_NAME, where: 'owasp_top_10 IS NULL' + end +end diff --git a/db/post_migrate/20241024183427_drop_tmp_idx_for_feedback_comment_processing.rb b/db/post_migrate/20241024183427_drop_tmp_idx_for_feedback_comment_processing.rb new file mode 100644 index 0000000000000000000000000000000000000000..8bcc5c1afe2cf5ba7e57133b4d2d4879cbf02662 --- /dev/null +++ b/db/post_migrate/20241024183427_drop_tmp_idx_for_feedback_comment_processing.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DropTmpIdxForFeedbackCommentProcessing < Gitlab::Database::Migration[2.2] + milestone '17.6' + + disable_ddl_transaction! + + TABLE_NAME = 'vulnerability_feedback' + INDEX_NAME = 'tmp_idx_for_feedback_comment_processing' + + def up + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, [:id], name: INDEX_NAME, where: 'char_length(comment) > 50000' + end +end diff --git a/db/post_migrate/20241024183459_drop_tmp_idx_for_vulnerability_feedback_migration.rb b/db/post_migrate/20241024183459_drop_tmp_idx_for_vulnerability_feedback_migration.rb new file mode 100644 index 0000000000000000000000000000000000000000..5a2f9229385b31e030e20c9e37ce63dbbb91bf69 --- /dev/null +++ b/db/post_migrate/20241024183459_drop_tmp_idx_for_vulnerability_feedback_migration.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class DropTmpIdxForVulnerabilityFeedbackMigration < Gitlab::Database::Migration[2.2] + milestone '17.6' + + disable_ddl_transaction! + + TABLE_NAME = 'vulnerability_feedback' + INDEX_NAME = 'tmp_idx_for_vulnerability_feedback_migration' + + def up + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, [:id], name: INDEX_NAME, + where: '(migrated_to_state_transition = false) AND (feedback_type = 0)' + end +end diff --git a/db/post_migrate/20241024183548_drop_tmp_index_for_succeeded_security_scans.rb b/db/post_migrate/20241024183548_drop_tmp_index_for_succeeded_security_scans.rb new file mode 100644 index 0000000000000000000000000000000000000000..a2adac7fc9b6d13461e7d9ca2be9b8403589f3a5 --- /dev/null +++ b/db/post_migrate/20241024183548_drop_tmp_index_for_succeeded_security_scans.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DropTmpIndexForSucceededSecurityScans < Gitlab::Database::Migration[2.2] + milestone '17.6' + + disable_ddl_transaction! + + TABLE_NAME = 'security_scans' + INDEX_NAME = 'tmp_index_for_succeeded_security_scans' + + def up + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, [:id], name: INDEX_NAME, where: 'status = 1' + end +end diff --git a/db/post_migrate/20241024183603_drop_tmp_index_on_vulnerabilities_non_dismissed.rb b/db/post_migrate/20241024183603_drop_tmp_index_on_vulnerabilities_non_dismissed.rb new file mode 100644 index 0000000000000000000000000000000000000000..5e421a121e71b5092e47020070d550a5d67f911c --- /dev/null +++ b/db/post_migrate/20241024183603_drop_tmp_index_on_vulnerabilities_non_dismissed.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DropTmpIndexOnVulnerabilitiesNonDismissed < Gitlab::Database::Migration[2.2] + milestone '17.6' + + disable_ddl_transaction! + + TABLE_NAME = 'vulnerabilities' + INDEX_NAME = 'tmp_index_on_vulnerabilities_non_dismissed' + + def up + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, [:id], name: INDEX_NAME, where: 'state <> 2' + end +end diff --git a/db/post_migrate/20241024183617_drop_tmp_index_vulnerability_overlong_title_html.rb b/db/post_migrate/20241024183617_drop_tmp_index_vulnerability_overlong_title_html.rb new file mode 100644 index 0000000000000000000000000000000000000000..ee951960e7446ec4f315b26359bec8bbb062f1ff --- /dev/null +++ b/db/post_migrate/20241024183617_drop_tmp_index_vulnerability_overlong_title_html.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DropTmpIndexVulnerabilityOverlongTitleHtml < Gitlab::Database::Migration[2.2] + milestone '17.6' + + disable_ddl_transaction! + + TABLE_NAME = 'vulnerabilities' + INDEX_NAME = 'tmp_index_vulnerability_overlong_title_html' + + def up + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, [:id], name: INDEX_NAME, where: 'length(title_html) > 800' + end +end diff --git a/db/schema_migrations/20241024183136 b/db/schema_migrations/20241024183136 new file mode 100644 index 0000000000000000000000000000000000000000..66370b4d310e5faac536a968ffa70ab4150c82b9 --- /dev/null +++ b/db/schema_migrations/20241024183136 @@ -0,0 +1 @@ +dc555f7bd357fa57a44d53496126c96cbb55c08165f65b1c245edd0fd8fc6762 \ No newline at end of file diff --git a/db/schema_migrations/20241024183211 b/db/schema_migrations/20241024183211 new file mode 100644 index 0000000000000000000000000000000000000000..5dad53e88c12a5d7b775a6cb46245af19fab86b3 --- /dev/null +++ b/db/schema_migrations/20241024183211 @@ -0,0 +1 @@ +f60e353f87d6dce6e4c2c056d510db7408334f6c6373d010999202ede2761a05 \ No newline at end of file diff --git a/db/schema_migrations/20241024183427 b/db/schema_migrations/20241024183427 new file mode 100644 index 0000000000000000000000000000000000000000..71a8dd4aa6e5dc49a21e5d11f1bdbd276aec948c --- /dev/null +++ b/db/schema_migrations/20241024183427 @@ -0,0 +1 @@ +546aaaf617e43d4b33dc80ec78ae71cc28f299561f731156ee6c9350d5ae8dcf \ No newline at end of file diff --git a/db/schema_migrations/20241024183459 b/db/schema_migrations/20241024183459 new file mode 100644 index 0000000000000000000000000000000000000000..951851ba323d168584d0dc5ea4f4d8481a98b21c --- /dev/null +++ b/db/schema_migrations/20241024183459 @@ -0,0 +1 @@ +f9983661931c3e3658c9e6c735332e83f63240b0af8fb1f4e6621fb458e29523 \ No newline at end of file diff --git a/db/schema_migrations/20241024183548 b/db/schema_migrations/20241024183548 new file mode 100644 index 0000000000000000000000000000000000000000..7e881a11812b0eae1240853797a38d169384d02c --- /dev/null +++ b/db/schema_migrations/20241024183548 @@ -0,0 +1 @@ +9219385757dc068902e484030dc7fab4db833d6048f2183d810df5ea0013c958 \ No newline at end of file diff --git a/db/schema_migrations/20241024183603 b/db/schema_migrations/20241024183603 new file mode 100644 index 0000000000000000000000000000000000000000..f345bf80fd9633b1d3eded9bca129b091dda8523 --- /dev/null +++ b/db/schema_migrations/20241024183603 @@ -0,0 +1 @@ +63540e74ccbf820dfe63970a621251561d79f2a5aef791d0cbbe4d2c177e1739 \ No newline at end of file diff --git a/db/schema_migrations/20241024183617 b/db/schema_migrations/20241024183617 new file mode 100644 index 0000000000000000000000000000000000000000..9adbf47d08be02857f075cd1e089820ab78c3d64 --- /dev/null +++ b/db/schema_migrations/20241024183617 @@ -0,0 +1 @@ +e1727dbe662a718aaed60c38c611bb57baebc5eedc484cb38b55b735ac6e2bf0 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index cb6a08c87c6b93b0e405c1e8c10c6eecec9df796..c979473112e9a541a0b85b341ea2f5b7555f200c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -32596,10 +32596,6 @@ CREATE INDEX temp_index_on_users_where_dark_theme ON users USING btree (id) WHER CREATE UNIQUE INDEX term_agreements_unique_index ON term_agreements USING btree (user_id, term_id); -CREATE INDEX tmp_idx_for_feedback_comment_processing ON vulnerability_feedback USING btree (id) WHERE (char_length(comment) > 50000); - -CREATE INDEX tmp_idx_for_vulnerability_feedback_migration ON vulnerability_feedback USING btree (id) WHERE ((migrated_to_state_transition = false) AND (feedback_type = 0)); - CREATE INDEX tmp_idx_orphaned_approval_merge_request_rules ON approval_merge_request_rules USING btree (id) WHERE ((report_type = ANY (ARRAY[2, 4])) AND (security_orchestration_policy_configuration_id IS NULL)); CREATE INDEX tmp_idx_orphaned_approval_project_rules ON approval_project_rules USING btree (id) WHERE ((report_type = ANY (ARRAY[2, 4])) AND (security_orchestration_policy_configuration_id IS NULL)); @@ -32610,24 +32606,16 @@ CREATE INDEX tmp_index_ci_job_artifacts_on_expire_at_where_locked_unknown ON ci_ CREATE INDEX tmp_index_for_null_member_namespace_id ON members USING btree (member_namespace_id) WHERE (member_namespace_id IS NULL); -CREATE INDEX tmp_index_for_owasp_null_on_vulnerability_reads ON vulnerability_reads USING btree (vulnerability_id) WHERE (owasp_top_10 IS NULL); - CREATE INDEX tmp_index_for_project_namespace_id_migration_on_routes ON routes USING btree (id) WHERE ((namespace_id IS NULL) AND ((source_type)::text = 'Project'::text)); -CREATE INDEX tmp_index_for_succeeded_security_scans ON security_scans USING btree (id) WHERE (status = 1); - CREATE UNIQUE INDEX tmp_index_issues_on_tmp_epic_id ON issues USING btree (tmp_epic_id); -CREATE INDEX tmp_index_on_vulnerabilities_non_dismissed ON vulnerabilities USING btree (id) WHERE (state <> 2); - CREATE INDEX tmp_index_packages_dependencies_on_id_without_project_id ON packages_dependencies USING btree (id) WHERE (project_id IS NULL); CREATE INDEX tmp_index_pats_on_notification_columns_and_expires_at ON personal_access_tokens USING btree (id) WHERE ((expire_notification_delivered IS TRUE) AND (seven_days_notification_sent_at IS NULL) AND (expires_at IS NOT NULL)); CREATE INDEX tmp_index_project_statistics_cont_registry_size ON project_statistics USING btree (project_id) WHERE (container_registry_size = 0); -CREATE INDEX tmp_index_vulnerability_overlong_title_html ON vulnerabilities USING btree (id) WHERE (length(title_html) > 800); - CREATE UNIQUE INDEX u_compliance_requirements_for_framework ON compliance_requirements USING btree (framework_id, name); CREATE UNIQUE INDEX u_project_compliance_standards_adherence_for_reporting ON project_compliance_standards_adherence USING btree (project_id, check_name, standard); diff --git a/spec/lib/gitlab/background_migration/update_owasp_top10_default_of_vulnerability_reads_spec.rb b/spec/lib/gitlab/background_migration/update_owasp_top10_default_of_vulnerability_reads_spec.rb index c14565d09522cb09289dbd884291c9703686eb4c..6a4b36a9705baf3ded2382e44391184c26e4fc85 100644 --- a/spec/lib/gitlab/background_migration/update_owasp_top10_default_of_vulnerability_reads_spec.rb +++ b/spec/lib/gitlab/background_migration/update_owasp_top10_default_of_vulnerability_reads_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Gitlab::BackgroundMigration::UpdateOwaspTop10DefaultOfVulnerabilityReads, feature_category: :vulnerability_management do +RSpec.describe Gitlab::BackgroundMigration::UpdateOwaspTop10DefaultOfVulnerabilityReads, + schema: 20241024183136, + feature_category: :vulnerability_management do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:users) { table(:users) }