X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=blobdiff_plain;f=remove_ou_data%2F04_remove_circ.sql;h=ed115607d90b7af63efb9371297a63a67627566e;hp=786de02e9b2b03806836eba9d04775e2c26c6c54;hb=d8010c11b88b4420eb594415b02d307971ca7230;hpb=0cefde660c085b23bc9a6120762ae221cec32bbb diff --git a/remove_ou_data/04_remove_circ.sql b/remove_ou_data/04_remove_circ.sql index 786de02..ed11560 100644 --- a/remove_ou_data/04_remove_circ.sql +++ b/remove_ou_data/04_remove_circ.sql @@ -21,13 +21,11 @@ ALTER TABLE action.circulation DISABLE TRIGGER action_circulation_aging_tgr; ALTER TABLE action.circulation DISABLE TRIGGER age_parent_circ; +ALTER TABLE action.circulation_limit_group_map DROP CONSTRAINT circulation_limit_group_map_circ_fkey; +ALTER TABLE action.usr_circ_history DROP CONSTRAINT usr_circ_history_source_circ_fkey; BEGIN; -UPDATE action.circulation SET parent_circ = NULL WHERE parent_circ -(SELECT id FROM action.circulation WHERE circ_lib = (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)) -AND circ_lib NOT IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del); - DELETE FROM action.circulation WHERE usr IN (SELECT id FROM actor.usr WHERE home_ou IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)); @@ -44,7 +42,21 @@ DELETE FROM action.aged_circulation WHERE copy_circ_lib IN DELETE FROM action.aged_circulation WHERE copy_owning_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del); +DELETE FROM action.non_cat_in_house_use WHERE org_unit IN +(SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del); + +UPDATE action.non_cat_in_house_use SET staff = 1 WHERE staff IN +(SELECT id FROM actor.usr WHERE home_ou IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)) +AND org_unit IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del); + +DELETE FROM action.usr_circ_history WHERE id IN (SELECT a.id FROM action.usr_circ_history a LEFT JOIN action.circulation b ON b.id = a.source_circ WHERE b.id IS NULL); + +DELETE FROM action.circulation_limit_group_map WHERE circ IN (SELECT a.id FROM action.circulation_limit_group_map a LEFT JOIN action.circulation b ON b.id = a.circ WHERE b.id IS NULL); + COMMIT; ALTER TABLE action.circulation ENABLE TRIGGER action_circulation_aging_tgr; ALTER TABLE action.circulation ENABLE TRIGGER age_parent_circ; +ALTER TABLE action.usr_circ_history ADD CONSTRAINT usr_circ_history_source_circ_fkey FOREIGN KEY (source_circ) REFERENCES action.circulation(id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE action.circulation_limit_group_map ADD CONSTRAINT circulation_limit_group_map_circ_fkey FOREIGN KEY (circ) REFERENCES action.circulation(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; +