Packages build info, properly implement the uniqueness constraint
🔥 Problem
Follow-up of !68649 (comment 656594885).
We have an issue with build infos problems.
- A lot of rows have
nilpipeline_id. This is not useful, the code will not do anything with that that. - Several rows are duplicated (excluding with a
NULLpipeline_id). This doesn't make sense. The build infos are meant to link a package model (see below) with a pipeline object. We don't need the same package and same pipeline to be linked multiple times.
We have two tables for builds infos:
- At the
packages_packageslevel. This level has problem (1.) and (2.). - At the
packages_packages_fileslevel. This level has only problem (1.).
🚒 Solution
There are two things to do here:
- Existing rows cleanup:
- Remove all rows with a
nilpipeline_id. They are not used or better said, the code can't do anything with that, it's not valuable. - Deduplicate duplicated rows. We have cases with multiple rows on the same package_id and pipeline_id. This is not useful. We only need one row.
- Remove all rows with a
- Enforce a unique constraint:
- Implement the unique constraint at the database level
- Implement the unique constraint at the rails level
-
⚠ The table currently doesn't have any constraint. By adding one, we can't usefind_or_create_byanymore. The solution is to switch fromfind_to_create_byto upsert to uniquely insert the build info rows.
- Enforce a non null constraint:
Edited by David Fernandez