2 * Copyright (C) 2004-2008 Georgia Public Library Service
3 * Copyright (C) 2007-2008 Equinox Software, Inc.
4 * Mike Rylander <miker@esilibrary.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 DROP SCHEMA asset CASCADE;
24 CREATE TABLE asset.copy_location (
25 id SERIAL PRIMARY KEY,
27 owning_lib INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
28 holdable BOOL NOT NULL DEFAULT TRUE,
29 hold_verify BOOL NOT NULL DEFAULT FALSE,
30 opac_visible BOOL NOT NULL DEFAULT TRUE,
31 circulate BOOL NOT NULL DEFAULT TRUE
34 CREATE TABLE asset.copy (
35 id BIGSERIAL PRIMARY KEY,
36 circ_lib INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
37 creator BIGINT NOT NULL,
38 call_number BIGINT NOT NULL,
39 editor BIGINT NOT NULL,
40 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
41 edit_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
43 status INT NOT NULL DEFAULT 0 REFERENCES config.copy_status (id) DEFERRABLE INITIALLY DEFERRED,
44 location INT NOT NULL DEFAULT 1 REFERENCES asset.copy_location (id) DEFERRABLE INITIALLY DEFERRED,
45 loan_duration INT NOT NULL CHECK ( loan_duration IN (1,2,3) ),
46 fine_level INT NOT NULL CHECK ( fine_level IN (1,2,3) ),
48 circulate BOOL NOT NULL DEFAULT TRUE,
49 deposit BOOL NOT NULL DEFAULT FALSE,
50 ref BOOL NOT NULL DEFAULT FALSE,
51 holdable BOOL NOT NULL DEFAULT TRUE,
52 deposit_amount NUMERIC(6,2) NOT NULL DEFAULT 0.00,
54 barcode TEXT NOT NULL,
60 opac_visible BOOL NOT NULL DEFAULT TRUE,
61 deleted BOOL NOT NULL DEFAULT FALSE
63 CREATE UNIQUE INDEX copy_barcode_key ON asset.copy (barcode) WHERE deleted IS FALSE;
64 CREATE INDEX cp_cn_idx ON asset.copy (call_number);
65 CREATE INDEX cp_avail_cn_idx ON asset.copy (call_number);
66 CREATE RULE protect_copy_delete AS ON DELETE TO asset.copy DO INSTEAD UPDATE asset.copy SET deleted = TRUE WHERE OLD.id = asset.copy.id;
68 CREATE TABLE asset.copy_transparency (
69 id SERIAL PRIMARY KEY,
70 deposit_amount NUMERIC(6,2),
71 owner INT NOT NULL REFERENCES actor.org_unit (id),
72 circ_lib INT REFERENCES actor.org_unit (id),
73 loan_duration INT CHECK ( loan_duration IN (1,2,3) ),
74 fine_level INT CHECK ( fine_level IN (1,2,3) ),
83 CONSTRAINT scte_name_once_per_lib UNIQUE (owner,name)
86 CREATE TABLE asset.copy_tranparency_map (
87 id BIGSERIAL PRIMARY KEY,
88 tansparency INT NOT NULL REFERENCES asset.copy_transparency (id),
89 target_copy INT NOT NULL UNIQUE REFERENCES asset.copy (id)
91 CREATE INDEX cp_tr_cp_idx ON asset.copy_tranparency_map (tansparency);
93 CREATE TABLE asset.stat_cat_entry_transparency_map (
94 id BIGSERIAL PRIMARY KEY,
95 stat_cat INT NOT NULL, -- needs ON DELETE CASCADE
96 stat_cat_entry INT NOT NULL, -- needs ON DELETE CASCADE
97 owning_transparency INT NOT NULL, -- needs ON DELETE CASCADE
98 CONSTRAINT scte_once_per_trans UNIQUE (owning_transparency,stat_cat)
101 CREATE TABLE asset.stat_cat (
102 id SERIAL PRIMARY KEY,
104 opac_visible BOOL NOT NULL DEFAULT FALSE,
106 CONSTRAINT sc_once_per_owner UNIQUE (owner,name)
109 CREATE TABLE asset.stat_cat_entry (
110 id SERIAL PRIMARY KEY,
111 stat_cat INT NOT NULL,
114 CONSTRAINT sce_once_per_owner UNIQUE (stat_cat,owner,value)
117 CREATE TABLE asset.stat_cat_entry_copy_map (
118 id BIGSERIAL PRIMARY KEY,
119 stat_cat INT NOT NULL,
120 stat_cat_entry INT NOT NULL,
121 owning_copy BIGINT NOT NULL,
122 CONSTRAINT sce_once_per_copy UNIQUE (owning_copy,stat_cat)
125 CREATE TABLE asset.copy_note (
126 id BIGSERIAL PRIMARY KEY,
127 owning_copy BIGINT NOT NULL,
128 creator BIGINT NOT NULL,
129 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
130 pub BOOL NOT NULL DEFAULT FALSE,
135 CREATE TABLE asset.call_number (
136 id bigserial PRIMARY KEY,
137 creator BIGINT NOT NULL,
138 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
139 editor BIGINT NOT NULL,
140 edit_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
141 record bigint NOT NULL,
142 owning_lib INT NOT NULL,
144 deleted BOOL NOT NULL DEFAULT FALSE
146 CREATE INDEX asset_call_number_record_idx ON asset.call_number (record);
147 CREATE INDEX asset_call_number_creator_idx ON asset.call_number (creator);
148 CREATE INDEX asset_call_number_editor_idx ON asset.call_number (editor);
149 CREATE INDEX asset_call_number_dewey_idx ON asset.call_number (public.call_number_dewey(label));
150 CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (upper(label),id,owning_lib);
151 CREATE UNIQUE INDEX asset_call_number_label_once_per_lib ON asset.call_number (record, owning_lib, label) WHERE deleted IS FALSE;
152 CREATE RULE protect_cn_delete AS ON DELETE TO asset.call_number DO INSTEAD UPDATE asset.call_number SET deleted = TRUE WHERE OLD.id = asset.call_number.id;
154 CREATE TABLE asset.call_number_note (
155 id BIGSERIAL PRIMARY KEY,
156 call_number BIGINT NOT NULL,
157 creator BIGINT NOT NULL,
158 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
159 pub BOOL NOT NULL DEFAULT FALSE,
164 CREATE VIEW stats.fleshed_copy AS
166 CAST(cp.create_date AS DATE) AS create_date_day,
167 CAST(cp.edit_date AS DATE) AS edit_date_day,
168 DATE_TRUNC('hour', cp.create_date) AS create_date_hour,
169 DATE_TRUNC('hour', cp.edit_date) AS edit_date_hour,
170 cn.label AS call_number_label,
176 JOIN asset.call_number cn ON (cp.call_number = cn.id)
177 JOIN metabib.rec_descriptor rd ON (rd.record = cn.record);
179 CREATE VIEW stats.fleshed_call_number AS
181 CAST(cn.create_date AS DATE) AS create_date_day,
182 CAST(cn.edit_date AS DATE) AS edit_date_day,
183 DATE_TRUNC('hour', cn.create_date) AS create_date_hour,
184 DATE_TRUNC('hour', cn.edit_date) AS edit_date_hour,
188 FROM asset.call_number cn
189 JOIN metabib.rec_descriptor rd ON (rd.record = cn.record);