From be55b92a843dc3406677c7a477a8e243747ad049 Mon Sep 17 00:00:00 2001 From: gmc Date: Mon, 12 Jul 2010 17:09:23 +0000 Subject: [PATCH] protect against deletion of serial.unit rows Rules are not inherited by child tables, so must add one explicitly. Signed-off-by: Galen Charlton git-svn-id: svn://svn.open-ils.org/ILS/trunk@16910 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/210.schema.serials.sql | 3 +++ .../src/sql/Pg/upgrade/0333.schema.protect_serial_unit_delete.sql | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0333.schema.protect_serial_unit_delete.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 2e3695ae7d..2a29c9531d 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0332'); -- gmc +INSERT INTO config.upgrade_log (version) VALUES ('0333'); -- gmc CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/210.schema.serials.sql b/Open-ILS/src/sql/Pg/210.schema.serials.sql index b3ed598063..957ba04f23 100644 --- a/Open-ILS/src/sql/Pg/210.schema.serials.sql +++ b/Open-ILS/src/sql/Pg/210.schema.serials.sql @@ -162,6 +162,9 @@ CREATE TABLE serial.unit ( ALTER TABLE serial.unit ADD PRIMARY KEY (id); +-- must create this rule explicitly; it is not inherited from asset.copy +CREATE RULE protect_serial_unit_delete AS ON DELETE TO serial.unit DO INSTEAD UPDATE serial.unit SET deleted = TRUE WHERE OLD.id = serial.unit.id; + CREATE TABLE serial.item ( id SERIAL PRIMARY KEY, creator INT NOT NULL diff --git a/Open-ILS/src/sql/Pg/upgrade/0333.schema.protect_serial_unit_delete.sql b/Open-ILS/src/sql/Pg/upgrade/0333.schema.protect_serial_unit_delete.sql new file mode 100644 index 0000000000..4172421a22 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0333.schema.protect_serial_unit_delete.sql @@ -0,0 +1,8 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0333'); --gmc + +-- must create this rule explicitly; it is not inherited from asset.copy +CREATE RULE protect_serial_unit_delete AS ON DELETE TO serial.unit DO INSTEAD UPDATE serial.unit SET deleted = TRUE WHERE OLD.id = serial.unit.id; + +COMMIT; -- 2.11.0