usrname TEXT NOT NULL UNIQUE,
email TEXT,
passwd TEXT NOT NULL,
- standing INT NOT NULL DEFAULT 1 REFERENCES config.standing (id),
- ident_type INT NOT NULL REFERENCES config.identification_type (id),
+ standing INT NOT NULL DEFAULT 1 REFERENCES config.standing (id) DEFERRABLE INITIALLY DEFERRED,
+ ident_type INT NOT NULL REFERENCES config.identification_type (id) DEFERRABLE INITIALLY DEFERRED,
ident_value TEXT,
- ident_type2 INT REFERENCES config.identification_type (id),
+ ident_type2 INT REFERENCES config.identification_type (id) DEFERRABLE INITIALLY DEFERRED,
ident_value2 TEXT,
- net_access_level INT NOT NULL DEFAULT 1 REFERENCES config.net_access_level (id),
+ net_access_level INT NOT NULL DEFAULT 1 REFERENCES config.net_access_level (id) DEFERRABLE INITIALLY DEFERRED,
photo_url TEXT,
prefix TEXT,
first_given_name TEXT NOT NULL,
CREATE TABLE actor.usr_note (
id BIGSERIAL PRIMARY KEY,
- usr BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE,
- creator BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE,
+ usr BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ creator BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
pub BOOL NOT NULL DEFAULT FALSE,
title TEXT NOT NULL,
CREATE TABLE actor.usr_standing_penalty (
id SERIAL PRIMARY KEY,
- usr INT NOT NULL REFERENCES actor.usr ON DELETE CASCADE,
+ usr INT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
penalty_type TEXT NOT NULL
);
COMMENT ON TABLE actor.usr_standing_penalty IS $$
CREATE TABLE actor.usr_setting (
id BIGSERIAL PRIMARY KEY,
- usr INT NOT NULL REFERENCES actor.usr ON DELETE CASCADE,
+ usr INT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
name TEXT NOT NULL,
value TEXT NOT NULL,
CONSTRAINT usr_once_per_key UNIQUE (usr,name)
CREATE TABLE actor.card (
id SERIAL PRIMARY KEY,
- usr INT NOT NULL REFERENCES actor.usr (id),
+ usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
barcode TEXT NOT NULL UNIQUE,
active BOOL NOT NULL DEFAULT TRUE
);
name TEXT NOT NULL,
opac_label TEXT NOT NULL,
depth INT NOT NULL,
- parent INT REFERENCES actor.org_unit_type (id),
+ parent INT REFERENCES actor.org_unit_type (id) DEFERRABLE INITIALLY DEFERRED,
can_have_vols BOOL NOT NULL DEFAULT TRUE,
can_have_users BOOL NOT NULL DEFAULT TRUE
);
CREATE TABLE actor.org_unit (
id SERIAL PRIMARY KEY,
- parent_ou INT REFERENCES actor.org_unit (id),
- ou_type INT NOT NULL REFERENCES actor.org_unit_type (id),
+ parent_ou INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+ ou_type INT NOT NULL REFERENCES actor.org_unit_type (id) DEFERRABLE INITIALLY DEFERRED,
ill_address INT,
holds_address INT,
mailing_address INT,
CREATE TABLE actor.org_lasso_map (
id SERIAL PRIMARY KEY,
- lasso INT NOT NULL REFERENCES actor.org_lasso (id) ON DELETE CASCADE,
- org_unit INT NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE
+ lasso INT NOT NULL REFERENCES actor.org_lasso (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ org_unit INT NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
);
CREATE UNIQUE INDEX ou_lasso_lasso_ou_idx ON actor.org_lasso_map (lasso, org_unit);
CREATE INDEX ou_lasso_org_unit_idx ON actor.org_lasso_map (org_unit);
CREATE INDEX from_prox_idx ON actor.org_unit_proximity (from_org);
CREATE TABLE actor.hours_of_operation (
- id INT PRIMARY KEY REFERENCES actor.org_unit (id) ON DELETE CASCADE,
+ id INT PRIMARY KEY REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
dow_0_open TIME NOT NULL DEFAULT '09:00',
dow_0_close TIME NOT NULL DEFAULT '17:00',
dow_1_open TIME NOT NULL DEFAULT '09:00',
CREATE TABLE actor.org_unit_closed (
id SERIAL PRIMARY KEY,
- org_unit INT NOT NULL REFERENCES actor.org_unit (id),
+ org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
close_start TIMESTAMP WITH TIME ZONE NOT NULL,
close_end TIMESTAMP WITH TIME ZONE NOT NULL,
reason TEXT
CREATE TABLE actor.workstation (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
- owning_lib INT NOT NULL REFERENCES actor.org_unit (id)
+ owning_lib INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED
);
CREATE TABLE actor.usr_org_unit_opt_in (
id SERIAL PRIMARY KEY,
- org_unit INT NOT NULL REFERENCES actor.org_unit (id),
- usr INT NOT NULL REFERENCES actor.usr (id),
- staff INT NOT NULL REFERENCES actor.usr (id),
+ org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+ usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+ staff INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
opt_in_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
- opt_in_ws INT NOT NULL REFERENCES actor.workstation (id),
+ opt_in_ws INT NOT NULL REFERENCES actor.workstation (id) DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT usr_opt_in_once_per_org_unit UNIQUE (usr,org_unit)
);
CREATE TABLE actor.org_unit_setting (
id BIGSERIAL PRIMARY KEY,
- org_unit INT NOT NULL REFERENCES actor.org_unit ON DELETE CASCADE,
+ org_unit INT NOT NULL REFERENCES actor.org_unit ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
name TEXT NOT NULL,
value TEXT NOT NULL,
CONSTRAINT ou_once_per_key UNIQUE (org_unit,name)
valid BOOL NOT NULL DEFAULT TRUE,
within_city_limits BOOL NOT NULL DEFAULT TRUE,
address_type TEXT NOT NULL DEFAULT 'MAILING',
- usr INT NOT NULL REFERENCES actor.usr (id),
+ usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
street1 TEXT NOT NULL,
street2 TEXT,
city TEXT NOT NULL,
id SERIAL PRIMARY KEY,
valid BOOL NOT NULL DEFAULT TRUE,
address_type TEXT NOT NULL DEFAULT 'MAILING',
- org_unit INT NOT NULL REFERENCES actor.org_unit (id),
+ org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
street1 TEXT NOT NULL,
street2 TEXT,
city TEXT NOT NULL,
CREATE TABLE permission.grp_tree (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
- parent INT REFERENCES permission.grp_tree (id) ON DELETE RESTRICT,
+ parent INT REFERENCES permission.grp_tree (id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED,
usergroup BOOL NOT NULL DEFAULT TRUE,
perm_interval INTERVAL DEFAULT '3 years'::interval NOT NULL,
description TEXT,
CREATE TABLE permission.grp_perm_map (
id SERIAL PRIMARY KEY,
- grp INT NOT NULL REFERENCES permission.grp_tree (id) ON DELETE CASCADE,
- perm INT NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE,
+ grp INT NOT NULL REFERENCES permission.grp_tree (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ perm INT NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
depth INT NOT NULL,
grantable BOOL NOT NULL DEFAULT FALSE,
CONSTRAINT perm_grp_once UNIQUE (grp,perm)
CREATE TABLE permission.usr_perm_map (
id SERIAL PRIMARY KEY,
- usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE,
- perm INT NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE,
+ usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ perm INT NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
depth INT NOT NULL,
grantable BOOL NOT NULL DEFAULT FALSE,
CONSTRAINT perm_usr_once UNIQUE (usr,perm)
CREATE TABLE permission.usr_object_perm_map (
id SERIAL PRIMARY KEY,
- usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE,
- perm INT NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE,
+ usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ perm INT NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
object_type TEXT NOT NULL,
object_id TEXT NOT NULL,
grantable BOOL NOT NULL DEFAULT FALSE,
CREATE TABLE permission.usr_grp_map (
id SERIAL PRIMARY KEY,
- usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE,
- grp INT NOT NULL REFERENCES permission.grp_tree (id) ON DELETE CASCADE,
+ usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ grp INT NOT NULL REFERENCES permission.grp_tree (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT usr_grp_once UNIQUE (usr,grp)
);
CREATE TABLE permission.usr_work_ou_map (
id SERIAL PRIMARY KEY,
- usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE,
- work_ou INT NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE,
+ usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ work_ou INT NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT usr_work_ou_once UNIQUE (usr,work_ou)
);
CREATE TABLE authority.record_note (
id BIGSERIAL PRIMARY KEY,
- record BIGINT NOT NULL REFERENCES authority.record_entry (id),
+ record BIGINT NOT NULL REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED,
value TEXT NOT NULL,
creator INT NOT NULL DEFAULT 1,
editor INT NOT NULL DEFAULT 1,
CREATE TABLE vandelay.queue (
id BIGSERIAL PRIMARY KEY,
- owner INT NOT NULL REFERENCES actor.usr (id),
+ owner INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
name TEXT NOT NULL,
complete BOOL NOT NULL DEFAULT FALSE,
queue_type TEXT NOT NULL DEFAULT 'bib' CHECK (queue_type IN ('bib','authority')),
ALTER TABLE vandelay.bib_queue ADD PRIMARY KEY (id);
CREATE TABLE vandelay.queued_bib_record (
- queue INT NOT NULL REFERENCES vandelay.bib_queue (id) ON DELETE CASCADE,
- bib_source INT REFERENCES config.bib_source (id),
- imported_as INT REFERENCES biblio.record_entry (id)
+ queue INT NOT NULL REFERENCES vandelay.bib_queue (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ bib_source INT REFERENCES config.bib_source (id) DEFERRABLE INITIALLY DEFERRED,
+ imported_as INT REFERENCES biblio.record_entry (id) DEFERRABLE INITIALLY DEFERRED
) INHERITS (vandelay.queued_record);
ALTER TABLE vandelay.queued_bib_record ADD PRIMARY KEY (id);
CREATE TABLE vandelay.queued_bib_record_attr (
id BIGSERIAL PRIMARY KEY,
- record BIGINT NOT NULL REFERENCES vandelay.queued_bib_record (id),
- field INT NOT NULL REFERENCES vandelay.bib_attr_definition (id),
+ record BIGINT NOT NULL REFERENCES vandelay.queued_bib_record (id) DEFERRABLE INITIALLY DEFERRED,
+ field INT NOT NULL REFERENCES vandelay.bib_attr_definition (id) DEFERRABLE INITIALLY DEFERRED,
attr_value TEXT NOT NULL
);
CREATE TABLE vandelay.bib_match (
id BIGSERIAL PRIMARY KEY,
field_type TEXT NOT NULL CHECK (field_type in ('isbn','tcn_value','id')),
- matched_attr INT REFERENCES vandelay.queued_bib_record_attr (id) ON DELETE CASCADE,
- queued_record BIGINT REFERENCES vandelay.queued_bib_record (id) ON DELETE CASCADE,
- eg_record BIGINT REFERENCES biblio.record_entry (id)
+ matched_attr INT REFERENCES vandelay.queued_bib_record_attr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ queued_record BIGINT REFERENCES vandelay.queued_bib_record (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ eg_record BIGINT REFERENCES biblio.record_entry (id) DEFERRABLE INITIALLY DEFERRED
);
CREATE OR REPLACE FUNCTION vandelay.ingest_bib_marc ( ) RETURNS TRIGGER AS $$
ALTER TABLE vandelay.authority_queue ADD PRIMARY KEY (id);
CREATE TABLE vandelay.queued_authority_record (
- queue INT NOT NULL REFERENCES vandelay.authority_queue (id) ON DELETE CASCADE,
- imported_as INT REFERENCES authority.record_entry (id)
+ queue INT NOT NULL REFERENCES vandelay.authority_queue (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ imported_as INT REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED
) INHERITS (vandelay.queued_record);
ALTER TABLE vandelay.queued_authority_record ADD PRIMARY KEY (id);
CREATE TABLE vandelay.queued_authority_record_attr (
id BIGSERIAL PRIMARY KEY,
- record BIGINT NOT NULL REFERENCES vandelay.queued_authority_record (id),
- field INT NOT NULL REFERENCES vandelay.authority_attr_definition (id),
+ record BIGINT NOT NULL REFERENCES vandelay.queued_authority_record (id) DEFERRABLE INITIALLY DEFERRED,
+ field INT NOT NULL REFERENCES vandelay.authority_attr_definition (id) DEFERRABLE INITIALLY DEFERRED,
attr_value TEXT NOT NULL
);
CREATE TABLE vandelay.authority_match (
id BIGSERIAL PRIMARY KEY,
- matched_attr INT REFERENCES vandelay.queued_authority_record_attr (id) ON DELETE CASCADE,
- queued_record BIGINT REFERENCES vandelay.queued_authority_record (id) ON DELETE CASCADE,
- eg_record BIGINT REFERENCES authority.record_entry (id)
+ matched_attr INT REFERENCES vandelay.queued_authority_record_attr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ queued_record BIGINT REFERENCES vandelay.queued_authority_record (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ eg_record BIGINT REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED
);
CREATE OR REPLACE FUNCTION vandelay.ingest_authority_marc ( ) RETURNS TRIGGER AS $$
CREATE TABLE money.collections_tracker (
id BIGSERIAL PRIMARY KEY,
- usr INT NOT NULL REFERENCES actor.usr (id), -- actor.usr.id
- collector INT NOT NULL REFERENCES actor.usr (id),
- location INT NOT NULL REFERENCES actor.org_unit (id),
+ usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, -- actor.usr.id
+ collector INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+ location INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
enter_time TIMESTAMP WITH TIME ZONE
);
CREATE UNIQUE INDEX m_c_t_usr_collector_location_once_idx ON money.collections_tracker (usr, collector, location);
CREATE INDEX money_goods_payment_accepting_usr_idx ON money.goods_payment (accepting_usr);
CREATE TABLE money.bnm_desk_payment (
- cash_drawer INT REFERENCES actor.workstation (id)
+ cash_drawer INT REFERENCES actor.workstation (id) DEFERRABLE INITIALLY DEFERRED
) INHERITS (money.bnm_payment);
ALTER TABLE money.bnm_desk_payment ADD PRIMARY KEY (id);
CREATE TABLE action.in_house_use (
id SERIAL PRIMARY KEY,
- item BIGINT NOT NULL REFERENCES asset.copy (id),
- staff INT NOT NULL REFERENCES actor.usr (id),
- org_unit INT NOT NULL REFERENCES actor.org_unit (id),
+ item BIGINT NOT NULL REFERENCES asset.copy (id) DEFERRABLE INITIALLY DEFERRED,
+ staff INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+ org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
use_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
CREATE TABLE action.non_cataloged_circulation (
id SERIAL PRIMARY KEY,
- patron INT NOT NULL REFERENCES actor.usr (id),
- staff INT NOT NULL REFERENCES actor.usr (id),
- circ_lib INT NOT NULL REFERENCES actor.org_unit (id),
- item_type INT NOT NULL REFERENCES config.non_cataloged_type (id),
+ patron INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+ staff INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+ circ_lib INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+ item_type INT NOT NULL REFERENCES config.non_cataloged_type (id) DEFERRABLE INITIALLY DEFERRED,
circ_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
CREATE TABLE action.non_cat_in_house_use (
id SERIAL PRIMARY KEY,
- item_type BIGINT NOT NULL REFERENCES config.non_cataloged_type(id),
- staff INT NOT NULL REFERENCES actor.usr (id),
- org_unit INT NOT NULL REFERENCES actor.org_unit (id),
+ item_type BIGINT NOT NULL REFERENCES config.non_cataloged_type(id) DEFERRABLE INITIALLY DEFERRED,
+ staff INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+ org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
use_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
CREATE TABLE action.survey (
id SERIAL PRIMARY KEY,
- owner INT NOT NULL REFERENCES actor.org_unit (id),
+ owner INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
start_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
end_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() + '10 years'::INTERVAL,
usr_summary BOOL NOT NULL DEFAULT FALSE,
CREATE TABLE action.survey_question (
id SERIAL PRIMARY KEY,
- survey INT NOT NULL REFERENCES action.survey,
+ survey INT NOT NULL REFERENCES action.survey DEFERRABLE INITIALLY DEFERRED,
question TEXT NOT NULL
);
CREATE TABLE action.survey_answer (
id SERIAL PRIMARY KEY,
- question INT NOT NULL REFERENCES action.survey_question,
+ question INT NOT NULL REFERENCES action.survey_question DEFERRABLE INITIALLY DEFERRED,
answer TEXT NOT NULL
);
id BIGSERIAL PRIMARY KEY,
response_group_id INT,
usr INT, -- REFERENCES actor.usr
- survey INT NOT NULL REFERENCES action.survey,
- question INT NOT NULL REFERENCES action.survey_question,
- answer INT NOT NULL REFERENCES action.survey_answer,
+ survey INT NOT NULL REFERENCES action.survey DEFERRABLE INITIALLY DEFERRED,
+ question INT NOT NULL REFERENCES action.survey_question DEFERRABLE INITIALLY DEFERRED,
+ answer INT NOT NULL REFERENCES action.survey_answer DEFERRABLE INITIALLY DEFERRED,
answer_date TIMESTAMP WITH TIME ZONE,
effective_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
expire_time TIMESTAMP WITH TIME ZONE,
cancel_time TIMESTAMP WITH TIME ZONE,
target BIGINT NOT NULL, -- see hold_type
- current_copy BIGINT REFERENCES asset.copy (id) ON DELETE SET NULL,
- fulfillment_staff INT REFERENCES actor.usr (id),
- fulfillment_lib INT REFERENCES actor.org_unit (id),
- request_lib INT NOT NULL REFERENCES actor.org_unit (id),
- requestor INT NOT NULL REFERENCES actor.usr (id),
- usr INT NOT NULL REFERENCES actor.usr (id),
+ current_copy BIGINT REFERENCES asset.copy (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
+ fulfillment_staff INT REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+ fulfillment_lib INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+ request_lib INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+ requestor INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+ usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
selection_ou INT NOT NULL,
selection_depth INT NOT NULL DEFAULT 0,
- pickup_lib INT NOT NULL REFERENCES actor.org_unit,
+ pickup_lib INT NOT NULL REFERENCES actor.org_unit DEFERRABLE INITIALLY DEFERRED,
hold_type TEXT NOT NULL CHECK (hold_type IN ('M','T','V','C')),
holdable_formats TEXT,
phone_notify TEXT,
CREATE TABLE action.hold_notification (
id SERIAL PRIMARY KEY,
- hold INT NOT NULL REFERENCES action.hold_request (id),
- notify_staff INT REFERENCES actor.usr (id),
+ hold INT NOT NULL REFERENCES action.hold_request (id) DEFERRABLE INITIALLY DEFERRED,
+ notify_staff INT REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
notify_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
method TEXT NOT NULL, -- email address or phone number
note TEXT
CREATE TABLE action.hold_copy_map (
id SERIAL PRIMARY KEY,
- hold INT NOT NULL REFERENCES action.hold_request (id) ON DELETE CASCADE,
- target_copy BIGINT NOT NULL REFERENCES asset.copy (id) ON DELETE CASCADE,
+ hold INT NOT NULL REFERENCES action.hold_request (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ target_copy BIGINT NOT NULL REFERENCES asset.copy (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT copy_once_per_hold UNIQUE (hold,target_copy)
);
-- CREATE INDEX acm_hold_idx ON action.hold_copy_map (hold);
id SERIAL PRIMARY KEY,
source_send_time TIMESTAMP WITH TIME ZONE,
dest_recv_time TIMESTAMP WITH TIME ZONE,
- target_copy BIGINT NOT NULL REFERENCES asset.copy (id) ON DELETE CASCADE,
- source INT NOT NULL REFERENCES actor.org_unit (id),
- dest INT NOT NULL REFERENCES actor.org_unit (id),
- prev_hop INT REFERENCES action.transit_copy (id),
- copy_status INT NOT NULL REFERENCES config.copy_status (id),
+ target_copy BIGINT NOT NULL REFERENCES asset.copy (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+ source INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+ dest INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+ prev_hop INT REFERENCES action.transit_copy (id) DEFERRABLE INITIALLY DEFERRED,
+ copy_status INT NOT NULL REFERENCES config.copy_status (id) DEFERRABLE INITIALLY DEFERRED,
persistant_transfer BOOL NOT NULL DEFAULT FALSE
);
CREATE INDEX active_transit_dest_idx ON "action".transit_copy (dest);
hold INT REFERENCES action.hold_request (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED
) INHERITS (action.transit_copy);
ALTER TABLE action.hold_transit_copy ADD PRIMARY KEY (id);
-ALTER TABLE action.hold_transit_copy ADD CONSTRAINT ahtc_tc_fkey FOREIGN KEY (target_copy) REFERENCES asset.copy (id) ON DELETE CASCADE;
+ALTER TABLE action.hold_transit_copy ADD CONSTRAINT ahtc_tc_fkey FOREIGN KEY (target_copy) REFERENCES asset.copy (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX active_hold_transit_dest_idx ON "action".hold_transit_copy (dest);
CREATE INDEX active_hold_transit_source_idx ON "action".hold_transit_copy (source);
CREATE INDEX active_hold_transit_cp_idx ON "action".hold_transit_copy (target_copy);
CREATE TABLE search.relevance_adjustment (
id SERIAL PRIMARY KEY,
active BOOL NOT NULL DEFAULT TRUE,
- field INT NOT NULL REFERENCES config.metabib_field (id),
+ field INT NOT NULL REFERENCES config.metabib_field (id) DEFERRABLE INITIALLY DEFERRED,
bump_type TEXT NOT NULL CHECK (bump_type IN ('word_order','first_word','full_match')),
multiplier NUMERIC NOT NULL DEFAULT 1.0
);
CREATE TABLE config.circ_matrix_matchpoint (
id SERIAL PRIMARY KEY,
active BOOL NOT NULL DEFAULT TRUE,
- org_unit INT NOT NULL REFERENCES actor.org_unit (id), -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
- grp INT NOT NULL REFERENCES permission.grp_tree (id), -- Set to the top applicable group from the group tree; will need decendents and prox functions for filtering
- circ_modifier TEXT REFERENCES config.circ_modifier (code),
- marc_type TEXT REFERENCES config.item_type_map (code),
- marc_form TEXT REFERENCES config.item_form_map (code),
- marc_vr_format TEXT REFERENCES config.videorecording_format_map (code),
+ org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
+ grp INT NOT NULL REFERENCES permission.grp_tree (id) DEFERRABLE INITIALLY DEFERRED, -- Set to the top applicable group from the group tree; will need descendents and prox functions for filtering
+ circ_modifier TEXT REFERENCES config.circ_modifier (code) DEFERRABLE INITIALLY DEFERRED,
+ marc_type TEXT REFERENCES config.item_type_map (code) DEFERRABLE INITIALLY DEFERRED,
+ marc_form TEXT REFERENCES config.item_form_map (code) DEFERRABLE INITIALLY DEFERRED,
+ marc_vr_format TEXT REFERENCES config.videorecording_format_map (code) DEFERRABLE INITIALLY DEFERRED,
ref_flag BOOL,
usr_age_lower_bound INTERVAL,
usr_age_upper_bound INTERVAL,
-- Tests to determine if circ can occur for this item at this location for this patron
CREATE TABLE config.circ_matrix_test (
- matchpoint INT PRIMARY KEY NOT NULL REFERENCES config.circ_matrix_matchpoint (id) ON DELETE CASCADE,
+ matchpoint INT PRIMARY KEY NOT NULL REFERENCES config.circ_matrix_matchpoint (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
circulate BOOL NOT NULL DEFAULT TRUE, -- Hard "can't circ" flag requiring an override
max_items_out INT, -- Total current active circulations must be less than this, NULL means skip (always pass)
max_overdue INT, -- Total overdue active circulations must be less than this, NULL means skip (always pass)
-- Tests for max items out by circ_modifier
CREATE TABLE config.circ_matrix_circ_mod_test (
id SERIAL PRIMARY KEY,
- matchpoint INT NOT NULL REFERENCES config.circ_matrix_matchpoint (id) ON DELETE CASCADE,
+ matchpoint INT NOT NULL REFERENCES config.circ_matrix_matchpoint (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
items_out INT NOT NULL, -- Total current active circulations must be less than this, NULL means skip (always pass)
- circ_mod TEXT NOT NULL REFERENCES config.circ_modifier (code) ON DELETE CASCADE ON UPDATE CASCADE -- circ_modifier type that the max out applies to
+ circ_mod TEXT NOT NULL REFERENCES config.circ_modifier (code) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED-- circ_modifier type that the max out applies to
);
-- How to circ, assuming tests pass
CREATE TABLE config.circ_matrix_ruleset (
- matchpoint INT PRIMARY KEY REFERENCES config.circ_matrix_matchpoint (id),
- duration_rule INT NOT NULL REFERENCES config.rule_circ_duration (id),
- recurring_fine_rule INT NOT NULL REFERENCES config.rule_recuring_fine (id),
- max_fine_rule INT NOT NULL REFERENCES config.rule_max_fine (id)
+ matchpoint INT PRIMARY KEY REFERENCES config.circ_matrix_matchpoint (id) DEFERRABLE INITIALLY DEFERRED,
+ duration_rule INT NOT NULL REFERENCES config.rule_circ_duration (id) DEFERRABLE INITIALLY DEFERRED,
+ recurring_fine_rule INT NOT NULL REFERENCES config.rule_recuring_fine (id) DEFERRABLE INITIALLY DEFERRED,
+ max_fine_rule INT NOT NULL REFERENCES config.rule_max_fine (id) DEFERRABLE INITIALLY DEFERRED
);
CREATE OR REPLACE FUNCTION action.find_circ_matrix_matchpoint( context_ou INT, match_item BIGINT, match_user INT ) RETURNS INT AS $func$
CREATE TABLE config.hold_matrix_matchpoint (
id SERIAL PRIMARY KEY,
active BOOL NOT NULL DEFAULT TRUE,
- user_home_ou INT REFERENCES actor.org_unit (id), -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
- request_ou INT REFERENCES actor.org_unit (id), -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
- pickup_ou INT REFERENCES actor.org_unit (id), -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
- item_owning_ou INT REFERENCES actor.org_unit (id), -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
- item_circ_ou INT REFERENCES actor.org_unit (id), -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
- usr_grp INT REFERENCES permission.grp_tree (id), -- Set to the top applicable group from the group tree; will need decendents and prox functions for filtering
- requestor_grp INT NOT NULL REFERENCES permission.grp_tree (id), -- Set to the top applicable group from the group tree; will need decendents and prox functions for filtering
- circ_modifier TEXT REFERENCES config.circ_modifier (code),
- marc_type TEXT REFERENCES config.item_type_map (code),
- marc_form TEXT REFERENCES config.item_form_map (code),
- marc_vr_format TEXT REFERENCES config.videorecording_format_map (code),
+ user_home_ou INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
+ request_ou INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
+ pickup_ou INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
+ item_owning_ou INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
+ item_circ_ou INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, -- Set to the top OU for the matchpoint applicability range; we can use org_unit_prox to choose the "best"
+ usr_grp INT REFERENCES permission.grp_tree (id) DEFERRABLE INITIALLY DEFERRED, -- Set to the top applicable group from the group tree; will need descendents and prox functions for filtering
+ requestor_grp INT NOT NULL REFERENCES permission.grp_tree (id) DEFERRABLE INITIALLY DEFERRED, -- Set to the top applicable group from the group tree; will need descendents and prox functions for filtering
+ circ_modifier TEXT REFERENCES config.circ_modifier (code) DEFERRABLE INITIALLY DEFERRED,
+ marc_type TEXT REFERENCES config.item_type_map (code) DEFERRABLE INITIALLY DEFERRED,
+ marc_form TEXT REFERENCES config.item_form_map (code) DEFERRABLE INITIALLY DEFERRED,
+ marc_vr_format TEXT REFERENCES config.videorecording_format_map (code) DEFERRABLE INITIALLY DEFERRED,
ref_flag BOOL,
CONSTRAINT hous_once_per_grp_loc_mod_marc UNIQUE (user_home_ou, request_ou, pickup_ou, item_owning_ou, item_circ_ou, requestor_grp, usr_grp, circ_modifier, marc_type, marc_form, marc_vr_format)
);
-- Tests to determine if hold against a specific copy is possible for a user at (and from) a location
CREATE TABLE config.hold_matrix_test (
- matchpoint INT PRIMARY KEY REFERENCES config.hold_matrix_matchpoint (id),
+ matchpoint INT PRIMARY KEY REFERENCES config.hold_matrix_matchpoint (id) DEFERRABLE INITIALLY DEFERRED,
holdable BOOL NOT NULL DEFAULT TRUE, -- Hard "can't hold" flag requiring an override
distance_is_from_owner BOOL NOT NULL DEFAULT FALSE, -- How to calculate transit_range. True means owning lib, false means copy circ lib
- transit_range INT REFERENCES actor.org_unit_type (id), -- Can circ inside range of cn.owner/cp.circ_lib at depth of the org_unit_type specified here
+ transit_range INT REFERENCES actor.org_unit_type (id) DEFERRABLE INITIALLY DEFERRED, -- Can circ inside range of cn.owner/cp.circ_lib at depth of the org_unit_type specified here
max_holds INT, -- Total hold requests must be less than this, NULL means skip (always pass)
include_frozen_holds BOOL NOT NULL DEFAULT TRUE, -- Include frozen hold requests in the count for max_holds test
- age_hold_protect_rule INT REFERENCES config.rule_age_hold_protect (id) -- still not sure we want to move this off the copy
+ age_hold_protect_rule INT REFERENCES config.rule_age_hold_protect (id) DEFERRABLE INITIALLY DEFERRED -- still not sure we want to move this off the copy
);
CREATE OR REPLACE FUNCTION action.find_hold_matrix_matchpoint( pickup_ou INT, request_ou INT, match_item BIGINT, match_user INT, match_requestor INT ) RETURNS INT AS $func$
CREATE TABLE search.relevance_adjustment (
id SERIAL PRIMARY KEY,
active BOOL NOT NULL DEFAULT TRUE,
- field INT NOT NULL REFERENCES config.metabib_field (id),
+ field INT NOT NULL REFERENCES config.metabib_field (id) DEFERRABLE INITIALLY DEFERRED,
bump_type TEXT NOT NULL CHECK (bump_type IN ('word_order','first_word','full_match')),
multiplier NUMERIC NOT NULL DEFAULT 1.0
);
name TEXT NOT NULL,
description TEXT NOT NULL,
data TEXT NOT NULL,
- folder INT NOT NULL REFERENCES reporter.template_folder (id)
+ folder INT NOT NULL REFERENCES reporter.template_folder (id) DEFERRABLE INITIALLY DEFERRED
);
CREATE INDEX rpt_tmpl_owner_idx ON reporter.template (owner);
CREATE INDEX rpt_tmpl_fldr_idx ON reporter.template (folder);
description TEXT NOT NULL DEFAULT '',
template INT NOT NULL REFERENCES reporter.template (id) DEFERRABLE INITIALLY DEFERRED,
data TEXT NOT NULL,
- folder INT NOT NULL REFERENCES reporter.report_folder (id),
+ folder INT NOT NULL REFERENCES reporter.report_folder (id) DEFERRABLE INITIALLY DEFERRED,
recur BOOL NOT NULL DEFAULT FALSE,
recurance INTERVAL
);
CREATE TABLE reporter.schedule (
id SERIAL PRIMARY KEY,
report INT NOT NULL REFERENCES reporter.report (id) DEFERRABLE INITIALLY DEFERRED,
- folder INT NOT NULL REFERENCES reporter.output_folder (id),
+ folder INT NOT NULL REFERENCES reporter.output_folder (id) DEFERRABLE INITIALLY DEFERRED,
runner INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
run_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
start_time TIMESTAMP WITH TIME ZONE,
this.location = kwargs.location;
this.authcookie = kwargs.authcookie || openils.User.authcookie;
- if (this.authtoken) this.getBySession();
- else if (this.id && this.authtoken) this.user = this.getById( this.id );
+ if (this.id && this.authtoken) this.user = this.getById( this.id );
+ else if (this.authtoken) this.getBySession();
else if (kwargs.login) this.login();
},