LP 849008 : Cascade delete Z39.50 attributes
authorBill Erickson <berick@esilibrary.com>
Wed, 13 Mar 2013 18:26:48 +0000 (14:26 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 13 Mar 2013 18:50:08 +0000 (14:50 -0400)
Force deletion of Z39.50 attributes within the database when the Z39.50
source to which the attributes refer is deleted.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config_z3950_source_attr_cascade_delete.sql [new file with mode: 0644]

index e578c0f..a7db50d 100644 (file)
@@ -505,7 +505,7 @@ $$;
 
 CREATE TABLE config.z3950_attr (
     id          SERIAL  PRIMARY KEY,
-    source      TEXT    NOT NULL REFERENCES config.z3950_source (name) DEFERRABLE INITIALLY DEFERRED,
+    source      TEXT    NOT NULL REFERENCES config.z3950_source (name) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
     name        TEXT    NOT NULL,
     label       TEXT    NOT NULL,
     code        INT     NOT NULL,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config_z3950_source_attr_cascade_delete.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config_z3950_source_attr_cascade_delete.sql
new file mode 100644 (file)
index 0000000..9b99364
--- /dev/null
@@ -0,0 +1,15 @@
+
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER TABLE config.z3950_attr
+    DROP CONSTRAINT z3950_attr_source_fkey,
+    ADD CONSTRAINT z3950_attr_source_fkey 
+        FOREIGN KEY (source) 
+        REFERENCES config.z3950_source(name) 
+        ON UPDATE CASCADE
+        ON DELETE CASCADE
+        DEFERRABLE INITIALLY DEFERRED;
+
+COMMIT;