]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/070.schema.container.sql
LP2042879 Shelving Location Groups Admin accessibility
[Evergreen.git] / Open-ILS / src / sql / Pg / 070.schema.container.sql
1 /*
2  * Copyright (C) 2004-2008  Georgia Public Library Service
3  * Copyright (C) 2007-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 IF EXISTS container CASCADE;
19
20 BEGIN;
21 CREATE SCHEMA container;
22
23 CREATE TABLE container.copy_bucket_type (
24         code    TEXT    PRIMARY KEY,
25         label   TEXT    NOT NULL UNIQUE
26 );
27
28 CREATE TABLE container.copy_bucket (
29         id              SERIAL                          PRIMARY KEY,
30         owner           INT                             NOT NULL
31                                                         REFERENCES actor.usr (id)
32                                                                 ON DELETE CASCADE
33                                                                 ON UPDATE CASCADE
34                                                                 DEFERRABLE
35                                                                 INITIALLY DEFERRED,
36         name            TEXT                            NOT NULL,
37         btype           TEXT                            NOT NULL DEFAULT 'misc' REFERENCES container.copy_bucket_type (code) DEFERRABLE INITIALLY DEFERRED,
38         description TEXT,
39         pub             BOOL                            NOT NULL DEFAULT FALSE,
40         owning_lib      INT                             REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
41         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(),
42         CONSTRAINT cb_name_once_per_owner UNIQUE (owner,name,btype)
43 );
44
45 CREATE TABLE container.copy_bucket_note (
46     id      SERIAL      PRIMARY KEY,
47     bucket  INT         NOT NULL REFERENCES container.copy_bucket (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
48     note    TEXT        NOT NULL
49 );
50
51 CREATE TABLE container.copy_bucket_item (
52         id              SERIAL  PRIMARY KEY,
53         bucket          INT     NOT NULL
54                                 REFERENCES container.copy_bucket (id)
55                                         ON DELETE CASCADE
56                                         ON UPDATE CASCADE
57                                         DEFERRABLE
58                                         INITIALLY DEFERRED,
59         target_copy     INT     NOT NULL,
60     pos         INT,
61         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW()
62 );
63 CREATE INDEX copy_bucket_item_bucket_idx ON container.copy_bucket_item (bucket);
64
65 CREATE OR REPLACE FUNCTION evergreen.container_copy_bucket_item_target_copy_inh_fkey() RETURNS TRIGGER AS $f$
66 BEGIN
67         PERFORM 1 FROM asset.copy WHERE id = NEW.target_copy;
68         IF NOT FOUND THEN
69                 RAISE foreign_key_violation USING MESSAGE = FORMAT(
70                         $$Referenced asset.copy id not found, target_copy:%s$$, NEW.target_copy
71                 );
72         END IF;
73         RETURN NEW;
74 END;
75 $f$ LANGUAGE PLPGSQL VOLATILE COST 50;
76
77 CREATE CONSTRAINT TRIGGER inherit_copy_bucket_item_target_copy_fkey
78         AFTER UPDATE OR INSERT ON container.copy_bucket_item
79         DEFERRABLE FOR EACH ROW EXECUTE PROCEDURE evergreen.container_copy_bucket_item_target_copy_inh_fkey();
80
81
82 CREATE TABLE container.copy_bucket_item_note (
83     id      SERIAL      PRIMARY KEY,
84     item    INT         NOT NULL REFERENCES container.copy_bucket_item (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
85     note    TEXT        NOT NULL
86 );
87
88
89
90 CREATE TABLE container.call_number_bucket_type (
91         code    TEXT    PRIMARY KEY,
92         label   TEXT    NOT NULL UNIQUE
93 );
94
95 CREATE TABLE container.call_number_bucket (
96         id      SERIAL  PRIMARY KEY,
97         owner   INT     NOT NULL
98                         REFERENCES actor.usr (id)
99                                 ON DELETE CASCADE
100                                 ON UPDATE CASCADE
101                                 DEFERRABLE
102                                 INITIALLY DEFERRED,
103         name    TEXT    NOT NULL,
104         btype   TEXT    NOT NULL DEFAULT 'misc' REFERENCES container.call_number_bucket_type (code) DEFERRABLE INITIALLY DEFERRED,
105         description TEXT,
106         pub     BOOL    NOT NULL DEFAULT FALSE,
107         owning_lib      INT                             REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
108         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(),
109         CONSTRAINT cnb_name_once_per_owner UNIQUE (owner,name,btype)
110 );
111
112 CREATE TABLE container.call_number_bucket_note (
113     id      SERIAL      PRIMARY KEY,
114     bucket  INT         NOT NULL REFERENCES container.call_number_bucket (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
115     note    TEXT        NOT NULL
116 );
117
118 CREATE TABLE container.call_number_bucket_item (
119         id              SERIAL  PRIMARY KEY,
120         bucket          INT     NOT NULL
121                                 REFERENCES container.call_number_bucket (id)
122                                         ON DELETE CASCADE
123                                         ON UPDATE CASCADE
124                                         DEFERRABLE
125                                         INITIALLY DEFERRED,
126         target_call_number      INT     NOT NULL
127                                 REFERENCES asset.call_number (id)
128                                         ON DELETE CASCADE
129                                         ON UPDATE CASCADE
130                                         DEFERRABLE
131                                         INITIALLY DEFERRED,
132     pos         INT,
133         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW()
134 );
135
136 CREATE TABLE container.call_number_bucket_item_note (
137     id      SERIAL      PRIMARY KEY,
138     item    INT         NOT NULL REFERENCES container.call_number_bucket_item (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
139     note    TEXT        NOT NULL
140 );
141
142
143
144
145 CREATE TABLE container.biblio_record_entry_bucket_type (
146         code    TEXT    PRIMARY KEY,
147         label   TEXT    NOT NULL UNIQUE
148 );
149
150
151 CREATE TABLE container.biblio_record_entry_bucket (
152         id      SERIAL  PRIMARY KEY,
153         owner   INT     NOT NULL
154                         REFERENCES actor.usr (id)
155                                 ON DELETE CASCADE
156                                 ON UPDATE CASCADE
157                                 DEFERRABLE
158                                 INITIALLY DEFERRED,
159         name    TEXT    NOT NULL,
160         btype   TEXT    NOT NULL DEFAULT 'misc' REFERENCES container.biblio_record_entry_bucket_type (code) DEFERRABLE INITIALLY DEFERRED,
161         description TEXT,
162         pub     BOOL    NOT NULL DEFAULT FALSE,
163         owning_lib      INT                             REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
164         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(),
165         CONSTRAINT breb_name_once_per_owner UNIQUE (owner,name,btype)
166 );
167
168 CREATE TABLE container.biblio_record_entry_bucket_note (
169     id      SERIAL      PRIMARY KEY,
170     bucket  INT         NOT NULL REFERENCES container.biblio_record_entry_bucket (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
171     note    TEXT        NOT NULL
172 );
173
174 CREATE TABLE container.biblio_record_entry_bucket_item (
175         id                              SERIAL  PRIMARY KEY,
176         bucket                          INT     NOT NULL
177                                                 REFERENCES container.biblio_record_entry_bucket (id)
178                                                         ON DELETE CASCADE
179                                                         ON UPDATE CASCADE
180                                                         DEFERRABLE
181                                                         INITIALLY DEFERRED,
182         target_biblio_record_entry      BIGINT  NOT NULL
183                                                 REFERENCES biblio.record_entry (id)
184                                                         ON DELETE CASCADE
185                                                         ON UPDATE CASCADE
186                                                         DEFERRABLE
187                                                         INITIALLY DEFERRED,
188     pos         INT,
189         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW()
190 );
191
192 CREATE TABLE container.biblio_record_entry_bucket_item_note (
193     id      SERIAL      PRIMARY KEY,
194     item    INT         NOT NULL REFERENCES container.biblio_record_entry_bucket_item (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
195     note    TEXT        NOT NULL
196 );
197
198
199
200 CREATE TABLE container.user_bucket_type (
201         code    TEXT    PRIMARY KEY,
202         label   TEXT    NOT NULL UNIQUE
203 );
204
205 CREATE TABLE container.user_bucket (
206         id      SERIAL  PRIMARY KEY,
207         owner   INT     NOT NULL
208                         REFERENCES actor.usr (id)
209                                 ON DELETE CASCADE
210                                 ON UPDATE CASCADE
211                                 DEFERRABLE
212                                 INITIALLY DEFERRED,
213         name    TEXT    NOT NULL,
214         btype   TEXT    NOT NULL DEFAULT 'misc' REFERENCES container.user_bucket_type (code) DEFERRABLE INITIALLY DEFERRED,
215         description TEXT,
216         pub     BOOL    NOT NULL DEFAULT FALSE,
217         owning_lib      INT                             REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
218         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(),
219         CONSTRAINT ub_name_once_per_owner UNIQUE (owner,name,btype)
220 );
221
222 CREATE TABLE container.user_bucket_note (
223     id      SERIAL      PRIMARY KEY,
224     bucket  INT         NOT NULL REFERENCES container.user_bucket (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
225     note    TEXT        NOT NULL
226 );
227
228 CREATE TABLE container.user_bucket_item (
229         id              SERIAL  PRIMARY KEY,
230         bucket          INT     NOT NULL
231                                 REFERENCES container.user_bucket (id)
232                                         ON DELETE CASCADE
233                                         ON UPDATE CASCADE
234                                         DEFERRABLE
235                                         INITIALLY DEFERRED,
236         target_user     INT     NOT NULL
237                                 REFERENCES actor.usr (id)
238                                         ON DELETE CASCADE
239                                         ON UPDATE CASCADE
240                                         DEFERRABLE
241                                         INITIALLY DEFERRED,
242     pos         INT,
243         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW()
244 );
245 CREATE INDEX user_bucket_item_target_user_idx ON container.user_bucket_item ( target_user );
246
247 CREATE TABLE container.user_bucket_item_note (
248     id      SERIAL      PRIMARY KEY,
249     item    INT         NOT NULL REFERENCES container.user_bucket_item (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
250     note    TEXT        NOT NULL
251 );
252
253 CREATE TABLE container.carousel (
254     id                      SERIAL PRIMARY KEY,
255     type                    INTEGER NOT NULL REFERENCES config.carousel_type (id),
256     owner                   INTEGER NOT NULL REFERENCES actor.org_unit (id),
257     name                    TEXT NOT NULL,
258     bucket                  INTEGER REFERENCES container.biblio_record_entry_bucket (id),
259     creator                 INTEGER NOT NULL REFERENCES actor.usr (id),
260     editor                  INTEGER NOT NULL REFERENCES actor.usr (id),
261     create_time             TIMESTAMPTZ NOT NULL DEFAULT now(),
262     edit_time               TIMESTAMPTZ NOT NULL DEFAULT now(),
263     age_filter              INTERVAL,
264     owning_lib_filter       INT[],
265     copy_location_filter    INT[],
266     last_refresh_time       TIMESTAMPTZ,
267     active                  BOOLEAN NOT NULL DEFAULT TRUE,
268     max_items               INTEGER NOT NULL
269 );
270
271 CREATE TABLE container.carousel_org_unit (
272     id              SERIAL PRIMARY KEY,
273     carousel        INTEGER NOT NULL REFERENCES container.carousel (id) ON DELETE CASCADE,
274     override_name   TEXT,
275     org_unit        INTEGER NOT NULL REFERENCES actor.org_unit (id),
276     seq             INTEGER NOT NULL
277 );
278
279 COMMIT;