3 DROP SCHEMA IF EXISTS serial CASCADE;
9 CREATE TABLE serial.record_entry (
10 id BIGSERIAL PRIMARY KEY,
11 record BIGINT REFERENCES biblio.record_entry (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
12 owning_lib INT NOT NULL DEFAULT 1 REFERENCES actor.org_unit (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
13 creator INT NOT NULL DEFAULT 1,
14 editor INT NOT NULL DEFAULT 1,
16 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
17 edit_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
18 active BOOL NOT NULL DEFAULT TRUE,
19 deleted BOOL NOT NULL DEFAULT FALSE,
21 last_xact_id TEXT NOT NULL
23 CREATE INDEX serial_record_entry_creator_idx ON serial.record_entry ( creator );
24 CREATE INDEX serial_record_entry_editor_idx ON serial.record_entry ( editor );
25 CREATE INDEX serial_record_entry_owning_lib_idx ON serial.record_entry ( owning_lib, deleted );
27 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;
29 CREATE TABLE serial.subscription (
30 id SERIAL PRIMARY KEY,
31 start_date TIMESTAMP WITH TIME ZONE NOT NULL,
32 end_date TIMESTAMP WITH TIME ZONE, -- interpret NULL as current subscription
33 record_entry BIGINT REFERENCES biblio.record_entry (id)
35 DEFERRABLE INITIALLY DEFERRED,
36 expected_date_offset INTERVAL
37 -- acquisitions/business-side tables link to here
41 CREATE TABLE serial.caption_and_pattern (
42 id SERIAL PRIMARY KEY,
43 subscription INT NOT NULL
44 REFERENCES serial.subscription (id)
46 DEFERRABLE INITIALLY DEFERRED,
48 CONSTRAINT cap_type CHECK ( type in
49 ( 'basic', 'supplement', 'index' )),
50 create_time TIMESTAMPTZ NOT NULL DEFAULT now(),
51 active BOOL NOT NULL DEFAULT FALSE,
52 pattern_code TEXT NOT NULL, -- must contain JSON
66 --at least one distribution per org_unit holding issues
67 CREATE TABLE serial.distribution (
68 id SERIAL PRIMARY KEY,
69 record_entry BIGINT REFERENCES serial.record_entry (id)
71 DEFERRABLE INITIALLY DEFERRED,
72 subscription INT NOT NULL
73 REFERENCES serial.subscription (id)
75 DEFERRABLE INITIALLY DEFERRED,
76 holding_lib INT NOT NULL
77 REFERENCES actor.org_unit (id)
78 DEFERRABLE INITIALLY DEFERRED,
80 receive_call_number BIGINT REFERENCES asset.call_number (id)
81 DEFERRABLE INITIALLY DEFERRED,
82 receive_unit_template INT REFERENCES asset.copy_template (id)
83 DEFERRABLE INITIALLY DEFERRED,
84 bind_call_number BIGINT REFERENCES asset.call_number (id)
85 DEFERRABLE INITIALLY DEFERRED,
86 bind_unit_template INT REFERENCES asset.copy_template (id)
87 DEFERRABLE INITIALLY DEFERRED,
89 unit_label_suffix TEXT
91 CREATE UNIQUE INDEX one_dist_per_sre_idx ON serial.distribution (record_entry);
93 CREATE TABLE serial.stream (
94 id SERIAL PRIMARY KEY,
95 distribution INT NOT NULL
96 REFERENCES serial.distribution (id)
98 DEFERRABLE INITIALLY DEFERRED,
102 CREATE UNIQUE INDEX label_once_per_dist
103 ON serial.stream (distribution, routing_label)
104 WHERE routing_label IS NOT NULL;
106 CREATE TABLE serial.routing_list_user (
107 id SERIAL PRIMARY KEY,
109 REFERENCES serial.stream
111 DEFERRABLE INITIALLY DEFERRED,
112 pos INT NOT NULL DEFAULT 1,
113 reader INT REFERENCES actor.usr
115 DEFERRABLE INITIALLY DEFERRED,
118 CONSTRAINT one_pos_per_routing_list UNIQUE ( stream, pos ),
119 CONSTRAINT reader_or_dept CHECK
121 -- Recipient is a person or a department, but not both
122 (reader IS NOT NULL AND department IS NULL) OR
123 (reader IS NULL AND department IS NOT NULL)
127 CREATE TABLE serial.issuance (
128 id SERIAL PRIMARY KEY,
130 REFERENCES actor.usr (id)
131 DEFERRABLE INITIALLY DEFERRED,
133 REFERENCES actor.usr (id)
134 DEFERRABLE INITIALLY DEFERRED,
135 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
136 edit_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
137 subscription INT NOT NULL
138 REFERENCES serial.subscription (id)
140 DEFERRABLE INITIALLY DEFERRED,
142 date_published TIMESTAMP WITH TIME ZONE,
144 holding_type TEXT CONSTRAINT valid_holding_type CHECK
147 OR holding_type IN ('basic','supplement','index')
150 -- TODO: add columns for separate enumeration/chronology values
153 CREATE TABLE serial.unit (
156 contents TEXT NOT NULL
157 ) INHERITS (asset.copy);
159 ALTER TABLE serial.unit ADD PRIMARY KEY (id);
161 CREATE TABLE serial.item (
162 id SERIAL PRIMARY KEY,
164 REFERENCES actor.usr (id)
165 DEFERRABLE INITIALLY DEFERRED,
167 REFERENCES actor.usr (id)
168 DEFERRABLE INITIALLY DEFERRED,
169 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
170 edit_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
171 issuance INT NOT NULL
172 REFERENCES serial.issuance (id)
174 DEFERRABLE INITIALLY DEFERRED,
176 REFERENCES serial.stream (id)
178 DEFERRABLE INITIALLY DEFERRED,
179 unit INT REFERENCES serial.unit (id)
181 DEFERRABLE INITIALLY DEFERRED,
182 uri INT REFERENCES asset.uri (id)
184 DEFERRABLE INITIALLY DEFERRED,
185 date_expected TIMESTAMP WITH TIME ZONE,
186 date_received TIMESTAMP WITH TIME ZONE
189 CREATE TABLE serial.item_note (
190 id SERIAL PRIMARY KEY,
192 REFERENCES serial.item (id)
194 DEFERRABLE INITIALLY DEFERRED,
196 REFERENCES actor.usr (id)
197 DEFERRABLE INITIALLY DEFERRED,
198 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
199 pub BOOL NOT NULL DEFAULT FALSE,
204 CREATE TABLE serial.bib_summary (
205 id SERIAL PRIMARY KEY,
206 distribution INT NOT NULL
207 REFERENCES serial.distribution (id)
209 DEFERRABLE INITIALLY DEFERRED,
210 generated_coverage TEXT NOT NULL,
211 textual_holdings TEXT
214 CREATE TABLE serial.sup_summary (
215 id SERIAL PRIMARY KEY,
216 distribution INT NOT NULL
217 REFERENCES serial.distribution (id)
219 DEFERRABLE INITIALLY DEFERRED,
220 generated_coverage TEXT NOT NULL,
221 textual_holdings TEXT
224 CREATE TABLE serial.index_summary (
225 id SERIAL PRIMARY KEY,
226 distribution INT NOT NULL
227 REFERENCES serial.distribution (id)
229 DEFERRABLE INITIALLY DEFERRED,
230 generated_coverage TEXT NOT NULL,
231 textual_holdings TEXT