]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/210.schema.serials.sql
46d7e2286c72b6bfabf91b6766f788f393fe4258
[working/Evergreen.git] / Open-ILS / src / sql / Pg / 210.schema.serials.sql
1
2
3 DROP SCHEMA serial CASCADE;
4
5 BEGIN;
6
7 CREATE SCHEMA serial;
8
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,
15         source          INT,
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,
20         marc            TEXT            NOT NULL,
21         last_xact_id    TEXT            NOT NULL
22 );
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
27 CREATE TABLE serial.subscription (
28         id              SERIAL  PRIMARY KEY,
29         callnumber      BIGINT  REFERENCES asset.call_number (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
30         uri             INT     REFERENCES asset.uri (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
31         start_date      DATE    NOT NULL,
32         end_date        DATE    -- interpret NULL as current subscription 
33 );
34
35 CREATE TABLE serial.binding_unit (
36         id              SERIAL  PRIMARY KEY,
37         subscription    INT     NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
38         label           TEXT    NOT NULL,
39         CONSTRAINT bu_label_once_per_sub UNIQUE (subscription, label)
40 );
41
42 CREATE TABLE serial.issuance (
43         id              SERIAL  PRIMARY KEY,
44         subscription    INT     NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
45         target_copy     BIGINT  REFERENCES asset.copy (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
46         location        BIGINT  REFERENCES asset.copy_location(id) DEFERRABLE INITIALLY DEFERRED,
47         binding_unit    INT     REFERENCES serial.binding_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
48         label           TEXT
49 );
50
51 CREATE TABLE serial.bib_summary (
52         id                      SERIAL  PRIMARY KEY,
53         subscription            INT     UNIQUE NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
54         generated_coverage      TEXT    NOT NULL,
55         textual_holdings        TEXT
56 );
57
58 CREATE TABLE serial.sup_summary (
59         id                      SERIAL  PRIMARY KEY,
60         subscription            INT     UNIQUE NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
61         generated_coverage      TEXT    NOT NULL,
62         textual_holdings        TEXT
63 );
64
65 CREATE TABLE serial.index_summary (
66         id                      SERIAL  PRIMARY KEY,
67         subscription            INT     UNIQUE NOT NULL REFERENCES serial.subscription (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
68         generated_coverage      TEXT    NOT NULL,
69         textual_holdings        TEXT
70 );
71
72 COMMIT;
73