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