3 -- Highest-numbered individual upgrade script
4 -- incorporated herein:
6 INSERT INTO config.upgrade_log (version) VALUES ('0387');
8 -- Add ON UPDATE CASCADE to some foreign keys so that, if we renumber the
9 -- permissions, the dependents will follow and stay in sync:
11 ALTER TABLE permission.grp_perm_map DROP CONSTRAINT grp_perm_map_perm_fkey;
12 ALTER TABLE permission.grp_perm_map ADD CONSTRAINT grp_perm_map_perm_fkey FOREIGN KEY (perm)
13 REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED;
15 ALTER TABLE permission.usr_perm_map DROP CONSTRAINT usr_perm_map_perm_fkey;
16 ALTER TABLE permission.usr_perm_map ADD CONSTRAINT usr_perm_map_perm_fkey FOREIGN KEY (perm)
17 REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED;
19 ALTER TABLE permission.usr_object_perm_map DROP CONSTRAINT usr_object_perm_map_perm_fkey;
20 ALTER TABLE permission.usr_object_perm_map ADD CONSTRAINT usr_object_perm_map_perm_fkey FOREIGN KEY (perm)
21 REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED;
23 -- Create a reference table as parent to both
24 -- config.org_unit_setting_type and config_usr_setting_type
26 CREATE TABLE config.settings_group (
27 name TEXT PRIMARY KEY,
28 label TEXT UNIQUE NOT NULL -- I18N
31 -- org_unit setting types
32 CREATE TABLE config.org_unit_setting_type (
33 name TEXT PRIMARY KEY,
34 label TEXT UNIQUE NOT NULL,
35 grp TEXT REFERENCES config.settings_group (name),
37 datatype TEXT NOT NULL DEFAULT 'string',
42 -- define valid datatypes
44 CONSTRAINT coust_valid_datatype CHECK ( datatype IN
45 ( 'bool', 'integer', 'float', 'currency', 'interval',
46 'date', 'string', 'object', 'array', 'link' ) ),
48 -- fm_class is meaningful only for 'link' datatype
50 CONSTRAINT coust_no_empty_link CHECK
51 ( ( datatype = 'link' AND fm_class IS NOT NULL ) OR
52 ( datatype <> 'link' AND fm_class IS NULL ) ),
53 CONSTRAINT view_perm_fkey FOREIGN KEY (view_perm) REFERENCES permission.perm_list (id)
56 DEFERRABLE INITIALLY DEFERRED,
57 CONSTRAINT update_perm_fkey FOREIGN KEY (update_perm) REFERENCES permission.perm_list (id)
59 DEFERRABLE INITIALLY DEFERRED
62 CREATE TABLE config.usr_setting_type (
64 name TEXT PRIMARY KEY,
65 opac_visible BOOL NOT NULL DEFAULT FALSE,
66 label TEXT UNIQUE NOT NULL,
68 grp TEXT REFERENCES config.settings_group (name),
69 datatype TEXT NOT NULL DEFAULT 'string',
73 -- define valid datatypes
75 CONSTRAINT coust_valid_datatype CHECK ( datatype IN
76 ( 'bool', 'integer', 'float', 'currency', 'interval',
77 'date', 'string', 'object', 'array', 'link' ) ),
80 -- fm_class is meaningful only for 'link' datatype
82 CONSTRAINT coust_no_empty_link CHECK
83 ( ( datatype = 'link' AND fm_class IS NOT NULL ) OR
84 ( datatype <> 'link' AND fm_class IS NULL ) )
88 --------------------------------------
89 -- Seed data for org_unit_setting_type
90 --------------------------------------
92 INSERT into config.org_unit_setting_type
93 ( name, label, description, datatype ) VALUES
95 ( 'auth.opac_timeout',
96 'OPAC Inactivity Timeout (in seconds)',
100 ( 'auth.staff_timeout',
101 'Staff Login Inactivity Timeout (in seconds)',
105 ( 'circ.lost_materials_processing_fee',
106 'Lost Materials Processing Fee',
110 ( 'cat.default_item_price',
111 'Default Item Price',
115 ( 'org.bounced_emails',
116 'Sending email address for patron notices',
120 ( 'circ.hold_expire_alert_interval',
121 'Holds: Expire Alert Interval',
122 'Amount of time before a hold expires at which point the patron should be alerted',
125 ( 'circ.hold_expire_interval',
126 'Holds: Expire Interval',
127 'Amount of time after a hold is placed before the hold expires. Example "100 days"',
130 ( 'credit.payments.allow',
131 'Allow Credit Card Payments',
132 'If enabled, patrons will be able to pay fines accrued at this location via credit card',
135 ( 'global.default_locale',
136 'Global Default Locale',
140 ( 'circ.void_overdue_on_lost',
141 'Void overdue fines when items are marked lost',
145 ( 'circ.hold_stalling.soft',
146 'Holds: Soft stalling interval',
147 'How long to wait before allowing remote items to be opportunisticaly captured for a hold. Example "5 days"',
150 ( 'circ.hold_stalling_hard',
151 'Holds: Hard stalling interval',
155 ( 'circ.hold_boundary.hard',
156 'Holds: Hard boundary',
160 ( 'circ.hold_boundary.soft',
161 'Holds: Soft boundary',
165 ( 'opac.barcode_regex',
166 'Patron barcode format',
167 'Regular expression defining the patron barcode format',
170 ( 'global.password_regex',
172 'Regular expression defining the password format',
175 ( 'circ.item_checkout_history.max',
176 'Maximum previous checkouts displayed',
177 'This is maximum number of previous circulations the staff client will display when investigating item details',
180 ( 'circ.reshelving_complete.interval',
181 'Change reshelving status interval',
182 'Amount of time to wait before changing an item from "reshelving" status to "available". Examples "1 day", "6 hours"',
185 ( 'circ.holds.default_estimated_wait_interval',
186 'Holds: Default Estimated Wait',
187 'When predicting the amount of time a patron will be waiting for a hold to be fulfilled, this is the default estimated length of time to assume an item will be checked out.',
190 ( 'circ.holds.min_estimated_wait_interval',
191 'Holds: Minimum Estimated Wait',
192 'When predicting the amount of time a patron will be waiting for a hold to be fulfilled, this is the minimum estimated length of time to assume an item will be checked out.',
195 ( 'circ.selfcheck.patron_login_timeout',
196 'Selfcheck: Patron Login Timeout (in seconds)',
197 'Number of seconds of inactivity before the patron is logged out of the selfcheck interfacer',
200 ( 'circ.selfcheck.alert.popup',
201 'Selfcheck: Pop-up alert for errors',
202 'If true, checkout/renewal errors will cause a pop-up window in addition to the on-screen message',
205 ( 'circ.selfcheck.require_patron_password',
206 'Selfcheck: Require patron password',
207 'If true, patrons will be required to enter their password in addition to their username/barcode to log into the selfcheck interface',
210 ( 'global.juvenile_age_threshold',
211 'Juvenile Age Threshold',
212 'The age at which a user is no long considered a juvenile. For example, "18 years".',
215 ( 'cat.bib.keep_on_empty',
216 'Retain empty bib records',
217 'Retain a bib record even when all attached copies are deleted',
220 ( 'cat.bib.alert_on_empty',
221 'Alert on empty bib records',
222 'Alert staff when the last copy for a record is being deleted',
225 ( 'patron.password.use_phone',
226 'Patron: password from phone #',
227 'Use the last 4 digits of the patrons phone number as the default password when creating new users',
230 ( 'circ.charge_on_damaged',
231 'Charge item price when marked damaged',
232 'Charge item price when marked damaged',
235 ( 'circ.charge_lost_on_zero',
236 'Charge lost on zero',
240 ( 'circ.damaged_item_processing_fee',
241 'Charge processing fee for damaged items',
242 'Charge processing fee for damaged items',
245 ( 'circ.void_lost_on_checkin',
246 'Circ: Void lost item billing when returned',
247 'Void lost item billing when returned',
250 ( 'circ.max_accept_return_of_lost',
251 'Circ: Void lost max interval',
252 'Items that have been lost this long will not result in voided billings when returned. E.g. ''6 months''',
255 ( 'circ.void_lost_proc_fee_on_checkin',
256 'Circ: Void processing fee on lost item return',
257 'Void processing fee when lost item returned',
260 ( 'circ.restore_overdue_on_lost_return',
261 'Circ: Restore overdues on lost item return',
262 'Restore overdue fines on lost item return',
265 ( 'circ.lost_immediately_available',
266 'Circ: Lost items usable on checkin',
267 'Lost items are usable on checkin instead of going ''home'' first',
272 'Force holds to a more strict First-In, First-Out capture',
275 ( 'opac.allow_pending_address',
276 'OPAC: Allow pending addresses',
277 'If enabled, patrons can create and edit existing addresses. Addresses are kept in a pending state until staff approves the changes',
280 ( 'ui.circ.show_billing_tab_on_bills',
281 'Show billing tab first when bills are present',
282 'If enabled and a patron has outstanding bills and the alert page is not required, show the billing tab by default, instead of the checkout tab, when a patron is loaded',
285 ( 'ui.general.idle_timeout',
287 'If you want staff client windows to be minimized after a certain amount of system idle time, set this to the number of seconds of idle time that you want to allow before minimizing (requires staff client restart).',
290 ( 'ui.circ.in_house_use.entry_cap',
291 'GUI: Record In-House Use: Maximum # of uses allowed per entry.',
292 'The # of uses entry in the Record In-House Use interface may not exceed the value of this setting.',
295 ( 'ui.circ.in_house_use.entry_warn',
296 'GUI: Record In-House Use: # of uses threshold for Are You Sure? dialog.',
297 'In the Record In-House Use interface, a submission attempt will warn if the # of uses field exceeds the value of this setting.',
300 ( 'acq.default_circ_modifier',
301 'Default circulation modifier',
305 ( 'acq.tmp_barcode_prefix',
306 'Temporary barcode prefix',
310 ( 'acq.tmp_callnumber_prefix',
311 'Temporary call number prefix',
315 ( 'ui.circ.patron_summary.horizontal',
316 'Patron circulation summary is horizontal',
320 ( 'ui.staff.require_initials',
321 oils_i18n_gettext('ui.staff.require_initials', 'GUI: Require staff initials for entry/edit of item/patron/penalty notes/messages.', 'coust', 'label'),
322 oils_i18n_gettext('ui.staff.require_initials', 'Appends staff initials and edit date into note content.', 'coust', 'description'),
325 ( 'ui.general.button_bar',
330 ( 'circ.hold_shelf_status_delay',
331 'Hold Shelf Status Delay',
332 'The purpose is to provide an interval of time after an item goes into the on-holds-shelf status before it appears to patrons that it is actually on the holds shelf. This gives staff time to process the item before it shows as ready-for-pickup.',
335 ( 'circ.patron_invalid_address_apply_penalty',
336 'Invalid patron address penalty',
337 'When set, if a patron address is set to invalid, a penalty is applied.',
340 ( 'circ.checkout_fills_related_hold',
341 'Checkout Fills Related Hold',
342 'When a patron checks out an item and they have no holds that directly target the item, the system will attempt to find a hold for the patron that could be fulfilled by the checked out item and fulfills it',
345 ( 'circ.selfcheck.auto_override_checkout_events',
346 'Selfcheck override events list',
347 'List of checkout/renewal events that the selfcheck interface should automatically override instead instead of alerting and stopping the transaction',
350 ( 'circ.staff_client.do_not_auto_attempt_print',
351 'Disable Automatic Print Attempt Type List',
352 'Disable automatic print attempts from staff client interfaces for the receipt types in this list. Possible values: "Checkout", "Bill Pay", "Hold Slip", "Transit Slip", and "Hold/Transit Slip". This is different from the Auto-Print checkbox in the pertinent interfaces in that it disables automatic print attempts altogether, rather than encouraging silent printing by suppressing the print dialog. The Auto-Print checkbox in these interfaces have no effect on the behavior for this setting. In the case of the Hold, Transit, and Hold/Transit slips, this also suppresses the alert dialogs that precede the print dialog (the ones that offer Print and Do Not Print as options).',
355 ( 'ui.patron.default_inet_access_level',
356 'Default level of patrons'' internet access',
360 ( 'circ.max_patron_claim_return_count',
361 'Max Patron Claims Returned Count',
362 'When this count is exceeded, a staff override is required to mark the item as claims returned',
365 ( 'circ.obscure_dob',
366 'Obscure the Date of Birth field',
367 'When true, the Date of Birth column in patron lists will default to Not Visible, and in the Patron Summary sidebar the value will display as <Hidden> unless the field label is clicked.',
370 ( 'circ.auto_hide_patron_summary',
371 'GUI: Toggle off the patron summary sidebar after first view.',
372 'When true, the patron summary sidebar will collapse after a new patron sub-interface is selected.',
375 ( 'credit.processor.default',
376 'Credit card processing: Name default credit processor',
377 'This might be "AuthorizeNet", "PayPal", etc.',
380 ( 'credit.processor.authorizenet.enabled',
381 'Credit card processing: AuthorizeNet enabled',
385 ( 'credit.processor.authorizenet.login',
386 'Credit card processing: AuthorizeNet login',
390 ( 'credit.processor.authorizenet.password',
391 'Credit card processing: AuthorizeNet password',
395 ( 'credit.processor.authorizenet.server',
396 'Credit card processing: AuthorizeNet server',
397 'Required if using a developer/test account with AuthorizeNet',
400 ( 'credit.processor.authorizenet.testmode',
401 'Credit card processing: AuthorizeNet test mode',
405 ( 'credit.processor.paypal.enabled',
406 'Credit card processing: PayPal enabled',
409 ( 'credit.processor.paypal.login',
410 'Credit card processing: PayPal login',
413 ( 'credit.processor.paypal.password',
414 'Credit card processing: PayPal password',
417 ( 'credit.processor.paypal.signature',
418 'Credit card processing: PayPal signature',
421 ( 'credit.processor.paypal.testmode',
422 'Credit card processing: PayPal test mode',
426 ( 'ui.admin.work_log.max_entries',
427 oils_i18n_gettext('ui.admin.work_log.max_entries', 'GUI: Work Log: Maximum Actions Logged', 'coust', 'label'),
428 oils_i18n_gettext('ui.admin.work_log.max_entries', 'Maximum entries for "Most Recent Staff Actions" section of the Work Log interface.', 'coust', 'description'),
431 ( 'ui.admin.patron_log.max_entries',
432 oils_i18n_gettext('ui.admin.patron_log.max_entries', 'GUI: Work Log: Maximum Patrons Logged', 'coust', 'label'),
433 oils_i18n_gettext('ui.admin.patron_log.max_entries', 'Maximum entries for "Most Recently Affected Patrons..." section of the Work Log interface.', 'coust', 'description'),
436 ( 'lib.courier_code',
437 oils_i18n_gettext('lib.courier_code', 'Courier Code', 'coust', 'label'),
438 oils_i18n_gettext('lib.courier_code', 'Courier Code for the library. Available in transit slip templates as the %courier_code% macro.', 'coust', 'description'),
441 ( 'circ.block_renews_for_holds',
442 oils_i18n_gettext('circ.block_renews_for_holds', 'Holds: Block Renewal of Items Needed for Holds', 'coust', 'label'),
443 oils_i18n_gettext('circ.block_renews_for_holds', 'When an item could fulfill a hold, do not allow the current patron to renew', 'coust', 'description'),
446 ( 'circ.password_reset_request_per_user_limit',
447 oils_i18n_gettext('circ.password_reset_request_per_user_limit', 'Circulation: Maximum concurrently active self-serve password reset requests per user', 'coust', 'label'),
448 oils_i18n_gettext('circ.password_reset_request_per_user_limit', 'When a user has more than this number of concurrently active self-serve password reset requests for their account, prevent the user from creating any new self-serve password reset requests until the number of active requests for the user drops back below this number.', 'coust', 'description'),
451 ( 'circ.password_reset_request_time_to_live',
452 oils_i18n_gettext('circ.password_reset_request_time_to_live', 'Circulation: Self-serve password reset request time-to-live', 'coust', 'label'),
453 oils_i18n_gettext('circ.password_reset_request_time_to_live', 'Length of time (in seconds) a self-serve password reset request should remain active.', 'coust', 'description'),
456 ( 'circ.password_reset_request_throttle',
457 oils_i18n_gettext('circ.password_reset_request_throttle', 'Circulation: Maximum concurrently active self-serve password reset requests', 'coust', 'label'),
458 oils_i18n_gettext('circ.password_reset_request_throttle', 'Prevent the creation of new self-serve password reset requests until the number of active requests drops back below this number.', 'coust', 'description'),
462 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
463 'ui.circ.suppress_checkin_popups',
465 'ui.circ.suppress_checkin_popups',
466 'Circ: Suppress popup-dialogs during check-in.',
470 'ui.circ.suppress_checkin_popups',
471 'Circ: Suppress popup-dialogs during check-in.',
477 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
481 'GUI: Format Dates with this pattern.',
486 'GUI: Format Dates with this pattern (examples: "yyyy-MM-dd" for "2010-04-26", "MMM d, yyyy" for "Apr 26, 2010")',
494 'GUI: Format Times with this pattern.',
499 'GUI: Format Times with this pattern (examples: "h:m:s.SSS a z" for "2:07:20.666 PM Eastern Daylight Time", "HH:mm" for "14:07")',
505 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
506 'cat.bib.delete_on_no_copy_via_acq_lineitem_cancel',
508 'cat.bib.delete_on_no_copy_via_acq_lineitem_cancel',
509 'CAT: Delete bib if all copies are deleted via Acquisitions lineitem cancellation.',
513 'cat.bib.delete_on_no_copy_via_acq_lineitem_cancel',
514 'CAT: Delete bib if all copies are deleted via Acquisitions lineitem cancellation.',
520 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
521 'url.remote_column_settings',
523 'url.remote_column_settings',
524 'GUI: URL for remote directory containing list column settings.',
528 'url.remote_column_settings',
529 'GUI: URL for remote directory containing list column settings. The format and naming convention for the files found in this directory match those in the local settings directory for a given workstation. An administrator could create the desired settings locally and then copy all the tree_columns_for_* files to the remote directory.',
535 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
536 'gui.disable_local_save_columns',
538 'gui.disable_local_save_columns',
539 'GUI: Disable the ability to save list column configurations locally.',
543 'gui.disable_local_save_columns',
544 'GUI: Disable the ability to save list column configurations locally. If set, columns may still be manipulated, however, the changes do not persist. Also, existing local configurations are ignored if this setting is true.',
550 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
551 'circ.password_reset_request_requires_matching_email',
553 'circ.password_reset_request_requires_matching_email',
554 'Circulation: Require matching email address for password reset requests',
558 'circ.password_reset_request_requires_matching_email',
559 'Circulation: Require matching email address for password reset requests',
565 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
566 'circ.holds.expired_patron_block',
568 'circ.holds.expired_patron_block',
569 'Circulation: Block hold request if hold recipient privileges have expired',
573 'circ.holds.expired_patron_block',
574 'Circulation: Block hold request if hold recipient privileges have expired',
580 INSERT INTO config.org_unit_setting_type
581 (name, label, description, datatype) VALUES (
582 'circ.booking_reservation.default_elbow_room',
584 'circ.booking_reservation.default_elbow_room',
585 'Booking: Elbow room',
590 'circ.booking_reservation.default_elbow_room',
591 'Elbow room specifies how far in the future you must make a reservation on an item if that item will have to transit to reach its pickup location. It secondarily defines how soon a reservation on a given item must start before the check-in process will opportunistically capture it for the reservation shelf.',
598 -- Org_unit_setting_type(s) that need an fm_class:
599 INSERT into config.org_unit_setting_type
600 ( name, label, description, datatype, fm_class ) VALUES
601 ( 'acq.default_copy_location',
602 'Default copy location',
607 INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
608 'circ.holds.org_unit_target_weight',
609 'Holds: Org Unit Target Weight',
610 'Org Units can be organized into hold target groups based on a weight. Potential copies from org units with the same weight are chosen at random.',
614 INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
615 'circ.holds.target_holds_by_org_unit_weight',
616 'Holds: Use weight-based hold targeting',
617 'Use library weight based hold targeting',
621 INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
622 'circ.holds.max_org_unit_target_loops',
623 'Holds: Maximum library target attempts',
624 'When this value is set and greater than 0, the system will only attempt to find a copy at each possible branch the configured number of times',
629 -- Org setting for overriding the circ lib of a precat copy
630 INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
631 'circ.pre_cat_copy_circ_lib',
632 'Pre-cat Item Circ Lib',
633 'Override the default circ lib of "here" with a pre-configured circ lib for pre-cat items. The value should be the "shortname" (aka policy name) of the org unit',
637 -- Circ auto-renew interval setting
638 INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
639 'circ.checkout_auto_renew_age',
640 'Checkout auto renew age',
641 'When an item has been checked out for at least this amount of time, an attempt to check out the item to the patron that it is already checked out to will simply renew the circulation',
645 -- Setting for behind the desk hold pickups
646 INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
647 'circ.holds.behind_desk_pickup_supported',
648 'Holds: Behind Desk Pickup Supported',
649 'If a branch supports both a public holds shelf and behind-the-desk pickups, set this value to true. This gives the patron the option to enable behind-the-desk pickups for their holds',
653 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
654 'acq.holds.allow_holds_from_purchase_request',
656 'acq.holds.allow_holds_from_purchase_request',
657 'Allows patrons to create automatic holds from purchase requests.',
661 'acq.holds.allow_holds_from_purchase_request',
662 'Allows patrons to create automatic holds from purchase requests.',
668 INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
669 'circ.holds.target_skip_me',
670 'Skip For Hold Targeting',
671 'When true, don''t target any copies at this org unit for holds',
675 -- claims returned mark item missing
677 config.org_unit_setting_type ( name, label, description, datatype )
679 'circ.claim_return.mark_missing',
680 'Claim Return: Mark copy as missing',
681 'When a circ is marked as claims-returned, also mark the copy as missing',
685 -- claims never checked out mark item missing
687 config.org_unit_setting_type ( name, label, description, datatype )
689 'circ.claim_never_checked_out.mark_missing',
690 'Claim Never Checked Out: Mark copy as missing',
691 'When a circ is marked as claims-never-checked-out, mark the copy as missing',
695 -- mark damaged void overdue setting
697 config.org_unit_setting_type ( name, label, description, datatype )
699 'circ.damaged.void_ovedue',
700 'Mark item damaged voids overdues',
701 'When an item is marked damaged, overdue fines on the most recent circulation are voided.',
705 -- hold cancel display limits
706 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
708 'circ.holds.canceled.display_count',
709 'Holds: Canceled holds display count',
710 'How many canceled holds to show in patron holds interfaces',
714 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
716 'circ.holds.canceled.display_age',
717 'Holds: Canceled holds display age',
718 'Show all canceled holds that were canceled within this amount of time',
722 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
724 'circ.holds.uncancel.reset_request_time',
725 'Holds: Reset request time on un-cancel',
726 'When a holds is uncanceled, reset the request time to push it to the end of the queue',
730 INSERT INTO config.org_unit_setting_type (name, label, description, datatype)
732 'circ.holds.default_shelf_expire_interval',
733 'Default hold shelf expire interval',
738 INSERT INTO config.org_unit_setting_type (name, label, description, datatype, fm_class)
740 'circ.claim_return.copy_status',
741 'Claim Return Copy Status',
742 'Claims returned copies are put into this status. Default is to leave the copy in the Checked Out status',
747 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
749 'circ.max_fine.cap_at_price',
750 oils_i18n_gettext('circ.max_fine.cap_at_price', 'Circ: Cap Max Fine at Item Price', 'coust', 'label'),
751 oils_i18n_gettext('circ.max_fine.cap_at_price', 'This prevents the system from charging more than the item price in overdue fines', 'coust', 'description'),
755 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype, fm_class )
757 'circ.holds.clear_shelf.copy_status',
758 oils_i18n_gettext('circ.holds.clear_shelf.copy_status', 'Holds: Clear shelf copy status', 'coust', 'label'),
759 oils_i18n_gettext('circ.holds.clear_shelf.copy_status', 'Any copies that have not been put into reshelving, in-transit, or on-holds-shelf (for a new hold) during the clear shelf process will be put into this status. This is basically a purgatory status for copies waiting to be pulled from the shelf and processed by hand', 'coust', 'description'),
764 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
766 'circ.selfcheck.workstation_required',
767 oils_i18n_gettext('circ.selfcheck.workstation_required', 'Selfcheck: Workstation Required', 'coust', 'label'),
768 oils_i18n_gettext('circ.selfcheck.workstation_required', 'All selfcheck stations must use a workstation', 'coust', 'description'),
771 'circ.selfcheck.patron_password_required',
772 oils_i18n_gettext('circ.selfcheck.patron_password_required', 'Selfcheck: Require Patron Password', 'coust', 'label'),
773 oils_i18n_gettext('circ.selfcheck.patron_password_required', 'Patron must log in with barcode and password at selfcheck station', 'coust', 'description'),
777 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
779 'circ.selfcheck.alert.sound',
780 oils_i18n_gettext('circ.selfcheck.alert.sound', 'Selfcheck: Audio Alerts', 'coust', 'label'),
781 oils_i18n_gettext('circ.selfcheck.alert.sound', 'Use audio alerts for selfcheck events', 'coust', 'description'),
786 config.org_unit_setting_type (name, label, description, datatype)
788 'notice.telephony.callfile_lines',
789 'Telephony: Arbitrary line(s) to include in each notice callfile',
791 This overrides lines from opensrf.xml.
792 Line(s) must be valid for your target server and platform
798 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
800 'circ.offline.username_allowed',
801 oils_i18n_gettext('circ.offline.username_allowed', 'Offline: Patron Usernames Allowed', 'coust', 'label'),
802 oils_i18n_gettext('circ.offline.username_allowed', 'During offline circulations, allow patrons to identify themselves with usernames in addition to barcode. For this setting to work, a barcode format must also be defined', 'coust', 'description'),
806 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
808 'acq.fund.balance_limit.warn',
809 oils_i18n_gettext('acq.fund.balance_limit.warn', 'Fund Spending Limit for Warning', 'coust', 'label'),
810 oils_i18n_gettext('acq.fund.balance_limit.warn', 'When the amount remaining in the fund, including spent money and encumbrances, goes below this percentage, attempts to spend from the fund will result in a warning to the staff.', 'coust', 'descripton'),
814 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
816 'acq.fund.balance_limit.block',
817 oils_i18n_gettext('acq.fund.balance_limit.block', 'Fund Spending Limit for Block', 'coust', 'label'),
818 oils_i18n_gettext('acq.fund.balance_limit.block', 'When the amount remaining in the fund, including spent money and encumbrances, goes below this percentage, attempts to spend from the fund will be blocked.', 'coust', 'description'),
822 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
824 'circ.holds.hold_has_copy_at.alert',
825 oils_i18n_gettext('circ.holds.hold_has_copy_at.alert', 'Holds: Has Local Copy Alert', 'coust', 'label'),
826 oils_i18n_gettext('circ.holds.hold_has_copy_at.alert', 'If there is an available copy at the requesting library that could fulfill a hold during hold placement time, alert the patron', 'coust', 'description'),
829 'circ.holds.hold_has_copy_at.block',
830 oils_i18n_gettext('circ.holds.hold_has_copy_at.block', 'Holds: Has Local Copy Block', 'coust', 'label'),
831 oils_i18n_gettext('circ.holds.hold_has_copy_at.block', 'If there is an available copy at the requesting library that could fulfill a hold during hold placement time, do not allow the hold to be placed', 'coust', 'description'),
835 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
837 'auth.persistent_login_interval',
838 oils_i18n_gettext('auth.persistent_login_interval', 'Persistent Login Duration', 'coust', 'label'),
839 oils_i18n_gettext('auth.persistent_login_interval', 'How long a persistent login lasts. E.g. ''2 weeks''', 'coust', 'description'),
843 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
844 'cat.marc_control_number_identifier',
846 'cat.marc_control_number_identifier',
847 'Cat: Defines the control number identifier used in 003 and 035 fields.',
851 'cat.marc_control_number_identifier',
852 'Cat: Defines the control number identifier used in 003 and 035 fields.',
858 INSERT INTO config.org_unit_setting_type (name, label, description, datatype)
860 'circ.selfcheck.block_checkout_on_copy_status',
862 'circ.selfcheck.block_checkout_on_copy_status',
863 'Selfcheck: Block copy checkout status',
868 'circ.selfcheck.block_checkout_on_copy_status',
869 'List of copy status IDs that will block checkout even if the generic COPY_NOT_AVAILABLE event is overridden',
876 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype, fm_class )
878 'serial.prev_issuance_copy_location',
880 'serial.prev_issuance_copy_location',
881 'Serials: Previous Issuance Copy Location',
886 'serial.prev_issuance_copy_location',
887 'When a serial issuance is received, copies (units) of the previous issuance will be automatically moved into the configured shelving location',
895 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype, fm_class )
897 'cat.default_classification_scheme',
899 'cat.default_classification_scheme',
900 'Cataloging: Default Classification Scheme',
905 'cat.default_classification_scheme',
906 'Defines the default classification scheme for new call numbers: 1 = Generic; 2 = Dewey; 3 = LC',
914 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
915 'opac.org_unit_hiding.depth',
917 'opac.org_unit_hiding.depth',
918 'OPAC: Org Unit Hiding Depth',
922 'opac.org_unit_hiding.depth',
923 'This will hide certain org units in the public OPAC if the Original Location (url param "ol") for the OPAC inherits this setting. This setting specifies an org unit depth, that together with the OPAC Original Location determines which section of the Org Hierarchy should be visible in the OPAC. For example, a stock Evergreen installation will have a 3-tier hierarchy (Consortium/System/Branch), where System has a depth of 1 and Branch has a depth of 2. If this setting contains a depth of 1 in such an installation, then every library in the System in which the Original Location belongs will be visible, and everything else will be hidden. A depth of 0 will effectively make every org visible. The embedded OPAC in the staff client ignores this setting.',
929 INSERT INTO config.org_unit_setting_type (name, label, description, datatype)
931 ('circ.holds.alert_if_local_avail',
932 'Holds: Local available alert',
933 'If local copy is available, alert the person making the hold',
936 ('circ.holds.deny_if_local_avail',
937 'Holds: Local available block',
938 'If local copy is available, deny the creation of the hold',
942 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
944 'circ.holds.clear_shelf.no_capture_holds',
945 oils_i18n_gettext('circ.holds.clear_shelf.no_capture_holds', 'Holds: Bypass hold capture during clear shelf process', 'coust', 'label'),
946 oils_i18n_gettext('circ.holds.clear_shelf.no_capture_holds', 'During the clear shelf process, avoid capturing new holds on cleared items.', 'coust', 'description'),
950 INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES (
951 'circ.booking_reservation.stop_circ',
952 'Disallow circulation of items when they are on booking reserve and that reserve overlaps with the checkout period',
953 'When true, items on booking reserve during the proposed checkout period will not be allowed to circulate unless overridden with the COPY_RESERVED.override permission.',
957 ---------------------------------
958 -- Seed data for usr_setting_type
959 ----------------------------------
961 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
962 VALUES ('opac.default_font', TRUE, 'OPAC Font Size', 'OPAC Font Size', 'string');
964 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
965 VALUES ('opac.default_search_depth', TRUE, 'OPAC Search Depth', 'OPAC Search Depth', 'integer');
967 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
968 VALUES ('opac.default_search_location', TRUE, 'OPAC Search Location', 'OPAC Search Location', 'integer');
970 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
971 VALUES ('opac.hits_per_page', TRUE, 'Hits per Page', 'Hits per Page', 'string');
973 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
974 VALUES ('opac.hold_notify', TRUE, 'Hold Notification Format', 'Hold Notification Format', 'string');
976 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
977 VALUES ('staff_client.catalog.record_view.default', TRUE, 'Default Record View', 'Default Record View', 'string');
979 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
980 VALUES ('staff_client.copy_editor.templates', TRUE, 'Copy Editor Template', 'Copy Editor Template', 'object');
982 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
983 VALUES ('circ.holds_behind_desk', FALSE, 'Hold is behind Circ Desk', 'Hold is behind Circ Desk', 'bool');
985 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
987 'history.circ.retention_age',
989 oils_i18n_gettext('history.circ.retention_age','Historical Circulation Retention Age','cust','label'),
990 oils_i18n_gettext('history.circ.retention_age','Historical Circulation Retention Age','cust','description'),
993 'history.circ.retention_start',
995 oils_i18n_gettext('history.circ.retention_start','Historical Circulation Retention Start Date','cust','label'),
996 oils_i18n_gettext('history.circ.retention_start','Historical Circulation Retention Start Date','cust','description'),
1000 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
1002 'history.hold.retention_age',
1004 oils_i18n_gettext('history.hold.retention_age','Historical Hold Retention Age','cust','label'),
1005 oils_i18n_gettext('history.hold.retention_age','Historical Hold Retention Age','cust','description'),
1008 'history.hold.retention_start',
1010 oils_i18n_gettext('history.hold.retention_start','Historical Hold Retention Start Date','cust','label'),
1011 oils_i18n_gettext('history.hold.retention_start','Historical Hold Retention Start Date','cust','description'),
1014 'history.hold.retention_count',
1016 oils_i18n_gettext('history.hold.retention_count','Historical Hold Retention Count','cust','label'),
1017 oils_i18n_gettext('history.hold.retention_count','Historical Hold Retention Count','cust','description'),
1021 INSERT INTO config.usr_setting_type (name, opac_visible, label, description, datatype)
1023 'opac.default_sort',
1026 'opac.default_sort',
1027 'OPAC Default Search Sort',
1032 'opac.default_sort',
1033 'OPAC Default Search Sort',
1040 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype, fm_class ) VALUES (
1041 'circ.missing_pieces.copy_status',
1043 'circ.missing_pieces.copy_status',
1044 'Circulation: Item Status for Missing Pieces',
1048 'circ.missing_pieces.copy_status',
1049 'This is the Item Status to use for items that have been marked or scanned as having Missing Pieces. In absense of this setting, the Damaged status is used.',
1056 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
1057 'circ.do_not_tally_claims_returned',
1059 'circ.do_not_tally_claims_returned',
1060 'Circulation: Do not include outstanding Claims Returned circulations in lump sum tallies in Patron Display.',
1064 'circ.do_not_tally_claims_returned',
1065 'In the Patron Display interface, the number of total active circulations for a given patron is presented in the Summary sidebar and underneath the Items Out navigation button. This setting will prevent Claims Returned circulations from counting toward these tallies.',
1071 INSERT INTO config.org_unit_setting_type (name, label, description, datatype)
1073 ('cat.label.font.size',
1074 oils_i18n_gettext('cat.label.font.size',
1075 'Cataloging: Spine and pocket label font size', 'coust', 'label'),
1076 oils_i18n_gettext('cat.label.font.size',
1077 'Set the default font size for spine and pocket labels', 'coust', 'description'),
1080 ,('cat.label.font.family',
1081 oils_i18n_gettext('cat.label.font.family',
1082 'Cataloging: Spine and pocket label font family', 'coust', 'label'),
1083 oils_i18n_gettext('cat.label.font.family',
1084 'Set the preferred font family for spine and pocket labels. You can specify a list of fonts, separated by commas, in order of preference; the system will use the first font it finds with a matching name. For example, "Arial, Helvetica, serif".',
1085 'coust', 'description'),
1088 ,('cat.spine.line.width',
1089 oils_i18n_gettext('cat.spine.line.width',
1090 'Cataloging: Spine label line width', 'coust', 'label'),
1091 oils_i18n_gettext('cat.spine.line.width',
1092 'Set the default line width for spine labels in number of characters. This specifies the boundary at which lines must be wrapped.',
1093 'coust', 'description'),
1096 ,('cat.spine.line.height',
1097 oils_i18n_gettext('cat.spine.line.height',
1098 'Cataloging: Spine label maximum lines', 'coust', 'label'),
1099 oils_i18n_gettext('cat.spine.line.height',
1100 'Set the default maximum number of lines for spine labels.',
1101 'coust', 'description'),
1104 ,('cat.spine.line.margin',
1105 oils_i18n_gettext('cat.spine.line.margin',
1106 'Cataloging: Spine label left margin', 'coust', 'label'),
1107 oils_i18n_gettext('cat.spine.line.margin',
1108 'Set the left margin for spine labels in number of characters.',
1109 'coust', 'description'),
1114 INSERT INTO config.org_unit_setting_type (name, label, description, datatype)
1116 ('cat.label.font.weight',
1117 oils_i18n_gettext('cat.label.font.weight',
1118 'Cataloging: Spine and pocket label font weight', 'coust', 'label'),
1119 oils_i18n_gettext('cat.label.font.weight',
1120 'Set the preferred font weight for spine and pocket labels. You can specify "normal", "bold", "bolder", or "lighter".',
1121 'coust', 'description'),
1126 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
1127 'circ.patron_edit.clone.copy_address',
1129 'circ.patron_edit.clone.copy_address',
1130 'Patron Registration: Cloned patrons get address copy',
1135 'circ.patron_edit.clone.copy_address',
1136 'In the Patron editor, copy addresses from the cloned user instead of linking directly to the address',
1143 -- Patch the name of an old selfcheck setting
1144 UPDATE actor.org_unit_setting
1145 SET name = 'circ.selfcheck.alert.popup'
1146 WHERE name = 'circ.selfcheck.alert_on_checkout_event';
1148 -- Rename certain existing org_unit settings, if present,
1149 -- and make sure their values are JSON
1150 UPDATE actor.org_unit_setting SET
1151 name = 'circ.holds.default_estimated_wait_interval',
1153 -- The value column should be JSON. The old value should be a number,
1154 -- but it may or may not be quoted. The following CASE behaves
1155 -- differently depending on whether value is quoted. It is simplistic,
1156 -- and will be defeated by leading or trailing white space, or various
1159 value = CASE WHEN SUBSTR( value, 1, 1 ) = '"'
1160 THEN '"' || SUBSTR( value, 2, LENGTH(value) - 2 ) || ' days"'
1161 ELSE '"' || value || ' days"'
1163 WHERE name = 'circ.hold_estimate_wait_interval';
1165 -- Create types for existing org unit settings
1166 -- not otherwise accounted for
1168 INSERT INTO config.org_unit_setting_type(
1178 actor.org_unit_setting
1182 FROM config.org_unit_setting_type
1185 -- Add foreign key to org_unit_setting
1187 ALTER TABLE actor.org_unit_setting
1188 ADD FOREIGN KEY (name) REFERENCES config.org_unit_setting_type (name)
1189 DEFERRABLE INITIALLY DEFERRED;
1191 -- Create types for existing user settings
1192 -- not otherwise accounted for
1194 INSERT INTO config.usr_setting_type (
1208 FROM config.usr_setting_type
1211 -- Add foreign key to user_setting_type
1213 ALTER TABLE actor.usr_setting
1214 ADD FOREIGN KEY (name) REFERENCES config.usr_setting_type (name)
1215 ON DELETE CASCADE ON UPDATE CASCADE
1216 DEFERRABLE INITIALLY DEFERRED;
1218 INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES
1219 (1, 'cat.spine.line.margin', 0)
1220 ,(1, 'cat.spine.line.height', 9)
1221 ,(1, 'cat.spine.line.width', 8)
1222 ,(1, 'cat.label.font.family', '"monospace"')
1223 ,(1, 'cat.label.font.size', 10)
1224 ,(1, 'cat.label.font.weight', '"normal"')
1227 ALTER TABLE action_trigger.event_definition ADD COLUMN granularity TEXT;
1228 ALTER TABLE action_trigger.event ADD COLUMN async_output BIGINT REFERENCES action_trigger.event_output (id);
1229 ALTER TABLE action_trigger.event_definition ADD COLUMN usr_field TEXT;
1230 ALTER TABLE action_trigger.event_definition ADD COLUMN opt_in_setting TEXT REFERENCES config.usr_setting_type (name) DEFERRABLE INITIALLY DEFERRED;
1232 CREATE OR REPLACE FUNCTION is_json( TEXT ) RETURNS BOOL AS $f$
1235 eval { JSON::XS->new->allow_nonref->decode( $json ) };
1237 $f$ LANGUAGE PLPERLU;
1239 ALTER TABLE action_trigger.event ADD COLUMN user_data TEXT CHECK (user_data IS NULL OR is_json( user_data ));
1241 INSERT INTO action_trigger.hook (key,core_type,description) VALUES (
1242 'hold_request.cancel.expire_no_target',
1244 'A hold is cancelled because no copies were found'
1247 INSERT INTO action_trigger.hook (key,core_type,description) VALUES (
1248 'hold_request.cancel.expire_holds_shelf',
1250 'A hold is cancelled becuase it was on the holds shelf too long'
1253 INSERT INTO action_trigger.hook (key,core_type,description) VALUES (
1254 'hold_request.cancel.staff',
1256 'A hold is cancelled becuase it was cancelled by staff'
1259 INSERT INTO action_trigger.hook (key,core_type,description) VALUES (
1260 'hold_request.cancel.patron',
1262 'A hold is cancelled by the patron'
1265 -- Fix typos in descriptions
1266 UPDATE action_trigger.hook SET description = 'A hold is successfully placed' WHERE key = 'hold_request.success';
1267 UPDATE action_trigger.hook SET description = 'A hold is attempted but not successfully placed' WHERE key = 'hold_request.failure';
1269 -- Add a hook for renewals
1270 INSERT INTO action_trigger.hook (key,core_type,description) VALUES ('renewal','circ','Item renewed to user');
1272 INSERT INTO action_trigger.validator (module,description) VALUES ('MaxPassiveDelayAge','Check that the event is not too far past the delay_field time -- requires a max_delay_age interval parameter');
1274 -- Sample Pre-due Notice --
1276 INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, delay, delay_field, group_field, template)
1277 VALUES (6, 'f', 1, '3 Day Courtesy Notice', 'checkout.due', 'CircIsOpen', 'SendEmail', '-3 days', 'due_date', 'usr',
1280 [%- user = target.0.usr -%]
1281 To: [%- params.recipient_email || user.email %]
1282 From: [%- params.sender_email || default_sender %]
1283 Subject: Courtesy Notice
1285 Dear [% user.family_name %], [% user.first_given_name %]
1286 As a reminder, the following items are due in 3 days.
1288 [% FOR circ IN target %]
1289 Title: [% circ.target_copy.call_number.record.simple_record.title %]
1290 Barcode: [% circ.target_copy.barcode %]
1291 Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
1292 Item Cost: [% helpers.get_copy_price(circ.target_copy) %]
1293 Library: [% circ.circ_lib.name %]
1294 Library Phone: [% circ.circ_lib.phone %]
1299 INSERT INTO action_trigger.environment (event_def, path) VALUES
1300 (6, 'target_copy.call_number.record.simple_record'),
1302 (6, 'circ_lib.billing_address');
1304 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
1305 (6, 'max_delay_age', '"1 day"');
1307 -- also add the max delay age to the default overdue notice event def
1308 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
1309 (1, 'max_delay_age', '"1 day"');
1311 INSERT INTO action_trigger.validator (module,description) VALUES ('MinPassiveTargetAge','Check that the target is old enough to be used by this event -- requires a min_target_age interval parameter, and accepts an optional target_age_field to specify what time to use for offsetting');
1313 INSERT INTO action_trigger.reactor (module,description) VALUES ('ApplyPatronPenalty','Applies the conifigured penalty to a patron. Required named environment variables are "user", which refers to the user object, and "context_org", which refers to the org_unit object that acts as the focus for the penalty.');
1315 INSERT INTO action_trigger.hook (
1321 'hold_request.shelf_expires_soon',
1323 'A hold on the shelf will expire there soon.',
1327 INSERT INTO action_trigger.event_definition (
1343 'Hold Expires from Shelf Soon',
1344 'hold_request.shelf_expires_soon',
1348 'shelf_expire_time',
1352 [%- user = target.0.usr -%]
1353 To: [%- params.recipient_email || user.email %]
1354 From: [%- params.sender_email || default_sender %]
1355 Subject: Hold Available Notification
1357 Dear [% user.family_name %], [% user.first_given_name %]
1358 You requested holds on the following item(s), which are available for
1359 pickup, but these holds will soon expire.
1361 [% FOR hold IN target %]
1362 [%- data = helpers.get_copy_bib_basics(hold.current_copy.id) -%]
1363 Title: [% data.title %]
1364 Author: [% data.author %]
1365 Library: [% hold.pickup_lib.name %]
1370 INSERT INTO action_trigger.environment (
1374 ( 7, 'current_copy'),
1375 ( 7, 'pickup_lib.billing_address'),
1378 INSERT INTO action_trigger.hook (
1384 'hold_request.long_wait',
1386 'A patron has been waiting on a hold to be fulfilled for a long time.',
1390 INSERT INTO action_trigger.event_definition (
1406 'Hold waiting for pickup for long time',
1407 'hold_request.long_wait',
1415 [%- user = target.0.usr -%]
1416 To: [%- params.recipient_email || user.email %]
1417 From: [%- params.sender_email || default_sender %]
1418 Subject: Long Wait Hold Notification
1420 Dear [% user.family_name %], [% user.first_given_name %]
1422 You requested hold(s) on the following item(s), but unfortunately
1423 we have not been able to fulfill your request after a considerable
1424 length of time. If you would still like to recieve these items,
1425 no action is required.
1427 [% FOR hold IN target %]
1428 Title: [% hold.bib_rec.bib_record.simple_record.title %]
1429 Author: [% hold.bib_rec.bib_record.simple_record.author %]
1434 INSERT INTO action_trigger.environment (
1440 (9, 'bib_rec.bib_record.simple_record');
1442 INSERT INTO action_trigger.hook (key, core_type, description, passive)
1444 'format.selfcheck.checkout',
1446 'Formats circ objects for self-checkout receipt',
1450 INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, group_field, granularity, template )
1455 'Self-Checkout Receipt',
1456 'format.selfcheck.checkout',
1463 [%- SET user = target.0.usr -%]
1464 [%- SET lib = target.0.circ_lib -%]
1465 [%- SET lib_addr = target.0.circ_lib.billing_address -%]
1466 [%- SET hours = lib.hours_of_operation -%]
1468 <style> li { padding: 8px; margin 5px; }</style>
1469 <div>[% date.format %]</div>
1470 <div>[% lib.name %]</div>
1471 <div>[% lib_addr.street1 %] [% lib_addr.street2 %]</div>
1472 <div>[% lib_addr.city %], [% lib_addr.state %] [% lb_addr.post_code %]</div>
1473 <div>[% lib.phone %]</div>
1476 [% user.family_name %], [% user.first_given_name %]
1478 [% FOR circ IN target %]
1480 SET idx = loop.count - 1;
1481 SET udata = user_data.$idx
1484 <div>[% helpers.get_copy_bib_basics(circ.target_copy.id).title %]</div>
1485 <div>Barcode: [% circ.target_copy.barcode %]</div>
1486 [% IF udata.renewal_failure %]
1487 <div style='color:red;'>Renewal Failed</div>
1489 <div>Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]</div>
1497 [%- BLOCK format_time; date.format(time _ ' 1/1/1000', format='%I:%M %p'); END -%]
1500 [% PROCESS format_time time = hours.dow_0_open %]
1501 [% PROCESS format_time time = hours.dow_0_close %]
1505 [% PROCESS format_time time = hours.dow_1_open %]
1506 [% PROCESS format_time time = hours.dow_1_close %]
1510 [% PROCESS format_time time = hours.dow_2_open %]
1511 [% PROCESS format_time time = hours.dow_2_close %]
1515 [% PROCESS format_time time = hours.dow_3_open %]
1516 [% PROCESS format_time time = hours.dow_3_close %]
1520 [% PROCESS format_time time = hours.dow_4_open %]
1521 [% PROCESS format_time time = hours.dow_4_close %]
1525 [% PROCESS format_time time = hours.dow_5_open %]
1526 [% PROCESS format_time time = hours.dow_5_close %]
1530 [% PROCESS format_time time = hours.dow_6_open %]
1531 [% PROCESS format_time time = hours.dow_6_close %]
1538 INSERT INTO action_trigger.environment ( event_def, path) VALUES
1539 ( 10, 'target_copy'),
1540 ( 10, 'circ_lib.billing_address'),
1541 ( 10, 'circ_lib.hours_of_operation'),
1544 INSERT INTO action_trigger.hook (key, core_type, description, passive)
1546 'format.selfcheck.items_out',
1548 'Formats items out for self-checkout receipt',
1552 INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, group_field, granularity, template )
1557 'Self-Checkout Items Out Receipt',
1558 'format.selfcheck.items_out',
1565 [%- SET user = target.0.usr -%]
1567 <style> li { padding: 8px; margin 5px; }</style>
1568 <div>[% date.format %]</div>
1571 [% user.family_name %], [% user.first_given_name %]
1573 [% FOR circ IN target %]
1575 <div>[% helpers.get_copy_bib_basics(circ.target_copy.id).title %]</div>
1576 <div>Barcode: [% circ.target_copy.barcode %]</div>
1577 <div>Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]</div>
1586 INSERT INTO action_trigger.environment ( event_def, path) VALUES
1587 ( 11, 'target_copy'),
1588 ( 11, 'circ_lib.billing_address'),
1589 ( 11, 'circ_lib.hours_of_operation'),
1592 INSERT INTO action_trigger.hook (key, core_type, description, passive)
1594 'format.selfcheck.holds',
1596 'Formats holds for self-checkout receipt',
1600 INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, group_field, granularity, template )
1605 'Self-Checkout Holds Receipt',
1606 'format.selfcheck.holds',
1613 [%- SET user = target.0.usr -%]
1615 <style> li { padding: 8px; margin 5px; }</style>
1616 <div>[% date.format %]</div>
1619 [% user.family_name %], [% user.first_given_name %]
1621 [% FOR hold IN target %]
1623 SET idx = loop.count - 1;
1624 SET udata = user_data.$idx
1627 <div>Title: [% hold.bib_rec.bib_record.simple_record.title %]</div>
1628 <div>Author: [% hold.bib_rec.bib_record.simple_record.author %]</div>
1629 <div>Pickup Location: [% hold.pickup_lib.name %]</div>
1631 [%- IF udata.ready -%]
1634 #[% udata.queue_position %] of [% udata.potential_copies %] copies.
1645 INSERT INTO action_trigger.environment ( event_def, path) VALUES
1646 ( 12, 'bib_rec.bib_record.simple_record'),
1647 ( 12, 'pickup_lib'),
1650 INSERT INTO action_trigger.hook (key, core_type, description, passive)
1652 'format.selfcheck.fines',
1654 'Formats fines for self-checkout receipt',
1658 INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, granularity, template )
1663 'Self-Checkout Fines Receipt',
1664 'format.selfcheck.fines',
1670 [%- SET user = target -%]
1672 <style> li { padding: 8px; margin 5px; }</style>
1673 <div>[% date.format %]</div>
1676 [% user.family_name %], [% user.first_given_name %]
1678 [% FOR xact IN user.open_billable_transactions_summary %]
1681 [% IF xact.xact_type == 'circulation' %]
1682 [%- helpers.get_copy_bib_basics(xact.circulation.target_copy).title -%]
1684 [%- xact.last_billing_type -%]
1687 <div>Total Billed: [% xact.total_owed %]</div>
1688 <div>Total Paid: [% xact.total_paid %]</div>
1689 <div>Balance Owed : [% xact.balance_owed %]</div>
1697 INSERT INTO action_trigger.environment ( event_def, path) VALUES
1698 ( 13, 'open_billable_transactions_summary.circulation' );
1700 INSERT INTO action_trigger.reactor (module,description) VALUES
1704 'Build and transfer a file to a remote server. Required parameter "remote_host" specifying target server. Optional parameters: remote_user, remote_password, remote_account, port, type (FTP, SFTP or SCP), and debug.',
1710 INSERT INTO action_trigger.hook (key, core_type, description, passive)
1712 'format.acqli.html',
1714 'Formats lineitem worksheet for titles received',
1718 INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, granularity, template)
1723 'Lineitem Worksheet',
1724 'format.acqli.html',
1730 [%- SET li = target; -%]
1731 <div class="wrapper">
1732 <div class="summary" style='font-size:110%; font-weight:bold;'>
1734 <div>Title: [% helpers.get_li_attr("title", "", li.attributes) %]</div>
1735 <div>Author: [% helpers.get_li_attr("author", "", li.attributes) %]</div>
1736 <div class="count">Item Count: [% li.lineitem_details.size %]</div>
1737 <div class="lineid">Lineitem ID: [% li.id %]</div>
1739 [% IF li.distribution_formulas.size > 0 %]
1740 [% SET forms = [] %]
1741 [% FOREACH form IN li.distribution_formulas; forms.push(form.formula.name); END %]
1742 <div>Distribution Formulas: [% forms.join(',') %]</div>
1745 [% IF li.lineitem_notes.size > 0 %]
1748 [%- FOR note IN li.lineitem_notes -%]
1750 [% IF note.alert_text %]
1751 [% note.alert_text.code -%]
1752 [% IF note.value -%]
1769 <th>Call Number</th>
1776 [% FOREACH detail IN li.lineitem_details.sort('owning_lib') %]
1779 SET copy = copy.eg_copy_id;
1780 SET cn_label = copy.call_number.label;
1783 SET cn_label = detail.cn_label;
1787 <!-- acq.lineitem_detail.id = [%- detail.id -%] -->
1788 <td style='padding:5px;'>[% detail.owning_lib.shortname %]</td>
1789 <td style='padding:5px;'>[% IF copy.barcode %]<span class="barcode" >[% detail.barcode %]</span>[% END %]</td>
1790 <td style='padding:5px;'>[% IF cn_label %]<span class="cn_label" >[% cn_label %]</span>[% END %]</td>
1791 <td style='padding:5px;'>[% IF detail.fund %]<span class="fund">[% detail.fund.code %] ([% detail.fund.year %])</span>[% END %]</td>
1792 <td style='padding:5px;'>[% IF detail.recv_time %]<span class="recv_time">[% detail.recv_time %]</span>[% END %]</td>
1793 <td style='padding:5px;'>[% detail.note %]</td>
1803 INSERT INTO action_trigger.environment (event_def, path) VALUES
1804 ( 14, 'attributes' ),
1805 ( 14, 'lineitem_details' ),
1806 ( 14, 'lineitem_details.owning_lib' ),
1807 ( 14, 'lineitem_notes' )
1810 INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES (
1815 'A patron acquisition request has been marked On-Order.',
1825 'A patron acquisition request has been marked Received.',
1835 'A patron acquisition request has been marked Cancelled.',
1843 INSERT INTO action_trigger.validator (module,description) VALUES (
1844 'Acq::UserRequestOrdered',
1846 'Acq::UserRequestOrdered',
1847 'Tests to see if the corresponding Line Item has a state of "on-order".',
1852 'Acq::UserRequestReceived',
1854 'Acq::UserRequestReceived',
1855 'Tests to see if the corresponding Line Item has a state of "received".',
1860 'Acq::UserRequestCancelled',
1862 'Acq::UserRequestCancelled',
1863 'Tests to see if the corresponding Line Item has a state of "cancelled".',
1870 -- What was event_definition #15 in v1.6.1 will be recreated as #20. This
1871 -- renumbering requires some juggling:
1873 -- 1. Update any child rows to point to #20. These updates will temporarily
1874 -- violate foreign key constraints, but that's okay as long as we create
1875 -- #20 before committing.
1877 -- 2. Delete the old #15.
1879 -- 3. Insert the new #15.
1883 -- We could combine steps 2 and 3 into a single update, but that would create
1884 -- additional opportunities for typos, since we already have the insert from
1885 -- an upgrade script.
1887 UPDATE action_trigger.environment
1889 WHERE event_def = 15;
1891 UPDATE action_trigger.event
1893 WHERE event_def = 15;
1895 UPDATE action_trigger.event_params
1897 WHERE event_def = 15;
1899 DELETE FROM action_trigger.event_definition
1902 INSERT INTO action_trigger.event_definition (
1915 'Email Notice: Patron Acquisition Request marked On-Order.',
1917 'Acq::UserRequestOrdered',
1921 [%- SET li = target.lineitem; -%]
1922 [%- SET user = target.usr -%]
1923 [%- SET title = helpers.get_li_attr("title", "", li.attributes) -%]
1924 [%- SET author = helpers.get_li_attr("author", "", li.attributes) -%]
1925 [%- SET edition = helpers.get_li_attr("edition", "", li.attributes) -%]
1926 [%- SET isbn = helpers.get_li_attr("isbn", "", li.attributes) -%]
1927 [%- SET publisher = helpers.get_li_attr("publisher", "", li.attributes) -%]
1928 [%- SET pubdate = helpers.get_li_attr("pubdate", "", li.attributes) -%]
1930 To: [%- params.recipient_email || user.email %]
1931 From: [%- params.sender_email || default_sender %]
1932 Subject: Acquisition Request Notification
1934 Dear [% user.family_name %], [% user.first_given_name %]
1935 Our records indicate the following acquisition request has been placed on order.
1938 [% IF author %]Author: [% author %][% END %]
1939 [% IF edition %]Edition: [% edition %][% END %]
1940 [% IF isbn %]ISBN: [% isbn %][% END %]
1941 [% IF publisher %]Publisher: [% publisher %][% END %]
1942 [% IF pubdate %]Publication Date: [% pubdate %][% END %]
1943 Lineitem ID: [% li.id %]
1949 'Email Notice: Patron Acquisition Request marked Received.',
1951 'Acq::UserRequestReceived',
1955 [%- SET li = target.lineitem; -%]
1956 [%- SET user = target.usr -%]
1957 [%- SET title = helpers.get_li_attr("title", "", li.attributes) %]
1958 [%- SET author = helpers.get_li_attr("author", "", li.attributes) %]
1959 [%- SET edition = helpers.get_li_attr("edition", "", li.attributes) %]
1960 [%- SET isbn = helpers.get_li_attr("isbn", "", li.attributes) %]
1961 [%- SET publisher = helpers.get_li_attr("publisher", "", li.attributes) -%]
1962 [%- SET pubdate = helpers.get_li_attr("pubdate", "", li.attributes) -%]
1964 To: [%- params.recipient_email || user.email %]
1965 From: [%- params.sender_email || default_sender %]
1966 Subject: Acquisition Request Notification
1968 Dear [% user.family_name %], [% user.first_given_name %]
1969 Our records indicate the materials for the following acquisition request have been received.
1972 [% IF author %]Author: [% author %][% END %]
1973 [% IF edition %]Edition: [% edition %][% END %]
1974 [% IF isbn %]ISBN: [% isbn %][% END %]
1975 [% IF publisher %]Publisher: [% publisher %][% END %]
1976 [% IF pubdate %]Publication Date: [% pubdate %][% END %]
1977 Lineitem ID: [% li.id %]
1983 'Email Notice: Patron Acquisition Request marked Cancelled.',
1985 'Acq::UserRequestCancelled',
1989 [%- SET li = target.lineitem; -%]
1990 [%- SET user = target.usr -%]
1991 [%- SET title = helpers.get_li_attr("title", "", li.attributes) %]
1992 [%- SET author = helpers.get_li_attr("author", "", li.attributes) %]
1993 [%- SET edition = helpers.get_li_attr("edition", "", li.attributes) %]
1994 [%- SET isbn = helpers.get_li_attr("isbn", "", li.attributes) %]
1995 [%- SET publisher = helpers.get_li_attr("publisher", "", li.attributes) -%]
1996 [%- SET pubdate = helpers.get_li_attr("pubdate", "", li.attributes) -%]
1998 To: [%- params.recipient_email || user.email %]
1999 From: [%- params.sender_email || default_sender %]
2000 Subject: Acquisition Request Notification
2002 Dear [% user.family_name %], [% user.first_given_name %]
2003 Our records indicate the following acquisition request has been cancelled.
2006 [% IF author %]Author: [% author %][% END %]
2007 [% IF edition %]Edition: [% edition %][% END %]
2008 [% IF isbn %]ISBN: [% isbn %][% END %]
2009 [% IF publisher %]Publisher: [% publisher %][% END %]
2010 [% IF pubdate %]Publication Date: [% pubdate %][% END %]
2011 Lineitem ID: [% li.id %]
2015 INSERT INTO action_trigger.environment (
2020 ( 15, 'lineitem.attributes' ),
2024 ( 16, 'lineitem.attributes' ),
2028 ( 17, 'lineitem.attributes' ),
2032 INSERT INTO action_trigger.event_definition
2033 (id, active, owner, name, hook, validator, reactor, cleanup_success, cleanup_failure, delay, delay_field, group_field, template) VALUES
2034 (23, true, 1, 'PO JEDI', 'acqpo.activated', 'Acq::PurchaseOrderEDIRequired', 'GeneratePurchaseOrderJEDI', NULL, NULL, '00:05:00', NULL, NULL,
2036 [%# start JEDI document -%]
2037 [%- BLOCK big_block -%]
2039 "recipient":"[% target.provider.san %]",
2040 "sender":"[% target.ordering_agency.mailing_address.san %]",
2042 "ORDERS":[ "order", {
2043 "po_number":[% target.id %],
2044 "date":"[% date.format(date.now, '%Y%m%d') %]",
2046 [%- IF target.provider.edi_default.vendcode -%]
2047 "id":"[% target.ordering_agency.mailing_address.san _ ' ' _ target.provider.edi_default.vendcode %]",
2050 "id":"[% target.ordering_agency.mailing_address.san %]"
2054 [%- # target.provider.name (target.provider.id) -%]
2055 "[% target.provider.san %]",
2056 {"id-qualifier": 92, "id":"[% target.provider.id %]"}
2058 "currency":"[% target.provider.currency_type %]",
2060 [% FOR li IN target.lineitems %]
2062 "identifiers":[ [%-# li.isbns = helpers.get_li_isbns(li.attributes) %]
2063 [% FOR isbn IN helpers.get_li_isbns(li.attributes) -%]
2064 [% IF isbn.length == 13 -%]
2065 {"id-qualifier":"EN","id":"[% isbn %]"},
2067 {"id-qualifier":"IB","id":"[% isbn %]"},
2070 {"id-qualifier":"SA","id":"[% li.id %]"}
2072 "price":[% li.estimated_unit_price || '0.00' %],
2074 {"BTI":"[% helpers.get_li_attr('title', '', li.attributes) %]"},
2075 {"BPU":"[% helpers.get_li_attr('publisher', '', li.attributes) %]"},
2076 {"BPD":"[% helpers.get_li_attr('pubdate', '', li.attributes) %]"},
2077 {"BPH":"[% helpers.get_li_attr('pagination','', li.attributes) %]"}
2079 "quantity":[% li.lineitem_details.size %]
2080 }[% UNLESS loop.last %],[% END %]
2081 [%-# TODO: lineitem details (later) -%]
2084 "line_items":[% target.lineitems.size %]
2085 }] [% # close ORDERS array %]
2086 }] [% # close body array %]
2089 [% tempo = PROCESS big_block; helpers.escape_json(tempo) %]
2093 INSERT INTO action_trigger.environment (event_def, path) VALUES
2094 (23, 'lineitems.attributes'),
2095 (23, 'lineitems.lineitem_details'),
2096 (23, 'lineitems.lineitem_notes'),
2097 (23, 'ordering_agency.mailing_address'),
2100 UPDATE action_trigger.event_definition SET template =
2104 # find a lineitem attribute by name and optional type
2106 FOR attr IN li.attributes;
2107 IF attr.attr_name == attr_name;
2108 IF !attr_type OR attr_type == attr.attr_type;
2117 <h2>Purchase Order [% target.id %]</h2>
2119 date <b>[% date.format(date.now, '%Y%m%d') %]</b>
2123 table td { padding:5px; border:1px solid #aaa;}
2124 table { width:95%; border-collapse:collapse; }
2125 #vendor-notes { padding:5px; border:1px solid #aaa; }
2127 <table id='vendor-table'>
2129 <td valign='top'>Vendor</td>
2131 <div>[% target.provider.name %]</div>
2132 <div>[% target.provider.addresses.0.street1 %]</div>
2133 <div>[% target.provider.addresses.0.street2 %]</div>
2134 <div>[% target.provider.addresses.0.city %]</div>
2135 <div>[% target.provider.addresses.0.state %]</div>
2136 <div>[% target.provider.addresses.0.country %]</div>
2137 <div>[% target.provider.addresses.0.post_code %]</div>
2139 <td valign='top'>Ship to / Bill to</td>
2141 <div>[% target.ordering_agency.name %]</div>
2142 <div>[% target.ordering_agency.billing_address.street1 %]</div>
2143 <div>[% target.ordering_agency.billing_address.street2 %]</div>
2144 <div>[% target.ordering_agency.billing_address.city %]</div>
2145 <div>[% target.ordering_agency.billing_address.state %]</div>
2146 <div>[% target.ordering_agency.billing_address.country %]</div>
2147 <div>[% target.ordering_agency.billing_address.post_code %]</div>
2153 <fieldset id='vendor-notes'>
2154 <legend>Notes to the Vendor</legend>
2156 [% FOR note IN target.notes %]
2157 [% IF note.vendor_public == 't' %]
2158 <li>[% note.value %]</li>
2169 <th>ISBN or Item #</th>
2180 [% FOR li IN target.lineitems %]
2183 [% count = li.lineitem_details.size %]
2184 [% price = li.estimated_unit_price %]
2185 [% litotal = (price * count) %]
2186 [% subtotal = subtotal + litotal %]
2187 [% isbn = PROCESS get_li_attr attr_name = 'isbn' %]
2188 [% ident = PROCESS get_li_attr attr_name = 'identifier' %]
2190 <td>[% target.id %]</td>
2191 <td>[% isbn || ident %]</td>
2192 <td>[% PROCESS get_li_attr attr_name = 'title' %]</td>
2193 <td>[% count %]</td>
2194 <td>[% price %]</td>
2195 <td>[% litotal %]</td>
2198 [% FOR note IN li.lineitem_notes %]
2199 [% IF note.vendor_public == 't' %]
2200 <li>[% note.value %]</li>
2208 <td/><td/><td/><td/>
2210 <td>[% subtotal %]</td>
2217 Total Line Item Count: [% target.lineitems.size %]
2221 INSERT INTO action_trigger.environment (event_def, path) VALUES
2222 (4, 'lineitems.lineitem_notes'),
2225 INSERT INTO action_trigger.environment (event_def, path) VALUES
2226 ( 14, 'lineitem_notes.alert_text' ),
2227 ( 14, 'distribution_formulas.formula' ),
2228 ( 14, 'lineitem_details.fund' ),
2229 ( 14, 'lineitem_details.eg_copy_id' ),
2230 ( 14, 'lineitem_details.eg_copy_id.call_number' )
2233 INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES (
2238 'A patron has made an acquisitions request.',
2248 'A patron acquisition request has been rejected.',
2256 INSERT INTO action_trigger.event_definition (
2269 'Email Notice: Acquisition Request created.',
2275 [%- SET user = target.usr -%]
2276 [%- SET title = target.title -%]
2277 [%- SET author = target.author -%]
2278 [%- SET isxn = target.isxn -%]
2279 [%- SET publisher = target.publisher -%]
2280 [%- SET pubdate = target.pubdate -%]
2282 To: [%- params.recipient_email || user.email %]
2283 From: [%- params.sender_email || default_sender %]
2284 Subject: Acquisition Request Notification
2286 Dear [% user.family_name %], [% user.first_given_name %]
2287 Our records indicate that you have made the following acquisition request:
2290 [% IF author %]Author: [% author %][% END %]
2291 [% IF edition %]Edition: [% edition %][% END %]
2292 [% IF isbn %]ISXN: [% isxn %][% END %]
2293 [% IF publisher %]Publisher: [% publisher %][% END %]
2294 [% IF pubdate %]Publication Date: [% pubdate %][% END %]
2300 'Email Notice: Acquisition Request Rejected.',
2306 [%- SET user = target.usr -%]
2307 [%- SET title = target.title -%]
2308 [%- SET author = target.author -%]
2309 [%- SET isxn = target.isxn -%]
2310 [%- SET publisher = target.publisher -%]
2311 [%- SET pubdate = target.pubdate -%]
2312 [%- SET cancel_reason = target.cancel_reason.description -%]
2314 To: [%- params.recipient_email || user.email %]
2315 From: [%- params.sender_email || default_sender %]
2316 Subject: Acquisition Request Notification
2318 Dear [% user.family_name %], [% user.first_given_name %]
2319 Our records indicate the following acquisition request has been rejected for this reason: [% cancel_reason %]
2322 [% IF author %]Author: [% author %][% END %]
2323 [% IF edition %]Edition: [% edition %][% END %]
2324 [% IF isbn %]ISBN: [% isbn %][% END %]
2325 [% IF publisher %]Publisher: [% publisher %][% END %]
2326 [% IF pubdate %]Publication Date: [% pubdate %][% END %]
2330 INSERT INTO action_trigger.environment (
2336 ( 19, 'cancel_reason' )
2339 INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, delay, template)
2340 VALUES (20, 'f', 1, 'Password reset request notification', 'password.reset_request', 'NOOP_True', 'SendEmail', '00:00:01',
2343 [%- user = target.usr -%]
2344 To: [%- params.recipient_email || user.email %]
2345 From: [%- params.sender_email || user.home_ou.email || default_sender %]
2346 Subject: [% user.home_ou.name %]: library account password reset request
2348 You have received this message because you, or somebody else, requested a reset
2349 of your library system password. If you did not request a reset of your library
2350 system password, just ignore this message and your current password will
2353 If you did request a reset of your library system password, please perform
2354 the following steps to continue the process of resetting your password:
2356 1. Open the following link in a web browser: https://[% params.hostname %]/opac/password/[% params.locale || 'en-US' %]/[% target.uuid %]
2357 The browser displays a password reset form.
2359 2. Enter your new password in the password reset form in the browser. You must
2360 enter the password twice to ensure that you do not make a mistake. If the
2361 passwords match, you will then be able to log in to your library system account
2362 with the new password.
2366 INSERT INTO action_trigger.hook (key, core_type, description, passive)
2368 'format.acqcle.html',
2370 'Formats claim events into a voucher',
2374 INSERT INTO action_trigger.event_definition (
2375 id, active, owner, name, hook, group_field,
2376 validator, reactor, granularity, template
2382 'format.acqcle.html',
2389 [%- SET claim = target.0.claim -%]
2390 <!-- This will need refined/prettified. -->
2391 <div class="acq-claim-voucher">
2392 <h2>Claim: [% claim.id %] ([% claim.type.code %])</h2>
2393 <h3>Against: [%- helpers.get_li_attr("title", "", claim.lineitem_detail.lineitem.attributes) -%]</h3>
2395 [% FOR event IN target %]
2397 Event type: [% event.type.code %]
2398 [% IF event.type.library_initiated %](Library initiated)[% END %]
2400 Event date: [% event.event_date %]<br />
2401 Order date: [% event.claim.lineitem_detail.lineitem.purchase_order.order_date %]<br />
2402 Expected receive date: [% event.claim.lineitem_detail.lineitem.expected_recv_time %]<br />
2403 Initiated by: [% event.creator.family_name %], [% event.creator.first_given_name %] [% event.creator.second_given_name %]<br />
2404 Barcode: [% event.claim.lineitem_detail.barcode %]; Fund:
2405 [% event.claim.lineitem_detail.fund.code %]
2406 ([% event.claim.lineitem_detail.fund.year %])
2414 INSERT INTO action_trigger.environment (event_def, path) VALUES
2417 (21, 'claim.lineitem_detail'),
2418 (21, 'claim.lineitem_detail.fund'),
2419 (21, 'claim.lineitem_detail.lineitem.attributes'),
2420 (21, 'claim.lineitem_detail.lineitem.purchase_order'),
2425 INSERT INTO action_trigger.hook (key, core_type, description, passive)
2427 'format.acqinv.html',
2429 'Formats invoices into a voucher',
2433 INSERT INTO action_trigger.event_definition (
2434 id, active, owner, name, hook,
2435 validator, reactor, granularity, template
2441 'format.acqinv.html',
2446 [% FILTER collapse %]
2447 [%- SET invoice = target -%]
2448 <!-- This lacks totals, info about funds (for invoice entries,
2449 funds are per-LID!), and general refinement -->
2450 <div class="acq-invoice-voucher">
2453 <strong>No.</strong> [% invoice.inv_ident %]
2454 [% IF invoice.inv_type %]
2455 / <strong>Type:</strong>[% invoice.inv_type %]
2460 [% BLOCK ent_with_address %]
2461 <dt>[% ent_label %]: [% ent.name %] ([% ent.code %])</dt>
2463 [% IF ent.addresses.0 %]
2464 [% SET addr = ent.addresses.0 %]
2465 [% addr.street1 %]<br />
2466 [% IF addr.street2 %][% addr.street2 %]<br />[% END %]
2468 [% IF addr.county %] [% addr.county %], [% END %]
2469 [% IF addr.state %] [% addr.state %] [% END %]
2470 [% IF addr.post_code %][% addr.post_code %][% END %]<br />
2471 [% IF addr.country %] [% addr.country %] [% END %]
2474 [% IF ent.phone %] Phone: [% ent.phone %]<br />[% END %]
2475 [% IF ent.fax_phone %] Fax: [% ent.fax_phone %]<br />[% END %]
2476 [% IF ent.url %] URL: [% ent.url %]<br />[% END %]
2477 [% IF ent.email %] E-mail: [% ent.email %] [% END %]
2481 [% INCLUDE ent_with_address
2482 ent = invoice.provider
2483 ent_label = "Provider" %]
2484 [% INCLUDE ent_with_address
2485 ent = invoice.shipper
2486 ent_label = "Shipper" %]
2489 [% invoice.receiver.name %] ([% invoice.receiver.shortname %])
2493 [% helpers.format_date(invoice.recv_date) %] by
2494 [% invoice.recv_method %]
2496 [% IF invoice.note %]
2505 [% FOR entry IN invoice.entries %]
2507 [% IF entry.lineitem %]
2508 Title: [% helpers.get_li_attr(
2509 "title", "", entry.lineitem.attributes
2511 Author: [% helpers.get_li_attr(
2512 "author", "", entry.lineitem.attributes
2515 [% IF entry.purchase_order %]
2516 (PO: [% entry.purchase_order.name %])
2518 Invoice item count: [% entry.inv_item_count %]
2519 [% IF entry.phys_item_count %]
2520 / Physical item count: [% entry.phys_item_count %]
2523 [% IF entry.cost_billed %]
2524 Cost billed: [% entry.cost_billed %]
2525 [% IF entry.billed_per_item %](per item)[% END %]
2528 [% IF entry.actual_cost %]
2529 Actual cost: [% entry.actual_cost %]<br />
2531 [% IF entry.amount_paid %]
2532 Amount paid: [% entry.amount_paid %]<br />
2534 [% IF entry.note %]Note: [% entry.note %][% END %]
2537 [% FOR item IN invoice.items %]
2539 [% IF item.inv_item_type %]
2540 Item Type: [% item.inv_item_type %]<br />
2542 [% IF item.title %]Title/Description:
2543 [% item.title %]<br />
2545 [% IF item.author %]Author: [% item.author %]<br />[% END %]
2546 [% IF item.purchase_order %]PO: [% item.purchase_order %]<br />[% END %]
2547 [% IF item.note %]Note: [% item.note %]<br />[% END %]
2548 [% IF item.cost_billed %]
2549 Cost billed: [% item.cost_billed %]<br />
2551 [% IF item.actual_cost %]
2552 Actual cost: [% item.actual_cost %]<br />
2554 [% IF item.amount_paid %]
2555 Amount paid: [% item.amount_paid %]<br />
2565 INSERT INTO action_trigger.environment (event_def, path) VALUES
2567 (22, 'provider.addresses'),
2569 (22, 'shipper.addresses'),
2572 (22, 'entries.purchase_order'),
2573 (22, 'entries.lineitem'),
2574 (22, 'entries.lineitem.attributes'),
2578 INSERT INTO action_trigger.environment (event_def, path) VALUES
2579 (23, 'provider.edi_default');
2581 INSERT INTO action_trigger.validator (module, description)
2583 'Acq::PurchaseOrderEDIRequired',
2585 'Acq::PurchaseOrderEDIRequired',
2586 'Purchase order is delivered via EDI',
2592 INSERT INTO action_trigger.reactor (module, description)
2594 'GeneratePurchaseOrderJEDI',
2596 'GeneratePurchaseOrderJEDI',
2597 'Creates purchase order JEDI (JSON EDI) for subsequent EDI processing',
2603 UPDATE action_trigger.hook
2605 key = 'acqpo.activated',
2607 description = oils_i18n_gettext(
2609 'Purchase order was activated',
2613 WHERE key = 'format.po.jedi';
2615 -- We just changed a key in action_trigger.hook. Now redirect any
2616 -- child rows to point to the new key. (There probably aren't any;
2617 -- this is just a precaution against possible local modifications.)
2619 UPDATE action_trigger.event_definition
2620 SET hook = 'acqpo.activated'
2621 WHERE hook = 'format.po.jedi';
2623 INSERT INTO action_trigger.reactor (module, description) VALUES (
2624 'AstCall', 'Possibly place a phone call with Asterisk'
2628 action_trigger.event_definition (
2629 id, active, owner, name, hook, validator, reactor,
2630 cleanup_success, cleanup_failure, delay, delay_field, group_field,
2631 max_delay, granularity, usr_field, opt_in_setting, template
2636 'Telephone Overdue Notice',
2637 'checkout.due', 'NOOP_True', 'AstCall',
2638 DEFAULT, DEFAULT, '5 seconds', 'due_date', 'usr',
2639 DEFAULT, DEFAULT, DEFAULT, DEFAULT,
2641 [% phone = target.0.usr.day_phone | replace('[\s\-\(\)]', '') -%]
2642 [% IF phone.match('^[2-9]') %][% country = 1 %][% ELSE %][% country = '' %][% END -%]
2643 Channel: [% channel_prefix %]/[% country %][% phone %]
2644 Context: overdue-test
2650 Set: eg_user_id=[% target.0.usr.id %]
2651 Set: items=[% target.size %]
2652 Set: titlestring=[% titles = [] %][% FOR circ IN target %][% titles.push(circ.target_copy.call_number.record.simple_record.title) %][% END %][% titles.join(". ") %]
2657 action_trigger.environment (id, event_def, path)
2659 (DEFAULT, 24, 'target_copy.call_number.record.simple_record'),
2660 (DEFAULT, 24, 'usr')
2663 INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES (
2664 'circ.format.history.email',
2667 'circ.format.history.email',
2668 'An email has been requested for a circ history.',
2675 'circ.format.history.print',
2678 'circ.format.history.print',
2679 'A circ history needs to be formatted for printing.',
2686 'ahr.format.history.email',
2689 'ahr.format.history.email',
2690 'An email has been requested for a hold request history.',
2697 'ahr.format.history.print',
2700 'ahr.format.history.print',
2701 'A hold request history needs to be formatted for printing.',
2710 INSERT INTO action_trigger.event_definition (
2725 'circ.history.email',
2726 'circ.format.history.email',
2733 [%- SET user = target.0.usr -%]
2734 To: [%- params.recipient_email || user.email %]
2735 From: [%- params.sender_email || default_sender %]
2736 Subject: Circulation History
2738 [% FOR circ IN target %]
2739 [% helpers.get_copy_bib_basics(circ.target_copy.id).title %]
2740 Barcode: [% circ.target_copy.barcode %]
2741 Checked Out: [% date.format(helpers.format_date(circ.xact_start), '%Y-%m-%d') %]
2742 Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
2743 Returned: [% date.format(helpers.format_date(circ.checkin_time), '%Y-%m-%d') %]
2751 'circ.history.print',
2752 'circ.format.history.print',
2760 <style> li { padding: 8px; margin 5px; }</style>
2761 <div>[% date.format %]</div>
2764 [% user.family_name %], [% user.first_given_name %]
2766 [% FOR circ IN target %]
2768 <div>[% helpers.get_copy_bib_basics(circ.target_copy.id).title %]</div>
2769 <div>Barcode: [% circ.target_copy.barcode %]</div>
2770 <div>Checked Out: [% date.format(helpers.format_date(circ.xact_start), '%Y-%m-%d') %]</div>
2771 <div>Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]</div>
2772 <div>Returned: [% date.format(helpers.format_date(circ.checkin_time), '%Y-%m-%d') %]</div>
2783 'ahr.history.email',
2784 'ahr.format.history.email',
2791 [%- SET user = target.0.usr -%]
2792 To: [%- params.recipient_email || user.email %]
2793 From: [%- params.sender_email || default_sender %]
2794 Subject: Hold Request History
2796 [% FOR hold IN target %]
2797 [% helpers.get_copy_bib_basics(hold.current_copy.id).title %]
2798 Requested: [% date.format(helpers.format_date(hold.request_time), '%Y-%m-%d') %]
2799 [% IF hold.fulfillment_time %]Fulfilled: [% date.format(helpers.format_date(hold.fulfillment_time), '%Y-%m-%d') %][% END %]
2807 'ahr.history.print',
2808 'ahr.format.history.print',
2816 <style> li { padding: 8px; margin 5px; }</style>
2817 <div>[% date.format %]</div>
2820 [% user.family_name %], [% user.first_given_name %]
2822 [% FOR hold IN target %]
2824 <div>[% helpers.get_copy_bib_basics(hold.current_copy.id).title %]</div>
2825 <div>Requested: [% date.format(helpers.format_date(hold.request_time), '%Y-%m-%d') %]</div>
2826 [% IF hold.fulfillment_time %]<div>Fulfilled: [% date.format(helpers.format_date(hold.fulfillment_time), '%Y-%m-%d') %]</div>[% END %]
2836 INSERT INTO action_trigger.environment (
2840 ( 25, 'target_copy')
2842 ,( 26, 'target_copy' )
2844 ,( 27, 'current_copy' )
2846 ,( 28, 'current_copy' )
2850 INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES (
2851 'money.format.payment_receipt.email',
2854 'money.format.payment_receipt.email',
2855 'An email has been requested for a payment receipt.',
2862 'money.format.payment_receipt.print',
2865 'money.format.payment_receipt.print',
2866 'A payment receipt needs to be formatted for printing.',
2874 INSERT INTO action_trigger.event_definition (
2889 'money.payment_receipt.email',
2890 'money.format.payment_receipt.email',
2897 [%- SET user = target.0.xact.usr -%]
2898 To: [%- params.recipient_email || user.email %]
2899 From: [%- params.sender_email || default_sender %]
2900 Subject: Payment Receipt
2903 [%- SET xact_mp_hash = {} -%]
2904 [%- FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions -%]
2905 [%- SET xact_id = mp.xact.id -%]
2906 [%- IF ! xact_mp_hash.defined( xact_id ) -%][%- xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } -%][%- END -%]
2907 [%- xact_mp_hash.$xact_id.payments.push(mp) -%]
2909 [%- FOR xact_id IN xact_mp_hash.keys.sort -%]
2910 [%- SET xact = xact_mp_hash.$xact_id.xact %]
2911 Transaction ID: [% xact_id %]
2912 [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %]
2913 [% ELSE %]Miscellaneous
2916 [%- SET mb_type_hash = {} -%]
2917 [%- FOR mb IN xact.billings %][%# Group billings by their btype -%]
2918 [%- IF mb.voided == 'f' -%]
2919 [%- SET mb_type = mb.btype.id -%]
2920 [%- IF ! mb_type_hash.defined( mb_type ) -%][%- mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } -%][%- END -%]
2921 [%- IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) -%][%- mb_type_hash.$mb_type.first_ts = mb.billing_ts -%][%- END -%]
2922 [%- mb_type_hash.$mb_type.last_ts = mb.billing_ts -%]
2923 [%- mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount -%]
2924 [%- mb_type_hash.$mb_type.billings.push( mb ) -%]
2927 [%- FOR mb_type IN mb_type_hash.keys.sort -%]
2928 [%- IF mb_type == 1 %][%-# Consolidated view of overdue billings -%]
2929 $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %]
2930 on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %]
2931 [%- ELSE -%][%# all other billings show individually %]
2932 [% FOR mb IN mb_type_hash.$mb_type.billings %]
2933 $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %]
2938 [% FOR mp IN xact_mp_hash.$xact_id.payments %]
2939 Payment ID: [% mp.id %]
2940 Paid [% mp.amount %] via [% SWITCH mp.payment_type -%]
2941 [% CASE "cash_payment" %]cash
2942 [% CASE "check_payment" %]check
2943 [% CASE "credit_card_payment" %]credit card (
2944 [%- SET cc_chunks = mp.credit_card_payment.cc_number.replace(' ','').chunk(4); -%]
2945 [%- cc_chunks.slice(0, -1+cc_chunks.max).join.replace('\S','X') -%]
2946 [% cc_chunks.last -%]
2947 exp [% mp.credit_card_payment.expire_month %]/[% mp.credit_card_payment.expire_year -%]
2949 [% CASE "credit_payment" %]credit
2950 [% CASE "forgive_payment" %]forgiveness
2951 [% CASE "goods_payment" %]goods
2952 [% CASE "work_payment" %]work
2953 [%- END %] on [% mp.payment_ts %] [% mp.note %]
2962 'money.payment_receipt.print',
2963 'money.format.payment_receipt.print',
2969 [%- USE date -%][%- SET user = target.0.xact.usr -%]
2970 <div style="li { padding: 8px; margin 5px; }">
2971 <div>[% date.format %]</div><br/>
2973 [% SET xact_mp_hash = {} %]
2974 [% FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions %]
2975 [% SET xact_id = mp.xact.id %]
2976 [% IF ! xact_mp_hash.defined( xact_id ) %][% xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } %][% END %]
2977 [% xact_mp_hash.$xact_id.payments.push(mp) %]
2979 [% FOR xact_id IN xact_mp_hash.keys.sort %]
2980 [% SET xact = xact_mp_hash.$xact_id.xact %]
2981 <li>Transaction ID: [% xact_id %]
2982 [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %]
2983 [% ELSE %]Miscellaneous
2985 Line item billings:<ol>
2986 [% SET mb_type_hash = {} %]
2987 [% FOR mb IN xact.billings %][%# Group billings by their btype %]
2988 [% IF mb.voided == 'f' %]
2989 [% SET mb_type = mb.btype.id %]
2990 [% IF ! mb_type_hash.defined( mb_type ) %][% mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } %][% END %]
2991 [% IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) %][% mb_type_hash.$mb_type.first_ts = mb.billing_ts %][% END %]
2992 [% mb_type_hash.$mb_type.last_ts = mb.billing_ts %]
2993 [% mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount %]
2994 [% mb_type_hash.$mb_type.billings.push( mb ) %]
2997 [% FOR mb_type IN mb_type_hash.keys.sort %]
2998 <li>[% IF mb_type == 1 %][%# Consolidated view of overdue billings %]
2999 $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %]
3000 on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %]
3001 [% ELSE %][%# all other billings show individually %]
3002 [% FOR mb IN mb_type_hash.$mb_type.billings %]
3003 $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %]
3008 Line item payments:<ol>
3009 [% FOR mp IN xact_mp_hash.$xact_id.payments %]
3010 <li>Payment ID: [% mp.id %]
3011 Paid [% mp.amount %] via [% SWITCH mp.payment_type -%]
3012 [% CASE "cash_payment" %]cash
3013 [% CASE "check_payment" %]check
3014 [% CASE "credit_card_payment" %]credit card (
3015 [%- SET cc_chunks = mp.credit_card_payment.cc_number.replace(' ','').chunk(4); -%]
3016 [%- cc_chunks.slice(0, -1+cc_chunks.max).join.replace('\S','X') -%]
3017 [% cc_chunks.last -%]
3018 exp [% mp.credit_card_payment.expire_month %]/[% mp.credit_card_payment.expire_year -%]
3020 [% CASE "credit_payment" %]credit
3021 [% CASE "forgive_payment" %]forgiveness
3022 [% CASE "goods_payment" %]goods
3023 [% CASE "work_payment" %]work
3024 [%- END %] on [% mp.payment_ts %] [% mp.note %]
3036 INSERT INTO action_trigger.environment (
3039 ) VALUES -- for fleshing mp objects
3042 ,( 29, 'xact.grocery' )
3043 ,( 29, 'xact.circulation' )
3044 ,( 29, 'xact.summary' )
3047 ,( 30, 'xact.grocery' )
3048 ,( 30, 'xact.circulation' )
3049 ,( 30, 'xact.summary' )
3052 INSERT INTO action_trigger.cleanup ( module, description ) VALUES (
3053 'DeleteTempBiblioBucket',
3055 'DeleteTempBiblioBucket',
3056 'Deletes a cbreb object used as a target if it has a btype of "temp"',
3062 INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES (
3063 'biblio.format.record_entry.email',
3066 'biblio.format.record_entry.email',
3067 'An email has been requested for one or more biblio record entries.',
3074 'biblio.format.record_entry.print',
3077 'biblio.format.record_entry.print',
3078 'One or more biblio record entries need to be formatted for printing.',
3086 INSERT INTO action_trigger.event_definition (
3103 'biblio.record_entry.email',
3104 'biblio.format.record_entry.email',
3107 'DeleteTempBiblioBucket',
3108 'DeleteTempBiblioBucket',
3113 [%- SET user = target.0.owner -%]
3114 To: [%- params.recipient_email || user.email %]
3115 From: [%- params.sender_email || default_sender %]
3116 Subject: Bibliographic Records
3118 [% FOR cbreb IN target %]
3119 [% FOR cbrebi IN cbreb.items %]
3120 Bib ID# [% cbrebi.target_biblio_record_entry.id %] ISBN: [% crebi.target_biblio_record_entry.simple_record.isbn %]
3121 Title: [% cbrebi.target_biblio_record_entry.simple_record.title %]
3122 Author: [% cbrebi.target_biblio_record_entry.simple_record.author %]
3123 Publication Year: [% cbrebi.target_biblio_record_entry.simple_record.pubdate %]
3133 'biblio.record_entry.print',
3134 'biblio.format.record_entry.print',
3137 'DeleteTempBiblioBucket',
3138 'DeleteTempBiblioBucket',
3144 <style> li { padding: 8px; margin 5px; }</style>
3146 [% FOR cbreb IN target %]
3147 [% FOR cbrebi IN cbreb.items %]
3148 <li>Bib ID# [% cbrebi.target_biblio_record_entry.id %] ISBN: [% crebi.target_biblio_record_entry.simple_record.isbn %]<br />
3149 Title: [% cbrebi.target_biblio_record_entry.simple_record.title %]<br />
3150 Author: [% cbrebi.target_biblio_record_entry.simple_record.author %]<br />
3151 Publication Year: [% cbrebi.target_biblio_record_entry.simple_record.pubdate %]
3161 INSERT INTO action_trigger.environment (
3164 ) VALUES -- for fleshing cbreb objects
3167 ,( 31, 'items.target_biblio_record_entry' )
3168 ,( 31, 'items.target_biblio_record_entry.simple_record' )
3169 ,( 31, 'items.target_biblio_record_entry.call_numbers' )
3170 ,( 31, 'items.target_biblio_record_entry.fixed_fields' )
3171 ,( 31, 'items.target_biblio_record_entry.notes' )
3172 ,( 31, 'items.target_biblio_record_entry.full_record_entries' )
3175 ,( 32, 'items.target_biblio_record_entry' )
3176 ,( 32, 'items.target_biblio_record_entry.simple_record' )
3177 ,( 32, 'items.target_biblio_record_entry.call_numbers' )
3178 ,( 32, 'items.target_biblio_record_entry.fixed_fields' )
3179 ,( 32, 'items.target_biblio_record_entry.notes' )
3180 ,( 32, 'items.target_biblio_record_entry.full_record_entries' )
3183 INSERT INTO action_trigger.environment (
3186 ) VALUES -- for fleshing mp objects
3187 ( 29, 'credit_card_payment')
3188 ,( 29, 'xact.billings')
3189 ,( 29, 'xact.billings.btype')
3190 ,( 30, 'credit_card_payment')
3191 ,( 30, 'xact.billings')
3192 ,( 30, 'xact.billings.btype')
3195 INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES
3196 ( 'circ.format.missing_pieces.slip.print',
3199 'circ.format.missing_pieces.slip.print',
3200 'A missing pieces slip needs to be formatted for printing.',
3206 ,( 'circ.format.missing_pieces.letter.print',
3209 'circ.format.missing_pieces.letter.print',
3210 'A missing pieces patron letter needs to be formatted for printing.',
3218 INSERT INTO action_trigger.event_definition (
3233 'circ.missing_pieces.slip.print',
3234 'circ.format.missing_pieces.slip.print',
3241 [%- SET user = target.0.usr -%]
3242 <div style="li { padding: 8px; margin 5px; }">
3243 <div>[% date.format %]</div><br/>
3246 [% FOR circ IN target %]
3247 <li>Barcode: [% circ.target_copy.barcode %] Transaction ID: [% circ.id %] Due: [% circ.due_date.format %]<br />
3248 [% helpers.get_copy_bib_basics(circ.target_copy.id).title %]
3259 'circ.missing_pieces.letter.print',
3260 'circ.format.missing_pieces.letter.print',
3267 [%- SET user = target.0.usr -%]
3269 Dear [% user.prefix %] [% user.first_given_name %] [% user.family_name %],
3271 We are missing pieces for the following returned items:
3272 [% FOR circ IN target %]
3273 Barcode: [% circ.target_copy.barcode %] Transaction ID: [% circ.id %] Due: [% circ.due_date.format %]
3274 [% helpers.get_copy_bib_basics(circ.target_copy.id).title %]
3277 Please return these pieces as soon as possible.
3286 INSERT INTO action_trigger.environment (
3289 ) VALUES -- for fleshing circ objects
3291 ,( 33, 'target_copy')
3292 ,( 33, 'target_copy.circ_lib')
3293 ,( 33, 'target_copy.circ_lib.mailing_address')
3294 ,( 33, 'target_copy.circ_lib.billing_address')
3295 ,( 33, 'target_copy.call_number')
3296 ,( 33, 'target_copy.call_number.owning_lib')
3297 ,( 33, 'target_copy.call_number.owning_lib.mailing_address')
3298 ,( 33, 'target_copy.call_number.owning_lib.billing_address')
3300 ,( 33, 'circ_lib.mailing_address')
3301 ,( 33, 'circ_lib.billing_address')
3303 ,( 34, 'target_copy')
3304 ,( 34, 'target_copy.circ_lib')
3305 ,( 34, 'target_copy.circ_lib.mailing_address')
3306 ,( 34, 'target_copy.circ_lib.billing_address')
3307 ,( 34, 'target_copy.call_number')
3308 ,( 34, 'target_copy.call_number.owning_lib')
3309 ,( 34, 'target_copy.call_number.owning_lib.mailing_address')
3310 ,( 34, 'target_copy.call_number.owning_lib.billing_address')
3312 ,( 34, 'circ_lib.mailing_address')
3313 ,( 34, 'circ_lib.billing_address')
3316 INSERT INTO action_trigger.hook (key,core_type,description,passive)
3318 'ahr.format.pull_list',
3321 'ahr.format.pull_list',
3322 'Format holds pull list for printing',
3329 INSERT INTO action_trigger.event_definition (
3345 'ahr.format.pull_list',
3353 table { border-collapse: collapse; }
3354 td { padding: 5px; border-bottom: 1px solid #888; }
3355 th { font-weight: bold; }
3358 # Sort the holds into copy-location buckets
3359 # In the main print loop, sort each bucket by callnumber before printing
3360 SET holds_list = [];
3362 SET current_location = target.0.current_copy.location.id;
3364 IF current_location != hold.current_copy.location.id;
3365 SET current_location = hold.current_copy.location.id;
3366 holds_list.push(loc_data);
3371 'callnumber' => hold.current_copy.call_number.label
3373 loc_data.push(hold_data);
3375 holds_list.push(loc_data)
3382 <th>Shelving Location</th>
3383 <th>Call Number</th>
3389 [% FOR loc_data IN holds_list %]
3390 [% FOR hold_data IN loc_data.sort('callnumber') %]
3392 SET hold = hold_data.hold;
3393 SET copy_data = helpers.get_copy_bib_basics(hold.current_copy.id);
3396 <td>[% copy_data.title | truncate %]</td>
3397 <td>[% copy_data.author | truncate %]</td>
3398 <td>[% hold.current_copy.location.name %]</td>
3399 <td>[% hold.current_copy.call_number.label %]</td>
3400 <td>[% hold.current_copy.barcode %]</td>
3401 <td>[% hold.usr.card.barcode %]</td>
3410 INSERT INTO action_trigger.environment (
3414 (35, 'current_copy.location'),
3415 (35, 'current_copy.call_number'),
3420 -- Create the query schema, and the tables and views therein
3422 DROP SCHEMA IF EXISTS sql CASCADE;
3423 DROP SCHEMA IF EXISTS query CASCADE;
3425 CREATE SCHEMA query;
3427 CREATE TABLE query.datatype (
3428 id SERIAL PRIMARY KEY,
3429 datatype_name TEXT NOT NULL UNIQUE,
3430 is_numeric BOOL NOT NULL DEFAULT FALSE,
3431 is_composite BOOL NOT NULL DEFAULT FALSE,
3432 CONSTRAINT qdt_comp_not_num CHECK
3433 ( is_numeric IS FALSE OR is_composite IS FALSE )
3436 -- Define the most common datatypes in query.datatype. Note that none of
3437 -- these stock datatypes specifies a width or precision.
3439 -- Also: set the sequence for query.datatype to 1000, leaving plenty of
3440 -- room for more stock datatypes if we ever want to add them.
3442 SELECT setval( 'query.datatype_id_seq', 1000 );
3444 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3445 VALUES (1, 'SMALLINT', true);
3447 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3448 VALUES (2, 'INTEGER', true);
3450 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3451 VALUES (3, 'BIGINT', true);
3453 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3454 VALUES (4, 'DECIMAL', true);
3456 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3457 VALUES (5, 'NUMERIC', true);
3459 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3460 VALUES (6, 'REAL', true);
3462 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3463 VALUES (7, 'DOUBLE PRECISION', true);
3465 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3466 VALUES (8, 'SERIAL', true);
3468 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3469 VALUES (9, 'BIGSERIAL', true);
3471 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3472 VALUES (10, 'MONEY', false);
3474 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3475 VALUES (11, 'VARCHAR', false);
3477 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3478 VALUES (12, 'CHAR', false);
3480 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3481 VALUES (13, 'TEXT', false);
3483 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3484 VALUES (14, '"char"', false);
3486 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3487 VALUES (15, 'NAME', false);
3489 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3490 VALUES (16, 'BYTEA', false);
3492 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3493 VALUES (17, 'TIMESTAMP WITHOUT TIME ZONE', false);
3495 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3496 VALUES (18, 'TIMESTAMP WITH TIME ZONE', false);
3498 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3499 VALUES (19, 'DATE', false);
3501 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3502 VALUES (20, 'TIME WITHOUT TIME ZONE', false);
3504 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3505 VALUES (21, 'TIME WITH TIME ZONE', false);
3507 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3508 VALUES (22, 'INTERVAL', false);
3510 INSERT INTO query.datatype (id, datatype_name, is_numeric )
3511 VALUES (23, 'BOOLEAN', false);
3513 CREATE TABLE query.subfield (
3514 id SERIAL PRIMARY KEY,
3515 composite_type INT NOT NULL
3516 REFERENCES query.datatype(id)
3518 DEFERRABLE INITIALLY DEFERRED,
3520 CONSTRAINT qsf_pos_seq_no
3521 CHECK( seq_no > 0 ),
3522 subfield_type INT NOT NULL
3523 REFERENCES query.datatype(id)
3524 DEFERRABLE INITIALLY DEFERRED,
3525 CONSTRAINT qsf_datatype_seq_no UNIQUE (composite_type, seq_no)
3528 CREATE TABLE query.function_sig (
3529 id SERIAL PRIMARY KEY,
3530 function_name TEXT NOT NULL,
3531 return_type INT REFERENCES query.datatype(id)
3532 DEFERRABLE INITIALLY DEFERRED,
3533 is_aggregate BOOL NOT NULL DEFAULT FALSE,
3534 CONSTRAINT qfd_rtn_or_aggr CHECK
3535 ( return_type IS NULL OR is_aggregate = FALSE )
3538 CREATE INDEX query_function_sig_name_idx
3539 ON query.function_sig (function_name);
3541 CREATE TABLE query.function_param_def (
3542 id SERIAL PRIMARY KEY,
3543 function_id INT NOT NULL
3544 REFERENCES query.function_sig( id )
3546 DEFERRABLE INITIALLY DEFERRED,
3548 CONSTRAINT qfpd_pos_seq_no CHECK
3550 datatype INT NOT NULL
3551 REFERENCES query.datatype( id )
3552 DEFERRABLE INITIALLY DEFERRED,
3553 CONSTRAINT qfpd_function_param_seq UNIQUE (function_id, seq_no)
3556 CREATE TABLE query.stored_query (
3557 id SERIAL PRIMARY KEY,
3558 type TEXT NOT NULL CONSTRAINT query_type CHECK
3559 ( type IN ( 'SELECT', 'UNION', 'INTERSECT', 'EXCEPT' ) ),
3560 use_all BOOLEAN NOT NULL DEFAULT FALSE,
3561 use_distinct BOOLEAN NOT NULL DEFAULT FALSE,
3562 from_clause INT , --REFERENCES query.from_clause
3563 --DEFERRABLE INITIALLY DEFERRED,
3564 where_clause INT , --REFERENCES query.expression
3565 --DEFERRABLE INITIALLY DEFERRED,
3566 having_clause INT , --REFERENCES query.expression
3567 --DEFERRABLE INITIALLY DEFERRED
3568 limit_count INT , --REFERENCES query.expression( id )
3569 --DEFERRABLE INITIALLY DEFERRED,
3570 offset_count INT --REFERENCES query.expression( id )
3571 --DEFERRABLE INITIALLY DEFERRED
3574 -- (Foreign keys to be defined later after other tables are created)
3576 CREATE TABLE query.query_sequence (
3577 id SERIAL PRIMARY KEY,
3578 parent_query INT NOT NULL
3579 REFERENCES query.stored_query
3581 DEFERRABLE INITIALLY DEFERRED,
3582 seq_no INT NOT NULL,
3583 child_query INT NOT NULL
3584 REFERENCES query.stored_query
3586 DEFERRABLE INITIALLY DEFERRED,
3587 CONSTRAINT query_query_seq UNIQUE( parent_query, seq_no )
3590 CREATE TABLE query.bind_variable (
3591 name TEXT PRIMARY KEY,
3593 CONSTRAINT bind_variable_type CHECK
3594 ( type in ( 'string', 'number', 'string_list', 'number_list' )),
3595 description TEXT NOT NULL,
3596 default_value TEXT, -- to be encoded in JSON
3600 CREATE TABLE query.expression (
3601 id SERIAL PRIMARY KEY,
3602 type TEXT NOT NULL CONSTRAINT expression_type CHECK
3605 'xbind', -- bind variable
3611 'xfunc', -- function
3613 'xisnull', -- is null
3621 parenthesize BOOL NOT NULL DEFAULT FALSE,
3622 parent_expr INT REFERENCES query.expression
3624 DEFERRABLE INITIALLY DEFERRED,
3625 seq_no INT NOT NULL DEFAULT 1,
3629 left_operand INT REFERENCES query.expression
3630 DEFERRABLE INITIALLY DEFERRED,
3632 right_operand INT REFERENCES query.expression
3633 DEFERRABLE INITIALLY DEFERRED,
3634 function_id INT REFERENCES query.function_sig
3635 DEFERRABLE INITIALLY DEFERRED,
3636 subquery INT REFERENCES query.stored_query
3637 DEFERRABLE INITIALLY DEFERRED,
3638 cast_type INT REFERENCES query.datatype
3639 DEFERRABLE INITIALLY DEFERRED,
3640 negate BOOL NOT NULL DEFAULT FALSE,
3641 bind_variable TEXT REFERENCES query.bind_variable
3642 DEFERRABLE INITIALLY DEFERRED
3645 CREATE UNIQUE INDEX query_expr_parent_seq
3646 ON query.expression( parent_expr, seq_no )
3647 WHERE parent_expr IS NOT NULL;
3649 -- Due to some circular references, the following foreign key definitions
3650 -- had to be deferred until query.expression existed:
3652 ALTER TABLE query.stored_query
3653 ADD FOREIGN KEY ( where_clause )
3654 REFERENCES query.expression( id )
3655 DEFERRABLE INITIALLY DEFERRED;
3657 ALTER TABLE query.stored_query
3658 ADD FOREIGN KEY ( having_clause )
3659 REFERENCES query.expression( id )
3660 DEFERRABLE INITIALLY DEFERRED;
3662 ALTER TABLE query.stored_query
3663 ADD FOREIGN KEY ( limit_count )
3664 REFERENCES query.expression( id )
3665 DEFERRABLE INITIALLY DEFERRED;
3667 ALTER TABLE query.stored_query
3668 ADD FOREIGN KEY ( offset_count )
3669 REFERENCES query.expression( id )
3670 DEFERRABLE INITIALLY DEFERRED;
3672 CREATE TABLE query.case_branch (
3673 id SERIAL PRIMARY KEY,
3674 parent_expr INT NOT NULL REFERENCES query.expression
3676 DEFERRABLE INITIALLY DEFERRED,
3677 seq_no INT NOT NULL,
3678 condition INT REFERENCES query.expression
3679 DEFERRABLE INITIALLY DEFERRED,
3680 result INT NOT NULL REFERENCES query.expression
3681 DEFERRABLE INITIALLY DEFERRED,
3682 CONSTRAINT case_branch_parent_seq UNIQUE (parent_expr, seq_no)
3685 CREATE TABLE query.from_relation (
3686 id SERIAL PRIMARY KEY,
3687 type TEXT NOT NULL CONSTRAINT relation_type CHECK (
3688 type IN ( 'RELATION', 'SUBQUERY', 'FUNCTION' ) ),
3691 subquery INT REFERENCES query.stored_query,
3692 function_call INT REFERENCES query.expression,
3694 parent_relation INT REFERENCES query.from_relation
3696 DEFERRABLE INITIALLY DEFERRED,
3697 seq_no INT NOT NULL DEFAULT 1,
3698 join_type TEXT CONSTRAINT good_join_type CHECK (
3699 join_type IS NULL OR join_type IN
3700 ( 'INNER', 'LEFT', 'RIGHT', 'FULL' )
3702 on_clause INT REFERENCES query.expression
3703 DEFERRABLE INITIALLY DEFERRED,
3704 CONSTRAINT join_or_core CHECK (
3705 ( parent_relation IS NULL AND join_type IS NULL
3706 AND on_clause IS NULL )
3708 ( parent_relation IS NOT NULL AND join_type IS NOT NULL
3709 AND on_clause IS NOT NULL )
3713 CREATE UNIQUE INDEX from_parent_seq
3714 ON query.from_relation( parent_relation, seq_no )
3715 WHERE parent_relation IS NOT NULL;
3717 -- The following foreign key had to be deferred until
3718 -- query.from_relation existed
3720 ALTER TABLE query.stored_query
3721 ADD FOREIGN KEY (from_clause)
3722 REFERENCES query.from_relation
3723 DEFERRABLE INITIALLY DEFERRED;
3725 CREATE TABLE query.record_column (
3726 id SERIAL PRIMARY KEY,
3727 from_relation INT NOT NULL REFERENCES query.from_relation
3729 DEFERRABLE INITIALLY DEFERRED,
3730 seq_no INT NOT NULL,
3731 column_name TEXT NOT NULL,
3732 column_type INT NOT NULL REFERENCES query.datatype
3734 DEFERRABLE INITIALLY DEFERRED,
3735 CONSTRAINT column_sequence UNIQUE (from_relation, seq_no)
3738 CREATE TABLE query.select_item (
3739 id SERIAL PRIMARY KEY,
3740 stored_query INT NOT NULL REFERENCES query.stored_query
3742 DEFERRABLE INITIALLY DEFERRED,
3743 seq_no INT NOT NULL,
3744 expression INT NOT NULL REFERENCES query.expression
3745 DEFERRABLE INITIALLY DEFERRED,
3747 grouped_by BOOL NOT NULL DEFAULT FALSE,
3748 CONSTRAINT select_sequence UNIQUE( stored_query, seq_no )
3751 CREATE TABLE query.order_by_item (
3752 id SERIAL PRIMARY KEY,
3753 stored_query INT NOT NULL REFERENCES query.stored_query
3755 DEFERRABLE INITIALLY DEFERRED,
3756 seq_no INT NOT NULL,
3757 expression INT NOT NULL REFERENCES query.expression
3759 DEFERRABLE INITIALLY DEFERRED,
3760 CONSTRAINT order_by_sequence UNIQUE( stored_query, seq_no )
3763 ------------------------------------------------------------
3764 -- Create updatable views for different kinds of expressions
3765 ------------------------------------------------------------
3767 -- Create updatable view for BETWEEN expressions
3769 CREATE OR REPLACE VIEW query.expr_xbet AS
3782 CREATE OR REPLACE RULE query_expr_xbet_insert_rule AS
3783 ON INSERT TO query.expr_xbet
3785 INSERT INTO query.expression (
3794 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
3796 COALESCE(NEW.parenthesize, FALSE),
3798 COALESCE(NEW.seq_no, 1),
3800 COALESCE(NEW.negate, false)
3803 CREATE OR REPLACE RULE query_expr_xbet_update_rule AS
3804 ON UPDATE TO query.expr_xbet
3806 UPDATE query.expression SET
3808 parenthesize = NEW.parenthesize,
3809 parent_expr = NEW.parent_expr,
3810 seq_no = NEW.seq_no,
3811 left_operand = NEW.left_operand,
3816 CREATE OR REPLACE RULE query_expr_xbet_delete_rule AS
3817 ON DELETE TO query.expr_xbet
3819 DELETE FROM query.expression WHERE id = OLD.id;
3821 -- Create updatable view for bind variable expressions
3823 CREATE OR REPLACE VIEW query.expr_xbind AS
3835 CREATE OR REPLACE RULE query_expr_xbind_insert_rule AS
3836 ON INSERT TO query.expr_xbind
3838 INSERT INTO query.expression (
3846 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
3848 COALESCE(NEW.parenthesize, FALSE),
3850 COALESCE(NEW.seq_no, 1),
3854 CREATE OR REPLACE RULE query_expr_xbind_update_rule AS
3855 ON UPDATE TO query.expr_xbind
3857 UPDATE query.expression SET
3859 parenthesize = NEW.parenthesize,
3860 parent_expr = NEW.parent_expr,
3861 seq_no = NEW.seq_no,
3862 bind_variable = NEW.bind_variable
3866 CREATE OR REPLACE RULE query_expr_xbind_delete_rule AS
3867 ON DELETE TO query.expr_xbind
3869 DELETE FROM query.expression WHERE id = OLD.id;
3871 -- Create updatable view for boolean expressions
3873 CREATE OR REPLACE VIEW query.expr_xbool AS
3886 CREATE OR REPLACE RULE query_expr_xbool_insert_rule AS
3887 ON INSERT TO query.expr_xbool
3889 INSERT INTO query.expression (
3898 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
3900 COALESCE(NEW.parenthesize, FALSE),
3902 COALESCE(NEW.seq_no, 1),
3904 COALESCE(NEW.negate, false)
3907 CREATE OR REPLACE RULE query_expr_xbool_update_rule AS
3908 ON UPDATE TO query.expr_xbool
3910 UPDATE query.expression SET
3912 parenthesize = NEW.parenthesize,
3913 parent_expr = NEW.parent_expr,
3914 seq_no = NEW.seq_no,
3915 literal = NEW.literal,
3920 CREATE OR REPLACE RULE query_expr_xbool_delete_rule AS
3921 ON DELETE TO query.expr_xbool
3923 DELETE FROM query.expression WHERE id = OLD.id;
3925 -- Create updatable view for CASE expressions
3927 CREATE OR REPLACE VIEW query.expr_xcase AS
3940 CREATE OR REPLACE RULE query_expr_xcase_insert_rule AS
3941 ON INSERT TO query.expr_xcase
3943 INSERT INTO query.expression (
3952 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
3954 COALESCE(NEW.parenthesize, FALSE),
3956 COALESCE(NEW.seq_no, 1),
3958 COALESCE(NEW.negate, false)
3961 CREATE OR REPLACE RULE query_expr_xcase_update_rule AS
3962 ON UPDATE TO query.expr_xcase
3964 UPDATE query.expression SET
3966 parenthesize = NEW.parenthesize,
3967 parent_expr = NEW.parent_expr,
3968 seq_no = NEW.seq_no,
3969 left_operand = NEW.left_operand,
3974 CREATE OR REPLACE RULE query_expr_xcase_delete_rule AS
3975 ON DELETE TO query.expr_xcase
3977 DELETE FROM query.expression WHERE id = OLD.id;
3979 -- Create updatable view for cast expressions
3981 CREATE OR REPLACE VIEW query.expr_xcast AS
3995 CREATE OR REPLACE RULE query_expr_xcast_insert_rule AS
3996 ON INSERT TO query.expr_xcast
3998 INSERT INTO query.expression (
4008 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4010 COALESCE(NEW.parenthesize, FALSE),
4012 COALESCE(NEW.seq_no, 1),
4015 COALESCE(NEW.negate, false)
4018 CREATE OR REPLACE RULE query_expr_xcast_update_rule AS
4019 ON UPDATE TO query.expr_xcast
4021 UPDATE query.expression SET
4023 parenthesize = NEW.parenthesize,
4024 parent_expr = NEW.parent_expr,
4025 seq_no = NEW.seq_no,
4026 left_operand = NEW.left_operand,
4027 cast_type = NEW.cast_type,
4032 CREATE OR REPLACE RULE query_expr_xcast_delete_rule AS
4033 ON DELETE TO query.expr_xcast
4035 DELETE FROM query.expression WHERE id = OLD.id;
4037 -- Create updatable view for column expressions
4039 CREATE OR REPLACE VIEW query.expr_xcol AS
4053 CREATE OR REPLACE RULE query_expr_xcol_insert_rule AS
4054 ON INSERT TO query.expr_xcol
4056 INSERT INTO query.expression (
4066 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4068 COALESCE(NEW.parenthesize, FALSE),
4070 COALESCE(NEW.seq_no, 1),
4073 COALESCE(NEW.negate, false)
4076 CREATE OR REPLACE RULE query_expr_xcol_update_rule AS
4077 ON UPDATE TO query.expr_xcol
4079 UPDATE query.expression SET
4081 parenthesize = NEW.parenthesize,
4082 parent_expr = NEW.parent_expr,
4083 seq_no = NEW.seq_no,
4084 table_alias = NEW.table_alias,
4085 column_name = NEW.column_name,
4090 CREATE OR REPLACE RULE query_expr_xcol_delete_rule AS
4091 ON DELETE TO query.expr_xcol
4093 DELETE FROM query.expression WHERE id = OLD.id;
4095 -- Create updatable view for EXISTS expressions
4097 CREATE OR REPLACE VIEW query.expr_xex AS
4110 CREATE OR REPLACE RULE query_expr_xex_insert_rule AS
4111 ON INSERT TO query.expr_xex
4113 INSERT INTO query.expression (
4122 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4124 COALESCE(NEW.parenthesize, FALSE),
4126 COALESCE(NEW.seq_no, 1),
4128 COALESCE(NEW.negate, false)
4131 CREATE OR REPLACE RULE query_expr_xex_update_rule AS
4132 ON UPDATE TO query.expr_xex
4134 UPDATE query.expression SET
4136 parenthesize = NEW.parenthesize,
4137 parent_expr = NEW.parent_expr,
4138 seq_no = NEW.seq_no,
4139 subquery = NEW.subquery,
4144 CREATE OR REPLACE RULE query_expr_xex_delete_rule AS
4145 ON DELETE TO query.expr_xex
4147 DELETE FROM query.expression WHERE id = OLD.id;
4149 -- Create updatable view for function call expressions
4151 CREATE OR REPLACE VIEW query.expr_xfunc AS
4165 CREATE OR REPLACE RULE query_expr_xfunc_insert_rule AS
4166 ON INSERT TO query.expr_xfunc
4168 INSERT INTO query.expression (
4178 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4180 COALESCE(NEW.parenthesize, FALSE),
4182 COALESCE(NEW.seq_no, 1),
4185 COALESCE(NEW.negate, false)
4188 CREATE OR REPLACE RULE query_expr_xfunc_update_rule AS
4189 ON UPDATE TO query.expr_xfunc
4191 UPDATE query.expression SET
4193 parenthesize = NEW.parenthesize,
4194 parent_expr = NEW.parent_expr,
4195 seq_no = NEW.seq_no,
4196 column_name = NEW.column_name,
4197 function_id = NEW.function_id,
4202 CREATE OR REPLACE RULE query_expr_xfunc_delete_rule AS
4203 ON DELETE TO query.expr_xfunc
4205 DELETE FROM query.expression WHERE id = OLD.id;
4207 -- Create updatable view for IN expressions
4209 CREATE OR REPLACE VIEW query.expr_xin AS
4223 CREATE OR REPLACE RULE query_expr_xin_insert_rule AS
4224 ON INSERT TO query.expr_xin
4226 INSERT INTO query.expression (
4236 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4238 COALESCE(NEW.parenthesize, FALSE),
4240 COALESCE(NEW.seq_no, 1),
4243 COALESCE(NEW.negate, false)
4246 CREATE OR REPLACE RULE query_expr_xin_update_rule AS
4247 ON UPDATE TO query.expr_xin
4249 UPDATE query.expression SET
4251 parenthesize = NEW.parenthesize,
4252 parent_expr = NEW.parent_expr,
4253 seq_no = NEW.seq_no,
4254 left_operand = NEW.left_operand,
4255 subquery = NEW.subquery,
4260 CREATE OR REPLACE RULE query_expr_xin_delete_rule AS
4261 ON DELETE TO query.expr_xin
4263 DELETE FROM query.expression WHERE id = OLD.id;
4265 -- Create updatable view for IS NULL expressions
4267 CREATE OR REPLACE VIEW query.expr_xisnull AS
4280 CREATE OR REPLACE RULE query_expr_xisnull_insert_rule AS
4281 ON INSERT TO query.expr_xisnull
4283 INSERT INTO query.expression (
4292 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4294 COALESCE(NEW.parenthesize, FALSE),
4296 COALESCE(NEW.seq_no, 1),
4298 COALESCE(NEW.negate, false)
4301 CREATE OR REPLACE RULE query_expr_xisnull_update_rule AS
4302 ON UPDATE TO query.expr_xisnull
4304 UPDATE query.expression SET
4306 parenthesize = NEW.parenthesize,
4307 parent_expr = NEW.parent_expr,
4308 seq_no = NEW.seq_no,
4309 left_operand = NEW.left_operand,
4314 CREATE OR REPLACE RULE query_expr_xisnull_delete_rule AS
4315 ON DELETE TO query.expr_xisnull
4317 DELETE FROM query.expression WHERE id = OLD.id;
4319 -- Create updatable view for NULL expressions
4321 CREATE OR REPLACE VIEW query.expr_xnull AS
4333 CREATE OR REPLACE RULE query_expr_xnull_insert_rule AS
4334 ON INSERT TO query.expr_xnull
4336 INSERT INTO query.expression (
4344 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4346 COALESCE(NEW.parenthesize, FALSE),
4348 COALESCE(NEW.seq_no, 1),
4349 COALESCE(NEW.negate, false)
4352 CREATE OR REPLACE RULE query_expr_xnull_update_rule AS
4353 ON UPDATE TO query.expr_xnull
4355 UPDATE query.expression SET
4357 parenthesize = NEW.parenthesize,
4358 parent_expr = NEW.parent_expr,
4359 seq_no = NEW.seq_no,
4364 CREATE OR REPLACE RULE query_expr_xnull_delete_rule AS
4365 ON DELETE TO query.expr_xnull
4367 DELETE FROM query.expression WHERE id = OLD.id;
4369 -- Create updatable view for numeric literal expressions
4371 CREATE OR REPLACE VIEW query.expr_xnum AS
4383 CREATE OR REPLACE RULE query_expr_xnum_insert_rule AS
4384 ON INSERT TO query.expr_xnum
4386 INSERT INTO query.expression (
4394 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4396 COALESCE(NEW.parenthesize, FALSE),
4398 COALESCE(NEW.seq_no, 1),
4402 CREATE OR REPLACE RULE query_expr_xnum_update_rule AS
4403 ON UPDATE TO query.expr_xnum
4405 UPDATE query.expression SET
4407 parenthesize = NEW.parenthesize,
4408 parent_expr = NEW.parent_expr,
4409 seq_no = NEW.seq_no,
4410 literal = NEW.literal
4414 CREATE OR REPLACE RULE query_expr_xnum_delete_rule AS
4415 ON DELETE TO query.expr_xnum
4417 DELETE FROM query.expression WHERE id = OLD.id;
4419 -- Create updatable view for operator expressions
4421 CREATE OR REPLACE VIEW query.expr_xop AS
4436 CREATE OR REPLACE RULE query_expr_xop_insert_rule AS
4437 ON INSERT TO query.expr_xop
4439 INSERT INTO query.expression (
4450 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4452 COALESCE(NEW.parenthesize, FALSE),
4454 COALESCE(NEW.seq_no, 1),
4458 COALESCE(NEW.negate, false)
4461 CREATE OR REPLACE RULE query_expr_xop_update_rule AS
4462 ON UPDATE TO query.expr_xop
4464 UPDATE query.expression SET
4466 parenthesize = NEW.parenthesize,
4467 parent_expr = NEW.parent_expr,
4468 seq_no = NEW.seq_no,
4469 left_operand = NEW.left_operand,
4470 operator = NEW.operator,
4471 right_operand = NEW.right_operand,
4476 CREATE OR REPLACE RULE query_expr_xop_delete_rule AS
4477 ON DELETE TO query.expr_xop
4479 DELETE FROM query.expression WHERE id = OLD.id;
4481 -- Create updatable view for series expressions
4482 -- i.e. series of expressions separated by operators
4484 CREATE OR REPLACE VIEW query.expr_xser AS
4497 CREATE OR REPLACE RULE query_expr_xser_insert_rule AS
4498 ON INSERT TO query.expr_xser
4500 INSERT INTO query.expression (
4509 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4511 COALESCE(NEW.parenthesize, FALSE),
4513 COALESCE(NEW.seq_no, 1),
4515 COALESCE(NEW.negate, false)
4518 CREATE OR REPLACE RULE query_expr_xser_update_rule AS
4519 ON UPDATE TO query.expr_xser
4521 UPDATE query.expression SET
4523 parenthesize = NEW.parenthesize,
4524 parent_expr = NEW.parent_expr,
4525 seq_no = NEW.seq_no,
4526 operator = NEW.operator,
4531 CREATE OR REPLACE RULE query_expr_xser_delete_rule AS
4532 ON DELETE TO query.expr_xser
4534 DELETE FROM query.expression WHERE id = OLD.id;
4536 -- Create updatable view for string literal expressions
4538 CREATE OR REPLACE VIEW query.expr_xstr AS
4550 CREATE OR REPLACE RULE query_expr_string_insert_rule AS
4551 ON INSERT TO query.expr_xstr
4553 INSERT INTO query.expression (
4561 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4563 COALESCE(NEW.parenthesize, FALSE),
4565 COALESCE(NEW.seq_no, 1),
4569 CREATE OR REPLACE RULE query_expr_string_update_rule AS
4570 ON UPDATE TO query.expr_xstr
4572 UPDATE query.expression SET
4574 parenthesize = NEW.parenthesize,
4575 parent_expr = NEW.parent_expr,
4576 seq_no = NEW.seq_no,
4577 literal = NEW.literal
4581 CREATE OR REPLACE RULE query_expr_string_delete_rule AS
4582 ON DELETE TO query.expr_xstr
4584 DELETE FROM query.expression WHERE id = OLD.id;
4586 -- Create updatable view for subquery expressions
4588 CREATE OR REPLACE VIEW query.expr_xsubq AS
4601 CREATE OR REPLACE RULE query_expr_xsubq_insert_rule AS
4602 ON INSERT TO query.expr_xsubq
4604 INSERT INTO query.expression (
4613 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
4615 COALESCE(NEW.parenthesize, FALSE),
4617 COALESCE(NEW.seq_no, 1),
4619 COALESCE(NEW.negate, false)
4622 CREATE OR REPLACE RULE query_expr_xsubq_update_rule AS
4623 ON UPDATE TO query.expr_xsubq
4625 UPDATE query.expression SET
4627 parenthesize = NEW.parenthesize,
4628 parent_expr = NEW.parent_expr,
4629 seq_no = NEW.seq_no,
4630 subquery = NEW.subquery,
4635 CREATE OR REPLACE RULE query_expr_xsubq_delete_rule AS
4636 ON DELETE TO query.expr_xsubq
4638 DELETE FROM query.expression WHERE id = OLD.id;
4640 CREATE TABLE action.fieldset (
4641 id SERIAL PRIMARY KEY,
4642 owner INT NOT NULL REFERENCES actor.usr (id)
4643 DEFERRABLE INITIALLY DEFERRED,
4644 owning_lib INT NOT NULL REFERENCES actor.org_unit (id)
4645 DEFERRABLE INITIALLY DEFERRED,
4646 status TEXT NOT NULL
4647 CONSTRAINT valid_status CHECK ( status in
4648 ( 'PENDING', 'APPLIED', 'ERROR' )),
4649 creation_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
4650 scheduled_time TIMESTAMPTZ,
4651 applied_time TIMESTAMPTZ,
4652 classname TEXT NOT NULL, -- an IDL class name
4654 stored_query INT REFERENCES query.stored_query (id)
4655 DEFERRABLE INITIALLY DEFERRED,
4657 CONSTRAINT lib_name_unique UNIQUE (owning_lib, name),
4658 CONSTRAINT fieldset_one_or_the_other CHECK (
4659 (stored_query IS NOT NULL AND pkey_value IS NULL) OR
4660 (pkey_value IS NOT NULL AND stored_query IS NULL)
4662 -- the CHECK constraint means we can update the fields for a single
4663 -- row without all the extra overhead involved in a query
4666 CREATE INDEX action_fieldset_sched_time_idx ON action.fieldset( scheduled_time );
4667 CREATE INDEX action_owner_idx ON action.fieldset( owner );
4669 CREATE TABLE action.fieldset_col_val (
4670 id SERIAL PRIMARY KEY,
4671 fieldset INT NOT NULL REFERENCES action.fieldset
4673 DEFERRABLE INITIALLY DEFERRED,
4674 col TEXT NOT NULL, -- "field" from the idl ... the column on the table
4675 val TEXT, -- value for the column ... NULL means, well, NULL
4676 CONSTRAINT fieldset_col_once_per_set UNIQUE (fieldset, col)
4679 CREATE OR REPLACE FUNCTION action.apply_fieldset(
4680 fieldset_id IN INT, -- id from action.fieldset
4681 table_name IN TEXT, -- table to be updated
4682 pkey_name IN TEXT, -- name of primary key column in that table
4683 query IN TEXT -- query constructed by qstore (for query-based
4684 -- fieldsets only; otherwise null
4699 IF fieldset_id IS NULL THEN
4700 RETURN 'Fieldset ID parameter is NULL';
4702 IF table_name IS NULL THEN
4703 RETURN 'Table name parameter is NULL';
4705 IF pkey_name IS NULL THEN
4706 RETURN 'Primary key name parameter is NULL';
4709 statement := 'UPDATE ' || table_name || ' SET';
4713 quote_literal( pkey_value )
4722 IF fs_status IS NULL THEN
4723 RETURN 'No fieldset found for id = ' || fieldset_id;
4724 ELSIF fs_status = 'APPLIED' THEN
4725 RETURN 'Fieldset ' || fieldset_id || ' has already been applied';
4732 FROM action.fieldset_col_val
4733 WHERE fieldset = fieldset_id
4735 statement := statement || sep || ' ' || cv.col
4736 || ' = ' || coalesce( quote_literal( cv.val ), 'NULL' );
4741 RETURN 'Fieldset ' || fieldset_id || ' has no column values defined';
4744 -- Add the WHERE clause. This differs according to whether it's a
4745 -- single-row fieldset or a query-based fieldset.
4747 IF query IS NULL AND fs_pkey_value IS NULL THEN
4748 RETURN 'Incomplete fieldset: neither a primary key nor a query available';
4749 ELSIF query IS NOT NULL AND fs_pkey_value IS NULL THEN
4750 fs_query := rtrim( query, ';' );
4751 statement := statement || ' WHERE ' || pkey_name || ' IN ( '
4752 || fs_query || ' );';
4753 ELSIF query IS NULL AND fs_pkey_value IS NOT NULL THEN
4754 statement := statement || ' WHERE ' || pkey_name || ' = '
4755 || fs_pkey_value || ';';
4756 ELSE -- both are not null
4757 RETURN 'Ambiguous fieldset: both a primary key and a query provided';
4760 -- Execute the update
4764 GET DIAGNOSTICS update_count = ROW_COUNT;
4766 IF UPDATE_COUNT > 0 THEN
4767 status_code := 'APPLIED';
4770 status_code := 'ERROR';
4771 msg := 'No eligible rows found for fieldset ' || fieldset_id;
4773 EXCEPTION WHEN OTHERS THEN
4774 status_code := 'ERROR';
4775 msg := 'Unable to apply fieldset ' || fieldset_id
4779 -- Update fieldset status
4781 UPDATE action.fieldset
4782 SET status = status_code,
4783 applied_time = now()
4784 WHERE id = fieldset_id;
4788 $$ LANGUAGE plpgsql;
4790 COMMENT ON FUNCTION action.apply_fieldset( INT, TEXT, TEXT, TEXT ) IS $$
4792 * Applies a specified fieldset, using a supplied table name and primary
4793 * key name. The query parameter should be non-null only for
4794 * query-based fieldsets.
4796 * Returns NULL if successful, or an error message if not.
4801 -- stuff pertaining to settings and setting types
4802 -- almost everything pertaining to permission.perm_list
4803 -- everything pertaining to the action_trigger schema
4805 -- almost everything pertaining to fieldsets
4807 CREATE INDEX uhr_hold_idx ON action.unfulfilled_hold_list (hold);
4809 CREATE OR REPLACE VIEW action.unfulfilled_hold_loops AS
4813 FROM action.unfulfilled_hold_list u
4814 JOIN asset.copy c ON (c.id = u.current_copy)
4817 CREATE OR REPLACE VIEW action.unfulfilled_hold_min_loop AS
4820 FROM action.unfulfilled_hold_loops
4823 CREATE OR REPLACE VIEW action.unfulfilled_hold_innermost_loop AS
4825 FROM action.unfulfilled_hold_loops l
4826 JOIN action.unfulfilled_hold_min_loop m USING (hold)
4827 WHERE l.count = m.min;
4829 ALTER TABLE asset.copy
4830 ADD COLUMN dummy_isbn TEXT;
4832 ALTER TABLE auditor.asset_copy_history
4833 ADD COLUMN dummy_isbn TEXT;
4835 -- Add new column status_changed_date to asset.copy, with trigger to maintain it
4836 -- Add corresponding new column to auditor.asset_copy_history
4838 ALTER TABLE asset.copy
4839 ADD COLUMN status_changed_time TIMESTAMPTZ;
4841 ALTER TABLE auditor.asset_copy_history
4842 ADD COLUMN status_changed_time TIMESTAMPTZ;
4844 CREATE OR REPLACE FUNCTION asset.acp_status_changed()
4845 RETURNS TRIGGER AS $$
4847 IF NEW.status <> OLD.status THEN
4848 NEW.status_changed_time := now();
4852 $$ LANGUAGE plpgsql;
4854 CREATE TRIGGER acp_status_changed_trig
4855 BEFORE UPDATE ON asset.copy
4856 FOR EACH ROW EXECUTE PROCEDURE asset.acp_status_changed();
4858 ALTER TABLE asset.copy
4859 ADD COLUMN mint_condition boolean NOT NULL DEFAULT TRUE;
4861 ALTER TABLE auditor.asset_copy_history
4862 ADD COLUMN mint_condition boolean NOT NULL DEFAULT TRUE;
4864 ALTER TABLE asset.copy ADD COLUMN floating BOOL NOT NULL DEFAULT FALSE;
4865 ALTER TABLE auditor.asset_copy_history ADD COLUMN floating BOOL;
4867 DROP INDEX IF EXISTS asset.copy_barcode_key;
4868 CREATE UNIQUE INDEX copy_barcode_key ON asset.copy (barcode) WHERE deleted = FALSE OR deleted IS FALSE;
4870 -- Note: later we create a trigger a_opac_vis_mat_view_tgr
4871 -- AFTER INSERT OR UPDATE ON asset.copy
4873 ALTER TABLE asset.copy ADD COLUMN cost NUMERIC(8,2);
4874 ALTER TABLE auditor.asset_copy_history ADD COLUMN cost NUMERIC(8,2);
4876 -- Moke mostly parallel changes to action.circulation
4877 -- and action.aged_circulation
4879 ALTER TABLE action.circulation
4880 ADD COLUMN workstation INT
4881 REFERENCES actor.workstation
4883 DEFERRABLE INITIALLY DEFERRED;
4885 ALTER TABLE action.aged_circulation
4886 ADD COLUMN workstation INT;
4888 ALTER TABLE action.circulation
4889 ADD COLUMN parent_circ BIGINT
4890 REFERENCES action.circulation(id)
4891 DEFERRABLE INITIALLY DEFERRED;
4893 CREATE UNIQUE INDEX circ_parent_idx
4894 ON action.circulation( parent_circ )
4895 WHERE parent_circ IS NOT NULL;
4897 ALTER TABLE action.aged_circulation
4898 ADD COLUMN parent_circ BIGINT;
4900 ALTER TABLE action.circulation
4901 ADD COLUMN checkin_workstation INT
4902 REFERENCES actor.workstation(id)
4904 DEFERRABLE INITIALLY DEFERRED;
4906 ALTER TABLE action.aged_circulation
4907 ADD COLUMN checkin_workstation INT;
4909 ALTER TABLE action.circulation
4910 ADD COLUMN checkin_scan_time TIMESTAMPTZ;
4912 ALTER TABLE action.aged_circulation
4913 ADD COLUMN checkin_scan_time TIMESTAMPTZ;
4915 CREATE INDEX action_circulation_target_copy_idx
4916 ON action.circulation (target_copy);
4918 CREATE INDEX action_aged_circulation_target_copy_idx
4919 ON action.aged_circulation (target_copy);
4921 ALTER TABLE action.circulation
4922 DROP CONSTRAINT circulation_stop_fines_check;
4924 ALTER TABLE action.circulation
4925 ADD CONSTRAINT circulation_stop_fines_check
4926 CHECK (stop_fines IN (
4927 'CHECKIN','CLAIMSRETURNED','LOST','MAXFINES','RENEW','LONGOVERDUE','CLAIMSNEVERCHECKEDOUT'));
4929 -- Correct some long-standing misspellings involving variations of "recur"
4931 ALTER TABLE action.circulation RENAME COLUMN recuring_fine TO recurring_fine;
4932 ALTER TABLE action.circulation RENAME COLUMN recuring_fine_rule TO recurring_fine_rule;
4934 ALTER TABLE action.aged_circulation RENAME COLUMN recuring_fine TO recurring_fine;
4935 ALTER TABLE action.aged_circulation RENAME COLUMN recuring_fine_rule TO recurring_fine_rule;
4937 ALTER TABLE config.rule_recuring_fine RENAME TO rule_recurring_fine;
4938 ALTER TABLE config.rule_recuring_fine_id_seq RENAME TO rule_recurring_fine_id_seq;
4940 ALTER TABLE config.rule_recurring_fine RENAME COLUMN recurance_interval TO recurrence_interval;
4942 -- Might as well keep the comment in sync as well
4943 COMMENT ON TABLE config.rule_recurring_fine IS $$
4945 * Copyright (C) 2005 Georgia Public Library Service
4946 * Mike Rylander <mrylander@gmail.com>
4948 * Circulation Recurring Fine rules
4950 * Each circulation is given a recurring fine amount based on one of
4951 * these rules. The recurrence_interval should not be any shorter
4952 * than the interval between runs of the fine_processor.pl script
4953 * (which is run from CRON), or you could miss fines.
4958 * This program is free software; you can redistribute it and/or
4959 * modify it under the terms of the GNU General Public License
4960 * as published by the Free Software Foundation; either version 2
4961 * of the License, or (at your option) any later version.
4963 * This program is distributed in the hope that it will be useful,
4964 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4965 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4966 * GNU General Public License for more details.
4970 -- Extend the name change to some related views:
4972 -- Drop a view temporarily in order to alter action.all_circulation, upon
4973 -- which it is dependent. We will recreate the view later.
4975 DROP VIEW IF EXISTS extend_reporter.full_circ_count;
4977 -- You would think that CREATE OR REPLACE would be enough, but in testing
4978 -- PostgreSQL complained about renaming the columns in the view. So we
4979 -- drop the view first.
4980 DROP VIEW IF EXISTS action.all_circulation;
4982 CREATE OR REPLACE VIEW action.all_circulation AS
4983 SELECT id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
4984 copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
4985 circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, due_date,
4986 stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
4987 max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
4988 max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ
4989 FROM action.aged_circulation
4991 SELECT DISTINCT circ.id,COALESCE(a.post_code,b.post_code) AS usr_post_code, p.home_ou AS usr_home_ou, p.profile AS usr_profile, EXTRACT(YEAR FROM p.dob)::INT AS usr_birth_year,
4992 cp.call_number AS copy_call_number, cp.location AS copy_location, cn.owning_lib AS copy_owning_lib, cp.circ_lib AS copy_circ_lib,
4993 cn.record AS copy_bib_record, circ.xact_start, circ.xact_finish, circ.target_copy, circ.circ_lib, circ.circ_staff, circ.checkin_staff,
4994 circ.checkin_lib, circ.renewal_remaining, circ.due_date, circ.stop_fines_time, circ.checkin_time, circ.create_time, circ.duration,
4995 circ.fine_interval, circ.recurring_fine, circ.max_fine, circ.phone_renewal, circ.desk_renewal, circ.opac_renewal, circ.duration_rule,
4996 circ.recurring_fine_rule, circ.max_fine_rule, circ.stop_fines, circ.workstation, circ.checkin_workstation, circ.checkin_scan_time,
4998 FROM action.circulation circ
4999 JOIN asset.copy cp ON (circ.target_copy = cp.id)
5000 JOIN asset.call_number cn ON (cp.call_number = cn.id)
5001 JOIN actor.usr p ON (circ.usr = p.id)
5002 LEFT JOIN actor.usr_address a ON (p.mailing_address = a.id)
5003 LEFT JOIN actor.usr_address b ON (p.billing_address = a.id);
5005 -- Recreate the temporarily dropped view, having altered the action.all_circulation view:
5007 CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS
5008 SELECT cp.id, COALESCE(sum(c.circ_count), 0::bigint) + COALESCE(count(circ.id), 0::bigint) + COALESCE(count(acirc.id), 0::bigint) AS circ_count
5009 FROM asset."copy" cp
5010 LEFT JOIN extend_reporter.legacy_circ_count c USING (id)
5011 LEFT JOIN "action".circulation circ ON circ.target_copy = cp.id
5012 LEFT JOIN "action".aged_circulation acirc ON acirc.target_copy = cp.id
5015 CREATE UNIQUE INDEX only_one_concurrent_checkout_per_copy ON action.circulation(target_copy) WHERE checkin_time IS NULL;
5017 ALTER TABLE action.circulation DROP CONSTRAINT action_circulation_target_copy_fkey;
5019 CREATE OR REPLACE FUNCTION action.age_circ_on_delete () RETURNS TRIGGER AS $$
5024 -- If there are any renewals for this circulation, don't archive or delete
5025 -- it yet. We'll do so later, when we archive and delete the renewals.
5027 SELECT 'Y' INTO found
5028 FROM action.circulation
5029 WHERE parent_circ = OLD.id
5033 RETURN NULL; -- don't delete
5036 -- Archive a copy of the old row to action.aged_circulation
5038 INSERT INTO action.aged_circulation
5039 (id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
5040 copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
5041 circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, due_date,
5042 stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
5043 max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
5044 max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ)
5046 id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
5047 copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
5048 circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, due_date,
5049 stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
5050 max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
5051 max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ
5052 FROM action.all_circulation WHERE id = OLD.id;
5056 $$ LANGUAGE 'plpgsql';
5058 UPDATE config.z3950_attr SET truncation = 1 WHERE source = 'biblios' AND name = 'title';
5060 UPDATE config.z3950_attr SET truncation = 1 WHERE source = 'biblios' AND truncation = 0;
5062 -- Adding circ.holds.target_skip_me OU setting logic to the pre-matchpoint tests
5064 CREATE OR REPLACE FUNCTION action.hold_request_permit_test( pickup_ou INT, request_ou INT, match_item BIGINT, match_user INT, match_requestor INT ) RETURNS SETOF action.matrix_test_result AS $func$
5067 user_object actor.usr%ROWTYPE;
5068 age_protect_object config.rule_age_hold_protect%ROWTYPE;
5069 standing_penalty config.standing_penalty%ROWTYPE;
5070 transit_range_ou_type actor.org_unit_type%ROWTYPE;
5071 transit_source actor.org_unit%ROWTYPE;
5072 item_object asset.copy%ROWTYPE;
5073 ou_skip actor.org_unit_setting%ROWTYPE;
5074 result action.matrix_test_result;
5075 hold_test config.hold_matrix_matchpoint%ROWTYPE;
5077 hold_transit_prox INT;
5078 frozen_hold_count INT;
5079 context_org_list INT[];
5082 SELECT INTO user_object * FROM actor.usr WHERE id = match_user;
5083 SELECT INTO context_org_list ARRAY_ACCUM(id) FROM actor.org_unit_full_path( pickup_ou );
5085 result.success := TRUE;
5087 -- Fail if we couldn't find a user
5088 IF user_object.id IS NULL THEN
5089 result.fail_part := 'no_user';
5090 result.success := FALSE;
5096 SELECT INTO item_object * FROM asset.copy WHERE id = match_item;
5098 -- Fail if we couldn't find a copy
5099 IF item_object.id IS NULL THEN
5100 result.fail_part := 'no_item';
5101 result.success := FALSE;
5107 SELECT INTO matchpoint_id action.find_hold_matrix_matchpoint(pickup_ou, request_ou, match_item, match_user, match_requestor);
5108 result.matchpoint := matchpoint_id;
5110 SELECT INTO ou_skip * FROM actor.org_unit_setting WHERE name = 'circ.holds.target_skip_me' AND org_unit = item_object.circ_lib;
5112 -- Fail if the circ_lib for the item has circ.holds.target_skip_me set to true
5113 IF ou_skip.id IS NOT NULL AND ou_skip.value = 'true' THEN
5114 result.fail_part := 'circ.holds.target_skip_me';
5115 result.success := FALSE;
5121 -- Fail if user is barred
5122 IF user_object.barred IS TRUE THEN
5123 result.fail_part := 'actor.usr.barred';
5124 result.success := FALSE;
5130 -- Fail if we couldn't find any matchpoint (requires a default)
5131 IF matchpoint_id IS NULL THEN
5132 result.fail_part := 'no_matchpoint';
5133 result.success := FALSE;
5139 SELECT INTO hold_test * FROM config.hold_matrix_matchpoint WHERE id = matchpoint_id;
5141 IF hold_test.holdable IS FALSE THEN
5142 result.fail_part := 'config.hold_matrix_test.holdable';
5143 result.success := FALSE;
5148 IF hold_test.transit_range IS NOT NULL THEN
5149 SELECT INTO transit_range_ou_type * FROM actor.org_unit_type WHERE id = hold_test.transit_range;
5150 IF hold_test.distance_is_from_owner THEN
5151 SELECT INTO transit_source ou.* FROM actor.org_unit ou JOIN asset.call_number cn ON (cn.owning_lib = ou.id) WHERE cn.id = item_object.call_number;
5153 SELECT INTO transit_source * FROM actor.org_unit WHERE id = item_object.circ_lib;
5156 PERFORM * FROM actor.org_unit_descendants( transit_source.id, transit_range_ou_type.depth ) WHERE id = pickup_ou;
5159 result.fail_part := 'transit_range';
5160 result.success := FALSE;
5166 FOR standing_penalty IN
5167 SELECT DISTINCT csp.*
5168 FROM actor.usr_standing_penalty usp
5169 JOIN config.standing_penalty csp ON (csp.id = usp.standing_penalty)
5170 WHERE usr = match_user
5171 AND usp.org_unit IN ( SELECT * FROM explode_array(context_org_list) )
5172 AND (usp.stop_date IS NULL or usp.stop_date > NOW())
5173 AND csp.block_list LIKE '%HOLD%' LOOP
5175 result.fail_part := standing_penalty.name;
5176 result.success := FALSE;
5181 IF hold_test.stop_blocked_user IS TRUE THEN
5182 FOR standing_penalty IN
5183 SELECT DISTINCT csp.*
5184 FROM actor.usr_standing_penalty usp
5185 JOIN config.standing_penalty csp ON (csp.id = usp.standing_penalty)
5186 WHERE usr = match_user
5187 AND usp.org_unit IN ( SELECT * FROM explode_array(context_org_list) )
5188 AND (usp.stop_date IS NULL or usp.stop_date > NOW())
5189 AND csp.block_list LIKE '%CIRC%' LOOP
5191 result.fail_part := standing_penalty.name;
5192 result.success := FALSE;
5198 IF hold_test.max_holds IS NOT NULL THEN
5199 SELECT INTO hold_count COUNT(*)
5200 FROM action.hold_request
5201 WHERE usr = match_user
5202 AND fulfillment_time IS NULL
5203 AND cancel_time IS NULL
5204 AND CASE WHEN hold_test.include_frozen_holds THEN TRUE ELSE frozen IS FALSE END;
5206 IF hold_count >= hold_test.max_holds THEN
5207 result.fail_part := 'config.hold_matrix_test.max_holds';
5208 result.success := FALSE;
5214 IF item_object.age_protect IS NOT NULL THEN
5215 SELECT INTO age_protect_object * FROM config.rule_age_hold_protect WHERE id = item_object.age_protect;
5217 IF item_object.create_date + age_protect_object.age > NOW() THEN
5218 IF hold_test.distance_is_from_owner THEN
5219 SELECT INTO hold_transit_prox prox FROM actor.org_unit_proximity WHERE from_org = item_cn_object.owning_lib AND to_org = pickup_ou;
5221 SELECT INTO hold_transit_prox prox FROM actor.org_unit_proximity WHERE from_org = item_object.circ_lib AND to_org = pickup_ou;
5224 IF hold_transit_prox > age_protect_object.prox THEN
5225 result.fail_part := 'config.rule_age_hold_protect.prox';
5226 result.success := FALSE;
5239 $func$ LANGUAGE plpgsql;
5241 -- New post-delete trigger to propagate deletions to parent(s)
5243 CREATE OR REPLACE FUNCTION action.age_parent_circ_on_delete () RETURNS TRIGGER AS $$
5246 -- Having deleted a renewal, we can delete the original circulation (or a previous
5247 -- renewal, if that's what parent_circ is pointing to). That deletion will trigger
5248 -- deletion of any prior parents, etc. recursively.
5250 IF OLD.parent_circ IS NOT NULL THEN
5251 DELETE FROM action.circulation
5252 WHERE id = OLD.parent_circ;
5257 $$ LANGUAGE 'plpgsql';
5259 CREATE TRIGGER age_parent_circ AFTER DELETE ON action.circulation
5260 FOR EACH ROW EXECUTE PROCEDURE action.age_parent_circ_on_delete ();
5262 -- This only gets inserted if there are no other id > 100 billing types
5263 INSERT INTO config.billing_type (id, name, owner) SELECT DISTINCT 101, oils_i18n_gettext(101, 'Misc', 'cbt', 'name'), 1 FROM config.billing_type_id_seq WHERE last_value < 101;
5264 SELECT SETVAL('config.billing_type_id_seq'::TEXT, 101) FROM config.billing_type_id_seq WHERE last_value < 101;
5266 -- Populate xact_type column in the materialized version of billable_xact_summary
5268 CREATE OR REPLACE FUNCTION money.mat_summary_create () RETURNS TRIGGER AS $$
5270 INSERT INTO money.materialized_billable_xact_summary (id, usr, xact_start, xact_finish, total_paid, total_owed, balance_owed, xact_type)
5271 VALUES ( NEW.id, NEW.usr, NEW.xact_start, NEW.xact_finish, 0.0, 0.0, 0.0, TG_ARGV[0]);
5274 $$ LANGUAGE PLPGSQL;
5276 DROP TRIGGER IF EXISTS mat_summary_create_tgr ON action.circulation;
5277 CREATE TRIGGER mat_summary_create_tgr AFTER INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_create ('circulation');
5279 DROP TRIGGER IF EXISTS mat_summary_create_tgr ON money.grocery;
5280 CREATE TRIGGER mat_summary_create_tgr AFTER INSERT ON money.grocery FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_create ('grocery');
5282 CREATE RULE money_payment_view_update AS ON UPDATE TO money.payment_view DO INSTEAD
5283 UPDATE money.payment SET xact = NEW.xact, payment_ts = NEW.payment_ts, voided = NEW.voided, amount = NEW.amount, note = NEW.note WHERE id = NEW.id;
5285 -- Generate the equivalent of compound subject entries from the existing rows
5286 -- so that we don't have to laboriously reindex them
5288 --INSERT INTO config.metabib_field (field_class, name, format, xpath ) VALUES
5289 -- ( 'subject', 'complete', 'mods32', $$//mods32:mods/mods32:subject//text()$$ );
5291 --CREATE INDEX metabib_subject_field_entry_source_idx ON metabib.subject_field_entry (source);
5293 --INSERT INTO metabib.subject_field_entry (source, field, value)
5296 -- FROM config.metabib_field
5297 -- WHERE field_class = 'subject' AND name = 'complete'
5299 -- ARRAY_TO_STRING (
5302 -- FROM metabib.subject_field_entry msfe
5303 -- WHERE msfe.source = groupee.source
5309 -- FROM metabib.subject_field_entry
5313 CREATE OR REPLACE FUNCTION money.materialized_summary_billing_del () RETURNS TRIGGER AS $$
5315 prev_billing money.billing%ROWTYPE;
5316 old_billing money.billing%ROWTYPE;
5318 SELECT * INTO prev_billing FROM money.billing WHERE xact = OLD.xact AND NOT voided ORDER BY billing_ts DESC LIMIT 1 OFFSET 1;
5319 SELECT * INTO old_billing FROM money.billing WHERE xact = OLD.xact AND NOT voided ORDER BY billing_ts DESC LIMIT 1;
5321 IF OLD.id = old_billing.id THEN
5322 UPDATE money.materialized_billable_xact_summary
5323 SET last_billing_ts = prev_billing.billing_ts,
5324 last_billing_note = prev_billing.note,
5325 last_billing_type = prev_billing.billing_type
5326 WHERE id = OLD.xact;
5329 IF NOT OLD.voided THEN
5330 UPDATE money.materialized_billable_xact_summary
5331 SET total_owed = total_owed - OLD.amount,
5332 balance_owed = balance_owed + OLD.amount
5333 WHERE id = OLD.xact;
5338 $$ LANGUAGE PLPGSQL;
5340 -- ARG! need to rid ourselves of the broken table definition ... this mechanism is not ideal, sorry.
5341 DROP TABLE IF EXISTS config.index_normalizer CASCADE;
5343 CREATE OR REPLACE FUNCTION public.naco_normalize( TEXT, TEXT ) RETURNS TEXT AS $func$
5344 use Unicode::Normalize;
5347 # When working with Unicode data, the first step is to decode it to
5348 # a byte string; after that, lowercasing is safe
5349 my $txt = lc(decode_utf8(shift));
5353 $txt =~ s/\pM+//go; # Remove diacritics
5355 $txt =~ s/\xE6/AE/go; # Convert ae digraph
5356 $txt =~ s/\x{153}/OE/go;# Convert oe digraph
5357 $txt =~ s/\xFE/TH/go; # Convert Icelandic thorn
5359 $txt =~ tr/\x{2070}\x{2071}\x{2072}\x{2073}\x{2074}\x{2075}\x{2076}\x{2077}\x{2078}\x{2079}\x{207A}\x{207B}/0123456789+-/;# Convert superscript numbers
5360 $txt =~ tr/\x{2080}\x{2081}\x{2082}\x{2083}\x{2084}\x{2085}\x{2086}\x{2087}\x{2088}\x{2089}\x{208A}\x{208B}/0123456889+-/;# Convert subscript numbers
5362 $txt =~ tr/\x{0251}\x{03B1}\x{03B2}\x{0262}\x{03B3}/AABGG/; # Convert Latin and Greek
5363 $txt =~ tr/\x{2113}\xF0\!\"\(\)\-\{\}\<\>\;\:\.\?\xA1\xBF\/\\\@\*\%\=\xB1\+\xAE\xA9\x{2117}\$\xA3\x{FFE1}\xB0\^\_\~\`/LD /; # Convert Misc
5364 $txt =~ tr/\'\[\]\|//d; # Remove Misc
5366 if ($sf && $sf =~ /^a/o) {
5367 my $commapos = index($txt,',');
5368 if ($commapos > -1) {
5369 if ($commapos != length($txt) - 1) {
5370 my @list = split /,/, $txt;
5371 my $first = shift @list;
5372 $txt = $first . ',' . join(' ', @list);
5381 $txt =~ s/\s+/ /go; # Compress multiple spaces
5382 $txt =~ s/^\s+//o; # Remove leading space
5383 $txt =~ s/\s+$//o; # Remove trailing space
5385 # Encoding the outgoing string is good practice, but not strictly
5386 # necessary in this case because we've stripped everything from it
5387 return encode_utf8($txt);
5388 $func$ LANGUAGE 'plperlu' STRICT IMMUTABLE;
5390 -- Some handy functions, based on existing ones, to provide optional ingest normalization
5392 CREATE OR REPLACE FUNCTION public.left_trunc( TEXT, INT ) RETURNS TEXT AS $func$
5393 SELECT SUBSTRING($1,$2);
5394 $func$ LANGUAGE SQL STRICT IMMUTABLE;
5396 CREATE OR REPLACE FUNCTION public.right_trunc( TEXT, INT ) RETURNS TEXT AS $func$
5397 SELECT SUBSTRING($1,1,$2);
5398 $func$ LANGUAGE SQL STRICT IMMUTABLE;
5400 CREATE OR REPLACE FUNCTION public.naco_normalize_keep_comma( TEXT ) RETURNS TEXT AS $func$
5401 SELECT public.naco_normalize($1,'a');
5402 $func$ LANGUAGE SQL STRICT IMMUTABLE;
5404 CREATE OR REPLACE FUNCTION public.split_date_range( TEXT ) RETURNS TEXT AS $func$
5405 SELECT REGEXP_REPLACE( $1, E'(\\d{4})-(\\d{4})', E'\\1 \\2', 'g' );
5406 $func$ LANGUAGE SQL STRICT IMMUTABLE;
5408 -- And ... a table in which to register them
5410 CREATE TABLE config.index_normalizer (
5411 id SERIAL PRIMARY KEY,
5412 name TEXT UNIQUE NOT NULL,
5413 description TEXT UNIQUE NOT NULL,
5415 param_count INT NOT NULL DEFAULT 0
5418 CREATE TABLE config.metabib_field_index_norm_map (
5419 id SERIAL PRIMARY KEY,
5420 field INT NOT NULL REFERENCES config.metabib_field (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
5421 norm INT NOT NULL REFERENCES config.index_normalizer (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
5423 pos INT NOT NULL DEFAULT 0
5426 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5428 'Apply NACO normalization rules to the extracted text. See http://www.loc.gov/catdir/pcc/naco/normrule-2.html for details.',
5433 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5434 'Normalize date range',
5435 'Split date ranges in the form of "XXXX-YYYY" into "XXXX YYYY" for proper index.',
5440 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5441 'NACO Normalize -- retain first comma',
5442 'Apply NACO normalization rules to the extracted text, retaining the first comma. See http://www.loc.gov/catdir/pcc/naco/normrule-2.html for details.',
5443 'naco_normalize_keep_comma',
5447 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5449 'Convert text to NFD form and remove non-spacing combining marks.',
5450 'remove_diacritics',
5454 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5456 'Convert text upper case.',
5461 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5463 'Convert text lower case.',
5468 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5469 'Extract Dewey-like number',
5470 'Extract a string of numeric characters ther resembles a DDC number.',
5471 'call_number_dewey',
5475 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5477 'Discard the specified number of characters from the left side of the string.',
5482 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5484 'Include only the specified number of characters from the left side of the string.',
5489 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
5491 'Include only the first space-separated word of a string.',
5496 INSERT INTO config.metabib_field_index_norm_map (field,norm)
5499 FROM config.metabib_field m,
5500 config.index_normalizer i
5501 WHERE i.func IN ('naco_normalize','split_date_range');
5503 CREATE OR REPLACE FUNCTION oils_tsearch2 () RETURNS TRIGGER AS $$
5511 IF TG_TABLE_NAME::TEXT ~ 'field_entry$' THEN
5513 SELECT n.func AS func,
5514 n.param_count AS param_count,
5516 FROM config.index_normalizer n
5517 JOIN config.metabib_field_index_norm_map m ON (m.norm = n.id)
5518 WHERE field = NEW.field AND m.pos < 0
5520 EXECUTE 'SELECT ' || normalizer.func || '(' ||
5521 quote_literal( value ) ||
5523 WHEN normalizer.param_count > 0
5524 THEN ',' || REPLACE(REPLACE(BTRIM(normalizer.params,'[]'),E'\'',E'\\\''),E'"',E'\'')
5534 IF NEW.index_vector = ''::tsvector THEN
5538 IF TG_TABLE_NAME::TEXT ~ 'field_entry$' THEN
5540 SELECT n.func AS func,
5541 n.param_count AS param_count,
5543 FROM config.index_normalizer n
5544 JOIN config.metabib_field_index_norm_map m ON (m.norm = n.id)
5545 WHERE field = NEW.field AND m.pos >= 0
5547 EXECUTE 'SELECT ' || normalizer.func || '(' ||
5548 quote_literal( value ) ||
5550 WHEN normalizer.param_count > 0
5551 THEN ',' || REPLACE(REPLACE(BTRIM(normalizer.params,'[]'),E'\'',E'\\\''),E'"',E'\'')
5559 IF REGEXP_REPLACE(VERSION(),E'^.+?(\\d+\\.\\d+).*?$',E'\\1')::FLOAT > 8.2 THEN
5560 NEW.index_vector = to_tsvector((TG_ARGV[0])::regconfig, value);
5562 NEW.index_vector = to_tsvector(TG_ARGV[0], value);
5567 $$ LANGUAGE PLPGSQL;
5569 CREATE OR REPLACE FUNCTION oils_xpath ( TEXT, TEXT, ANYARRAY ) RETURNS TEXT[] AS 'SELECT XPATH( $1, $2::XML, $3 )::TEXT[];' LANGUAGE SQL IMMUTABLE;
5571 CREATE OR REPLACE FUNCTION oils_xpath ( TEXT, TEXT ) RETURNS TEXT[] AS 'SELECT XPATH( $1, $2::XML )::TEXT[];' LANGUAGE SQL IMMUTABLE;
5573 CREATE OR REPLACE FUNCTION oils_xpath_string ( TEXT, TEXT, TEXT, ANYARRAY ) RETURNS TEXT AS $func$
5574 SELECT ARRAY_TO_STRING(
5577 CASE WHEN $1 ~ $re$/[^/[]*@[^]]+$$re$ OR $1 ~ $re$text\(\)$$re$ THEN '' ELSE '//text()' END,
5583 $func$ LANGUAGE SQL IMMUTABLE;
5585 CREATE OR REPLACE FUNCTION oils_xpath_string ( TEXT, TEXT, TEXT ) RETURNS TEXT AS $func$
5586 SELECT oils_xpath_string( $1, $2, $3, '{}'::TEXT[] );
5587 $func$ LANGUAGE SQL IMMUTABLE;
5589 CREATE OR REPLACE FUNCTION oils_xpath_string ( TEXT, TEXT, ANYARRAY ) RETURNS TEXT AS $func$
5590 SELECT oils_xpath_string( $1, $2, '', $3 );
5591 $func$ LANGUAGE SQL IMMUTABLE;
5593 CREATE OR REPLACE FUNCTION oils_xpath_string ( TEXT, TEXT ) RETURNS TEXT AS $func$
5594 SELECT oils_xpath_string( $1, $2, '{}'::TEXT[] );
5595 $func$ LANGUAGE SQL IMMUTABLE;
5597 CREATE TYPE metabib.field_entry_template AS (
5604 CREATE OR REPLACE FUNCTION oils_xslt_process(TEXT, TEXT) RETURNS TEXT AS $func$
5613 # The following approach uses the older XML::LibXML 1.69 / XML::LibXSLT 1.68
5614 # methods of parsing XML documents and stylesheets, in the hopes of broader
5615 # compatibility with distributions
5616 my $parser = $_SHARED{'_xslt_process'}{parsers}{xml} || XML::LibXML->new();
5618 # Cache the XML parser, if we do not already have one
5619 $_SHARED{'_xslt_process'}{parsers}{xml} = $parser
5620 unless ($_SHARED{'_xslt_process'}{parsers}{xml});
5622 my $xslt_parser = $_SHARED{'_xslt_process'}{parsers}{xslt} || XML::LibXSLT->new();
5624 # Cache the XSLT processor, if we do not already have one
5625 $_SHARED{'_xslt_process'}{parsers}{xslt} = $xslt_parser
5626 unless ($_SHARED{'_xslt_process'}{parsers}{xslt});
5628 my $stylesheet = $_SHARED{'_xslt_process'}{stylesheets}{$xslt} ||
5629 $xslt_parser->parse_stylesheet( $parser->parse_string($xslt) );
5631 $_SHARED{'_xslt_process'}{stylesheets}{$xslt} = $stylesheet
5632 unless ($_SHARED{'_xslt_process'}{stylesheets}{$xslt});
5634 return $stylesheet->output_string(
5635 $stylesheet->transform(
5636 $parser->parse_string($doc)
5640 $func$ LANGUAGE 'plperlu' STRICT IMMUTABLE;
5642 -- Add two columns so that the following function will compile.
5643 -- Eventually the label column will be NOT NULL, but not yet.
5644 ALTER TABLE config.metabib_field ADD COLUMN label TEXT;
5645 ALTER TABLE config.metabib_field ADD COLUMN facet_xpath TEXT;
5647 CREATE OR REPLACE FUNCTION biblio.extract_metabib_field_entry ( rid BIGINT, default_joiner TEXT ) RETURNS SETOF metabib.field_entry_template AS $func$
5649 bib biblio.record_entry%ROWTYPE;
5650 idx config.metabib_field%ROWTYPE;
5651 xfrm config.xml_transform%ROWTYPE;
5653 transformed_xml TEXT;
5655 xml_node_list TEXT[];
5659 joiner TEXT := default_joiner; -- XXX will index defs supply a joiner?
5660 output_row metabib.field_entry_template%ROWTYPE;
5664 SELECT INTO bib * FROM biblio.record_entry WHERE id = rid;
5666 -- Loop over the indexing entries
5667 FOR idx IN SELECT * FROM config.metabib_field ORDER BY format LOOP
5669 SELECT INTO xfrm * from config.xml_transform WHERE name = idx.format;
5671 -- See if we can skip the XSLT ... it's expensive
5672 IF prev_xfrm IS NULL OR prev_xfrm <> xfrm.name THEN
5673 -- Can't skip the transform
5674 IF xfrm.xslt <> '---' THEN
5675 transformed_xml := oils_xslt_process(bib.marc,xfrm.xslt);
5677 transformed_xml := bib.marc;
5680 prev_xfrm := xfrm.name;
5683 xml_node_list := oils_xpath( idx.xpath, transformed_xml, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
5686 FOR xml_node IN SELECT x FROM explode_array(xml_node_list) AS x LOOP
5687 CONTINUE WHEN xml_node !~ E'^\\s*<';
5689 curr_text := ARRAY_TO_STRING(
5690 oils_xpath( '//text()',
5691 REGEXP_REPLACE( -- This escapes all &s not followed by "amp;". Data ise returned from oils_xpath (above) in UTF-8, not entity encoded
5692 REGEXP_REPLACE( -- This escapes embeded <s
5694 $re$(>[^<]+)(<)([^>]+<)$re$,
5706 CONTINUE WHEN curr_text IS NULL OR curr_text = '';
5708 IF raw_text IS NOT NULL THEN
5709 raw_text := raw_text || joiner;
5712 raw_text := COALESCE(raw_text,'') || curr_text;
5714 -- insert raw node text for faceting
5715 IF idx.facet_field THEN
5717 IF idx.facet_xpath IS NOT NULL AND idx.facet_xpath <> '' THEN
5718 facet_text := oils_xpath_string( idx.facet_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
5720 facet_text := curr_text;
5723 output_row.field_class = idx.field_class;
5724 output_row.field = -1 * idx.id;
5725 output_row.source = rid;
5726 output_row.value = BTRIM(REGEXP_REPLACE(facet_text, E'\\s+', ' ', 'g'));
5728 RETURN NEXT output_row;
5733 CONTINUE WHEN raw_text IS NULL OR raw_text = '';
5735 -- insert combined node text for searching
5736 IF idx.search_field THEN
5737 output_row.field_class = idx.field_class;
5738 output_row.field = idx.id;
5739 output_row.source = rid;
5740 output_row.value = BTRIM(REGEXP_REPLACE(raw_text, E'\\s+', ' ', 'g'));
5742 RETURN NEXT output_row;
5748 $func$ LANGUAGE PLPGSQL;
5750 -- default to a space joiner
5751 CREATE OR REPLACE FUNCTION biblio.extract_metabib_field_entry ( BIGINT ) RETURNS SETOF metabib.field_entry_template AS $func$
5752 SELECT * FROM biblio.extract_metabib_field_entry($1, ' ');
5753 $func$ LANGUAGE SQL;
5755 CREATE OR REPLACE FUNCTION biblio.flatten_marc ( TEXT ) RETURNS SETOF metabib.full_rec AS $func$
5758 use MARC::File::XML (BinaryEncoding => 'UTF-8');
5761 my $r = MARC::Record->new_from_xml( $xml );
5763 return_next( { tag => 'LDR', value => $r->leader } );
5765 for my $f ( $r->fields ) {
5766 if ($f->is_control_field) {
5767 return_next({ tag => $f->tag, value => $f->data });
5769 for my $s ($f->subfields) {
5772 ind1 => $f->indicator(1),
5773 ind2 => $f->indicator(2),
5774 subfield => $s->[0],
5778 if ( $f->tag eq '245' and $s->[0] eq 'a' ) {
5779 my $trim = $f->indicator(2) || 0;
5782 ind1 => $f->indicator(1),
5783 ind2 => $f->indicator(2),
5785 value => substr( $s->[1], $trim )
5794 $func$ LANGUAGE PLPERLU;
5796 CREATE OR REPLACE FUNCTION biblio.flatten_marc ( rid BIGINT ) RETURNS SETOF metabib.full_rec AS $func$
5798 bib biblio.record_entry%ROWTYPE;
5799 output metabib.full_rec%ROWTYPE;
5802 SELECT INTO bib * FROM biblio.record_entry WHERE id = rid;
5804 FOR field IN SELECT * FROM biblio.flatten_marc( bib.marc ) LOOP
5805 output.record := rid;
5806 output.ind1 := field.ind1;
5807 output.ind2 := field.ind2;
5808 output.tag := field.tag;
5809 output.subfield := field.subfield;
5810 IF field.subfield IS NOT NULL AND field.tag NOT IN ('020','022','024') THEN -- exclude standard numbers and control fields
5811 output.value := naco_normalize(field.value, field.subfield);
5813 output.value := field.value;
5816 CONTINUE WHEN output.value IS NULL;
5821 $func$ LANGUAGE PLPGSQL;
5823 ALTER TABLE action.hold_request ADD COLUMN cut_in_line BOOL;
5825 ALTER TABLE action.hold_request
5826 ADD COLUMN mint_condition boolean NOT NULL DEFAULT TRUE;
5828 ALTER TABLE action.hold_request
5829 ADD COLUMN shelf_expire_time TIMESTAMPTZ;
5831 ALTER TABLE action.hold_request DROP CONSTRAINT hold_request_current_copy_fkey;
5833 ALTER TABLE action.hold_request DROP CONSTRAINT hold_request_hold_type_check;
5835 UPDATE config.index_normalizer SET param_count = 0 WHERE func = 'split_date_range';
5837 ALTER TABLE actor.usr ADD COLUMN
5838 claims_never_checked_out_count INT NOT NULL DEFAULT 0;
5840 ALTER TABLE AUDITOR.actor_usr_history ADD COLUMN
5841 claims_never_checked_out_count INT NOT NULL DEFAULT 0;
5843 CREATE OR REPLACE FUNCTION action.circulation_claims_returned () RETURNS TRIGGER AS $$
5845 IF OLD.stop_fines IS NULL OR OLD.stop_fines <> NEW.stop_fines THEN
5846 IF NEW.stop_fines = 'CLAIMSRETURNED' THEN
5847 UPDATE actor.usr SET claims_returned_count = claims_returned_count + 1 WHERE id = NEW.usr;
5849 IF NEW.stop_fines = 'CLAIMSNEVERCHECKEDOUT' THEN
5850 UPDATE actor.usr SET claims_never_checked_out_count = claims_never_checked_out_count + 1 WHERE id = NEW.usr;
5852 IF NEW.stop_fines = 'LOST' THEN
5853 UPDATE asset.copy SET status = 3 WHERE id = NEW.target_copy;
5858 $$ LANGUAGE 'plpgsql';
5860 -- Create new table acq.fund_allocation_percent
5861 -- Populate it from acq.fund_allocation
5862 -- Convert all percentages to amounts in acq.fund_allocation
5864 CREATE TABLE acq.fund_allocation_percent
5866 id SERIAL PRIMARY KEY,
5867 funding_source INT NOT NULL REFERENCES acq.funding_source
5868 DEFERRABLE INITIALLY DEFERRED,
5869 org INT NOT NULL REFERENCES actor.org_unit
5870 DEFERRABLE INITIALLY DEFERRED,
5872 percent NUMERIC NOT NULL,
5873 allocator INTEGER NOT NULL REFERENCES actor.usr
5874 DEFERRABLE INITIALLY DEFERRED,
5876 create_time TIMESTAMPTZ NOT NULL DEFAULT now(),
5877 CONSTRAINT logical_key UNIQUE( funding_source, org, fund_code ),
5878 CONSTRAINT percentage_range CHECK( percent >= 0 AND percent <= 100 )
5881 -- Trigger function to validate combination of org_unit and fund_code
5883 CREATE OR REPLACE FUNCTION acq.fund_alloc_percent_val()
5884 RETURNS TRIGGER AS $$
5899 AND code = NEW.fund_code
5905 RAISE EXCEPTION 'No fund exists for org % and code %', NEW.org, NEW.fund_code;
5908 $$ LANGUAGE plpgsql;
5910 CREATE TRIGGER acq_fund_alloc_percent_val_trig
5911 BEFORE INSERT OR UPDATE ON acq.fund_allocation_percent
5912 FOR EACH ROW EXECUTE PROCEDURE acq.fund_alloc_percent_val();
5914 CREATE OR REPLACE FUNCTION acq.fap_limit_100()
5915 RETURNS TRIGGER AS $$
5918 total_percent numeric;
5926 acq.fund_allocation_percent AS fap
5928 fap.funding_source = NEW.funding_source;
5930 IF total_percent > 100 THEN
5931 RAISE EXCEPTION 'Total percentages exceed 100 for funding_source %',
5937 $$ LANGUAGE plpgsql;
5939 CREATE TRIGGER acqfap_limit_100_trig
5940 AFTER INSERT OR UPDATE ON acq.fund_allocation_percent
5941 FOR EACH ROW EXECUTE PROCEDURE acq.fap_limit_100();
5943 -- Populate new table from acq.fund_allocation
5945 INSERT INTO acq.fund_allocation_percent
5964 acq.fund_allocation AS fa
5965 INNER JOIN acq.fund AS fund
5966 ON ( fa.fund = fund.id )
5968 fa.percent is not null
5972 -- Temporary function to convert percentages to amounts in acq.fund_allocation
5974 -- Algorithm to apply to each funding source:
5976 -- 1. Add up the credits.
5977 -- 2. Add up the percentages.
5978 -- 3. Multiply the sum of the percentages times the sum of the credits. Drop any
5979 -- fractional cents from the result. This is the total amount to be allocated.
5980 -- 4. For each allocation: multiply the percentage by the total allocation. Drop any
5981 -- fractional cents to get a preliminary amount.
5982 -- 5. Add up the preliminary amounts for all the allocations.
5983 -- 6. Subtract the results of step 5 from the result of step 3. The difference is the
5984 -- number of residual cents (resulting from having dropped fractional cents) that
5985 -- must be distributed across the funds in order to make the total of the amounts
5986 -- match the total allocation.
5987 -- 7. Make a second pass through the allocations, in decreasing order of the fractional
5988 -- cents that were dropped from their amounts in step 4. Add one cent to the amount
5989 -- for each successive fund, until all the residual cents have been exhausted.
5991 -- Result: the sum of the individual allocations now equals the total to be allocated,
5992 -- to the penny. The individual amounts match the percentages as closely as possible,
5993 -- given the constraint that the total must match.
5995 CREATE OR REPLACE FUNCTION acq.apply_percents()
6006 curr_amount NUMERIC;
6008 total_of_floors INTEGER;
6009 total_percent NUMERIC;
6010 total_allocation INTEGER;
6014 RAISE NOTICE 'Applying percents';
6017 fsrc.funding_source,
6018 sum( fsrc.amount ) AS total
6020 acq.funding_source_credit AS fsrc
6021 WHERE fsrc.funding_source IN
6022 ( SELECT DISTINCT fa.funding_source
6023 FROM acq.fund_allocation AS fa
6024 WHERE fa.percent IS NOT NULL )
6028 tot_cents = floor( tot.total * 100 );
6029 src = tot.funding_source;
6030 RAISE NOTICE 'Funding source % total %',
6033 total_of_floors := 0;
6040 floor( fa.percent * tot_cents / 100 ) as floor_pennies
6042 acq.fund_allocation AS fa
6044 fa.funding_source = src
6045 AND fa.percent IS NOT NULL
6047 mod( fa.percent * tot_cents / 100, 1 ),
6051 RAISE NOTICE ' %: %',
6056 pennies[i] = fund.floor_pennies;
6057 total_percent := total_percent + fund.percent;
6058 total_of_floors := total_of_floors + pennies[i];
6060 total_allocation := floor( total_percent * tot_cents /100 );
6061 RAISE NOTICE 'Total before distributing residue: %', total_of_floors;
6062 residue := total_allocation - total_of_floors;
6063 RAISE NOTICE 'Residue: %', residue;
6065 -- Post the calculated amounts, revising as needed to
6066 -- distribute the rounding error
6070 pennies[i] = pennies[i] + 1;
6071 residue := residue - 1;
6077 curr_amount := trunc( pennies[i] / 100, 2 );
6080 acq.fund_allocation AS fa
6082 amount = curr_amount,
6087 RAISE NOTICE ' ID % and amount %',
6094 $$ LANGUAGE 'plpgsql';
6096 -- Run the temporary function
6098 select * from acq.apply_percents();
6100 -- Drop the temporary function now that we're done with it
6102 DROP FUNCTION IF EXISTS acq.apply_percents();
6104 -- Eliminate acq.fund_allocation.percent, which has been moved to the acq.fund_allocation_percent table.
6106 -- If the following step fails, it's probably because there are still some non-null percent values in
6107 -- acq.fund_allocation. They should have all been converted to amounts, and then set to null, by a
6108 -- previous upgrade step based on 0049.schema.acq_funding_allocation_percent.sql. If there are any
6109 -- non-null values, then either that step didn't run, or it didn't work, or some non-null values
6110 -- slipped in afterwards.
6112 -- To convert any remaining percents to amounts: create, run, and then drop the temporary stored
6113 -- procedure acq.apply_percents() as defined above.
6115 ALTER TABLE acq.fund_allocation
6116 ALTER COLUMN amount SET NOT NULL;
6118 CREATE OR REPLACE VIEW acq.fund_allocation_total AS
6120 SUM(a.amount * acq.exchange_ratio(s.currency_type, f.currency_type))::NUMERIC(100,2) AS amount
6121 FROM acq.fund_allocation a
6122 JOIN acq.fund f ON (a.fund = f.id)
6123 JOIN acq.funding_source s ON (a.funding_source = s.id)
6126 CREATE OR REPLACE VIEW acq.funding_source_allocation_total AS
6127 SELECT funding_source,
6128 SUM(a.amount)::NUMERIC(100,2) AS amount
6129 FROM acq.fund_allocation a
6132 ALTER TABLE acq.fund_allocation
6133 DROP COLUMN percent;
6135 CREATE TABLE asset.copy_location_order
6137 id SERIAL PRIMARY KEY,
6138 location INT NOT NULL
6139 REFERENCES asset.copy_location
6141 DEFERRABLE INITIALLY DEFERRED,
6143 REFERENCES actor.org_unit
6145 DEFERRABLE INITIALLY DEFERRED,
6146 position INT NOT NULL DEFAULT 0,
6147 CONSTRAINT acplo_once_per_org UNIQUE ( location, org )
6150 ALTER TABLE money.credit_card_payment ADD COLUMN cc_processor TEXT;
6152 -- If you ran this before its most recent incarnation:
6153 -- delete from config.upgrade_log where version = '0328';
6154 -- alter table money.credit_card_payment drop column cc_name;
6156 ALTER TABLE money.credit_card_payment ADD COLUMN cc_first_name TEXT;
6157 ALTER TABLE money.credit_card_payment ADD COLUMN cc_last_name TEXT;
6159 CREATE OR REPLACE FUNCTION action.find_circ_matrix_matchpoint( context_ou INT, match_item BIGINT, match_user INT, renewal BOOL ) RETURNS config.circ_matrix_matchpoint AS $func$
6161 current_group permission.grp_tree%ROWTYPE;
6162 user_object actor.usr%ROWTYPE;
6163 item_object asset.copy%ROWTYPE;
6164 cn_object asset.call_number%ROWTYPE;
6165 rec_descriptor metabib.rec_descriptor%ROWTYPE;
6166 current_mp config.circ_matrix_matchpoint%ROWTYPE;
6167 matchpoint config.circ_matrix_matchpoint%ROWTYPE;
6169 SELECT INTO user_object * FROM actor.usr WHERE id = match_user;
6170 SELECT INTO item_object * FROM asset.copy WHERE id = match_item;
6171 SELECT INTO cn_object * FROM asset.call_number WHERE id = item_object.call_number;
6172 SELECT INTO rec_descriptor r.* FROM metabib.rec_descriptor r JOIN asset.call_number c USING (record) WHERE c.id = item_object.call_number;
6173 SELECT INTO current_group * FROM permission.grp_tree WHERE id = user_object.profile;
6176 -- for each potential matchpoint for this ou and group ...
6179 FROM config.circ_matrix_matchpoint m
6180 JOIN actor.org_unit_ancestors( context_ou ) d ON (m.org_unit = d.id)
6181 LEFT JOIN actor.org_unit_proximity p ON (p.from_org = context_ou AND p.to_org = d.id)
6182 WHERE m.grp = current_group.id
6184 AND (m.copy_owning_lib IS NULL OR cn_object.owning_lib IN ( SELECT id FROM actor.org_unit_descendants(m.copy_owning_lib) ))
6185 AND (m.copy_circ_lib IS NULL OR item_object.circ_lib IN ( SELECT id FROM actor.org_unit_descendants(m.copy_circ_lib) ))
6186 ORDER BY CASE WHEN p.prox IS NULL THEN 999 ELSE p.prox END,
6187 CASE WHEN m.copy_owning_lib IS NOT NULL
6188 THEN 256 / ( SELECT COALESCE(prox, 255) + 1 FROM actor.org_unit_proximity WHERE to_org = cn_object.owning_lib AND from_org = m.copy_owning_lib LIMIT 1 )
6191 CASE WHEN m.copy_circ_lib IS NOT NULL
6192 THEN 256 / ( SELECT COALESCE(prox, 255) + 1 FROM actor.org_unit_proximity WHERE to_org = item_object.circ_lib AND from_org = m.copy_circ_lib LIMIT 1 )
6195 CASE WHEN m.is_renewal = renewal THEN 128 ELSE 0 END +
6196 CASE WHEN m.juvenile_flag IS NOT NULL THEN 64 ELSE 0 END +
6197 CASE WHEN m.circ_modifier IS NOT NULL THEN 32 ELSE 0 END +
6198 CASE WHEN m.marc_type IS NOT NULL THEN 16 ELSE 0 END +
6199 CASE WHEN m.marc_form IS NOT NULL THEN 8 ELSE 0 END +
6200 CASE WHEN m.marc_vr_format IS NOT NULL THEN 4 ELSE 0 END +
6201 CASE WHEN m.ref_flag IS NOT NULL THEN 2 ELSE 0 END +
6202 CASE WHEN m.usr_age_lower_bound IS NOT NULL THEN 0.5 ELSE 0 END +
6203 CASE WHEN m.usr_age_upper_bound IS NOT NULL THEN 0.5 ELSE 0 END DESC LOOP
6205 IF current_mp.circ_modifier IS NOT NULL THEN
6206 CONTINUE WHEN current_mp.circ_modifier <> item_object.circ_modifier OR item_object.circ_modifier IS NULL;
6209 IF current_mp.marc_type IS NOT NULL THEN
6210 IF item_object.circ_as_type IS NOT NULL THEN
6211 CONTINUE WHEN current_mp.marc_type <> item_object.circ_as_type;
6213 CONTINUE WHEN current_mp.marc_type <> rec_descriptor.item_type;
6217 IF current_mp.marc_form IS NOT NULL THEN
6218 CONTINUE WHEN current_mp.marc_form <> rec_descriptor.item_form;
6221 IF current_mp.marc_vr_format IS NOT NULL THEN
6222 CONTINUE WHEN current_mp.marc_vr_format <> rec_descriptor.vr_format;
6225 IF current_mp.ref_flag IS NOT NULL THEN
6226 CONTINUE WHEN current_mp.ref_flag <> item_object.ref;
6229 IF current_mp.juvenile_flag IS NOT NULL THEN
6230 CONTINUE WHEN current_mp.juvenile_flag <> user_object.juvenile;
6233 IF current_mp.usr_age_lower_bound IS NOT NULL THEN
6234 CONTINUE WHEN user_object.dob IS NULL OR current_mp.usr_age_lower_bound < age(user_object.dob);
6237 IF current_mp.usr_age_upper_bound IS NOT NULL THEN
6238 CONTINUE WHEN user_object.dob IS NULL OR current_mp.usr_age_upper_bound > age(user_object.dob);
6242 -- everything was undefined or matched
6243 matchpoint = current_mp;
6245 EXIT WHEN matchpoint.id IS NOT NULL;
6248 EXIT WHEN current_group.parent IS NULL OR matchpoint.id IS NOT NULL;
6250 SELECT INTO current_group * FROM permission.grp_tree WHERE id = current_group.parent;
6255 $func$ LANGUAGE plpgsql;
6257 CREATE TYPE action.hold_stats AS (
6260 available_count INT,
6261 total_copy_ratio FLOAT,
6262 available_copy_ratio FLOAT
6265 CREATE OR REPLACE FUNCTION action.copy_related_hold_stats (copy_id INT) RETURNS action.hold_stats AS $func$
6267 output action.hold_stats%ROWTYPE;
6268 hold_count INT := 0;
6269 copy_count INT := 0;
6270 available_count INT := 0;
6271 hold_map_data RECORD;
6274 output.hold_count := 0;
6275 output.copy_count := 0;
6276 output.available_count := 0;
6278 SELECT COUNT( DISTINCT m.hold ) INTO hold_count
6279 FROM action.hold_copy_map m
6280 JOIN action.hold_request h ON (m.hold = h.id)
6281 WHERE m.target_copy = copy_id
6284 output.hold_count := hold_count;
6286 IF output.hold_count > 0 THEN
6287 FOR hold_map_data IN
6288 SELECT DISTINCT m.target_copy,
6290 FROM action.hold_copy_map m
6291 JOIN asset.copy acp ON (m.target_copy = acp.id)
6292 JOIN action.hold_request h ON (m.hold = h.id)
6293 WHERE m.hold IN ( SELECT DISTINCT hold FROM action.hold_copy_map WHERE target_copy = copy_id ) AND NOT h.frozen
6295 output.copy_count := output.copy_count + 1;
6296 IF hold_map_data.status IN (0,7,12) THEN
6297 output.available_count := output.available_count + 1;
6300 output.total_copy_ratio = output.copy_count::FLOAT / output.hold_count::FLOAT;
6301 output.available_copy_ratio = output.available_count::FLOAT / output.hold_count::FLOAT;
6308 $func$ LANGUAGE PLPGSQL;
6310 ALTER TABLE config.circ_matrix_matchpoint ADD COLUMN total_copy_hold_ratio FLOAT;
6311 ALTER TABLE config.circ_matrix_matchpoint ADD COLUMN available_copy_hold_ratio FLOAT;
6313 ALTER TABLE config.circ_matrix_matchpoint DROP CONSTRAINT ep_once_per_grp_loc_mod_marc;
6315 ALTER TABLE config.circ_matrix_matchpoint ADD COLUMN copy_circ_lib INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED;
6316 ALTER TABLE config.circ_matrix_matchpoint ADD COLUMN copy_owning_lib INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED;
6318 ALTER TABLE config.circ_matrix_matchpoint ADD CONSTRAINT ep_once_per_grp_loc_mod_marc UNIQUE (
6319 grp, org_unit, circ_modifier, marc_type, marc_form, marc_vr_format, ref_flag,
6320 juvenile_flag, usr_age_lower_bound, usr_age_upper_bound, is_renewal, copy_circ_lib,
6324 -- Return the correct fail_part when the item can't be found
6325 CREATE OR REPLACE FUNCTION action.item_user_circ_test( circ_ou INT, match_item BIGINT, match_user INT, renewal BOOL ) RETURNS SETOF action.matrix_test_result AS $func$
6327 user_object actor.usr%ROWTYPE;
6328 standing_penalty config.standing_penalty%ROWTYPE;
6329 item_object asset.copy%ROWTYPE;
6330 item_status_object config.copy_status%ROWTYPE;
6331 item_location_object asset.copy_location%ROWTYPE;
6332 result action.matrix_test_result;
6333 circ_test config.circ_matrix_matchpoint%ROWTYPE;
6334 out_by_circ_mod config.circ_matrix_circ_mod_test%ROWTYPE;
6335 circ_mod_map config.circ_matrix_circ_mod_test_map%ROWTYPE;
6336 hold_ratio action.hold_stats%ROWTYPE;
6340 context_org_list INT[];
6343 result.success := TRUE;
6345 -- Fail if the user is BARRED
6346 SELECT INTO user_object * FROM actor.usr WHERE id = match_user;
6348 -- Fail if we couldn't find the user
6349 IF user_object.id IS NULL THEN
6350 result.fail_part := 'no_user';
6351 result.success := FALSE;
6357 SELECT INTO item_object * FROM asset.copy WHERE id = match_item;
6359 -- Fail if we couldn't find the item
6360 IF item_object.id IS NULL THEN
6361 result.fail_part := 'no_item';
6362 result.success := FALSE;
6368 SELECT INTO circ_test * FROM action.find_circ_matrix_matchpoint(circ_ou, match_item, match_user, renewal);
6369 result.matchpoint := circ_test.id;
6371 -- Fail if we couldn't find a matchpoint
6372 IF result.matchpoint IS NULL THEN
6373 result.fail_part := 'no_matchpoint';
6374 result.success := FALSE;
6379 IF user_object.barred IS TRUE THEN
6380 result.fail_part := 'actor.usr.barred';
6381 result.success := FALSE;
6386 -- Fail if the item can't circulate
6387 IF item_object.circulate IS FALSE THEN
6388 result.fail_part := 'asset.copy.circulate';
6389 result.success := FALSE;
6394 -- Fail if the item isn't in a circulateable status on a non-renewal
6395 IF NOT renewal AND item_object.status NOT IN ( 0, 7, 8 ) THEN
6396 result.fail_part := 'asset.copy.status';
6397 result.success := FALSE;
6400 ELSIF renewal AND item_object.status <> 1 THEN
6401 result.fail_part := 'asset.copy.status';
6402 result.success := FALSE;
6407 -- Fail if the item can't circulate because of the shelving location
6408 SELECT INTO item_location_object * FROM asset.copy_location WHERE id = item_object.location;
6409 IF item_location_object.circulate IS FALSE THEN
6410 result.fail_part := 'asset.copy_location.circulate';
6411 result.success := FALSE;
6416 SELECT INTO context_org_list ARRAY_ACCUM(id) FROM actor.org_unit_full_path( circ_test.org_unit );
6418 -- Fail if the test is set to hard non-circulating
6419 IF circ_test.circulate IS FALSE THEN
6420 result.fail_part := 'config.circ_matrix_test.circulate';
6421 result.success := FALSE;
6426 -- Fail if the total copy-hold ratio is too low
6427 IF circ_test.total_copy_hold_ratio IS NOT NULL THEN
6428 SELECT INTO hold_ratio * FROM action.copy_related_hold_stats(match_item);
6429 IF hold_ratio.total_copy_ratio IS NOT NULL AND hold_ratio.total_copy_ratio < circ_test.total_copy_hold_ratio THEN
6430 result.fail_part := 'config.circ_matrix_test.total_copy_hold_ratio';
6431 result.success := FALSE;
6437 -- Fail if the available copy-hold ratio is too low
6438 IF circ_test.available_copy_hold_ratio IS NOT NULL THEN
6439 SELECT INTO hold_ratio * FROM action.copy_related_hold_stats(match_item);
6440 IF hold_ratio.available_copy_ratio IS NOT NULL AND hold_ratio.available_copy_ratio < circ_test.available_copy_hold_ratio THEN
6441 result.fail_part := 'config.circ_matrix_test.available_copy_hold_ratio';
6442 result.success := FALSE;
6449 penalty_type = '%RENEW%';
6451 penalty_type = '%CIRC%';
6454 FOR standing_penalty IN
6455 SELECT DISTINCT csp.*
6456 FROM actor.usr_standing_penalty usp
6457 JOIN config.standing_penalty csp ON (csp.id = usp.standing_penalty)
6458 WHERE usr = match_user
6459 AND usp.org_unit IN ( SELECT * FROM explode_array(context_org_list) )
6460 AND (usp.stop_date IS NULL or usp.stop_date > NOW())
6461 AND csp.block_list LIKE penalty_type LOOP
6463 result.fail_part := standing_penalty.name;
6464 result.success := FALSE;
6469 -- Fail if the user has too many items with specific circ_modifiers checked out
6470 FOR out_by_circ_mod IN SELECT * FROM config.circ_matrix_circ_mod_test WHERE matchpoint = circ_test.id LOOP
6471 SELECT INTO items_out COUNT(*)
6472 FROM action.circulation circ
6473 JOIN asset.copy cp ON (cp.id = circ.target_copy)
6474 WHERE circ.usr = match_user
6475 AND circ.circ_lib IN ( SELECT * FROM explode_array(context_org_list) )
6476 AND circ.checkin_time IS NULL
6477 AND (circ.stop_fines IN ('MAXFINES','LONGOVERDUE') OR circ.stop_fines IS NULL)
6478 AND cp.circ_modifier IN (SELECT circ_mod FROM config.circ_matrix_circ_mod_test_map WHERE circ_mod_test = out_by_circ_mod.id);
6479 IF items_out >= out_by_circ_mod.items_out THEN
6480 result.fail_part := 'config.circ_matrix_circ_mod_test';
6481 result.success := FALSE;
6487 -- If we passed everything, return the successful matchpoint id
6494 $func$ LANGUAGE plpgsql;
6496 CREATE TABLE config.remote_account (
6497 id SERIAL PRIMARY KEY,
6498 label TEXT NOT NULL,
6499 host TEXT NOT NULL, -- name or IP, :port optional
6500 username TEXT, -- optional, since we could default to $USER
6501 password TEXT, -- optional, since we could use SSH keys, or anonymous login.
6502 account TEXT, -- aka profile or FTP "account" command
6503 path TEXT, -- aka directory
6504 owner INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
6505 last_activity TIMESTAMP WITH TIME ZONE
6508 CREATE TABLE acq.edi_account ( -- similar tables can extend remote_account for other parts of EG
6509 provider INT NOT NULL REFERENCES acq.provider (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
6510 in_dir TEXT, -- incoming messages dir (probably different than config.remote_account.path, the outgoing dir)
6514 ) INHERITS (config.remote_account);
6516 ALTER TABLE acq.edi_account ADD PRIMARY KEY (id);
6518 CREATE TABLE acq.claim_type (
6519 id SERIAL PRIMARY KEY,
6520 org_unit INT NOT NULL REFERENCES actor.org_unit(id)
6521 DEFERRABLE INITIALLY DEFERRED,
6523 description TEXT NOT NULL,
6524 CONSTRAINT claim_type_once_per_org UNIQUE ( org_unit, code )
6527 CREATE TABLE acq.claim (
6528 id SERIAL PRIMARY KEY,
6529 type INT NOT NULL REFERENCES acq.claim_type
6530 DEFERRABLE INITIALLY DEFERRED,
6531 lineitem_detail BIGINT NOT NULL REFERENCES acq.lineitem_detail
6532 DEFERRABLE INITIALLY DEFERRED
6535 CREATE TABLE acq.claim_policy (
6536 id SERIAL PRIMARY KEY,
6537 org_unit INT NOT NULL REFERENCES actor.org_unit
6538 DEFERRABLE INITIALLY DEFERRED,
6540 description TEXT NOT NULL,
6541 CONSTRAINT name_once_per_org UNIQUE (org_unit, name)
6544 -- Add a san column for EDI.
6545 -- See: http://isbn.org/standards/home/isbn/us/san/san-qa.asp
6547 ALTER TABLE acq.provider ADD COLUMN san INT;
6549 ALTER TABLE acq.provider ALTER COLUMN san TYPE TEXT USING lpad(text(san), 7, '0');
6551 -- null edi_default is OK... it has to be, since we have no values in acq.edi_account yet
6552 ALTER TABLE acq.provider ADD COLUMN edi_default INT REFERENCES acq.edi_account (id) DEFERRABLE INITIALLY DEFERRED;
6554 ALTER TABLE acq.provider
6555 ADD COLUMN active BOOL NOT NULL DEFAULT TRUE;
6557 ALTER TABLE acq.provider
6558 ADD COLUMN prepayment_required BOOLEAN NOT NULL DEFAULT FALSE;
6560 ALTER TABLE acq.provider
6561 ADD COLUMN url TEXT;
6563 ALTER TABLE acq.provider
6564 ADD COLUMN email TEXT;
6566 ALTER TABLE acq.provider
6567 ADD COLUMN phone TEXT;
6569 ALTER TABLE acq.provider
6570 ADD COLUMN fax_phone TEXT;
6572 ALTER TABLE acq.provider
6573 ADD COLUMN default_claim_policy INT
6574 REFERENCES acq.claim_policy
6575 DEFERRABLE INITIALLY DEFERRED;
6577 ALTER TABLE action.transit_copy
6578 ADD COLUMN prev_dest INTEGER REFERENCES actor.org_unit( id )
6579 DEFERRABLE INITIALLY DEFERRED;
6581 DROP SCHEMA IF EXISTS booking CASCADE;
6583 CREATE SCHEMA booking;
6585 CREATE TABLE booking.resource_type (
6586 id SERIAL PRIMARY KEY,
6588 fine_interval INTERVAL,
6589 fine_amount DECIMAL(8,2) NOT NULL DEFAULT 0,
6591 REFERENCES actor.org_unit( id )
6592 DEFERRABLE INITIALLY DEFERRED,
6593 catalog_item BOOLEAN NOT NULL DEFAULT FALSE,
6594 transferable BOOLEAN NOT NULL DEFAULT FALSE,
6595 record BIGINT REFERENCES biblio.record_entry (id)
6596 DEFERRABLE INITIALLY DEFERRED,
6597 max_fine NUMERIC(8,2),
6598 elbow_room INTERVAL,
6599 CONSTRAINT brt_name_or_record_once_per_owner UNIQUE(owner, name, record)
6602 CREATE TABLE booking.resource (
6603 id SERIAL PRIMARY KEY,
6605 REFERENCES actor.org_unit(id)
6606 DEFERRABLE INITIALLY DEFERRED,
6608 REFERENCES booking.resource_type(id)
6609 DEFERRABLE INITIALLY DEFERRED,
6610 overbook BOOLEAN NOT NULL DEFAULT FALSE,
6611 barcode TEXT NOT NULL,
6612 deposit BOOLEAN NOT NULL DEFAULT FALSE,
6613 deposit_amount DECIMAL(8,2) NOT NULL DEFAULT 0.00,
6614 user_fee DECIMAL(8,2) NOT NULL DEFAULT 0.00,
6615 CONSTRAINT br_unique UNIQUE (owner, barcode)
6618 -- For non-catalog items: hijack barcode for name/description
6620 CREATE TABLE booking.resource_attr (
6621 id SERIAL PRIMARY KEY,
6623 REFERENCES actor.org_unit(id)
6624 DEFERRABLE INITIALLY DEFERRED,
6626 resource_type INT NOT NULL
6627 REFERENCES booking.resource_type(id)
6629 DEFERRABLE INITIALLY DEFERRED,
6630 required BOOLEAN NOT NULL DEFAULT FALSE,
6631 CONSTRAINT bra_name_once_per_type UNIQUE(resource_type, name)
6634 CREATE TABLE booking.resource_attr_value (
6635 id SERIAL PRIMARY KEY,
6637 REFERENCES actor.org_unit(id)
6638 DEFERRABLE INITIALLY DEFERRED,
6640 REFERENCES booking.resource_attr(id)
6641 DEFERRABLE INITIALLY DEFERRED,
6642 valid_value TEXT NOT NULL,
6643 CONSTRAINT brav_logical_key UNIQUE(owner, attr, valid_value)
6646 CREATE TABLE booking.resource_attr_map (
6647 id SERIAL PRIMARY KEY,
6648 resource INT NOT NULL
6649 REFERENCES booking.resource(id)
6651 DEFERRABLE INITIALLY DEFERRED,
6652 resource_attr INT NOT NULL
6653 REFERENCES booking.resource_attr(id)
6655 DEFERRABLE INITIALLY DEFERRED,
6657 REFERENCES booking.resource_attr_value(id)
6658 DEFERRABLE INITIALLY DEFERRED,
6659 CONSTRAINT bram_one_value_per_attr UNIQUE(resource, resource_attr)
6662 CREATE TABLE booking.reservation (
6663 request_time TIMESTAMPTZ NOT NULL DEFAULT now(),
6664 start_time TIMESTAMPTZ,
6665 end_time TIMESTAMPTZ,
6666 capture_time TIMESTAMPTZ,
6667 cancel_time TIMESTAMPTZ,
6668 pickup_time TIMESTAMPTZ,
6669 return_time TIMESTAMPTZ,
6670 booking_interval INTERVAL,
6671 fine_interval INTERVAL,
6672 fine_amount DECIMAL(8,2),
6673 target_resource_type INT NOT NULL
6674 REFERENCES booking.resource_type(id)
6676 DEFERRABLE INITIALLY DEFERRED,
6677 target_resource INT REFERENCES booking.resource(id)
6679 DEFERRABLE INITIALLY DEFERRED,
6680 current_resource INT REFERENCES booking.resource(id)
6682 DEFERRABLE INITIALLY DEFERRED,
6683 request_lib INT NOT NULL
6684 REFERENCES actor.org_unit(id)
6685 DEFERRABLE INITIALLY DEFERRED,
6686 pickup_lib INT REFERENCES actor.org_unit(id)
6687 DEFERRABLE INITIALLY DEFERRED,
6688 capture_staff INT REFERENCES actor.usr(id)
6689 DEFERRABLE INITIALLY DEFERRED,
6690 max_fine NUMERIC(8,2)
6691 ) INHERITS (money.billable_xact);
6693 ALTER TABLE booking.reservation ADD PRIMARY KEY (id);
6695 ALTER TABLE booking.reservation
6696 ADD CONSTRAINT booking_reservation_usr_fkey
6697 FOREIGN KEY (usr) REFERENCES actor.usr (id)
6698 DEFERRABLE INITIALLY DEFERRED;
6700 CREATE TABLE booking.reservation_attr_value_map (
6701 id SERIAL PRIMARY KEY,
6702 reservation INT NOT NULL
6703 REFERENCES booking.reservation(id)
6705 DEFERRABLE INITIALLY DEFERRED,
6706 attr_value INT NOT NULL
6707 REFERENCES booking.resource_attr_value(id)
6709 DEFERRABLE INITIALLY DEFERRED,
6710 CONSTRAINT bravm_logical_key UNIQUE(reservation, attr_value)
6713 CREATE FUNCTION auditor.create_auditor_seq ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
6716 CREATE SEQUENCE auditor.$$ || sch || $$_$$ || tbl || $$_pkey_seq;
6720 $creator$ LANGUAGE 'plpgsql';
6722 CREATE FUNCTION auditor.create_auditor_history ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
6725 CREATE TABLE auditor.$$ || sch || $$_$$ || tbl || $$_history (
6726 audit_id BIGINT PRIMARY KEY,
6727 audit_time TIMESTAMP WITH TIME ZONE NOT NULL,
6728 audit_action TEXT NOT NULL,
6729 LIKE $$ || sch || $$.$$ || tbl || $$
6734 $creator$ LANGUAGE 'plpgsql';
6736 CREATE FUNCTION auditor.create_auditor_func ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
6739 CREATE FUNCTION auditor.audit_$$ || sch || $$_$$ || tbl || $$_func ()
6740 RETURNS TRIGGER AS $func$
6742 INSERT INTO auditor.$$ || sch || $$_$$ || tbl || $$_history
6743 SELECT nextval('auditor.$$ || sch || $$_$$ || tbl || $$_pkey_seq'),
6749 $func$ LANGUAGE 'plpgsql';
6753 $creator$ LANGUAGE 'plpgsql';
6755 CREATE FUNCTION auditor.create_auditor_update_trigger ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
6758 CREATE TRIGGER audit_$$ || sch || $$_$$ || tbl || $$_update_trigger
6759 AFTER UPDATE OR DELETE ON $$ || sch || $$.$$ || tbl || $$ FOR EACH ROW
6760 EXECUTE PROCEDURE auditor.audit_$$ || sch || $$_$$ || tbl || $$_func ();
6764 $creator$ LANGUAGE 'plpgsql';
6766 CREATE FUNCTION auditor.create_auditor_lifecycle ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
6769 CREATE VIEW auditor.$$ || sch || $$_$$ || tbl || $$_lifecycle AS
6770 SELECT -1, now() as audit_time, '-' as audit_action, *
6771 FROM $$ || sch || $$.$$ || tbl || $$
6774 FROM auditor.$$ || sch || $$_$$ || tbl || $$_history;
6778 $creator$ LANGUAGE 'plpgsql';
6780 DROP FUNCTION IF EXISTS auditor.create_auditor (TEXT, TEXT);
6784 CREATE FUNCTION auditor.create_auditor ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
6786 PERFORM auditor.create_auditor_seq(sch, tbl);
6787 PERFORM auditor.create_auditor_history(sch, tbl);
6788 PERFORM auditor.create_auditor_func(sch, tbl);
6789 PERFORM auditor.create_auditor_update_trigger(sch, tbl);
6790 PERFORM auditor.create_auditor_lifecycle(sch, tbl);
6793 $creator$ LANGUAGE 'plpgsql';
6795 -- represents a circ chain summary
6796 CREATE TYPE action.circ_chain_summary AS (
6798 start_time TIMESTAMP WITH TIME ZONE,
6799 checkout_workstation TEXT,
6800 last_renewal_time TIMESTAMP WITH TIME ZONE, -- NULL if no renewals
6801 last_stop_fines TEXT,
6802 last_stop_fines_time TIMESTAMP WITH TIME ZONE,
6803 last_renewal_workstation TEXT, -- NULL if no renewals
6804 last_checkin_workstation TEXT,
6805 last_checkin_time TIMESTAMP WITH TIME ZONE,
6806 last_checkin_scan_time TIMESTAMP WITH TIME ZONE
6809 CREATE OR REPLACE FUNCTION action.circ_chain ( ctx_circ_id INTEGER ) RETURNS SETOF action.circulation AS $$
6811 tmp_circ action.circulation%ROWTYPE;
6812 circ_0 action.circulation%ROWTYPE;
6815 SELECT INTO tmp_circ * FROM action.circulation WHERE id = ctx_circ_id;
6817 IF tmp_circ IS NULL THEN
6818 RETURN NEXT tmp_circ;
6822 -- find the front of the chain
6824 SELECT INTO tmp_circ * FROM action.circulation WHERE id = tmp_circ.parent_circ;
6825 IF tmp_circ IS NULL THEN
6831 -- now send the circs to the caller, oldest to newest
6834 IF tmp_circ IS NULL THEN
6837 RETURN NEXT tmp_circ;
6838 SELECT INTO tmp_circ * FROM action.circulation WHERE parent_circ = tmp_circ.id;
6842 $$ LANGUAGE 'plpgsql';
6844 CREATE OR REPLACE FUNCTION action.summarize_circ_chain ( ctx_circ_id INTEGER ) RETURNS action.circ_chain_summary AS $$
6848 -- first circ in the chain
6849 circ_0 action.circulation%ROWTYPE;
6851 -- last circ in the chain
6852 circ_n action.circulation%ROWTYPE;
6854 -- circ chain under construction
6855 chain action.circ_chain_summary;
6856 tmp_circ action.circulation%ROWTYPE;
6860 chain.num_circs := 0;
6861 FOR tmp_circ IN SELECT * FROM action.circ_chain(ctx_circ_id) LOOP
6863 IF chain.num_circs = 0 THEN
6867 chain.num_circs := chain.num_circs + 1;
6871 chain.start_time := circ_0.xact_start;
6872 chain.last_stop_fines := circ_n.stop_fines;
6873 chain.last_stop_fines_time := circ_n.stop_fines_time;
6874 chain.last_checkin_time := circ_n.checkin_time;
6875 chain.last_checkin_scan_time := circ_n.checkin_scan_time;
6876 SELECT INTO chain.checkout_workstation name FROM actor.workstation WHERE id = circ_0.workstation;
6877 SELECT INTO chain.last_checkin_workstation name FROM actor.workstation WHERE id = circ_n.checkin_workstation;
6879 IF chain.num_circs > 1 THEN
6880 chain.last_renewal_time := circ_n.xact_start;
6881 SELECT INTO chain.last_renewal_workstation name FROM actor.workstation WHERE id = circ_n.workstation;
6887 $$ LANGUAGE 'plpgsql';
6889 CREATE TRIGGER mat_summary_create_tgr AFTER INSERT ON booking.reservation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_create ('reservation');
6890 CREATE TRIGGER mat_summary_change_tgr AFTER UPDATE ON booking.reservation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_update ();
6891 CREATE TRIGGER mat_summary_remove_tgr AFTER DELETE ON booking.reservation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_delete ();
6893 ALTER TABLE config.standing_penalty
6894 ADD COLUMN org_depth INTEGER;
6896 CREATE OR REPLACE FUNCTION actor.calculate_system_penalties( match_user INT, context_org INT ) RETURNS SETOF actor.usr_standing_penalty AS $func$
6898 user_object actor.usr%ROWTYPE;
6899 new_sp_row actor.usr_standing_penalty%ROWTYPE;
6900 existing_sp_row actor.usr_standing_penalty%ROWTYPE;
6901 collections_fines permission.grp_penalty_threshold%ROWTYPE;
6902 max_fines permission.grp_penalty_threshold%ROWTYPE;
6903 max_overdue permission.grp_penalty_threshold%ROWTYPE;
6904 max_items_out permission.grp_penalty_threshold%ROWTYPE;
6908 context_org_list INT[];
6909 current_fines NUMERIC(8,2) := 0.0;
6910 tmp_fines NUMERIC(8,2);
6913 tmp_org actor.org_unit%ROWTYPE;
6914 tmp_penalty config.standing_penalty%ROWTYPE;
6917 SELECT INTO user_object * FROM actor.usr WHERE id = match_user;
6920 SELECT INTO tmp_org * FROM actor.org_unit WHERE id = context_org;
6922 -- Fail if the user has a high fine balance
6924 tmp_grp := user_object.profile;
6926 SELECT * INTO max_fines FROM permission.grp_penalty_threshold WHERE grp = tmp_grp AND penalty = 1 AND org_unit = tmp_org.id;
6928 IF max_fines.threshold IS NULL THEN
6929 SELECT parent INTO tmp_grp FROM permission.grp_tree WHERE id = tmp_grp;
6934 IF tmp_grp IS NULL THEN
6939 IF max_fines.threshold IS NOT NULL OR tmp_org.parent_ou IS NULL THEN
6943 SELECT * INTO tmp_org FROM actor.org_unit WHERE id = tmp_org.parent_ou;
6947 IF max_fines.threshold IS NOT NULL THEN
6949 FOR existing_sp_row IN
6951 FROM actor.usr_standing_penalty
6952 WHERE usr = match_user
6953 AND org_unit = max_fines.org_unit
6954 AND (stop_date IS NULL or stop_date > NOW())
6955 AND standing_penalty = 1
6957 RETURN NEXT existing_sp_row;
6960 SELECT SUM(f.balance_owed) INTO current_fines
6961 FROM money.materialized_billable_xact_summary f
6964 FROM booking.reservation r
6965 JOIN actor.org_unit_full_path( max_fines.org_unit ) fp ON (r.pickup_lib = fp.id)
6966 WHERE usr = match_user
6967 AND xact_finish IS NULL
6970 FROM money.grocery g
6971 JOIN actor.org_unit_full_path( max_fines.org_unit ) fp ON (g.billing_location = fp.id)
6972 WHERE usr = match_user
6973 AND xact_finish IS NULL
6976 FROM action.circulation circ
6977 JOIN actor.org_unit_full_path( max_fines.org_unit ) fp ON (circ.circ_lib = fp.id)
6978 WHERE usr = match_user
6979 AND xact_finish IS NULL ) l USING (id);
6981 IF current_fines >= max_fines.threshold THEN
6982 new_sp_row.usr := match_user;
6983 new_sp_row.org_unit := max_fines.org_unit;
6984 new_sp_row.standing_penalty := 1;
6985 RETURN NEXT new_sp_row;
6989 -- Start over for max overdue
6990 SELECT INTO tmp_org * FROM actor.org_unit WHERE id = context_org;
6992 -- Fail if the user has too many overdue items
6994 tmp_grp := user_object.profile;
6997 SELECT * INTO max_overdue FROM permission.grp_penalty_threshold WHERE grp = tmp_grp AND penalty = 2 AND org_unit = tmp_org.id;
6999 IF max_overdue.threshold IS NULL THEN
7000 SELECT parent INTO tmp_grp FROM permission.grp_tree WHERE id = tmp_grp;
7005 IF tmp_grp IS NULL THEN
7010 IF max_overdue.threshold IS NOT NULL OR tmp_org.parent_ou IS NULL THEN
7014 SELECT INTO tmp_org * FROM actor.org_unit WHERE id = tmp_org.parent_ou;
7018 IF max_overdue.threshold IS NOT NULL THEN
7020 FOR existing_sp_row IN
7022 FROM actor.usr_standing_penalty
7023 WHERE usr = match_user
7024 AND org_unit = max_overdue.org_unit
7025 AND (stop_date IS NULL or stop_date > NOW())
7026 AND standing_penalty = 2
7028 RETURN NEXT existing_sp_row;
7031 SELECT INTO items_overdue COUNT(*)
7032 FROM action.circulation circ
7033 JOIN actor.org_unit_full_path( max_overdue.org_unit ) fp ON (circ.circ_lib = fp.id)
7034 WHERE circ.usr = match_user
7035 AND circ.checkin_time IS NULL
7036 AND circ.due_date < NOW()
7037 AND (circ.stop_fines = 'MAXFINES' OR circ.stop_fines IS NULL);
7039 IF items_overdue >= max_overdue.threshold::INT THEN
7040 new_sp_row.usr := match_user;
7041 new_sp_row.org_unit := max_overdue.org_unit;
7042 new_sp_row.standing_penalty := 2;
7043 RETURN NEXT new_sp_row;
7047 -- Start over for max out
7048 SELECT INTO tmp_org * FROM actor.org_unit WHERE id = context_org;
7050 -- Fail if the user has too many checked out items
7052 tmp_grp := user_object.profile;
7054 SELECT * INTO max_items_out FROM permission.grp_penalty_threshold WHERE grp = tmp_grp AND penalty = 3 AND org_unit = tmp_org.id;
7056 IF max_items_out.threshold IS NULL THEN
7057 SELECT parent INTO tmp_grp FROM permission.grp_tree WHERE id = tmp_grp;
7062 IF tmp_grp IS NULL THEN
7067 IF max_items_out.threshold IS NOT NULL OR tmp_org.parent_ou IS NULL THEN
7071 SELECT INTO tmp_org * FROM actor.org_unit WHERE id = tmp_org.parent_ou;
7076 -- Fail if the user has too many items checked out
7077 IF max_items_out.threshold IS NOT NULL THEN
7079 FOR existing_sp_row IN
7081 FROM actor.usr_standing_penalty
7082 WHERE usr = match_user
7083 AND org_unit = max_items_out.org_unit
7084 AND (stop_date IS NULL or stop_date > NOW())
7085 AND standing_penalty = 3
7087 RETURN NEXT existing_sp_row;
7090 SELECT INTO items_out COUNT(*)
7091 FROM action.circulation circ
7092 JOIN actor.org_unit_full_path( max_items_out.org_unit ) fp ON (circ.circ_lib = fp.id)
7093 WHERE circ.usr = match_user
7094 AND circ.checkin_time IS NULL
7095 AND (circ.stop_fines IN ('MAXFINES','LONGOVERDUE') OR circ.stop_fines IS NULL);
7097 IF items_out >= max_items_out.threshold::INT THEN
7098 new_sp_row.usr := match_user;
7099 new_sp_row.org_unit := max_items_out.org_unit;
7100 new_sp_row.standing_penalty := 3;
7101 RETURN NEXT new_sp_row;
7105 -- Start over for collections warning
7106 SELECT INTO tmp_org * FROM actor.org_unit WHERE id = context_org;
7108 -- Fail if the user has a collections-level fine balance
7110 tmp_grp := user_object.profile;
7112 SELECT * INTO max_fines FROM permission.grp_penalty_threshold WHERE grp = tmp_grp AND penalty = 4 AND org_unit = tmp_org.id;
7114 IF max_fines.threshold IS NULL THEN
7115 SELECT parent INTO tmp_grp FROM permission.grp_tree WHERE id = tmp_grp;
7120 IF tmp_grp IS NULL THEN
7125 IF max_fines.threshold IS NOT NULL OR tmp_org.parent_ou IS NULL THEN
7129 SELECT * INTO tmp_org FROM actor.org_unit WHERE id = tmp_org.parent_ou;
7133 IF max_fines.threshold IS NOT NULL THEN
7135 FOR existing_sp_row IN
7137 FROM actor.usr_standing_penalty
7138 WHERE usr = match_user
7139 AND org_unit = max_fines.org_unit
7140 AND (stop_date IS NULL or stop_date > NOW())
7141 AND standing_penalty = 4
7143 RETURN NEXT existing_sp_row;
7146 SELECT SUM(f.balance_owed) INTO current_fines
7147 FROM money.materialized_billable_xact_summary f
7150 FROM booking.reservation r
7151 JOIN actor.org_unit_full_path( max_fines.org_unit ) fp ON (r.pickup_lib = fp.id)
7152 WHERE usr = match_user
7153 AND xact_finish IS NULL
7156 FROM money.grocery g
7157 JOIN actor.org_unit_full_path( max_fines.org_unit ) fp ON (g.billing_location = fp.id)
7158 WHERE usr = match_user
7159 AND xact_finish IS NULL
7162 FROM action.circulation circ
7163 JOIN actor.org_unit_full_path( max_fines.org_unit ) fp ON (circ.circ_lib = fp.id)
7164 WHERE usr = match_user
7165 AND xact_finish IS NULL ) l USING (id);
7167 IF current_fines >= max_fines.threshold THEN
7168 new_sp_row.usr := match_user;
7169 new_sp_row.org_unit := max_fines.org_unit;
7170 new_sp_row.standing_penalty := 4;
7171 RETURN NEXT new_sp_row;
7175 -- Start over for in collections
7176 SELECT INTO tmp_org * FROM actor.org_unit WHERE id = context_org;
7178 -- Remove the in-collections penalty if the user has paid down enough
7179 -- This penalty is different, because this code is not responsible for creating
7180 -- new in-collections penalties, only for removing them
7182 tmp_grp := user_object.profile;
7184 SELECT * INTO max_fines FROM permission.grp_penalty_threshold WHERE grp = tmp_grp AND penalty = 30 AND org_unit = tmp_org.id;
7186 IF max_fines.threshold IS NULL THEN
7187 SELECT parent INTO tmp_grp FROM permission.grp_tree WHERE id = tmp_grp;
7192 IF tmp_grp IS NULL THEN
7197 IF max_fines.threshold IS NOT NULL OR tmp_org.parent_ou IS NULL THEN
7201 SELECT * INTO tmp_org FROM actor.org_unit WHERE id = tmp_org.parent_ou;
7205 IF max_fines.threshold IS NOT NULL THEN
7207 -- first, see if the user had paid down to the threshold
7208 SELECT SUM(f.balance_owed) INTO current_fines
7209 FROM money.materialized_billable_xact_summary f
7212 FROM booking.reservation r
7213 JOIN actor.org_unit_full_path( max_fines.org_unit ) fp ON (r.pickup_lib = fp.id)
7214 WHERE usr = match_user
7215 AND xact_finish IS NULL
7218 FROM money.grocery g
7219 JOIN actor.org_unit_full_path( max_fines.org_unit ) fp ON (g.billing_location = fp.id)
7220 WHERE usr = match_user
7221 AND xact_finish IS NULL
7224 FROM action.circulation circ
7225 JOIN actor.org_unit_full_path( max_fines.org_unit ) fp ON (circ.circ_lib = fp.id)
7226 WHERE usr = match_user
7227 AND xact_finish IS NULL ) l USING (id);
7229 IF current_fines IS NULL OR current_fines <= max_fines.threshold THEN
7230 -- patron has paid down enough
7232 SELECT INTO tmp_penalty * FROM config.standing_penalty WHERE id = 30;
7234 IF tmp_penalty.org_depth IS NOT NULL THEN
7236 -- since this code is not responsible for applying the penalty, it can't
7237 -- guarantee the current context org will match the org at which the penalty
7238 --- was applied. search up the org tree until we hit the configured penalty depth
7239 SELECT INTO tmp_org * FROM actor.org_unit WHERE id = context_org;
7240 SELECT INTO tmp_depth depth FROM actor.org_unit_type WHERE id = tmp_org.ou_type;
7242 WHILE tmp_depth >= tmp_penalty.org_depth LOOP
7244 FOR existing_sp_row IN
7246 FROM actor.usr_standing_penalty
7247 WHERE usr = match_user
7248 AND org_unit = tmp_org.id
7249 AND (stop_date IS NULL or stop_date > NOW())
7250 AND standing_penalty = 30
7253 -- Penalty exists, return it for removal
7254 RETURN NEXT existing_sp_row;
7257 IF tmp_org.parent_ou IS NULL THEN
7261 SELECT * INTO tmp_org FROM actor.org_unit WHERE id = tmp_org.parent_ou;
7262 SELECT INTO tmp_depth depth FROM actor.org_unit_type WHERE id = tmp_org.ou_type;
7267 -- no penalty depth is defined, look for exact matches
7269 FOR existing_sp_row IN
7271 FROM actor.usr_standing_penalty
7272 WHERE usr = match_user
7273 AND org_unit = max_fines.org_unit
7274 AND (stop_date IS NULL or stop_date > NOW())
7275 AND standing_penalty = 30
7277 -- Penalty exists, return it for removal
7278 RETURN NEXT existing_sp_row;
7288 $func$ LANGUAGE plpgsql;
7290 -- Create a default row in acq.fiscal_calendar
7291 -- Add a column in actor.org_unit to point to it
7293 INSERT INTO acq.fiscal_calendar ( id, name ) VALUES ( 1, 'Default' );
7295 ALTER TABLE actor.org_unit
7296 ADD COLUMN fiscal_calendar INT NOT NULL
7297 REFERENCES acq.fiscal_calendar( id )
7298 DEFERRABLE INITIALLY DEFERRED
7301 ALTER TABLE auditor.actor_org_unit_history
7302 ADD COLUMN fiscal_calendar INT;
7304 ALTER TABLE acq.funding_source_credit
7305 ADD COLUMN deadline_date TIMESTAMPTZ;
7307 ALTER TABLE acq.funding_source_credit
7308 ADD COLUMN effective_date TIMESTAMPTZ NOT NULL DEFAULT now();
7310 INSERT INTO config.standing_penalty (id,name,label) VALUES (30,'PATRON_IN_COLLECTIONS','Patron has been referred to a collections agency');
7312 CREATE TABLE acq.fund_transfer (
7313 id SERIAL PRIMARY KEY,
7314 src_fund INT NOT NULL REFERENCES acq.fund( id )
7315 DEFERRABLE INITIALLY DEFERRED,
7316 src_amount NUMERIC NOT NULL,
7317 dest_fund INT REFERENCES acq.fund( id )
7318 DEFERRABLE INITIALLY DEFERRED,
7319 dest_amount NUMERIC,
7320 transfer_time TIMESTAMPTZ NOT NULL DEFAULT now(),
7321 transfer_user INT NOT NULL REFERENCES actor.usr( id )
7322 DEFERRABLE INITIALLY DEFERRED,
7324 funding_source_credit INTEGER NOT NULL
7325 REFERENCES acq.funding_source_credit(id)
7326 DEFERRABLE INITIALLY DEFERRED
7329 CREATE INDEX acqftr_usr_idx
7330 ON acq.fund_transfer( transfer_user );
7332 COMMENT ON TABLE acq.fund_transfer IS $$
7334 * Copyright (C) 2009 Georgia Public Library Service
7335 * Scott McKellar <scott@esilibrary.com>
7339 * Each row represents the transfer of money from a source fund
7340 * to a destination fund. There should be corresponding entries
7341 * in acq.fund_allocation. The purpose of acq.fund_transfer is
7342 * to record how much money moved from which fund to which other
7345 * The presence of two amount fields, rather than one, reflects
7346 * the possibility that the two funds are denominated in different
7347 * currencies. If they use the same currency type, the two
7348 * amounts should be the same.
7352 * This program is free software; you can redistribute it and/or
7353 * modify it under the terms of the GNU General Public License
7354 * as published by the Free Software Foundation; either version 2
7355 * of the License, or (at your option) any later version.
7357 * This program is distributed in the hope that it will be useful,
7358 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7359 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7360 * GNU General Public License for more details.
7364 CREATE TABLE acq.claim_event_type (
7365 id SERIAL PRIMARY KEY,
7366 org_unit INT NOT NULL REFERENCES actor.org_unit(id)
7367 DEFERRABLE INITIALLY DEFERRED,
7369 description TEXT NOT NULL,
7370 library_initiated BOOL NOT NULL DEFAULT FALSE,
7371 CONSTRAINT event_type_once_per_org UNIQUE ( org_unit, code )
7374 CREATE TABLE acq.claim_event (
7375 id BIGSERIAL PRIMARY KEY,
7376 type INT NOT NULL REFERENCES acq.claim_event_type
7377 DEFERRABLE INITIALLY DEFERRED,
7378 claim SERIAL NOT NULL REFERENCES acq.claim
7379 DEFERRABLE INITIALLY DEFERRED,
7380 event_date TIMESTAMPTZ NOT NULL DEFAULT now(),
7381 creator INT NOT NULL REFERENCES actor.usr
7382 DEFERRABLE INITIALLY DEFERRED,
7386 CREATE INDEX claim_event_claim_date_idx ON acq.claim_event( claim, event_date );
7388 CREATE OR REPLACE FUNCTION actor.usr_purge_data(
7391 ) RETURNS VOID AS $$
7394 renamable_row RECORD;
7397 UPDATE actor.usr SET
7400 mailing_address = NULL,
7401 billing_address = NULL
7405 UPDATE acq.fund_allocation SET allocator = dest_usr WHERE allocator = src_usr;
7406 UPDATE acq.lineitem SET creator = dest_usr WHERE creator = src_usr;
7407 UPDATE acq.lineitem SET editor = dest_usr WHERE editor = src_usr;
7408 UPDATE acq.lineitem SET selector = dest_usr WHERE selector = src_usr;
7409 UPDATE acq.lineitem_note SET creator = dest_usr WHERE creator = src_usr;
7410 UPDATE acq.lineitem_note SET editor = dest_usr WHERE editor = src_usr;
7411 DELETE FROM acq.lineitem_usr_attr_definition WHERE usr = src_usr;
7413 -- Update with a rename to avoid collisions
7414 FOR renamable_row in
7417 WHERE owner = src_usr
7419 suffix := ' (' || src_usr || ')';
7423 SET owner = dest_usr, name = name || suffix
7424 WHERE id = renamable_row.id;
7425 EXCEPTION WHEN unique_violation THEN
7426 suffix := suffix || ' ';
7433 UPDATE acq.picklist SET creator = dest_usr WHERE creator = src_usr;
7434 UPDATE acq.picklist SET editor = dest_usr WHERE editor = src_usr;
7435 UPDATE acq.po_note SET creator = dest_usr WHERE creator = src_usr;
7436 UPDATE acq.po_note SET editor = dest_usr WHERE editor = src_usr;
7437 UPDATE acq.purchase_order SET owner = dest_usr WHERE owner = src_usr;
7438 UPDATE acq.purchase_order SET creator = dest_usr WHERE creator = src_usr;
7439 UPDATE acq.purchase_order SET editor = dest_usr WHERE editor = src_usr;
7440 UPDATE acq.claim_event SET creator = dest_usr WHERE creator = src_usr;
7443 DELETE FROM action.circulation WHERE usr = src_usr;
7444 UPDATE action.circulation SET circ_staff = dest_usr WHERE circ_staff = src_usr;
7445 UPDATE action.circulation SET checkin_staff = dest_usr WHERE checkin_staff = src_usr;
7446 UPDATE action.hold_notification SET notify_staff = dest_usr WHERE notify_staff = src_usr;
7447 UPDATE action.hold_request SET fulfillment_staff = dest_usr WHERE fulfillment_staff = src_usr;
7448 UPDATE action.hold_request SET requestor = dest_usr WHERE requestor = src_usr;
7449 DELETE FROM action.hold_request WHERE usr = src_usr;
7450 UPDATE action.in_house_use SET staff = dest_usr WHERE staff = src_usr;
7451 UPDATE action.non_cat_in_house_use SET staff = dest_usr WHERE staff = src_usr;
7452 DELETE FROM action.non_cataloged_circulation WHERE patron = src_usr;
7453 UPDATE action.non_cataloged_circulation SET staff = dest_usr WHERE staff = src_usr;
7454 DELETE FROM action.survey_response WHERE usr = src_usr;
7455 UPDATE action.fieldset SET owner = dest_usr WHERE owner = src_usr;
7458 DELETE FROM actor.card WHERE usr = src_usr;
7459 DELETE FROM actor.stat_cat_entry_usr_map WHERE target_usr = src_usr;
7461 -- The following update is intended to avoid transient violations of a foreign
7462 -- key constraint, whereby actor.usr_address references itself. It may not be
7463 -- necessary, but it does no harm.
7464 UPDATE actor.usr_address SET replaces = NULL
7465 WHERE usr = src_usr AND replaces IS NOT NULL;
7466 DELETE FROM actor.usr_address WHERE usr = src_usr;
7467 DELETE FROM actor.usr_note WHERE usr = src_usr;
7468 UPDATE actor.usr_note SET creator = dest_usr WHERE creator = src_usr;
7469 DELETE FROM actor.usr_org_unit_opt_in WHERE usr = src_usr;
7470 UPDATE actor.usr_org_unit_opt_in SET staff = dest_usr WHERE staff = src_usr;
7471 DELETE FROM actor.usr_setting WHERE usr = src_usr;
7472 DELETE FROM actor.usr_standing_penalty WHERE usr = src_usr;
7473 UPDATE actor.usr_standing_penalty SET staff = dest_usr WHERE staff = src_usr;
7476 UPDATE asset.call_number SET creator = dest_usr WHERE creator = src_usr;
7477 UPDATE asset.call_number SET editor = dest_usr WHERE editor = src_usr;
7478 UPDATE asset.call_number_note SET creator = dest_usr WHERE creator = src_usr;
7479 UPDATE asset.copy SET creator = dest_usr WHERE creator = src_usr;
7480 UPDATE asset.copy SET editor = dest_usr WHERE editor = src_usr;
7481 UPDATE asset.copy_note SET creator = dest_usr WHERE creator = src_usr;
7484 DELETE FROM auditor.actor_usr_address_history WHERE id = src_usr;
7485 DELETE FROM auditor.actor_usr_history WHERE id = src_usr;
7486 UPDATE auditor.asset_call_number_history SET creator = dest_usr WHERE creator = src_usr;
7487 UPDATE auditor.asset_call_number_history SET editor = dest_usr WHERE editor = src_usr;
7488 UPDATE auditor.asset_copy_history SET creator = dest_usr WHERE creator = src_usr;
7489 UPDATE auditor.asset_copy_history SET editor = dest_usr WHERE editor = src_usr;
7490 UPDATE auditor.biblio_record_entry_history SET creator = dest_usr WHERE creator = src_usr;
7491 UPDATE auditor.biblio_record_entry_history SET editor = dest_usr WHERE editor = src_usr;
7494 UPDATE biblio.record_entry SET creator = dest_usr WHERE creator = src_usr;
7495 UPDATE biblio.record_entry SET editor = dest_usr WHERE editor = src_usr;
7496 UPDATE biblio.record_note SET creator = dest_usr WHERE creator = src_usr;
7497 UPDATE biblio.record_note SET editor = dest_usr WHERE editor = src_usr;
7500 -- Update buckets with a rename to avoid collisions
7501 FOR renamable_row in
7503 FROM container.biblio_record_entry_bucket
7504 WHERE owner = src_usr
7506 suffix := ' (' || src_usr || ')';
7509 UPDATE container.biblio_record_entry_bucket
7510 SET owner = dest_usr, name = name || suffix
7511 WHERE id = renamable_row.id;
7512 EXCEPTION WHEN unique_violation THEN
7513 suffix := suffix || ' ';
7520 FOR renamable_row in
7522 FROM container.call_number_bucket
7523 WHERE owner = src_usr
7525 suffix := ' (' || src_usr || ')';
7528 UPDATE container.call_number_bucket
7529 SET owner = dest_usr, name = name || suffix
7530 WHERE id = renamable_row.id;
7531 EXCEPTION WHEN unique_violation THEN
7532 suffix := suffix || ' ';
7539 FOR renamable_row in
7541 FROM container.copy_bucket
7542 WHERE owner = src_usr
7544 suffix := ' (' || src_usr || ')';
7547 UPDATE container.copy_bucket
7548 SET owner = dest_usr, name = name || suffix
7549 WHERE id = renamable_row.id;
7550 EXCEPTION WHEN unique_violation THEN
7551 suffix := suffix || ' ';
7558 FOR renamable_row in
7560 FROM container.user_bucket
7561 WHERE owner = src_usr
7563 suffix := ' (' || src_usr || ')';
7566 UPDATE container.user_bucket
7567 SET owner = dest_usr, name = name || suffix
7568 WHERE id = renamable_row.id;
7569 EXCEPTION WHEN unique_violation THEN
7570 suffix := suffix || ' ';
7577 DELETE FROM container.user_bucket_item WHERE target_user = src_usr;
7580 DELETE FROM money.billable_xact WHERE usr = src_usr;
7581 DELETE FROM money.collections_tracker WHERE usr = src_usr;
7582 UPDATE money.collections_tracker SET collector = dest_usr WHERE collector = src_usr;
7585 DELETE FROM permission.usr_grp_map WHERE usr = src_usr;
7586 DELETE FROM permission.usr_object_perm_map WHERE usr = src_usr;
7587 DELETE FROM permission.usr_perm_map WHERE usr = src_usr;
7588 DELETE FROM permission.usr_work_ou_map WHERE usr = src_usr;
7591 -- Update with a rename to avoid collisions
7593 FOR renamable_row in
7595 FROM reporter.output_folder
7596 WHERE owner = src_usr
7598 suffix := ' (' || src_usr || ')';
7601 UPDATE reporter.output_folder
7602 SET owner = dest_usr, name = name || suffix
7603 WHERE id = renamable_row.id;
7604 EXCEPTION WHEN unique_violation THEN
7605 suffix := suffix || ' ';
7611 EXCEPTION WHEN undefined_table THEN
7616 UPDATE reporter.report SET owner = dest_usr WHERE owner = src_usr;
7617 EXCEPTION WHEN undefined_table THEN
7621 -- Update with a rename to avoid collisions
7623 FOR renamable_row in
7625 FROM reporter.report_folder
7626 WHERE owner = src_usr
7628 suffix := ' (' || src_usr || ')';
7631 UPDATE reporter.report_folder
7632 SET owner = dest_usr, name = name || suffix
7633 WHERE id = renamable_row.id;
7634 EXCEPTION WHEN unique_violation THEN
7635 suffix := suffix || ' ';
7641 EXCEPTION WHEN undefined_table THEN
7646 UPDATE reporter.schedule SET runner = dest_usr WHERE runner = src_usr;
7647 EXCEPTION WHEN undefined_table THEN
7652 UPDATE reporter.template SET owner = dest_usr WHERE owner = src_usr;
7653 EXCEPTION WHEN undefined_table THEN
7657 -- Update with a rename to avoid collisions
7659 FOR renamable_row in
7661 FROM reporter.template_folder
7662 WHERE owner = src_usr
7664 suffix := ' (' || src_usr || ')';
7667 UPDATE reporter.template_folder
7668 SET owner = dest_usr, name = name || suffix
7669 WHERE id = renamable_row.id;
7670 EXCEPTION WHEN unique_violation THEN
7671 suffix := suffix || ' ';
7677 EXCEPTION WHEN undefined_table THEN
7682 -- Update with a rename to avoid collisions
7683 FOR renamable_row in
7686 WHERE owner = src_usr
7688 suffix := ' (' || src_usr || ')';
7691 UPDATE vandelay.queue
7692 SET owner = dest_usr, name = name || suffix
7693 WHERE id = renamable_row.id;
7694 EXCEPTION WHEN unique_violation THEN
7695 suffix := suffix || ' ';
7703 $$ LANGUAGE plpgsql;
7705 -- INSERT INTO config.copy_status (id,name) VALUES (15,oils_i18n_gettext(15, 'On reservation shelf', 'ccs', 'name'));
7707 ALTER TABLE acq.fund
7708 ADD COLUMN rollover BOOL NOT NULL DEFAULT FALSE;
7710 ALTER TABLE acq.fund
7711 ADD COLUMN propagate BOOLEAN NOT NULL DEFAULT TRUE;
7713 -- A fund can't roll over if it doesn't propagate from one year to the next
7715 ALTER TABLE acq.fund
7716 ADD CONSTRAINT acq_fund_rollover_implies_propagate CHECK
7717 ( propagate OR NOT rollover );
7719 ALTER TABLE acq.fund
7720 ADD COLUMN active BOOL NOT NULL DEFAULT TRUE;
7722 ALTER TABLE acq.fund
7723 ADD COLUMN balance_warning_percent INT
7724 CONSTRAINT balance_warning_percent_limit
7725 CHECK( balance_warning_percent <= 100 );
7727 ALTER TABLE acq.fund
7728 ADD COLUMN balance_stop_percent INT
7729 CONSTRAINT balance_stop_percent_limit
7730 CHECK( balance_stop_percent <= 100 );
7732 CREATE VIEW acq.ordered_funding_source_credit AS
7734 CASE WHEN deadline_date IS NULL THEN
7738 END AS sort_priority,
7739 CASE WHEN deadline_date IS NULL THEN
7749 acq.funding_source_credit;
7751 COMMENT ON VIEW acq.ordered_funding_source_credit IS $$
7753 * Copyright (C) 2009 Georgia Public Library Service
7754 * Scott McKellar <scott@gmail.com>
7756 * The acq.ordered_funding_source_credit view is a prioritized
7757 * ordering of funding source credits. When ordered by the first
7758 * three columns, this view defines the order in which the various
7759 * credits are to be tapped for spending, subject to the allocations
7760 * in the acq.fund_allocation table.
7762 * The first column reflects the principle that we should spend
7763 * money with deadlines before spending money without deadlines.
7765 * The second column reflects the principle that we should spend the
7766 * oldest money first. For money with deadlines, that means that we
7767 * spend first from the credit with the earliest deadline. For
7768 * money without deadlines, we spend first from the credit with the
7769 * earliest effective date.
7771 * The third column is a tie breaker to ensure a consistent
7776 * This program is free software; you can redistribute it and/or
7777 * modify it under the terms of the GNU General Public License
7778 * as published by the Free Software Foundation; either version 2
7779 * of the License, or (at your option) any later version.
7781 * This program is distributed in the hope that it will be useful,
7782 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7783 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7784 * GNU General Public License for more details.
7788 CREATE OR REPLACE VIEW money.billable_xact_summary_location_view AS
7789 SELECT m.*, COALESCE(c.circ_lib, g.billing_location, r.pickup_lib) AS billing_location
7790 FROM money.materialized_billable_xact_summary m
7791 LEFT JOIN action.circulation c ON (c.id = m.id)
7792 LEFT JOIN money.grocery g ON (g.id = m.id)
7793 LEFT JOIN booking.reservation r ON (r.id = m.id);
7795 CREATE TABLE config.marc21_rec_type_map (
7796 code TEXT PRIMARY KEY,
7797 type_val TEXT NOT NULL,
7798 blvl_val TEXT NOT NULL
7801 CREATE TABLE config.marc21_ff_pos_map (
7802 id SERIAL PRIMARY KEY,
7803 fixed_field TEXT NOT NULL,
7805 rec_type TEXT NOT NULL,
7806 start_pos INT NOT NULL,
7807 length INT NOT NULL,
7808 default_val TEXT NOT NULL DEFAULT ' '
7811 CREATE TABLE config.marc21_physical_characteristic_type_map (
7812 ptype_key TEXT PRIMARY KEY,
7813 label TEXT NOT NULL -- I18N
7816 CREATE TABLE config.marc21_physical_characteristic_subfield_map (
7817 id SERIAL PRIMARY KEY,
7818 ptype_key TEXT NOT NULL REFERENCES config.marc21_physical_characteristic_type_map (ptype_key) ON DELETE CASCADE ON UPDATE CASCADE,
7819 subfield TEXT NOT NULL,
7820 start_pos INT NOT NULL,
7821 length INT NOT NULL,
7822 label TEXT NOT NULL -- I18N
7825 CREATE TABLE config.marc21_physical_characteristic_value_map (
7826 id SERIAL PRIMARY KEY,
7827 value TEXT NOT NULL,
7828 ptype_subfield INT NOT NULL REFERENCES config.marc21_physical_characteristic_subfield_map (id),
7829 label TEXT NOT NULL -- I18N
7832 ----------------------------------
7833 -- MARC21 record structure data --
7834 ----------------------------------
7837 INSERT INTO config.marc21_rec_type_map (code, type_val, blvl_val) VALUES ('BKS','at','acdm');
7838 INSERT INTO config.marc21_rec_type_map (code, type_val, blvl_val) VALUES ('SER','a','bsi');
7839 INSERT INTO config.marc21_rec_type_map (code, type_val, blvl_val) VALUES ('VIS','gkro','abcdmsi');
7840 INSERT INTO config.marc21_rec_type_map (code, type_val, blvl_val) VALUES ('MIX','p','cdi');
7841 INSERT INTO config.marc21_rec_type_map (code, type_val, blvl_val) VALUES ('MAP','ef','abcdmsi');
7842 INSERT INTO config.marc21_rec_type_map (code, type_val, blvl_val) VALUES ('SCO','cd','abcdmsi');
7843 INSERT INTO config.marc21_rec_type_map (code, type_val, blvl_val) VALUES ('REC','ij','abcdmsi');
7844 INSERT INTO config.marc21_rec_type_map (code, type_val, blvl_val) VALUES ('COM','m','abcdmsi');
7846 ------ Physical Characteristics
7849 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('a','Map');
7850 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('a','b','1','1','SMD');
7851 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Atlas');
7852 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Diagram');
7853 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Map');
7854 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('k',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Profile');
7855 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Model');
7856 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Remote-sensing image');
7857 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Section');
7858 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
7859 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('y',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'View');
7860 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
7861 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('a','d','3','1','Color');
7862 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'One color');
7863 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multicolored');
7864 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('a','e','4','1','Physical medium');
7865 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Paper');
7866 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Wood');
7867 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Stone');
7868 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Metal');
7869 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Synthetics');
7870 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Skins');
7871 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Textile');
7872 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Plaster');
7873 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Flexible base photographic medium, positive');
7874 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Flexible base photographic medium, negative');
7875 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Non-flexible base photographic medium, positive');
7876 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('t',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Non-flexible base photographic medium, negative');
7877 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7878 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('y',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other photographic medium');
7879 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
7880 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('a','f','5','1','Type of reproduction');
7881 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Facsimile');
7882 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
7883 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7884 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
7885 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('a','g','6','1','Production/reproduction details');
7886 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Photocopy, blueline print');
7887 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Photocopy');
7888 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Pre-production');
7889 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Film');
7890 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7891 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
7892 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('a','h','7','1','Positive/negative');
7893 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Positive');
7894 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Negative');
7895 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
7896 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
7898 -- Electronic Resource
7899 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('c','Electronic Resource');
7900 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','b','1','1','SMD');
7901 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Tape Cartridge');
7902 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Chip cartridge');
7903 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Computer optical disk cartridge');
7904 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Tape cassette');
7905 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Tape reel');
7906 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic disk');
7907 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magneto-optical disk');
7908 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Optical disk');
7909 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Remote');
7910 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
7911 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
7912 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','d','3','1','Color');
7913 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'One color');
7914 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Black-and-white');
7915 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multicolored');
7916 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Gray scale');
7917 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
7918 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
7919 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7920 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
7921 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','e','4','1','Dimensions');
7922 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'3 1/2 in.');
7923 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'12 in.');
7924 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'4 3/4 in. or 12 cm.');
7925 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1 1/8 x 2 3/8 in.');
7926 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'3 7/8 x 2 1/2 in.');
7927 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
7928 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'5 1/4 in.');
7929 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7930 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('v',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'8 in.');
7931 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
7932 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','f','5','1','Sound');
7933 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES (' ',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'No sound (Silent)');
7934 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound');
7935 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7936 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','g','6','3','Image bit depth');
7937 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('---',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7938 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('mmm',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multiple');
7939 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('nnn',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
7940 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','h','9','1','File formats');
7941 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'One file format');
7942 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multiple file formats');
7943 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7944 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','i','10','1','Quality assurance target(s)');
7945 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Absent');
7946 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
7947 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Present');
7948 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7949 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','j','11','1','Antecedent/Source');
7950 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'File reproduced from original');
7951 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'File reproduced from microform');
7952 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'File reproduced from electronic resource');
7953 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'File reproduced from an intermediate (not microform)');
7954 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
7955 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
7956 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7957 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','k','12','1','Level of compression');
7958 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Uncompressed');
7959 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Lossless');
7960 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Lossy');
7961 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
7962 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7963 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('c','l','13','1','Reformatting quality');
7964 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Access');
7965 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
7966 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Preservation');
7967 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Replacement');
7968 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7971 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('d','Globe');
7972 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('d','b','1','1','SMD');
7973 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Celestial globe');
7974 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Planetary or lunar globe');
7975 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Terrestrial globe');
7976 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Earth moon globe');
7977 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
7978 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
7979 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('d','d','3','1','Color');
7980 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'One color');
7981 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multicolored');
7982 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('d','e','4','1','Physical medium');
7983 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Paper');
7984 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Wood');
7985 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Stone');
7986 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Metal');
7987 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Synthetics');
7988 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Skins');
7989 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Textile');
7990 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Plaster');
7991 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7992 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
7993 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('d','f','5','1','Type of reproduction');
7994 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Facsimile');
7995 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
7996 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
7997 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8000 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('f','Tactile Material');
8001 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('f','b','1','1','SMD');
8002 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Moon');
8003 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Braille');
8004 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Combination');
8005 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Tactile, with no writing system');
8006 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
8007 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8008 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('f','d','3','2','Class of braille writing');
8009 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Literary braille');
8010 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Format code braille');
8011 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mathematics and scientific braille');
8012 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Computer braille');
8013 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Music braille');
8014 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multiple braille types');
8015 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8016 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8017 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8018 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('f','e','4','1','Level of contraction');
8019 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Uncontracted');
8020 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Contracted');
8021 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Combination');
8022 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8023 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8024 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8025 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('f','f','6','3','Braille music format');
8026 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Bar over bar');
8027 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Bar by bar');
8028 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Line over line');
8029 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Paragraph');
8030 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Single line');
8031 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Section by section');
8032 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Line by line');
8033 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Open score');
8034 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Spanner short form scoring');
8035 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Short form scoring');
8036 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('k',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Outline');
8037 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('l',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Vertical score');
8038 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8039 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8040 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8041 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('f','g','9','1','Special physical characteristics');
8042 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Print/braille');
8043 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Jumbo or enlarged braille');
8044 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8045 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8046 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8048 -- Projected Graphic
8049 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('g','Projected Graphic');
8050 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('g','b','1','1','SMD');
8051 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Film cartridge');
8052 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Filmstrip');
8053 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Film filmstrip type');
8054 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Filmstrip roll');
8055 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Slide');
8056 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('t',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Transparency');
8057 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8058 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('g','d','3','1','Color');
8059 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Black-and-white');
8060 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multicolored');
8061 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Hand-colored');
8062 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
8063 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8064 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8065 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8066 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('g','e','4','1','Base of emulsion');
8067 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Glass');
8068 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Synthetics');
8069 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Safety film');
8070 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('k',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Film base, other than safety film');
8071 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed collection');
8072 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Paper');
8073 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8074 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8075 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('g','f','5','1','Sound on medium or separate');
8076 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound on medium');
8077 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound separate from medium');
8078 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8079 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('g','g','6','1','Medium for sound');
8080 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Optical sound track on motion picture film');
8081 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic sound track on motion picture film');
8082 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic audio tape in cartridge');
8083 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound disc');
8084 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic audio tape on reel');
8085 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic audio tape in cassette');
8086 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Optical and magnetic sound track on film');
8087 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videotape');
8088 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videodisc');
8089 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8090 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8091 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('g','h','7','1','Dimensions');
8092 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Standard 8 mm.');
8093 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Super 8 mm./single 8 mm.');
8094 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'9.5 mm.');
8095 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'16 mm.');
8096 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'28 mm.');
8097 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'35 mm.');
8098 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'70 mm.');
8099 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'2 x 2 in. (5 x 5 cm.)');
8100 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('k',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'2 1/4 x 2 1/4 in. (6 x 6 cm.)');
8101 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'4 x 5 in. (10 x 13 cm.)');
8102 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('t',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'5 x 7 in. (13 x 18 cm.)');
8103 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8104 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('v',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'8 x 10 in. (21 x 26 cm.)');
8105 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('w',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'9 x 9 in. (23 x 23 cm.)');
8106 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('x',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'10 x 10 in. (26 x 26 cm.)');
8107 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('y',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'7 x 7 in. (18 x 18 cm.)');
8108 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8109 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('g','i','8','1','Secondary support material');
8110 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Cardboard');
8111 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Glass');
8112 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Synthetics');
8113 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'metal');
8114 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Metal and glass');
8115 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('k',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Synthetics and glass');
8116 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed collection');
8117 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8118 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8121 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('h','Microform');
8122 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('h','b','1','1','SMD');
8123 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Aperture card');
8124 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Microfilm cartridge');
8125 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Microfilm cassette');
8126 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Microfilm reel');
8127 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Microfiche');
8128 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Microfiche cassette');
8129 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Microopaque');
8130 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
8131 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8132 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('h','d','3','1','Positive/negative');
8133 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Positive');
8134 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Negative');
8135 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
8136 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8137 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('h','e','4','1','Dimensions');
8138 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'8 mm.');
8139 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'16 mm.');
8140 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'35 mm.');
8141 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'70mm.');
8142 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'105 mm.');
8143 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('l',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'3 x 5 in. (8 x 13 cm.)');
8144 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'4 x 6 in. (11 x 15 cm.)');
8145 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'6 x 9 in. (16 x 23 cm.)');
8146 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'3 1/4 x 7 3/8 in. (9 x 19 cm.)');
8147 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8148 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8149 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('h','f','5','4','Reduction ratio range/Reduction ratio');
8150 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Low (1-16x)');
8151 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Normal (16-30x)');
8152 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'High (31-60x)');
8153 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Very high (61-90x)');
8154 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Ultra (90x-)');
8155 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8156 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('v',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Reduction ratio varies');
8157 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('h','g','9','1','Color');
8158 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Black-and-white');
8159 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multicolored');
8160 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
8161 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8162 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8163 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('h','h','10','1','Emulsion on film');
8164 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Silver halide');
8165 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Diazo');
8166 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Vesicular');
8167 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
8168 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8169 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8170 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8171 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('h','i','11','1','Quality assurance target(s)');
8172 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1st gen. master');
8173 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Printing master');
8174 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Service copy');
8175 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed generation');
8176 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8177 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('h','j','12','1','Base of film');
8178 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Safety base, undetermined');
8179 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Safety base, acetate undetermined');
8180 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Safety base, diacetate');
8181 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('l',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Nitrate base');
8182 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed base');
8183 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8184 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Safety base, polyester');
8185 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Safety base, mixed');
8186 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('t',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Safety base, triacetate');
8187 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8188 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8190 -- Non-projected Graphic
8191 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('k','Non-projected Graphic');
8192 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('k','b','1','1','SMD');
8193 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Collage');
8194 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Drawing');
8195 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Painting');
8196 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Photo-mechanical print');
8197 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Photonegative');
8198 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Photoprint');
8199 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Picture');
8200 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Print');
8201 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('l',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Technical drawing');
8202 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Chart');
8203 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Flash/activity card');
8204 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
8205 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8206 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('k','d','3','1','Color');
8207 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'One color');
8208 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Black-and-white');
8209 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multicolored');
8210 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Hand-colored');
8211 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
8212 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8213 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8214 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('k','e','4','1','Primary support material');
8215 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Canvas');
8216 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Bristol board');
8217 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Cardboard/illustration board');
8218 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Glass');
8219 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Synthetics');
8220 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Skins');
8221 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Textile');
8222 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Metal');
8223 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed collection');
8224 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Paper');
8225 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Plaster');
8226 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Hardboard');
8227 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Porcelain');
8228 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Stone');
8229 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('t',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Wood');
8230 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8231 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8232 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('k','f','5','1','Secondary support material');
8233 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Canvas');
8234 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Bristol board');
8235 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Cardboard/illustration board');
8236 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Glass');
8237 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Synthetics');
8238 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Skins');
8239 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Textile');
8240 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Metal');
8241 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed collection');
8242 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Paper');
8243 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Plaster');
8244 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Hardboard');
8245 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Porcelain');
8246 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Stone');
8247 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('t',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Wood');
8248 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8249 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8252 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('m','Motion Picture');
8253 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('m','b','1','1','SMD');
8254 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Film cartridge');
8255 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Film cassette');
8256 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Film reel');
8257 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
8258 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8259 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('m','d','3','1','Color');
8260 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Black-and-white');
8261 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multicolored');
8262 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Hand-colored');
8263 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
8264 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8265 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8266 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('m','e','4','1','Motion picture presentation format');
8267 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Standard sound aperture, reduced frame');
8268 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Nonanamorphic (wide-screen)');
8269 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'3D');
8270 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Anamorphic (wide-screen)');
8271 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other-wide screen format');
8272 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Standard. silent aperture, full frame');
8273 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8274 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8275 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('m','f','5','1','Sound on medium or separate');
8276 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound on medium');
8277 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound separate from medium');
8278 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8279 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('m','g','6','1','Medium for sound');
8280 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Optical sound track on motion picture film');
8281 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic sound track on motion picture film');
8282 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic audio tape in cartridge');
8283 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound disc');
8284 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic audio tape on reel');
8285 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic audio tape in cassette');
8286 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Optical and magnetic sound track on film');
8287 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videotape');
8288 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videodisc');
8289 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8290 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8291 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('m','h','7','1','Dimensions');
8292 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Standard 8 mm.');
8293 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Super 8 mm./single 8 mm.');
8294 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'9.5 mm.');
8295 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'16 mm.');
8296 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'28 mm.');
8297 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'35 mm.');
8298 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'70 mm.');
8299 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8300 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8301 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('m','i','8','1','Configuration of playback channels');
8302 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('k',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
8303 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Monaural');
8304 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8305 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multichannel, surround or quadraphonic');
8306 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Stereophonic');
8307 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8308 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8309 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('m','j','9','1','Production elements');
8310 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Work print');
8311 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Trims');
8312 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Outtakes');
8313 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Rushes');
8314 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixing tracks');
8315 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Title bands/inter-title rolls');
8316 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Production rolls');
8317 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8318 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8320 -- Remote-sensing Image
8321 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('r','Remote-sensing Image');
8322 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('r','b','1','1','SMD');
8323 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
8324 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('r','d','3','1','Altitude of sensor');
8325 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Surface');
8326 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Airborne');
8327 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Spaceborne');
8328 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8329 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8330 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8331 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('r','e','4','1','Attitude of sensor');
8332 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Low oblique');
8333 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'High oblique');
8334 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Vertical');
8335 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8336 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8337 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('r','f','5','1','Cloud cover');
8338 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('0',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'0-09%');
8339 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('1',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'10-19%');
8340 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('2',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'20-29%');
8341 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('3',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'30-39%');
8342 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('4',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'40-49%');
8343 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('5',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'50-59%');
8344 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('6',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'60-69%');
8345 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('7',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'70-79%');
8346 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('8',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'80-89%');
8347 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('9',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'90-100%');
8348 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8349 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8350 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('r','g','6','1','Platform construction type');
8351 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Balloon');
8352 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Aircraft-low altitude');
8353 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Aircraft-medium altitude');
8354 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Aircraft-high altitude');
8355 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Manned spacecraft');
8356 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unmanned spacecraft');
8357 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Land-based remote-sensing device');
8358 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Water surface-based remote-sensing device');
8359 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Submersible remote-sensing device');
8360 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8361 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8362 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8363 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('r','h','7','1','Platform use category');
8364 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Meteorological');
8365 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Surface observing');
8366 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Space observing');
8367 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed uses');
8368 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8369 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8370 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8371 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('r','i','8','1','Sensor type');
8372 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Active');
8373 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Passive');
8374 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8375 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8376 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('r','j','9','2','Data type');
8377 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('aa',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Visible light');
8378 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('da',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Near infrared');
8379 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('db',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Middle infrared');
8380 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('dc',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Far infrared');
8381 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('dd',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Thermal infrared');
8382 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('de',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Shortwave infrared (SWIR)');
8383 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('df',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Reflective infrared');
8384 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('dv',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Combinations');
8385 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('dz',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other infrared data');
8386 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('ga',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sidelooking airborne radar (SLAR)');
8387 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('gb',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Synthetic aperture radar (SAR-single frequency)');
8388 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('gc',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'SAR-multi-frequency (multichannel)');
8389 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('gd',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'SAR-like polarization');
8390 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('ge',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'SAR-cross polarization');
8391 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('gf',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Infometric SAR');
8392 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('gg',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Polarmetric SAR');
8393 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('gu',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Passive microwave mapping');
8394 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('gz',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other microwave data');
8395 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('ja',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Far ultraviolet');
8396 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('jb',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Middle ultraviolet');
8397 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('jc',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Near ultraviolet');
8398 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('jv',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Ultraviolet combinations');
8399 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('jz',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other ultraviolet data');
8400 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('ma',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multi-spectral, multidata');
8401 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('mb',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multi-temporal');
8402 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('mm',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Combination of various data types');
8403 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('nn',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8404 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('pa',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sonar-water depth');
8405 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('pb',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sonar-bottom topography images, sidescan');
8406 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('pc',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sonar-bottom topography, near-surface');
8407 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('pd',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sonar-bottom topography, near-bottom');
8408 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('pe',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Seismic surveys');
8409 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('pz',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other acoustical data');
8410 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('ra',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Gravity anomales (general)');
8411 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('rb',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Free-air');
8412 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('rc',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Bouger');
8413 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('rd',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Isostatic');
8414 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('sa',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic field');
8415 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('ta',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Radiometric surveys');
8416 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('uu',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8417 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('zz',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8420 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('s','Sound Recording');
8421 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('s','b','1','1','SMD');
8422 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound disc');
8423 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Cylinder');
8424 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound cartridge');
8425 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound-track film');
8426 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Roll');
8427 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound cassette');
8428 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('t',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound-tape reel');
8429 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
8430 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('w',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Wire recording');
8431 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8432 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('s','d','3','1','Speed');
8433 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'16 rpm');
8434 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'33 1/3 rpm');
8435 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'45 rpm');
8436 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'78 rpm');
8437 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'8 rpm');
8438 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1.4 mps');
8439 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'120 rpm');
8440 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'160 rpm');
8441 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('k',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'15/16 ips');
8442 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('l',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1 7/8 ips');
8443 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'3 3/4 ips');
8444 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'7 1/2 ips');
8445 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'15 ips');
8446 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'30 ips');
8447 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8448 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8449 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('s','e','4','1','Configuration of playback channels');
8450 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Monaural');
8451 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Quadraphonic');
8452 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Stereophonic');
8453 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8454 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8455 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('s','f','5','1','Groove width or pitch');
8456 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Microgroove/fine');
8457 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8458 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Coarse/standard');
8459 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8460 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8461 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('s','g','6','1','Dimensions');
8462 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'3 in.');
8463 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'5 in.');
8464 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'7 in.');
8465 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'10 in.');
8466 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'12 in.');
8467 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'16 in.');
8468 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'4 3/4 in. (12 cm.)');
8469 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'3 7/8 x 2 1/2 in.');
8470 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8471 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'5 1/4 x 3 7/8 in.');
8472 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'2 3/4 x 4 in.');
8473 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8474 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8475 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('s','h','7','1','Tape width');
8476 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('l',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1/8 in.');
8477 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1/4in.');
8478 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8479 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1/2 in.');
8480 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1 in.');
8481 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8482 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8483 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('s','i','8','1','Tape configuration ');
8484 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Full (1) track');
8485 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Half (2) track');
8486 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Quarter (4) track');
8487 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'8 track');
8488 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'12 track');
8489 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'16 track');
8490 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8491 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8492 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8493 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('s','m','12','1','Special playback');
8494 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'NAB standard');
8495 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'CCIR standard');
8496 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Dolby-B encoded, standard Dolby');
8497 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'dbx encoded');
8498 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Digital recording');
8499 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Dolby-A encoded');
8500 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Dolby-C encoded');
8501 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'CX encoded');
8502 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8503 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8504 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8505 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('s','n','13','1','Capture and storage');
8506 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Acoustical capture, direct storage');
8507 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Direct storage, not acoustical');
8508 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Digital storage');
8509 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Analog electrical storage');
8510 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8511 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8514 INSERT INTO config.marc21_physical_characteristic_type_map (ptype_key, label) VALUES ('v','Videorecording');
8515 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('v','b','1','1','SMD');
8516 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videocartridge');
8517 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videodisc');
8518 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videocassette');
8519 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videoreel');
8520 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unspecified');
8521 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8522 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('v','d','3','1','Color');
8523 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Black-and-white');
8524 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multicolored');
8525 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
8526 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8527 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8528 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8529 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('v','e','4','1','Videorecording format');
8530 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Beta');
8531 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'VHS');
8532 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'U-matic');
8533 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'EIAJ');
8534 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Type C');
8535 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Quadruplex');
8536 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Laserdisc');
8537 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'CED');
8538 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Betacam');
8539 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('j',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Betacam SP');
8540 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('k',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Super-VHS');
8541 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'M-II');
8542 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'D-2');
8543 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'8 mm.');
8544 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Hi-8 mm.');
8545 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8546 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('v',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'DVD');
8547 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8548 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('v','f','5','1','Sound on medium or separate');
8549 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound on medium');
8550 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound separate from medium');
8551 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8552 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('v','g','6','1','Medium for sound');
8553 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Optical sound track on motion picture film');
8554 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic sound track on motion picture film');
8555 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('c',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic audio tape in cartridge');
8556 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('d',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Sound disc');
8557 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('e',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic audio tape on reel');
8558 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('f',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Magnetic audio tape in cassette');
8559 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('g',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Optical and magnetic sound track on motion picture film');
8560 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('h',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videotape');
8561 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('i',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Videodisc');
8562 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8563 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8564 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('v','h','7','1','Dimensions');
8565 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'8 mm.');
8566 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1/4 in.');
8567 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('o',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1/2 in.');
8568 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('p',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'1 in.');
8569 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'2 in.');
8570 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('r',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'3/4 in.');
8571 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8572 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8573 INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('v','i','8','1','Configuration of playback channel');
8574 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('k',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Mixed');
8575 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Monaural');
8576 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
8577 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('q',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Multichannel, surround or quadraphonic');
8578 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('s',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Stereophonic');
8579 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
8580 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
8582 -- Fixed Field position data -- 0-based!
8583 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Alph', '006', 'SER', 16, 1, ' ');
8584 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Alph', '008', 'SER', 33, 1, ' ');
8585 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '006', 'BKS', 5, 1, ' ');
8586 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '006', 'COM', 5, 1, ' ');
8587 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '006', 'REC', 5, 1, ' ');
8588 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '006', 'SCO', 5, 1, ' ');
8589 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '006', 'SER', 5, 1, ' ');
8590 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '006', 'VIS', 5, 1, ' ');
8591 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '008', 'BKS', 22, 1, ' ');
8592 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '008', 'COM', 22, 1, ' ');
8593 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '008', 'REC', 22, 1, ' ');
8594 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '008', 'SCO', 22, 1, ' ');
8595 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '008', 'SER', 22, 1, ' ');
8596 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Audn', '008', 'VIS', 22, 1, ' ');
8597 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('BLvl', 'ldr', 'BKS', 7, 1, 'm');
8598 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('BLvl', 'ldr', 'COM', 7, 1, 'm');
8599 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('BLvl', 'ldr', 'MAP', 7, 1, 'm');
8600 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('BLvl', 'ldr', 'MIX', 7, 1, 'c');
8601 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('BLvl', 'ldr', 'REC', 7, 1, 'm');
8602 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('BLvl', 'ldr', 'SCO', 7, 1, 'm');
8603 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('BLvl', 'ldr', 'SER', 7, 1, 's');
8604 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('BLvl', 'ldr', 'VIS', 7, 1, 'm');
8605 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Biog', '006', 'BKS', 17, 1, ' ');
8606 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Biog', '008', 'BKS', 34, 1, ' ');
8607 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Conf', '006', 'BKS', 7, 4, ' ');
8608 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Conf', '006', 'SER', 8, 3, ' ');
8609 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Conf', '008', 'BKS', 24, 4, ' ');
8610 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Conf', '008', 'SER', 25, 3, ' ');
8611 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctrl', 'ldr', 'BKS', 8, 1, ' ');
8612 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctrl', 'ldr', 'COM', 8, 1, ' ');
8613 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctrl', 'ldr', 'MAP', 8, 1, ' ');
8614 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctrl', 'ldr', 'MIX', 8, 1, ' ');
8615 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctrl', 'ldr', 'REC', 8, 1, ' ');
8616 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctrl', 'ldr', 'SCO', 8, 1, ' ');
8617 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctrl', 'ldr', 'SER', 8, 1, ' ');
8618 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctrl', 'ldr', 'VIS', 8, 1, ' ');
8619 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctry', '008', 'BKS', 15, 3, ' ');
8620 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctry', '008', 'COM', 15, 3, ' ');
8621 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctry', '008', 'MAP', 15, 3, ' ');
8622 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctry', '008', 'MIX', 15, 3, ' ');
8623 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctry', '008', 'REC', 15, 3, ' ');
8624 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctry', '008', 'SCO', 15, 3, ' ');
8625 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctry', '008', 'SER', 15, 3, ' ');
8626 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ctry', '008', 'VIS', 15, 3, ' ');
8627 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date1', '008', 'BKS', 7, 4, ' ');
8628 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date1', '008', 'COM', 7, 4, ' ');
8629 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date1', '008', 'MAP', 7, 4, ' ');
8630 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date1', '008', 'MIX', 7, 4, ' ');
8631 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date1', '008', 'REC', 7, 4, ' ');
8632 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date1', '008', 'SCO', 7, 4, ' ');
8633 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date1', '008', 'SER', 7, 4, ' ');
8634 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date1', '008', 'VIS', 7, 4, ' ');
8635 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date2', '008', 'BKS', 11, 4, ' ');
8636 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date2', '008', 'COM', 11, 4, ' ');
8637 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date2', '008', 'MAP', 11, 4, ' ');
8638 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date2', '008', 'MIX', 11, 4, ' ');
8639 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date2', '008', 'REC', 11, 4, ' ');
8640 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date2', '008', 'SCO', 11, 4, ' ');
8641 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date2', '008', 'SER', 11, 4, '9');
8642 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Date2', '008', 'VIS', 11, 4, ' ');
8643 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Desc', 'ldr', 'BKS', 18, 1, ' ');
8644 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Desc', 'ldr', 'COM', 18, 1, ' ');
8645 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Desc', 'ldr', 'MAP', 18, 1, ' ');
8646 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Desc', 'ldr', 'MIX', 18, 1, ' ');
8647 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Desc', 'ldr', 'REC', 18, 1, ' ');
8648 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Desc', 'ldr', 'SCO', 18, 1, ' ');
8649 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Desc', 'ldr', 'SER', 18, 1, ' ');
8650 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Desc', 'ldr', 'VIS', 18, 1, ' ');
8651 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('DtSt', '008', 'BKS', 6, 1, ' ');
8652 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('DtSt', '008', 'COM', 6, 1, ' ');
8653 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('DtSt', '008', 'MAP', 6, 1, ' ');
8654 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('DtSt', '008', 'MIX', 6, 1, ' ');
8655 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('DtSt', '008', 'REC', 6, 1, ' ');
8656 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('DtSt', '008', 'SCO', 6, 1, ' ');
8657 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('DtSt', '008', 'SER', 6, 1, 'c');
8658 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('DtSt', '008', 'VIS', 6, 1, ' ');
8659 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('ELvl', 'ldr', 'BKS', 17, 1, ' ');
8660 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('ELvl', 'ldr', 'COM', 17, 1, ' ');
8661 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('ELvl', 'ldr', 'MAP', 17, 1, ' ');
8662 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('ELvl', 'ldr', 'MIX', 17, 1, ' ');
8663 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('ELvl', 'ldr', 'REC', 17, 1, ' ');
8664 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('ELvl', 'ldr', 'SCO', 17, 1, ' ');
8665 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('ELvl', 'ldr', 'SER', 17, 1, ' ');
8666 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('ELvl', 'ldr', 'VIS', 17, 1, ' ');
8667 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Fest', '006', 'BKS', 13, 1, '0');
8668 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Fest', '008', 'BKS', 30, 1, '0');
8669 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '006', 'BKS', 6, 1, ' ');
8670 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '006', 'MAP', 12, 1, ' ');
8671 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '006', 'MIX', 6, 1, ' ');
8672 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '006', 'REC', 6, 1, ' ');
8673 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '006', 'SCO', 6, 1, ' ');
8674 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '006', 'SER', 6, 1, ' ');
8675 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '006', 'VIS', 12, 1, ' ');
8676 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '008', 'BKS', 23, 1, ' ');
8677 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '008', 'MAP', 29, 1, ' ');
8678 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '008', 'MIX', 23, 1, ' ');
8679 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '008', 'REC', 23, 1, ' ');
8680 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '008', 'SCO', 23, 1, ' ');
8681 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '008', 'SER', 23, 1, ' ');
8682 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Form', '008', 'VIS', 29, 1, ' ');
8683 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '006', 'BKS', 11, 1, ' ');
8684 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '006', 'COM', 11, 1, ' ');
8685 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '006', 'MAP', 11, 1, ' ');
8686 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '006', 'SER', 11, 1, ' ');
8687 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '006', 'VIS', 11, 1, ' ');
8688 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '008', 'BKS', 28, 1, ' ');
8689 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '008', 'COM', 28, 1, ' ');
8690 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '008', 'MAP', 28, 1, ' ');
8691 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '008', 'SER', 28, 1, ' ');
8692 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('GPub', '008', 'VIS', 28, 1, ' ');
8693 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ills', '006', 'BKS', 1, 4, ' ');
8694 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Ills', '008', 'BKS', 18, 4, ' ');
8695 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Indx', '006', 'BKS', 14, 1, '0');
8696 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Indx', '006', 'MAP', 14, 1, '0');
8697 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Indx', '008', 'BKS', 31, 1, '0');
8698 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Indx', '008', 'MAP', 31, 1, '0');
8699 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Lang', '008', 'BKS', 35, 3, ' ');
8700 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Lang', '008', 'COM', 35, 3, ' ');
8701 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Lang', '008', 'MAP', 35, 3, ' ');
8702 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Lang', '008', 'MIX', 35, 3, ' ');
8703 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Lang', '008', 'REC', 35, 3, ' ');
8704 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Lang', '008', 'SCO', 35, 3, ' ');
8705 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Lang', '008', 'SER', 35, 3, ' ');
8706 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Lang', '008', 'VIS', 35, 3, ' ');
8707 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('LitF', '006', 'BKS', 16, 1, '0');
8708 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('LitF', '008', 'BKS', 33, 1, '0');
8709 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('MRec', '008', 'BKS', 38, 1, ' ');
8710 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('MRec', '008', 'COM', 38, 1, ' ');
8711 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('MRec', '008', 'MAP', 38, 1, ' ');
8712 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('MRec', '008', 'MIX', 38, 1, ' ');
8713 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('MRec', '008', 'REC', 38, 1, ' ');
8714 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('MRec', '008', 'SCO', 38, 1, ' ');
8715 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('MRec', '008', 'SER', 38, 1, ' ');
8716 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('MRec', '008', 'VIS', 38, 1, ' ');
8717 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('S/L', '006', 'SER', 17, 1, '0');
8718 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('S/L', '008', 'SER', 34, 1, '0');
8719 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('TMat', '006', 'VIS', 16, 1, ' ');
8720 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('TMat', '008', 'VIS', 33, 1, ' ');
8721 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Type', 'ldr', 'BKS', 6, 1, 'a');
8722 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Type', 'ldr', 'COM', 6, 1, 'm');
8723 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Type', 'ldr', 'MAP', 6, 1, 'e');
8724 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Type', 'ldr', 'MIX', 6, 1, 'p');
8725 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Type', 'ldr', 'REC', 6, 1, 'i');
8726 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Type', 'ldr', 'SCO', 6, 1, 'c');
8727 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Type', 'ldr', 'SER', 6, 1, 'a');
8728 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Type', 'ldr', 'VIS', 6, 1, 'g');
8730 CREATE OR REPLACE FUNCTION biblio.marc21_record_type( rid BIGINT ) RETURNS config.marc21_rec_type_map AS $func$
8737 retval config.marc21_rec_type_map%ROWTYPE;
8739 SELECT * INTO ldr FROM metabib.full_rec WHERE record = rid AND tag = 'LDR' LIMIT 1;
8741 IF ldr.id IS NULL THEN
8742 SELECT * INTO retval FROM config.marc21_rec_type_map WHERE code = 'BKS';
8746 SELECT * INTO tval_rec FROM config.marc21_ff_pos_map WHERE fixed_field = 'Type' LIMIT 1; -- They're all the same
8747 SELECT * INTO bval_rec FROM config.marc21_ff_pos_map WHERE fixed_field = 'BLvl' LIMIT 1; -- They're all the same
8750 tval := SUBSTRING( ldr.value, tval_rec.start_pos + 1, tval_rec.length );
8751 bval := SUBSTRING( ldr.value, bval_rec.start_pos + 1, bval_rec.length );
8753 -- RAISE NOTICE 'type %, blvl %, ldr %', tval, bval, ldr.value;
8755 SELECT * INTO retval FROM config.marc21_rec_type_map WHERE type_val LIKE '%' || tval || '%' AND blvl_val LIKE '%' || bval || '%';
8758 IF retval.code IS NULL THEN
8759 SELECT * INTO retval FROM config.marc21_rec_type_map WHERE code = 'BKS';
8764 $func$ LANGUAGE PLPGSQL;
8766 CREATE OR REPLACE FUNCTION biblio.marc21_extract_fixed_field( rid BIGINT, ff TEXT ) RETURNS TEXT AS $func$
8773 rtype := (biblio.marc21_record_type( rid )).code;
8774 FOR ff_pos IN SELECT * FROM config.marc21_ff_pos_map WHERE fixed_field = ff AND rec_type = rtype ORDER BY tag DESC LOOP
8775 FOR tag_data IN SELECT * FROM metabib.full_rec WHERE tag = UPPER(ff_pos.tag) AND record = rid LOOP
8776 val := SUBSTRING( tag_data.value, ff_pos.start_pos + 1, ff_pos.length );
8779 val := REPEAT( ff_pos.default_val, ff_pos.length );
8785 $func$ LANGUAGE PLPGSQL;
8787 CREATE TYPE biblio.marc21_physical_characteristics AS ( id INT, record BIGINT, ptype TEXT, subfield INT, value INT );
8788 CREATE OR REPLACE FUNCTION biblio.marc21_physical_characteristics( rid BIGINT ) RETURNS SETOF biblio.marc21_physical_characteristics AS $func$
8792 ptype config.marc21_physical_characteristic_type_map%ROWTYPE;
8793 psf config.marc21_physical_characteristic_subfield_map%ROWTYPE;
8794 pval config.marc21_physical_characteristic_value_map%ROWTYPE;
8795 retval biblio.marc21_physical_characteristics%ROWTYPE;
8798 SELECT * INTO _007 FROM metabib.full_rec WHERE record = rid AND tag = '007' LIMIT 1;
8800 IF _007.id IS NOT NULL THEN
8801 SELECT * INTO ptype FROM config.marc21_physical_characteristic_type_map WHERE ptype_key = SUBSTRING( _007.value, 1, 1 );
8803 IF ptype.ptype_key IS NOT NULL THEN
8804 FOR psf IN SELECT * FROM config.marc21_physical_characteristic_subfield_map WHERE ptype_key = ptype.ptype_key LOOP
8805 SELECT * INTO pval FROM config.marc21_physical_characteristic_value_map WHERE ptype_subfield = psf.id AND value = SUBSTRING( _007.value, psf.start_pos + 1, psf.length );
8807 IF pval.id IS NOT NULL THEN
8810 retval.record := rid;
8811 retval.ptype := ptype.ptype_key;
8812 retval.subfield := psf.id;
8813 retval.value := pval.id;
8823 $func$ LANGUAGE PLPGSQL;
8825 DROP VIEW IF EXISTS money.open_usr_circulation_summary;
8826 DROP VIEW IF EXISTS money.open_usr_summary;
8827 DROP VIEW IF EXISTS money.open_billable_xact_summary;
8829 -- The view should supply defaults for numeric (amount) columns
8830 CREATE OR REPLACE VIEW money.billable_xact_summary AS
8835 COALESCE(credit.amount, 0.0::numeric) AS total_paid,
8836 credit.payment_ts AS last_payment_ts,
8837 credit.note AS last_payment_note,
8838 credit.payment_type AS last_payment_type,
8839 COALESCE(debit.amount, 0.0::numeric) AS total_owed,
8840 debit.billing_ts AS last_billing_ts,
8841 debit.note AS last_billing_note,
8842 debit.billing_type AS last_billing_type,
8843 COALESCE(debit.amount, 0.0::numeric) - COALESCE(credit.amount, 0.0::numeric) AS balance_owed,
8844 p.relname AS xact_type
8845 FROM money.billable_xact xact
8846 JOIN pg_class p ON xact.tableoid = p.oid
8848 SELECT billing.xact,
8849 sum(billing.amount) AS amount,
8850 max(billing.billing_ts) AS billing_ts,
8851 last(billing.note) AS note,
8852 last(billing.billing_type) AS billing_type
8854 WHERE billing.voided IS FALSE
8855 GROUP BY billing.xact
8856 ) debit ON xact.id = debit.xact
8858 SELECT payment_view.xact,
8859 sum(payment_view.amount) AS amount,
8860 max(payment_view.payment_ts) AS payment_ts,
8861 last(payment_view.note) AS note,
8862 last(payment_view.payment_type) AS payment_type
8863 FROM money.payment_view
8864 WHERE payment_view.voided IS FALSE
8865 GROUP BY payment_view.xact
8866 ) credit ON xact.id = credit.xact
8867 ORDER BY debit.billing_ts, credit.payment_ts;
8869 CREATE OR REPLACE VIEW money.open_billable_xact_summary AS
8870 SELECT * FROM money.billable_xact_summary_location_view
8871 WHERE xact_finish IS NULL;
8873 CREATE OR REPLACE VIEW money.open_usr_circulation_summary AS
8876 SUM(total_paid) AS total_paid,
8877 SUM(total_owed) AS total_owed,
8878 SUM(balance_owed) AS balance_owed
8879 FROM money.materialized_billable_xact_summary
8880 WHERE xact_type = 'circulation' AND xact_finish IS NULL
8883 CREATE OR REPLACE VIEW money.usr_summary AS
8886 sum(total_paid) AS total_paid,
8887 sum(total_owed) AS total_owed,
8888 sum(balance_owed) AS balance_owed
8889 FROM money.materialized_billable_xact_summary
8892 CREATE OR REPLACE VIEW money.open_usr_summary AS
8895 sum(total_paid) AS total_paid,
8896 sum(total_owed) AS total_owed,
8897 sum(balance_owed) AS balance_owed
8898 FROM money.materialized_billable_xact_summary
8899 WHERE xact_finish IS NULL
8902 -- CREATE RULE protect_mfhd_delete AS ON DELETE TO serial.record_entry DO INSTEAD UPDATE serial.record_entry SET deleted = true WHERE old.id = serial.record_entry.id;
8904 CREATE TABLE config.biblio_fingerprint (
8905 id SERIAL PRIMARY KEY,
8907 xpath TEXT NOT NULL,
8908 first_word BOOL NOT NULL DEFAULT FALSE,
8909 format TEXT NOT NULL DEFAULT 'marcxml'
8912 INSERT INTO config.biblio_fingerprint (name, xpath, format)
8915 '//marc:datafield[@tag="700"]/marc:subfield[@code="t"]|' ||
8916 '//marc:datafield[@tag="240"]/marc:subfield[@code="a"]|' ||
8917 '//marc:datafield[@tag="242"]/marc:subfield[@code="a"]|' ||
8918 '//marc:datafield[@tag="246"]/marc:subfield[@code="a"]|' ||
8919 '//marc:datafield[@tag="245"]/marc:subfield[@code="a"]',
8923 INSERT INTO config.biblio_fingerprint (name, xpath, format, first_word)
8926 '//marc:datafield[@tag="700" and ./*[@code="t"]]/marc:subfield[@code="a"]|'
8927 '//marc:datafield[@tag="100"]/marc:subfield[@code="a"]|'
8928 '//marc:datafield[@tag="110"]/marc:subfield[@code="a"]|'
8929 '//marc:datafield[@tag="111"]/marc:subfield[@code="a"]|'
8930 '//marc:datafield[@tag="260"]/marc:subfield[@code="b"]',
8935 CREATE OR REPLACE FUNCTION biblio.extract_quality ( marc TEXT, best_lang TEXT, best_type TEXT ) RETURNS INT AS $func$
8948 IF marc IS NULL OR marc = '' THEN
8952 -- First, the count of tags
8953 qual := ARRAY_UPPER(oils_xpath('*[local-name()="datafield"]', marc), 1);
8955 -- now go through a bunch of pain to get the record type
8956 IF best_type IS NOT NULL THEN
8957 ldr := (oils_xpath('//*[local-name()="leader"]/text()', marc))[1];
8959 IF ldr IS NOT NULL THEN
8960 SELECT * INTO tval_rec FROM config.marc21_ff_pos_map WHERE fixed_field = 'Type' LIMIT 1; -- They're all the same
8961 SELECT * INTO bval_rec FROM config.marc21_ff_pos_map WHERE fixed_field = 'BLvl' LIMIT 1; -- They're all the same
8964 tval := SUBSTRING( ldr, tval_rec.start_pos + 1, tval_rec.length );
8965 bval := SUBSTRING( ldr, bval_rec.start_pos + 1, bval_rec.length );
8967 -- RAISE NOTICE 'type %, blvl %, ldr %', tval, bval, ldr;
8969 SELECT * INTO type_map FROM config.marc21_rec_type_map WHERE type_val LIKE '%' || tval || '%' AND blvl_val LIKE '%' || bval || '%';
8971 IF type_map.code IS NOT NULL THEN
8972 IF best_type = type_map.code THEN
8973 qual := qual + qual / 2;
8976 FOR ff_pos IN SELECT * FROM config.marc21_ff_pos_map WHERE fixed_field = 'Lang' AND rec_type = type_map.code ORDER BY tag DESC LOOP
8977 ff_tag_data := SUBSTRING((oils_xpath('//*[@tag="' || ff_pos.tag || '"]/text()',marc))[1], ff_pos.start_pos + 1, ff_pos.length);
8978 IF ff_tag_data = best_lang THEN
8986 -- Now look for some quality metrics
8988 IF ARRAY_UPPER(oils_xpath('//*[@tag="040"]/*[@code="a" and contains(.,"DLC")]', marc), 1) = 1 THEN
8993 IF (oils_xpath('//*[@tag="003"]/text()', marc))[1] ~* E'oclo?c' THEN
9000 $func$ LANGUAGE PLPGSQL;
9002 CREATE OR REPLACE FUNCTION biblio.extract_fingerprint ( marc text ) RETURNS TEXT AS $func$
9004 idx config.biblio_fingerprint%ROWTYPE;
9005 xfrm config.xml_transform%ROWTYPE;
9007 transformed_xml TEXT;
9009 xml_node_list TEXT[];
9011 output_text TEXT := '';
9014 IF marc IS NULL OR marc = '' THEN
9018 -- Loop over the indexing entries
9019 FOR idx IN SELECT * FROM config.biblio_fingerprint ORDER BY format, id LOOP
9021 SELECT INTO xfrm * from config.xml_transform WHERE name = idx.format;
9023 -- See if we can skip the XSLT ... it's expensive
9024 IF prev_xfrm IS NULL OR prev_xfrm <> xfrm.name THEN
9025 -- Can't skip the transform
9026 IF xfrm.xslt <> '---' THEN
9027 transformed_xml := oils_xslt_process(marc,xfrm.xslt);
9029 transformed_xml := marc;
9032 prev_xfrm := xfrm.name;
9035 raw_text := COALESCE(
9043 ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]]
9052 raw_text := REGEXP_REPLACE(raw_text, E'\\[.+?\\]', E'');
9053 raw_text := REGEXP_REPLACE(raw_text, E'\\mthe\\M|\\man?d?d\\M', E'', 'g'); -- arg! the pain!
9055 IF idx.first_word IS TRUE THEN
9056 raw_text := REGEXP_REPLACE(raw_text, E'^(\\w+).*?$', E'\\1');
9059 output_text := output_text || REGEXP_REPLACE(raw_text, E'\\s+', '', 'g');
9066 $func$ LANGUAGE PLPGSQL;
9068 -- BEFORE UPDATE OR INSERT trigger for biblio.record_entry
9069 CREATE OR REPLACE FUNCTION biblio.fingerprint_trigger () RETURNS TRIGGER AS $func$
9072 -- For TG_ARGV, first param is language (like 'eng'), second is record type (like 'BKS')
9074 IF NEW.deleted IS TRUE THEN -- we don't much care, then, do we?
9078 NEW.fingerprint := biblio.extract_fingerprint(NEW.marc);
9079 NEW.quality := biblio.extract_quality(NEW.marc, TG_ARGV[0], TG_ARGV[1]);
9084 $func$ LANGUAGE PLPGSQL;
9086 CREATE TABLE config.internal_flag (
9087 name TEXT PRIMARY KEY,
9089 enabled BOOL NOT NULL DEFAULT FALSE
9091 INSERT INTO config.internal_flag (name) VALUES ('ingest.metarecord_mapping.skip_on_insert');
9092 INSERT INTO config.internal_flag (name) VALUES ('ingest.reingest.force_on_same_marc');
9093 INSERT INTO config.internal_flag (name) VALUES ('ingest.reingest.skip_located_uri');
9094 INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_located_uri');
9095 INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_metabib_full_rec');
9096 INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_metabib_rec_descriptor');
9097 INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_metabib_field_entry');
9098 INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_authority_linking');
9100 CREATE TABLE authority.bib_linking (
9101 id BIGSERIAL PRIMARY KEY,
9102 bib BIGINT NOT NULL REFERENCES biblio.record_entry (id),
9103 authority BIGINT NOT NULL REFERENCES authority.record_entry (id)
9105 CREATE INDEX authority_bl_bib_idx ON authority.bib_linking ( bib );
9106 CREATE UNIQUE INDEX authority_bl_bib_authority_once_idx ON authority.bib_linking ( authority, bib );
9108 CREATE OR REPLACE FUNCTION public.remove_paren_substring( TEXT ) RETURNS TEXT AS $func$
9109 SELECT regexp_replace($1, $$\([^)]+\)$$, '', 'g');
9110 $func$ LANGUAGE SQL STRICT IMMUTABLE;
9112 CREATE OR REPLACE FUNCTION biblio.map_authority_linking (bibid BIGINT, marc TEXT) RETURNS BIGINT AS $func$
9113 DELETE FROM authority.bib_linking WHERE bib = $1;
9114 INSERT INTO authority.bib_linking (bib, authority)
9117 FROM ( SELECT DISTINCT $1 AS bib,
9118 BTRIM(remove_paren_substring(txt))::BIGINT AS authority
9119 FROM explode_array(oils_xpath('//*[@code="0"]/text()',$2)) x(txt)
9120 WHERE BTRIM(remove_paren_substring(txt)) ~ $re$^\d+$$re$
9121 ) y JOIN authority.record_entry r ON r.id = y.authority;
9123 $func$ LANGUAGE SQL;
9125 CREATE OR REPLACE FUNCTION metabib.reingest_metabib_rec_descriptor( bib_id BIGINT ) RETURNS VOID AS $func$
9127 DELETE FROM metabib.rec_descriptor WHERE record = bib_id;
9128 INSERT INTO metabib.rec_descriptor (record, item_type, item_form, bib_level, control_type, enc_level, audience, lit_form, type_mat, cat_form, pub_status, item_lang, vr_format, date1, date2)
9130 biblio.marc21_extract_fixed_field( bib_id, 'Type' ),
9131 biblio.marc21_extract_fixed_field( bib_id, 'Form' ),
9132 biblio.marc21_extract_fixed_field( bib_id, 'BLvl' ),
9133 biblio.marc21_extract_fixed_field( bib_id, 'Ctrl' ),
9134 biblio.marc21_extract_fixed_field( bib_id, 'ELvl' ),
9135 biblio.marc21_extract_fixed_field( bib_id, 'Audn' ),
9136 biblio.marc21_extract_fixed_field( bib_id, 'LitF' ),
9137 biblio.marc21_extract_fixed_field( bib_id, 'TMat' ),
9138 biblio.marc21_extract_fixed_field( bib_id, 'Desc' ),
9139 biblio.marc21_extract_fixed_field( bib_id, 'DtSt' ),
9140 biblio.marc21_extract_fixed_field( bib_id, 'Lang' ),
9142 FROM biblio.marc21_physical_characteristics( bib_id) p
9143 JOIN config.marc21_physical_characteristic_subfield_map s ON (s.id = p.subfield)
9144 JOIN config.marc21_physical_characteristic_value_map v ON (v.id = p.value)
9145 WHERE p.ptype = 'v' AND s.subfield = 'e' ),
9146 biblio.marc21_extract_fixed_field( bib_id, 'Date1'),
9147 biblio.marc21_extract_fixed_field( bib_id, 'Date2');
9151 $func$ LANGUAGE PLPGSQL;
9153 CREATE TABLE config.metabib_class (
9154 name TEXT PRIMARY KEY,
9155 label TEXT NOT NULL UNIQUE
9158 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'keyword', oils_i18n_gettext('keyword', 'Keyword', 'cmc', 'label') );
9159 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'title', oils_i18n_gettext('title', 'Title', 'cmc', 'label') );
9160 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'author', oils_i18n_gettext('author', 'Author', 'cmc', 'label') );
9161 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'subject', oils_i18n_gettext('subject', 'Subject', 'cmc', 'label') );
9162 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'series', oils_i18n_gettext('series', 'Series', 'cmc', 'label') );
9164 CREATE TABLE metabib.facet_entry (
9165 id BIGSERIAL PRIMARY KEY,
9166 source BIGINT NOT NULL,
9171 CREATE OR REPLACE FUNCTION metabib.reingest_metabib_field_entries( bib_id BIGINT ) RETURNS VOID AS $func$
9174 ind_data metabib.field_entry_template%ROWTYPE;
9176 FOR fclass IN SELECT * FROM config.metabib_class LOOP
9177 -- RAISE NOTICE 'Emptying out %', fclass.name;
9178 EXECUTE $$DELETE FROM metabib.$$ || fclass.name || $$_field_entry WHERE source = $$ || bib_id;
9181 DELETE FROM metabib.facet_entry WHERE source = bib_id;
9183 FOR ind_data IN SELECT * FROM biblio.extract_metabib_field_entry( bib_id ) LOOP
9184 IF ind_data.field < 0 THEN
9185 ind_data.field = -1 * ind_data.field;
9186 INSERT INTO metabib.facet_entry (field, source, value)
9187 VALUES (ind_data.field, ind_data.source, ind_data.value);
9190 INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value)
9192 quote_literal(ind_data.field) || $$, $$ ||
9193 quote_literal(ind_data.source) || $$, $$ ||
9194 quote_literal(ind_data.value) ||
9202 $func$ LANGUAGE PLPGSQL;
9204 CREATE OR REPLACE FUNCTION biblio.extract_located_uris( bib_id BIGINT, marcxml TEXT, editor_id INT ) RETURNS VOID AS $func$
9218 uris := oils_xpath('//*[@tag="856" and (@ind1="4" or @ind1="1") and (@ind2="0" or @ind2="1")]',marcxml);
9219 IF ARRAY_UPPER(uris,1) > 0 THEN
9220 FOR i IN 1 .. ARRAY_UPPER(uris, 1) LOOP
9221 -- First we pull info out of the 856
9224 uri_href := (oils_xpath('//*[@code="u"]/text()',uri_xml))[1];
9225 CONTINUE WHEN uri_href IS NULL;
9227 uri_label := (oils_xpath('//*[@code="y"]/text()|//*[@code="3"]/text()|//*[@code="u"]/text()',uri_xml))[1];
9228 CONTINUE WHEN uri_label IS NULL;
9230 uri_owner := (oils_xpath('//*[@code="9"]/text()|//*[@code="w"]/text()|//*[@code="n"]/text()',uri_xml))[1];
9231 CONTINUE WHEN uri_owner IS NULL;
9233 uri_use := (oils_xpath('//*[@code="z"]/text()|//*[@code="2"]/text()|//*[@code="n"]/text()',uri_xml))[1];
9235 uri_owner := REGEXP_REPLACE(uri_owner, $re$^.*?\((\w+)\).*$$re$, E'\\1');
9237 SELECT id INTO uri_owner_id FROM actor.org_unit WHERE shortname = uri_owner;
9238 CONTINUE WHEN NOT FOUND;
9240 -- now we look for a matching uri
9241 SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction = uri_use AND active;
9242 IF NOT FOUND THEN -- create one
9243 INSERT INTO asset.uri (label, href, use_restriction) VALUES (uri_label, uri_href, uri_use);
9244 SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction = uri_use AND active;
9247 -- we need a call number to link through
9248 SELECT id INTO uri_cn_id FROM asset.call_number WHERE owning_lib = uri_owner_id AND record = bib_id AND label = '##URI##' AND NOT deleted;
9250 INSERT INTO asset.call_number (owning_lib, record, create_date, edit_date, creator, editor, label)
9251 VALUES (uri_owner_id, bib_id, 'now', 'now', editor_id, editor_id, '##URI##');
9252 SELECT id INTO uri_cn_id FROM asset.call_number WHERE owning_lib = uri_owner_id AND record = bib_id AND label = '##URI##' AND NOT deleted;
9255 -- now, link them if they're not already
9256 SELECT id INTO uri_map_id FROM asset.uri_call_number_map WHERE call_number = uri_cn_id AND uri = uri_id;
9258 INSERT INTO asset.uri_call_number_map (call_number, uri) VALUES (uri_cn_id, uri_id);
9266 $func$ LANGUAGE PLPGSQL;
9268 CREATE OR REPLACE FUNCTION metabib.remap_metarecord_for_bib( bib_id BIGINT, fp TEXT ) RETURNS BIGINT AS $func$
9272 tmp_mr metabib.metarecord%ROWTYPE;
9273 deleted_mrs BIGINT[];
9276 DELETE FROM metabib.metarecord_source_map WHERE source = bib_id; -- Rid ourselves of the search-estimate-killing linkage
9278 FOR tmp_mr IN SELECT m.* FROM metabib.metarecord m JOIN metabib.metarecord_source_map s ON (s.metarecord = m.id) WHERE s.source = bib_id LOOP
9280 IF old_mr IS NULL AND fp = tmp_mr.fingerprint THEN -- Find the first fingerprint-matching
9281 old_mr := tmp_mr.id;
9283 SELECT COUNT(*) INTO source_count FROM metabib.metarecord_source_map WHERE metarecord = tmp_mr.id;
9284 IF source_count = 0 THEN -- No other records
9285 deleted_mrs := ARRAY_APPEND(deleted_mrs, tmp_mr.id);
9286 DELETE FROM metabib.metarecord WHERE id = tmp_mr.id;
9292 IF old_mr IS NULL THEN -- we found no suitable, preexisting MR based on old source maps
9293 SELECT id INTO old_mr FROM metabib.metarecord WHERE fingerprint = fp; -- is there one for our current fingerprint?
9294 IF old_mr IS NULL THEN -- nope, create one and grab its id
9295 INSERT INTO metabib.metarecord ( fingerprint, master_record ) VALUES ( fp, bib_id );
9296 SELECT id INTO old_mr FROM metabib.metarecord WHERE fingerprint = fp;
9297 ELSE -- indeed there is. update it with a null cache and recalcualated master record
9298 UPDATE metabib.metarecord
9300 master_record = ( SELECT id FROM biblio.record_entry WHERE fingerprint = fp ORDER BY quality DESC LIMIT 1)
9303 ELSE -- there was one we already attached to, update its mods cache and master_record
9304 UPDATE metabib.metarecord
9306 master_record = ( SELECT id FROM biblio.record_entry WHERE fingerprint = fp ORDER BY quality DESC LIMIT 1)
9310 INSERT INTO metabib.metarecord_source_map (metarecord, source) VALUES (old_mr, bib_id); -- new source mapping
9312 IF ARRAY_UPPER(deleted_mrs,1) > 0 THEN
9313 UPDATE action.hold_request SET target = old_mr WHERE target IN ( SELECT explode_array(deleted_mrs) ) AND hold_type = 'M'; -- if we had to delete any MRs above, make sure their holds are moved
9319 $func$ LANGUAGE PLPGSQL;
9321 CREATE OR REPLACE FUNCTION metabib.reingest_metabib_full_rec( bib_id BIGINT ) RETURNS VOID AS $func$
9323 DELETE FROM metabib.real_full_rec WHERE record = bib_id;
9324 INSERT INTO metabib.real_full_rec (record, tag, ind1, ind2, subfield, value)
9325 SELECT record, tag, ind1, ind2, subfield, value FROM biblio.flatten_marc( bib_id );
9329 $func$ LANGUAGE PLPGSQL;
9331 -- AFTER UPDATE OR INSERT trigger for biblio.record_entry
9332 CREATE OR REPLACE FUNCTION biblio.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$
9335 IF NEW.deleted IS TRUE THEN -- If this bib is deleted
9336 DELETE FROM metabib.metarecord_source_map WHERE source = NEW.id; -- Rid ourselves of the search-estimate-killing linkage
9337 DELETE FROM authority.bib_linking WHERE bib = NEW.id; -- Avoid updating fields in bibs that are no longer visible
9338 RETURN NEW; -- and we're done
9341 IF TG_OP = 'UPDATE' THEN -- re-ingest?
9342 PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled;
9344 IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change
9349 -- Record authority linking
9350 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_linking' AND enabled;
9352 PERFORM biblio.map_authority_linking( NEW.id, NEW.marc );
9355 -- Flatten and insert the mfr data
9356 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_metabib_full_rec' AND enabled;
9358 PERFORM metabib.reingest_metabib_full_rec(NEW.id);
9359 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_metabib_rec_descriptor' AND enabled;
9361 PERFORM metabib.reingest_metabib_rec_descriptor(NEW.id);
9365 -- Gather and insert the field entry data
9366 PERFORM metabib.reingest_metabib_field_entries(NEW.id);
9368 -- Located URI magic
9369 IF TG_OP = 'INSERT' THEN
9370 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_located_uri' AND enabled;
9372 PERFORM biblio.extract_located_uris( NEW.id, NEW.marc, NEW.editor );
9375 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_located_uri' AND enabled;
9377 PERFORM biblio.extract_located_uris( NEW.id, NEW.marc, NEW.editor );
9381 -- (re)map metarecord-bib linking
9382 IF TG_OP = 'INSERT' THEN -- if not deleted and performing an insert, check for the flag
9383 PERFORM * FROM config.internal_flag WHERE name = 'ingest.metarecord_mapping.skip_on_insert' AND enabled;
9385 PERFORM metabib.remap_metarecord_for_bib( NEW.id, NEW.fingerprint );
9387 ELSE -- we're doing an update, and we're not deleted, remap
9388 PERFORM metabib.remap_metarecord_for_bib( NEW.id, NEW.fingerprint );
9393 $func$ LANGUAGE PLPGSQL;
9395 CREATE TRIGGER fingerprint_tgr BEFORE INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.fingerprint_trigger ('eng','BKS');
9396 CREATE TRIGGER aaa_indexing_ingest_or_delete AFTER INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.indexing_ingest_or_delete ();
9398 DROP TRIGGER IF EXISTS zzz_update_materialized_simple_rec_delete_tgr ON biblio.record_entry;
9400 CREATE OR REPLACE FUNCTION oils_xpath_table ( key TEXT, document_field TEXT, relation_name TEXT, xpaths TEXT, criteria TEXT )
9401 RETURNS SETOF RECORD AS $func$
9410 xpath_list := STRING_TO_ARRAY( xpaths, '|' );
9412 select_list := ARRAY_APPEND( select_list, key || '::INT AS key' );
9414 FOR i IN 1 .. ARRAY_UPPER(xpath_list,1) LOOP
9415 select_list := ARRAY_APPEND(
9425 WHEN xpath_list[i] ~ $re$/[^/[]*@[^/]+$$re$ OR xpath_list[i] ~ $re$text\(\)$$re$ THEN xpath_list[i]
9426 ELSE xpath_list[i] || '//text()'
9430 $sel$ || document_field || $sel$
9438 where_list := ARRAY_APPEND(
9440 'c_' || i || ' IS NOT NULL'
9446 SELECT $q$ || ARRAY_TO_STRING( select_list, ', ' ) || $q$ FROM $q$ || relation_name || $q$ WHERE ($q$ || criteria || $q$)
9447 )x WHERE $q$ || ARRAY_TO_STRING( where_list, ' AND ' );
9448 -- RAISE NOTICE 'query: %', q;
9450 FOR out_record IN EXECUTE q LOOP
9451 RETURN NEXT out_record;
9456 $func$ LANGUAGE PLPGSQL;
9458 CREATE OR REPLACE FUNCTION vandelay.ingest_items ( import_id BIGINT, attr_def_id BIGINT ) RETURNS SETOF vandelay.import_item AS $$
9469 deposit_amount TEXT;
9482 tmp_attr_set RECORD;
9483 attr_set vandelay.import_item%ROWTYPE;
9489 SELECT * INTO attr_def FROM vandelay.import_item_attr_definition WHERE id = attr_def_id;
9493 attr_set.definition := attr_def.id;
9495 -- Build the combined XPath
9499 WHEN attr_def.owning_lib IS NULL THEN 'null()'
9500 WHEN LENGTH( attr_def.owning_lib ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.owning_lib || '"]'
9501 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.owning_lib
9506 WHEN attr_def.circ_lib IS NULL THEN 'null()'
9507 WHEN LENGTH( attr_def.circ_lib ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_lib || '"]'
9508 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_lib
9513 WHEN attr_def.call_number IS NULL THEN 'null()'
9514 WHEN LENGTH( attr_def.call_number ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.call_number || '"]'
9515 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.call_number
9520 WHEN attr_def.copy_number IS NULL THEN 'null()'
9521 WHEN LENGTH( attr_def.copy_number ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.copy_number || '"]'
9522 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.copy_number
9527 WHEN attr_def.status IS NULL THEN 'null()'
9528 WHEN LENGTH( attr_def.status ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.status || '"]'
9529 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.status
9534 WHEN attr_def.location IS NULL THEN 'null()'
9535 WHEN LENGTH( attr_def.location ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.location || '"]'
9536 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.location
9541 WHEN attr_def.circulate IS NULL THEN 'null()'
9542 WHEN LENGTH( attr_def.circulate ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circulate || '"]'
9543 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circulate
9548 WHEN attr_def.deposit IS NULL THEN 'null()'
9549 WHEN LENGTH( attr_def.deposit ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.deposit || '"]'
9550 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.deposit
9555 WHEN attr_def.deposit_amount IS NULL THEN 'null()'
9556 WHEN LENGTH( attr_def.deposit_amount ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.deposit_amount || '"]'
9557 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.deposit_amount
9562 WHEN attr_def.ref IS NULL THEN 'null()'
9563 WHEN LENGTH( attr_def.ref ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.ref || '"]'
9564 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.ref
9569 WHEN attr_def.holdable IS NULL THEN 'null()'
9570 WHEN LENGTH( attr_def.holdable ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.holdable || '"]'
9571 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.holdable
9576 WHEN attr_def.price IS NULL THEN 'null()'
9577 WHEN LENGTH( attr_def.price ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.price || '"]'
9578 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.price
9583 WHEN attr_def.barcode IS NULL THEN 'null()'
9584 WHEN LENGTH( attr_def.barcode ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.barcode || '"]'
9585 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.barcode
9590 WHEN attr_def.circ_modifier IS NULL THEN 'null()'
9591 WHEN LENGTH( attr_def.circ_modifier ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_modifier || '"]'
9592 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_modifier
9597 WHEN attr_def.circ_as_type IS NULL THEN 'null()'
9598 WHEN LENGTH( attr_def.circ_as_type ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_as_type || '"]'
9599 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_as_type
9604 WHEN attr_def.alert_message IS NULL THEN 'null()'
9605 WHEN LENGTH( attr_def.alert_message ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.alert_message || '"]'
9606 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.alert_message
9611 WHEN attr_def.opac_visible IS NULL THEN 'null()'
9612 WHEN LENGTH( attr_def.opac_visible ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.opac_visible || '"]'
9613 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.opac_visible
9618 WHEN attr_def.pub_note IS NULL THEN 'null()'
9619 WHEN LENGTH( attr_def.pub_note ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.pub_note || '"]'
9620 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.pub_note
9624 WHEN attr_def.priv_note IS NULL THEN 'null()'
9625 WHEN LENGTH( attr_def.priv_note ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.priv_note || '"]'
9626 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.priv_note
9631 owning_lib || '|' ||
9633 call_number || '|' ||
9634 copy_number || '|' ||
9639 deposit_amount || '|' ||
9644 circ_modifier || '|' ||
9645 circ_as_type || '|' ||
9646 alert_message || '|' ||
9651 -- RAISE NOTICE 'XPath: %', xpath;
9655 FROM oils_xpath_table( 'id', 'marc', 'vandelay.queued_bib_record', xpath, 'id = ' || import_id )
9656 AS t( id INT, ol TEXT, clib TEXT, cn TEXT, cnum TEXT, cs TEXT, cl TEXT, circ TEXT,
9657 dep TEXT, dep_amount TEXT, r TEXT, hold TEXT, pr TEXT, bc TEXT, circ_mod TEXT,
9658 circ_as TEXT, amessage TEXT, note TEXT, pnote TEXT, opac_vis TEXT )
9661 tmp_attr_set.pr = REGEXP_REPLACE(tmp_attr_set.pr, E'[^0-9\\.]', '', 'g');
9662 tmp_attr_set.dep_amount = REGEXP_REPLACE(tmp_attr_set.dep_amount, E'[^0-9\\.]', '', 'g');
9664 tmp_attr_set.pr := NULLIF( tmp_attr_set.pr, '' );
9665 tmp_attr_set.dep_amount := NULLIF( tmp_attr_set.dep_amount, '' );
9667 SELECT id INTO attr_set.owning_lib FROM actor.org_unit WHERE shortname = UPPER(tmp_attr_set.ol); -- INT
9668 SELECT id INTO attr_set.circ_lib FROM actor.org_unit WHERE shortname = UPPER(tmp_attr_set.clib); -- INT
9669 SELECT id INTO attr_set.status FROM config.copy_status WHERE LOWER(name) = LOWER(tmp_attr_set.cs); -- INT
9671 SELECT id INTO attr_set.location
9672 FROM asset.copy_location
9673 WHERE LOWER(name) = LOWER(tmp_attr_set.cl)
9674 AND asset.copy_location.owning_lib = COALESCE(attr_set.owning_lib, attr_set.circ_lib); -- INT
9676 attr_set.circulate :=
9677 LOWER( SUBSTRING( tmp_attr_set.circ, 1, 1)) IN ('t','y','1')
9678 OR LOWER(tmp_attr_set.circ) = 'circulating'; -- BOOL
9681 LOWER( SUBSTRING( tmp_attr_set.dep, 1, 1 ) ) IN ('t','y','1')
9682 OR LOWER(tmp_attr_set.dep) = 'deposit'; -- BOOL
9684 attr_set.holdable :=
9685 LOWER( SUBSTRING( tmp_attr_set.hold, 1, 1 ) ) IN ('t','y','1')
9686 OR LOWER(tmp_attr_set.hold) = 'holdable'; -- BOOL
9688 attr_set.opac_visible :=
9689 LOWER( SUBSTRING( tmp_attr_set.opac_vis, 1, 1 ) ) IN ('t','y','1')
9690 OR LOWER(tmp_attr_set.opac_vis) = 'visible'; -- BOOL
9693 LOWER( SUBSTRING( tmp_attr_set.r, 1, 1 ) ) IN ('t','y','1')
9694 OR LOWER(tmp_attr_set.r) = 'reference'; -- BOOL
9696 attr_set.copy_number := tmp_attr_set.cnum::INT; -- INT,
9697 attr_set.deposit_amount := tmp_attr_set.dep_amount::NUMERIC(6,2); -- NUMERIC(6,2),
9698 attr_set.price := tmp_attr_set.pr::NUMERIC(8,2); -- NUMERIC(8,2),
9700 attr_set.call_number := tmp_attr_set.cn; -- TEXT
9701 attr_set.barcode := tmp_attr_set.bc; -- TEXT,
9702 attr_set.circ_modifier := tmp_attr_set.circ_mod; -- TEXT,
9703 attr_set.circ_as_type := tmp_attr_set.circ_as; -- TEXT,
9704 attr_set.alert_message := tmp_attr_set.amessage; -- TEXT,
9705 attr_set.pub_note := tmp_attr_set.note; -- TEXT,
9706 attr_set.priv_note := tmp_attr_set.pnote; -- TEXT,
9707 attr_set.alert_message := tmp_attr_set.amessage; -- TEXT,
9709 RETURN NEXT attr_set;
9718 $$ LANGUAGE PLPGSQL;
9720 CREATE OR REPLACE FUNCTION vandelay.ingest_bib_items ( ) RETURNS TRIGGER AS $func$
9723 item_data vandelay.import_item%ROWTYPE;
9726 SELECT item_attr_def INTO attr_def FROM vandelay.bib_queue WHERE id = NEW.queue;
9728 FOR item_data IN SELECT * FROM vandelay.ingest_items( NEW.id::BIGINT, attr_def ) LOOP
9729 INSERT INTO vandelay.import_item (
9753 item_data.definition,
9754 item_data.owning_lib,
9756 item_data.call_number,
9757 item_data.copy_number,
9760 item_data.circulate,
9762 item_data.deposit_amount,
9767 item_data.circ_modifier,
9768 item_data.circ_as_type,
9769 item_data.alert_message,
9771 item_data.priv_note,
9772 item_data.opac_visible
9778 $func$ LANGUAGE PLPGSQL;
9780 CREATE OR REPLACE FUNCTION acq.create_acq_seq ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
9783 CREATE SEQUENCE acq.$$ || sch || $$_$$ || tbl || $$_pkey_seq;
9787 $creator$ LANGUAGE 'plpgsql';
9789 CREATE OR REPLACE FUNCTION acq.create_acq_history ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
9792 CREATE TABLE acq.$$ || sch || $$_$$ || tbl || $$_history (
9793 audit_id BIGINT PRIMARY KEY,
9794 audit_time TIMESTAMP WITH TIME ZONE NOT NULL,
9795 audit_action TEXT NOT NULL,
9796 LIKE $$ || sch || $$.$$ || tbl || $$
9801 $creator$ LANGUAGE 'plpgsql';
9803 CREATE OR REPLACE FUNCTION acq.create_acq_func ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
9806 CREATE OR REPLACE FUNCTION acq.audit_$$ || sch || $$_$$ || tbl || $$_func ()
9807 RETURNS TRIGGER AS $func$
9809 INSERT INTO acq.$$ || sch || $$_$$ || tbl || $$_history
9810 SELECT nextval('acq.$$ || sch || $$_$$ || tbl || $$_pkey_seq'),
9816 $func$ LANGUAGE 'plpgsql';
9820 $creator$ LANGUAGE 'plpgsql';
9822 CREATE OR REPLACE FUNCTION acq.create_acq_update_trigger ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
9825 CREATE TRIGGER audit_$$ || sch || $$_$$ || tbl || $$_update_trigger
9826 AFTER UPDATE OR DELETE ON $$ || sch || $$.$$ || tbl || $$ FOR EACH ROW
9827 EXECUTE PROCEDURE acq.audit_$$ || sch || $$_$$ || tbl || $$_func ();
9831 $creator$ LANGUAGE 'plpgsql';
9833 CREATE OR REPLACE FUNCTION acq.create_acq_lifecycle ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
9836 CREATE OR REPLACE VIEW acq.$$ || sch || $$_$$ || tbl || $$_lifecycle AS
9837 SELECT -1, now() as audit_time, '-' as audit_action, *
9838 FROM $$ || sch || $$.$$ || tbl || $$
9841 FROM acq.$$ || sch || $$_$$ || tbl || $$_history;
9845 $creator$ LANGUAGE 'plpgsql';
9849 CREATE OR REPLACE FUNCTION acq.create_acq_auditor ( sch TEXT, tbl TEXT ) RETURNS BOOL AS $creator$
9851 PERFORM acq.create_acq_seq(sch, tbl);
9852 PERFORM acq.create_acq_history(sch, tbl);
9853 PERFORM acq.create_acq_func(sch, tbl);
9854 PERFORM acq.create_acq_update_trigger(sch, tbl);
9855 PERFORM acq.create_acq_lifecycle(sch, tbl);
9858 $creator$ LANGUAGE 'plpgsql';
9860 SELECT acq.create_acq_auditor ( 'acq', 'purchase_order' );
9861 CREATE INDEX acq_po_hist_id_idx ON acq.acq_purchase_order_history( id );
9863 SELECT acq.create_acq_auditor ( 'acq', 'lineitem' );
9864 CREATE INDEX acq_lineitem_hist_id_idx ON acq.acq_lineitem_history( id );
9866 CREATE OR REPLACE VIEW acq.fund_debit_total AS
9867 SELECT fund.id AS fund,
9868 fund_debit.encumbrance AS encumbrance,
9869 SUM( COALESCE( fund_debit.amount, 0 ) ) AS amount
9870 FROM acq.fund AS fund
9871 LEFT JOIN acq.fund_debit AS fund_debit
9872 ON ( fund.id = fund_debit.fund )
9875 CREATE TABLE acq.debit_attribution (
9876 id INT NOT NULL PRIMARY KEY,
9877 fund_debit INT NOT NULL
9878 REFERENCES acq.fund_debit
9879 DEFERRABLE INITIALLY DEFERRED,
9880 debit_amount NUMERIC NOT NULL,
9881 funding_source_credit INT REFERENCES acq.funding_source_credit
9882 DEFERRABLE INITIALLY DEFERRED,
9883 credit_amount NUMERIC
9886 CREATE INDEX acq_attribution_debit_idx
9887 ON acq.debit_attribution( fund_debit );
9889 CREATE INDEX acq_attribution_credit_idx
9890 ON acq.debit_attribution( funding_source_credit );
9892 CREATE OR REPLACE FUNCTION acq.attribute_debits() RETURNS VOID AS $$
9894 Function to attribute expenditures and encumbrances to funding source credits,
9895 and thereby to funding sources.
9897 Read the debits in chonological order, attributing each one to one or
9898 more funding source credits. Constraints:
9900 1. Don't attribute more to a credit than the amount of the credit.
9902 2. For a given fund, don't attribute more to a funding source than the
9903 source has allocated to that fund.
9905 3. Attribute debits to credits with deadlines before attributing them to
9906 credits without deadlines. Otherwise attribute to the earliest credits
9907 first, based on the deadline date when present, or on the effective date
9908 when there is no deadline. Use funding_source_credit.id as a tie-breaker.
9909 This ordering is defined by an ORDER BY clause on the view
9910 acq.ordered_funding_source_credit.
9912 Start by truncating the table acq.debit_attribution. Then insert a row
9913 into that table for each attribution. If a debit cannot be fully
9914 attributed, insert a row for the unattributable balance, with the
9915 funding_source_credit and credit_amount columns NULL.
9918 curr_fund_source_bal RECORD;
9919 seqno INT; -- sequence num for credits applicable to a fund
9920 fund_credit RECORD; -- current row in temp t_fund_credit table
9921 fc RECORD; -- used for loading t_fund_credit table
9922 sc RECORD; -- used for loading t_fund_credit table
9924 -- Used exclusively in the main loop:
9926 deb RECORD; -- current row from acq.fund_debit table
9927 curr_credit_bal RECORD; -- current row from temp t_credit table
9928 debit_balance NUMERIC; -- amount left to attribute for current debit
9929 conv_debit_balance NUMERIC; -- debit balance in currency of the fund
9930 attr_amount NUMERIC; -- amount being attributed, in currency of debit
9931 conv_attr_amount NUMERIC; -- amount being attributed, in currency of source
9932 conv_cred_balance NUMERIC; -- credit_balance in the currency of the fund
9933 conv_alloc_balance NUMERIC; -- allocated balance in the currency of the fund
9934 attrib_count INT; -- populates id of acq.debit_attribution
9937 -- Load a temporary table. For each combination of fund and funding source,
9938 -- load an entry with the total amount allocated to that fund by that source.
9939 -- This sum may reflect transfers as well as original allocations. We will
9940 -- reduce this balance whenever we attribute debits to it.
9942 CREATE TEMP TABLE t_fund_source_bal
9946 funding_source AS source,
9947 sum( amount ) AS balance
9956 CREATE INDEX t_fund_source_bal_idx
9957 ON t_fund_source_bal( fund, source );
9958 -------------------------------------------------------------------------------
9960 -- Load another temporary table. For each fund, load zero or more
9961 -- funding source credits from which that fund can get money.
9963 CREATE TEMP TABLE t_fund_credit (
9970 SELECT DISTINCT fund
9971 FROM acq.fund_allocation
9973 LOOP -- Loop over the funds
9979 acq.ordered_funding_source_credit AS ofsc
9981 ofsc.funding_source IN
9983 SELECT funding_source
9984 FROM acq.fund_allocation
9985 WHERE fund = fc.fund
9991 LOOP -- Add each credit to the list
9992 INSERT INTO t_fund_credit (
10001 --RAISE NOTICE 'Fund % credit %', fc.fund, sc.id;
10002 seqno := seqno + 1;
10003 END LOOP; -- Loop over credits for a given fund
10004 END LOOP; -- Loop over funds
10006 CREATE INDEX t_fund_credit_idx
10007 ON t_fund_credit( fund, seq );
10008 -------------------------------------------------------------------------------
10010 -- Load yet another temporary table. This one is a list of funding source
10011 -- credits, with their balances. We shall reduce those balances as we
10012 -- attribute debits to them.
10014 CREATE TEMP TABLE t_credit
10018 fsc.funding_source AS source,
10019 fsc.amount AS balance,
10020 fs.currency_type AS currency_type
10022 acq.funding_source_credit AS fsc,
10023 acq.funding_source fs
10025 fsc.funding_source = fs.id
10026 AND fsc.amount > 0;
10028 CREATE INDEX t_credit_idx
10029 ON t_credit( credit );
10031 -------------------------------------------------------------------------------
10033 -- Now that we have loaded the lookup tables: loop through the debits,
10034 -- attributing each one to one or more funding source credits.
10036 truncate table acq.debit_attribution;
10054 --RAISE NOTICE 'Debit %, fund %', deb.id, deb.fund;
10056 debit_balance := deb.amount;
10058 -- Loop over the funding source credits that are eligible
10059 -- to pay for this debit
10071 --RAISE NOTICE ' Examining credit %', fund_credit.credit;
10073 -- Look up the balance for this credit. If it's zero, then
10074 -- it's not useful, so treat it as if you didn't find it.
10075 -- (Actually there shouldn't be any zero balances in the table,
10076 -- but we check just to make sure.)
10079 INTO curr_credit_bal
10082 credit = fund_credit.credit
10085 IF curr_credit_bal IS NULL THEN
10087 -- This credit is exhausted; try the next one.
10093 -- At this point we have an applicable credit with some money left.
10094 -- Now see if the relevant funding_source has any money left.
10096 -- Look up the balance of the allocation for this combination of
10097 -- fund and source. If you find such an entry, but it has a zero
10098 -- balance, then it's not useful, so treat it as unfound.
10099 -- (Actually there shouldn't be any zero balances in the table,
10100 -- but we check just to make sure.)
10103 INTO curr_fund_source_bal
10104 FROM t_fund_source_bal
10107 AND source = curr_credit_bal.source
10110 IF curr_fund_source_bal IS NULL THEN
10112 -- This fund/source doesn't exist or is already exhausted,
10113 -- so we can't use this credit. Go on to the next one.
10118 -- Convert the available balances to the currency of the fund
10120 conv_alloc_balance := curr_fund_source_bal.balance * acq.exchange_ratio(
10121 curr_credit_bal.currency_type, deb.currency_type );
10122 conv_cred_balance := curr_credit_bal.balance * acq.exchange_ratio(
10123 curr_credit_bal.currency_type, deb.currency_type );
10125 -- Determine how much we can attribute to this credit: the minimum
10126 -- of the debit amount, the fund/source balance, and the
10129 --RAISE NOTICE ' deb bal %', debit_balance;
10130 --RAISE NOTICE ' source % balance %', curr_credit_bal.source, conv_alloc_balance;
10131 --RAISE NOTICE ' credit % balance %', curr_credit_bal.credit, conv_cred_balance;
10133 conv_attr_amount := NULL;
10134 attr_amount := debit_balance;
10136 IF attr_amount > conv_alloc_balance THEN
10137 attr_amount := conv_alloc_balance;
10138 conv_attr_amount := curr_fund_source_bal.balance;
10140 IF attr_amount > conv_cred_balance THEN
10141 attr_amount := conv_cred_balance;
10142 conv_attr_amount := curr_credit_bal.balance;
10145 -- If we're attributing all of one of the balances, then that's how
10146 -- much we will deduct from the balances, and we already captured
10147 -- that amount above. Otherwise we must convert the amount of the
10148 -- attribution from the currency of the fund back to the currency of
10149 -- the funding source.
10151 IF conv_attr_amount IS NULL THEN
10152 conv_attr_amount := attr_amount * acq.exchange_ratio(
10153 deb.currency_type, curr_credit_bal.currency_type );
10156 -- Insert a row to record the attribution
10158 attrib_count := attrib_count + 1;
10159 INSERT INTO acq.debit_attribution (
10163 funding_source_credit,
10169 curr_credit_bal.credit,
10173 -- Subtract the attributed amount from the various balances
10175 debit_balance := debit_balance - attr_amount;
10176 curr_fund_source_bal.balance := curr_fund_source_bal.balance - conv_attr_amount;
10178 IF curr_fund_source_bal.balance <= 0 THEN
10180 -- This allocation is exhausted. Delete it so
10181 -- that we don't waste time looking at it again.
10183 DELETE FROM t_fund_source_bal
10185 fund = curr_fund_source_bal.fund
10186 AND source = curr_fund_source_bal.source;
10188 UPDATE t_fund_source_bal
10189 SET balance = balance - conv_attr_amount
10191 fund = curr_fund_source_bal.fund
10192 AND source = curr_fund_source_bal.source;
10195 IF curr_credit_bal.balance <= 0 THEN
10197 -- This funding source credit is exhausted. Delete it
10198 -- so that we don't waste time looking at it again.
10200 --DELETE FROM t_credit
10202 -- credit = curr_credit_bal.credit;
10204 DELETE FROM t_fund_credit
10206 credit = curr_credit_bal.credit;
10209 SET balance = curr_credit_bal.balance
10211 credit = curr_credit_bal.credit;
10214 -- Are we done with this debit yet?
10216 IF debit_balance <= 0 THEN
10217 EXIT; -- We've fully attributed this debit; stop looking at credits.
10219 END LOOP; -- End loop over credits
10221 IF debit_balance <> 0 THEN
10223 -- We weren't able to attribute this debit, or at least not
10224 -- all of it. Insert a row for the unattributed balance.
10226 attrib_count := attrib_count + 1;
10227 INSERT INTO acq.debit_attribution (
10231 funding_source_credit,
10241 END LOOP; -- End of loop over debits
10243 $$ LANGUAGE 'plpgsql';
10245 CREATE OR REPLACE FUNCTION extract_marc_field ( TEXT, BIGINT, TEXT, TEXT ) RETURNS TEXT AS $$
10251 SELECT regexp_replace(
10253 $q$ || quote_literal($3) || $q$,
10257 $q$ || quote_literal($4) || $q$,
10260 FROM $q$ || $1 || $q$
10261 WHERE id = $q$ || $2;
10263 EXECUTE query INTO output;
10265 -- RAISE NOTICE 'query: %, output; %', query, output;
10269 $$ LANGUAGE PLPGSQL IMMUTABLE;
10271 CREATE OR REPLACE FUNCTION extract_marc_field ( TEXT, BIGINT, TEXT ) RETURNS TEXT AS $$
10272 SELECT extract_marc_field($1,$2,$3,'');
10273 $$ LANGUAGE SQL IMMUTABLE;
10275 CREATE OR REPLACE FUNCTION asset.merge_record_assets( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$
10277 moved_objects INT := 0;
10278 source_cn asset.call_number%ROWTYPE;
10279 target_cn asset.call_number%ROWTYPE;
10280 metarec metabib.metarecord%ROWTYPE;
10281 hold action.hold_request%ROWTYPE;
10282 ser_rec serial.record_entry%ROWTYPE;
10283 uri_count INT := 0;
10285 uri_datafield TEXT;
10286 uri_text TEXT := '';
10289 -- move any 856 entries on records that have at least one MARC-mapped URI entry
10290 SELECT INTO uri_count COUNT(*)
10291 FROM asset.uri_call_number_map m
10292 JOIN asset.call_number cn ON (m.call_number = cn.id)
10293 WHERE cn.record = source_record;
10295 IF uri_count > 0 THEN
10297 SELECT COUNT(*) INTO counter
10298 FROM oils_xpath_table(
10301 'biblio.record_entry',
10303 'id=' || source_record
10304 ) as t(i int,c text);
10306 FOR i IN 1 .. counter LOOP
10307 SELECT '<datafield xmlns="http://www.loc.gov/MARC21/slim"' ||
10309 ' ind1="' || FIRST(ind1) || '"' ||
10310 ' ind2="' || FIRST(ind2) || '">' ||
10313 '<subfield code="' || subfield || '">' ||
10316 regexp_replace(data,'&','&','g'),
10322 ) || '</datafield>' INTO uri_datafield
10323 FROM oils_xpath_table(
10326 'biblio.record_entry',
10327 '//*[@tag="856"][position()=' || i || ']/@ind1|' ||
10328 '//*[@tag="856"][position()=' || i || ']/@ind2|' ||
10329 '//*[@tag="856"][position()=' || i || ']/*/@code|' ||
10330 '//*[@tag="856"][position()=' || i || ']/*[@code]',
10331 'id=' || source_record
10332 ) as t(id int,ind1 text, ind2 text,subfield text,data text);
10334 uri_text := uri_text || uri_datafield;
10337 IF uri_text <> '' THEN
10338 UPDATE biblio.record_entry
10339 SET marc = regexp_replace(marc,'(</[^>]*record>)', uri_text || E'\\1')
10340 WHERE id = target_record;
10345 -- Find and move metarecords to the target record
10346 SELECT INTO metarec *
10347 FROM metabib.metarecord
10348 WHERE master_record = source_record;
10351 UPDATE metabib.metarecord
10352 SET master_record = target_record,
10354 WHERE id = metarec.id;
10356 moved_objects := moved_objects + 1;
10359 -- Find call numbers attached to the source ...
10360 FOR source_cn IN SELECT * FROM asset.call_number WHERE record = source_record LOOP
10362 SELECT INTO target_cn *
10363 FROM asset.call_number
10364 WHERE label = source_cn.label
10365 AND owning_lib = source_cn.owning_lib
10366 AND record = target_record;
10368 -- ... and if there's a conflicting one on the target ...
10371 -- ... move the copies to that, and ...
10373 SET call_number = target_cn.id
10374 WHERE call_number = source_cn.id;
10376 -- ... move V holds to the move-target call number
10377 FOR hold IN SELECT * FROM action.hold_request WHERE target = source_cn.id AND hold_type = 'V' LOOP
10379 UPDATE action.hold_request
10380 SET target = target_cn.id
10381 WHERE id = hold.id;
10383 moved_objects := moved_objects + 1;
10388 -- ... just move the call number to the target record
10389 UPDATE asset.call_number
10390 SET record = target_record
10391 WHERE id = source_cn.id;
10394 moved_objects := moved_objects + 1;
10397 -- Find T holds targeting the source record ...
10398 FOR hold IN SELECT * FROM action.hold_request WHERE target = source_record AND hold_type = 'T' LOOP
10400 -- ... and move them to the target record
10401 UPDATE action.hold_request
10402 SET target = target_record
10403 WHERE id = hold.id;
10405 moved_objects := moved_objects + 1;
10408 -- Find serial records targeting the source record ...
10409 FOR ser_rec IN SELECT * FROM serial.record_entry WHERE record = source_record LOOP
10410 -- ... and move them to the target record
10411 UPDATE serial.record_entry
10412 SET record = target_record
10413 WHERE id = ser_rec.id;
10415 moved_objects := moved_objects + 1;
10418 -- Finally, "delete" the source record
10419 DELETE FROM biblio.record_entry WHERE id = source_record;
10421 -- That's all, folks!
10422 RETURN moved_objects;
10424 $func$ LANGUAGE plpgsql;
10426 CREATE OR REPLACE FUNCTION acq.transfer_fund(
10428 old_amount IN NUMERIC, -- in currency of old fund
10430 new_amount IN NUMERIC, -- in currency of new fund
10432 xfer_note IN TEXT -- to be recorded in acq.fund_transfer
10433 -- ,funding_source_in IN INT -- if user wants to specify a funding source (see notes)
10434 ) RETURNS VOID AS $$
10435 /* -------------------------------------------------------------------------------
10437 Function to transfer money from one fund to another.
10439 A transfer is represented as a pair of entries in acq.fund_allocation, with a
10440 negative amount for the old (losing) fund and a positive amount for the new
10441 (gaining) fund. In some cases there may be more than one such pair of entries
10442 in order to pull the money from different funding sources, or more specifically
10443 from different funding source credits. For each such pair there is also an
10444 entry in acq.fund_transfer.
10446 Since funding_source is a non-nullable column in acq.fund_allocation, we must
10447 choose a funding source for the transferred money to come from. This choice
10448 must meet two constraints, so far as possible:
10450 1. The amount transferred from a given funding source must not exceed the
10451 amount allocated to the old fund by the funding source. To that end we
10452 compare the amount being transferred to the amount allocated.
10454 2. We shouldn't transfer money that has already been spent or encumbered, as
10455 defined by the funding attribution process. We attribute expenses to the
10456 oldest funding source credits first. In order to avoid transferring that
10457 attributed money, we reverse the priority, transferring from the newest funding
10458 source credits first. There can be no guarantee that this approach will
10459 avoid overcommitting a fund, but no other approach can do any better.
10461 In this context the age of a funding source credit is defined by the
10462 deadline_date for credits with deadline_dates, and by the effective_date for
10463 credits without deadline_dates, with the proviso that credits with deadline_dates
10464 are all considered "older" than those without.
10468 In the signature for this function, there is one last parameter commented out,
10469 named "funding_source_in". Correspondingly, the WHERE clause for the query
10470 driving the main loop has an OR clause commented out, which references the
10471 funding_source_in parameter.
10473 If these lines are uncommented, this function will allow the user optionally to
10474 restrict a fund transfer to a specified funding source. If the source
10475 parameter is left NULL, then there will be no such restriction.
10477 ------------------------------------------------------------------------------- */
10479 same_currency BOOLEAN;
10480 currency_ratio NUMERIC;
10481 old_fund_currency TEXT;
10482 old_remaining NUMERIC; -- in currency of old fund
10483 new_fund_currency TEXT;
10484 new_fund_active BOOLEAN;
10485 new_remaining NUMERIC; -- in currency of new fund
10486 curr_old_amt NUMERIC; -- in currency of old fund
10487 curr_new_amt NUMERIC; -- in currency of new fund
10488 source_addition NUMERIC; -- in currency of funding source
10489 source_deduction NUMERIC; -- in currency of funding source
10490 orig_allocated_amt NUMERIC; -- in currency of funding source
10491 allocated_amt NUMERIC; -- in currency of fund
10497 IF old_fund IS NULL THEN
10498 RAISE EXCEPTION 'acq.transfer_fund: old fund id is NULL';
10501 IF old_amount IS NULL THEN
10502 RAISE EXCEPTION 'acq.transfer_fund: amount to transfer is NULL';
10505 -- The new fund and its amount must be both NULL or both not NULL.
10507 IF new_fund IS NOT NULL AND new_amount IS NULL THEN
10508 RAISE EXCEPTION 'acq.transfer_fund: amount to transfer to receiving fund is NULL';
10511 IF new_fund IS NULL AND new_amount IS NOT NULL THEN
10512 RAISE EXCEPTION 'acq.transfer_fund: receiving fund is NULL, its amount is not NULL';
10515 IF user_id IS NULL THEN
10516 RAISE EXCEPTION 'acq.transfer_fund: user id is NULL';
10519 -- Initialize the amounts to be transferred, each denominated
10520 -- in the currency of its respective fund. They will be
10521 -- reduced on each iteration of the loop.
10523 old_remaining := old_amount;
10524 new_remaining := new_amount;
10526 -- RAISE NOTICE 'Transferring % in fund % to % in fund %',
10527 -- old_amount, old_fund, new_amount, new_fund;
10529 -- Get the currency types of the old and new funds.
10540 IF old_fund_currency IS NULL THEN
10541 RAISE EXCEPTION 'acq.transfer_fund: old fund id % is not defined', old_fund;
10544 IF new_fund IS NOT NULL THEN
10556 IF new_fund_currency IS NULL THEN
10557 RAISE EXCEPTION 'acq.transfer_fund: new fund id % is not defined', new_fund;
10558 ELSIF NOT new_fund_active THEN
10560 -- No point in putting money into a fund from whence you can't spend it
10562 RAISE EXCEPTION 'acq.transfer_fund: new fund id % is inactive', new_fund;
10565 IF new_amount = old_amount THEN
10566 same_currency := true;
10567 currency_ratio := 1;
10570 -- We'll have to translate currency between funds. We presume that
10571 -- the calling code has already applied an appropriate exchange rate,
10572 -- so we'll apply the same conversion to each sub-transfer.
10574 same_currency := false;
10575 currency_ratio := new_amount / old_amount;
10579 -- Identify the funding source(s) from which we want to transfer the money.
10580 -- The principle is that we want to transfer the newest money first, because
10581 -- we spend the oldest money first. The priority for spending is defined
10582 -- by a sort of the view acq.ordered_funding_source_credit.
10587 ofsc.funding_source,
10589 ofsc.amount * acq.exchange_ratio( fs.currency_type, old_fund_currency )
10593 acq.ordered_funding_source_credit AS ofsc,
10594 acq.funding_source fs
10596 ofsc.funding_source = fs.id
10597 and ofsc.funding_source IN
10599 SELECT funding_source
10600 FROM acq.fund_allocation
10601 WHERE fund = old_fund
10605 -- ofsc.funding_source = funding_source_in
10606 -- OR funding_source_in IS NULL
10609 ofsc.sort_priority desc,
10610 ofsc.sort_date desc,
10614 -- Determine how much money the old fund got from this funding source,
10615 -- denominated in the currency types of the source and of the fund.
10616 -- This result may reflect transfers from previous iterations.
10619 COALESCE( sum( amount ), 0 ),
10620 COALESCE( sum( amount )
10621 * acq.exchange_ratio( source.currency_type, old_fund_currency ), 0 )
10623 orig_allocated_amt, -- in currency of the source
10624 allocated_amt -- in currency of the old fund
10626 acq.fund_allocation
10629 and funding_source = source.funding_source;
10631 -- Determine how much to transfer from this credit, in the currency
10632 -- of the fund. Begin with the amount remaining to be attributed:
10634 curr_old_amt := old_remaining;
10636 -- Can't attribute more than was allocated from the fund:
10638 IF curr_old_amt > allocated_amt THEN
10639 curr_old_amt := allocated_amt;
10642 -- Can't attribute more than the amount of the current credit:
10644 IF curr_old_amt > source.converted_amt THEN
10645 curr_old_amt := source.converted_amt;
10648 curr_old_amt := trunc( curr_old_amt, 2 );
10650 old_remaining := old_remaining - curr_old_amt;
10652 -- Determine the amount to be deducted, if any,
10653 -- from the old allocation.
10655 IF old_remaining > 0 THEN
10657 -- In this case we're using the whole allocation, so use that
10658 -- amount directly instead of applying a currency translation
10659 -- and thereby inviting round-off errors.
10661 source_deduction := - orig_allocated_amt;
10663 source_deduction := trunc(
10664 ( - curr_old_amt ) *
10665 acq.exchange_ratio( old_fund_currency, source.currency_type ),
10669 IF source_deduction <> 0 THEN
10671 -- Insert negative allocation for old fund in fund_allocation,
10672 -- converted into the currency of the funding source
10674 INSERT INTO acq.fund_allocation (
10681 source.funding_source,
10685 'Transfer to fund ' || new_fund
10689 IF new_fund IS NOT NULL THEN
10691 -- Determine how much to add to the new fund, in
10692 -- its currency, and how much remains to be added:
10694 IF same_currency THEN
10695 curr_new_amt := curr_old_amt;
10697 IF old_remaining = 0 THEN
10699 -- This is the last iteration, so nothing should be left
10701 curr_new_amt := new_remaining;
10702 new_remaining := 0;
10704 curr_new_amt := trunc( curr_old_amt * currency_ratio, 2 );
10705 new_remaining := new_remaining - curr_new_amt;
10709 -- Determine how much to add, if any,
10710 -- to the new fund's allocation.
10712 IF old_remaining > 0 THEN
10714 -- In this case we're using the whole allocation, so use that amount
10715 -- amount directly instead of applying a currency translation and
10716 -- thereby inviting round-off errors.
10718 source_addition := orig_allocated_amt;
10719 ELSIF source.currency_type = old_fund_currency THEN
10721 -- In this case we don't need a round trip currency translation,
10722 -- thereby inviting round-off errors:
10724 source_addition := curr_old_amt;
10726 source_addition := trunc(
10728 acq.exchange_ratio( new_fund_currency, source.currency_type ),
10732 IF source_addition <> 0 THEN
10734 -- Insert positive allocation for new fund in fund_allocation,
10735 -- converted to the currency of the founding source
10737 INSERT INTO acq.fund_allocation (
10744 source.funding_source,
10748 'Transfer from fund ' || old_fund
10753 IF trunc( curr_old_amt, 2 ) <> 0
10754 OR trunc( curr_new_amt, 2 ) <> 0 THEN
10756 -- Insert row in fund_transfer, using amounts in the currency of the funds
10758 INSERT INTO acq.fund_transfer (
10765 funding_source_credit
10768 trunc( curr_old_amt, 2 ),
10770 trunc( curr_new_amt, 2 ),
10777 if old_remaining <= 0 THEN
10778 EXIT; -- Nothing more to be transferred
10782 $$ LANGUAGE plpgsql;
10784 CREATE OR REPLACE FUNCTION acq.propagate_funds_by_org_unit(
10787 org_unit_id INTEGER
10788 ) RETURNS VOID AS $$
10799 IF old_year IS NULL THEN
10800 RAISE EXCEPTION 'Input year argument is NULL';
10801 ELSIF old_year NOT BETWEEN 2008 and 2200 THEN
10802 RAISE EXCEPTION 'Input year is out of range';
10805 IF user_id IS NULL THEN
10806 RAISE EXCEPTION 'Input user id argument is NULL';
10809 IF org_unit_id IS NULL THEN
10810 RAISE EXCEPTION 'Org unit id argument is NULL';
10812 SELECT TRUE INTO org_found
10813 FROM actor.org_unit
10814 WHERE id = org_unit_id;
10816 IF org_found IS NULL THEN
10817 RAISE EXCEPTION 'Org unit id is invalid';
10821 -- Loop over the applicable funds
10823 FOR old_fund in SELECT * FROM acq.fund
10827 AND org = org_unit_id
10830 INSERT INTO acq.fund (
10838 balance_warning_percent,
10839 balance_stop_percent
10844 old_fund.currency_type,
10848 old_fund.balance_warning_percent,
10849 old_fund.balance_stop_percent
10851 RETURNING id INTO new_id;
10853 WHEN unique_violation THEN
10854 --RAISE NOTICE 'Fund % already propagated', old_fund.id;
10857 --RAISE NOTICE 'Propagating fund % to fund %',
10858 -- old_fund.code, new_id;
10861 $$ LANGUAGE plpgsql;
10863 CREATE OR REPLACE FUNCTION acq.propagate_funds_by_org_tree(
10866 org_unit_id INTEGER
10867 ) RETURNS VOID AS $$
10878 IF old_year IS NULL THEN
10879 RAISE EXCEPTION 'Input year argument is NULL';
10880 ELSIF old_year NOT BETWEEN 2008 and 2200 THEN
10881 RAISE EXCEPTION 'Input year is out of range';
10884 IF user_id IS NULL THEN
10885 RAISE EXCEPTION 'Input user id argument is NULL';
10888 IF org_unit_id IS NULL THEN
10889 RAISE EXCEPTION 'Org unit id argument is NULL';
10891 SELECT TRUE INTO org_found
10892 FROM actor.org_unit
10893 WHERE id = org_unit_id;
10895 IF org_found IS NULL THEN
10896 RAISE EXCEPTION 'Org unit id is invalid';
10900 -- Loop over the applicable funds
10902 FOR old_fund in SELECT * FROM acq.fund
10907 SELECT id FROM actor.org_unit_descendants( org_unit_id )
10911 INSERT INTO acq.fund (
10919 balance_warning_percent,
10920 balance_stop_percent
10925 old_fund.currency_type,
10929 old_fund.balance_warning_percent,
10930 old_fund.balance_stop_percent
10932 RETURNING id INTO new_id;
10934 WHEN unique_violation THEN
10935 --RAISE NOTICE 'Fund % already propagated', old_fund.id;
10938 --RAISE NOTICE 'Propagating fund % to fund %',
10939 -- old_fund.code, new_id;
10942 $$ LANGUAGE plpgsql;
10944 CREATE OR REPLACE FUNCTION acq.rollover_funds_by_org_unit(
10947 org_unit_id INTEGER
10948 ) RETURNS VOID AS $$
10952 new_year INT := old_year + 1;
10954 xfer_amount NUMERIC;
10963 IF old_year IS NULL THEN
10964 RAISE EXCEPTION 'Input year argument is NULL';
10965 ELSIF old_year NOT BETWEEN 2008 and 2200 THEN
10966 RAISE EXCEPTION 'Input year is out of range';
10969 IF user_id IS NULL THEN
10970 RAISE EXCEPTION 'Input user id argument is NULL';
10973 IF org_unit_id IS NULL THEN
10974 RAISE EXCEPTION 'Org unit id argument is NULL';
10977 -- Validate the org unit
10981 FROM actor.org_unit
10982 WHERE id = org_unit_id;
10984 IF org_found IS NULL THEN
10985 RAISE EXCEPTION 'Org unit id % is invalid', org_unit_id;
10989 -- Loop over the propagable funds to identify the details
10990 -- from the old fund plus the id of the new one, if it exists.
10994 oldf.id AS old_fund,
10997 oldf.currency_type,
11000 newf.id AS new_fund_id
11003 LEFT JOIN acq.fund AS newf
11004 ON ( oldf.code = newf.code )
11006 oldf.org = org_unit_id
11007 and oldf.year = old_year
11009 and newf.year = new_year
11011 --RAISE NOTICE 'Processing fund %', roll_fund.old_fund;
11013 IF roll_fund.new_fund_id IS NULL THEN
11015 -- The old fund hasn't been propagated yet. Propagate it now.
11017 INSERT INTO acq.fund (
11025 balance_warning_percent,
11026 balance_stop_percent
11031 roll_fund.currency_type,
11035 roll_fund.balance_warning_percent,
11036 roll_fund.balance_stop_percent
11038 RETURNING id INTO new_fund;
11040 new_fund = roll_fund.new_fund_id;
11043 -- Determine the amount to transfer
11047 FROM acq.fund_spent_balance
11048 WHERE fund = roll_fund.old_fund;
11050 IF xfer_amount <> 0 THEN
11051 IF roll_fund.rollover THEN
11053 -- Transfer balance from old fund to new
11055 --RAISE NOTICE 'Transferring % from fund % to %', xfer_amount, roll_fund.old_fund, new_fund;
11057 PERFORM acq.transfer_fund(
11058 roll_fund.old_fund,
11067 -- Transfer balance from old fund to the void
11069 -- RAISE NOTICE 'Transferring % from fund % to the void', xfer_amount, roll_fund.old_fund;
11071 PERFORM acq.transfer_fund(
11072 roll_fund.old_fund,
11082 IF roll_fund.rollover THEN
11084 -- Move any lineitems from the old fund to the new one
11085 -- where the associated debit is an encumbrance.
11087 -- Any other tables tying expenditure details to funds should
11088 -- receive similar treatment. At this writing there are none.
11090 UPDATE acq.lineitem_detail
11091 SET fund = new_fund
11093 fund = roll_fund.old_fund -- this condition may be redundant
11097 FROM acq.fund_debit
11099 fund = roll_fund.old_fund
11103 -- Move encumbrance debits from the old fund to the new fund
11105 UPDATE acq.fund_debit
11106 SET fund = new_fund
11108 fund = roll_fund.old_fund
11112 -- Mark old fund as inactive, now that we've closed it
11116 WHERE id = roll_fund.old_fund;
11119 $$ LANGUAGE plpgsql;
11121 CREATE OR REPLACE FUNCTION acq.rollover_funds_by_org_tree(
11124 org_unit_id INTEGER
11125 ) RETURNS VOID AS $$
11129 new_year INT := old_year + 1;
11131 xfer_amount NUMERIC;
11140 IF old_year IS NULL THEN
11141 RAISE EXCEPTION 'Input year argument is NULL';
11142 ELSIF old_year NOT BETWEEN 2008 and 2200 THEN
11143 RAISE EXCEPTION 'Input year is out of range';
11146 IF user_id IS NULL THEN
11147 RAISE EXCEPTION 'Input user id argument is NULL';
11150 IF org_unit_id IS NULL THEN
11151 RAISE EXCEPTION 'Org unit id argument is NULL';
11154 -- Validate the org unit
11158 FROM actor.org_unit
11159 WHERE id = org_unit_id;
11161 IF org_found IS NULL THEN
11162 RAISE EXCEPTION 'Org unit id % is invalid', org_unit_id;
11166 -- Loop over the propagable funds to identify the details
11167 -- from the old fund plus the id of the new one, if it exists.
11171 oldf.id AS old_fund,
11174 oldf.currency_type,
11177 newf.id AS new_fund_id
11180 LEFT JOIN acq.fund AS newf
11181 ON ( oldf.code = newf.code )
11183 oldf.year = old_year
11185 AND newf.year = new_year
11187 SELECT id FROM actor.org_unit_descendants( org_unit_id )
11190 --RAISE NOTICE 'Processing fund %', roll_fund.old_fund;
11192 IF roll_fund.new_fund_id IS NULL THEN
11194 -- The old fund hasn't been propagated yet. Propagate it now.
11196 INSERT INTO acq.fund (
11204 balance_warning_percent,
11205 balance_stop_percent
11210 roll_fund.currency_type,
11214 roll_fund.balance_warning_percent,
11215 roll_fund.balance_stop_percent
11217 RETURNING id INTO new_fund;
11219 new_fund = roll_fund.new_fund_id;
11222 -- Determine the amount to transfer
11226 FROM acq.fund_spent_balance
11227 WHERE fund = roll_fund.old_fund;
11229 IF xfer_amount <> 0 THEN
11230 IF roll_fund.rollover THEN
11232 -- Transfer balance from old fund to new
11234 --RAISE NOTICE 'Transferring % from fund % to %', xfer_amount, roll_fund.old_fund, new_fund;
11236 PERFORM acq.transfer_fund(
11237 roll_fund.old_fund,
11246 -- Transfer balance from old fund to the void
11248 -- RAISE NOTICE 'Transferring % from fund % to the void', xfer_amount, roll_fund.old_fund;
11250 PERFORM acq.transfer_fund(
11251 roll_fund.old_fund,
11261 IF roll_fund.rollover THEN
11263 -- Move any lineitems from the old fund to the new one
11264 -- where the associated debit is an encumbrance.
11266 -- Any other tables tying expenditure details to funds should
11267 -- receive similar treatment. At this writing there are none.
11269 UPDATE acq.lineitem_detail
11270 SET fund = new_fund
11272 fund = roll_fund.old_fund -- this condition may be redundant
11276 FROM acq.fund_debit
11278 fund = roll_fund.old_fund
11282 -- Move encumbrance debits from the old fund to the new fund
11284 UPDATE acq.fund_debit
11285 SET fund = new_fund
11287 fund = roll_fund.old_fund
11291 -- Mark old fund as inactive, now that we've closed it
11295 WHERE id = roll_fund.old_fund;
11298 $$ LANGUAGE plpgsql;
11300 CREATE OR REPLACE FUNCTION public.remove_commas( TEXT ) RETURNS TEXT AS $$
11301 SELECT regexp_replace($1, ',', '', 'g');
11302 $$ LANGUAGE SQL STRICT IMMUTABLE;
11304 CREATE OR REPLACE FUNCTION public.remove_whitespace( TEXT ) RETURNS TEXT AS $$
11305 SELECT regexp_replace(normalize_space($1), E'\\s+', '', 'g');
11306 $$ LANGUAGE SQL STRICT IMMUTABLE;
11308 CREATE TABLE acq.distribution_formula_application (
11309 id BIGSERIAL PRIMARY KEY,
11310 creator INT NOT NULL REFERENCES actor.usr(id) DEFERRABLE INITIALLY DEFERRED,
11311 create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
11312 formula INT NOT NULL
11313 REFERENCES acq.distribution_formula(id) DEFERRABLE INITIALLY DEFERRED,
11314 lineitem INT NOT NULL
11315 REFERENCES acq.lineitem( id )
11317 DEFERRABLE INITIALLY DEFERRED
11320 CREATE INDEX acqdfa_df_idx
11321 ON acq.distribution_formula_application(formula);
11322 CREATE INDEX acqdfa_li_idx
11323 ON acq.distribution_formula_application(lineitem);
11324 CREATE INDEX acqdfa_creator_idx
11325 ON acq.distribution_formula_application(creator);
11327 CREATE TABLE acq.user_request_type (
11328 id SERIAL PRIMARY KEY,
11329 label TEXT NOT NULL UNIQUE -- i18n-ize
11332 INSERT INTO acq.user_request_type (id,label) VALUES (1, oils_i18n_gettext('1', 'Books', 'aurt', 'label'));
11333 INSERT INTO acq.user_request_type (id,label) VALUES (2, oils_i18n_gettext('2', 'Journal/Magazine & Newspaper Articles', 'aurt', 'label'));
11334 INSERT INTO acq.user_request_type (id,label) VALUES (3, oils_i18n_gettext('3', 'Audiobooks', 'aurt', 'label'));
11335 INSERT INTO acq.user_request_type (id,label) VALUES (4, oils_i18n_gettext('4', 'Music', 'aurt', 'label'));
11336 INSERT INTO acq.user_request_type (id,label) VALUES (5, oils_i18n_gettext('5', 'DVDs', 'aurt', 'label'));
11338 SELECT SETVAL('acq.user_request_type_id_seq'::TEXT, 6);
11340 CREATE TABLE acq.cancel_reason (
11341 id SERIAL PRIMARY KEY,
11342 org_unit INTEGER NOT NULL REFERENCES actor.org_unit( id )
11343 DEFERRABLE INITIALLY DEFERRED,
11344 label TEXT NOT NULL,
11345 description TEXT NOT NULL,
11346 keep_debits BOOL NOT NULL DEFAULT FALSE,
11347 CONSTRAINT acq_cancel_reason_one_per_org_unit UNIQUE( org_unit, label )
11350 -- Reserve ids 1-999 for stock reasons
11351 -- Reserve ids 1000-1999 for EDI reasons
11352 -- 2000+ are available for staff to create
11354 SELECT SETVAL('acq.cancel_reason_id_seq'::TEXT, 2000);
11356 CREATE TABLE acq.user_request (
11357 id SERIAL PRIMARY KEY,
11358 usr INT NOT NULL REFERENCES actor.usr (id), -- requesting user
11359 hold BOOL NOT NULL DEFAULT TRUE,
11361 pickup_lib INT NOT NULL REFERENCES actor.org_unit (id), -- pickup lib
11362 holdable_formats TEXT, -- nullable, for use in hold creation
11364 email_notify BOOL NOT NULL DEFAULT TRUE,
11365 lineitem INT REFERENCES acq.lineitem (id) ON DELETE CASCADE,
11366 eg_bib BIGINT REFERENCES biblio.record_entry (id) ON DELETE CASCADE,
11367 request_date TIMESTAMPTZ NOT NULL DEFAULT NOW(), -- when they requested it
11368 need_before TIMESTAMPTZ, -- don't create holds after this
11371 request_type INT NOT NULL REFERENCES acq.user_request_type (id),
11376 article_title TEXT,
11377 article_pages TEXT,
11383 cancel_reason INT REFERENCES acq.cancel_reason( id )
11384 DEFERRABLE INITIALLY DEFERRED
11387 CREATE TABLE acq.lineitem_alert_text (
11388 id SERIAL PRIMARY KEY,
11389 code TEXT UNIQUE NOT NULL,
11391 owning_lib INT NOT NULL
11392 REFERENCES actor.org_unit(id)
11393 DEFERRABLE INITIALLY DEFERRED,
11394 CONSTRAINT alert_one_code_per_org UNIQUE (code, owning_lib)
11397 ALTER TABLE acq.lineitem_note
11398 ADD COLUMN alert_text INT REFERENCES acq.lineitem_alert_text(id)
11399 DEFERRABLE INITIALLY DEFERRED;
11401 -- add ON DELETE CASCADE clause
11403 ALTER TABLE acq.lineitem_note
11404 DROP CONSTRAINT lineitem_note_lineitem_fkey;
11406 ALTER TABLE acq.lineitem_note
11407 ADD FOREIGN KEY (lineitem) REFERENCES acq.lineitem( id )
11409 DEFERRABLE INITIALLY DEFERRED;
11411 ALTER TABLE acq.lineitem_note
11412 ADD COLUMN vendor_public BOOLEAN NOT NULL DEFAULT FALSE;
11414 CREATE TABLE acq.invoice_method (
11415 code TEXT PRIMARY KEY,
11416 name TEXT NOT NULL -- i18n-ize
11418 INSERT INTO acq.invoice_method (code,name) VALUES ('EDI',oils_i18n_gettext('EDI', 'EDI', 'acqim', 'name'));
11419 INSERT INTO acq.invoice_method (code,name) VALUES ('PPR',oils_i18n_gettext('PPR', 'Paper', 'acqit', 'name'));
11421 CREATE TABLE acq.invoice_payment_method (
11422 code TEXT PRIMARY KEY,
11426 CREATE TABLE acq.invoice (
11427 id SERIAL PRIMARY KEY,
11428 receiver INT NOT NULL REFERENCES actor.org_unit (id),
11429 provider INT NOT NULL REFERENCES acq.provider (id),
11430 shipper INT NOT NULL REFERENCES acq.provider (id),
11431 recv_date TIMESTAMPTZ NOT NULL DEFAULT NOW(),
11432 recv_method TEXT NOT NULL REFERENCES acq.invoice_method (code) DEFAULT 'EDI',
11433 inv_type TEXT, -- A "type" field is desired, but no idea what goes here
11434 inv_ident TEXT NOT NULL, -- vendor-supplied invoice id/number
11436 payment_method TEXT REFERENCES acq.invoice_payment_method (code)
11437 DEFERRABLE INITIALLY DEFERRED,
11439 complete BOOL NOT NULL DEFAULT FALSE,
11440 CONSTRAINT inv_ident_once_per_provider UNIQUE(provider, inv_ident)
11443 CREATE TABLE acq.invoice_entry (
11444 id SERIAL PRIMARY KEY,
11445 invoice INT NOT NULL REFERENCES acq.invoice (id) ON DELETE CASCADE,
11446 purchase_order INT REFERENCES acq.purchase_order (id) ON UPDATE CASCADE ON DELETE SET NULL,
11447 lineitem INT REFERENCES acq.lineitem (id) ON UPDATE CASCADE ON DELETE SET NULL,
11448 inv_item_count INT NOT NULL, -- How many acqlids did they say they sent
11449 phys_item_count INT, -- and how many did staff count
11451 billed_per_item BOOL,
11452 cost_billed NUMERIC(8,2),
11453 actual_cost NUMERIC(8,2),
11454 amount_paid NUMERIC (8,2)
11457 CREATE TABLE acq.invoice_item_type (
11458 code TEXT PRIMARY KEY,
11459 name TEXT NOT NULL, -- i18n-ize
11460 prorate BOOL NOT NULL DEFAULT FALSE
11463 INSERT INTO acq.invoice_item_type (code,name) VALUES ('TAX',oils_i18n_gettext('TAX', 'Tax', 'aiit', 'name'));
11464 INSERT INTO acq.invoice_item_type (code,name) VALUES ('PRO',oils_i18n_gettext('PRO', 'Processing Fee', 'aiit', 'name'));
11465 INSERT INTO acq.invoice_item_type (code,name) VALUES ('SHP',oils_i18n_gettext('SHP', 'Shipping Charge', 'aiit', 'name'));
11466 INSERT INTO acq.invoice_item_type (code,name) VALUES ('HND',oils_i18n_gettext('HND', 'Handling Charge', 'aiit', 'name'));
11467 INSERT INTO acq.invoice_item_type (code,name) VALUES ('ITM',oils_i18n_gettext('ITM', 'Non-library Item', 'aiit', 'name'));
11468 INSERT INTO acq.invoice_item_type (code,name) VALUES ('SUB',oils_i18n_gettext('SUB', 'Searial Subscription', 'aiit', 'name'));
11470 CREATE TABLE acq.po_item (
11471 id SERIAL PRIMARY KEY,
11472 purchase_order INT REFERENCES acq.purchase_order (id)
11473 ON UPDATE CASCADE ON DELETE SET NULL
11474 DEFERRABLE INITIALLY DEFERRED,
11475 fund_debit INT REFERENCES acq.fund_debit (id)
11476 DEFERRABLE INITIALLY DEFERRED,
11477 inv_item_type TEXT NOT NULL
11478 REFERENCES acq.invoice_item_type (code)
11479 DEFERRABLE INITIALLY DEFERRED,
11483 estimated_cost NUMERIC(8,2),
11484 fund INT REFERENCES acq.fund (id)
11485 DEFERRABLE INITIALLY DEFERRED,
11489 CREATE TABLE acq.invoice_item ( -- for invoice-only debits: taxes/fees/non-bib items/etc
11490 id SERIAL PRIMARY KEY,
11491 invoice INT NOT NULL REFERENCES acq.invoice (id) ON UPDATE CASCADE ON DELETE CASCADE,
11492 purchase_order INT REFERENCES acq.purchase_order (id) ON UPDATE CASCADE ON DELETE SET NULL,
11493 fund_debit INT REFERENCES acq.fund_debit (id),
11494 inv_item_type TEXT NOT NULL REFERENCES acq.invoice_item_type (code),
11498 cost_billed NUMERIC(8,2),
11499 actual_cost NUMERIC(8,2),
11500 fund INT REFERENCES acq.fund (id)
11501 DEFERRABLE INITIALLY DEFERRED,
11502 amount_paid NUMERIC (8,2),
11503 po_item INT REFERENCES acq.po_item (id)
11504 DEFERRABLE INITIALLY DEFERRED,
11508 CREATE TABLE acq.edi_message (
11509 id SERIAL PRIMARY KEY,
11510 account INTEGER REFERENCES acq.edi_account(id)
11511 DEFERRABLE INITIALLY DEFERRED,
11513 create_time TIMESTAMPTZ NOT NULL DEFAULT now(),
11514 translate_time TIMESTAMPTZ,
11515 process_time TIMESTAMPTZ,
11516 error_time TIMESTAMPTZ,
11517 status TEXT NOT NULL DEFAULT 'new'
11518 CONSTRAINT status_value CHECK
11520 'new', -- needs to be translated
11521 'translated', -- needs to be processed
11522 'trans_error', -- error in translation step
11523 'processed', -- needs to have remote_file deleted
11524 'proc_error', -- error in processing step
11525 'delete_error', -- error in deletion
11526 'retry', -- need to retry
11532 purchase_order INT REFERENCES acq.purchase_order
11533 DEFERRABLE INITIALLY DEFERRED,
11534 message_type TEXT NOT NULL CONSTRAINT valid_message_type
11535 CHECK ( message_type IN (
11544 ALTER TABLE actor.org_address ADD COLUMN san TEXT;
11546 ALTER TABLE acq.provider_address
11547 ADD COLUMN fax_phone TEXT;
11549 ALTER TABLE acq.provider_contact_address
11550 ADD COLUMN fax_phone TEXT;
11552 CREATE TABLE acq.provider_note (
11553 id SERIAL PRIMARY KEY,
11554 provider INT NOT NULL REFERENCES acq.provider (id) DEFERRABLE INITIALLY DEFERRED,
11555 creator INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
11556 editor INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
11557 create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
11558 edit_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
11559 value TEXT NOT NULL
11561 CREATE INDEX acq_pro_note_pro_idx ON acq.provider_note ( provider );
11562 CREATE INDEX acq_pro_note_creator_idx ON acq.provider_note ( creator );
11563 CREATE INDEX acq_pro_note_editor_idx ON acq.provider_note ( editor );
11565 -- For each fund: the total allocation from all sources, in the
11566 -- currency of the fund (or 0 if there are no allocations)
11568 CREATE VIEW acq.all_fund_allocation_total AS
11571 COALESCE( SUM( a.amount * acq.exchange_ratio(
11572 s.currency_type, f.currency_type))::numeric(100,2), 0 )
11576 LEFT JOIN acq.fund_allocation a
11578 LEFT JOIN acq.funding_source s
11579 ON a.funding_source = s.id
11583 -- For every fund: the total encumbrances (or 0 if none),
11584 -- in the currency of the fund.
11586 CREATE VIEW acq.all_fund_encumbrance_total AS
11589 COALESCE( encumb.amount, 0 ) AS amount
11595 sum( amount ) AS amount
11602 ON f.id = encumb.fund;
11604 -- For every fund: the total spent (or 0 if none),
11605 -- in the currency of the fund.
11607 CREATE VIEW acq.all_fund_spent_total AS
11610 COALESCE( spent.amount, 0 ) AS amount
11616 sum( amount ) AS amount
11623 ON f.id = spent.fund;
11625 -- For each fund: the amount not yet spent, in the currency
11626 -- of the fund. May include encumbrances.
11628 CREATE VIEW acq.all_fund_spent_balance AS
11631 c.amount - d.amount AS amount
11632 FROM acq.all_fund_allocation_total c
11633 LEFT JOIN acq.all_fund_spent_total d USING (fund);
11635 -- For each fund: the amount neither spent nor encumbered,
11636 -- in the currency of the fund
11638 CREATE VIEW acq.all_fund_combined_balance AS
11641 a.amount - COALESCE( c.amount, 0 ) AS amount
11643 acq.all_fund_allocation_total a
11647 SUM( amount ) AS amount
11652 ) AS c USING ( fund );
11654 CREATE OR REPLACE FUNCTION actor.usr_merge(
11659 deactivate_cards BOOLEAN
11660 ) RETURNS VOID AS $$
11664 picklist_row RECORD;
11669 -- do some initial cleanup
11670 UPDATE actor.usr SET card = NULL WHERE id = src_usr;
11671 UPDATE actor.usr SET mailing_address = NULL WHERE id = src_usr;
11672 UPDATE actor.usr SET billing_address = NULL WHERE id = src_usr;
11676 DELETE FROM actor.card where usr = src_usr;
11678 IF deactivate_cards THEN
11679 UPDATE actor.card SET active = 'f' WHERE usr = src_usr;
11681 UPDATE actor.card SET usr = dest_usr WHERE usr = src_usr;
11686 DELETE FROM actor.usr_address WHERE usr = src_usr;
11688 UPDATE actor.usr_address SET usr = dest_usr WHERE usr = src_usr;
11691 UPDATE actor.usr_note SET usr = dest_usr WHERE usr = src_usr;
11692 -- dupes are technically OK in actor.usr_standing_penalty, should manually delete them...
11693 UPDATE actor.usr_standing_penalty SET usr = dest_usr WHERE usr = src_usr;
11694 PERFORM actor.usr_merge_rows('actor.usr_org_unit_opt_in', 'usr', src_usr, dest_usr);
11695 PERFORM actor.usr_merge_rows('actor.usr_setting', 'usr', src_usr, dest_usr);
11698 PERFORM actor.usr_merge_rows('permission.usr_perm_map', 'usr', src_usr, dest_usr);
11699 PERFORM actor.usr_merge_rows('permission.usr_object_perm_map', 'usr', src_usr, dest_usr);
11700 PERFORM actor.usr_merge_rows('permission.usr_grp_map', 'usr', src_usr, dest_usr);
11701 PERFORM actor.usr_merge_rows('permission.usr_work_ou_map', 'usr', src_usr, dest_usr);
11706 -- For each *_bucket table: transfer every bucket belonging to src_usr
11707 -- into the custody of dest_usr.
11709 -- In order to avoid colliding with an existing bucket owned by
11710 -- the destination user, append the source user's id (in parenthesese)
11711 -- to the name. If you still get a collision, add successive
11712 -- spaces to the name and keep trying until you succeed.
11716 FROM container.biblio_record_entry_bucket
11717 WHERE owner = src_usr
11719 suffix := ' (' || src_usr || ')';
11722 UPDATE container.biblio_record_entry_bucket
11723 SET owner = dest_usr, name = name || suffix
11724 WHERE id = bucket_row.id;
11725 EXCEPTION WHEN unique_violation THEN
11726 suffix := suffix || ' ';
11735 FROM container.call_number_bucket
11736 WHERE owner = src_usr
11738 suffix := ' (' || src_usr || ')';
11741 UPDATE container.call_number_bucket
11742 SET owner = dest_usr, name = name || suffix
11743 WHERE id = bucket_row.id;
11744 EXCEPTION WHEN unique_violation THEN
11745 suffix := suffix || ' ';
11754 FROM container.copy_bucket
11755 WHERE owner = src_usr
11757 suffix := ' (' || src_usr || ')';
11760 UPDATE container.copy_bucket
11761 SET owner = dest_usr, name = name || suffix
11762 WHERE id = bucket_row.id;
11763 EXCEPTION WHEN unique_violation THEN
11764 suffix := suffix || ' ';
11773 FROM container.user_bucket
11774 WHERE owner = src_usr
11776 suffix := ' (' || src_usr || ')';
11779 UPDATE container.user_bucket
11780 SET owner = dest_usr, name = name || suffix
11781 WHERE id = bucket_row.id;
11782 EXCEPTION WHEN unique_violation THEN
11783 suffix := suffix || ' ';
11790 UPDATE container.user_bucket_item SET target_user = dest_usr WHERE target_user = src_usr;
11793 -- transfer queues the same way we transfer buckets (see above)
11796 FROM vandelay.queue
11797 WHERE owner = src_usr
11799 suffix := ' (' || src_usr || ')';
11802 UPDATE vandelay.queue
11803 SET owner = dest_usr, name = name || suffix
11804 WHERE id = queue_row.id;
11805 EXCEPTION WHEN unique_violation THEN
11806 suffix := suffix || ' ';
11814 PERFORM actor.usr_merge_rows('money.collections_tracker', 'usr', src_usr, dest_usr);
11815 PERFORM actor.usr_merge_rows('money.collections_tracker', 'collector', src_usr, dest_usr);
11816 UPDATE money.billable_xact SET usr = dest_usr WHERE usr = src_usr;
11817 UPDATE money.billing SET voider = dest_usr WHERE voider = src_usr;
11818 UPDATE money.bnm_payment SET accepting_usr = dest_usr WHERE accepting_usr = src_usr;
11821 UPDATE action.circulation SET usr = dest_usr WHERE usr = src_usr;
11822 UPDATE action.circulation SET circ_staff = dest_usr WHERE circ_staff = src_usr;
11823 UPDATE action.circulation SET checkin_staff = dest_usr WHERE checkin_staff = src_usr;
11825 UPDATE action.hold_request SET usr = dest_usr WHERE usr = src_usr;
11826 UPDATE action.hold_request SET fulfillment_staff = dest_usr WHERE fulfillment_staff = src_usr;
11827 UPDATE action.hold_request SET requestor = dest_usr WHERE requestor = src_usr;
11828 UPDATE action.hold_notification SET notify_staff = dest_usr WHERE notify_staff = src_usr;
11830 UPDATE action.in_house_use SET staff = dest_usr WHERE staff = src_usr;
11831 UPDATE action.non_cataloged_circulation SET staff = dest_usr WHERE staff = src_usr;
11832 UPDATE action.non_cataloged_circulation SET patron = dest_usr WHERE patron = src_usr;
11833 UPDATE action.non_cat_in_house_use SET staff = dest_usr WHERE staff = src_usr;
11834 UPDATE action.survey_response SET usr = dest_usr WHERE usr = src_usr;
11837 UPDATE acq.fund_allocation SET allocator = dest_usr WHERE allocator = src_usr;
11838 UPDATE acq.fund_transfer SET transfer_user = dest_usr WHERE transfer_user = src_usr;
11840 -- transfer picklists the same way we transfer buckets (see above)
11841 FOR picklist_row in
11844 WHERE owner = src_usr
11846 suffix := ' (' || src_usr || ')';
11849 UPDATE acq.picklist
11850 SET owner = dest_usr, name = name || suffix
11851 WHERE id = picklist_row.id;
11852 EXCEPTION WHEN unique_violation THEN
11853 suffix := suffix || ' ';
11860 UPDATE acq.purchase_order SET owner = dest_usr WHERE owner = src_usr;
11861 UPDATE acq.po_note SET creator = dest_usr WHERE creator = src_usr;
11862 UPDATE acq.po_note SET editor = dest_usr WHERE editor = src_usr;
11863 UPDATE acq.provider_note SET creator = dest_usr WHERE creator = src_usr;
11864 UPDATE acq.provider_note SET editor = dest_usr WHERE editor = src_usr;
11865 UPDATE acq.lineitem_note SET creator = dest_usr WHERE creator = src_usr;
11866 UPDATE acq.lineitem_note SET editor = dest_usr WHERE editor = src_usr;
11867 UPDATE acq.lineitem_usr_attr_definition SET usr = dest_usr WHERE usr = src_usr;
11870 UPDATE asset.copy SET creator = dest_usr WHERE creator = src_usr;
11871 UPDATE asset.copy SET editor = dest_usr WHERE editor = src_usr;
11872 UPDATE asset.copy_note SET creator = dest_usr WHERE creator = src_usr;
11873 UPDATE asset.call_number SET creator = dest_usr WHERE creator = src_usr;
11874 UPDATE asset.call_number SET editor = dest_usr WHERE editor = src_usr;
11875 UPDATE asset.call_number_note SET creator = dest_usr WHERE creator = src_usr;
11878 UPDATE serial.record_entry SET creator = dest_usr WHERE creator = src_usr;
11879 UPDATE serial.record_entry SET editor = dest_usr WHERE editor = src_usr;
11882 -- It's not uncommon to define the reporter schema in a replica
11883 -- DB only, so don't assume these tables exist in the write DB.
11885 UPDATE reporter.template SET owner = dest_usr WHERE owner = src_usr;
11886 EXCEPTION WHEN undefined_table THEN
11890 UPDATE reporter.report SET owner = dest_usr WHERE owner = src_usr;
11891 EXCEPTION WHEN undefined_table THEN
11895 UPDATE reporter.schedule SET runner = dest_usr WHERE runner = src_usr;
11896 EXCEPTION WHEN undefined_table THEN
11900 -- transfer folders the same way we transfer buckets (see above)
11903 FROM reporter.template_folder
11904 WHERE owner = src_usr
11906 suffix := ' (' || src_usr || ')';
11909 UPDATE reporter.template_folder
11910 SET owner = dest_usr, name = name || suffix
11911 WHERE id = folder_row.id;
11912 EXCEPTION WHEN unique_violation THEN
11913 suffix := suffix || ' ';
11919 EXCEPTION WHEN undefined_table THEN
11923 -- transfer folders the same way we transfer buckets (see above)
11926 FROM reporter.report_folder
11927 WHERE owner = src_usr
11929 suffix := ' (' || src_usr || ')';
11932 UPDATE reporter.report_folder
11933 SET owner = dest_usr, name = name || suffix
11934 WHERE id = folder_row.id;
11935 EXCEPTION WHEN unique_violation THEN
11936 suffix := suffix || ' ';
11942 EXCEPTION WHEN undefined_table THEN
11946 -- transfer folders the same way we transfer buckets (see above)
11949 FROM reporter.output_folder
11950 WHERE owner = src_usr
11952 suffix := ' (' || src_usr || ')';
11955 UPDATE reporter.output_folder
11956 SET owner = dest_usr, name = name || suffix
11957 WHERE id = folder_row.id;
11958 EXCEPTION WHEN unique_violation THEN
11959 suffix := suffix || ' ';
11965 EXCEPTION WHEN undefined_table THEN
11969 -- Finally, delete the source user
11970 DELETE FROM actor.usr WHERE id = src_usr;
11973 $$ LANGUAGE plpgsql;
11975 -- The "add" trigger functions should protect against existing NULLed values, just in case
11976 CREATE OR REPLACE FUNCTION money.materialized_summary_billing_add () RETURNS TRIGGER AS $$
11978 IF NOT NEW.voided THEN
11979 UPDATE money.materialized_billable_xact_summary
11980 SET total_owed = COALESCE(total_owed, 0.0::numeric) + NEW.amount,
11981 last_billing_ts = NEW.billing_ts,
11982 last_billing_note = NEW.note,
11983 last_billing_type = NEW.billing_type,
11984 balance_owed = balance_owed + NEW.amount
11985 WHERE id = NEW.xact;
11990 $$ LANGUAGE PLPGSQL;
11992 CREATE OR REPLACE FUNCTION money.materialized_summary_payment_add () RETURNS TRIGGER AS $$
11994 IF NOT NEW.voided THEN
11995 UPDATE money.materialized_billable_xact_summary
11996 SET total_paid = COALESCE(total_paid, 0.0::numeric) + NEW.amount,
11997 last_payment_ts = NEW.payment_ts,
11998 last_payment_note = NEW.note,
11999 last_payment_type = TG_ARGV[0],
12000 balance_owed = balance_owed - NEW.amount
12001 WHERE id = NEW.xact;
12006 $$ LANGUAGE PLPGSQL;
12008 -- Refresh the mat view with the corrected underlying view
12009 TRUNCATE money.materialized_billable_xact_summary;
12010 INSERT INTO money.materialized_billable_xact_summary SELECT * FROM money.billable_xact_summary;
12012 CREATE OR REPLACE FUNCTION permission.usr_has_perm_at_nd(
12013 user_id IN INTEGER,
12016 RETURNS SETOF INTEGER AS $$
12018 -- Return a set of all the org units for which a given user has a given
12019 -- permission, granted directly (not through inheritance from a parent
12022 -- The permissions apply to a minimum depth of the org unit hierarchy,
12023 -- for the org unit(s) to which the user is assigned. (They also apply
12024 -- to the subordinates of those org units, but we don't report the
12025 -- subordinates here.)
12027 -- For purposes of this function, the permission.usr_work_ou_map table
12028 -- defines which users belong to which org units. I.e. we ignore the
12029 -- home_ou column of actor.usr.
12031 -- The result set may contain duplicates, which should be eliminated
12032 -- by a DISTINCT clause.
12037 n_min_depth INTEGER;
12041 n_curr_depth INTEGER;
12044 -- Check for superuser
12046 SELECT INTO b_super
12054 return; -- No user? No permissions.
12057 -- Super user has all permissions everywhere
12067 RETURN NEXT n_work_ou;
12072 -- Translate the permission name
12073 -- to a numeric permission id
12078 permission.perm_list
12083 RETURN; -- No such permission
12086 -- Find the highest-level org unit (i.e. the minimum depth)
12087 -- to which the permission is applied for this user
12089 -- This query is modified from the one in permission.usr_perms().
12091 SELECT INTO n_min_depth
12095 FROM permission.usr_perm_map upm
12096 WHERE upm.usr = user_id
12097 AND (upm.perm = n_perm OR upm.perm = -1)
12100 FROM permission.grp_perm_map gpm
12101 WHERE (gpm.perm = n_perm OR gpm.perm = -1)
12103 SELECT (permission.grp_ancestors(
12104 (SELECT profile FROM actor.usr WHERE id = user_id)
12109 FROM permission.grp_perm_map p
12110 WHERE (p.perm = n_perm OR p.perm = -1)
12112 SELECT (permission.grp_ancestors(m.grp)).id
12113 FROM permission.usr_grp_map m
12114 WHERE m.usr = user_id
12119 RETURN; -- No such permission for this user
12122 -- Identify the org units to which the user is assigned. Note that
12123 -- we pay no attention to the home_ou column in actor.usr.
12129 permission.usr_work_ou_map
12132 LOOP -- For each org unit to which the user is assigned
12134 -- Determine the level of the org unit by a lookup in actor.org_unit_type.
12135 -- We take it on faith that this depth agrees with the actual hierarchy
12136 -- defined in actor.org_unit.
12138 SELECT INTO n_depth
12141 actor.org_unit_type type
12142 INNER JOIN actor.org_unit ou
12143 ON ( ou.ou_type = type.id )
12148 CONTINUE; -- Maybe raise exception?
12151 -- Compare the depth of the work org unit to the
12152 -- minimum depth, and branch accordingly
12154 IF n_depth = n_min_depth THEN
12156 -- The org unit is at the right depth, so return it.
12158 RETURN NEXT n_work_ou;
12159 ELSIF n_depth > n_min_depth THEN
12161 -- Traverse the org unit tree toward the root,
12162 -- until you reach the minimum depth determined above
12164 n_curr_depth := n_depth;
12165 n_curr_ou := n_work_ou;
12166 WHILE n_curr_depth > n_min_depth LOOP
12167 SELECT INTO n_curr_ou
12175 n_curr_depth := n_curr_depth - 1;
12178 -- This can happen only if the hierarchy defined in
12179 -- actor.org_unit is corrupted, or out of sync with
12180 -- the depths defined in actor.org_unit_type.
12181 -- Maybe we should raise an exception here, instead
12182 -- of silently ignoring the problem.
12189 IF n_curr_ou IS NOT NULL THEN
12190 RETURN NEXT n_curr_ou;
12194 -- The permission applies only at a depth greater than the work org unit.
12195 -- Use connectby() to find all dependent org units at the specified depth.
12200 'actor.org_unit', -- table name
12201 'id', -- key column
12202 'parent_ou', -- recursive foreign key
12203 n_work_ou::TEXT, -- id of starting point
12204 (n_min_depth - n_depth) -- max depth to search, relative
12205 ) -- to starting point
12207 ou text, -- dependent org unit
12208 parent_ou text, -- (ignore)
12209 level int -- depth relative to starting point
12212 level = n_min_depth - n_depth
12214 RETURN NEXT n_curr_ou;
12223 $$ LANGUAGE 'plpgsql';
12225 ALTER TABLE acq.purchase_order
12226 ADD COLUMN cancel_reason INT REFERENCES acq.cancel_reason( id )
12227 DEFERRABLE INITIALLY DEFERRED;
12229 ALTER TABLE acq.acq_purchase_order_history
12230 ADD COLUMN cancel_reason INTEGER;
12232 ALTER TABLE acq.purchase_order
12233 ADD COLUMN prepayment_required BOOLEAN NOT NULL DEFAULT FALSE;
12235 ALTER TABLE acq.acq_purchase_order_history
12236 ADD COLUMN prepayment_required BOOLEAN NOT NULL DEFAULT FALSE;
12238 ALTER TABLE acq.lineitem
12239 ADD COLUMN cancel_reason INT REFERENCES acq.cancel_reason( id )
12240 DEFERRABLE INITIALLY DEFERRED;
12242 ALTER TABLE acq.acq_lineitem_history
12243 ADD COLUMN cancel_reason INTEGER;
12245 ALTER TABLE acq.lineitem
12246 ADD COLUMN estimated_unit_price NUMERIC;
12248 ALTER TABLE acq.acq_lineitem_history
12249 ADD COLUMN estimated_unit_price NUMERIC;
12251 ALTER TABLE acq.lineitem
12252 ADD COLUMN claim_policy INT
12253 REFERENCES acq.claim_policy
12254 DEFERRABLE INITIALLY DEFERRED;
12256 ALTER TABLE acq.acq_lineitem_history
12257 ADD COLUMN claim_policy INT
12258 REFERENCES acq.claim_policy
12259 DEFERRABLE INITIALLY DEFERRED;
12261 ALTER TABLE acq.lineitem_detail
12262 ADD COLUMN cancel_reason INT REFERENCES acq.cancel_reason( id )
12263 DEFERRABLE INITIALLY DEFERRED;
12265 ALTER TABLE acq.lineitem_detail
12266 DROP CONSTRAINT lineitem_detail_lineitem_fkey;
12268 ALTER TABLE acq.lineitem_detail
12269 ADD FOREIGN KEY (lineitem) REFERENCES acq.lineitem( id )
12271 DEFERRABLE INITIALLY DEFERRED;
12273 ALTER TABLE acq.lineitem_detail DROP CONSTRAINT lineitem_detail_eg_copy_id_fkey;
12275 INSERT INTO acq.cancel_reason ( id, org_unit, label, description ) VALUES (
12276 1, 1, 'invalid_isbn', oils_i18n_gettext( 1, 'ISBN is unrecognizable', 'acqcr', 'label' ));
12278 INSERT INTO acq.cancel_reason ( id, org_unit, label, description ) VALUES (
12279 2, 1, 'postpone', oils_i18n_gettext( 2, 'Title has been postponed', 'acqcr', 'label' ));
12281 CREATE OR REPLACE FUNCTION vandelay.add_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
12284 use MARC::File::XML (BinaryEncoding => 'UTF-8');
12287 my $target_xml = shift;
12288 my $source_xml = shift;
12289 my $field_spec = shift;
12291 my $target_r = MARC::Record->new_from_xml( $target_xml );
12292 my $source_r = MARC::Record->new_from_xml( $source_xml );
12294 return $target_xml unless ($target_r && $source_r);
12296 my @field_list = split(',', $field_spec);
12299 for my $f (@field_list) {
12300 $f =~ s/^\s*//; $f =~ s/\s*$//;
12301 if ($f =~ /^(.{3})(\w*)(?:\[([^]]*)\])?$/) {
12307 $match =~ s/^\s*//; $match =~ s/\s*$//;
12308 $fields{$field} = { sf => [ split('', $sf) ] };
12310 my ($msf,$mre) = split('~', $match);
12311 if (length($msf) > 0 and length($mre) > 0) {
12312 $msf =~ s/^\s*//; $msf =~ s/\s*$//;
12313 $mre =~ s/^\s*//; $mre =~ s/\s*$//;
12314 $fields{$field}{match} = { sf => $msf, re => qr/$mre/ };
12320 for my $f ( keys %fields) {
12321 if ( @{$fields{$f}{sf}} ) {
12322 for my $from_field ($source_r->field( $f )) {
12323 for my $to_field ($target_r->field( $f )) {
12324 if (exists($fields{$f}{match})) {
12325 next unless (grep { $_ =~ $fields{$f}{match}{re} } $to_field->subfield($fields{$f}{match}{sf}));
12327 my @new_sf = map { ($_ => $from_field->subfield($_)) } @{$fields{$f}{sf}};
12328 $to_field->add_subfields( @new_sf );
12332 my @new_fields = map { $_->clone } $source_r->field( $f );
12333 $target_r->insert_fields_ordered( @new_fields );
12337 $target_xml = $target_r->as_xml_record;
12338 $target_xml =~ s/^<\?.+?\?>$//mo;
12339 $target_xml =~ s/\n//sgo;
12340 $target_xml =~ s/>\s+</></sgo;
12342 return $target_xml;
12344 $_$ LANGUAGE PLPERLU;
12346 CREATE OR REPLACE FUNCTION vandelay.strip_field ( xml TEXT, field TEXT ) RETURNS TEXT AS $_$
12349 use MARC::File::XML (BinaryEncoding => 'UTF-8');
12353 my $r = MARC::Record->new_from_xml( $xml );
12355 return $xml unless ($r);
12357 my $field_spec = shift;
12358 my @field_list = split(',', $field_spec);
12361 for my $f (@field_list) {
12362 $f =~ s/^\s*//; $f =~ s/\s*$//;
12363 if ($f =~ /^(.{3})(\w*)(?:\[([^]]*)\])?$/) {
12369 $match =~ s/^\s*//; $match =~ s/\s*$//;
12370 $fields{$field} = { sf => [ split('', $sf) ] };
12372 my ($msf,$mre) = split('~', $match);
12373 if (length($msf) > 0 and length($mre) > 0) {
12374 $msf =~ s/^\s*//; $msf =~ s/\s*$//;
12375 $mre =~ s/^\s*//; $mre =~ s/\s*$//;
12376 $fields{$field}{match} = { sf => $msf, re => qr/$mre/ };
12382 for my $f ( keys %fields) {
12383 for my $to_field ($r->field( $f )) {
12384 if (exists($fields{$f}{match})) {
12385 next unless (grep { $_ =~ $fields{$f}{match}{re} } $to_field->subfield($fields{$f}{match}{sf}));
12388 if ( @{$fields{$f}{sf}} ) {
12389 $to_field->delete_subfield(code => $fields{$f}{sf});
12391 $r->delete_field( $to_field );
12396 $xml = $r->as_xml_record;
12397 $xml =~ s/^<\?.+?\?>$//mo;
12399 $xml =~ s/>\s+</></sgo;
12403 $_$ LANGUAGE PLPERLU;
12405 CREATE OR REPLACE FUNCTION vandelay.replace_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
12406 SELECT vandelay.add_field( vandelay.strip_field( $1, $3), $2, $3 );
12409 CREATE OR REPLACE FUNCTION vandelay.preserve_field ( incumbent_xml TEXT, incoming_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
12410 SELECT vandelay.add_field( vandelay.strip_field( $2, $3), $1, $3 );
12413 CREATE VIEW action.unfulfilled_hold_max_loop AS
12416 FROM action.unfulfilled_hold_loops
12419 ALTER TABLE acq.lineitem_attr
12420 DROP CONSTRAINT lineitem_attr_lineitem_fkey;
12422 ALTER TABLE acq.lineitem_attr
12423 ADD FOREIGN KEY (lineitem) REFERENCES acq.lineitem( id )
12425 DEFERRABLE INITIALLY DEFERRED;
12427 ALTER TABLE acq.po_note
12428 ADD COLUMN vendor_public BOOLEAN NOT NULL DEFAULT FALSE;
12430 CREATE TABLE vandelay.merge_profile (
12431 id BIGSERIAL PRIMARY KEY,
12432 owner INT NOT NULL REFERENCES actor.org_unit (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
12433 name TEXT NOT NULL,
12437 preserve_spec TEXT,
12438 CONSTRAINT vand_merge_prof_owner_name_idx UNIQUE (owner,name),
12439 CONSTRAINT add_replace_strip_or_preserve CHECK ((preserve_spec IS NOT NULL OR replace_spec IS NOT NULL) OR (preserve_spec IS NULL AND replace_spec IS NULL))
12442 CREATE OR REPLACE FUNCTION vandelay.match_bib_record ( ) RETURNS TRIGGER AS $func$
12451 DELETE FROM vandelay.bib_match WHERE queued_record = NEW.id;
12453 SELECT * INTO attr_def FROM vandelay.bib_attr_definition WHERE xpath = '//*[@tag="901"]/*[@code="c"]' ORDER BY id LIMIT 1;
12455 IF attr_def IS NOT NULL AND attr_def.id IS NOT NULL THEN
12456 id_value := extract_marc_field('vandelay.queued_bib_record', NEW.id, attr_def.xpath, attr_def.remove);
12458 IF id_value IS NOT NULL AND id_value <> '' AND id_value ~ $r$^\d+$$r$ THEN
12459 SELECT id INTO exact_id FROM biblio.record_entry WHERE id = id_value::BIGINT AND NOT deleted;
12460 SELECT * INTO attr FROM vandelay.queued_bib_record_attr WHERE record = NEW.id and field = attr_def.id LIMIT 1;
12461 IF exact_id IS NOT NULL THEN
12462 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('id', attr.id, NEW.id, exact_id);
12467 IF exact_id IS NULL THEN
12468 FOR attr IN SELECT a.* FROM vandelay.queued_bib_record_attr a JOIN vandelay.bib_attr_definition d ON (d.id = a.field) WHERE record = NEW.id AND d.ident IS TRUE LOOP
12470 -- All numbers? check for an id match
12471 IF (attr.attr_value ~ $r$^\d+$$r$) THEN
12472 FOR eg_rec IN SELECT * FROM biblio.record_entry WHERE id = attr.attr_value::BIGINT AND deleted IS FALSE LOOP
12473 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('id', attr.id, NEW.id, eg_rec.id);
12477 -- Looks like an ISBN? check for an isbn match
12478 IF (attr.attr_value ~* $r$^[0-9x]+$$r$ AND character_length(attr.attr_value) IN (10,13)) THEN
12479 FOR eg_rec IN EXECUTE $$SELECT * FROM metabib.full_rec fr WHERE fr.value LIKE LOWER('$$ || attr.attr_value || $$%') AND fr.tag = '020' AND fr.subfield = 'a'$$ LOOP
12480 PERFORM id FROM biblio.record_entry WHERE id = eg_rec.record AND deleted IS FALSE;
12482 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('isbn', attr.id, NEW.id, eg_rec.record);
12486 -- subcheck for isbn-as-tcn
12487 FOR eg_rec IN SELECT * FROM biblio.record_entry WHERE tcn_value = 'i' || attr.attr_value AND deleted IS FALSE LOOP
12488 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('tcn_value', attr.id, NEW.id, eg_rec.id);
12492 -- check for an OCLC tcn_value match
12493 IF (attr.attr_value ~ $r$^o\d+$$r$) THEN
12494 FOR eg_rec IN SELECT * FROM biblio.record_entry WHERE tcn_value = regexp_replace(attr.attr_value,'^o','ocm') AND deleted IS FALSE LOOP
12495 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('tcn_value', attr.id, NEW.id, eg_rec.id);
12499 -- check for a direct tcn_value match
12500 FOR eg_rec IN SELECT * FROM biblio.record_entry WHERE tcn_value = attr.attr_value AND deleted IS FALSE LOOP
12501 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('tcn_value', attr.id, NEW.id, eg_rec.id);
12504 -- check for a direct item barcode match
12506 SELECT DISTINCT b.*
12507 FROM biblio.record_entry b
12508 JOIN asset.call_number cn ON (cn.record = b.id)
12509 JOIN asset.copy cp ON (cp.call_number = cn.id)
12510 WHERE cp.barcode = attr.attr_value AND cp.deleted IS FALSE
12512 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('id', attr.id, NEW.id, eg_rec.id);
12520 $func$ LANGUAGE PLPGSQL;
12522 CREATE OR REPLACE FUNCTION vandelay.merge_record_xml ( target_xml TEXT, source_xml TEXT, add_rule TEXT, replace_preserve_rule TEXT, strip_rule TEXT ) RETURNS TEXT AS $_$
12523 SELECT vandelay.replace_field( vandelay.add_field( vandelay.strip_field( $1, $5) , $2, $3 ), $2, $4);
12526 CREATE TYPE vandelay.compile_profile AS (add_rule TEXT, replace_rule TEXT, preserve_rule TEXT, strip_rule TEXT);
12527 CREATE OR REPLACE FUNCTION vandelay.compile_profile ( incoming_xml TEXT ) RETURNS vandelay.compile_profile AS $_$
12529 output vandelay.compile_profile%ROWTYPE;
12530 profile vandelay.merge_profile%ROWTYPE;
12532 profile_tmpl_owner TEXT;
12533 add_rule TEXT := '';
12534 strip_rule TEXT := '';
12535 replace_rule TEXT := '';
12536 preserve_rule TEXT := '';
12540 profile_tmpl := (oils_xpath('//*[@tag="905"]/*[@code="t"]/text()',incoming_xml))[1];
12541 profile_tmpl_owner := (oils_xpath('//*[@tag="905"]/*[@code="o"]/text()',incoming_xml))[1];
12543 IF profile_tmpl IS NOT NULL AND profile_tmpl <> '' AND profile_tmpl_owner IS NOT NULL AND profile_tmpl_owner <> '' THEN
12544 SELECT p.* INTO profile
12545 FROM vandelay.merge_profile p
12546 JOIN actor.org_unit u ON (u.id = p.owner)
12547 WHERE p.name = profile_tmpl
12548 AND u.shortname = profile_tmpl_owner;
12550 IF profile.id IS NOT NULL THEN
12551 add_rule := COALESCE(profile.add_spec,'');
12552 strip_rule := COALESCE(profile.strip_spec,'');
12553 replace_rule := COALESCE(profile.replace_spec,'');
12554 preserve_rule := COALESCE(profile.preserve_spec,'');
12558 add_rule := add_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="a"]/text()',incoming_xml),''),'');
12559 strip_rule := strip_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="d"]/text()',incoming_xml),''),'');
12560 replace_rule := replace_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="r"]/text()',incoming_xml),''),'');
12561 preserve_rule := preserve_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="p"]/text()',incoming_xml),''),'');
12563 output.add_rule := BTRIM(add_rule,',');
12564 output.replace_rule := BTRIM(replace_rule,',');
12565 output.strip_rule := BTRIM(strip_rule,',');
12566 output.preserve_rule := BTRIM(preserve_rule,',');
12570 $_$ LANGUAGE PLPGSQL;
12572 -- Template-based marc munging functions
12573 CREATE OR REPLACE FUNCTION vandelay.template_overlay_bib_record ( v_marc TEXT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
12575 merge_profile vandelay.merge_profile%ROWTYPE;
12576 dyn_profile vandelay.compile_profile%ROWTYPE;
12577 editor_string TEXT;
12586 SELECT b.marc INTO eg_marc
12587 FROM biblio.record_entry b
12591 IF eg_marc IS NULL OR v_marc IS NULL THEN
12592 -- RAISE NOTICE 'no marc for template or bib record';
12596 dyn_profile := vandelay.compile_profile( v_marc );
12598 IF merge_profile_id IS NOT NULL THEN
12599 SELECT * INTO merge_profile FROM vandelay.merge_profile WHERE id = merge_profile_id;
12601 dyn_profile.add_rule := BTRIM( dyn_profile.add_rule || ',' || COALESCE(merge_profile.add_spec,''), ',');
12602 dyn_profile.strip_rule := BTRIM( dyn_profile.strip_rule || ',' || COALESCE(merge_profile.strip_spec,''), ',');
12603 dyn_profile.replace_rule := BTRIM( dyn_profile.replace_rule || ',' || COALESCE(merge_profile.replace_spec,''), ',');
12604 dyn_profile.preserve_rule := BTRIM( dyn_profile.preserve_rule || ',' || COALESCE(merge_profile.preserve_spec,''), ',');
12608 IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
12609 -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
12613 IF dyn_profile.replace_rule <> '' THEN
12614 source_marc = v_marc;
12615 target_marc = eg_marc;
12616 replace_rule = dyn_profile.replace_rule;
12618 source_marc = eg_marc;
12619 target_marc = v_marc;
12620 replace_rule = dyn_profile.preserve_rule;
12623 UPDATE biblio.record_entry
12624 SET marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
12628 -- RAISE NOTICE 'update of biblio.record_entry failed';
12635 $$ LANGUAGE PLPGSQL;
12637 CREATE OR REPLACE FUNCTION vandelay.template_overlay_bib_record ( v_marc TEXT, eg_id BIGINT) RETURNS BOOL AS $$
12638 SELECT vandelay.template_overlay_bib_record( $1, $2, NULL);
12641 CREATE OR REPLACE FUNCTION vandelay.overlay_bib_record ( import_id BIGINT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
12643 merge_profile vandelay.merge_profile%ROWTYPE;
12644 dyn_profile vandelay.compile_profile%ROWTYPE;
12645 editor_string TEXT;
12655 SELECT q.marc INTO v_marc
12656 FROM vandelay.queued_record q
12657 JOIN vandelay.bib_match m ON (m.queued_record = q.id AND q.id = import_id)
12660 IF v_marc IS NULL THEN
12661 -- RAISE NOTICE 'no marc for vandelay or bib record';
12665 IF vandelay.template_overlay_bib_record( v_marc, eg_id, merge_profile_id) THEN
12666 UPDATE vandelay.queued_bib_record
12667 SET imported_as = eg_id,
12668 import_time = NOW()
12669 WHERE id = import_id;
12671 editor_string := (oils_xpath('//*[@tag="905"]/*[@code="u"]/text()',v_marc))[1];
12673 IF editor_string IS NOT NULL AND editor_string <> '' THEN
12674 SELECT usr INTO editor_id FROM actor.card WHERE barcode = editor_string;
12676 IF editor_id IS NULL THEN
12677 SELECT id INTO editor_id FROM actor.usr WHERE usrname = editor_string;
12680 IF editor_id IS NOT NULL THEN
12681 UPDATE biblio.record_entry SET editor = editor_id WHERE id = eg_id;
12688 -- RAISE NOTICE 'update of biblio.record_entry failed';
12693 $$ LANGUAGE PLPGSQL;
12695 CREATE OR REPLACE FUNCTION vandelay.auto_overlay_bib_record ( import_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
12699 match_attr vandelay.bib_attr_definition%ROWTYPE;
12702 PERFORM * FROM vandelay.queued_bib_record WHERE import_time IS NOT NULL AND id = import_id;
12705 -- RAISE NOTICE 'already imported, cannot auto-overlay'
12709 SELECT COUNT(*) INTO match_count FROM vandelay.bib_match WHERE queued_record = import_id;
12711 IF match_count <> 1 THEN
12712 -- RAISE NOTICE 'not an exact match';
12716 SELECT d.* INTO match_attr
12717 FROM vandelay.bib_attr_definition d
12718 JOIN vandelay.queued_bib_record_attr a ON (a.field = d.id)
12719 JOIN vandelay.bib_match m ON (m.matched_attr = a.id)
12720 WHERE m.queued_record = import_id;
12722 IF NOT (match_attr.xpath ~ '@tag="901"' AND match_attr.xpath ~ '@code="c"') THEN
12723 -- RAISE NOTICE 'not a 901c match: %', match_attr.xpath;
12727 SELECT m.eg_record INTO eg_id
12728 FROM vandelay.bib_match m
12729 WHERE m.queued_record = import_id
12732 IF eg_id IS NULL THEN
12736 RETURN vandelay.overlay_bib_record( import_id, eg_id, merge_profile_id );
12738 $$ LANGUAGE PLPGSQL;
12740 CREATE OR REPLACE FUNCTION vandelay.auto_overlay_bib_queue ( queue_id BIGINT, merge_profile_id INT ) RETURNS SETOF BIGINT AS $$
12742 queued_record vandelay.queued_bib_record%ROWTYPE;
12745 FOR queued_record IN SELECT * FROM vandelay.queued_bib_record WHERE queue = queue_id AND import_time IS NULL LOOP
12747 IF vandelay.auto_overlay_bib_record( queued_record.id, merge_profile_id ) THEN
12748 RETURN NEXT queued_record.id;
12756 $$ LANGUAGE PLPGSQL;
12758 CREATE OR REPLACE FUNCTION vandelay.auto_overlay_bib_queue ( queue_id BIGINT ) RETURNS SETOF BIGINT AS $$
12759 SELECT * FROM vandelay.auto_overlay_bib_queue( $1, NULL );
12762 CREATE OR REPLACE FUNCTION vandelay.overlay_authority_record ( import_id BIGINT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
12764 merge_profile vandelay.merge_profile%ROWTYPE;
12765 dyn_profile vandelay.compile_profile%ROWTYPE;
12774 SELECT b.marc INTO eg_marc
12775 FROM authority.record_entry b
12776 JOIN vandelay.authority_match m ON (m.eg_record = b.id AND m.queued_record = import_id)
12779 SELECT q.marc INTO v_marc
12780 FROM vandelay.queued_record q
12781 JOIN vandelay.authority_match m ON (m.queued_record = q.id AND q.id = import_id)
12784 IF eg_marc IS NULL OR v_marc IS NULL THEN
12785 -- RAISE NOTICE 'no marc for vandelay or authority record';
12789 dyn_profile := vandelay.compile_profile( v_marc );
12791 IF merge_profile_id IS NOT NULL THEN
12792 SELECT * INTO merge_profile FROM vandelay.merge_profile WHERE id = merge_profile_id;
12794 dyn_profile.add_rule := BTRIM( dyn_profile.add_rule || ',' || COALESCE(merge_profile.add_spec,''), ',');
12795 dyn_profile.strip_rule := BTRIM( dyn_profile.strip_rule || ',' || COALESCE(merge_profile.strip_spec,''), ',');
12796 dyn_profile.replace_rule := BTRIM( dyn_profile.replace_rule || ',' || COALESCE(merge_profile.replace_spec,''), ',');
12797 dyn_profile.preserve_rule := BTRIM( dyn_profile.preserve_rule || ',' || COALESCE(merge_profile.preserve_spec,''), ',');
12801 IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
12802 -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
12806 IF dyn_profile.replace_rule <> '' THEN
12807 source_marc = v_marc;
12808 target_marc = eg_marc;
12809 replace_rule = dyn_profile.replace_rule;
12811 source_marc = eg_marc;
12812 target_marc = v_marc;
12813 replace_rule = dyn_profile.preserve_rule;
12816 UPDATE authority.record_entry
12817 SET marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
12821 UPDATE vandelay.queued_authority_record
12822 SET imported_as = eg_id,
12823 import_time = NOW()
12824 WHERE id = import_id;
12828 -- RAISE NOTICE 'update of authority.record_entry failed';
12833 $$ LANGUAGE PLPGSQL;
12835 CREATE OR REPLACE FUNCTION vandelay.auto_overlay_authority_record ( import_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
12840 SELECT COUNT(*) INTO match_count FROM vandelay.authority_match WHERE queued_record = import_id;
12842 IF match_count <> 1 THEN
12843 -- RAISE NOTICE 'not an exact match';
12847 SELECT m.eg_record INTO eg_id
12848 FROM vandelay.authority_match m
12849 WHERE m.queued_record = import_id
12852 IF eg_id IS NULL THEN
12856 RETURN vandelay.overlay_authority_record( import_id, eg_id, merge_profile_id );
12858 $$ LANGUAGE PLPGSQL;
12860 CREATE OR REPLACE FUNCTION vandelay.auto_overlay_authority_queue ( queue_id BIGINT, merge_profile_id INT ) RETURNS SETOF BIGINT AS $$
12862 queued_record vandelay.queued_authority_record%ROWTYPE;
12865 FOR queued_record IN SELECT * FROM vandelay.queued_authority_record WHERE queue = queue_id AND import_time IS NULL LOOP
12867 IF vandelay.auto_overlay_authority_record( queued_record.id, merge_profile_id ) THEN
12868 RETURN NEXT queued_record.id;
12876 $$ LANGUAGE PLPGSQL;
12878 CREATE OR REPLACE FUNCTION vandelay.auto_overlay_authority_queue ( queue_id BIGINT ) RETURNS SETOF BIGINT AS $$
12879 SELECT * FROM vandelay.auto_overlay_authority_queue( $1, NULL );
12882 CREATE TYPE vandelay.tcn_data AS (tcn TEXT, tcn_source TEXT, used BOOL);
12883 CREATE OR REPLACE FUNCTION vandelay.find_bib_tcn_data ( xml TEXT ) RETURNS SETOF vandelay.tcn_data AS $_$
12886 eg_tcn_source TEXT;
12887 output vandelay.tcn_data%ROWTYPE;
12891 eg_tcn := BTRIM((oils_xpath('//*[@tag="001"]/text()',xml))[1]);
12892 IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
12894 eg_tcn_source := BTRIM((oils_xpath('//*[@tag="003"]/text()',xml))[1]);
12895 IF eg_tcn_source IS NULL OR eg_tcn_source = '' THEN
12896 eg_tcn_source := 'System Local';
12899 PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
12902 output.used := FALSE;
12904 output.used := TRUE;
12907 output.tcn := eg_tcn;
12908 output.tcn_source := eg_tcn_source;
12909 RETURN NEXT output;
12914 eg_tcn := BTRIM((oils_xpath('//*[@tag="901"]/*[@code="a"]/text()',xml))[1]);
12915 IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
12917 eg_tcn_source := BTRIM((oils_xpath('//*[@tag="901"]/*[@code="b"]/text()',xml))[1]);
12918 IF eg_tcn_source IS NULL OR eg_tcn_source = '' THEN
12919 eg_tcn_source := 'System Local';
12922 PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
12925 output.used := FALSE;
12927 output.used := TRUE;
12930 output.tcn := eg_tcn;
12931 output.tcn_source := eg_tcn_source;
12932 RETURN NEXT output;
12937 eg_tcn := BTRIM((oils_xpath('//*[@tag="039"]/*[@code="a"]/text()',xml))[1]);
12938 IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
12940 eg_tcn_source := BTRIM((oils_xpath('//*[@tag="039"]/*[@code="b"]/text()',xml))[1]);
12941 IF eg_tcn_source IS NULL OR eg_tcn_source = '' THEN
12942 eg_tcn_source := 'System Local';
12945 PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
12948 output.used := FALSE;
12950 output.used := TRUE;
12953 output.tcn := eg_tcn;
12954 output.tcn_source := eg_tcn_source;
12955 RETURN NEXT output;
12960 eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="020"]/*[@code="a"]/text()',xml))[1], $re$^(\w+).*?$$re$, $re$\1$re$);
12961 IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
12963 eg_tcn_source := 'ISBN';
12965 PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
12968 output.used := FALSE;
12970 output.used := TRUE;
12973 output.tcn := eg_tcn;
12974 output.tcn_source := eg_tcn_source;
12975 RETURN NEXT output;
12980 eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="022"]/*[@code="a"]/text()',xml))[1], $re$^(\w+).*?$$re$, $re$\1$re$);
12981 IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
12983 eg_tcn_source := 'ISSN';
12985 PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
12988 output.used := FALSE;
12990 output.used := TRUE;
12993 output.tcn := eg_tcn;
12994 output.tcn_source := eg_tcn_source;
12995 RETURN NEXT output;
13000 eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="010"]/*[@code="a"]/text()',xml))[1], $re$^(\w+).*?$$re$, $re$\1$re$);
13001 IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
13003 eg_tcn_source := 'LCCN';
13005 PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
13008 output.used := FALSE;
13010 output.used := TRUE;
13013 output.tcn := eg_tcn;
13014 output.tcn_source := eg_tcn_source;
13015 RETURN NEXT output;
13020 eg_tcn := REGEXP_REPLACE((oils_xpath('//*[@tag="035"]/*[@code="a"]/text()',xml))[1], $re$^.*?(\w+)$$re$, $re$\1$re$);
13021 IF eg_tcn IS NOT NULL AND eg_tcn <> '' THEN
13023 eg_tcn_source := 'System Legacy';
13025 PERFORM id FROM biblio.record_entry WHERE tcn_value = eg_tcn AND NOT deleted;
13028 output.used := FALSE;
13030 output.used := TRUE;
13033 output.tcn := eg_tcn;
13034 output.tcn_source := eg_tcn_source;
13035 RETURN NEXT output;
13041 $_$ LANGUAGE PLPGSQL;
13043 CREATE INDEX claim_lid_idx ON acq.claim( lineitem_detail );
13045 CREATE OR REPLACE RULE protect_bib_rec_delete AS ON DELETE TO biblio.record_entry DO INSTEAD (UPDATE biblio.record_entry SET deleted = TRUE WHERE OLD.id = biblio.record_entry.id; DELETE FROM metabib.metarecord_source_map WHERE source = OLD.id);
13047 UPDATE biblio.record_entry SET marc = '<record xmlns="http://www.loc.gov/MARC21/slim"/>' WHERE id = -1;
13049 CREATE INDEX metabib_title_field_entry_value_idx ON metabib.title_field_entry (SUBSTRING(value,1,1024)) WHERE index_vector = ''::TSVECTOR;
13050 CREATE INDEX metabib_author_field_entry_value_idx ON metabib.author_field_entry (SUBSTRING(value,1,1024)) WHERE index_vector = ''::TSVECTOR;
13051 CREATE INDEX metabib_subject_field_entry_value_idx ON metabib.subject_field_entry (SUBSTRING(value,1,1024)) WHERE index_vector = ''::TSVECTOR;
13052 CREATE INDEX metabib_keyword_field_entry_value_idx ON metabib.keyword_field_entry (SUBSTRING(value,1,1024)) WHERE index_vector = ''::TSVECTOR;
13053 CREATE INDEX metabib_series_field_entry_value_idx ON metabib.series_field_entry (SUBSTRING(value,1,1024)) WHERE index_vector = ''::TSVECTOR;
13055 CREATE INDEX metabib_author_field_entry_source_idx ON metabib.author_field_entry (source);
13056 CREATE INDEX metabib_keyword_field_entry_source_idx ON metabib.keyword_field_entry (source);
13057 CREATE INDEX metabib_title_field_entry_source_idx ON metabib.title_field_entry (source);
13058 CREATE INDEX metabib_series_field_entry_source_idx ON metabib.series_field_entry (source);
13060 CREATE TABLE acq.claim_policy_action (
13061 id SERIAL PRIMARY KEY,
13062 claim_policy INT NOT NULL REFERENCES acq.claim_policy
13064 DEFERRABLE INITIALLY DEFERRED,
13065 action_interval INTERVAL NOT NULL,
13066 action INT NOT NULL REFERENCES acq.claim_event_type
13067 DEFERRABLE INITIALLY DEFERRED,
13068 CONSTRAINT action_sequence UNIQUE (claim_policy, action_interval)
13071 CREATE OR REPLACE FUNCTION public.ingest_acq_marc ( ) RETURNS TRIGGER AS $function$
13080 FOR adef IN SELECT *,tableoid FROM acq.lineitem_attr_definition LOOP
13082 SELECT relname::TEXT INTO atype FROM pg_class WHERE oid = adef.tableoid;
13084 IF (atype NOT IN ('lineitem_usr_attr_definition','lineitem_local_attr_definition')) THEN
13085 IF (atype = 'lineitem_provider_attr_definition') THEN
13086 SELECT provider INTO prov FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
13087 CONTINUE WHEN NEW.provider IS NULL OR prov <> NEW.provider;
13090 IF (atype = 'lineitem_provider_attr_definition') THEN
13091 SELECT xpath INTO xpath_string FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
13092 ELSIF (atype = 'lineitem_marc_attr_definition') THEN
13093 SELECT xpath INTO xpath_string FROM acq.lineitem_marc_attr_definition WHERE id = adef.id;
13094 ELSIF (atype = 'lineitem_generated_attr_definition') THEN
13095 SELECT xpath INTO xpath_string FROM acq.lineitem_generated_attr_definition WHERE id = adef.id;
13098 xpath_string := REGEXP_REPLACE(xpath_string,$re$//?text\(\)$$re$,'');
13103 SELECT extract_acq_marc_field(id, xpath_string || '[' || pos || ']', adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id;
13105 IF (value IS NOT NULL AND value <> '') THEN
13106 INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value)
13107 VALUES (NEW.id, adef.id, atype, adef.code, value);
13121 $function$ LANGUAGE PLPGSQL;
13123 UPDATE config.metabib_field SET label = name;
13124 ALTER TABLE config.metabib_field ALTER COLUMN label SET NOT NULL;
13126 ALTER TABLE config.metabib_field ADD CONSTRAINT field_class_fkey FOREIGN KEY (field_class) REFERENCES config.metabib_class (name);
13128 ALTER TABLE config.metabib_field DROP CONSTRAINT metabib_field_field_class_check;
13130 ALTER TABLE config.metabib_field ADD CONSTRAINT metabib_field_format_fkey FOREIGN KEY (format) REFERENCES config.xml_transform (name);
13132 CREATE TABLE config.metabib_search_alias (
13133 alias TEXT PRIMARY KEY,
13134 field_class TEXT NOT NULL REFERENCES config.metabib_class (name),
13135 field INT REFERENCES config.metabib_field (id)
13138 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('kw','keyword');
13139 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('eg.keyword','keyword');
13140 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('dc.publisher','keyword');
13141 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('dc.identifier','keyword');
13142 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('bib.subjecttitle','keyword');
13143 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('bib.genre','keyword');
13144 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('bib.edition','keyword');
13145 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('srw.serverchoice','keyword');
13147 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('au','author');
13148 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('name','author');
13149 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('creator','author');
13150 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('eg.author','author');
13151 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('eg.name','author');
13152 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('dc.creator','author');
13153 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('dc.contributor','author');
13154 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('bib.name','author');
13155 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.namepersonal','author',8);
13156 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.namepersonalfamily','author',8);
13157 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.namepersonalgiven','author',8);
13158 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.namecorporate','author',7);
13159 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.nameconference','author',9);
13161 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('ti','title');
13162 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('eg.title','title');
13163 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('dc.title','title');
13164 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.titleabbreviated','title',2);
13165 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.titleuniform','title',5);
13166 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.titletranslated','title',3);
13167 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.titlealternative','title',4);
13168 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.title','title',2);
13170 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('su','subject');
13171 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('eg.subject','subject');
13172 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('dc.subject','subject');
13173 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.subjectplace','subject',11);
13174 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.subjectname','subject',12);
13175 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.subjectoccupation','subject',16);
13177 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('se','series');
13178 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('eg.series','series');
13179 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('bib.titleseries','series',1);
13181 UPDATE config.metabib_field SET facet_field=TRUE WHERE id = 1;
13182 UPDATE config.metabib_field SET xpath=$$//mods32:mods/mods32:name[@type='corporate' and mods32:role/mods32:roleTerm[text()='creator']]$$, facet_field=TRUE, facet_xpath=$$*[local-name()='namePart']$$ WHERE id = 7;
13183 UPDATE config.metabib_field SET xpath=$$//mods32:mods/mods32:name[@type='personal' and mods32:role/mods32:roleTerm[text()='creator']]$$, facet_field=TRUE, facet_xpath=$$*[local-name()='namePart']$$ WHERE id = 8;
13184 UPDATE config.metabib_field SET xpath=$$//mods32:mods/mods32:name[@type='conference' and mods32:role/mods32:roleTerm[text()='creator']]$$, facet_field=TRUE, facet_xpath=$$*[local-name()='namePart']$$ WHERE id = 9;
13185 UPDATE config.metabib_field SET xpath=$$//mods32:mods/mods32:name[@type='personal' and not(mods32:role)]$$, facet_field=TRUE, facet_xpath=$$*[local-name()='namePart']$$ WHERE id = 10;
13187 UPDATE config.metabib_field SET facet_field=TRUE WHERE id = 11;
13188 UPDATE config.metabib_field SET facet_field=TRUE , facet_xpath=$$*[local-name()='namePart']$$ WHERE id = 12;
13189 UPDATE config.metabib_field SET facet_field=TRUE WHERE id = 13;
13190 UPDATE config.metabib_field SET facet_field=TRUE WHERE id = 14;
13192 CREATE INDEX metabib_rec_descriptor_item_type_idx ON metabib.rec_descriptor (item_type);
13193 CREATE INDEX metabib_rec_descriptor_item_form_idx ON metabib.rec_descriptor (item_form);
13194 CREATE INDEX metabib_rec_descriptor_bib_level_idx ON metabib.rec_descriptor (bib_level);
13195 CREATE INDEX metabib_rec_descriptor_control_type_idx ON metabib.rec_descriptor (control_type);
13196 CREATE INDEX metabib_rec_descriptor_char_encoding_idx ON metabib.rec_descriptor (char_encoding);
13197 CREATE INDEX metabib_rec_descriptor_enc_level_idx ON metabib.rec_descriptor (enc_level);
13198 CREATE INDEX metabib_rec_descriptor_audience_idx ON metabib.rec_descriptor (audience);
13199 CREATE INDEX metabib_rec_descriptor_lit_form_idx ON metabib.rec_descriptor (lit_form);
13200 CREATE INDEX metabib_rec_descriptor_cat_form_idx ON metabib.rec_descriptor (cat_form);
13201 CREATE INDEX metabib_rec_descriptor_pub_status_idx ON metabib.rec_descriptor (pub_status);
13202 CREATE INDEX metabib_rec_descriptor_item_lang_idx ON metabib.rec_descriptor (item_lang);
13203 CREATE INDEX metabib_rec_descriptor_vr_format_idx ON metabib.rec_descriptor (vr_format);
13204 CREATE INDEX metabib_rec_descriptor_date1_idx ON metabib.rec_descriptor (date1);
13205 CREATE INDEX metabib_rec_descriptor_dates_idx ON metabib.rec_descriptor (date1,date2);
13207 CREATE TABLE asset.opac_visible_copies (
13208 id BIGINT primary key, -- copy id
13212 COMMENT ON TABLE asset.opac_visible_copies IS $$
13213 Materialized view of copies that are visible in the OPAC, used by
13214 search.query_parser_fts() to speed up OPAC visibility checks on large
13215 databases. Contents are maintained by a set of triggers.
13217 CREATE INDEX opac_visible_copies_idx1 on asset.opac_visible_copies (record, circ_lib);
13219 CREATE OR REPLACE FUNCTION search.query_parser_fts (
13221 param_search_ou INT,
13224 param_statuses INT[],
13225 param_locations INT[],
13232 ) RETURNS SETOF search.search_result AS $func$
13235 current_res search.search_result%ROWTYPE;
13236 search_org_list INT[];
13243 core_result RECORD;
13244 core_cursor REFCURSOR;
13245 core_rel_query TEXT;
13247 total_count INT := 0;
13248 check_count INT := 0;
13249 deleted_count INT := 0;
13250 visible_count INT := 0;
13251 excluded_count INT := 0;
13255 check_limit := COALESCE( param_check, 1000 );
13256 core_limit := COALESCE( param_limit, 25000 );
13257 core_offset := COALESCE( param_offset, 0 );
13259 -- core_skip_chk := COALESCE( param_skip_chk, 1 );
13261 IF param_search_ou > 0 THEN
13262 IF param_depth IS NOT NULL THEN
13263 SELECT array_accum(distinct id) INTO search_org_list FROM actor.org_unit_descendants( param_search_ou, param_depth );
13265 SELECT array_accum(distinct id) INTO search_org_list FROM actor.org_unit_descendants( param_search_ou );
13267 ELSIF param_search_ou < 0 THEN
13268 SELECT array_accum(distinct org_unit) INTO search_org_list FROM actor.org_lasso_map WHERE lasso = -param_search_ou;
13269 ELSIF param_search_ou = 0 THEN
13270 -- reserved for user lassos (ou_buckets/type='lasso') with ID passed in depth ... hack? sure.
13273 OPEN core_cursor FOR EXECUTE param_query;
13277 FETCH core_cursor INTO core_result;
13278 EXIT WHEN NOT FOUND;
13279 EXIT WHEN total_count >= core_limit;
13281 total_count := total_count + 1;
13283 CONTINUE WHEN total_count NOT BETWEEN core_offset + 1 AND check_limit + core_offset;
13285 check_count := check_count + 1;
13287 PERFORM 1 FROM biblio.record_entry b WHERE NOT b.deleted AND b.id IN ( SELECT * FROM search.explode_array( core_result.records ) );
13289 -- RAISE NOTICE ' % were all deleted ... ', core_result.records;
13290 deleted_count := deleted_count + 1;
13295 FROM biblio.record_entry b
13296 JOIN config.bib_source s ON (b.source = s.id)
13297 WHERE s.transcendant
13298 AND b.id IN ( SELECT * FROM search.explode_array( core_result.records ) );
13301 -- RAISE NOTICE ' % were all transcendant ... ', core_result.records;
13302 visible_count := visible_count + 1;
13304 current_res.id = core_result.id;
13305 current_res.rel = core_result.rel;
13309 SELECT COUNT(DISTINCT s.source) INTO tmp_int FROM metabib.metarecord_source_map s WHERE s.metarecord = core_result.id;
13312 IF tmp_int = 1 THEN
13313 current_res.record = core_result.records[1];
13315 current_res.record = NULL;
13318 RETURN NEXT current_res;
13324 FROM asset.call_number cn
13325 JOIN asset.uri_call_number_map map ON (map.call_number = cn.id)
13326 JOIN asset.uri uri ON (map.uri = uri.id)
13327 WHERE NOT cn.deleted
13328 AND cn.label = '##URI##'
13330 AND ( param_locations IS NULL OR array_upper(param_locations, 1) IS NULL )
13331 AND cn.record IN ( SELECT * FROM search.explode_array( core_result.records ) )
13332 AND cn.owning_lib IN ( SELECT * FROM search.explode_array( search_org_list ) )
13336 -- RAISE NOTICE ' % have at least one URI ... ', core_result.records;
13337 visible_count := visible_count + 1;
13339 current_res.id = core_result.id;
13340 current_res.rel = core_result.rel;
13344 SELECT COUNT(DISTINCT s.source) INTO tmp_int FROM metabib.metarecord_source_map s WHERE s.metarecord = core_result.id;
13347 IF tmp_int = 1 THEN
13348 current_res.record = core_result.records[1];
13350 current_res.record = NULL;
13353 RETURN NEXT current_res;
13358 IF param_statuses IS NOT NULL AND array_upper(param_statuses, 1) > 0 THEN
13361 FROM asset.call_number cn
13362 JOIN asset.copy cp ON (cp.call_number = cn.id)
13363 WHERE NOT cn.deleted
13365 AND cp.status IN ( SELECT * FROM search.explode_array( param_statuses ) )
13366 AND cn.record IN ( SELECT * FROM search.explode_array( core_result.records ) )
13367 AND cp.circ_lib IN ( SELECT * FROM search.explode_array( search_org_list ) )
13371 -- RAISE NOTICE ' % were all status-excluded ... ', core_result.records;
13372 excluded_count := excluded_count + 1;
13378 IF param_locations IS NOT NULL AND array_upper(param_locations, 1) > 0 THEN
13381 FROM asset.call_number cn
13382 JOIN asset.copy cp ON (cp.call_number = cn.id)
13383 WHERE NOT cn.deleted
13385 AND cp.location IN ( SELECT * FROM search.explode_array( param_locations ) )
13386 AND cn.record IN ( SELECT * FROM search.explode_array( core_result.records ) )
13387 AND cp.circ_lib IN ( SELECT * FROM search.explode_array( search_org_list ) )
13391 -- RAISE NOTICE ' % were all copy_location-excluded ... ', core_result.records;
13392 excluded_count := excluded_count + 1;
13398 IF staff IS NULL OR NOT staff THEN
13401 FROM asset.opac_visible_copies
13402 WHERE circ_lib IN ( SELECT * FROM search.explode_array( search_org_list ) )
13403 AND record IN ( SELECT * FROM search.explode_array( core_result.records ) )
13407 -- RAISE NOTICE ' % were all visibility-excluded ... ', core_result.records;
13408 excluded_count := excluded_count + 1;
13415 FROM asset.call_number cn
13416 JOIN asset.copy cp ON (cp.call_number = cn.id)
13417 JOIN actor.org_unit a ON (cp.circ_lib = a.id)
13418 WHERE NOT cn.deleted
13420 AND cp.circ_lib IN ( SELECT * FROM search.explode_array( search_org_list ) )
13421 AND cn.record IN ( SELECT * FROM search.explode_array( core_result.records ) )
13427 FROM asset.call_number cn
13428 WHERE cn.record IN ( SELECT * FROM search.explode_array( core_result.records ) )
13432 -- RAISE NOTICE ' % were all visibility-excluded ... ', core_result.records;
13433 excluded_count := excluded_count + 1;
13441 visible_count := visible_count + 1;
13443 current_res.id = core_result.id;
13444 current_res.rel = core_result.rel;
13448 SELECT COUNT(DISTINCT s.source) INTO tmp_int FROM metabib.metarecord_source_map s WHERE s.metarecord = core_result.id;
13451 IF tmp_int = 1 THEN
13452 current_res.record = core_result.records[1];
13454 current_res.record = NULL;
13457 RETURN NEXT current_res;
13459 IF visible_count % 1000 = 0 THEN
13460 -- RAISE NOTICE ' % visible so far ... ', visible_count;
13465 current_res.id = NULL;
13466 current_res.rel = NULL;
13467 current_res.record = NULL;
13468 current_res.total = total_count;
13469 current_res.checked = check_count;
13470 current_res.deleted = deleted_count;
13471 current_res.visible = visible_count;
13472 current_res.excluded = excluded_count;
13476 RETURN NEXT current_res;
13479 $func$ LANGUAGE PLPGSQL;
13481 ALTER TABLE biblio.record_entry ADD COLUMN owner INT REFERENCES actor.org_unit (id);
13482 ALTER TABLE biblio.record_entry ADD COLUMN share_depth INT;
13484 ALTER TABLE auditor.biblio_record_entry_history ADD COLUMN owner INT;
13485 ALTER TABLE auditor.biblio_record_entry_history ADD COLUMN share_depth INT;
13487 CREATE OR REPLACE FUNCTION public.first_word ( TEXT ) RETURNS TEXT AS $$
13488 SELECT COALESCE(SUBSTRING( $1 FROM $_$^\S+$_$), '');
13489 $$ LANGUAGE SQL STRICT IMMUTABLE;
13491 CREATE OR REPLACE FUNCTION public.normalize_space( TEXT ) RETURNS TEXT AS $$
13492 SELECT regexp_replace(regexp_replace(regexp_replace($1, E'\\n', ' ', 'g'), E'(?:^\\s+)|(\\s+$)', '', 'g'), E'\\s+', ' ', 'g');
13493 $$ LANGUAGE SQL STRICT IMMUTABLE;
13495 CREATE OR REPLACE FUNCTION public.lowercase( TEXT ) RETURNS TEXT AS $$
13497 $$ LANGUAGE PLPERLU STRICT IMMUTABLE;
13499 CREATE OR REPLACE FUNCTION public.uppercase( TEXT ) RETURNS TEXT AS $$
13501 $$ LANGUAGE PLPERLU STRICT IMMUTABLE;
13503 CREATE OR REPLACE FUNCTION public.remove_diacritics( TEXT ) RETURNS TEXT AS $$
13504 use Unicode::Normalize;
13506 my $x = NFD(shift);
13510 $$ LANGUAGE PLPERLU STRICT IMMUTABLE;
13512 CREATE OR REPLACE FUNCTION public.entityize( TEXT ) RETURNS TEXT AS $$
13513 use Unicode::Normalize;
13515 my $x = NFC(shift);
13516 $x =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
13519 $$ LANGUAGE PLPERLU STRICT IMMUTABLE;
13521 CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_setting( setting_name TEXT, org_id INT ) RETURNS SETOF actor.org_unit_setting AS $$
13528 SELECT INTO setting * FROM actor.org_unit_setting WHERE org_unit = cur_org AND name = setting_name;
13530 RETURN NEXT setting;
13532 SELECT INTO cur_org parent_ou FROM actor.org_unit WHERE id = cur_org;
13533 EXIT WHEN cur_org IS NULL;
13537 $$ LANGUAGE plpgsql STABLE;
13539 CREATE OR REPLACE FUNCTION acq.extract_holding_attr_table (lineitem int, tag text) RETURNS SETOF acq.flat_lineitem_holding_subfield AS $$
13542 lida acq.flat_lineitem_holding_subfield%ROWTYPE;
13545 SELECT COUNT(*) INTO counter
13546 FROM oils_xpath_table(
13550 '//*[@tag="' || tag || '"]',
13552 ) as t(i int,c text);
13554 FOR i IN 1 .. counter LOOP
13557 FROM ( SELECT id,i,t,v
13558 FROM oils_xpath_table(
13562 '//*[@tag="' || tag || '"][position()=' || i || ']/*/@code|' ||
13563 '//*[@tag="' || tag || '"][position()=' || i || ']/*[@code]',
13565 ) as t(id int,t text,v text)
13574 $$ LANGUAGE PLPGSQL;
13576 CREATE OR REPLACE FUNCTION oils_i18n_xlate ( keytable TEXT, keyclass TEXT, keycol TEXT, identcol TEXT, keyvalue TEXT, raw_locale TEXT ) RETURNS TEXT AS $func$
13578 locale TEXT := REGEXP_REPLACE( REGEXP_REPLACE( raw_locale, E'[;, ].+$', '' ), E'_', '-', 'g' );
13579 language TEXT := REGEXP_REPLACE( locale, E'-.+$', '' );
13580 result config.i18n_core%ROWTYPE;
13582 keyfield TEXT := keyclass || '.' || keycol;
13585 -- Try the full locale
13586 SELECT * INTO result
13587 FROM config.i18n_core
13588 WHERE fq_field = keyfield
13589 AND identity_value = keyvalue
13590 AND translation = locale;
13592 -- Try just the language
13594 SELECT * INTO result
13595 FROM config.i18n_core
13596 WHERE fq_field = keyfield
13597 AND identity_value = keyvalue
13598 AND translation = language;
13601 -- Fall back to the string we passed in in the first place
13606 ' FROM ' || keytable ||
13607 ' WHERE ' || identcol || ' = ' || quote_literal(keyvalue)
13612 RETURN result.string;
13614 $func$ LANGUAGE PLPGSQL STABLE;
13616 SELECT auditor.create_auditor ( 'acq', 'invoice' );
13618 SELECT auditor.create_auditor ( 'acq', 'invoice_item' );
13620 SELECT auditor.create_auditor ( 'acq', 'invoice_entry' );
13622 INSERT INTO acq.cancel_reason ( id, org_unit, label, description, keep_debits ) VALUES (
13623 3, 1, 'delivered_but_lost',
13624 oils_i18n_gettext( 2, 'Delivered but not received; presumed lost', 'acqcr', 'label' ), TRUE );
13626 CREATE TABLE config.global_flag (
13627 label TEXT NOT NULL
13628 ) INHERITS (config.internal_flag);
13629 ALTER TABLE config.global_flag ADD PRIMARY KEY (name);
13631 INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE
13633 'cat.bib.use_id_for_tcn',
13635 'cat.bib.use_id_for_tcn',
13636 'Cat: Use Internal ID for TCN Value',
13642 -- resolves performance issue noted by EG Indiana
13644 CREATE INDEX scecm_owning_copy_idx ON asset.stat_cat_entry_copy_map(owning_copy);
13646 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'identifier', oils_i18n_gettext('identifier', 'Identifier', 'cmc', 'name') );
13648 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES
13649 (17, 'identifier', 'accession', oils_i18n_gettext(17, 'Accession Number', 'cmf', 'label'), 'marcxml', $$//marcxml:datafield[tag="001"]/text()$$, TRUE );
13650 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES
13651 (18, 'identifier', 'isbn', oils_i18n_gettext(18, 'ISBN', 'cmf', 'label'), 'marcxml', $$//marcxml:datafield[tag="020"]/marcxml:subfield[code="a" or code="z"]/text()$$, TRUE );
13652 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES
13653 (19, 'identifier', 'issn', oils_i18n_gettext(19, 'ISSN', 'cmf', 'label'), 'marcxml', $$//marcxml:datafield[tag="022"]/marcxml:subfield[code="a" or code="z"]/text()$$, TRUE );
13654 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES
13655 (20, 'identifier', 'upc', oils_i18n_gettext(20, 'UPC', 'cmf', 'label'), 'marcxml', $$//marcxml:datafield[tag="024" and ind1="1"]/marcxml:subfield[code="a" or code="z"]/text()$$, TRUE );
13656 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES
13657 (21, 'identifier', 'ismn', oils_i18n_gettext(21, 'ISMN', 'cmf', 'label'), 'marcxml', $$//marcxml:datafield[tag="024" and ind1="2"]/marcxml:subfield[code="a" or code="z"]/text()$$, TRUE );
13658 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES
13659 (22, 'identifier', 'ean', oils_i18n_gettext(22, 'EAN', 'cmf', 'label'), 'marcxml', $$//marcxml:datafield[tag="024" and ind1="3"]/marcxml:subfield[code="a" or code="z"]/text()$$, TRUE );
13660 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES
13661 (23, 'identifier', 'isrc', oils_i18n_gettext(23, 'ISRC', 'cmf', 'label'), 'marcxml', $$//marcxml:datafield[tag="024" and ind1="0"]/marcxml:subfield[code="a" or code="z"]/text()$$, TRUE );
13662 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES
13663 (24, 'identifier', 'sici', oils_i18n_gettext(24, 'SICI', 'cmf', 'label'), 'marcxml', $$//marcxml:datafield[tag="024" and ind1="4"]/marcxml:subfield[code="a" or code="z"]/text()$$, TRUE );
13664 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES
13665 (25, 'identifier', 'bibcn', oils_i18n_gettext(25, 'Local Free-Text Call Number', 'cmf', 'label'), 'marcxml', $$//marcxml:datafield[tag="099"]//text()$$, TRUE );
13667 SELECT SETVAL('config.metabib_field_id_seq'::TEXT, (SELECT MAX(id) FROM config.metabib_field), TRUE);
13670 DELETE FROM config.metabib_search_alias WHERE alias = 'dc.identifier';
13672 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('id','identifier');
13673 INSERT INTO config.metabib_search_alias (alias,field_class) VALUES ('dc.identifier','identifier');
13674 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('eg.isbn','identifier', 18);
13675 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('eg.issn','identifier', 19);
13676 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('eg.upc','identifier', 20);
13677 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('eg.callnumber','identifier', 25);
13679 CREATE TABLE metabib.identifier_field_entry (
13680 id BIGSERIAL PRIMARY KEY,
13681 source BIGINT NOT NULL,
13682 field INT NOT NULL,
13683 value TEXT NOT NULL,
13684 index_vector tsvector NOT NULL
13686 CREATE TRIGGER metabib_identifier_field_entry_fti_trigger
13687 BEFORE UPDATE OR INSERT ON metabib.identifier_field_entry
13688 FOR EACH ROW EXECUTE PROCEDURE oils_tsearch2('keyword');
13690 CREATE INDEX metabib_identifier_field_entry_index_vector_idx ON metabib.identifier_field_entry USING GIST (index_vector);
13691 CREATE INDEX metabib_identifier_field_entry_value_idx ON metabib.identifier_field_entry
13692 (SUBSTRING(value,1,1024)) WHERE index_vector = ''::TSVECTOR;
13693 CREATE INDEX metabib_identifier_field_entry_source_idx ON metabib.identifier_field_entry (source);
13695 ALTER TABLE metabib.identifier_field_entry ADD CONSTRAINT metabib_identifier_field_entry_source_pkey
13696 FOREIGN KEY (source) REFERENCES biblio.record_entry (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
13697 ALTER TABLE metabib.identifier_field_entry ADD CONSTRAINT metabib_identifier_field_entry_field_pkey
13698 FOREIGN KEY (field) REFERENCES config.metabib_field (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
13700 CREATE OR REPLACE FUNCTION public.translate_isbn1013( TEXT ) RETURNS TEXT AS $func$
13701 use Business::ISBN;
13705 # For each ISBN found in a single string containing a set of ISBNs:
13706 # * Normalize an incoming ISBN to have the correct checksum and no hyphens
13707 # * Convert an incoming ISBN10 or ISBN13 to its counterpart and return
13712 foreach my $word (split(/\s/, $input)) {
13713 my $isbn = Business::ISBN->new($word);
13715 # First check the checksum; if it is not valid, fix it and add the original
13716 # bad-checksum ISBN to the output
13717 if ($isbn && $isbn->is_valid_checksum() == Business::ISBN::BAD_CHECKSUM) {
13718 $output .= $isbn->isbn() . " ";
13719 $isbn->fix_checksum();
13722 # If we now have a valid ISBN, convert it to its counterpart ISBN10/ISBN13
13723 # and add the normalized original ISBN to the output
13724 if ($isbn && $isbn->is_valid()) {
13725 my $isbn_xlated = ($isbn->type eq "ISBN13") ? $isbn->as_isbn10 : $isbn->as_isbn13;
13726 $output .= $isbn->isbn . " ";
13728 # If we successfully converted the ISBN to its counterpart, add the
13729 # converted ISBN to the output as well
13730 $output .= ($isbn_xlated->isbn . " ") if ($isbn_xlated);
13733 return $output if $output;
13735 # If there were no valid ISBNs, just return the raw input
13737 $func$ LANGUAGE PLPERLU;
13739 COMMENT ON FUNCTION public.translate_isbn1013(TEXT) IS $$
13741 * Copyright (C) 2010 Merrimack Valley Library Consortium
13742 * Jason Stephenson <jstephenson@mvlc.org>
13743 * Copyright (C) 2010 Laurentian University
13744 * Dan Scott <dscott@laurentian.ca>
13746 * The translate_isbn1013 function takes an input ISBN and returns the
13747 * following in a single space-delimited string if the input ISBN is valid:
13748 * - The normalized input ISBN (hyphens stripped)
13749 * - The normalized input ISBN with a fixed checksum if the checksum was bad
13750 * - The ISBN converted to its ISBN10 or ISBN13 counterpart, if possible
13754 UPDATE config.metabib_field SET facet_field = FALSE WHERE id BETWEEN 17 AND 25;
13755 UPDATE config.metabib_field SET xpath = REPLACE(xpath,'marcxml','marc') WHERE id BETWEEN 17 AND 25;
13756 UPDATE config.metabib_field SET xpath = REPLACE(xpath,'tag','@tag') WHERE id BETWEEN 17 AND 25;
13757 UPDATE config.metabib_field SET xpath = REPLACE(xpath,'code','@code') WHERE id BETWEEN 17 AND 25;
13758 UPDATE config.metabib_field SET xpath = REPLACE(xpath,'"',E'\'') WHERE id BETWEEN 17 AND 25;
13759 UPDATE config.metabib_field SET xpath = REPLACE(xpath,'/text()','') WHERE id BETWEEN 17 AND 24;
13761 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
13762 'ISBN 10/13 conversion',
13763 'Translate ISBN10 to ISBN13, and vice versa, for indexing purposes.',
13764 'translate_isbn1013',
13768 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
13770 'Replace all occurances of first parameter in the string with the second parameter.',
13775 INSERT INTO config.metabib_field_index_norm_map (field,norm,pos)
13776 SELECT m.id, i.id, 1
13777 FROM config.metabib_field m,
13778 config.index_normalizer i
13779 WHERE i.func IN ('first_word')
13782 INSERT INTO config.metabib_field_index_norm_map (field,norm,pos)
13783 SELECT m.id, i.id, 2
13784 FROM config.metabib_field m,
13785 config.index_normalizer i
13786 WHERE i.func IN ('translate_isbn1013')
13789 INSERT INTO config.metabib_field_index_norm_map (field,norm,params)
13790 SELECT m.id, i.id, $$['-','']$$
13791 FROM config.metabib_field m,
13792 config.index_normalizer i
13793 WHERE i.func IN ('replace')
13796 INSERT INTO config.metabib_field_index_norm_map (field,norm,params)
13797 SELECT m.id, i.id, $$[' ','']$$
13798 FROM config.metabib_field m,
13799 config.index_normalizer i
13800 WHERE i.func IN ('replace')
13803 DELETE FROM config.metabib_field_index_norm_map WHERE norm IN (1,2) and field > 16;
13805 UPDATE config.metabib_field_index_norm_map
13806 SET params = REPLACE(params,E'\'','"')
13807 WHERE params IS NOT NULL AND params <> '';
13809 DROP TRIGGER IF EXISTS metabib_identifier_field_entry_fti_trigger ON metabib.identifier_field_entry;
13811 CREATE TEXT SEARCH CONFIGURATION identifier ( COPY = title );
13813 ALTER TABLE config.circ_modifier
13814 ADD COLUMN avg_wait_time INTERVAL;
13816 --CREATE TABLE actor.usr_password_reset (
13817 -- id SERIAL PRIMARY KEY,
13818 -- uuid TEXT NOT NULL,
13819 -- usr BIGINT NOT NULL REFERENCES actor.usr(id) DEFERRABLE INITIALLY DEFERRED,
13820 -- request_time TIMESTAMP NOT NULL DEFAULT NOW(),
13821 -- has_been_reset BOOL NOT NULL DEFAULT false
13823 --COMMENT ON TABLE actor.usr_password_reset IS $$
13825 -- * Copyright (C) 2010 Laurentian University
13826 -- * Dan Scott <dscott@laurentian.ca>
13828 -- * Self-serve password reset requests
13832 -- * This program is free software; you can redistribute it and/or
13833 -- * modify it under the terms of the GNU General Public License
13834 -- * as published by the Free Software Foundation; either version 2
13835 -- * of the License, or (at your option) any later version.
13837 -- * This program is distributed in the hope that it will be useful,
13838 -- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13839 -- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13840 -- * GNU General Public License for more details.
13843 --CREATE UNIQUE INDEX actor_usr_password_reset_uuid_idx ON actor.usr_password_reset (uuid);
13844 --CREATE INDEX actor_usr_password_reset_usr_idx ON actor.usr_password_reset (usr);
13845 --CREATE INDEX actor_usr_password_reset_request_time_idx ON actor.usr_password_reset (request_time);
13846 --CREATE INDEX actor_usr_password_reset_has_been_reset_idx ON actor.usr_password_reset (has_been_reset);
13848 -- Use the identifier search class tsconfig
13849 DROP TRIGGER IF EXISTS metabib_identifier_field_entry_fti_trigger ON metabib.identifier_field_entry;
13850 CREATE TRIGGER metabib_identifier_field_entry_fti_trigger
13851 BEFORE INSERT OR UPDATE ON metabib.identifier_field_entry
13853 EXECUTE PROCEDURE public.oils_tsearch2('identifier');
13855 INSERT INTO config.global_flag (name,label,enabled)
13856 VALUES ('history.circ.retention_age',oils_i18n_gettext('history.circ.retention_age', 'Historical Circulation Retention Age', 'cgf', 'label'), TRUE);
13857 INSERT INTO config.global_flag (name,label,enabled)
13858 VALUES ('history.circ.retention_count',oils_i18n_gettext('history.circ.retention_count', 'Historical Circulations per Copy', 'cgf', 'label'), TRUE);
13860 -- turn a JSON scalar into an SQL TEXT value
13861 CREATE OR REPLACE FUNCTION oils_json_to_text( TEXT ) RETURNS TEXT AS $f$
13863 my $json = shift();
13865 eval { $txt = JSON::XS->new->allow_nonref->decode( $json ) };
13866 return undef if ($@);
13868 $f$ LANGUAGE PLPERLU;
13870 -- Return the list of circ chain heads in xact_start order that the user has chosen to "retain"
13871 CREATE OR REPLACE FUNCTION action.usr_visible_circs (usr_id INT) RETURNS SETOF action.circulation AS $func$
13873 c action.circulation%ROWTYPE;
13875 usr_view_age actor.usr_setting%ROWTYPE;
13876 usr_view_start actor.usr_setting%ROWTYPE;
13878 SELECT * INTO usr_view_age FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.circ.retention_age';
13879 SELECT * INTO usr_view_start FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.circ.retention_start';
13881 IF usr_view_age.value IS NOT NULL AND usr_view_start.value IS NOT NULL THEN
13882 -- User opted in and supplied a retention age
13883 IF oils_json_to_text(usr_view_age.value)::INTERVAL > AGE(NOW(), oils_json_to_text(usr_view_start.value)::TIMESTAMPTZ) THEN
13884 view_age := AGE(NOW(), oils_json_to_text(usr_view_start.value)::TIMESTAMPTZ);
13886 view_age := oils_json_to_text(usr_view_age.value)::INTERVAL;
13888 ELSIF usr_view_start.value IS NOT NULL THEN
13890 view_age := AGE(NOW(), oils_json_to_text(usr_view_start.value)::TIMESTAMPTZ);
13892 -- User did not opt in
13898 FROM action.circulation
13900 AND parent_circ IS NULL
13901 AND xact_start > NOW() - view_age
13902 ORDER BY xact_start
13909 $func$ LANGUAGE PLPGSQL;
13911 CREATE OR REPLACE FUNCTION action.purge_circulations () RETURNS INT AS $func$
13913 usr_keep_age actor.usr_setting%ROWTYPE;
13914 usr_keep_start actor.usr_setting%ROWTYPE;
13915 org_keep_age INTERVAL;
13916 org_keep_count INT;
13921 circ_chain_head action.circulation%ROWTYPE;
13922 circ_chain_tail action.circulation%ROWTYPE;
13924 purge_position INT;
13930 SELECT value::INTERVAL INTO org_keep_age FROM config.global_flag WHERE name = 'history.circ.retention_age' AND enabled;
13932 SELECT value::INT INTO org_keep_count FROM config.global_flag WHERE name = 'history.circ.retention_count' AND enabled;
13933 IF org_keep_count IS NULL THEN
13934 RETURN count_purged; -- Gimme a count to keep, or I keep them all, forever
13937 -- First, find copies with more than keep_count non-renewal circs
13939 SELECT target_copy,
13940 COUNT(*) AS total_real_circs
13941 FROM action.circulation
13942 WHERE parent_circ IS NULL
13943 AND xact_finish IS NOT NULL
13944 GROUP BY target_copy
13945 HAVING COUNT(*) > org_keep_count
13947 purge_position := 0;
13948 -- And, for those, select circs that are finished and older than keep_age
13949 FOR circ_chain_head IN
13951 FROM action.circulation
13952 WHERE target_copy = target_acp.target_copy
13953 AND parent_circ IS NULL
13954 ORDER BY xact_start
13957 -- Stop once we've purged enough circs to hit org_keep_count
13958 EXIT WHEN target_acp.total_real_circs - purge_position <= org_keep_count;
13960 SELECT * INTO circ_chain_tail FROM action.circ_chain(circ_chain_head.id) ORDER BY xact_start DESC LIMIT 1;
13961 EXIT WHEN circ_chain_tail.xact_finish IS NULL;
13963 -- Now get the user setings, if any, to block purging if the user wants to keep more circs
13964 usr_keep_age.value := NULL;
13965 SELECT * INTO usr_keep_age FROM actor.usr_setting WHERE usr = circ_chain_head.usr AND name = 'history.circ.retention_age';
13967 usr_keep_start.value := NULL;
13968 SELECT * INTO usr_keep_start FROM actor.usr_setting WHERE usr = circ_chain_head.usr AND name = 'history.circ.retention_start_date';
13970 IF usr_keep_age.value IS NOT NULL AND usr_keep_start.value IS NOT NULL THEN
13971 IF oils_json_to_string(usr_keep_age.value)::INTERVAL > AGE(NOW(), oils_json_to_string(usr_keep_start.value)::TIMESTAMPTZ) THEN
13972 keep_age := AGE(NOW(), oils_json_to_string(usr_keep_start.value)::TIMESTAMPTZ);
13974 keep_age := oils_json_to_string(usr_keep_age.value)::INTERVAL;
13976 ELSIF usr_keep_start.value IS NOT NULL THEN
13977 keep_age := AGE(NOW(), oils_json_to_string(usr_keep_start.value)::TIMESTAMPTZ);
13979 keep_age := COALESCE( org_keep_age::INTERVAL, '2000 years'::INTEVAL );
13982 EXIT WHEN AGE(NOW(), circ_chain_tail.xact_finish) < keep_age;
13984 -- We've passed the purging tests, purge the circ chain starting at the end
13985 DELETE FROM action.circulation WHERE id = circ_chain_tail.id;
13986 WHILE circ_chain_tail.parent_circ IS NOT NULL LOOP
13987 SELECT * INTO circ_chain_tail FROM action.circulation WHERE id = circ_chain_tail.parent_circ;
13988 DELETE FROM action.circulation WHERE id = circ_chain_tail.id;
13991 count_purged := count_purged + 1;
13992 purge_position := purge_position + 1;
13997 $func$ LANGUAGE PLPGSQL;
13999 CREATE OR REPLACE FUNCTION action.usr_visible_holds (usr_id INT) RETURNS SETOF action.hold_request AS $func$
14001 h action.hold_request%ROWTYPE;
14004 usr_view_count actor.usr_setting%ROWTYPE;
14005 usr_view_age actor.usr_setting%ROWTYPE;
14006 usr_view_start actor.usr_setting%ROWTYPE;
14008 SELECT * INTO usr_view_count FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.hold.retention_count';
14009 SELECT * INTO usr_view_age FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.hold.retention_age';
14010 SELECT * INTO usr_view_start FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.hold.retention_start';
14014 FROM action.hold_request
14016 AND fulfillment_time IS NULL
14017 AND cancel_time IS NULL
14018 ORDER BY request_time DESC
14023 IF usr_view_start.value IS NULL THEN
14027 IF usr_view_age.value IS NOT NULL THEN
14028 -- User opted in and supplied a retention age
14029 IF oils_json_to_string(usr_view_age.value)::INTERVAL > AGE(NOW(), oils_json_to_string(usr_view_start.value)::TIMESTAMPTZ) THEN
14030 view_age := AGE(NOW(), oils_json_to_string(usr_view_start.value)::TIMESTAMPTZ);
14032 view_age := oils_json_to_string(usr_view_age.value)::INTERVAL;
14036 view_age := AGE(NOW(), oils_json_to_string(usr_view_start.value)::TIMESTAMPTZ);
14039 IF usr_view_count.value IS NOT NULL THEN
14040 view_count := oils_json_to_text(usr_view_count.value)::INT;
14042 view_count := 1000;
14045 -- show some fulfilled/canceled holds
14048 FROM action.hold_request
14050 AND ( fulfillment_time IS NOT NULL OR cancel_time IS NOT NULL )
14051 AND request_time > NOW() - view_age
14052 ORDER BY request_time DESC
14060 $func$ LANGUAGE PLPGSQL;
14062 DROP TABLE IF EXISTS serial.bib_summary CASCADE;
14064 DROP TABLE IF EXISTS serial.index_summary CASCADE;
14066 DROP TABLE IF EXISTS serial.sup_summary CASCADE;
14068 DROP TABLE IF EXISTS serial.issuance CASCADE;
14070 DROP TABLE IF EXISTS serial.binding_unit CASCADE;
14072 DROP TABLE IF EXISTS serial.subscription CASCADE;
14074 CREATE TABLE asset.copy_template (
14075 id SERIAL PRIMARY KEY,
14076 owning_lib INT NOT NULL
14077 REFERENCES actor.org_unit (id)
14078 DEFERRABLE INITIALLY DEFERRED,
14079 creator BIGINT NOT NULL
14080 REFERENCES actor.usr (id)
14081 DEFERRABLE INITIALLY DEFERRED,
14082 editor BIGINT NOT NULL
14083 REFERENCES actor.usr (id)
14084 DEFERRABLE INITIALLY DEFERRED,
14085 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
14086 edit_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
14087 name TEXT NOT NULL,
14088 -- columns above this point are attributes of the template itself
14089 -- columns after this point are attributes of the copy this template modifies/creates
14090 circ_lib INT REFERENCES actor.org_unit (id)
14091 DEFERRABLE INITIALLY DEFERRED,
14092 status INT REFERENCES config.copy_status (id)
14093 DEFERRABLE INITIALLY DEFERRED,
14094 location INT REFERENCES asset.copy_location (id)
14095 DEFERRABLE INITIALLY DEFERRED,
14096 loan_duration INT CONSTRAINT valid_loan_duration CHECK (
14097 loan_duration IS NULL OR loan_duration IN (1,2,3)),
14098 fine_level INT CONSTRAINT valid_fine_level CHECK (
14099 fine_level IS NULL OR loan_duration IN (1,2,3)),
14105 deposit_amount NUMERIC(6,2),
14106 price NUMERIC(8,2),
14107 circ_modifier TEXT,
14109 alert_message TEXT,
14112 mint_condition BOOL
14115 CREATE TABLE serial.subscription (
14116 id SERIAL PRIMARY KEY,
14117 start_date TIMESTAMP WITH TIME ZONE NOT NULL,
14118 end_date TIMESTAMP WITH TIME ZONE, -- interpret NULL as current subscription
14119 record_entry BIGINT REFERENCES serial.record_entry (id)
14120 DEFERRABLE INITIALLY DEFERRED,
14121 expected_date_offset INTERVAL,
14122 owning_lib INT NOT NULL DEFAULT 1
14123 REFERENCES actor.org_unit (id)
14125 DEFERRABLE INITIALLY DEFERRED
14126 -- acquisitions/business-side tables link to here
14129 --at least one distribution per org_unit holding issues
14130 CREATE TABLE serial.distribution (
14131 id SERIAL PRIMARY KEY,
14132 subscription INT NOT NULL
14133 REFERENCES serial.subscription (id)
14135 DEFERRABLE INITIALLY DEFERRED,
14136 holding_lib INT NOT NULL
14137 REFERENCES actor.org_unit (id)
14138 DEFERRABLE INITIALLY DEFERRED,
14139 label TEXT NOT NULL,
14140 receive_call_number BIGINT REFERENCES asset.call_number (id)
14141 DEFERRABLE INITIALLY DEFERRED,
14142 receive_unit_template INT REFERENCES asset.copy_template (id)
14143 DEFERRABLE INITIALLY DEFERRED,
14144 bind_call_number BIGINT REFERENCES asset.call_number (id)
14145 DEFERRABLE INITIALLY DEFERRED,
14146 bind_unit_template INT REFERENCES asset.copy_template (id)
14147 DEFERRABLE INITIALLY DEFERRED,
14148 unit_label_prefix TEXT,
14149 unit_label_suffix TEXT,
14150 record_entry INT REFERENCES serial.record_entry (id)
14152 DEFERRABLE INITIALLY DEFERRED
14155 CREATE UNIQUE INDEX one_dist_per_sre_idx ON serial.distribution (record_entry);
14157 CREATE TABLE serial.stream (
14158 id SERIAL PRIMARY KEY,
14159 distribution INT NOT NULL
14160 REFERENCES serial.distribution (id)
14162 DEFERRABLE INITIALLY DEFERRED,
14166 CREATE UNIQUE INDEX label_once_per_dist
14167 ON serial.stream (distribution, routing_label)
14168 WHERE routing_label IS NOT NULL;
14170 CREATE TABLE serial.routing_list_user (
14171 id SERIAL PRIMARY KEY,
14172 stream INT NOT NULL
14173 REFERENCES serial.stream
14175 DEFERRABLE INITIALLY DEFERRED,
14176 pos INT NOT NULL DEFAULT 1,
14177 reader INT REFERENCES actor.usr
14179 DEFERRABLE INITIALLY DEFERRED,
14182 CONSTRAINT one_pos_per_routing_list UNIQUE ( stream, pos ),
14183 CONSTRAINT reader_or_dept CHECK
14185 -- Recipient is a person or a department, but not both
14186 (reader IS NOT NULL AND department IS NULL) OR
14187 (reader IS NULL AND department IS NOT NULL)
14191 CREATE TABLE serial.caption_and_pattern (
14192 id SERIAL PRIMARY KEY,
14194 CONSTRAINT cap_type CHECK ( type in
14195 ( 'basic', 'supplement', 'index' )),
14196 create_date TIMESTAMPTZ NOT NULL DEFAULT now(),
14197 active BOOL NOT NULL DEFAULT FALSE,
14198 pattern_code TEXT NOT NULL, -- must contain JSON
14210 subscription INT NOT NULL REFERENCES serial.subscription (id)
14212 DEFERRABLE INITIALLY DEFERRED
14215 CREATE TABLE serial.issuance (
14216 id SERIAL PRIMARY KEY,
14217 creator INT NOT NULL
14218 REFERENCES actor.usr (id)
14219 DEFERRABLE INITIALLY DEFERRED,
14220 editor INT NOT NULL
14221 REFERENCES actor.usr (id)
14222 DEFERRABLE INITIALLY DEFERRED,
14223 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
14224 edit_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
14225 subscription INT NOT NULL
14226 REFERENCES serial.subscription (id)
14228 DEFERRABLE INITIALLY DEFERRED,
14230 date_published TIMESTAMP WITH TIME ZONE,
14232 holding_type TEXT CONSTRAINT valid_holding_type CHECK
14234 holding_type IS NULL
14235 OR holding_type IN ('basic','supplement','index')
14237 holding_link_id INT,
14238 caption_and_pattern INT REFERENCES serial.caption_and_pattern (id)
14239 DEFERRABLE INITIALLY DEFERRED
14240 -- TODO: add columns for separate enumeration/chronology values
14243 CREATE TABLE serial.unit (
14245 label_sort_key TEXT,
14246 contents TEXT NOT NULL
14247 ) INHERITS (asset.copy);
14249 ALTER TABLE serial.unit ADD PRIMARY KEY (id);
14251 ALTER TABLE serial.unit ADD CONSTRAINT serial_unit_call_number_fkey FOREIGN KEY (call_number) REFERENCES asset.call_number (id) DEFERRABLE INITIALLY DEFERRED;
14253 ALTER TABLE serial.unit ADD CONSTRAINT serial_unit_creator_fkey FOREIGN KEY (creator) REFERENCES actor.usr (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;
14255 ALTER TABLE serial.unit ADD CONSTRAINT serial_unit_editor_fkey FOREIGN KEY (editor) REFERENCES actor.usr (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;
14257 CREATE TABLE serial.item (
14258 id SERIAL PRIMARY KEY,
14259 creator INT NOT NULL
14260 REFERENCES actor.usr (id)
14261 DEFERRABLE INITIALLY DEFERRED,
14262 editor INT NOT NULL
14263 REFERENCES actor.usr (id)
14264 DEFERRABLE INITIALLY DEFERRED,
14265 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
14266 edit_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
14267 issuance INT NOT NULL
14268 REFERENCES serial.issuance (id)
14270 DEFERRABLE INITIALLY DEFERRED,
14271 stream INT NOT NULL
14272 REFERENCES serial.stream (id)
14274 DEFERRABLE INITIALLY DEFERRED,
14275 unit INT REFERENCES serial.unit (id)
14277 DEFERRABLE INITIALLY DEFERRED,
14278 uri INT REFERENCES asset.uri (id)
14280 DEFERRABLE INITIALLY DEFERRED,
14281 date_expected TIMESTAMP WITH TIME ZONE,
14282 date_received TIMESTAMP WITH TIME ZONE,
14283 status TEXT CONSTRAINT value_status_check CHECK (
14284 status IN ( 'Bindery', 'Bound', 'Claimed', 'Discarded',
14285 'Expected', 'Not Held', 'Not Published', 'Received'))
14286 DEFAULT 'Expected',
14287 shadowed BOOL NOT NULL DEFAULT FALSE
14290 CREATE TABLE serial.item_note (
14291 id SERIAL PRIMARY KEY,
14293 REFERENCES serial.item (id)
14295 DEFERRABLE INITIALLY DEFERRED,
14296 creator INT NOT NULL
14297 REFERENCES actor.usr (id)
14298 DEFERRABLE INITIALLY DEFERRED,
14299 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
14300 pub BOOL NOT NULL DEFAULT FALSE,
14301 title TEXT NOT NULL,
14302 value TEXT NOT NULL
14305 CREATE TABLE serial.basic_summary (
14306 id SERIAL PRIMARY KEY,
14307 distribution INT NOT NULL
14308 REFERENCES serial.distribution (id)
14310 DEFERRABLE INITIALLY DEFERRED,
14311 generated_coverage TEXT NOT NULL,
14312 textual_holdings TEXT
14315 CREATE TABLE serial.supplement_summary (
14316 id SERIAL PRIMARY KEY,
14317 distribution INT NOT NULL
14318 REFERENCES serial.distribution (id)
14320 DEFERRABLE INITIALLY DEFERRED,
14321 generated_coverage TEXT NOT NULL,
14322 textual_holdings TEXT
14325 CREATE TABLE serial.index_summary (
14326 id SERIAL PRIMARY KEY,
14327 distribution INT NOT NULL
14328 REFERENCES serial.distribution (id)
14330 DEFERRABLE INITIALLY DEFERRED,
14331 generated_coverage TEXT NOT NULL,
14332 textual_holdings TEXT
14335 -- DELETE FROM action_trigger.environment WHERE event_def IN (29,30); DELETE FROM action_trigger.event where event_def IN (29,30); DELETE FROM action_trigger.event_definition WHERE id IN (29,30); DELETE FROM action_trigger.hook WHERE key IN ('money.format.payment_receipt.email','money.format.payment_receipt.print'); DELETE FROM config.upgrade_log WHERE version = '0289'; -- from testing, this sql will remove these events, etc.
14337 DROP INDEX IF EXISTS authority.authority_record_unique_tcn;
14338 CREATE UNIQUE INDEX authority_record_unique_tcn ON authority.record_entry (arn_source,arn_value) WHERE deleted = FALSE OR deleted IS FALSE;
14340 DROP INDEX IF EXISTS asset.asset_call_number_label_once_per_lib;
14341 CREATE UNIQUE INDEX asset_call_number_label_once_per_lib ON asset.call_number (record, owning_lib, label) WHERE deleted = FALSE OR deleted IS FALSE;
14343 DROP INDEX IF EXISTS biblio.biblio_record_unique_tcn;
14344 CREATE UNIQUE INDEX biblio_record_unique_tcn ON biblio.record_entry (tcn_value) WHERE deleted = FALSE OR deleted IS FALSE;
14346 CREATE OR REPLACE FUNCTION config.interval_to_seconds( interval_val INTERVAL )
14347 RETURNS INTEGER AS $$
14349 RETURN EXTRACT( EPOCH FROM interval_val );
14351 $$ LANGUAGE plpgsql;
14353 CREATE OR REPLACE FUNCTION config.interval_to_seconds( interval_string TEXT )
14354 RETURNS INTEGER AS $$
14356 RETURN config.interval_to_seconds( interval_string::INTERVAL );
14358 $$ LANGUAGE plpgsql;
14360 INSERT INTO container.biblio_record_entry_bucket_type( code, label ) VALUES (
14364 'Temporary bucket which gets deleted after use.',
14370 -- DELETE FROM action_trigger.environment WHERE event_def IN (31,32); DELETE FROM action_trigger.event where event_def IN (31,32); DELETE FROM action_trigger.event_definition WHERE id IN (31,32); DELETE FROM action_trigger.hook WHERE key IN ('biblio.format.record_entry.email','biblio.format.record_entry.print'); DELETE FROM action_trigger.cleanup WHERE module = 'DeleteTempBiblioBucket'; DELETE FROM container.biblio_record_entry_bucket_item WHERE bucket IN (SELECT id FROM container.biblio_record_entry_bucket WHERE btype = 'temp'); DELETE FROM container.biblio_record_entry_bucket WHERE btype = 'temp'; DELETE FROM container.biblio_record_entry_bucket_type WHERE code = 'temp'; DELETE FROM config.upgrade_log WHERE version = '0294'; -- from testing, this sql will remove these events, etc.
14372 CREATE OR REPLACE FUNCTION biblio.check_marcxml_well_formed () RETURNS TRIGGER AS $func$
14375 IF xml_is_well_formed(NEW.marc) THEN
14378 RAISE EXCEPTION 'Attempted to % MARCXML that is not well formed', TG_OP;
14382 $func$ LANGUAGE PLPGSQL;
14384 CREATE TRIGGER a_marcxml_is_well_formed BEFORE INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.check_marcxml_well_formed();
14386 CREATE TRIGGER a_marcxml_is_well_formed BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.check_marcxml_well_formed();
14388 ALTER TABLE serial.record_entry
14389 ALTER COLUMN marc DROP NOT NULL;
14391 insert INTO CONFIG.xml_transform(name, namespace_uri, prefix, xslt)
14392 VALUES ('marc21expand880', 'http://www.loc.gov/MARC21/slim', 'marc', $$<?xml version="1.0" encoding="UTF-8"?>
14394 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
14395 xmlns:marc="http://www.loc.gov/MARC21/slim"
14398 Copyright (C) 2010 Equinox Software, Inc.
14399 Galen Charlton <gmc@esilibrary.cOM.
14401 This program is free software; you can redistribute it and/or
14402 modify it under the terms of the GNU General Public License
14403 as published by the Free Software Foundation; either version 2
14404 of the License, or (at your option) any later version.
14406 This program is distributed in the hope that it will be useful,
14407 but WITHOUT ANY WARRANTY; without even the implied warranty of
14408 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14409 GNU General Public License for more details.
14411 marc21_expand_880.xsl - stylesheet used during indexing to
14412 map alternative graphical representations
14413 of MARC fields stored in 880 fields
14414 to the corresponding tag name and value.
14416 For example, if a MARC record for a Chinese book has
14418 245.00 $6 880-01 $a Ba shi san nian duan pian xiao shuo xuan
14419 880.00 $6 245-01/$1 $a八十三年短篇小說選
14421 this stylesheet will transform it to the equivalent of
14423 245.00 $6 880-01 $a Ba shi san nian duan pian xiao shuo xuan
14424 245.00 $6 245-01/$1 $a八十三年短篇小說選
14427 <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
14429 <xsl:template match="@*|node()">
14431 <xsl:apply-templates select="@*|node()"/>
14435 <xsl:template match="//marc:datafield[@tag='880']">
14436 <xsl:if test="./marc:subfield[@code='6'] and string-length(./marc:subfield[@code='6']) >= 6">
14438 <xsl:attribute name="tag">
14439 <xsl:value-of select="substring(./marc:subfield[@code='6'], 1, 3)" />
14441 <xsl:attribute name="ind1">
14442 <xsl:value-of select="@ind1" />
14444 <xsl:attribute name="ind2">
14445 <xsl:value-of select="@ind2" />
14447 <xsl:apply-templates />
14452 </xsl:stylesheet>$$);
14454 -- Splitting the ingest trigger up into little bits
14456 CREATE TEMPORARY TABLE eg_0301_check_if_has_contents (
14457 flag INTEGER PRIMARY KEY
14459 INSERT INTO eg_0301_check_if_has_contents VALUES (1);
14461 -- cause failure if either of the tables we want to drop have rows
14462 INSERT INTO eg_0301_check_if_has_contents SELECT 1 FROM asset.copy_transparency LIMIT 1;
14463 INSERT INTO eg_0301_check_if_has_contents SELECT 1 FROM asset.copy_transparency_map LIMIT 1;
14465 DROP TABLE IF EXISTS asset.copy_transparency_map;
14466 DROP TABLE IF EXISTS asset.copy_transparency;
14468 UPDATE config.metabib_field SET facet_xpath = '//' || facet_xpath WHERE facet_xpath IS NOT NULL;
14470 -- We won't necessarily use all of these, but they are here for completeness.
14471 -- Source is the EDI spec 1229 codelist, eg: http://www.stylusstudio.com/edifact/D04B/1229.htm
14472 -- Values are the EDI code value + 1000
14474 INSERT INTO acq.cancel_reason (keep_debits, id, org_unit, label, description) VALUES
14475 ('t',( 1+1000), 1, 'Added', 'The information is to be or has been added.'),
14476 ('f',( 2+1000), 1, 'Deleted', 'The information is to be or has been deleted.'),
14477 ('t',( 3+1000), 1, 'Changed', 'The information is to be or has been changed.'),
14478 ('t',( 4+1000), 1, 'No action', 'This line item is not affected by the actual message.'),
14479 ('t',( 5+1000), 1, 'Accepted without amendment', 'This line item is entirely accepted by the seller.'),
14480 ('t',( 6+1000), 1, 'Accepted with amendment', 'This line item is accepted but amended by the seller.'),
14481 ('f',( 7+1000), 1, 'Not accepted', 'This line item is not accepted by the seller.'),
14482 ('t',( 8+1000), 1, 'Schedule only', 'Code specifying that the message is a schedule only.'),
14483 ('t',( 9+1000), 1, 'Amendments', 'Code specifying that amendments are requested/notified.'),
14484 ('f',( 10+1000), 1, 'Not found', 'This line item is not found in the referenced message.'),
14485 ('t',( 11+1000), 1, 'Not amended', 'This line is not amended by the buyer.'),
14486 ('t',( 12+1000), 1, 'Line item numbers changed', 'Code specifying that the line item numbers have changed.'),
14487 ('t',( 13+1000), 1, 'Buyer has deducted amount', 'Buyer has deducted amount from payment.'),
14488 ('t',( 14+1000), 1, 'Buyer claims against invoice', 'Buyer has a claim against an outstanding invoice.'),
14489 ('t',( 15+1000), 1, 'Charge back by seller', 'Factor has been requested to charge back the outstanding item.'),
14490 ('t',( 16+1000), 1, 'Seller will issue credit note', 'Seller agrees to issue a credit note.'),
14491 ('t',( 17+1000), 1, 'Terms changed for new terms', 'New settlement terms have been agreed.'),
14492 ('t',( 18+1000), 1, 'Abide outcome of negotiations', 'Factor agrees to abide by the outcome of negotiations between seller and buyer.'),
14493 ('t',( 19+1000), 1, 'Seller rejects dispute', 'Seller does not accept validity of dispute.'),
14494 ('t',( 20+1000), 1, 'Settlement', 'The reported situation is settled.'),
14495 ('t',( 21+1000), 1, 'No delivery', 'Code indicating that no delivery will be required.'),
14496 ('t',( 22+1000), 1, 'Call-off delivery', 'A request for delivery of a particular quantity of goods to be delivered on a particular date (or within a particular period).'),
14497 ('t',( 23+1000), 1, 'Proposed amendment', 'A code used to indicate an amendment suggested by the sender.'),
14498 ('t',( 24+1000), 1, 'Accepted with amendment, no confirmation required', 'Accepted with changes which require no confirmation.'),
14499 ('t',( 25+1000), 1, 'Equipment provisionally repaired', 'The equipment or component has been provisionally repaired.'),
14500 ('t',( 26+1000), 1, 'Included', 'Code indicating that the entity is included.'),
14501 ('t',( 27+1000), 1, 'Verified documents for coverage', 'Upon receipt and verification of documents we shall cover you when due as per your instructions.'),
14502 ('t',( 28+1000), 1, 'Verified documents for debit', 'Upon receipt and verification of documents we shall authorize you to debit our account with you when due.'),
14503 ('t',( 29+1000), 1, 'Authenticated advice for coverage', 'On receipt of your authenticated advice we shall cover you when due as per your instructions.'),
14504 ('t',( 30+1000), 1, 'Authenticated advice for authorization', 'On receipt of your authenticated advice we shall authorize you to debit our account with you when due.'),
14505 ('t',( 31+1000), 1, 'Authenticated advice for credit', 'On receipt of your authenticated advice we shall credit your account with us when due.'),
14506 ('t',( 32+1000), 1, 'Credit advice requested for direct debit', 'A credit advice is requested for the direct debit.'),
14507 ('t',( 33+1000), 1, 'Credit advice and acknowledgement for direct debit', 'A credit advice and acknowledgement are requested for the direct debit.'),
14508 ('t',( 34+1000), 1, 'Inquiry', 'Request for information.'),
14509 ('t',( 35+1000), 1, 'Checked', 'Checked.'),
14510 ('t',( 36+1000), 1, 'Not checked', 'Not checked.'),
14511 ('f',( 37+1000), 1, 'Cancelled', 'Discontinued.'),
14512 ('t',( 38+1000), 1, 'Replaced', 'Provide a replacement.'),
14513 ('t',( 39+1000), 1, 'New', 'Not existing before.'),
14514 ('t',( 40+1000), 1, 'Agreed', 'Consent.'),
14515 ('t',( 41+1000), 1, 'Proposed', 'Put forward for consideration.'),
14516 ('t',( 42+1000), 1, 'Already delivered', 'Delivery has taken place.'),
14517 ('t',( 43+1000), 1, 'Additional subordinate structures will follow', 'Additional subordinate structures will follow the current hierarchy level.'),
14518 ('t',( 44+1000), 1, 'Additional subordinate structures will not follow', 'No additional subordinate structures will follow the current hierarchy level.'),
14519 ('t',( 45+1000), 1, 'Result opposed', 'A notification that the result is opposed.'),
14520 ('t',( 46+1000), 1, 'Auction held', 'A notification that an auction was held.'),
14521 ('t',( 47+1000), 1, 'Legal action pursued', 'A notification that legal action has been pursued.'),
14522 ('t',( 48+1000), 1, 'Meeting held', 'A notification that a meeting was held.'),
14523 ('t',( 49+1000), 1, 'Result set aside', 'A notification that the result has been set aside.'),
14524 ('t',( 50+1000), 1, 'Result disputed', 'A notification that the result has been disputed.'),
14525 ('t',( 51+1000), 1, 'Countersued', 'A notification that a countersuit has been filed.'),
14526 ('t',( 52+1000), 1, 'Pending', 'A notification that an action is awaiting settlement.'),
14527 ('f',( 53+1000), 1, 'Court action dismissed', 'A notification that a court action will no longer be heard.'),
14528 ('t',( 54+1000), 1, 'Referred item, accepted', 'The item being referred to has been accepted.'),
14529 ('f',( 55+1000), 1, 'Referred item, rejected', 'The item being referred to has been rejected.'),
14530 ('t',( 56+1000), 1, 'Debit advice statement line', 'Notification that the statement line is a debit advice.'),
14531 ('t',( 57+1000), 1, 'Credit advice statement line', 'Notification that the statement line is a credit advice.'),
14532 ('t',( 58+1000), 1, 'Grouped credit advices', 'Notification that the credit advices are grouped.'),
14533 ('t',( 59+1000), 1, 'Grouped debit advices', 'Notification that the debit advices are grouped.'),
14534 ('t',( 60+1000), 1, 'Registered', 'The name is registered.'),
14535 ('f',( 61+1000), 1, 'Payment denied', 'The payment has been denied.'),
14536 ('t',( 62+1000), 1, 'Approved as amended', 'Approved with modifications.'),
14537 ('t',( 63+1000), 1, 'Approved as submitted', 'The request has been approved as submitted.'),
14538 ('f',( 64+1000), 1, 'Cancelled, no activity', 'Cancelled due to the lack of activity.'),
14539 ('t',( 65+1000), 1, 'Under investigation', 'Investigation is being done.'),
14540 ('t',( 66+1000), 1, 'Initial claim received', 'Notification that the initial claim was received.'),
14541 ('f',( 67+1000), 1, 'Not in process', 'Not in process.'),
14542 ('f',( 68+1000), 1, 'Rejected, duplicate', 'Rejected because it is a duplicate.'),
14543 ('f',( 69+1000), 1, 'Rejected, resubmit with corrections', 'Rejected but may be resubmitted when corrected.'),
14544 ('t',( 70+1000), 1, 'Pending, incomplete', 'Pending because of incomplete information.'),
14545 ('t',( 71+1000), 1, 'Under field office investigation', 'Investigation by the field is being done.'),
14546 ('t',( 72+1000), 1, 'Pending, awaiting additional material', 'Pending awaiting receipt of additional material.'),
14547 ('t',( 73+1000), 1, 'Pending, awaiting review', 'Pending while awaiting review.'),
14548 ('t',( 74+1000), 1, 'Reopened', 'Opened again.'),
14549 ('t',( 75+1000), 1, 'Processed by primary, forwarded to additional payer(s)', 'This request has been processed by the primary payer and sent to additional payer(s).'),
14550 ('t',( 76+1000), 1, 'Processed by secondary, forwarded to additional payer(s)', 'This request has been processed by the secondary payer and sent to additional payer(s).'),
14551 ('t',( 77+1000), 1, 'Processed by tertiary, forwarded to additional payer(s)', 'This request has been processed by the tertiary payer and sent to additional payer(s).'),
14552 ('t',( 78+1000), 1, 'Previous payment decision reversed', 'A previous payment decision has been reversed.'),
14553 ('t',( 79+1000), 1, 'Not our claim, forwarded to another payer(s)', 'A request does not belong to this payer but has been forwarded to another payer(s).'),
14554 ('t',( 80+1000), 1, 'Transferred to correct insurance carrier', 'The request has been transferred to the correct insurance carrier for processing.'),
14555 ('t',( 81+1000), 1, 'Not paid, predetermination pricing only', 'Payment has not been made and the enclosed response is predetermination pricing only.'),
14556 ('t',( 82+1000), 1, 'Documentation claim', 'The claim is for documentation purposes only, no payment required.'),
14557 ('t',( 83+1000), 1, 'Reviewed', 'Assessed.'),
14558 ('f',( 84+1000), 1, 'Repriced', 'This price was changed.'),
14559 ('t',( 85+1000), 1, 'Audited', 'An official examination has occurred.'),
14560 ('t',( 86+1000), 1, 'Conditionally paid', 'Payment has been conditionally made.'),
14561 ('t',( 87+1000), 1, 'On appeal', 'Reconsideration of the decision has been applied for.'),
14562 ('t',( 88+1000), 1, 'Closed', 'Shut.'),
14563 ('t',( 89+1000), 1, 'Reaudited', 'A subsequent official examination has occurred.'),
14564 ('t',( 90+1000), 1, 'Reissued', 'Issued again.'),
14565 ('t',( 91+1000), 1, 'Closed after reopening', 'Reopened and then closed.'),
14566 ('t',( 92+1000), 1, 'Redetermined', 'Determined again or differently.'),
14567 ('t',( 93+1000), 1, 'Processed as primary', 'Processed as the first.'),
14568 ('t',( 94+1000), 1, 'Processed as secondary', 'Processed as the second.'),
14569 ('t',( 95+1000), 1, 'Processed as tertiary', 'Processed as the third.'),
14570 ('t',( 96+1000), 1, 'Correction of error', 'A correction to information previously communicated which contained an error.'),
14571 ('t',( 97+1000), 1, 'Single credit item of a group', 'Notification that the credit item is a single credit item of a group of credit items.'),
14572 ('t',( 98+1000), 1, 'Single debit item of a group', 'Notification that the debit item is a single debit item of a group of debit items.'),
14573 ('t',( 99+1000), 1, 'Interim response', 'The response is an interim one.'),
14574 ('t',(100+1000), 1, 'Final response', 'The response is an final one.'),
14575 ('t',(101+1000), 1, 'Debit advice requested', 'A debit advice is requested for the transaction.'),
14576 ('t',(102+1000), 1, 'Transaction not impacted', 'Advice that the transaction is not impacted.'),
14577 ('t',(103+1000), 1, 'Patient to be notified', 'The action to take is to notify the patient.'),
14578 ('t',(104+1000), 1, 'Healthcare provider to be notified', 'The action to take is to notify the healthcare provider.'),
14579 ('t',(105+1000), 1, 'Usual general practitioner to be notified', 'The action to take is to notify the usual general practitioner.'),
14580 ('t',(106+1000), 1, 'Advice without details', 'An advice without details is requested or notified.'),
14581 ('t',(107+1000), 1, 'Advice with details', 'An advice with details is requested or notified.'),
14582 ('t',(108+1000), 1, 'Amendment requested', 'An amendment is requested.'),
14583 ('t',(109+1000), 1, 'For information', 'Included for information only.'),
14584 ('f',(110+1000), 1, 'Withdraw', 'A code indicating discontinuance or retraction.'),
14585 ('t',(111+1000), 1, 'Delivery date change', 'The action / notiification is a change of the delivery date.'),
14586 ('f',(112+1000), 1, 'Quantity change', 'The action / notification is a change of quantity.'),
14587 ('t',(113+1000), 1, 'Resale and claim', 'The identified items have been sold by the distributor to the end customer, and compensation for the loss of inventory value is claimed.'),
14588 ('t',(114+1000), 1, 'Resale', 'The identified items have been sold by the distributor to the end customer.'),
14589 ('t',(115+1000), 1, 'Prior addition', 'This existing line item becomes available at an earlier date.');
14591 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field, search_field ) VALUES
14592 (26, 'identifier', 'arcn', oils_i18n_gettext(26, 'Authority record control number', 'cmf', 'label'), 'marcxml', $$//marc:subfield[@code='0']$$, TRUE, FALSE );
14594 SELECT SETVAL('config.metabib_field_id_seq'::TEXT, (SELECT MAX(id) FROM config.metabib_field), TRUE);
14596 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
14597 'Remove Parenthesized Substring',
14598 'Remove any parenthesized substrings from the extracted text, such as the agency code preceding authority record control numbers in subfield 0.',
14599 'remove_paren_substring',
14603 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
14604 'Trim Surrounding Space',
14605 'Trim leading and trailing spaces from extracted text.',
14610 INSERT INTO config.metabib_field_index_norm_map (field,norm,pos)
14614 FROM config.metabib_field m,
14615 config.index_normalizer i
14616 WHERE i.func IN ('remove_paren_substring')
14619 INSERT INTO config.metabib_field_index_norm_map (field,norm,pos)
14623 FROM config.metabib_field m,
14624 config.index_normalizer i
14625 WHERE i.func IN ('btrim')
14628 -- Function that takes, and returns, marcxml and compiles an embedded ruleset for you, and they applys it
14629 CREATE OR REPLACE FUNCTION vandelay.merge_record_xml ( target_marc TEXT, template_marc TEXT ) RETURNS TEXT AS $$
14631 dyn_profile vandelay.compile_profile%ROWTYPE;
14639 IF target_marc IS NULL OR template_marc IS NULL THEN
14640 -- RAISE NOTICE 'no marc for target or template record';
14644 dyn_profile := vandelay.compile_profile( template_marc );
14646 IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
14647 -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
14651 IF dyn_profile.replace_rule <> '' THEN
14652 trgt_marc = target_marc;
14653 tmpl_marc = template_marc;
14654 replace_rule = dyn_profile.replace_rule;
14656 tmp_marc = target_marc;
14657 trgt_marc = template_marc;
14658 tmpl_marc = tmp_marc;
14659 replace_rule = dyn_profile.preserve_rule;
14662 RETURN vandelay.merge_record_xml( trgt_marc, tmpl_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule );
14665 $$ LANGUAGE PLPGSQL;
14667 -- Function to generate an ephemeral overlay template from an authority record
14668 CREATE OR REPLACE FUNCTION authority.generate_overlay_template ( TEXT, BIGINT ) RETURNS TEXT AS $func$
14671 use MARC::File::XML (BinaryEncoding => 'UTF-8');
14674 my $r = MARC::Record->new_from_xml( $xml );
14676 return undef unless ($r);
14678 my $id = shift() || $r->subfield( '901' => 'c' );
14679 $id =~ s/^\s*(?:\([^)]+\))?\s*(.+)\s*?$/$1/;
14680 return undef unless ($id); # We need an ID!
14682 my $tmpl = MARC::Record->new();
14685 for my $field ( $r->field( '1..' ) ) { # Get main entry fields from the authority record
14687 my $tag = $field->tag;
14688 my $i1 = $field->indicator(1);
14689 my $i2 = $field->indicator(2);
14690 my $sf = join '', map { $_->[0] } $field->subfields;
14691 my @data = map { @$_ } $field->subfields;
14695 # Map the authority field to bib fields it can control.
14696 if ($tag >= 100 and $tag <= 111) { # names
14697 @replace_them = map { $tag + $_ } (0, 300, 500, 600, 700);
14698 } elsif ($tag eq '130') { # uniform title
14699 @replace_them = qw/130 240 440 730 830/;
14700 } elsif ($tag >= 150 and $tag <= 155) { # subjects
14701 @replace_them = ($tag + 500);
14702 } elsif ($tag >= 180 and $tag <= 185) { # floating subdivisions
14703 @replace_them = qw/100 400 600 700 800 110 410 610 710 810 111 411 611 711 811 130 240 440 730 830 650 651 655/;
14708 # Dummy up the bib-side data
14709 $tmpl->append_fields(
14711 MARC::Field->new( $_, $i1, $i2, @data )
14715 # Construct some 'replace' rules
14716 push @rule_fields, map { $_ . $sf . '[0~\)' .$id . '$]' } @replace_them;
14719 # Insert the replace rules into the template
14720 $tmpl->append_fields(
14721 MARC::Field->new( '905' => ' ' => ' ' => 'r' => join(',', @rule_fields ) )
14724 $xml = $tmpl->as_xml_record;
14725 $xml =~ s/^<\?.+?\?>$//mo;
14727 $xml =~ s/>\s+</></sgo;
14731 $func$ LANGUAGE PLPERLU;
14733 CREATE OR REPLACE FUNCTION authority.generate_overlay_template ( BIGINT ) RETURNS TEXT AS $func$
14734 SELECT authority.generate_overlay_template( marc, id ) FROM authority.record_entry WHERE id = $1;
14735 $func$ LANGUAGE SQL;
14737 CREATE OR REPLACE FUNCTION authority.generate_overlay_template ( TEXT ) RETURNS TEXT AS $func$
14738 SELECT authority.generate_overlay_template( $1, NULL );
14739 $func$ LANGUAGE SQL;
14741 DELETE FROM config.metabib_field_index_norm_map WHERE field = 26;
14742 DELETE FROM config.metabib_field WHERE id = 26;
14744 -- Making this a global_flag (UI accessible) instead of an internal_flag
14745 INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE
14747 'ingest.disable_authority_linking',
14749 'ingest.disable_authority_linking',
14750 'Authority Automation: Disable bib-authority link tracking',
14755 UPDATE config.global_flag SET enabled = (SELECT enabled FROM ONLY config.internal_flag WHERE name = 'ingest.disable_authority_linking');
14756 DELETE FROM config.internal_flag WHERE name = 'ingest.disable_authority_linking';
14758 INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE
14760 'ingest.disable_authority_auto_update',
14762 'ingest.disable_authority_auto_update',
14763 'Authority Automation: Disable automatic authority updating (requires link tracking)',
14769 -- Enable automated ingest of authority records; just insert the row into
14770 -- authority.record_entry and authority.full_rec will automatically be populated
14772 CREATE OR REPLACE FUNCTION authority.propagate_changes (aid BIGINT, bid BIGINT) RETURNS BIGINT AS $func$
14773 UPDATE biblio.record_entry
14774 SET marc = vandelay.merge_record_xml( marc, authority.generate_overlay_template( $1 ) )
14777 $func$ LANGUAGE SQL;
14779 CREATE OR REPLACE FUNCTION authority.propagate_changes (aid BIGINT) RETURNS SETOF BIGINT AS $func$
14780 SELECT authority.propagate_changes( authority, bib ) FROM authority.bib_linking WHERE authority = $1;
14781 $func$ LANGUAGE SQL;
14783 -- authority.rec_descriptor appears to be unused currently
14784 CREATE OR REPLACE FUNCTION authority.reingest_authority_rec_descriptor( auth_id BIGINT ) RETURNS VOID AS $func$
14786 DELETE FROM authority.rec_descriptor WHERE record = auth_id;
14787 -- INSERT INTO authority.rec_descriptor (record, record_status, char_encoding)
14788 -- SELECT auth_id, ;
14792 $func$ LANGUAGE PLPGSQL;
14794 CREATE OR REPLACE FUNCTION authority.reingest_authority_full_rec( auth_id BIGINT ) RETURNS VOID AS $func$
14796 DELETE FROM authority.full_rec WHERE record = auth_id;
14797 INSERT INTO authority.full_rec (record, tag, ind1, ind2, subfield, value)
14798 SELECT record, tag, ind1, ind2, subfield, value FROM authority.flatten_marc( auth_id );
14802 $func$ LANGUAGE PLPGSQL;
14804 -- AFTER UPDATE OR INSERT trigger for authority.record_entry
14805 CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$
14808 IF NEW.deleted IS TRUE THEN -- If this authority is deleted
14809 DELETE FROM authority.bib_linking WHERE authority = NEW.id; -- Avoid updating fields in bibs that are no longer visible
14810 -- Should remove matching $0 from controlled fields at the same time?
14811 RETURN NEW; -- and we're done
14814 IF TG_OP = 'UPDATE' THEN -- re-ingest?
14815 PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled;
14817 IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change
14822 -- Flatten and insert the afr data
14823 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_full_rec' AND enabled;
14825 PERFORM authority.reingest_authority_full_rec(NEW.id);
14826 -- authority.rec_descriptor is not currently used
14827 -- PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_rec_descriptor' AND enabled;
14828 -- IF NOT FOUND THEN
14829 -- PERFORM authority.reingest_authority_rec_descriptor(NEW.id);
14835 $func$ LANGUAGE PLPGSQL;
14837 CREATE TRIGGER aaa_auth_ingest_or_delete AFTER INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE authority.indexing_ingest_or_delete ();
14839 -- Some records manage to get XML namespace declarations into each element,
14840 -- like <datafield xmlns:marc="http://www.loc.gov/MARC21/slim"
14841 -- This broke the old maintain_901(), so we'll make the regex more robust
14843 CREATE OR REPLACE FUNCTION maintain_901 () RETURNS TRIGGER AS $func$
14845 -- Remove any existing 901 fields before we insert the authoritative one
14846 NEW.marc := REGEXP_REPLACE(NEW.marc, E'<datafield\s*[^<>]*?\s*tag="901".+?</datafield>', '', 'g');
14847 IF TG_TABLE_SCHEMA = 'biblio' THEN
14848 NEW.marc := REGEXP_REPLACE(
14850 E'(</(?:[^:]*?:)?record>)',
14851 E'<datafield tag="901" ind1=" " ind2=" ">' ||
14852 '<subfield code="a">' || NEW.tcn_value || E'</subfield>' ||
14853 '<subfield code="b">' || NEW.tcn_source || E'</subfield>' ||
14854 '<subfield code="c">' || NEW.id || E'</subfield>' ||
14855 '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
14856 CASE WHEN NEW.owner IS NOT NULL THEN '<subfield code="o">' || NEW.owner || E'</subfield>' ELSE '' END ||
14857 CASE WHEN NEW.share_depth IS NOT NULL THEN '<subfield code="d">' || NEW.share_depth || E'</subfield>' ELSE '' END ||
14860 ELSIF TG_TABLE_SCHEMA = 'authority' THEN
14861 NEW.marc := REGEXP_REPLACE(
14863 E'(</(?:[^:]*?:)?record>)',
14864 E'<datafield tag="901" ind1=" " ind2=" ">' ||
14865 '<subfield code="a">' || NEW.arn_value || E'</subfield>' ||
14866 '<subfield code="b">' || NEW.arn_source || E'</subfield>' ||
14867 '<subfield code="c">' || NEW.id || E'</subfield>' ||
14868 '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
14871 ELSIF TG_TABLE_SCHEMA = 'serial' THEN
14872 NEW.marc := REGEXP_REPLACE(
14874 E'(</(?:[^:]*?:)?record>)',
14875 E'<datafield tag="901" ind1=" " ind2=" ">' ||
14876 '<subfield code="c">' || NEW.id || E'</subfield>' ||
14877 '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
14878 '<subfield code="o">' || NEW.owning_lib || E'</subfield>' ||
14879 CASE WHEN NEW.record IS NOT NULL THEN '<subfield code="r">' || NEW.record || E'</subfield>' ELSE '' END ||
14883 NEW.marc := REGEXP_REPLACE(
14885 E'(</(?:[^:]*?:)?record>)',
14886 E'<datafield tag="901" ind1=" " ind2=" ">' ||
14887 '<subfield code="c">' || NEW.id || E'</subfield>' ||
14888 '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
14895 $func$ LANGUAGE PLPGSQL;
14897 CREATE TRIGGER b_maintain_901 BEFORE INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE maintain_901();
14898 CREATE TRIGGER b_maintain_901 BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE maintain_901();
14899 CREATE TRIGGER b_maintain_901 BEFORE INSERT OR UPDATE ON serial.record_entry FOR EACH ROW EXECUTE PROCEDURE maintain_901();
14901 -- In booking, elbow room defines:
14902 -- a) how far in the future you must make a reservation on a given item if
14903 -- that item will have to transit somewhere to fulfill the reservation.
14904 -- b) how soon a reservation must be starting for the reserved item to
14905 -- be op-captured by the checkin interface.
14907 -- We don't want to clobber any default_elbow room at any level:
14909 CREATE OR REPLACE FUNCTION pg_temp.default_elbow() RETURNS INTEGER AS $$
14911 existing actor.org_unit_setting%ROWTYPE;
14913 SELECT INTO existing id FROM actor.org_unit_setting WHERE name = 'circ.booking_reservation.default_elbow_room';
14915 INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES (
14916 (SELECT id FROM actor.org_unit WHERE parent_ou IS NULL),
14917 'circ.booking_reservation.default_elbow_room',
14924 $$ LANGUAGE plpgsql;
14926 SELECT pg_temp.default_elbow();
14928 DROP FUNCTION IF EXISTS action.usr_visible_circ_copies( INTEGER );
14930 -- returns the distinct set of target copy IDs from a user's visible circulation history
14931 CREATE OR REPLACE FUNCTION action.usr_visible_circ_copies( INTEGER ) RETURNS SETOF BIGINT AS $$
14932 SELECT DISTINCT(target_copy) FROM action.usr_visible_circs($1)
14935 ALTER TABLE action.in_house_use DROP CONSTRAINT in_house_use_item_fkey;
14936 ALTER TABLE action.transit_copy DROP CONSTRAINT transit_copy_target_copy_fkey;
14937 ALTER TABLE action.hold_transit_copy DROP CONSTRAINT ahtc_tc_fkey;
14939 ALTER TABLE asset.stat_cat_entry_copy_map DROP CONSTRAINT a_sc_oc_fkey;
14941 ALTER TABLE authority.record_entry ADD COLUMN owner INT;
14942 ALTER TABLE serial.record_entry ADD COLUMN owner INT;
14944 INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE
14946 'cat.maintain_control_numbers',
14948 'cat.maintain_control_numbers',
14949 'Cat: Maintain 001/003/035 according to the MARC21 specification',
14955 CREATE OR REPLACE FUNCTION maintain_control_numbers() RETURNS TRIGGER AS $func$
14958 use MARC::File::XML (BinaryEncoding => 'UTF-8');
14960 use Unicode::Normalize;
14962 my $record = MARC::Record->new_from_xml($_TD->{new}{marc});
14963 my $schema = $_TD->{table_schema};
14964 my $rec_id = $_TD->{new}{id};
14966 # Short-circuit if maintaining control numbers per MARC21 spec is not enabled
14967 my $enable = spi_exec_query("SELECT enabled FROM config.global_flag WHERE name = 'cat.maintain_control_numbers'");
14968 if (!($enable->{processed}) or $enable->{rows}[0]->{enabled} eq 'f') {
14972 # Get the control number identifier from an OU setting based on $_TD->{new}{owner}
14973 my $ou_cni = 'EVRGRN';
14976 if ($schema eq 'serial') {
14977 $owner = $_TD->{new}{owning_lib};
14979 # are.owner and bre.owner can be null, so fall back to the consortial setting
14980 $owner = $_TD->{new}{owner} || 1;
14983 my $ous_rv = spi_exec_query("SELECT value FROM actor.org_unit_ancestor_setting('cat.marc_control_number_identifier', $owner)");
14984 if ($ous_rv->{processed}) {
14985 $ou_cni = $ous_rv->{rows}[0]->{value};
14986 $ou_cni =~ s/"//g; # Stupid VIM syntax highlighting"
14988 # Fall back to the shortname of the OU if there was no OU setting
14989 $ous_rv = spi_exec_query("SELECT shortname FROM actor.org_unit WHERE id = $owner");
14990 if ($ous_rv->{processed}) {
14991 $ou_cni = $ous_rv->{rows}[0]->{shortname};
14995 my ($create, $munge) = (0, 0);
14996 my ($orig_001, $orig_003) = ('', '');
14998 # Incoming MARC records may have multiple 001s or 003s, despite the spec
14999 my @control_ids = $record->field('003');
15000 my @scns = $record->field('035');
15002 foreach my $id_field ('001', '003') {
15004 my @controls = $record->field($id_field);
15006 if ($id_field eq '001') {
15007 $spec_value = $rec_id;
15009 $spec_value = $ou_cni;
15012 # Create the 001/003 if none exist
15013 if (scalar(@controls) == 0) {
15014 $record->insert_fields_ordered(MARC::Field->new($id_field, $spec_value));
15016 } elsif (scalar(@controls) > 1) {
15017 # Do we already have the right 001/003 value in the existing set?
15018 unless (grep $_->data() eq $spec_value, @controls) {
15022 # Delete the other fields, as with more than 1 001/003 we do not know which 003/001 to match
15023 foreach my $control (@controls) {
15024 unless ($control->data() eq $spec_value) {
15025 $record->delete_field($control);
15029 # Only one field; check to see if we need to munge it
15030 unless (grep $_->data() eq $spec_value, @controls) {
15036 # Now, if we need to munge the 001, we will first push the existing 001/003 into the 035
15038 my $scn = "(" . $record->field('003')->data() . ")" . $record->field('001')->data();
15040 # Do not create duplicate 035 fields
15041 unless (grep $_->subfield('a') eq $scn, @scns) {
15042 $record->insert_fields_ordered(MARC::Field->new('035', '', '', 'a' => $scn));
15046 # Set the 001/003 and update the MARC
15047 if ($create or $munge) {
15048 $record->field('001')->data($rec_id);
15049 $record->field('003')->data($ou_cni);
15051 my $xml = $record->as_xml_record();
15053 $xml =~ s/^<\?xml.+\?\s*>//go;
15054 $xml =~ s/>\s+</></go;
15055 $xml =~ s/\p{Cc}//go;
15057 # Embed a version of OpenILS::Application::AppUtils->entityize()
15058 # to avoid having to set PERL5LIB for PostgreSQL as well
15060 # If we are going to convert non-ASCII characters to XML entities,
15061 # we had better be dealing with a UTF8 string to begin with
15062 $xml = decode_utf8($xml);
15066 # Convert raw ampersands to entities
15067 $xml =~ s/&(?!\S+;)/&/gso;
15069 # Convert Unicode characters to entities
15070 $xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
15072 $xml =~ s/[\x00-\x1f]//go;
15073 $_TD->{new}{marc} = $xml;
15079 $func$ LANGUAGE PLPERLU;
15081 CREATE TRIGGER c_maintain_control_numbers BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE maintain_control_numbers();
15082 CREATE TRIGGER c_maintain_control_numbers BEFORE INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE maintain_control_numbers();
15083 CREATE TRIGGER c_maintain_control_numbers BEFORE INSERT OR UPDATE ON serial.record_entry FOR EACH ROW EXECUTE PROCEDURE maintain_control_numbers();
15085 INSERT INTO metabib.facet_entry (source, field, value)
15086 SELECT source, field, value FROM (
15087 SELECT * FROM metabib.author_field_entry
15089 SELECT * FROM metabib.keyword_field_entry
15091 SELECT * FROM metabib.identifier_field_entry
15093 SELECT * FROM metabib.title_field_entry
15095 SELECT * FROM metabib.subject_field_entry
15097 SELECT * FROM metabib.series_field_entry
15099 WHERE x.index_vector = '';
15101 DELETE FROM metabib.author_field_entry WHERE index_vector = '';
15102 DELETE FROM metabib.keyword_field_entry WHERE index_vector = '';
15103 DELETE FROM metabib.identifier_field_entry WHERE index_vector = '';
15104 DELETE FROM metabib.title_field_entry WHERE index_vector = '';
15105 DELETE FROM metabib.subject_field_entry WHERE index_vector = '';
15106 DELETE FROM metabib.series_field_entry WHERE index_vector = '';
15108 CREATE INDEX metabib_facet_entry_field_idx ON metabib.facet_entry (field);
15109 CREATE INDEX metabib_facet_entry_value_idx ON metabib.facet_entry (SUBSTRING(value,1,1024));
15110 CREATE INDEX metabib_facet_entry_source_idx ON metabib.facet_entry (source);
15112 -- copy OPAC visibility materialized view
15113 CREATE OR REPLACE FUNCTION asset.refresh_opac_visible_copies_mat_view () RETURNS VOID AS $$
15115 TRUNCATE TABLE asset.opac_visible_copies;
15117 INSERT INTO asset.opac_visible_copies (id, circ_lib, record)
15118 SELECT cp.id, cp.circ_lib, cn.record
15120 JOIN asset.call_number cn ON (cn.id = cp.call_number)
15121 JOIN actor.org_unit a ON (cp.circ_lib = a.id)
15122 JOIN asset.copy_location cl ON (cp.location = cl.id)
15123 JOIN config.copy_status cs ON (cp.status = cs.id)
15124 JOIN biblio.record_entry b ON (cn.record = b.id)
15125 WHERE NOT cp.deleted
15128 AND cs.opac_visible
15129 AND cl.opac_visible
15130 AND cp.opac_visible
15131 AND a.opac_visible;
15134 COMMENT ON FUNCTION asset.refresh_opac_visible_copies_mat_view() IS $$
15135 Rebuild the copy OPAC visibility cache. Useful during migrations.
15138 -- and actually populate the table
15139 SELECT asset.refresh_opac_visible_copies_mat_view();
15141 CREATE OR REPLACE FUNCTION asset.cache_copy_visibility () RETURNS TRIGGER as $func$
15145 do_add BOOLEAN := false;
15146 do_remove BOOLEAN := false;
15149 INSERT INTO asset.opac_visible_copies (id, circ_lib, record)
15150 SELECT cp.id, cp.circ_lib, cn.record
15152 JOIN asset.call_number cn ON (cn.id = cp.call_number)
15153 JOIN actor.org_unit a ON (cp.circ_lib = a.id)
15154 JOIN asset.copy_location cl ON (cp.location = cl.id)
15155 JOIN config.copy_status cs ON (cp.status = cs.id)
15156 JOIN biblio.record_entry b ON (cn.record = b.id)
15157 WHERE NOT cp.deleted
15160 AND cs.opac_visible
15161 AND cl.opac_visible
15162 AND cp.opac_visible
15166 remove_query := $$ DELETE FROM asset.opac_visible_copies WHERE id IN ( SELECT id FROM asset.copy WHERE $$;
15168 IF TG_OP = 'INSERT' THEN
15170 IF TG_TABLE_NAME IN ('copy', 'unit') THEN
15171 add_query := add_query || 'AND cp.id = ' || NEW.id || ';';
15179 -- handle items first, since with circulation activity
15180 -- their statuses change frequently
15181 IF TG_TABLE_NAME IN ('copy', 'unit') THEN
15183 IF OLD.location <> NEW.location OR
15184 OLD.call_number <> NEW.call_number OR
15185 OLD.status <> NEW.status OR
15186 OLD.circ_lib <> NEW.circ_lib THEN
15187 -- any of these could change visibility, but
15188 -- we'll save some queries and not try to calculate
15189 -- the change directly
15194 IF OLD.deleted <> NEW.deleted THEN
15195 IF NEW.deleted THEN
15202 IF OLD.opac_visible <> NEW.opac_visible THEN
15203 IF OLD.opac_visible THEN
15205 ELSIF NOT do_remove THEN -- handle edge case where deleted item
15206 -- is also marked opac_visible
15214 DELETE FROM asset.opac_visible_copies WHERE id = NEW.id;
15217 add_query := add_query || 'AND cp.id = ' || NEW.id || ';';
15225 IF TG_TABLE_NAME IN ('call_number', 'record_entry') THEN -- these have a 'deleted' column
15227 IF OLD.deleted AND NEW.deleted THEN -- do nothing
15231 ELSIF NEW.deleted THEN -- remove rows
15233 IF TG_TABLE_NAME = 'call_number' THEN
15234 DELETE FROM asset.opac_visible_copies WHERE id IN (SELECT id FROM asset.copy WHERE call_number = NEW.id);
15235 ELSIF TG_TABLE_NAME = 'record_entry' THEN
15236 DELETE FROM asset.opac_visible_copies WHERE record = NEW.id;
15241 ELSIF OLD.deleted THEN -- add rows
15243 IF TG_TABLE_NAME IN ('copy','unit') THEN
15244 add_query := add_query || 'AND cp.id = ' || NEW.id || ';';
15245 ELSIF TG_TABLE_NAME = 'call_number' THEN
15246 add_query := add_query || 'AND cp.call_number = ' || NEW.id || ';';
15247 ELSIF TG_TABLE_NAME = 'record_entry' THEN
15248 add_query := add_query || 'AND cn.record = ' || NEW.id || ';';
15258 IF TG_TABLE_NAME = 'call_number' THEN
15260 IF OLD.record <> NEW.record THEN
15261 -- call number is linked to different bib
15262 remove_query := remove_query || 'call_number = ' || NEW.id || ');';
15263 EXECUTE remove_query;
15264 add_query := add_query || 'AND cp.call_number = ' || NEW.id || ';';
15272 IF TG_TABLE_NAME IN ('record_entry') THEN
15273 RETURN NEW; -- don't have 'opac_visible'
15276 -- actor.org_unit, asset.copy_location, asset.copy_status
15277 IF NEW.opac_visible = OLD.opac_visible THEN -- do nothing
15281 ELSIF NEW.opac_visible THEN -- add rows
15283 IF TG_TABLE_NAME = 'org_unit' THEN
15284 add_query := add_query || 'AND cp.circ_lib = ' || NEW.id || ';';
15285 ELSIF TG_TABLE_NAME = 'copy_location' THEN
15286 add_query := add_query || 'AND cp.location = ' || NEW.id || ';';
15287 ELSIF TG_TABLE_NAME = 'copy_status' THEN
15288 add_query := add_query || 'AND cp.status = ' || NEW.id || ';';
15293 ELSE -- delete rows
15295 IF TG_TABLE_NAME = 'org_unit' THEN
15296 remove_query := 'DELETE FROM asset.opac_visible_copies WHERE circ_lib = ' || NEW.id || ';';
15297 ELSIF TG_TABLE_NAME = 'copy_location' THEN
15298 remove_query := remove_query || 'location = ' || NEW.id || ');';
15299 ELSIF TG_TABLE_NAME = 'copy_status' THEN
15300 remove_query := remove_query || 'status = ' || NEW.id || ');';
15303 EXECUTE remove_query;
15309 $func$ LANGUAGE PLPGSQL;
15310 COMMENT ON FUNCTION asset.cache_copy_visibility() IS $$
15311 Trigger function to update the copy OPAC visiblity cache.
15313 CREATE TRIGGER a_opac_vis_mat_view_tgr AFTER INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE asset.cache_copy_visibility();
15314 CREATE TRIGGER a_opac_vis_mat_view_tgr AFTER INSERT OR UPDATE ON asset.copy FOR EACH ROW EXECUTE PROCEDURE asset.cache_copy_visibility();
15315 CREATE TRIGGER a_opac_vis_mat_view_tgr AFTER INSERT OR UPDATE ON asset.call_number FOR EACH ROW EXECUTE PROCEDURE asset.cache_copy_visibility();
15316 CREATE TRIGGER a_opac_vis_mat_view_tgr AFTER INSERT OR UPDATE ON asset.copy_location FOR EACH ROW EXECUTE PROCEDURE asset.cache_copy_visibility();
15317 CREATE TRIGGER a_opac_vis_mat_view_tgr AFTER INSERT OR UPDATE ON serial.unit FOR EACH ROW EXECUTE PROCEDURE asset.cache_copy_visibility();
15318 CREATE TRIGGER a_opac_vis_mat_view_tgr AFTER INSERT OR UPDATE ON config.copy_status FOR EACH ROW EXECUTE PROCEDURE asset.cache_copy_visibility();
15319 CREATE TRIGGER a_opac_vis_mat_view_tgr AFTER INSERT OR UPDATE ON actor.org_unit FOR EACH ROW EXECUTE PROCEDURE asset.cache_copy_visibility();
15321 -- must create this rule explicitly; it is not inherited from asset.copy
15322 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;
15324 CREATE RULE protect_authority_rec_delete AS ON DELETE TO authority.record_entry DO INSTEAD (UPDATE authority.record_entry SET deleted = TRUE WHERE OLD.id = authority.record_entry.id);
15326 CREATE OR REPLACE FUNCTION authority.merge_records ( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$
15328 moved_objects INT := 0;
15330 bib_rec biblio.record_entry%ROWTYPE;
15331 auth_link authority.bib_linking%ROWTYPE;
15334 -- 1. Make source_record MARC a copy of the target_record to get auto-sync in linked bib records
15335 UPDATE authority.record_entry
15338 FROM authority.record_entry
15339 WHERE id = target_record
15341 WHERE id = source_record;
15343 -- 2. Update all bib records with the ID from target_record in their $0
15344 FOR bib_rec IN SELECT bre.* FROM biblio.record_entry bre
15345 INNER JOIN authority.bib_linking abl ON abl.bib = bre.id
15346 WHERE abl.authority = target_record LOOP
15348 UPDATE biblio.record_entry
15349 SET marc = REGEXP_REPLACE(marc,
15350 E'(<subfield\\s+code="0"\\s*>[^<]*?\\))' || source_record || '<',
15351 E'\\1' || target_record || '<', 'g')
15352 WHERE id = bib_rec.id;
15354 moved_objects := moved_objects + 1;
15357 -- 3. "Delete" source_record
15358 DELETE FROM authority.record_entry
15359 WHERE id = source_record;
15361 RETURN moved_objects;
15363 $func$ LANGUAGE plpgsql;
15365 -- serial.record_entry already had an owner column spelled "owning_lib"
15366 -- Adjust the table and affected functions accordingly
15368 ALTER TABLE serial.record_entry DROP COLUMN owner;
15370 CREATE TABLE actor.usr_saved_search (
15371 id SERIAL PRIMARY KEY,
15372 owner INT NOT NULL REFERENCES actor.usr (id)
15374 DEFERRABLE INITIALLY DEFERRED,
15375 name TEXT NOT NULL,
15376 create_date TIMESTAMPTZ NOT NULL DEFAULT now(),
15377 query_text TEXT NOT NULL,
15378 query_type TEXT NOT NULL
15379 CONSTRAINT valid_query_text CHECK (
15380 query_type IN ( 'URL' )) DEFAULT 'URL',
15381 -- we may add other types someday
15382 target TEXT NOT NULL
15383 CONSTRAINT valid_target CHECK (
15384 target IN ( 'record', 'metarecord', 'callnumber' )),
15385 CONSTRAINT name_once_per_user UNIQUE (owner, name)
15388 -- Apply Dan Wells' changes to the serial schema, from the
15389 -- seials-integration branch
15391 CREATE TABLE serial.subscription_note (
15392 id SERIAL PRIMARY KEY,
15393 subscription INT NOT NULL
15394 REFERENCES serial.subscription (id)
15396 DEFERRABLE INITIALLY DEFERRED,
15397 creator INT NOT NULL
15398 REFERENCES actor.usr (id)
15399 DEFERRABLE INITIALLY DEFERRED,
15400 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
15401 pub BOOL NOT NULL DEFAULT FALSE,
15402 title TEXT NOT NULL,
15403 value TEXT NOT NULL
15406 CREATE TABLE serial.distribution_note (
15407 id SERIAL PRIMARY KEY,
15408 distribution INT NOT NULL
15409 REFERENCES serial.distribution (id)
15411 DEFERRABLE INITIALLY DEFERRED,
15412 creator INT NOT NULL
15413 REFERENCES actor.usr (id)
15414 DEFERRABLE INITIALLY DEFERRED,
15415 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
15416 pub BOOL NOT NULL DEFAULT FALSE,
15417 title TEXT NOT NULL,
15418 value TEXT NOT NULL
15421 ------- Begin surgery on serial.unit
15423 ALTER TABLE serial.unit
15426 ALTER TABLE serial.unit
15427 RENAME COLUMN label_sort_key TO sort_key;
15429 ALTER TABLE serial.unit
15430 RENAME COLUMN contents TO detailed_contents;
15432 ALTER TABLE serial.unit
15433 ADD COLUMN summary_contents TEXT;
15436 SET summary_contents = detailed_contents;
15438 ALTER TABLE serial.unit
15439 ALTER column summary_contents SET NOT NULL;
15441 ------- End surgery on serial.unit
15443 -- DELETE FROM config.upgrade_log WHERE version = 'temp'; DELETE FROM action_trigger.event WHERE event_def IN (33,34); DELETE FROM action_trigger.environment WHERE event_def IN (33,34); DELETE FROM action_trigger.event_definition WHERE id IN (33,34); DELETE FROM action_trigger.hook WHERE key IN ( 'circ.format.missing_pieces.slip.print', 'circ.format.missing_pieces.letter.print' );
15445 -- Now rebuild the constraints dropped via cascade.
15446 -- ALTER TABLE acq.provider ADD CONSTRAINT provider_edi_default_fkey FOREIGN KEY (edi_default) REFERENCES acq.edi_account (id) DEFERRABLE INITIALLY DEFERRED;
15447 DROP INDEX IF EXISTS money.money_mat_summary_id_idx;
15448 ALTER TABLE money.materialized_billable_xact_summary ADD PRIMARY KEY (id);
15450 -- ALTER TABLE staging.billing_address_stage ADD PRIMARY KEY (row_id);
15452 DELETE FROM config.metabib_field_index_norm_map
15455 FROM config.index_normalizer
15456 WHERE func IN ('first_word', 'naco_normalize', 'split_date_range')
15461 -- We won't necessarily use all of these, but they are here for completeness.
15462 -- Source is the EDI spec 6063 codelist, eg: http://www.stylusstudio.com/edifact/D04B/6063.htm
15463 -- Values are the EDI code value + 1200
15465 INSERT INTO acq.cancel_reason (org_unit, keep_debits, id, label, description) VALUES
15466 (1, 't', 1201, 'Discrete quantity', 'Individually separated and distinct quantity.'),
15467 (1, 't', 1202, 'Charge', 'Quantity relevant for charge.'),
15468 (1, 't', 1203, 'Cumulative quantity', 'Quantity accumulated.'),
15469 (1, 't', 1204, 'Interest for overdrawn account', 'Interest for overdrawing the account.'),
15470 (1, 't', 1205, 'Active ingredient dose per unit', 'The dosage of active ingredient per unit.'),
15471 (1, 't', 1206, 'Auditor', 'The number of entities that audit accounts.'),
15472 (1, 't', 1207, 'Branch locations, leased', 'The number of branch locations being leased by an entity.'),
15473 (1, 't', 1208, 'Inventory quantity at supplier''s subject to inspection by', 'customer Quantity of goods which the customer requires the supplier to have in inventory and which may be inspected by the customer if desired.'),
15474 (1, 't', 1209, 'Branch locations, owned', 'The number of branch locations owned by an entity.'),
15475 (1, 't', 1210, 'Judgements registered', 'The number of judgements registered against an entity.'),
15476 (1, 't', 1211, 'Split quantity', 'Part of the whole quantity.'),
15477 (1, 't', 1212, 'Despatch quantity', 'Quantity despatched by the seller.'),
15478 (1, 't', 1213, 'Liens registered', 'The number of liens registered against an entity.'),
15479 (1, 't', 1214, 'Livestock', 'The number of animals kept for use or profit.'),
15480 (1, 't', 1215, 'Insufficient funds returned cheques', 'The number of cheques returned due to insufficient funds.'),
15481 (1, 't', 1216, 'Stolen cheques', 'The number of stolen cheques.'),
15482 (1, 't', 1217, 'Quantity on hand', 'The total quantity of a product on hand at a location. This includes as well units awaiting return to manufacturer, units unavailable due to inspection procedures and undamaged stock available for despatch, resale or use.'),
15483 (1, 't', 1218, 'Previous quantity', 'Quantity previously referenced.'),
15484 (1, 't', 1219, 'Paid-in security shares', 'The number of security shares issued and for which full payment has been made.'),
15485 (1, 't', 1220, 'Unusable quantity', 'Quantity not usable.'),
15486 (1, 't', 1221, 'Ordered quantity', '[6024] The quantity which has been ordered.'),
15487 (1, 't', 1222, 'Quantity at 100%', 'Equivalent quantity at 100% purity.'),
15488 (1, 't', 1223, 'Active ingredient', 'Quantity at 100% active agent content.'),
15489 (1, 't', 1224, 'Inventory quantity at supplier''s not subject to inspection', 'by customer Quantity of goods which the customer requires the supplier to have in inventory but which will not be checked by the customer.'),
15490 (1, 't', 1225, 'Retail sales', 'Quantity of retail point of sale activity.'),
15491 (1, 't', 1226, 'Promotion quantity', 'A quantity associated with a promotional event.'),
15492 (1, 't', 1227, 'On hold for shipment', 'Article received which cannot be shipped in its present form.'),
15493 (1, 't', 1228, 'Military sales quantity', 'Quantity of goods or services sold to a military organization.'),
15494 (1, 't', 1229, 'On premises sales', 'Sale of product in restaurants or bars.'),
15495 (1, 't', 1230, 'Off premises sales', 'Sale of product directly to a store.'),
15496 (1, 't', 1231, 'Estimated annual volume', 'Volume estimated for a year.'),
15497 (1, 't', 1232, 'Minimum delivery batch', 'Minimum quantity of goods delivered at one time.'),
15498 (1, 't', 1233, 'Maximum delivery batch', 'Maximum quantity of goods delivered at one time.'),
15499 (1, 't', 1234, 'Pipes', 'The number of tubes used to convey a substance.'),
15500 (1, 't', 1235, 'Price break from', 'The minimum quantity of a quantity range for a specified (unit) price.'),
15501 (1, 't', 1236, 'Price break to', 'Maximum quantity to which the price break applies.'),
15502 (1, 't', 1237, 'Poultry', 'The number of domestic fowl.'),
15503 (1, 't', 1238, 'Secured charges registered', 'The number of secured charges registered against an entity.'),
15504 (1, 't', 1239, 'Total properties owned', 'The total number of properties owned by an entity.'),
15505 (1, 't', 1240, 'Normal delivery', 'Quantity normally delivered by the seller.'),
15506 (1, 't', 1241, 'Sales quantity not included in the replenishment', 'calculation Sales which will not be included in the calculation of replenishment requirements.'),
15507 (1, 't', 1242, 'Maximum supply quantity, supplier endorsed', 'Maximum supply quantity endorsed by a supplier.'),
15508 (1, 't', 1243, 'Buyer', 'The number of buyers.'),
15509 (1, 't', 1244, 'Debenture bond', 'The number of fixed-interest bonds of an entity backed by general credit rather than specified assets.'),
15510 (1, 't', 1245, 'Debentures filed against directors', 'The number of notices of indebtedness filed against an entity''s directors.'),
15511 (1, 't', 1246, 'Pieces delivered', 'Number of pieces actually received at the final destination.'),
15512 (1, 't', 1247, 'Invoiced quantity', 'The quantity as per invoice.'),
15513 (1, 't', 1248, 'Received quantity', 'The quantity which has been received.'),
15514 (1, 't', 1249, 'Chargeable distance', '[6110] The distance between two points for which a specific tariff applies.'),
15515 (1, 't', 1250, 'Disposition undetermined quantity', 'Product quantity that has not yet had its disposition determined.'),
15516 (1, 't', 1251, 'Inventory category transfer', 'Inventory that has been moved from one inventory category to another.'),
15517 (1, 't', 1252, 'Quantity per pack', 'Quantity for each pack.'),
15518 (1, 't', 1253, 'Minimum order quantity', 'Minimum quantity of goods for an order.'),
15519 (1, 't', 1254, 'Maximum order quantity', 'Maximum quantity of goods for an order.'),
15520 (1, 't', 1255, 'Total sales', 'The summation of total quantity sales.'),
15521 (1, 't', 1256, 'Wholesaler to wholesaler sales', 'Sale of product to other wholesalers by a wholesaler.'),
15522 (1, 't', 1257, 'In transit quantity', 'A quantity that is en route.'),
15523 (1, 't', 1258, 'Quantity withdrawn', 'Quantity withdrawn from a location.'),
15524 (1, 't', 1259, 'Numbers of consumer units in the traded unit', 'Number of units for consumer sales in a unit for trading.'),
15525 (1, 't', 1260, 'Current inventory quantity available for shipment', 'Current inventory quantity available for shipment.'),
15526 (1, 't', 1261, 'Return quantity', 'Quantity of goods returned.'),
15527 (1, 't', 1262, 'Sorted quantity', 'The quantity that is sorted.'),
15528 (1, 'f', 1263, 'Sorted quantity rejected', 'The sorted quantity that is rejected.'),
15529 (1, 't', 1264, 'Scrap quantity', 'Remainder of the total quantity after split deliveries.'),
15530 (1, 'f', 1265, 'Destroyed quantity', 'Quantity of goods destroyed.'),
15531 (1, 't', 1266, 'Committed quantity', 'Quantity a party is committed to.'),
15532 (1, 't', 1267, 'Estimated reading quantity', 'The value that is estimated to be the reading of a measuring device (e.g. meter).'),
15533 (1, 't', 1268, 'End quantity', 'The quantity recorded at the end of an agreement or period.'),
15534 (1, 't', 1269, 'Start quantity', 'The quantity recorded at the start of an agreement or period.'),
15535 (1, 't', 1270, 'Cumulative quantity received', 'Cumulative quantity of all deliveries of this article received by the buyer.'),
15536 (1, 't', 1271, 'Cumulative quantity ordered', 'Cumulative quantity of all deliveries, outstanding and scheduled orders.'),
15537 (1, 't', 1272, 'Cumulative quantity received end of prior year', 'Cumulative quantity of all deliveries of the product received by the buyer till end of prior year.'),
15538 (1, 't', 1273, 'Outstanding quantity', 'Difference between quantity ordered and quantity received.'),
15539 (1, 't', 1274, 'Latest cumulative quantity', 'Cumulative quantity after complete delivery of all scheduled quantities of the product.'),
15540 (1, 't', 1275, 'Previous highest cumulative quantity', 'Cumulative quantity after complete delivery of all scheduled quantities of the product from a prior schedule period.'),
15541 (1, 't', 1276, 'Adjusted corrector reading', 'A corrector reading after it has been adjusted.'),
15542 (1, 't', 1277, 'Work days', 'Number of work days, e.g. per respective period.'),
15543 (1, 't', 1278, 'Cumulative quantity scheduled', 'Adding the quantity actually scheduled to previous cumulative quantity.'),
15544 (1, 't', 1279, 'Previous cumulative quantity', 'Cumulative quantity prior the actual order.'),
15545 (1, 't', 1280, 'Unadjusted corrector reading', 'A corrector reading before it has been adjusted.'),
15546 (1, 't', 1281, 'Extra unplanned delivery', 'Non scheduled additional quantity.'),
15547 (1, 't', 1282, 'Quantity requirement for sample inspection', 'Required quantity for sample inspection.'),
15548 (1, 't', 1283, 'Backorder quantity', 'The quantity of goods that is on back-order.'),
15549 (1, 't', 1284, 'Urgent delivery quantity', 'Quantity for urgent delivery.'),
15550 (1, 'f', 1285, 'Previous order quantity to be cancelled', 'Quantity ordered previously to be cancelled.'),
15551 (1, 't', 1286, 'Normal reading quantity', 'The value recorded or read from a measuring device (e.g. meter) in the normal conditions.'),
15552 (1, 't', 1287, 'Customer reading quantity', 'The value recorded or read from a measuring device (e.g. meter) by the customer.'),
15553 (1, 't', 1288, 'Information reading quantity', 'The value recorded or read from a measuring device (e.g. meter) for information purposes.'),
15554 (1, 't', 1289, 'Quality control held', 'Quantity of goods held pending completion of a quality control assessment.'),
15555 (1, 't', 1290, 'As is quantity', 'Quantity as it is in the existing circumstances.'),
15556 (1, 't', 1291, 'Open quantity', 'Quantity remaining after partial delivery.'),
15557 (1, 't', 1292, 'Final delivery quantity', 'Quantity of final delivery to a respective order.'),
15558 (1, 't', 1293, 'Subsequent delivery quantity', 'Quantity delivered to a respective order after it''s final delivery.'),
15559 (1, 't', 1294, 'Substitutional quantity', 'Quantity delivered replacing previous deliveries.'),
15560 (1, 't', 1295, 'Redelivery after post processing', 'Quantity redelivered after post processing.'),
15561 (1, 'f', 1296, 'Quality control failed', 'Quantity of goods which have failed quality control.'),
15562 (1, 't', 1297, 'Minimum inventory', 'Minimum stock quantity on which replenishment is based.'),
15563 (1, 't', 1298, 'Maximum inventory', 'Maximum stock quantity on which replenishment is based.'),
15564 (1, 't', 1299, 'Estimated quantity', 'Quantity estimated.'),
15565 (1, 't', 1300, 'Chargeable weight', 'The weight on which charges are based.'),
15566 (1, 't', 1301, 'Chargeable gross weight', 'The gross weight on which charges are based.'),
15567 (1, 't', 1302, 'Chargeable tare weight', 'The tare weight on which charges are based.'),
15568 (1, 't', 1303, 'Chargeable number of axles', 'The number of axles on which charges are based.'),
15569 (1, 't', 1304, 'Chargeable number of containers', 'The number of containers on which charges are based.'),
15570 (1, 't', 1305, 'Chargeable number of rail wagons', 'The number of rail wagons on which charges are based.'),
15571 (1, 't', 1306, 'Chargeable number of packages', 'The number of packages on which charges are based.'),
15572 (1, 't', 1307, 'Chargeable number of units', 'The number of units on which charges are based.'),
15573 (1, 't', 1308, 'Chargeable period', 'The period of time on which charges are based.'),
15574 (1, 't', 1309, 'Chargeable volume', 'The volume on which charges are based.'),
15575 (1, 't', 1310, 'Chargeable cubic measurements', 'The cubic measurements on which charges are based.'),
15576 (1, 't', 1311, 'Chargeable surface', 'The surface area on which charges are based.'),
15577 (1, 't', 1312, 'Chargeable length', 'The length on which charges are based.'),
15578 (1, 't', 1313, 'Quantity to be delivered', 'The quantity to be delivered.'),
15579 (1, 't', 1314, 'Number of passengers', 'Total number of passengers on the conveyance.'),
15580 (1, 't', 1315, 'Number of crew', 'Total number of crew members on the conveyance.'),
15581 (1, 't', 1316, 'Number of transport documents', 'Total number of air waybills, bills of lading, etc. being reported for a specific conveyance.'),
15582 (1, 't', 1317, 'Quantity landed', 'Quantity of goods actually arrived.'),
15583 (1, 't', 1318, 'Quantity manifested', 'Quantity of goods contracted for delivery by the carrier.'),
15584 (1, 't', 1319, 'Short shipped', 'Indication that part of the consignment was not shipped.'),
15585 (1, 't', 1320, 'Split shipment', 'Indication that the consignment has been split into two or more shipments.'),
15586 (1, 't', 1321, 'Over shipped', 'The quantity of goods shipped that exceeds the quantity contracted.'),
15587 (1, 't', 1322, 'Short-landed goods', 'If quantity of goods actually landed is less than the quantity which appears in the documentation. This quantity is the difference between these quantities.'),
15588 (1, 't', 1323, 'Surplus goods', 'If quantity of goods actually landed is more than the quantity which appears in the documentation. This quantity is the difference between these quantities.'),
15589 (1, 'f', 1324, 'Damaged goods', 'Quantity of goods which have deteriorated in transport such that they cannot be used for the purpose for which they were originally intended.'),
15590 (1, 'f', 1325, 'Pilferage goods', 'Quantity of goods stolen during transport.'),
15591 (1, 'f', 1326, 'Lost goods', 'Quantity of goods that disappeared in transport.'),
15592 (1, 't', 1327, 'Report difference', 'The quantity concerning the same transaction differs between two documents/messages and the source of this difference is a typing error.'),
15593 (1, 't', 1328, 'Quantity loaded', 'Quantity of goods loaded onto a means of transport.'),
15594 (1, 't', 1329, 'Units per unit price', 'Number of units per unit price.'),
15595 (1, 't', 1330, 'Allowance', 'Quantity relevant for allowance.'),
15596 (1, 't', 1331, 'Delivery quantity', 'Quantity required by buyer to be delivered.'),
15597 (1, 't', 1332, 'Cumulative quantity, preceding period, planned', 'Cumulative quantity originally planned for the preceding period.'),
15598 (1, 't', 1333, 'Cumulative quantity, preceding period, reached', 'Cumulative quantity reached in the preceding period.'),
15599 (1, 't', 1334, 'Cumulative quantity, actual planned', 'Cumulative quantity planned for now.'),
15600 (1, 't', 1335, 'Period quantity, planned', 'Quantity planned for this period.'),
15601 (1, 't', 1336, 'Period quantity, reached', 'Quantity reached during this period.'),
15602 (1, 't', 1337, 'Cumulative quantity, preceding period, estimated', 'Estimated cumulative quantity reached in the preceding period.'),
15603 (1, 't', 1338, 'Cumulative quantity, actual estimated', 'Estimated cumulative quantity reached now.'),
15604 (1, 't', 1339, 'Cumulative quantity, preceding period, measured', 'Surveyed cumulative quantity reached in the preceding period.'),
15605 (1, 't', 1340, 'Cumulative quantity, actual measured', 'Surveyed cumulative quantity reached now.'),
15606 (1, 't', 1341, 'Period quantity, measured', 'Surveyed quantity reached during this period.'),
15607 (1, 't', 1342, 'Total quantity, planned', 'Total quantity planned.'),
15608 (1, 't', 1343, 'Quantity, remaining', 'Quantity remaining.'),
15609 (1, 't', 1344, 'Tolerance', 'Plus or minus tolerance expressed as a monetary amount.'),
15610 (1, 't', 1345, 'Actual stock', 'The stock on hand, undamaged, and available for despatch, sale or use.'),
15611 (1, 't', 1346, 'Model or target stock', 'The stock quantity required or planned to have on hand, undamaged and available for use.'),
15612 (1, 't', 1347, 'Direct shipment quantity', 'Quantity to be shipped directly to a customer from a manufacturing site.'),
15613 (1, 't', 1348, 'Amortization total quantity', 'Indication of final quantity for amortization.'),
15614 (1, 't', 1349, 'Amortization order quantity', 'Indication of actual share of the order quantity for amortization.'),
15615 (1, 't', 1350, 'Amortization cumulated quantity', 'Indication of actual cumulated quantity of previous and actual amortization order quantity.'),
15616 (1, 't', 1351, 'Quantity advised', 'Quantity advised by supplier or shipper, in contrast to quantity actually received.'),
15617 (1, 't', 1352, 'Consignment stock', 'Quantity of goods with an external customer which is still the property of the supplier. Payment for these goods is only made to the supplier when the ownership has been transferred between the trading partners.'),
15618 (1, 't', 1353, 'Statistical sales quantity', 'Quantity of goods sold in a specified period.'),
15619 (1, 't', 1354, 'Sales quantity planned', 'Quantity of goods required to meet future demands. - Market intelligence quantity.'),
15620 (1, 't', 1355, 'Replenishment quantity', 'Quantity required to maintain the requisite on-hand stock of goods.'),
15621 (1, 't', 1356, 'Inventory movement quantity', 'To specify the quantity of an inventory movement.'),
15622 (1, 't', 1357, 'Opening stock balance quantity', 'To specify the quantity of an opening stock balance.'),
15623 (1, 't', 1358, 'Closing stock balance quantity', 'To specify the quantity of a closing stock balance.'),
15624 (1, 't', 1359, 'Number of stops', 'Number of times a means of transport stops before arriving at destination.'),
15625 (1, 't', 1360, 'Minimum production batch', 'The quantity specified is the minimum output from a single production run.'),
15626 (1, 't', 1361, 'Dimensional sample quantity', 'The quantity defined is a sample for the purpose of validating dimensions.'),
15627 (1, 't', 1362, 'Functional sample quantity', 'The quantity defined is a sample for the purpose of validating function and performance.'),
15628 (1, 't', 1363, 'Pre-production quantity', 'Quantity of the referenced item required prior to full production.'),
15629 (1, 't', 1364, 'Delivery batch', 'Quantity of the referenced item which constitutes a standard batch for deliver purposes.'),
15630 (1, 't', 1365, 'Delivery batch multiple', 'The multiples in which delivery batches can be supplied.'),
15631 (1, 't', 1366, 'All time buy', 'The total quantity of the referenced covering all future needs. Further orders of the referenced item are not expected.'),
15632 (1, 't', 1367, 'Total delivery quantity', 'The total quantity required by the buyer to be delivered.'),
15633 (1, 't', 1368, 'Single delivery quantity', 'The quantity required by the buyer to be delivered in a single shipment.'),
15634 (1, 't', 1369, 'Supplied quantity', 'Quantity of the referenced item actually shipped.'),
15635 (1, 't', 1370, 'Allocated quantity', 'Quantity of the referenced item allocated from available stock for delivery.'),
15636 (1, 't', 1371, 'Maximum stackability', 'The number of pallets/handling units which can be safely stacked one on top of another.'),
15637 (1, 't', 1372, 'Amortisation quantity', 'The quantity of the referenced item which has a cost for tooling amortisation included in the item price.'),
15638 (1, 't', 1373, 'Previously amortised quantity', 'The cumulative quantity of the referenced item which had a cost for tooling amortisation included in the item price.'),
15639 (1, 't', 1374, 'Total amortisation quantity', 'The total quantity of the referenced item which has a cost for tooling amortisation included in the item price.'),
15640 (1, 't', 1375, 'Number of moulds', 'The number of pressing moulds contained within a single piece of the referenced tooling.'),
15641 (1, 't', 1376, 'Concurrent item output of tooling', 'The number of related items which can be produced simultaneously with a single piece of the referenced tooling.'),
15642 (1, 't', 1377, 'Periodic capacity of tooling', 'Maximum production output of the referenced tool over a period of time.'),
15643 (1, 't', 1378, 'Lifetime capacity of tooling', 'Maximum production output of the referenced tool over its productive lifetime.'),
15644 (1, 't', 1379, 'Number of deliveries per despatch period', 'The number of deliveries normally expected to be despatched within each despatch period.'),
15645 (1, 't', 1380, 'Provided quantity', 'The quantity of a referenced component supplied by the buyer for manufacturing of an ordered item.'),
15646 (1, 't', 1381, 'Maximum production batch', 'The quantity specified is the maximum output from a single production run.'),
15647 (1, 'f', 1382, 'Cancelled quantity', 'Quantity of the referenced item which has previously been ordered and is now cancelled.'),
15648 (1, 't', 1383, 'No delivery requirement in this instruction', 'This delivery instruction does not contain any delivery requirements.'),
15649 (1, 't', 1384, 'Quantity of material in ordered time', 'Quantity of the referenced material within the ordered time.'),
15650 (1, 'f', 1385, 'Rejected quantity', 'The quantity of received goods rejected for quantity reasons.'),
15651 (1, 't', 1386, 'Cumulative quantity scheduled up to accumulation start date', 'The cumulative quantity scheduled up to the accumulation start date.'),
15652 (1, 't', 1387, 'Quantity scheduled', 'The quantity scheduled for delivery.'),
15653 (1, 't', 1388, 'Number of identical handling units', 'Number of identical handling units in terms of type and contents.'),
15654 (1, 't', 1389, 'Number of packages in handling unit', 'The number of packages contained in one handling unit.'),
15655 (1, 't', 1390, 'Despatch note quantity', 'The item quantity specified on the despatch note.'),
15656 (1, 't', 1391, 'Adjustment to inventory quantity', 'An adjustment to inventory quantity.'),
15657 (1, 't', 1392, 'Free goods quantity', 'Quantity of goods which are free of charge.'),
15658 (1, 't', 1393, 'Free quantity included', 'Quantity included to which no charge is applicable.'),
15659 (1, 't', 1394, 'Received and accepted', 'Quantity which has been received and accepted at a given location.'),
15660 (1, 'f', 1395, 'Received, not accepted, to be returned', 'Quantity which has been received but not accepted at a given location and which will consequently be returned to the relevant party.'),
15661 (1, 'f', 1396, 'Received, not accepted, to be destroyed', 'Quantity which has been received but not accepted at a given location and which will consequently be destroyed.'),
15662 (1, 't', 1397, 'Reordering level', 'Quantity at which an order may be triggered to replenish.'),
15663 (1, 't', 1399, 'Inventory withdrawal quantity', 'Quantity which has been withdrawn from inventory since the last inventory report.'),
15664 (1, 't', 1400, 'Free quantity not included', 'Free quantity not included in ordered quantity.'),
15665 (1, 't', 1401, 'Recommended overhaul and repair quantity', 'To indicate the recommended quantity of an article required to support overhaul and repair activities.'),
15666 (1, 't', 1402, 'Quantity per next higher assembly', 'To indicate the quantity required for the next higher assembly.'),
15667 (1, 't', 1403, 'Quantity per unit of issue', 'Provides the standard quantity of an article in which one unit can be issued.'),
15668 (1, 't', 1404, 'Cumulative scrap quantity', 'Provides the cumulative quantity of an item which has been identified as scrapped.'),
15669 (1, 't', 1405, 'Publication turn size', 'The quantity of magazines or newspapers grouped together with the spine facing alternate directions in a bundle.'),
15670 (1, 't', 1406, 'Recommended maintenance quantity', 'Recommended quantity of an article which is required to meet an agreed level of maintenance.'),
15671 (1, 't', 1407, 'Labour hours', 'Number of labour hours.'),
15672 (1, 't', 1408, 'Quantity requirement for maintenance and repair of', 'equipment Quantity of the material needed to maintain and repair equipment.'),
15673 (1, 't', 1409, 'Additional replenishment demand quantity', 'Incremental needs over and above normal replenishment calculations, but not intended to permanently change the model parameters.'),
15674 (1, 't', 1410, 'Returned by consumer quantity', 'Quantity returned by a consumer.'),
15675 (1, 't', 1411, 'Replenishment override quantity', 'Quantity to override the normal replenishment model calculations, but not intended to permanently change the model parameters.'),
15676 (1, 't', 1412, 'Quantity sold, net', 'Net quantity sold which includes returns of saleable inventory and other adjustments.'),
15677 (1, 't', 1413, 'Transferred out quantity', 'Quantity which was transferred out of this location.'),
15678 (1, 't', 1414, 'Transferred in quantity', 'Quantity which was transferred into this location.'),
15679 (1, 't', 1415, 'Unsaleable quantity', 'Quantity of inventory received which cannot be sold in its present condition.'),
15680 (1, 't', 1416, 'Consumer reserved quantity', 'Quantity reserved for consumer delivery or pickup and not yet withdrawn from inventory.'),
15681 (1, 't', 1417, 'Out of inventory quantity', 'Quantity of inventory which was requested but was not available.'),
15682 (1, 't', 1418, 'Quantity returned, defective or damaged', 'Quantity returned in a damaged or defective condition.'),
15683 (1, 't', 1419, 'Taxable quantity', 'Quantity subject to taxation.'),
15684 (1, 't', 1420, 'Meter reading', 'The numeric value of measure units counted by a meter.'),
15685 (1, 't', 1421, 'Maximum requestable quantity', 'The maximum quantity which may be requested.'),
15686 (1, 't', 1422, 'Minimum requestable quantity', 'The minimum quantity which may be requested.'),
15687 (1, 't', 1423, 'Daily average quantity', 'The quantity for a defined period divided by the number of days of the period.'),
15688 (1, 't', 1424, 'Budgeted hours', 'The number of budgeted hours.'),
15689 (1, 't', 1425, 'Actual hours', 'The number of actual hours.'),
15690 (1, 't', 1426, 'Earned value hours', 'The number of earned value hours.'),
15691 (1, 't', 1427, 'Estimated hours', 'The number of estimated hours.'),
15692 (1, 't', 1428, 'Level resource task quantity', 'Quantity of a resource that is level for the duration of the task.'),
15693 (1, 't', 1429, 'Available resource task quantity', 'Quantity of a resource available to complete a task.'),
15694 (1, 't', 1430, 'Work time units', 'Quantity of work units of time.'),
15695 (1, 't', 1431, 'Daily work shifts', 'Quantity of work shifts per day.'),
15696 (1, 't', 1432, 'Work time units per shift', 'Work units of time per work shift.'),
15697 (1, 't', 1433, 'Work calendar units', 'Work calendar units of time.'),
15698 (1, 't', 1434, 'Elapsed duration', 'Quantity representing the elapsed duration.'),
15699 (1, 't', 1435, 'Remaining duration', 'Quantity representing the remaining duration.'),
15700 (1, 't', 1436, 'Original duration', 'Quantity representing the original duration.'),
15701 (1, 't', 1437, 'Current duration', 'Quantity representing the current duration.'),
15702 (1, 't', 1438, 'Total float time', 'Quantity representing the total float time.'),
15703 (1, 't', 1439, 'Free float time', 'Quantity representing the free float time.'),
15704 (1, 't', 1440, 'Lag time', 'Quantity representing lag time.'),
15705 (1, 't', 1441, 'Lead time', 'Quantity representing lead time.'),
15706 (1, 't', 1442, 'Number of months', 'The number of months.'),
15707 (1, 't', 1443, 'Reserved quantity customer direct delivery sales', 'Quantity of products reserved for sales delivered direct to the customer.'),
15708 (1, 't', 1444, 'Reserved quantity retail sales', 'Quantity of products reserved for retail sales.'),
15709 (1, 't', 1445, 'Consolidated discount inventory', 'A quantity of inventory supplied at consolidated discount terms.'),
15710 (1, 't', 1446, 'Returns replacement quantity', 'A quantity of goods issued as a replacement for a returned quantity.'),
15711 (1, 't', 1447, 'Additional promotion sales forecast quantity', 'A forecast of additional quantity which will be sold during a period of promotional activity.'),
15712 (1, 't', 1448, 'Reserved quantity', 'Quantity reserved for specific purposes.'),
15713 (1, 't', 1449, 'Quantity displayed not available for sale', 'Quantity displayed within a retail outlet but not available for sale.'),
15714 (1, 't', 1450, 'Inventory discrepancy', 'The difference recorded between theoretical and physical inventory.'),
15715 (1, 't', 1451, 'Incremental order quantity', 'The incremental quantity by which ordering is carried out.'),
15716 (1, 't', 1452, 'Quantity requiring manipulation before despatch', 'A quantity of goods which needs manipulation before despatch.'),
15717 (1, 't', 1453, 'Quantity in quarantine', 'A quantity of goods which are held in a restricted area for quarantine purposes.'),
15718 (1, 't', 1454, 'Quantity withheld by owner of goods', 'A quantity of goods which has been withheld by the owner of the goods.'),
15719 (1, 't', 1455, 'Quantity not available for despatch', 'A quantity of goods not available for despatch.'),
15720 (1, 't', 1456, 'Quantity awaiting delivery', 'Quantity of goods which are awaiting delivery.'),
15721 (1, 't', 1457, 'Quantity in physical inventory', 'A quantity of goods held in physical inventory.'),
15722 (1, 't', 1458, 'Quantity held by logistic service provider', 'Quantity of goods under the control of a logistic service provider.'),
15723 (1, 't', 1459, 'Optimal quantity', 'The optimal quantity for a given purpose.'),
15724 (1, 't', 1460, 'Delivery quantity balance', 'The difference between the scheduled quantity and the quantity delivered to the consignee at a given date.'),
15725 (1, 't', 1461, 'Cumulative quantity shipped', 'Cumulative quantity of all shipments.'),
15726 (1, 't', 1462, 'Quantity suspended', 'The quantity of something which is suspended.'),
15727 (1, 't', 1463, 'Control quantity', 'The quantity designated for control purposes.'),
15728 (1, 't', 1464, 'Equipment quantity', 'A count of a quantity of equipment.'),
15729 (1, 't', 1465, 'Factor', 'Number by which the measured unit has to be multiplied to calculate the units used.'),
15730 (1, 't', 1466, 'Unsold quantity held by wholesaler', 'Unsold quantity held by the wholesaler.'),
15731 (1, 't', 1467, 'Quantity held by delivery vehicle', 'Quantity of goods held by the delivery vehicle.'),
15732 (1, 't', 1468, 'Quantity held by retail outlet', 'Quantity held by the retail outlet.'),
15733 (1, 'f', 1469, 'Rejected return quantity', 'A quantity for return which has been rejected.'),
15734 (1, 't', 1470, 'Accounts', 'The number of accounts.'),
15735 (1, 't', 1471, 'Accounts placed for collection', 'The number of accounts placed for collection.'),
15736 (1, 't', 1472, 'Activity codes', 'The number of activity codes.'),
15737 (1, 't', 1473, 'Agents', 'The number of agents.'),
15738 (1, 't', 1474, 'Airline attendants', 'The number of airline attendants.'),
15739 (1, 't', 1475, 'Authorised shares', 'The number of shares authorised for issue.'),
15740 (1, 't', 1476, 'Employee average', 'The average number of employees.'),
15741 (1, 't', 1477, 'Branch locations', 'The number of branch locations.'),
15742 (1, 't', 1478, 'Capital changes', 'The number of capital changes made.'),
15743 (1, 't', 1479, 'Clerks', 'The number of clerks.'),
15744 (1, 't', 1480, 'Companies in same activity', 'The number of companies doing business in the same activity category.'),
15745 (1, 't', 1481, 'Companies included in consolidated financial statement', 'The number of companies included in a consolidated financial statement.'),
15746 (1, 't', 1482, 'Cooperative shares', 'The number of cooperative shares.'),
15747 (1, 't', 1483, 'Creditors', 'The number of creditors.'),
15748 (1, 't', 1484, 'Departments', 'The number of departments.'),
15749 (1, 't', 1485, 'Design employees', 'The number of employees involved in the design process.'),
15750 (1, 't', 1486, 'Physicians', 'The number of medical doctors.'),
15751 (1, 't', 1487, 'Domestic affiliated companies', 'The number of affiliated companies located within the country.'),
15752 (1, 't', 1488, 'Drivers', 'The number of drivers.'),
15753 (1, 't', 1489, 'Employed at location', 'The number of employees at the specified location.'),
15754 (1, 't', 1490, 'Employed by this company', 'The number of employees at the specified company.'),
15755 (1, 't', 1491, 'Total employees', 'The total number of employees.'),
15756 (1, 't', 1492, 'Employees shared', 'The number of employees shared among entities.'),
15757 (1, 't', 1493, 'Engineers', 'The number of engineers.'),
15758 (1, 't', 1494, 'Estimated accounts', 'The estimated number of accounts.'),
15759 (1, 't', 1495, 'Estimated employees at location', 'The estimated number of employees at the specified location.'),
15760 (1, 't', 1496, 'Estimated total employees', 'The total estimated number of employees.'),
15761 (1, 't', 1497, 'Executives', 'The number of executives.'),
15762 (1, 't', 1498, 'Agricultural workers', 'The number of agricultural workers.'),
15763 (1, 't', 1499, 'Financial institutions', 'The number of financial institutions.'),
15764 (1, 't', 1500, 'Floors occupied', 'The number of floors occupied.'),
15765 (1, 't', 1501, 'Foreign related entities', 'The number of related entities located outside the country.'),
15766 (1, 't', 1502, 'Group employees', 'The number of employees within the group.'),
15767 (1, 't', 1503, 'Indirect employees', 'The number of employees not associated with direct production.'),
15768 (1, 't', 1504, 'Installers', 'The number of employees involved with the installation process.'),
15769 (1, 't', 1505, 'Invoices', 'The number of invoices.'),
15770 (1, 't', 1506, 'Issued shares', 'The number of shares actually issued.'),
15771 (1, 't', 1507, 'Labourers', 'The number of labourers.'),
15772 (1, 't', 1508, 'Manufactured units', 'The number of units manufactured.'),
15773 (1, 't', 1509, 'Maximum number of employees', 'The maximum number of people employed.'),
15774 (1, 't', 1510, 'Maximum number of employees at location', 'The maximum number of people employed at a location.'),
15775 (1, 't', 1511, 'Members in group', 'The number of members within a group.'),
15776 (1, 't', 1512, 'Minimum number of employees at location', 'The minimum number of people employed at a location.'),
15777 (1, 't', 1513, 'Minimum number of employees', 'The minimum number of people employed.'),
15778 (1, 't', 1514, 'Non-union employees', 'The number of employees not belonging to a labour union.'),
15779 (1, 't', 1515, 'Floors', 'The number of floors in a building.'),
15780 (1, 't', 1516, 'Nurses', 'The number of nurses.'),
15781 (1, 't', 1517, 'Office workers', 'The number of workers in an office.'),
15782 (1, 't', 1518, 'Other employees', 'The number of employees otherwise categorised.'),
15783 (1, 't', 1519, 'Part time employees', 'The number of employees working on a part time basis.'),
15784 (1, 't', 1520, 'Accounts payable average overdue days', 'The average number of days accounts payable are overdue.'),
15785 (1, 't', 1521, 'Pilots', 'The number of pilots.'),
15786 (1, 't', 1522, 'Plant workers', 'The number of workers within a plant.'),
15787 (1, 't', 1523, 'Previous number of accounts', 'The number of accounts which preceded the current count.'),
15788 (1, 't', 1524, 'Previous number of branch locations', 'The number of branch locations which preceded the current count.'),
15789 (1, 't', 1525, 'Principals included as employees', 'The number of principals which are included in the count of employees.'),
15790 (1, 't', 1526, 'Protested bills', 'The number of bills which are protested.'),
15791 (1, 't', 1527, 'Registered brands distributed', 'The number of registered brands which are being distributed.'),
15792 (1, 't', 1528, 'Registered brands manufactured', 'The number of registered brands which are being manufactured.'),
15793 (1, 't', 1529, 'Related business entities', 'The number of related business entities.'),
15794 (1, 't', 1530, 'Relatives employed', 'The number of relatives which are counted as employees.'),
15795 (1, 't', 1531, 'Rooms', 'The number of rooms.'),
15796 (1, 't', 1532, 'Salespersons', 'The number of salespersons.'),
15797 (1, 't', 1533, 'Seats', 'The number of seats.'),
15798 (1, 't', 1534, 'Shareholders', 'The number of shareholders.'),
15799 (1, 't', 1535, 'Shares of common stock', 'The number of shares of common stock.'),
15800 (1, 't', 1536, 'Shares of preferred stock', 'The number of shares of preferred stock.'),
15801 (1, 't', 1537, 'Silent partners', 'The number of silent partners.'),
15802 (1, 't', 1538, 'Subcontractors', 'The number of subcontractors.'),
15803 (1, 't', 1539, 'Subsidiaries', 'The number of subsidiaries.'),
15804 (1, 't', 1540, 'Law suits', 'The number of law suits.'),
15805 (1, 't', 1541, 'Suppliers', 'The number of suppliers.'),
15806 (1, 't', 1542, 'Teachers', 'The number of teachers.'),
15807 (1, 't', 1543, 'Technicians', 'The number of technicians.'),
15808 (1, 't', 1544, 'Trainees', 'The number of trainees.'),
15809 (1, 't', 1545, 'Union employees', 'The number of employees who are members of a labour union.'),
15810 (1, 't', 1546, 'Number of units', 'The quantity of units.'),
15811 (1, 't', 1547, 'Warehouse employees', 'The number of employees who work in a warehouse setting.'),
15812 (1, 't', 1548, 'Shareholders holding remainder of shares', 'Number of shareholders owning the remainder of shares.'),
15813 (1, 't', 1549, 'Payment orders filed', 'Number of payment orders filed.'),
15814 (1, 't', 1550, 'Uncovered cheques', 'Number of uncovered cheques.'),
15815 (1, 't', 1551, 'Auctions', 'Number of auctions.'),
15816 (1, 't', 1552, 'Units produced', 'The number of units produced.'),
15817 (1, 't', 1553, 'Added employees', 'Number of employees that were added to the workforce.'),
15818 (1, 't', 1554, 'Number of added locations', 'Number of locations that were added.'),
15819 (1, 't', 1555, 'Total number of foreign subsidiaries not included in', 'financial statement The total number of foreign subsidiaries not included in the financial statement.'),
15820 (1, 't', 1556, 'Number of closed locations', 'Number of locations that were closed.'),
15821 (1, 't', 1557, 'Counter clerks', 'The number of clerks that work behind a flat-topped fitment.'),
15822 (1, 't', 1558, 'Payment experiences in the last 3 months', 'The number of payment experiences received for an entity over the last 3 months.'),
15823 (1, 't', 1559, 'Payment experiences in the last 12 months', 'The number of payment experiences received for an entity over the last 12 months.'),
15824 (1, 't', 1560, 'Total number of subsidiaries not included in the financial', 'statement The total number of subsidiaries not included in the financial statement.'),
15825 (1, 't', 1561, 'Paid-in common shares', 'The number of paid-in common shares.'),
15826 (1, 't', 1562, 'Total number of domestic subsidiaries not included in', 'financial statement The total number of domestic subsidiaries not included in the financial statement.'),
15827 (1, 't', 1563, 'Total number of foreign subsidiaries included in financial statement', 'The total number of foreign subsidiaries included in the financial statement.'),
15828 (1, 't', 1564, 'Total number of domestic subsidiaries included in financial statement', 'The total number of domestic subsidiaries included in the financial statement.'),
15829 (1, 't', 1565, 'Total transactions', 'The total number of transactions.'),
15830 (1, 't', 1566, 'Paid-in preferred shares', 'The number of paid-in preferred shares.'),
15831 (1, 't', 1567, 'Employees', 'Code specifying the quantity of persons working for a company, whose services are used for pay.'),
15832 (1, 't', 1568, 'Active ingredient dose per unit, dispensed', 'The dosage of active ingredient per dispensed unit.'),
15833 (1, 't', 1569, 'Budget', 'Budget quantity.'),
15834 (1, 't', 1570, 'Budget, cumulative to date', 'Budget quantity, cumulative to date.'),
15835 (1, 't', 1571, 'Actual units', 'The number of actual units.'),
15836 (1, 't', 1572, 'Actual units, cumulative to date', 'The number of cumulative to date actual units.'),
15837 (1, 't', 1573, 'Earned value', 'Earned value quantity.'),
15838 (1, 't', 1574, 'Earned value, cumulative to date', 'Earned value quantity accumulated to date.'),
15839 (1, 't', 1575, 'At completion quantity, estimated', 'The estimated quantity when a project is complete.'),
15840 (1, 't', 1576, 'To complete quantity, estimated', 'The estimated quantity required to complete a project.'),
15841 (1, 't', 1577, 'Adjusted units', 'The number of adjusted units.'),
15842 (1, 't', 1578, 'Number of limited partnership shares', 'Number of shares held in a limited partnership.'),
15843 (1, 't', 1579, 'National business failure incidences', 'Number of firms in a country that discontinued with a loss to creditors.'),
15844 (1, 't', 1580, 'Industry business failure incidences', 'Number of firms in a specific industry that discontinued with a loss to creditors.'),
15845 (1, 't', 1581, 'Business class failure incidences', 'Number of firms in a specific class that discontinued with a loss to creditors.'),
15846 (1, 't', 1582, 'Mechanics', 'Number of mechanics.'),
15847 (1, 't', 1583, 'Messengers', 'Number of messengers.'),
15848 (1, 't', 1584, 'Primary managers', 'Number of primary managers.'),
15849 (1, 't', 1585, 'Secretaries', 'Number of secretaries.'),
15850 (1, 't', 1586, 'Detrimental legal filings', 'Number of detrimental legal filings.'),
15851 (1, 't', 1587, 'Branch office locations, estimated', 'Estimated number of branch office locations.'),
15852 (1, 't', 1588, 'Previous number of employees', 'The number of employees for a previous period.'),
15853 (1, 't', 1589, 'Asset seizers', 'Number of entities that seize assets of another entity.'),
15854 (1, 't', 1590, 'Out-turned quantity', 'The quantity discharged.'),
15855 (1, 't', 1591, 'Material on-board quantity, prior to loading', 'The material in vessel tanks, void spaces, and pipelines prior to loading.'),
15856 (1, 't', 1592, 'Supplier estimated previous meter reading', 'Previous meter reading estimated by the supplier.'),
15857 (1, 't', 1593, 'Supplier estimated latest meter reading', 'Latest meter reading estimated by the supplier.'),
15858 (1, 't', 1594, 'Customer estimated previous meter reading', 'Previous meter reading estimated by the customer.'),
15859 (1, 't', 1595, 'Customer estimated latest meter reading', 'Latest meter reading estimated by the customer.'),
15860 (1, 't', 1596, 'Supplier previous meter reading', 'Previous meter reading done by the supplier.'),
15861 (1, 't', 1597, 'Supplier latest meter reading', 'Latest meter reading recorded by the supplier.'),
15862 (1, 't', 1598, 'Maximum number of purchase orders allowed', 'Maximum number of purchase orders that are allowed.'),
15863 (1, 't', 1599, 'File size before compression', 'The size of a file before compression.'),
15864 (1, 't', 1600, 'File size after compression', 'The size of a file after compression.'),
15865 (1, 't', 1601, 'Securities shares', 'Number of shares of securities.'),
15866 (1, 't', 1602, 'Patients', 'Number of patients.'),
15867 (1, 't', 1603, 'Completed projects', 'Number of completed projects.'),
15868 (1, 't', 1604, 'Promoters', 'Number of entities who finance or organize an event or a production.'),
15869 (1, 't', 1605, 'Administrators', 'Number of administrators.'),
15870 (1, 't', 1606, 'Supervisors', 'Number of supervisors.'),
15871 (1, 't', 1607, 'Professionals', 'Number of professionals.'),
15872 (1, 't', 1608, 'Debt collectors', 'Number of debt collectors.'),
15873 (1, 't', 1609, 'Inspectors', 'Number of individuals who perform inspections.'),
15874 (1, 't', 1610, 'Operators', 'Number of operators.'),
15875 (1, 't', 1611, 'Trainers', 'Number of trainers.'),
15876 (1, 't', 1612, 'Active accounts', 'Number of accounts in a current or active status.'),
15877 (1, 't', 1613, 'Trademarks used', 'Number of trademarks used.'),
15878 (1, 't', 1614, 'Machines', 'Number of machines.'),
15879 (1, 't', 1615, 'Fuel pumps', 'Number of fuel pumps.'),
15880 (1, 't', 1616, 'Tables available', 'Number of tables available for use.'),
15881 (1, 't', 1617, 'Directors', 'Number of directors.'),
15882 (1, 't', 1618, 'Freelance debt collectors', 'Number of debt collectors who work on a freelance basis.'),
15883 (1, 't', 1619, 'Freelance salespersons', 'Number of salespersons who work on a freelance basis.'),
15884 (1, 't', 1620, 'Travelling employees', 'Number of travelling employees.'),
15885 (1, 't', 1621, 'Foremen', 'Number of workers with limited supervisory responsibilities.'),
15886 (1, 't', 1622, 'Production workers', 'Number of employees engaged in production.'),
15887 (1, 't', 1623, 'Employees not including owners', 'Number of employees excluding business owners.'),
15888 (1, 't', 1624, 'Beds', 'Number of beds.'),
15889 (1, 't', 1625, 'Resting quantity', 'A quantity of product that is at rest before it can be used.'),
15890 (1, 't', 1626, 'Production requirements', 'Quantity needed to meet production requirements.'),
15891 (1, 't', 1627, 'Corrected quantity', 'The quantity has been corrected.'),
15892 (1, 't', 1628, 'Operating divisions', 'Number of divisions operating.'),
15893 (1, 't', 1629, 'Quantitative incentive scheme base', 'Quantity constituting the base for the quantitative incentive scheme.'),
15894 (1, 't', 1630, 'Petitions filed', 'Number of petitions that have been filed.'),
15895 (1, 't', 1631, 'Bankruptcy petitions filed', 'Number of bankruptcy petitions that have been filed.'),
15896 (1, 't', 1632, 'Projects in process', 'Number of projects in process.'),
15897 (1, 't', 1633, 'Changes in capital structure', 'Number of modifications made to the capital structure of an entity.'),
15898 (1, 't', 1634, 'Detrimental legal filings against directors', 'The number of legal filings that are of a detrimental nature that have been filed against the directors.'),
15899 (1, 't', 1635, 'Number of failed businesses of directors', 'The number of failed businesses with which the directors have been associated.'),
15900 (1, 't', 1636, 'Professor', 'The number of professors.'),
15901 (1, 't', 1637, 'Seller', 'The number of sellers.'),
15902 (1, 't', 1638, 'Skilled worker', 'The number of skilled workers.'),
15903 (1, 't', 1639, 'Trademark represented', 'The number of trademarks represented.'),
15904 (1, 't', 1640, 'Number of quantitative incentive scheme units', 'Number of units allocated to a quantitative incentive scheme.'),
15905 (1, 't', 1641, 'Quantity in manufacturing process', 'Quantity currently in the manufacturing process.'),
15906 (1, 't', 1642, 'Number of units in the width of a layer', 'Number of units which make up the width of a layer.'),
15907 (1, 't', 1643, 'Number of units in the depth of a layer', 'Number of units which make up the depth of a layer.'),
15908 (1, 't', 1644, 'Return to warehouse', 'A quantity of products sent back to the warehouse.'),
15909 (1, 't', 1645, 'Return to the manufacturer', 'A quantity of products sent back from the manufacturer.'),
15910 (1, 't', 1646, 'Delta quantity', 'An increment or decrement to a quantity.'),
15911 (1, 't', 1647, 'Quantity moved between outlets', 'A quantity of products moved between outlets.'),
15912 (1, 't', 1648, 'Pre-paid invoice annual consumption, estimated', 'The estimated annual consumption used for a prepayment invoice.'),
15913 (1, 't', 1649, 'Total quoted quantity', 'The sum of quoted quantities.'),
15914 (1, 't', 1650, 'Requests pertaining to entity in last 12 months', 'Number of requests received in last 12 months pertaining to the entity.'),
15915 (1, 't', 1651, 'Total inquiry matches', 'Number of instances which correspond with the inquiry.'),
15916 (1, 't', 1652, 'En route to warehouse quantity', 'A quantity of products that is en route to a warehouse.'),
15917 (1, 't', 1653, 'En route from warehouse quantity', 'A quantity of products that is en route from a warehouse.'),
15918 (1, 't', 1654, 'Quantity ordered but not yet allocated from stock', 'A quantity of products which has been ordered but which has not yet been allocated from stock.'),
15919 (1, 't', 1655, 'Not yet ordered quantity', 'The quantity which has not yet been ordered.'),
15920 (1, 't', 1656, 'Net reserve power', 'The reserve power available for the net.'),
15921 (1, 't', 1657, 'Maximum number of units per shelf', 'Maximum number of units of a product that can be placed on a shelf.'),
15922 (1, 't', 1658, 'Stowaway', 'Number of stowaway(s) on a conveyance.'),
15923 (1, 't', 1659, 'Tug', 'The number of tugboat(s).'),
15924 (1, 't', 1660, 'Maximum quantity capability of the package', 'Maximum quantity of a product that can be contained in a package.'),
15925 (1, 't', 1661, 'Calculated', 'The calculated quantity.'),
15926 (1, 't', 1662, 'Monthly volume, estimated', 'Volume estimated for a month.'),
15927 (1, 't', 1663, 'Total number of persons', 'Quantity representing the total number of persons.'),
15928 (1, 't', 1664, 'Tariff Quantity', 'Quantity of the goods in the unit as required by Customs for duty/tax/fee assessment. These quantities may also be used for other fiscal or statistical purposes.'),
15929 (1, 't', 1665, 'Deducted tariff quantity', 'Quantity deducted from tariff quantity to reckon duty/tax/fee assessment bases.'),
15930 (1, 't', 1666, 'Advised but not arrived', 'Goods are advised by the consignor or supplier, but have not yet arrived at the destination.'),
15931 (1, 't', 1667, 'Received but not available', 'Goods have been received in the arrival area but are not yet available.'),
15932 (1, 't', 1668, 'Goods blocked for transshipment process', 'Goods are physically present, but can not be ordered because they are scheduled for a transshipment process.'),
15933 (1, 't', 1669, 'Goods blocked for cross docking process', 'Goods are physically present, but can not be ordered because they are scheduled for a cross docking process.'),
15934 (1, 't', 1670, 'Chargeable number of trailers', 'The number of trailers on which charges are based.'),
15935 (1, 't', 1671, 'Number of packages for a set', 'Number of packages used to pack the individual items in a grouping of merchandise that is sold together as a single trade item.'),
15936 (1, 't', 1672, 'Number of items in a set', 'The number of individual items in a grouping of merchandise that is sold together as a single trade item.'),
15937 (1, 't', 1673, 'Order sizing factor', 'A trade item specification other than gross, net weight, or volume for a trade item or a transaction, used for order sizing and pricing purposes.'),
15938 (1, 't', 1674, 'Number of different next lower level trade items', 'Value indicates the number of differrent next lower level trade items contained in a complex trade item.'),
15939 (1, 't', 1675, 'Agreed maximum buying quantity', 'The agreed maximum quantity of the trade item that may be purchased.'),
15940 (1, 't', 1676, 'Agreed minimum buying quantity', 'The agreed minimum quantity of the trade item that may be purchased.'),
15941 (1, 't', 1677, 'Free quantity of next lower level trade item', 'The numeric quantity of free items in a combination pack. The unit of measure used for the free quantity of the next lower level must be the same as the unit of measure of the Net Content of the Child Trade Item.'),
15942 (1, 't', 1678, 'Marine Diesel Oil bunkers on board, on arrival', 'Number of Marine Diesel Oil (MDO) bunkers on board when the vessel arrives in the port.'),
15943 (1, 't', 1679, 'Marine Diesel Oil bunkers, loaded', 'Number of Marine Diesel Oil (MDO) bunkers taken on in the port.'),
15944 (1, 't', 1680, 'Intermediate Fuel Oil bunkers on board, on arrival', 'Number of Intermediate Fuel Oil (IFO) bunkers on board when the vessel arrives in the port.'),
15945 (1, 't', 1681, 'Intermediate Fuel Oil bunkers, loaded', 'Number of Intermediate Fuel Oil (IFO) bunkers taken on in the port.'),
15946 (1, 't', 1682, 'Bunker C bunkers on board, on arrival', 'Number of Bunker C, or Number 6 fuel oil bunkers on board when the vessel arrives in the port.'),
15947 (1, 't', 1683, 'Bunker C bunkers, loaded', 'Number of Bunker C, or Number 6 fuel oil bunkers, taken on in the port.'),
15948 (1, 't', 1684, 'Number of individual units within the smallest packaging', 'unit Total number of individual units contained within the smallest unit of packaging.'),
15949 (1, 't', 1685, 'Percentage of constituent element', 'The part of a product or material that is composed of the constituent element, as a percentage.'),
15950 (1, 't', 1686, 'Quantity to be decremented (LPCO)', 'Quantity to be decremented from the allowable quantity on a License, Permit, Certificate, or Other document (LPCO).'),
15951 (1, 't', 1687, 'Regulated commodity count', 'The number of regulated items.'),
15952 (1, 't', 1688, 'Number of passengers, embarking', 'The number of passengers going aboard a conveyance.'),
15953 (1, 't', 1689, 'Number of passengers, disembarking', 'The number of passengers disembarking the conveyance.'),
15954 (1, 't', 1690, 'Constituent element or component quantity', 'The specific quantity of the identified constituent element.')
15956 -- ZZZ, 'Mutually defined', 'As agreed by the trading partners.'),
15958 CREATE TABLE acq.serial_claim (
15959 id SERIAL PRIMARY KEY,
15960 type INT NOT NULL REFERENCES acq.claim_type
15961 DEFERRABLE INITIALLY DEFERRED,
15962 item BIGINT NOT NULL REFERENCES serial.item
15963 DEFERRABLE INITIALLY DEFERRED
15966 CREATE INDEX serial_claim_lid_idx ON acq.serial_claim( item );
15968 CREATE TABLE acq.serial_claim_event (
15969 id BIGSERIAL PRIMARY KEY,
15970 type INT NOT NULL REFERENCES acq.claim_event_type
15971 DEFERRABLE INITIALLY DEFERRED,
15972 claim SERIAL NOT NULL REFERENCES acq.serial_claim
15973 DEFERRABLE INITIALLY DEFERRED,
15974 event_date TIMESTAMPTZ NOT NULL DEFAULT now(),
15975 creator INT NOT NULL REFERENCES actor.usr
15976 DEFERRABLE INITIALLY DEFERRED,
15980 CREATE INDEX serial_claim_event_claim_date_idx ON acq.serial_claim_event( claim, event_date );
15982 ALTER TABLE asset.stat_cat ADD COLUMN required BOOL NOT NULL DEFAULT FALSE;
15984 -- now what about the auditor.*_lifecycle views??
15986 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) VALUES
15987 (26, 'identifier', 'tcn', oils_i18n_gettext(26, 'Title Control Number', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='901']/marc:subfield[@code='a']$$ );
15988 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) VALUES
15989 (27, 'identifier', 'bibid', oils_i18n_gettext(27, 'Internal ID', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='901']/marc:subfield[@code='c']$$ );
15990 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('eg.tcn','identifier', 26);
15991 INSERT INTO config.metabib_search_alias (alias,field_class,field) VALUES ('eg.bibid','identifier', 27);
15993 CREATE TABLE asset.call_number_class (
15994 id bigserial PRIMARY KEY,
15995 name TEXT NOT NULL,
15996 normalizer TEXT NOT NULL DEFAULT 'asset.normalize_generic',
15997 field TEXT NOT NULL DEFAULT '050ab,055ab,060ab,070ab,080ab,082ab,086ab,088ab,090,092,096,098,099'
16000 COMMENT ON TABLE asset.call_number_class IS $$
16001 Defines the call number normalization database functions in the "normalizer"
16002 column and the tag/subfield combinations to use to lookup the call number in
16003 the "field" column for a given classification scheme. Tag/subfield combinations
16004 are delimited by commas.
16007 INSERT INTO asset.call_number_class (name, normalizer) VALUES
16008 ('Generic', 'asset.label_normalizer_generic'),
16009 ('Dewey (DDC)', 'asset.label_normalizer_dewey'),
16010 ('Library of Congress (LC)', 'asset.label_normalizer_lc')
16014 UPDATE asset.call_number_class
16015 SET field = '050ab,055ab,060ab,070ab,080ab,082ab,086ab,088ab,090,092,096,098,099'
16020 UPDATE asset.call_number_class
16021 SET field = '080ab,082ab'
16026 UPDATE asset.call_number_class
16027 SET field = '050ab,055ab'
16031 ALTER TABLE auditor.asset_call_number_history ADD COLUMN label_class BIGINT;
16032 ALTER TABLE auditor.asset_call_number_history ADD COLUMN label_sortkey TEXT;
16033 ALTER TABLE asset.call_number ADD COLUMN label_class BIGINT DEFAULT 1 NOT NULL REFERENCES asset.call_number_class(id) DEFERRABLE INITIALLY DEFERRED;
16034 ALTER TABLE asset.call_number ADD COLUMN label_sortkey TEXT;
16035 CREATE INDEX asset_call_number_label_sortkey ON asset.call_number(label_sortkey);
16037 CREATE OR REPLACE FUNCTION asset.label_normalizer() RETURNS TRIGGER AS $func$
16039 sortkey TEXT := '';
16041 sortkey := NEW.label_sortkey;
16043 EXECUTE 'SELECT ' || acnc.normalizer || '(' ||
16044 quote_literal( NEW.label ) || ')'
16045 FROM asset.call_number_class acnc
16046 WHERE acnc.id = NEW.label_class
16049 NEW.label_sortkey = sortkey;
16053 $func$ LANGUAGE PLPGSQL;
16055 CREATE OR REPLACE FUNCTION asset.label_normalizer_generic(TEXT) RETURNS TEXT AS $func$
16056 # Created after looking at the Koha C4::ClassSortRoutine::Generic module,
16057 # thus could probably be considered a derived work, although nothing was
16058 # directly copied - but to err on the safe side of providing attribution:
16059 # Copyright (C) 2007 LibLime
16060 # Licensed under the GPL v2 or later
16065 # Converts the callnumber to uppercase
16066 # Strips spaces from start and end of the call number
16067 # Converts anything other than letters, digits, and periods into underscores
16068 # Collapses multiple underscores into a single underscore
16069 my $callnum = uc(shift);
16070 $callnum =~ s/^\s//g;
16071 $callnum =~ s/\s$//g;
16072 $callnum =~ s/[^A-Z0-9_.]/_/g;
16073 $callnum =~ s/_{2,}/_/g;
16076 $func$ LANGUAGE PLPERLU;
16078 CREATE OR REPLACE FUNCTION asset.label_normalizer_dewey(TEXT) RETURNS TEXT AS $func$
16079 # Derived from the Koha C4::ClassSortRoutine::Dewey module
16080 # Copyright (C) 2007 LibLime
16081 # Licensed under the GPL v2 or later
16086 my $init = uc(shift);
16090 $init =~ s/^([\p{IsAlpha}]+)/$1 /;
16091 my @tokens = split /\.|\s+/, $init;
16092 my $digit_group_count = 0;
16093 for (my $i = 0; $i <= $#tokens; $i++) {
16094 if ($tokens[$i] =~ /^\d+$/) {
16095 $digit_group_count++;
16096 if (2 == $digit_group_count) {
16097 $tokens[$i] = sprintf("%-15.15s", $tokens[$i]);
16098 $tokens[$i] =~ tr/ /0/;
16102 my $key = join("_", @tokens);
16103 $key =~ s/[^\p{IsAlnum}_]//g;
16107 $func$ LANGUAGE PLPERLU;
16109 CREATE OR REPLACE FUNCTION asset.label_normalizer_lc(TEXT) RETURNS TEXT AS $func$
16113 # Library::CallNumber::LC is currently hosted at http://code.google.com/p/library-callnumber-lc/
16114 # The author hopes to upload it to CPAN some day, which would make our lives easier
16115 use Library::CallNumber::LC;
16117 my $callnum = Library::CallNumber::LC->new(shift);
16118 return $callnum->normalize();
16120 $func$ LANGUAGE PLPERLU;
16122 CREATE OR REPLACE FUNCTION asset.opac_ou_record_copy_count (org INT, record BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16127 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = record;
16129 FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
16134 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
16138 actor.org_unit_descendants(ans.id) d
16139 JOIN asset.opac_visible_copies av ON (av.record = record AND av.circ_lib = d.id)
16140 JOIN asset.copy cp ON (cp.id = av.id)
16144 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
16151 $f$ LANGUAGE PLPGSQL;
16153 CREATE OR REPLACE FUNCTION asset.opac_lasso_record_copy_count (i_lasso INT, record BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16158 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = record;
16160 FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
16165 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
16169 actor.org_unit_descendants(ans.id) d
16170 JOIN asset.opac_visible_copies av ON (av.record = record AND av.circ_lib = d.id)
16171 JOIN asset.copy cp ON (cp.id = av.id)
16175 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
16182 $f$ LANGUAGE PLPGSQL;
16184 CREATE OR REPLACE FUNCTION asset.staff_ou_record_copy_count (org INT, record BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16189 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = record;
16191 FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
16196 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
16200 actor.org_unit_descendants(ans.id) d
16201 JOIN asset.copy cp ON (cp.circ_lib = d.id)
16202 JOIN asset.call_number cn ON (cn.record = record AND cn.id = cp.call_number)
16206 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
16213 $f$ LANGUAGE PLPGSQL;
16215 CREATE OR REPLACE FUNCTION asset.staff_lasso_record_copy_count (i_lasso INT, record BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16220 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = record;
16222 FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
16227 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
16231 actor.org_unit_descendants(ans.id) d
16232 JOIN asset.copy cp ON (cp.circ_lib = d.id)
16233 JOIN asset.call_number cn ON (cn.record = record AND cn.id = cp.call_number)
16237 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
16244 $f$ LANGUAGE PLPGSQL;
16246 CREATE OR REPLACE FUNCTION asset.record_copy_count ( place INT, record BIGINT, staff BOOL) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16248 IF staff IS TRUE THEN
16250 RETURN QUERY SELECT * FROM asset.staff_ou_record_copy_count( place, record );
16252 RETURN QUERY SELECT * FROM asset.staff_lasso_record_copy_count( -place, record );
16256 RETURN QUERY SELECT * FROM asset.opac_ou_record_copy_count( place, record );
16258 RETURN QUERY SELECT * FROM asset.opac_lasso_record_copy_count( -place, record );
16264 $f$ LANGUAGE PLPGSQL;
16266 CREATE OR REPLACE FUNCTION asset.opac_ou_metarecord_copy_count (org INT, record BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16271 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = record;
16273 FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
16278 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
16282 actor.org_unit_descendants(ans.id) d
16283 JOIN asset.opac_visible_copies av ON (av.record = record AND av.circ_lib = d.id)
16284 JOIN asset.copy cp ON (cp.id = av.id)
16285 JOIN metabib.metarecord_source_map m ON (m.source = av.record)
16289 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
16296 $f$ LANGUAGE PLPGSQL;
16298 CREATE OR REPLACE FUNCTION asset.opac_lasso_metarecord_copy_count (i_lasso INT, record BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16303 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = record;
16305 FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
16310 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
16314 actor.org_unit_descendants(ans.id) d
16315 JOIN asset.opac_visible_copies av ON (av.record = record AND av.circ_lib = d.id)
16316 JOIN asset.copy cp ON (cp.id = av.id)
16317 JOIN metabib.metarecord_source_map m ON (m.source = av.record)
16321 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
16328 $f$ LANGUAGE PLPGSQL;
16330 CREATE OR REPLACE FUNCTION asset.staff_ou_metarecord_copy_count (org INT, record BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16335 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = record;
16337 FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
16342 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
16346 actor.org_unit_descendants(ans.id) d
16347 JOIN asset.copy cp ON (cp.circ_lib = d.id)
16348 JOIN asset.call_number cn ON (cn.record = record AND cn.id = cp.call_number)
16349 JOIN metabib.metarecord_source_map m ON (m.source = cn.record)
16353 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
16360 $f$ LANGUAGE PLPGSQL;
16362 CREATE OR REPLACE FUNCTION asset.staff_lasso_metarecord_copy_count (i_lasso INT, record BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16367 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = record;
16369 FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
16374 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
16378 actor.org_unit_descendants(ans.id) d
16379 JOIN asset.copy cp ON (cp.circ_lib = d.id)
16380 JOIN asset.call_number cn ON (cn.record = record AND cn.id = cp.call_number)
16381 JOIN metabib.metarecord_source_map m ON (m.source = cn.record)
16385 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
16392 $f$ LANGUAGE PLPGSQL;
16394 CREATE OR REPLACE FUNCTION asset.metarecord_copy_count ( place INT, record BIGINT, staff BOOL) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
16396 IF staff IS TRUE THEN
16398 RETURN QUERY SELECT * FROM asset.staff_ou_metarecord_copy_count( place, record );
16400 RETURN QUERY SELECT * FROM asset.staff_lasso_metarecord_copy_count( -place, record );
16404 RETURN QUERY SELECT * FROM asset.opac_ou_metarecord_copy_count( place, record );
16406 RETURN QUERY SELECT * FROM asset.opac_lasso_metarecord_copy_count( -place, record );
16412 $f$ LANGUAGE PLPGSQL;
16414 -- No transaction is required
16416 -- Triggers on the vandelay.queued_*_record tables delete entries from
16417 -- the associated vandelay.queued_*_record_attr tables based on the record's
16418 -- ID; create an index on that column to avoid sequential scans for each
16419 -- queued record that is deleted
16420 CREATE INDEX queued_bib_record_attr_record_idx ON vandelay.queued_bib_record_attr (record);
16421 CREATE INDEX queued_authority_record_attr_record_idx ON vandelay.queued_authority_record_attr (record);
16423 -- Avoid sequential scans for queue retrieval operations by providing an
16424 -- index on the queue column
16425 CREATE INDEX queued_bib_record_queue_idx ON vandelay.queued_bib_record (queue);
16426 CREATE INDEX queued_authority_record_queue_idx ON vandelay.queued_authority_record (queue);
16428 CREATE INDEX actor_card_barcode_lower_idx ON actor.card (lower(barcode));
16430 -- Start picking up call number label prefixes and suffixes
16431 -- from asset.copy_location
16432 ALTER TABLE asset.copy_location ADD COLUMN label_prefix TEXT;
16433 ALTER TABLE asset.copy_location ADD COLUMN label_suffix TEXT;
16435 ALTER TABLE reporter.report RENAME COLUMN recurance TO recurrence;
16437 -- Let's not break existing reports
16438 UPDATE reporter.template SET data = REGEXP_REPLACE(data, E'^(.*)recuring(.*)$', E'\\1recurring\\2') WHERE data LIKE '%recuring%';
16439 UPDATE reporter.template SET data = REGEXP_REPLACE(data, E'^(.*)recurance(.*)$', E'\\1recurrence\\2') WHERE data LIKE '%recurance%';
16441 -- Need to recreate this view with DISTINCT calls to ARRAY_ACCUM, thus avoiding duplicated ISBN and ISSN values
16442 CREATE OR REPLACE VIEW reporter.old_super_simple_record AS
16448 FIRST(title.value) AS title,
16449 FIRST(author.value) AS author,
16450 ARRAY_TO_STRING(ARRAY_ACCUM( DISTINCT publisher.value), ', ') AS publisher,
16451 ARRAY_TO_STRING(ARRAY_ACCUM( DISTINCT SUBSTRING(pubdate.value FROM $$\d+$$) ), ', ') AS pubdate,
16452 ARRAY_ACCUM( DISTINCT SUBSTRING(isbn.value FROM $$^\S+$$) ) AS isbn,
16453 ARRAY_ACCUM( DISTINCT SUBSTRING(issn.value FROM $$^\S+$$) ) AS issn
16454 FROM biblio.record_entry r
16455 LEFT JOIN metabib.full_rec title ON (r.id = title.record AND title.tag = '245' AND title.subfield = 'a')
16456 LEFT JOIN metabib.full_rec author ON (r.id = author.record AND author.tag IN ('100','110','111') AND author.subfield = 'a')
16457 LEFT JOIN metabib.full_rec publisher ON (r.id = publisher.record AND publisher.tag = '260' AND publisher.subfield = 'b')
16458 LEFT JOIN metabib.full_rec pubdate ON (r.id = pubdate.record AND pubdate.tag = '260' AND pubdate.subfield = 'c')
16459 LEFT JOIN metabib.full_rec isbn ON (r.id = isbn.record AND isbn.tag IN ('024', '020') AND isbn.subfield IN ('a','z'))
16460 LEFT JOIN metabib.full_rec issn ON (r.id = issn.record AND issn.tag = '022' AND issn.subfield = 'a')
16461 GROUP BY 1,2,3,4,5;
16463 -- Correct the ISSN array definition for reporter.simple_record
16465 CREATE OR REPLACE VIEW reporter.simple_record AS
16472 title.value AS title,
16473 uniform_title.value AS uniform_title,
16474 author.value AS author,
16475 publisher.value AS publisher,
16476 SUBSTRING(pubdate.value FROM $$\d+$$) AS pubdate,
16477 series_title.value AS series_title,
16478 series_statement.value AS series_statement,
16479 summary.value AS summary,
16480 ARRAY_ACCUM( SUBSTRING(isbn.value FROM $$^\S+$$) ) AS isbn,
16481 ARRAY_ACCUM( REGEXP_REPLACE(issn.value, E'^\\S*(\\d{4})[-\\s](\\d{3,4}x?)', E'\\1 \\2') ) AS issn,
16482 ARRAY((SELECT DISTINCT value FROM metabib.full_rec WHERE tag = '650' AND subfield = 'a' AND record = r.id)) AS topic_subject,
16483 ARRAY((SELECT DISTINCT value FROM metabib.full_rec WHERE tag = '651' AND subfield = 'a' AND record = r.id)) AS geographic_subject,
16484 ARRAY((SELECT DISTINCT value FROM metabib.full_rec WHERE tag = '655' AND subfield = 'a' AND record = r.id)) AS genre,
16485 ARRAY((SELECT DISTINCT value FROM metabib.full_rec WHERE tag = '600' AND subfield = 'a' AND record = r.id)) AS name_subject,
16486 ARRAY((SELECT DISTINCT value FROM metabib.full_rec WHERE tag = '610' AND subfield = 'a' AND record = r.id)) AS corporate_subject,
16487 ARRAY((SELECT value FROM metabib.full_rec WHERE tag = '856' AND subfield IN ('3','y','u') AND record = r.id ORDER BY CASE WHEN subfield IN ('3','y') THEN 0 ELSE 1 END)) AS external_uri
16488 FROM biblio.record_entry r
16489 JOIN metabib.metarecord_source_map s ON (s.source = r.id)
16490 LEFT JOIN metabib.full_rec uniform_title ON (r.id = uniform_title.record AND uniform_title.tag = '240' AND uniform_title.subfield = 'a')
16491 LEFT JOIN metabib.full_rec title ON (r.id = title.record AND title.tag = '245' AND title.subfield = 'a')
16492 LEFT JOIN metabib.full_rec author ON (r.id = author.record AND author.tag = '100' AND author.subfield = 'a')
16493 LEFT JOIN metabib.full_rec publisher ON (r.id = publisher.record AND publisher.tag = '260' AND publisher.subfield = 'b')
16494 LEFT JOIN metabib.full_rec pubdate ON (r.id = pubdate.record AND pubdate.tag = '260' AND pubdate.subfield = 'c')
16495 LEFT JOIN metabib.full_rec isbn ON (r.id = isbn.record AND isbn.tag IN ('024', '020') AND isbn.subfield IN ('a','z'))
16496 LEFT JOIN metabib.full_rec issn ON (r.id = issn.record AND issn.tag = '022' AND issn.subfield = 'a')
16497 LEFT JOIN metabib.full_rec series_title ON (r.id = series_title.record AND series_title.tag IN ('830','440') AND series_title.subfield = 'a')
16498 LEFT JOIN metabib.full_rec series_statement ON (r.id = series_statement.record AND series_statement.tag = '490' AND series_statement.subfield = 'a')
16499 LEFT JOIN metabib.full_rec summary ON (r.id = summary.record AND summary.tag = '520' AND summary.subfield = 'a')
16500 GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14;
16502 CREATE OR REPLACE FUNCTION reporter.disable_materialized_simple_record_trigger () RETURNS VOID AS $$
16503 DROP TRIGGER IF EXISTS zzz_update_materialized_simple_record_tgr ON metabib.real_full_rec;
16506 CREATE OR REPLACE FUNCTION reporter.simple_rec_trigger () RETURNS TRIGGER AS $func$
16508 IF TG_OP = 'DELETE' THEN
16509 PERFORM reporter.simple_rec_delete(NEW.id);
16511 PERFORM reporter.simple_rec_update(NEW.id);
16516 $func$ LANGUAGE PLPGSQL;
16518 CREATE TRIGGER bbb_simple_rec_trigger AFTER INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE reporter.simple_rec_trigger ();
16520 ALTER TABLE extend_reporter.legacy_circ_count DROP CONSTRAINT legacy_circ_count_id_fkey;
16524 -- Outside of the commit: some alters that may legitimately fail
16525 -- if the table doesn't exist.
16527 ALTER TABLE auditor.action_hold_request_history ADD COLUMN cut_in_line BOOL;
16529 ALTER TABLE auditor.action_hold_request_history
16530 ADD COLUMN mint_condition boolean NOT NULL DEFAULT TRUE;
16532 ALTER TABLE auditor.action_hold_request_history
16533 ADD COLUMN shelf_expire_time TIMESTAMPTZ;