]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/210.schema.serials.sql
9637dada774134c5a744bb41605af9bffc025a34
[working/Evergreen.git] / Open-ILS / src / sql / Pg / 210.schema.serials.sql
1
2
3 DROP SCHEMA serial CASCADE;
4
5 CREATE TABLE asset.uri (
6         id      SERIAL  PRIMARY KEY,
7         href    TEXT    NOT NULL,
8         label   TEXT,
9         use     TEXT,
10         active  BOOL    NOT NULL DEFAULT TRUE
11 );
12
13 ALTER TABLE asset.call_number ADD COLUMN uri INT REFERENCES asset.uri (id) DEFERRABLE INITIALLY DEFERRED;
14
15 BEGIN;
16
17 CREATE SCHEMA serial;
18
19 CREATE TABLE serial.subscription (
20         id              SERIAL  PRIMARY KEY,
21         callnumber      BIGINT  REFERENCES asset.call_number (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
22         uri             INT     REFERENCES asset.uri (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
23         start_date      DATE    NOT NULL,
24         end_date        DATE    NOT NULL
25 );
26
27 CREATE TABLE serial.binding_unit (
28         id              SERIAL  PRIMARY KEY,
29         subscription    INT     NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
30         label           TEXT    NOT NULL,
31         CONSTRAINT bu_label_once_per_sub UNIQUE (subscription, label)
32 );
33
34 CREATE TABLE serial.issuance (
35         id              SERIAL  PRIMARY KEY,
36         subscription    INT     NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
37         target_copy     BIGINT  REFERENCES asset.copy (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
38         binding_unit    INT     REFERENCES serial.binding_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
39         label           TEXT
40 );
41
42 CREATE TABLE serial.bib_summary (
43         id                      SERIAL  PRIMARY KEY,
44         call_number             INT     UNIQUE NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
45         generated_coverage      TEXT    NOT NULL,
46         textual_holdings        TEXT
47 );
48
49 CREATE TABLE serial.sup_summary (
50         id                      SERIAL  PRIMARY KEY,
51         call_number             INT     UNIQUE NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
52         generated_coverage      TEXT    NOT NULL,
53         textual_holdings        TEXT
54 );
55
56 CREATE TABLE serial.index_summary (
57         id                      SERIAL  PRIMARY KEY,
58         call_number             INT     UNIQUE NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
59         generated_coverage      TEXT    NOT NULL,
60         textual_holdings        TEXT
61 );
62
63 COMMIT;
64