Skip to content

Migrate custom licenses to the new table.

We want to migrate the custom licenses to the new table created in MR !151445 (merged)

Implementation plan

  1. Add a data migration to fill the new table with the license name and project_id
# frozen_string_literal: true

class CopyCustomLicenses < Gitlab::Database::Migration[2.2]
 milestone '16.10'

 def up
 sql = <<-SQL
 INSERT INTO custom_software_licenses (name, project_id)
 SELECT
 name,
 project_id
 FROM
 software_licenses
 JOIN software_license_policies ON (software_licenses.id = software_license_id)
 WHERE
 spdx_identifier IS NULL
 GROUP BY
 name,
 project_id;
 SQL

 execute(sql)
 end

 def down
 # no-op
 end
end

We are expecting duplicated licenses among projects.

License project
custom 432
custom 165
custom 137
  1. Remove the method unclassified_licenses_for on SoftwareLicense

2.1 Remove the test cases related to this method from ee/spec/models/software_license_spec.rb

  1. Update software licenses with custom licenses.
UPDATE software_license_policies
 SET software_license_id = NULL,
 custom_software_license_id = custom_software_licenses.id
 FROM
 custom_software_licenses
 JOIN software_licenses ON custom_software_licenses.name = software_licenses.name
 WHERE
 software_licenses.spdx_identifier IS NULL
 AND custom_software_licenses.project_id = software_license_policies.project_id
 AND software_licenses.id = software_license_policies.software_license_id
Edited by Marcos Rocha