Index: openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.8.0d2-5.8.0d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.8.0d2-5.8.0d3.sql,v diff -u -r1.1 -r1.1.2.1 --- openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.8.0d2-5.8.0d3.sql 4 Aug 2011 08:26:20 -0000 1.1 +++ openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.8.0d2-5.8.0d3.sql 23 Jan 2015 11:13:16 -0000 1.1.2.1 @@ -6,10 +6,11 @@ create index cr_item_publish_audit_nrev_idx on cr_item_publish_audit(new_revision); -- make sure, we can add the foreign keys -delete from cr_item_publish_audit where item_id not in (select item_id from cr_items); -delete from cr_item_publish_audit where old_revision not in (select revision_id from cr_revisions); -delete from cr_item_publish_audit where new_revision not in (select revision_id from cr_revisions); +DELETE FROM cr_item_publish_audit a WHERE NOT EXISTS (SELECT 1 FROM cr_items i WHERE a.item_id = i.item_id); +DELETE FROM cr_item_publish_audit a WHERE NOT EXISTS (SELECT 1 FROM cr_revisions r WHERE a.old_revision = r.revision_id); +DELETE FROM cr_item_publish_audit a WHERE NOT EXISTS (SELECT 1 FROM cr_revisions r WHERE a.new_revision = r.revision_id); + -- add the foreign keys alter table cr_item_publish_audit add constraint cr_item_publish_audit_item_fk foreign key (item_id) references cr_items (item_id); alter table cr_item_publish_audit add constraint cr_item_publish_audit_orev_fk foreign key (old_revision) references cr_revisions (revision_id);