summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
downloadgitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb')
-rw-r--r--db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb b/db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb
new file mode 100644
index 00000000000..f7132407adb
--- /dev/null
+++ b/db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class CleanupOrphansApprovalProjectRules < Gitlab::Database::Migration[1.0]
+ class ApprovalProjectRule < ActiveRecord::Base
+ self.table_name = 'approval_project_rules'
+ end
+
+ def up
+ return unless Gitlab.ee?
+
+ ApprovalProjectRule.reset_column_information
+
+ logger = ::Gitlab::BackgroundMigration::Logger.build
+ records_ids = []
+
+ # Related enum: report_type: { vulnerability: 1, license_scanning: 2, code_coverage: 3, scan_finding: 4 }
+ ApprovalProjectRule.where(report_type: 4)
+ .joins("LEFT JOIN security_orchestration_policy_configurations
+ ON approval_project_rules.project_id = security_orchestration_policy_configurations.project_id")
+ .where(security_orchestration_policy_configurations: { project_id: nil }).each do |record|
+ records_ids << record.id
+ logger.info(
+ message: "CleanupOrphansApprovalProjectRules with record id: #{record.id}",
+ class: ApprovalProjectRule.name,
+ attributes: record.attributes
+ )
+ end
+
+ ApprovalProjectRule.where(id: records_ids).delete_all
+ end
+
+ def down
+ # no-op
+ end
+end