Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
drop constraint before modifying the path (#2312)
Browse files Browse the repository at this point in the history
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: openshiftio/saas-openshiftio#1082
  • Loading branch information
kwk authored Oct 9, 2018
1 parent a661437 commit 1371e82
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) <> '');

Expand Down

0 comments on commit 1371e82

Please sign in to comment.