Update CI resource latest_released_at when version is modified
What does this MR do and why?
In !132429 (merged), we added the latest_released_at
column to catalog_resources
with the purpose of containing the released_at
value of the catalog resource's latest Version. In this MR we populate the column when a Version/Release is created/destroyed/updated.
The logic implemented is:
- Evaluate the latest Version and update
latest_released_at
with the latest Version'sreleased_at
value - If there are no Versions, update
latest_released_at
tonull
when:
- Version is created.
- Version is destroyed.
- Associated Release's released_at value is updated.
- Associated Release is destroyed (the database is set up to cascade delete the Version when the Release is deleted.)
Since the value of latest_released_at
is tightly coupled to data changes to Version and Release, it was decided to implement this logic in model callbacks.
Additionally, this MR includes some refactoring to the spec spec/models/ci/catalog/resource_spec.rb
.
Resolves #427791 (closed).
How to set up and validate locally
- Create a catalog resource project.
- In the UI, create two releases, one with a released date set to
2023-12-10
and another set to2023-12-20
. - Check that the
latest_released_at
value of your catalog resource is2023-12-20
.
project = Project.find(<YOUR-PROJECT-ID>)
project.catalog_resource.reload.latest_released_at
- In the UI, delete the
2023-12-20
release and check that thelatest_released_at
value is now2023-12-10
.
- Update the release date of the remaining release to
2024-01-01
and check that thelatest_released_at
value updated accordingly. - Delete the remaining release and check that the
latest_released_at
value is now nil.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #427791 (closed)