Fix UpdateBuildNamesService to truncate build names before upsert
What does this MR do and why?
Fixes #583499
The Ci::UpdateBuildNamesService uses upsert_all to insert/update build names, which bypasses the Ci::BuildName model's name= setter that truncates values to 255 characters (MAX_JOB_NAME_LENGTH). This can lead to database constraint violations or inconsistent data when build names exceed the limit.
This MR ensures build names are truncated to MAX_JOB_NAME_LENGTH before being passed to upsert_all, maintaining data consistency and preventing potential database constraint violations.
How to set up and validate locally
- Create a pipeline with a build that has a name longer than 255 characters
- Run
Ci::UpdateBuildNamesService.new(pipeline).execute - Verify that the build name in
ci_build_namestable is truncated to 255 characters
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.
Related issues
- Parent issue: #583031 (Database schema inconsistency for CI build name fields)