ORDER BY id LIMIT 1;
$$ LANGUAGE SQL;
+/** Returns the next (by ID) non-deleted biblio.record_entry */
+CREATE FUNCTION evergreen.next_bib (bib_id BIGINT) RETURNS biblio.record_entry AS $$
+ SELECT * FROM biblio.record_entry
+ WHERE id > $1 AND NOT deleted
+ ORDER BY id LIMIT 1;
+$$ LANGUAGE SQL;
+
/** Create one circulation */
CREATE FUNCTION evergreen.populate_circ (
- patron_barcode TEXT,
- copy_barcode TEXT,
+ patron_id INTEGER,
+ copy_id BIGINT,
circ_lib INTEGER,
duration_rule TEXT,
recurring_fine_rule TEXT,
recurring_fine_rule, max_fine_rule, due_date )
VALUES (
xact_start,
- (SELECT usr FROM actor.card WHERE barcode = patron_barcode),
- (SELECT id FROM asset.copy WHERE barcode = copy_barcode AND NOT deleted),
+ patron_id,
+ copy_id,
circ_lib,
1, -- circ_staff
duration.max_renewals,
CREATE FUNCTION evergreen.populate_hold (
hold_type TEXT,
target BIGINT,
- patron_barcode TEXT,
- pickup_lib INTEGER
- -- ...
-)
-RETURNS void AS $$
+ patron_id INTEGER,
+ pickup_lib INTEGER,
+ frozen BOOLEAN,
+ thawdate TIMESTAMP WITH TIME ZONE
+) RETURNS void AS $$
BEGIN
INSERT INTO action.hold_request (
- requestor, hold_type, target, usr, pickup_lib, request_lib, selection_ou)
+ requestor, hold_type, target, usr, pickup_lib,
+ request_lib, selection_ou, frozen, thaw_date)
VALUES (
1, -- requestor
hold_type,
target,
- (SELECT usr FROM actor.card WHERE barcode = patron_barcode),
+ patron_id,
+ pickup_lib,
pickup_lib,
pickup_lib,
- pickup_lib
+ frozen,
+ thawdate
);
END;
$$ LANGUAGE PLPGSQL;
-
-/* NOTE: fine generator should be run after loading to produce billings */
+/**
+ * For the first (by ID) 20 users in each Patron group and the first 3 in
+ * each Staff group:
+ *
+ * 1. create 3 regular circs w/ varying (stock) rules and 3 overdue
+ * circs.
+ *
+ * 2. create 2 regular title holds and one frozen title hold. If the user
+ * is in a Staff group, also create one copy-level hold.
+ *
+ */
/**
- * create 3 regular circs w/ varying (stock) rules and 3 overdue
- * circs for the fisrt 2 (by ID) users in each profile group.
- * target copies start at ID 1 and progress upward by ID from
- * there, skipping deleted copies.
- * TODO: vary the rules more
+ * NOTE: The fine generator and hold targeter should be run after this is
+ * loaded to creating overdue billings and target copies for holds.
*/
+
DO $$
DECLARE grp INTEGER;
DECLARE recipient INTEGER;
DECLARE copy asset.copy%ROWTYPE;
+ DECLARE bre biblio.record_entry%ROWTYPE;
+ DECLARE user_count INTEGER;
BEGIN
+
copy := evergreen.next_copy(0);
+ bre := evergreen.next_bib(0);
+
+ FOR grp IN SELECT id FROM permission.grp_tree ORDER BY id LOOP
+
+ IF 2 IN (SELECT id FROM permission.grp_ancestors(grp)) THEN
+ -- patron group
+ user_count := 20;
+ ELSE
+ user_count := 3;
+ END IF;
- FOR grp IN SELECT id FROM permission.grp_tree LOOP
FOR recipient IN SELECT id FROM actor.usr
- WHERE profile = grp ORDER BY id LIMIT 2 LOOP
+ WHERE NOT deleted AND profile = grp
+ ORDER BY id LIMIT user_count LOOP
+
+ -- regular circs --------------------------------
copy := evergreen.next_copy(copy.id);
PERFORM evergreen.populate_circ(
- (SELECT barcode FROM actor.card WHERE usr = recipient),
- copy.barcode, copy.circ_lib,
+ recipient,
+ copy.id, copy.circ_lib,
'default', 'default', 'default', FALSE
);
copy := evergreen.next_copy(copy.id);
PERFORM evergreen.populate_circ(
- (SELECT barcode FROM actor.card WHERE usr = recipient),
- copy.barcode, copy.circ_lib,
+ recipient,
+ copy.id, copy.circ_lib,
'1_hour_2_renew', 'default', 'overdue_min', FALSE
);
copy := evergreen.next_copy(copy.id);
PERFORM evergreen.populate_circ(
- (SELECT barcode FROM actor.card WHERE usr = recipient),
- copy.barcode, copy.circ_lib,
+ recipient,
+ copy.id, copy.circ_lib,
'7_days_0_renew', 'default', 'overdue_max', FALSE
);
- -- overdues...
+ -- overdue circs ----------------------------------
copy := evergreen.next_copy(copy.id);
PERFORM evergreen.populate_circ(
- (SELECT barcode FROM actor.card WHERE usr = recipient),
- copy.barcode, copy.circ_lib,
+ recipient,
+ copy.id, copy.circ_lib,
'default', 'default', 'default', TRUE
);
copy := evergreen.next_copy(copy.id);
PERFORM evergreen.populate_circ(
- (SELECT barcode FROM actor.card WHERE usr = recipient),
- copy.barcode, copy.circ_lib,
+ recipient,
+ copy.id, copy.circ_lib,
'1_hour_2_renew', 'default', 'overdue_min', TRUE
);
copy := evergreen.next_copy(copy.id);
PERFORM evergreen.populate_circ(
- (SELECT barcode FROM actor.card WHERE usr = recipient),
- copy.barcode, copy.circ_lib,
+ recipient,
+ copy.id, copy.circ_lib,
'7_days_0_renew', 'default', 'overdue_max', TRUE
);
+ -- holds ------------------------------------------
+
+ -- title hold
+ bre := evergreen.next_bib(bre.id);
+ PERFORM evergreen.populate_hold(
+ 'T', bre.id, recipient,
+ (SELECT home_ou FROM actor.usr WHERE id = recipient),
+ FALSE, NULL
+ );
+
+ -- title hold
+ bre := evergreen.next_bib(bre.id);
+ PERFORM evergreen.populate_hold(
+ 'T', bre.id, recipient,
+ (SELECT home_ou FROM actor.usr WHERE id = recipient),
+ FALSE, NULL
+ );
+
+ -- frozen title hold
+ bre := evergreen.next_bib(bre.id);
+ PERFORM evergreen.populate_hold(
+ 'T', bre.id, recipient,
+ (SELECT home_ou FROM actor.usr WHERE id = recipient),
+ TRUE, NOW() + '3 months'::INTERVAL
+ );
+
+ -- is this a Staff account?
+ IF 3 IN (SELECT id FROM permission.grp_ancestors(grp)) THEN
+ copy := evergreen.next_copy(copy.id);
+ PERFORM evergreen.populate_hold(
+ 'C', copy.id, recipient,
+ (SELECT home_ou FROM actor.usr WHERE id = recipient),
+ FALSE, NULL
+ );
+ END IF;
+
END LOOP;
END LOOP;
END $$;