]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/070.schema.container.sql
LP#1689608: Batch user editing
[working/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                                 REFERENCES asset."copy" (id)
61                                         ON DELETE CASCADE
62                                         ON UPDATE CASCADE
63                                         DEFERRABLE
64                                         INITIALLY DEFERRED,
65     pos         INT,
66         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW()
67 );
68 CREATE INDEX copy_bucket_item_bucket_idx ON container.copy_bucket_item (bucket);
69
70 CREATE TABLE container.copy_bucket_item_note (
71     id      SERIAL      PRIMARY KEY,
72     item    INT         NOT NULL REFERENCES container.copy_bucket_item (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
73     note    TEXT        NOT NULL
74 );
75
76
77
78 CREATE TABLE container.call_number_bucket_type (
79         code    TEXT    PRIMARY KEY,
80         label   TEXT    NOT NULL UNIQUE
81 );
82
83 CREATE TABLE container.call_number_bucket (
84         id      SERIAL  PRIMARY KEY,
85         owner   INT     NOT NULL
86                         REFERENCES actor.usr (id)
87                                 ON DELETE CASCADE
88                                 ON UPDATE CASCADE
89                                 DEFERRABLE
90                                 INITIALLY DEFERRED,
91         name    TEXT    NOT NULL,
92         btype   TEXT    NOT NULL DEFAULT 'misc' REFERENCES container.call_number_bucket_type (code) DEFERRABLE INITIALLY DEFERRED,
93         description TEXT,
94         pub     BOOL    NOT NULL DEFAULT FALSE,
95         owning_lib      INT                             REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
96         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(),
97         CONSTRAINT cnb_name_once_per_owner UNIQUE (owner,name,btype)
98 );
99
100 CREATE TABLE container.call_number_bucket_note (
101     id      SERIAL      PRIMARY KEY,
102     bucket  INT         NOT NULL REFERENCES container.call_number_bucket (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
103     note    TEXT        NOT NULL
104 );
105
106 CREATE TABLE container.call_number_bucket_item (
107         id              SERIAL  PRIMARY KEY,
108         bucket          INT     NOT NULL
109                                 REFERENCES container.call_number_bucket (id)
110                                         ON DELETE CASCADE
111                                         ON UPDATE CASCADE
112                                         DEFERRABLE
113                                         INITIALLY DEFERRED,
114         target_call_number      INT     NOT NULL
115                                 REFERENCES asset.call_number (id)
116                                         ON DELETE CASCADE
117                                         ON UPDATE CASCADE
118                                         DEFERRABLE
119                                         INITIALLY DEFERRED,
120     pos         INT,
121         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW()
122 );
123
124 CREATE TABLE container.call_number_bucket_item_note (
125     id      SERIAL      PRIMARY KEY,
126     item    INT         NOT NULL REFERENCES container.call_number_bucket_item (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
127     note    TEXT        NOT NULL
128 );
129
130
131
132
133 CREATE TABLE container.biblio_record_entry_bucket_type (
134         code    TEXT    PRIMARY KEY,
135         label   TEXT    NOT NULL UNIQUE
136 );
137
138
139 CREATE TABLE container.biblio_record_entry_bucket (
140         id      SERIAL  PRIMARY KEY,
141         owner   INT     NOT NULL
142                         REFERENCES actor.usr (id)
143                                 ON DELETE CASCADE
144                                 ON UPDATE CASCADE
145                                 DEFERRABLE
146                                 INITIALLY DEFERRED,
147         name    TEXT    NOT NULL,
148         btype   TEXT    NOT NULL DEFAULT 'misc' REFERENCES container.biblio_record_entry_bucket_type (code) DEFERRABLE INITIALLY DEFERRED,
149         description TEXT,
150         pub     BOOL    NOT NULL DEFAULT FALSE,
151         owning_lib      INT                             REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
152         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(),
153         CONSTRAINT breb_name_once_per_owner UNIQUE (owner,name,btype)
154 );
155
156 CREATE TABLE container.biblio_record_entry_bucket_note (
157     id      SERIAL      PRIMARY KEY,
158     bucket  INT         NOT NULL REFERENCES container.biblio_record_entry_bucket (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
159     note    TEXT        NOT NULL
160 );
161
162 CREATE TABLE container.biblio_record_entry_bucket_item (
163         id                              SERIAL  PRIMARY KEY,
164         bucket                          INT     NOT NULL
165                                                 REFERENCES container.biblio_record_entry_bucket (id)
166                                                         ON DELETE CASCADE
167                                                         ON UPDATE CASCADE
168                                                         DEFERRABLE
169                                                         INITIALLY DEFERRED,
170         target_biblio_record_entry      BIGINT  NOT NULL
171                                                 REFERENCES biblio.record_entry (id)
172                                                         ON DELETE CASCADE
173                                                         ON UPDATE CASCADE
174                                                         DEFERRABLE
175                                                         INITIALLY DEFERRED,
176     pos         INT,
177         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW()
178 );
179
180 CREATE TABLE container.biblio_record_entry_bucket_item_note (
181     id      SERIAL      PRIMARY KEY,
182     item    INT         NOT NULL REFERENCES container.biblio_record_entry_bucket_item (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
183     note    TEXT        NOT NULL
184 );
185
186
187
188 CREATE TABLE container.user_bucket_type (
189         code    TEXT    PRIMARY KEY,
190         label   TEXT    NOT NULL UNIQUE
191 );
192
193 CREATE TABLE container.user_bucket (
194         id      SERIAL  PRIMARY KEY,
195         owner   INT     NOT NULL
196                         REFERENCES actor.usr (id)
197                                 ON DELETE CASCADE
198                                 ON UPDATE CASCADE
199                                 DEFERRABLE
200                                 INITIALLY DEFERRED,
201         name    TEXT    NOT NULL,
202         btype   TEXT    NOT NULL DEFAULT 'misc' REFERENCES container.user_bucket_type (code) DEFERRABLE INITIALLY DEFERRED,
203         description TEXT,
204         pub     BOOL    NOT NULL DEFAULT FALSE,
205         owning_lib      INT                             REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
206         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(),
207         CONSTRAINT ub_name_once_per_owner UNIQUE (owner,name,btype)
208 );
209
210 CREATE TABLE container.user_bucket_note (
211     id      SERIAL      PRIMARY KEY,
212     bucket  INT         NOT NULL REFERENCES container.user_bucket (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
213     note    TEXT        NOT NULL
214 );
215
216 CREATE TABLE container.user_bucket_item (
217         id              SERIAL  PRIMARY KEY,
218         bucket          INT     NOT NULL
219                                 REFERENCES container.user_bucket (id)
220                                         ON DELETE CASCADE
221                                         ON UPDATE CASCADE
222                                         DEFERRABLE
223                                         INITIALLY DEFERRED,
224         target_user     INT     NOT NULL
225                                 REFERENCES actor.usr (id)
226                                         ON DELETE CASCADE
227                                         ON UPDATE CASCADE
228                                         DEFERRABLE
229                                         INITIALLY DEFERRED,
230     pos         INT,
231         create_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW()
232 );
233 CREATE INDEX user_bucket_item_target_user_idx ON container.user_bucket_item ( target_user );
234
235 CREATE TABLE container.user_bucket_item_note (
236     id      SERIAL      PRIMARY KEY,
237     item    INT         NOT NULL REFERENCES container.user_bucket_item (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
238     note    TEXT        NOT NULL
239 );
240
241
242 COMMIT;