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