Add spdx_identifier or custom_license constraint to software_license_policies

What does this MR do and why?

This MR adds a database constraint to match the model validation. This constraint could not be added before because the software_license_policies in the sec database was not truncated yet as discussed in this thread.

Migration up

main: == 20250819181649 AddSoftwareLicenseOrCustomLicenseConstraintToSoftwareLicensePolicies: migrating 
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("ALTER TABLE software_license_policies\nADD CONSTRAINT check_6cb3facbb3\nCHECK ( num_nonnulls(custom_software_license_id, software_license_spdx_identifier) = 1 )\nNOT VALID;\n")
main:    -> 0.0037s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0028s
main: -- execute("ALTER TABLE software_license_policies VALIDATE CONSTRAINT check_6cb3facbb3;")
main:    -> 0.0014s
main: -- execute("RESET statement_timeout")
main:    -> 0.0004s
main: == 20250819181649 AddSoftwareLicenseOrCustomLicenseConstraintToSoftwareLicensePolicies: migrated (0.0694s) 

Migration down

main: == [advisory_lock_connection] object_id: 154160, pg_backend_pid: 18911
main: == 20250819181649 AddSoftwareLicenseOrCustomLicenseConstraintToSoftwareLicensePolicies: reverting 
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("            ALTER TABLE software_license_policies\n            DROP CONSTRAINT IF EXISTS check_6cb3facbb3\n")
main:    -> 0.0016s
main: == 20250819181649 AddSoftwareLicenseOrCustomLicenseConstraintToSoftwareLicensePolicies: reverted (0.0244s) 

References

Related to #550228 (closed)

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Marcos Rocha

Merge request reports

Loading