Skip to content

Migrate sbom_occurrences.component_name to match

Zamir Martins requested to merge migrate_sbom_occurrences_component_name into master

What does this MR do and why?

Migrate sbom_occurrences.component_name to match PEP 503.

Changelog: fixed

Related issue: #440391 (closed)

Production data

gitlabhq_dblab=# select count(*) from sbom_components where purl_type = 8 and name like '%\_%';
 count
-------
     0
(1 row)

gitlabhq_dblab=# select count(*) from sbom_components where purl_type = 8 and name like '%--%';
 count
-------
     0
(1 row)

gitlabhq_dblab=# select count(*) from sbom_components where purl_type = 8 and name like '%.%';
 count
-------
   413
(1 row)
gitlabhq_dblab=# select count(*) from sbom_occurrences inner join sbom_components on sbom_occurrences.component_id = sbom_components.id where purl_type = 8 and name like '%.%';
-[ RECORD 1 ]
count | 2945

DB migrate/rollback

$ bundle exec rails db:migrate
main: == [advisory_lock_connection] object_id: 119500, pg_backend_pid: 27683
main: == 20240306120522 QueueUpdateSbomOccurrencesComponentNameBasedOnPep503: migrating
main: == 20240306120522 QueueUpdateSbomOccurrencesComponentNameBasedOnPep503: migrated (0.0572s)

main: == [advisory_lock_connection] object_id: 119500, pg_backend_pid: 27683
ci: == [advisory_lock_connection] object_id: 120040, pg_backend_pid: 27688
ci: == 20240306120522 QueueUpdateSbomOccurrencesComponentNameBasedOnPep503: migrating
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_internal, :gitlab_shared].
ci: == 20240306120522 QueueUpdateSbomOccurrencesComponentNameBasedOnPep503: migrated (0.0074s)

ci: == [advisory_lock_connection] object_id: 120040, pg_backend_pid: 27688

$ bundle exec rails db:migrate:down:main VERSION=20240306120522
main: == [advisory_lock_connection] object_id: 119040, pg_backend_pid: 28402
main: == 20240306120522 QueueUpdateSbomOccurrencesComponentNameBasedOnPep503: reverting
main: == 20240306120522 QueueUpdateSbomOccurrencesComponentNameBasedOnPep503: reverted (0.1711s)

main: == [advisory_lock_connection] object_id: 119040, pg_backend_pid: 28402

Query plan for a single record

Link to plan

UPDATE "sbom_occurrences" SET "updated_at" = '2024-02-26 15:38:54.343479', "component_name" = 'yargs-parser' WHERE "sbom_occurrences"."id" = 8000;

MR acceptance checklist

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

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Edited by Zamir Martins

Merge request reports