[open-ils-commits] r11083 - branches/rel_1_4/Open-ILS/src/sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Nov 6 13:33:09 EST 2008
Author: miker
Date: 2008-11-06 13:33:04 -0500 (Thu, 06 Nov 2008)
New Revision: 11083
Modified:
branches/rel_1_4/Open-ILS/src/sql/Pg/040.schema.asset.sql
branches/rel_1_4/Open-ILS/src/sql/Pg/090.schema.action.sql
Log:
backporting move of asset merge stored proc
Modified: branches/rel_1_4/Open-ILS/src/sql/Pg/040.schema.asset.sql
===================================================================
--- branches/rel_1_4/Open-ILS/src/sql/Pg/040.schema.asset.sql 2008-11-06 18:30:43 UTC (rev 11082)
+++ branches/rel_1_4/Open-ILS/src/sql/Pg/040.schema.asset.sql 2008-11-06 18:33:04 UTC (rev 11083)
@@ -188,81 +188,5 @@
FROM asset.call_number cn
JOIN metabib.rec_descriptor rd ON (rd.record = cn.record);
-CREATE OR REPLACE FUNCTION asset.merge_record_assets( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$
-DECLARE
- moved_objects INT := 0;
- source_cn asset.call_number%ROWTYPE;
- target_cn asset.call_number%ROWTYPE;
- metarec metabib.metarecord%ROWTYPE;
- hold action.hold_request%ROWTYPE;
-BEGIN
- -- Find and move metarecords to the target record
- SELECT INTO metarec *
- FROM metabib.metarecord
- WHERE master_record = source_record;
-
- IF FOUND THEN
- UPDATE metabib.metarecord
- SET master_record = target_record,
- mods = NULL
- WHERE id = metarec.id;
-
- moved_objects := moved_objects + 1;
- END IF;
-
- -- Find call numbers attached to the source ...
- FOR source_cn IN SELECT * FROM asset.call_number WHERE record = source_record LOOP
-
- SELECT INTO target_cn *
- FROM asset.call_number
- WHERE label = source_cn.label
- AND owning_lib = source_cn.owning_lib
- AND record = target_record;
-
- -- ... and if there's a conflicting one on the target ...
- IF FOUND THEN
-
- -- ... move the copies to that, and ...
- UPDATE asset.copy
- SET call_number = target_cn.id
- WHERE call_number = source_cn.id;
-
- -- ... move V holds to the move-target call number
- FOR hold IN SELECT * FROM action.hold_request WHERE target = source_cn.id AND hold_type = 'V' LOOP
-
- UPDATE action.hold_request
- SET target = target_cn.id
- WHERE id = hold.id;
-
- moved_objects := moved_objects + 1;
- END LOOP;
-
- -- ... if not ...
- ELSE
- -- ... just move the call number to the target record
- UPDATE asset.call_number
- SET record = target_record
- WHERE id = source_cn.id;
- END IF;
-
- moved_objects := moved_objects + 1;
- END LOOP;
-
- -- Find T holds targeting the source record ...
- FOR hold IN SELECT * FROM action.hold_request WHERE target = source_record AND hold_type = 'T' LOOP
-
- -- ... and move them to the target record
- UPDATE action.hold_request
- SET target = target_record
- WHERE id = hold.id;
-
- moved_objects := moved_objects + 1;
- END LOOP;
-
- -- That's all, folks!
- RETURN moved_objects;
-END;
-$func$ LANGUAGE plpgsql;
-
COMMIT;
Modified: branches/rel_1_4/Open-ILS/src/sql/Pg/090.schema.action.sql
===================================================================
--- branches/rel_1_4/Open-ILS/src/sql/Pg/090.schema.action.sql 2008-11-06 18:30:43 UTC (rev 11082)
+++ branches/rel_1_4/Open-ILS/src/sql/Pg/090.schema.action.sql 2008-11-06 18:33:04 UTC (rev 11083)
@@ -331,5 +331,81 @@
fail_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
+CREATE OR REPLACE FUNCTION asset.merge_record_assets( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$
+DECLARE
+ moved_objects INT := 0;
+ source_cn asset.call_number%ROWTYPE;
+ target_cn asset.call_number%ROWTYPE;
+ metarec metabib.metarecord%ROWTYPE;
+ hold action.hold_request%ROWTYPE;
+BEGIN
+ -- Find and move metarecords to the target record
+ SELECT INTO metarec *
+ FROM metabib.metarecord
+ WHERE master_record = source_record;
+
+ IF FOUND THEN
+ UPDATE metabib.metarecord
+ SET master_record = target_record,
+ mods = NULL
+ WHERE id = metarec.id;
+
+ moved_objects := moved_objects + 1;
+ END IF;
+
+ -- Find call numbers attached to the source ...
+ FOR source_cn IN SELECT * FROM asset.call_number WHERE record = source_record LOOP
+
+ SELECT INTO target_cn *
+ FROM asset.call_number
+ WHERE label = source_cn.label
+ AND owning_lib = source_cn.owning_lib
+ AND record = target_record;
+
+ -- ... and if there's a conflicting one on the target ...
+ IF FOUND THEN
+
+ -- ... move the copies to that, and ...
+ UPDATE asset.copy
+ SET call_number = target_cn.id
+ WHERE call_number = source_cn.id;
+
+ -- ... move V holds to the move-target call number
+ FOR hold IN SELECT * FROM action.hold_request WHERE target = source_cn.id AND hold_type = 'V' LOOP
+
+ UPDATE action.hold_request
+ SET target = target_cn.id
+ WHERE id = hold.id;
+
+ moved_objects := moved_objects + 1;
+ END LOOP;
+
+ -- ... if not ...
+ ELSE
+ -- ... just move the call number to the target record
+ UPDATE asset.call_number
+ SET record = target_record
+ WHERE id = source_cn.id;
+ END IF;
+
+ moved_objects := moved_objects + 1;
+ END LOOP;
+
+ -- Find T holds targeting the source record ...
+ FOR hold IN SELECT * FROM action.hold_request WHERE target = source_record AND hold_type = 'T' LOOP
+
+ -- ... and move them to the target record
+ UPDATE action.hold_request
+ SET target = target_record
+ WHERE id = hold.id;
+
+ moved_objects := moved_objects + 1;
+ END LOOP;
+
+ -- That's all, folks!
+ RETURN moved_objects;
+END;
+$func$ LANGUAGE plpgsql;
+
COMMIT;
More information about the open-ils-commits
mailing list