From 790064df2e2a850b0ce2e507c002caa804247d5f Mon Sep 17 00:00:00 2001 From: Wang Yan Date: Thu, 16 Apr 2020 14:53:58 +0800 Subject: [PATCH] fix notification policy ugrade issue (#11627) Fixes #11624 All of the existing policies created v1.10 has no name, it fails the upgrade process. When to set the unique constraint for policy name, the empty can be seen as duplicated key. ERROR: could not create unique index "notification_policy_name_key" DETAIL: Key (name)=() is duplicated. Signed-off-by: wang yan --- make/migrations/postgresql/0030_2.0.0_schema.up.sql | 3 +++ 1 file changed, 3 insertions(+) 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 97ed28dc1..06a5889be 100644 --- a/make/migrations/postgresql/0030_2.0.0_schema.up.sql +++ b/make/migrations/postgresql/0030_2.0.0_schema.up.sql @@ -191,6 +191,9 @@ DROP TABLE IF EXISTS access_log; /*remove the constraint for project_id in table 'notification_policy'*/ ALTER TABLE notification_policy DROP CONSTRAINT unique_project_id; +/*the existing policy has no name, to make sure the unique constraint for name works, use the id as name*/ +/*if the name is set via API, it will be force to be changed with new pattern*/ +UPDATE notification_policy SET name=CONCAT('policy_', id); /*add the unique constraint for name in table 'notification_policy'*/ ALTER TABLE notification_policy ADD UNIQUE (name);