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