From a4a1913598ef48b7d4f01c372bea633054bc3637 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 12 Mar 2020 09:49:18 +0800 Subject: [PATCH] Repair the count usage during the upgrading As the count quota is against artifact rather than tag in 2.0, the count usage should be recalculated Signed-off-by: Wenkai Yin --- make/migrations/postgresql/0030_2.0.0_schema.up.sql | 8 ++++++++ src/migration/migration.go | 3 --- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/make/migrations/postgresql/0030_2.0.0_schema.up.sql b/make/migrations/postgresql/0030_2.0.0_schema.up.sql index c89b006d5..eec3c50ee 100644 --- a/make/migrations/postgresql/0030_2.0.0_schema.up.sql +++ b/make/migrations/postgresql/0030_2.0.0_schema.up.sql @@ -98,6 +98,14 @@ FROM ( ) AS s WHERE artifact.digest=s.digest; +/*repair the count usage as we calculate the count quota against artifact rather than tag*/ +/*count=count-(tag count-artifact count)*/ +UPDATE quota_usage SET used=jsonb_set(used, '{count}', ((used->>'count')::int - (SELECT ( + SELECT COUNT (*) FROM tag + JOIN artifact ON tag.artifact_id=artifact.id + WHERE artifact.project_id=quota_usage.reference_id::int)-( + SELECT COUNT (*) FROM artifact + WHERE project_id=quota_usage.reference_id::int)))::text::jsonb); /* artifact_reference records the child artifact referenced by parent artifact */ CREATE TABLE artifact_reference diff --git a/src/migration/migration.go b/src/migration/migration.go index 5f5c6653d..44273dc0d 100644 --- a/src/migration/migration.go +++ b/src/migration/migration.go @@ -66,9 +66,6 @@ func Migrate(database *models.Database) error { return err } - // update quota - // TODO - return nil }