summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-14 00:07:47 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-14 00:07:47 +0000
commite2d4a6dedbb55154ff9389dbe061fa74ccbae287 (patch)
tree13f364616561701ce2cea0426cad72f7914c5128 /db
parent30080dfe0a7475f37cdcf95ad1b04ce1ea060e3c (diff)
downloadgitlab-ce-e2d4a6dedbb55154ff9389dbe061fa74ccbae287.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20200511092714_update_undefined_confidence_from_vulnerabilities.rb35
-rw-r--r--db/structure.sql3
2 files changed, 38 insertions, 0 deletions
diff --git a/db/post_migrate/20200511092714_update_undefined_confidence_from_vulnerabilities.rb b/db/post_migrate/20200511092714_update_undefined_confidence_from_vulnerabilities.rb
new file mode 100644
index 00000000000..d6611ddbd66
--- /dev/null
+++ b/db/post_migrate/20200511092714_update_undefined_confidence_from_vulnerabilities.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class UpdateUndefinedConfidenceFromVulnerabilities < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'index_vulnerability_on_id_and_confidence_eq_zero'
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+ BATCH_SIZE = 1_000
+ INTERVAL = 2.minutes
+
+ # 87_602 records to be updated on GitLab.com
+ def up
+ # create temporary index for undefined vulnerabilities
+ add_concurrent_index(:vulnerabilities, :id, where: 'confidence = 0', name: INDEX_NAME)
+
+ return unless Gitlab.ee?
+
+ migration = Gitlab::BackgroundMigration::RemoveUndefinedVulnerabilityConfidenceLevel
+ migration_name = migration.to_s.demodulize
+ relation = migration::Vulnerability.undefined_confidence
+ queue_background_migration_jobs_by_range_at_intervals(relation,
+ migration_name,
+ INTERVAL,
+ batch_size: BATCH_SIZE)
+ end
+
+ def down
+ # no-op
+ # temporary index is to be dropped in a different migration in an upcoming release
+ remove_concurrent_index(:vulnerabilities, :id, where: 'confidence = 0', name: INDEX_NAME)
+ # This migration can not be reversed because we can not know which records had undefined confidence
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 9406b024eee..ad50cae5ca2 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -10843,6 +10843,8 @@ CREATE UNIQUE INDEX index_vulnerability_occurrences_on_uuid ON public.vulnerabil
CREATE INDEX index_vulnerability_occurrences_on_vulnerability_id ON public.vulnerability_occurrences USING btree (vulnerability_id);
+CREATE INDEX index_vulnerability_on_id_and_confidence_eq_zero ON public.vulnerabilities USING btree (id) WHERE (confidence = 0);
+
CREATE UNIQUE INDEX index_vulnerability_scanners_on_project_id_and_external_id ON public.vulnerability_scanners USING btree (project_id, external_id);
CREATE UNIQUE INDEX index_vulnerability_user_mentions_on_note_id ON public.vulnerability_user_mentions USING btree (note_id) WHERE (note_id IS NOT NULL);
@@ -13764,6 +13766,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200506154421
20200507221434
20200508091106
+20200511092714
20200511145545
\.