Index: openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.9.1b3-5.9.1b4.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.9.1b3-5.9.1b4.sql,v diff -u -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.9.1b3-5.9.1b4.sql 21 Mar 2017 15:49:25 -0000 1.1.2.1 +++ openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.9.1b3-5.9.1b4.sql 21 Mar 2017 16:21:20 -0000 1.1.2.2 @@ -5,10 +5,23 @@ begin; -alter table acs_rels drop constraint acs_rels_object_id_one_fk; -alter table acs_rels drop constraint acs_rels_object_id_two_fk; +-- make sure the old constraint names don't exist +alter table acs_rels drop constraint if exists acs_object_rels_one_fk; +alter table acs_rels drop constraint if exists acs_object_rels_two_fk; -alter table acs_rels add constraint acs_rels_object_id_one_fk foreign key (object_id_one) references acs_objects(object_id) on delete cascade; -alter table acs_rels add constraint acs_rels_object_id_two_fk foreign key (object_id_two) references acs_objects(object_id) on delete cascade; +-- create the new constraints if they don't exist already +DO $$ +BEGIN + BEGIN + alter table acs_rels add constraint acs_rels_object_id_one_fk foreign key (object_id_one) references acs_objects(object_id) on delete cascade; + EXCEPTION + WHEN duplicate_object THEN RAISE NOTICE 'Table constraint acs_rels_object_id_one_fk already exists, skipping'; + END; + BEGIN + alter table acs_rels add constraint acs_rels_object_id_two_fk foreign key (object_id_two) references acs_objects(object_id) on delete cascade; + EXCEPTION + WHEN duplicate_object THEN RAISE NOTICE 'Table constraint acs_rels_object_id_two_fk already exists, skipping'; + END; +END $$; end;