From 1371e8243fb9f68775a50a8eca738193db706164 Mon Sep 17 00:00:00 2001 From: Konrad Kleine <193408+kwk@users.noreply.github.com> Date: Tue, 9 Oct 2018 16:24:11 +0200 Subject: [PATCH] drop constraint before modifying the path (#2312) Based on [this discussion](https://chat.openshift.io/developers/pl/6m4cojtiotdoueqot8uww5ybpe) we first remove the unique name index on the `iterations` and `areas` table before we modify the data. This should fix the migration issue that was visible here: https://github.com/openshiftio/saas-openshiftio/pull/1082 --- .../105-update-root-area-and-iteration-path-field.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/migration/sql-files/105-update-root-area-and-iteration-path-field.sql b/migration/sql-files/105-update-root-area-and-iteration-path-field.sql index e0b91e454a..9c9a638b07 100644 --- a/migration/sql-files/105-update-root-area-and-iteration-path-field.sql +++ b/migration/sql-files/105-update-root-area-and-iteration-path-field.sql @@ -2,6 +2,10 @@ UPDATE iterations SET path=text2ltree(concat(path, concat('.',replace(cast(id as text), '-', '_')))) WHERE path!='' AND path IS NOT NULL; UPDATE areas SET path=text2ltree(concat(path, concat('.',replace(cast(id as text), '-', '_')))) WHERE path!='' AND path IS NOT NULL; +-- drop constraints +ALTER TABLE iterations DROP CONSTRAINT iterations_name_space_id_path_unique; +ALTER TABLE areas DROP CONSTRAINT areas_name_space_id_path_unique; + -- update root iteration and area paths to use converted ids UPDATE iterations SET path=text2ltree(replace(cast(id as text), '-', '_')) WHERE path='' OR PATH IS NULL; UPDATE areas SET path=text2ltree(replace(cast(id as text), '-', '_')) WHERE path='' OR PATH IS NULL; @@ -10,10 +14,6 @@ UPDATE areas SET path=text2ltree(replace(cast(id as text), '-', '_')) WHERE path ALTER TABLE iterations ALTER COLUMN path SET NOT NULL; ALTER TABLE areas ALTER COLUMN path SET NOT NULL; --- drop constraints -ALTER TABLE iterations DROP CONSTRAINT iterations_name_space_id_path_unique; -ALTER TABLE areas DROP CONSTRAINT areas_name_space_id_path_unique; - ALTER TABLE iterations ADD CONSTRAINT non_empty_path_check CHECK (trim(path::text) <> ''); ALTER TABLE areas ADD CONSTRAINT non_empty_path_check CHECK (trim(path::text) <> '');