From 1f7757a8a9d0f144d592e3570c1dfb3fbb87de3a Mon Sep 17 00:00:00 2001 From: dbwells Date: Mon, 17 Jan 2011 23:34:49 +0000 Subject: [PATCH] Auto-generation of placeholder barcodes This commit implements a very basic trigger for auto-generating placeholder barcodes, as discussed at the Dec. 14 2010 IRC developer meeting. The 1.6.1-2.0 upgrade script has not been changed, as backporting this to 2.0 is pending review. git-svn-id: svn://svn.open-ils.org/ILS/trunk@19189 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/040.schema.asset.sql | 13 +++++++++++++ .../upgrade/0475.schema.auto-placeholder-barcodes.sql | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0475.schema.auto-placeholder-barcodes.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index ec1b957ff5..382bb06afe 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -70,7 +70,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0474'); -- miker +INSERT INTO config.upgrade_log (version) VALUES ('0475'); -- dbwells CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql index 982e267e14..623b7f1278 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -682,5 +682,18 @@ BEGIN END; $f$ LANGUAGE PLPGSQL; +CREATE OR REPLACE FUNCTION asset.autogenerate_placeholder_barcode ( ) RETURNS TRIGGER AS $f$ +BEGIN + IF NEW.barcode LIKE '@@%' THEN + NEW.barcode := '@@' || NEW.id; + END IF; + RETURN NEW; +END; +$f$ LANGUAGE PLPGSQL; + +CREATE TRIGGER autogenerate_placeholder_barcode + BEFORE INSERT OR UPDATE ON asset.copy + FOR EACH ROW EXECUTE PROCEDURE asset.autogenerate_placeholder_barcode(); + COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/0475.schema.auto-placeholder-barcodes.sql b/Open-ILS/src/sql/Pg/upgrade/0475.schema.auto-placeholder-barcodes.sql new file mode 100644 index 0000000000..baace2a74a --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0475.schema.auto-placeholder-barcodes.sql @@ -0,0 +1,18 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0475'); -- dbwells + +CREATE OR REPLACE FUNCTION asset.autogenerate_placeholder_barcode ( ) RETURNS TRIGGER AS $f$ +BEGIN + IF NEW.barcode LIKE '@@%' THEN + NEW.barcode := '@@' || NEW.id; + END IF; + RETURN NEW; +END; +$f$ LANGUAGE PLPGSQL; + +CREATE TRIGGER autogenerate_placeholder_barcode + BEFORE INSERT OR UPDATE ON asset.copy + FOR EACH ROW EXECUTE PROCEDURE asset.autogenerate_placeholder_barcode(); + +COMMIT; -- 2.11.0