Skip to content

Update CI resource latest_released_at when version is modified

Leaminn Ma requested to merge ci-catalog-update-latest-released-at into master

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's released_at value
  • If there are no Versions, update latest_released_at to null

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

  1. Create a catalog resource project.
  2. In the UI, create two releases, one with a released date set to 2023-12-10 and another set to 2023-12-20.
  3. Check that the latest_released_at value of your catalog resource is 2023-12-20.
project = Project.find(<YOUR-PROJECT-ID>)
project.catalog_resource.reload.latest_released_at

Screenshot_2023-11-14_at_12.55.12_PM

  1. In the UI, delete the 2023-12-20 release and check that the latest_released_at value is now 2023-12-10.

Screenshot_2023-11-14_at_12.56.12_PM

  1. Update the release date of the remaining release to 2024-01-01 and check that the latest_released_at value updated accordingly.
  2. 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.

Related to #427791 (closed)

Edited by Leaminn Ma

Merge request reports