Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20230313185145_cleanup_orphan_software_licenses.rb')
-rw-r--r--db/post_migrate/20230313185145_cleanup_orphan_software_licenses.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/db/post_migrate/20230313185145_cleanup_orphan_software_licenses.rb b/db/post_migrate/20230313185145_cleanup_orphan_software_licenses.rb
new file mode 100644
index 00000000000..af971f692d6
--- /dev/null
+++ b/db/post_migrate/20230313185145_cleanup_orphan_software_licenses.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class CleanupOrphanSoftwareLicenses < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ class SoftwareLicense < MigrationRecord
+ self.table_name = 'software_licenses'
+ end
+
+ class SoftwareLicensePolicy < MigrationRecord
+ self.table_name = 'software_license_policies'
+ end
+
+ def up
+ SoftwareLicense
+ .where(spdx_identifier: nil)
+ .where.not(
+ id: SoftwareLicensePolicy.select(:software_license_id)
+ ).delete_all
+ end
+
+ def down
+ # NO-OP
+ end
+end