Add BBM to mark packages_helm_metadata_caches
as pending_destruction
What does this MR do and why?
In the previous MR, we fixed the bug to update helm_metadata_cache
for all channels when package gets deleted.
Because of the bug, we disabled the feature flag packages_helm_metadata_cache
, to be able to do the rollout again, we need to clean up the packages_helm_metadata_caches
table, otherwise, users who already had packages_helm_metadata_caches
records for the given project and channel, will get the legacy/wrong metadata cache.
This MR introduces a post-deployment migration to mark all the records in packages_helm_metadata_cache
as pending_destruction
status, since the table has LFK
on project_id
, it will trigger the deletion of the record as well as the file in object storage.
Database
Currently, we have 4748 records in packages_helm_metadata_caches
table.
Raw query
We mark packages_helm_metadata_caches
in batch.
UPDATE
"packages_helm_metadata_caches"
SET
"status" = 2
WHERE
"packages_helm_metadata_caches"."id" BETWEEN 11 AND 16
AND "packages_helm_metadata_caches"."id" >= 11
Query plan: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/43023/commands/131552
References
Screenshots or screen recordings
N/A
How to set up and validate locally
- Switch to this branch
- Enter Rails console and create
packages_helm_metadata_caches
recordssql = <<-SQL INSERT INTO packages_helm_metadata_caches (project_id, channel, object_storage_key, size, file, status, created_at, updated_at) VALUES (2, 'channel-0', 'key-0', 401, 'index.yaml', 0, NOW(), NOW()), (2, 'channel-1', 'key-1', 401, 'index.yaml', 0, NOW(), NOW()), (2, 'channel-2', 'key-2', 401, 'index.yaml', 0, NOW(), NOW()), (2, 'channel-3', 'key-3', 401, 'index.yaml', 0, NOW(), NOW()), (2, 'channel-4', 'key-4', 401, 'index.yaml', 0, NOW(), NOW()), (2, 'channel-5', 'key-5', 401, 'index.yaml', 0, NOW(), NOW()), (2, 'channel-6', 'key-6', 401, 'index.yaml', 0, NOW(), NOW()), (2, 'channel-7', 'key-7', 401, 'index.yaml', 0, NOW(), NOW()), (2, 'channel-8', 'key-8', 401, 'index.yaml', 0, NOW(), NOW()), (20, 'channel-9', 'key-9', 401, 'index.yaml', 0, NOW(), NOW()); SQL ActiveRecord::Base.connection.execute(sql)
- Check records, the statuses should all be
default
Packages::Helm::MetadataCache.all.map(&:status)
- Exit Rails console and run migration
rails db:migrate:up:main VERSION=20250829141659
- Check
background_migrations
page (http://gdk.test:3000/admin/background_migrations) - If exists, enter Rails console to check the status again
Packages::Helm::MetadataCache.all.map(&:status)
pending_destruction
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #566574 (closed)