From 1e38565aaea67a3df6d2f64e34058367c61069f7 Mon Sep 17 00:00:00 2001 From: Yang Jiao <72076317+YangJiao0817@users.noreply.github.com> Date: Fri, 10 Mar 2023 12:19:11 +0800 Subject: [PATCH] Migrate robot account and notification policy related to Chartmuseum (#18316) Migrate robot permission and notification policy related to Chartmuseum Update robot permission and notification policy as Harbor v2.8.0 deprecates chartmuseum. Harbor deprecates chartmuseum as of v2.8.0 Epic: goharbor#17958 Discussion: goharbor#15057 Signed-off-by: Yang Jiao --- .../postgresql/0110_2.8.0_schema.up.sql | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/make/migrations/postgresql/0110_2.8.0_schema.up.sql b/make/migrations/postgresql/0110_2.8.0_schema.up.sql index 527285c2e..5b3987a7b 100644 --- a/make/migrations/postgresql/0110_2.8.0_schema.up.sql +++ b/make/migrations/postgresql/0110_2.8.0_schema.up.sql @@ -50,3 +50,33 @@ WHERE id IN ( UNION SELECT id FROM replication_policy_ids ); +/* Update the role permission and permission policy associated with the chartmuseum */ +DELETE FROM role_permission +WHERE permission_policy_id IN ( + SELECT id FROM permission_policy WHERE resource IN ('helm-chart', 'helm-chart-version' ,'helm-chart-version-label') +); + +DELETE FROM permission_policy +WHERE resource IN ('helm-chart', 'helm-chart-version' ,'helm-chart-version-label'); +/* Update the notification policy associated with the chartmuseum */ +WITH event_type_objects AS ( + SELECT id, jsonb_array_elements(event_types::jsonb) as event_type + FROM notification_policy + WHERE event_types IS NOT NULL AND event_types != '' + AND jsonb_typeof(CAST(event_types AS jsonb)) = 'array' +) +UPDATE notification_policy AS np +SET event_types = ( + SELECT COALESCE(jsonb_agg(eto.event_type), '[]') + FROM event_type_objects AS eto + WHERE eto.id = np.id + AND NOT(event_type @> '"UPLOAD_CHART"'::jsonb OR event_type @> '"DOWNLOAD_CHART"'::jsonb OR event_type @> '"DELETE_CHART"'::jsonb) +) +WHERE id IN ( + SELECT id FROM event_type_objects WHERE (event_type @> '"UPLOAD_CHART"'::jsonb OR event_type @> '"DOWNLOAD_CHART"'::jsonb OR event_type @> '"DELETE_CHART"'::jsonb) +); + +UPDATE notification_policy +SET enabled = false, + description = 'Chartmuseum is deprecated in Harbor v2.8.0, because this notification policy only has event type about Chartmuseum, so please update or delete this notification policy.' +WHERE event_types = '[]';