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 serial.record_entry (id)
35 DEFERRABLE INITIALLY DEFERRED,
36 expected_date_offset INTERVAL
37 -- acquisitions/business-side tables link to here
40 --at least one distribution per org_unit holding issues
41 CREATE TABLE serial.distribution (
42 id SERIAL PRIMARY KEY,
43 subscription INT NOT NULL
44 REFERENCES serial.subscription (id)
46 DEFERRABLE INITIALLY DEFERRED,
47 holding_lib INT NOT NULL
48 REFERENCES actor.org_unit (id)
49 DEFERRABLE INITIALLY DEFERRED,
51 receive_call_number BIGINT REFERENCES asset.call_number (id)
52 DEFERRABLE INITIALLY DEFERRED,
53 receive_unit_template INT REFERENCES asset.copy_template (id)
54 DEFERRABLE INITIALLY DEFERRED,
55 bind_call_number BIGINT REFERENCES asset.call_number (id)
56 DEFERRABLE INITIALLY DEFERRED,
57 bind_unit_template INT REFERENCES asset.copy_template (id)
58 DEFERRABLE INITIALLY DEFERRED,
60 unit_label_suffix TEXT
63 CREATE TABLE serial.stream (
64 id SERIAL PRIMARY KEY,
65 distribution INT NOT NULL
66 REFERENCES serial.distribution (id)
68 DEFERRABLE INITIALLY DEFERRED,
72 CREATE UNIQUE INDEX label_once_per_dist
73 ON serial.stream (distribution, routing_label)
74 WHERE routing_label IS NOT NULL;
76 CREATE TABLE serial.routing_list_user (
77 id SERIAL PRIMARY KEY,
79 REFERENCES serial.stream
81 DEFERRABLE INITIALLY DEFERRED,
82 pos INT NOT NULL DEFAULT 1,
83 reader INT REFERENCES actor.usr
85 DEFERRABLE INITIALLY DEFERRED,
88 CONSTRAINT one_pos_per_routing_list UNIQUE ( stream, pos ),
89 CONSTRAINT reader_or_dept CHECK
91 -- Recipient is a person or a department, but not both
92 (reader IS NOT NULL AND department IS NULL) OR
93 (reader IS NULL AND department IS NOT NULL)
97 CREATE TABLE serial.issuance (
98 id SERIAL PRIMARY KEY,
100 REFERENCES actor.usr (id)
101 DEFERRABLE INITIALLY DEFERRED,
103 REFERENCES actor.usr (id)
104 DEFERRABLE INITIALLY DEFERRED,
105 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
106 edit_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
107 subscription INT NOT NULL
108 REFERENCES serial.subscription (id)
110 DEFERRABLE INITIALLY DEFERRED,
112 date_published TIMESTAMP WITH TIME ZONE,
114 holding_type TEXT CONSTRAINT valid_holding_type CHECK
117 OR holding_type IN ('basic','supplement','index')
120 -- TODO: add columns for separate enumeration/chronology values
123 CREATE TABLE serial.unit (
126 contents TEXT NOT NULL
127 ) INHERITS (asset.copy);
129 ALTER TABLE serial.unit ADD PRIMARY KEY (id);
131 CREATE TABLE serial.item (
132 id SERIAL PRIMARY KEY,
134 REFERENCES actor.usr (id)
135 DEFERRABLE INITIALLY DEFERRED,
137 REFERENCES actor.usr (id)
138 DEFERRABLE INITIALLY DEFERRED,
139 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
140 edit_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
141 issuance INT NOT NULL
142 REFERENCES serial.issuance (id)
144 DEFERRABLE INITIALLY DEFERRED,
146 REFERENCES serial.stream (id)
148 DEFERRABLE INITIALLY DEFERRED,
149 unit INT REFERENCES serial.unit (id)
151 DEFERRABLE INITIALLY DEFERRED,
152 uri INT REFERENCES asset.uri (id)
154 DEFERRABLE INITIALLY DEFERRED,
155 date_expected TIMESTAMP WITH TIME ZONE,
156 date_received TIMESTAMP WITH TIME ZONE
159 CREATE TABLE serial.item_note (
160 id SERIAL PRIMARY KEY,
162 REFERENCES serial.item (id)
164 DEFERRABLE INITIALLY DEFERRED,
166 REFERENCES actor.usr (id)
167 DEFERRABLE INITIALLY DEFERRED,
168 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
169 pub BOOL NOT NULL DEFAULT FALSE,
174 CREATE TABLE serial.bib_summary (
175 id SERIAL PRIMARY KEY,
176 distribution INT NOT NULL
177 REFERENCES serial.distribution (id)
179 DEFERRABLE INITIALLY DEFERRED,
180 generated_coverage TEXT NOT NULL,
181 textual_holdings TEXT
184 CREATE TABLE serial.sup_summary (
185 id SERIAL PRIMARY KEY,
186 distribution INT NOT NULL
187 REFERENCES serial.distribution (id)
189 DEFERRABLE INITIALLY DEFERRED,
190 generated_coverage TEXT NOT NULL,
191 textual_holdings TEXT
194 CREATE TABLE serial.index_summary (
195 id SERIAL PRIMARY KEY,
196 distribution INT NOT NULL
197 REFERENCES serial.distribution (id)
199 DEFERRABLE INITIALLY DEFERRED,
200 generated_coverage TEXT NOT NULL,
201 textual_holdings TEXT