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