Auto-generation of placeholder barcodes approved for backport
authordbwells <dbwells@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 18 Jan 2011 18:06:00 +0000 (18:06 +0000)
committerdbwells <dbwells@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 18 Jan 2011 18:06:00 +0000 (18:06 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@19190 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql

index a66c3b7..193f19d 100644 (file)
@@ -31,7 +31,7 @@ UPDATE biblio.record_entry SET marc = '<record xmlns="http://www.loc.gov/MARC21/
 
 -- Highest-numbered individual upgrade script incorporated herein:
 
-INSERT INTO config.upgrade_log (version) VALUES ('0474');
+INSERT INTO config.upgrade_log (version) VALUES ('0475');
 
 -- Push the auri sequence in case it's out of date
 -- Add 2 as the sequence value must be 1 or higher, and seed is -1
@@ -19019,6 +19019,20 @@ WHERE NOT EXISTS (
     SELECT 1 FROM acq.lineitem_marc_attr_definition WHERE code = 'upc'
 );  
 
+-- '@@' auto-placeholder barcode support
+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;
 
 -- Some operations go outside of the transaction, because they may