]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/010.schema.biblio.sql
Add a unique index on biblio.record_entry.id
[Evergreen.git] / Open-ILS / src / sql / Pg / 010.schema.biblio.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 biblio CASCADE;
19
20 BEGIN;
21 CREATE SCHEMA biblio;
22
23 CREATE SEQUENCE biblio.autogen_tcn_value_seq;
24 CREATE OR REPLACE FUNCTION biblio.next_autogen_tcn_value () RETURNS TEXT AS $$
25         BEGIN RETURN 'AUTOGENERATED-' || nextval('biblio.autogen_tcn_value_seq'::TEXT); END;
26 $$ LANGUAGE PLPGSQL;
27
28 CREATE TABLE biblio.record_entry (
29         id              BIGSERIAL       PRIMARY KEY,
30         creator         INT             NOT NULL DEFAULT 1,
31         editor          INT             NOT NULL DEFAULT 1,
32         source          INT,
33         quality         INT,
34         create_date     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT now(),
35         edit_date       TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT now(),
36         active          BOOL            NOT NULL DEFAULT TRUE,
37         deleted         BOOL            NOT NULL DEFAULT FALSE,
38         fingerprint     TEXT,
39         tcn_source      TEXT            NOT NULL DEFAULT 'AUTOGEN',
40         tcn_value       TEXT            NOT NULL DEFAULT biblio.next_autogen_tcn_value(),
41         marc            TEXT            NOT NULL,
42         last_xact_id    TEXT            NOT NULL
43 );
44 CREATE UNIQUE INDEX biblio_record_entry_unique ON biblio.record_entry ( id );
45 CREATE INDEX biblio_record_entry_creator_idx ON biblio.record_entry ( creator );
46 CREATE INDEX biblio_record_entry_create_date_idx ON biblio.record_entry ( create_date );
47 CREATE INDEX biblio_record_entry_editor_idx ON biblio.record_entry ( editor );
48 CREATE INDEX biblio_record_entry_edit_date_idx ON biblio.record_entry ( edit_date );
49 CREATE INDEX biblio_record_entry_fp_idx ON biblio.record_entry ( fingerprint );
50 CREATE UNIQUE INDEX biblio_record_unique_tcn ON biblio.record_entry (tcn_value) WHERE deleted IS FALSE;
51
52 CREATE RULE protect_bib_rec_delete AS ON DELETE TO biblio.record_entry DO INSTEAD UPDATE biblio.record_entry SET deleted = TRUE WHERE OLD.id = biblio.record_entry.id;
53
54
55 CREATE TABLE biblio.record_note (
56         id              BIGSERIAL       PRIMARY KEY,
57         record          BIGINT          NOT NULL,
58         value           TEXT            NOT NULL,
59         creator         INT             NOT NULL DEFAULT 1,
60         editor          INT             NOT NULL DEFAULT 1,
61         pub             BOOL            NOT NULL DEFAULT FALSE,
62         create_date     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT now(),
63         edit_date       TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT now()
64 );
65 CREATE INDEX biblio_record_note_record_idx ON biblio.record_note ( record );
66 CREATE INDEX biblio_record_note_creator_idx ON biblio.record_note ( creator );
67 CREATE INDEX biblio_record_note_editor_idx ON biblio.record_note ( editor );
68
69 COMMIT;