X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=blobdiff_plain;f=remove_ou_data%2F02_remove_patron_extras.sql;h=ffbd78933b44cf929943547d48811f6c63ef5357;hp=bc9b96a34fd2cccea4a14e6392d7ef59de96984f;hb=a42d5301d03e7f7c424df4642a31125c09aeafa2;hpb=c919228a7234c1fdfa9f9cfbae245fc30731eb85 diff --git a/remove_ou_data/02_remove_patron_extras.sql b/remove_ou_data/02_remove_patron_extras.sql index bc9b96a..ffbd789 100644 --- a/remove_ou_data/02_remove_patron_extras.sql +++ b/remove_ou_data/02_remove_patron_extras.sql @@ -21,6 +21,7 @@ ALTER TABLE actor.usr_address DISABLE TRIGGER audit_actor_usr_address_update_trigger; ALTER TABLE actor.usr DISABLE TRIGGER audit_actor_usr_update_trigger; +ALTER TABLE actor.usr_message DISABLE RULE protect_usr_message_delete; CREATE INDEX tmp_addr_replaces ON actor.usr_address(replaces); BEGIN; @@ -59,8 +60,33 @@ DELETE FROM actor.usr_address WHERE usr IN UPDATE actor.usr SET mailing_address = NULL, billing_address = NULL WHERE home_ou IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del); +DELETE FROM actor.usr_message 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)); + +DELETE FROM actor.stat_cat_entry_usr_map WHERE target_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)); + +DELETE FROM actor.stat_cat_entry_usr_map WHERE stat_cat IN +(SELECT id from actor.stat_cat WHERE owner IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)); + +DELETE FROM actor.stat_cat_entry WHERE stat_cat IN +(SELECT id from actor.stat_cat WHERE owner IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)); + +DELETE FROM actor.stat_cat WHERE id IN +(SELECT id from actor.stat_cat WHERE owner IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)); + +DELETE FROM action.survey_response 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)); + +DELETE FROM action.survey_question WHERE survey IN +(SELECT id FROM action.survey WHERE owner IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)); + +DELETE FROM action.survey WHERE owner IN +(SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del); + COMMIT; DROP INDEX actor.tmp_addr_replaces; ALTER TABLE actor.usr_address ENABLE TRIGGER audit_actor_usr_address_update_trigger; ALTER TABLE actor.usr ENABLE TRIGGER audit_actor_usr_update_trigger; +ALTER TABLE actor.usr_message ENABLE RULE protect_usr_message_delete;