diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-31 15:10:39 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-31 15:10:39 +0300 |
commit | 729eabcb410add9dbcfa46677308003dc95a64d0 (patch) | |
tree | bebeb3c720c370406c4a97c582233387f4379fba /db/post_migrate | |
parent | de0c73ffc58e75c1304a2b76e51ee49a89a2162a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb | 48 | ||||
-rw-r--r-- | db/post_migrate/20200824140259_update_location_fingerprint_for_cs_findings.rb | 30 |
2 files changed, 78 insertions, 0 deletions
diff --git a/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb b/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb new file mode 100644 index 00000000000..891201eaa52 --- /dev/null +++ b/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +class CreateMissingVulnerabilitiesIssueLinks < ActiveRecord::Migration[6.0] + class VulnerabilitiesFeedback < ActiveRecord::Base + include EachBatch + self.table_name = 'vulnerability_feedback' + end + + class VulnerabilitiesIssueLink < ActiveRecord::Base + self.table_name = 'vulnerability_issue_links' + LINK_TYPE_CREATED = 2 + end + + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + VulnerabilitiesFeedback.where('issue_id IS NOT NULL').each_batch do |relation| + timestamp = Time.now + issue_links = relation + .joins("JOIN vulnerability_occurrences vo ON vo.project_id = vulnerability_feedback.project_id AND vo.report_type = vulnerability_feedback.category AND encode(vo.project_fingerprint, 'hex') = vulnerability_feedback.project_fingerprint") + .where('vo.vulnerability_id IS NOT NULL') + .pluck(:vulnerability_id, :issue_id) + .map do |v_id, i_id| + { + vulnerability_id: v_id, + issue_id: i_id, + link_type: VulnerabilitiesIssueLink::LINK_TYPE_CREATED, + created_at: timestamp, + updated_at: timestamp + } + end + + next if issue_links.empty? + + VulnerabilitiesIssueLink.insert_all( + issue_links, + returning: false + ) + end + end + + def down + end +end diff --git a/db/post_migrate/20200824140259_update_location_fingerprint_for_cs_findings.rb b/db/post_migrate/20200824140259_update_location_fingerprint_for_cs_findings.rb new file mode 100644 index 00000000000..7ef4d5040b2 --- /dev/null +++ b/db/post_migrate/20200824140259_update_location_fingerprint_for_cs_findings.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class UpdateLocationFingerprintForCsFindings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + BATCH_SIZE = 1_000 + INTERVAL = 2.minutes + + # 815_565 records + def up + return unless Gitlab.ee? + + migration = Gitlab::BackgroundMigration::UpdateLocationFingerprintForCsFindings + migration_name = migration.to_s.demodulize + relation = migration::Finding.container_scanning + queue_background_migration_jobs_by_range_at_intervals(relation, + migration_name, + INTERVAL, + batch_size: BATCH_SIZE) + end + + def down + # no-op + # intentionally blank + end +end |