]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/011.schema.authority.sql
add a reasonable prefix to autogenerated TCNs
[Evergreen.git] / Open-ILS / src / sql / Pg / 011.schema.authority.sql
1 /*
2  * Copyright (C) 2004-2008  Georgia Public Library Service
3  * Copyright (C) 2008  Equinox Software, Inc.
4  * Mike Rylander <miker@esilibrary.com> 
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17
18 DROP SCHEMA authority CASCADE;
19
20 BEGIN;
21 CREATE SCHEMA authority;
22
23 CREATE TABLE authority.record_entry (
24         id              BIGSERIAL       PRIMARY KEY,
25         arn_source      TEXT            NOT NULL DEFAULT 'AUTOGEN',
26         arn_value       TEXT            NOT NULL,
27         creator         INT             NOT NULL DEFAULT 1,
28         editor          INT             NOT NULL DEFAULT 1,
29         create_date     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT now(),
30         edit_date       TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT now(),
31         active          BOOL            NOT NULL DEFAULT TRUE,
32         deleted         BOOL            NOT NULL DEFAULT FALSE,
33         source          INT,
34         marc            TEXT            NOT NULL,
35         last_xact_id    TEXT            NOT NULL
36 );
37 CREATE INDEX authority_record_entry_creator_idx ON authority.record_entry ( creator );
38 CREATE INDEX authority_record_entry_editor_idx ON authority.record_entry ( editor );
39 CREATE UNIQUE INDEX authority_record_unique_tcn ON authority.record_entry (arn_source,arn_value) WHERE deleted IS FALSE;
40
41 CREATE TABLE authority.record_note (
42         id              BIGSERIAL       PRIMARY KEY,
43         record          BIGINT          NOT NULL REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED,
44         value           TEXT            NOT NULL,
45         creator         INT             NOT NULL DEFAULT 1,
46         editor          INT             NOT NULL DEFAULT 1,
47         create_date     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT now(),
48         edit_date       TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT now()
49 );
50 CREATE INDEX authority_record_note_record_idx ON authority.record_note ( record );
51 CREATE INDEX authority_record_note_creator_idx ON authority.record_note ( creator );
52 CREATE INDEX authority_record_note_editor_idx ON authority.record_note ( editor );
53
54 CREATE TABLE authority.rec_descriptor (
55         id              BIGSERIAL PRIMARY KEY,
56         record          BIGINT,
57         record_status   TEXT,
58         char_encoding   TEXT
59 );
60 CREATE INDEX authority_rec_descriptor_record_idx ON authority.rec_descriptor (record);
61
62 CREATE TABLE authority.full_rec (
63         id              BIGSERIAL       PRIMARY KEY,
64         record          BIGINT          NOT NULL,
65         tag             CHAR(3)         NOT NULL,
66         ind1            TEXT,
67         ind2            TEXT,
68         subfield        TEXT,
69         value           TEXT            NOT NULL,
70         index_vector    tsvector        NOT NULL
71 );
72 CREATE INDEX authority_full_rec_record_idx ON authority.full_rec (record);
73 CREATE INDEX authority_full_rec_tag_part_idx ON authority.full_rec (SUBSTRING(tag FROM 2));
74 CREATE TRIGGER authority_full_rec_fti_trigger
75         BEFORE UPDATE OR INSERT ON authority.full_rec
76         FOR EACH ROW EXECUTE PROCEDURE tsearch2(index_vector, value);
77
78 CREATE INDEX authority_full_rec_index_vector_idx ON authority.full_rec USING GIST (index_vector);
79
80 CREATE OR REPLACE VIEW authority.tracing_links AS
81         SELECT  main.record AS record,
82                 main.id AS main_id,
83                 main.tag AS main_tag,
84                 main.value AS main_value,
85                 substr(link.value,1,1) AS relationship,
86                 substr(link.value,2,1) AS use_restriction,
87                 substr(link.value,3,1) AS deprecation,
88                 substr(link.value,4,1) AS display_restriction,
89                 link_value.id AS link_id,
90                 link_value.tag AS link_tag,
91                 link_value.value AS link_value
92           FROM  authority.full_rec main
93                 JOIN authority.full_rec link
94                         ON (    link.record = main.record
95                                 AND link.tag in ((main.tag::int + 400)::text, (main.tag::int + 300)::text)
96                                 AND link.subfield = 'w' )
97                 JOIN authority.full_rec link_value
98                         ON (    link_value.record = main.record
99                                 AND link_value.tag = link.tag
100                                 AND link_value.subfield = 'a' )
101           WHERE main.tag IN ('100','110','111','130','150','151','155','180','181','182','185')
102                 AND main.subfield = 'a';
103
104
105 COMMIT;