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 );
26 CREATE TRIGGER b_maintain_901 BEFORE INSERT OR UPDATE ON serial.record_entry FOR EACH ROW EXECUTE PROCEDURE maintain_901();
28 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;
30 CREATE TABLE serial.subscription (
31 id SERIAL PRIMARY KEY,
32 owning_lib INT NOT NULL DEFAULT 1 REFERENCES actor.org_unit (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
33 start_date TIMESTAMP WITH TIME ZONE NOT NULL,
34 end_date TIMESTAMP WITH TIME ZONE, -- interpret NULL as current subscription
35 record_entry BIGINT REFERENCES biblio.record_entry (id)
37 DEFERRABLE INITIALLY DEFERRED,
38 expected_date_offset INTERVAL
39 -- acquisitions/business-side tables link to here
43 CREATE TABLE serial.caption_and_pattern (
44 id SERIAL PRIMARY KEY,
45 subscription INT NOT NULL
46 REFERENCES serial.subscription (id)
48 DEFERRABLE INITIALLY DEFERRED,
50 CONSTRAINT cap_type CHECK ( type in
51 ( 'basic', 'supplement', 'index' )),
52 create_time TIMESTAMPTZ NOT NULL DEFAULT now(),
53 active BOOL NOT NULL DEFAULT FALSE,
54 pattern_code TEXT NOT NULL, -- must contain JSON
68 --at least one distribution per org_unit holding issues
69 CREATE TABLE serial.distribution (
70 id SERIAL PRIMARY KEY,
71 record_entry BIGINT REFERENCES serial.record_entry (id)
73 DEFERRABLE INITIALLY DEFERRED,
74 subscription INT NOT NULL
75 REFERENCES serial.subscription (id)
77 DEFERRABLE INITIALLY DEFERRED,
78 holding_lib INT NOT NULL
79 REFERENCES actor.org_unit (id)
80 DEFERRABLE INITIALLY DEFERRED,
82 receive_call_number BIGINT REFERENCES asset.call_number (id)
83 DEFERRABLE INITIALLY DEFERRED,
84 receive_unit_template INT REFERENCES asset.copy_template (id)
85 DEFERRABLE INITIALLY DEFERRED,
86 bind_call_number BIGINT REFERENCES asset.call_number (id)
87 DEFERRABLE INITIALLY DEFERRED,
88 bind_unit_template INT REFERENCES asset.copy_template (id)
89 DEFERRABLE INITIALLY DEFERRED,
91 unit_label_suffix TEXT
93 CREATE UNIQUE INDEX one_dist_per_sre_idx ON serial.distribution (record_entry);
95 CREATE TABLE serial.stream (
96 id SERIAL PRIMARY KEY,
97 distribution INT NOT NULL
98 REFERENCES serial.distribution (id)
100 DEFERRABLE INITIALLY DEFERRED,
104 CREATE UNIQUE INDEX label_once_per_dist
105 ON serial.stream (distribution, routing_label)
106 WHERE routing_label IS NOT NULL;
108 CREATE TABLE serial.routing_list_user (
109 id SERIAL PRIMARY KEY,
111 REFERENCES serial.stream
113 DEFERRABLE INITIALLY DEFERRED,
114 pos INT NOT NULL DEFAULT 1,
115 reader INT REFERENCES actor.usr
117 DEFERRABLE INITIALLY DEFERRED,
120 CONSTRAINT one_pos_per_routing_list UNIQUE ( stream, pos ),
121 CONSTRAINT reader_or_dept CHECK
123 -- Recipient is a person or a department, but not both
124 (reader IS NOT NULL AND department IS NULL) OR
125 (reader IS NULL AND department IS NOT NULL)
129 CREATE TABLE serial.issuance (
130 id SERIAL PRIMARY KEY,
132 REFERENCES actor.usr (id)
133 DEFERRABLE INITIALLY DEFERRED,
135 REFERENCES actor.usr (id)
136 DEFERRABLE INITIALLY DEFERRED,
137 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
138 edit_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
139 subscription INT NOT NULL
140 REFERENCES serial.subscription (id)
142 DEFERRABLE INITIALLY DEFERRED,
144 date_published TIMESTAMP WITH TIME ZONE,
146 holding_type TEXT CONSTRAINT valid_holding_type CHECK
149 OR holding_type IN ('basic','supplement','index')
152 -- TODO: add columns for separate enumeration/chronology values
155 CREATE TABLE serial.unit (
158 contents TEXT NOT NULL
159 ) INHERITS (asset.copy);
161 ALTER TABLE serial.unit ADD PRIMARY KEY (id);
163 CREATE TABLE serial.item (
164 id SERIAL PRIMARY KEY,
166 REFERENCES actor.usr (id)
167 DEFERRABLE INITIALLY DEFERRED,
169 REFERENCES actor.usr (id)
170 DEFERRABLE INITIALLY DEFERRED,
171 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
172 edit_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
173 issuance INT NOT NULL
174 REFERENCES serial.issuance (id)
176 DEFERRABLE INITIALLY DEFERRED,
178 REFERENCES serial.stream (id)
180 DEFERRABLE INITIALLY DEFERRED,
181 unit INT REFERENCES serial.unit (id)
183 DEFERRABLE INITIALLY DEFERRED,
184 uri INT REFERENCES asset.uri (id)
186 DEFERRABLE INITIALLY DEFERRED,
187 date_expected TIMESTAMP WITH TIME ZONE,
188 date_received TIMESTAMP WITH TIME ZONE
191 CREATE TABLE serial.item_note (
192 id SERIAL PRIMARY KEY,
194 REFERENCES serial.item (id)
196 DEFERRABLE INITIALLY DEFERRED,
198 REFERENCES actor.usr (id)
199 DEFERRABLE INITIALLY DEFERRED,
200 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
201 pub BOOL NOT NULL DEFAULT FALSE,
206 CREATE TABLE serial.bib_summary (
207 id SERIAL PRIMARY KEY,
208 distribution INT NOT NULL
209 REFERENCES serial.distribution (id)
211 DEFERRABLE INITIALLY DEFERRED,
212 generated_coverage TEXT NOT NULL,
213 textual_holdings TEXT
216 CREATE TABLE serial.sup_summary (
217 id SERIAL PRIMARY KEY,
218 distribution INT NOT NULL
219 REFERENCES serial.distribution (id)
221 DEFERRABLE INITIALLY DEFERRED,
222 generated_coverage TEXT NOT NULL,
223 textual_holdings TEXT
226 CREATE TABLE serial.index_summary (
227 id SERIAL PRIMARY KEY,
228 distribution INT NOT NULL
229 REFERENCES serial.distribution (id)
231 DEFERRABLE INITIALLY DEFERRED,
232 generated_coverage TEXT NOT NULL,
233 textual_holdings TEXT