Maven VReg: Move the cache_validity_period column to the upstreams table
Context
In Maven virtual registry MVC (API only interactions) (&14137 - closed), we have the virtual_registries_packages_maven_registries database table that hosts the column cache_validity_period. This column holds the duration in hours, after which the cache will be considered stale, and the registry should check for a fresh copy on the upstream.
At the beginning of the feature implementation, the motive to put this column in the registries table was the desire to avoid making users have to set up multiple similar periods for the many upstreams support. Later, with the idea of shared upstreams, it makes less sense to have the cache_validity_hours on the registry level. One registry could say that for upstream U, the cache is valid for 1.hour and a second registry could say 1.day for the exact same upstream U. We believe it isn't wise to allow such confusion or mix of settings.
So, we decided to move this column to the virtual_registries_packages_maven_upstreams table.
What does this MR do?
- Add
cache_validity_periodcolumn to thevirtual_registries_packages_maven_upstreamsdatabase table. - Ignore
virtual_registries_packages_maven_registries'cache_validity_periodcolumn to be dropped in the next milestone. - Replace any usage for the old
cache_validity_periodwith the new one in the codebase. - Update the specs accordingly.
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.
Screenshots or screen recordings
N/A
How to set up and validate locally
-
Enable the feature flag :
Feature.enable(:virtual_registry_maven). -
Make sure you have the dependency proxy enabled in your GDK, or simply comment out this line for easier testing.
-
Have a PAT and a root group (any visibility) ready.
-
In rails console, create a new registry:
registry = ::VirtualRegistries::Packages::Maven::Registry.create!(group: <root_group>) -
From your terminal, create a new
upstreamand pass a value forcache_validity_period:curl -i -H 'Content-Type: application/json' \ -d '{ "url": "https://maven.test", "username": "test", "password": "password", "cache_validity_period": 5 }' \ -X POST \ http://root:<PAT>@gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams -
Update
cache_validity_period's valuecurl -i -H 'Content-Type: application/json' \ -d '{ "cache_validity_hours": 10 }' \ -X PATCH \ http://root:<PAT>@gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams/<upstream_id> -
Follow these steps to test that pulling from the cache still works as usual after moving the column from the
registryto theupstream
Related to #500664 (closed)