1 DROP SCHEMA actor CASCADE;
5 COMMENT ON SCHEMA actor IS $$
7 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
8 * Mike Rylander <mrylander@gmail.com>
12 * Holds all tables pertaining to users and libraries (org units).
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
28 CREATE TABLE actor.usr (
29 id SERIAL PRIMARY KEY,
30 card INT UNIQUE, -- active card
31 profile INT NOT NULL, -- patron profile
32 usrname TEXT NOT NULL UNIQUE,
35 standing INT NOT NULL DEFAULT 1 REFERENCES config.standing (id) DEFERRABLE INITIALLY DEFERRED,
36 ident_type INT NOT NULL REFERENCES config.identification_type (id) DEFERRABLE INITIALLY DEFERRED,
38 ident_type2 INT REFERENCES config.identification_type (id) DEFERRABLE INITIALLY DEFERRED,
40 net_access_level INT NOT NULL DEFAULT 1 REFERENCES config.net_access_level (id) DEFERRABLE INITIALLY DEFERRED,
43 first_given_name TEXT NOT NULL,
44 second_given_name TEXT,
45 family_name TEXT NOT NULL,
54 dob TIMESTAMP WITH TIME ZONE,
55 active BOOL NOT NULL DEFAULT TRUE,
56 master_account BOOL NOT NULL DEFAULT FALSE,
57 super_user BOOL NOT NULL DEFAULT FALSE,
58 barred BOOL NOT NULL DEFAULT FALSE,
59 deleted BOOL NOT NULL DEFAULT FALSE,
60 juvenile BOOL NOT NULL DEFAULT FALSE,
61 usrgroup SERIAL NOT NULL,
62 claims_returned_count INT NOT NULL DEFAULT 0,
63 credit_forward_balance NUMERIC(6,2) NOT NULL DEFAULT 0.00,
64 last_xact_id TEXT NOT NULL DEFAULT 'none',
66 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
67 expire_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT (now() + '3 years'::INTERVAL)
69 COMMENT ON TABLE actor.usr IS $$
71 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
72 * Mike Rylander <mrylander@gmail.com>
76 * This table contains the core User objects that describe both
77 * staff members and patrons. The difference between the two
78 * types of users is based on the user's permissions.
82 * This program is free software; you can redistribute it and/or
83 * modify it under the terms of the GNU General Public License
84 * as published by the Free Software Foundation; either version 2
85 * of the License, or (at your option) any later version.
87 * This program is distributed in the hope that it will be useful,
88 * but WITHOUT ANY WARRANTY; without even the implied warranty of
89 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90 * GNU General Public License for more details.
94 CREATE INDEX actor_usr_home_ou_idx ON actor.usr (home_ou);
95 CREATE INDEX actor_usr_mailing_address_idx ON actor.usr (mailing_address);
96 CREATE INDEX actor_usr_billing_address_idx ON actor.usr (billing_address);
98 CREATE INDEX actor_usr_first_given_name_idx ON actor.usr (lower(first_given_name));
99 CREATE INDEX actor_usr_second_given_name_idx ON actor.usr (lower(second_given_name));
100 CREATE INDEX actor_usr_family_name_idx ON actor.usr (lower(family_name));
102 CREATE INDEX actor_usr_email_idx ON actor.usr (lower(email));
104 CREATE INDEX actor_usr_day_phone_idx ON actor.usr (lower(day_phone));
105 CREATE INDEX actor_usr_evening_phone_idx ON actor.usr (lower(evening_phone));
106 CREATE INDEX actor_usr_other_phone_idx ON actor.usr (lower(other_phone));
108 CREATE INDEX actor_usr_ident_value_idx ON actor.usr (lower(ident_value));
109 CREATE INDEX actor_usr_ident_value2_idx ON actor.usr (lower(ident_value2));
111 CREATE FUNCTION actor.crypt_pw_insert () RETURNS TRIGGER AS $$
113 NEW.passwd = MD5( NEW.passwd );
118 CREATE FUNCTION actor.crypt_pw_update () RETURNS TRIGGER AS $$
120 IF NEW.passwd <> OLD.passwd THEN
121 NEW.passwd = MD5( NEW.passwd );
127 CREATE TRIGGER actor_crypt_pw_update_trigger
128 BEFORE UPDATE ON actor.usr FOR EACH ROW
129 EXECUTE PROCEDURE actor.crypt_pw_update ();
131 CREATE TRIGGER actor_crypt_pw_insert_trigger
132 BEFORE INSERT ON actor.usr FOR EACH ROW
133 EXECUTE PROCEDURE actor.crypt_pw_insert ();
135 CREATE RULE protect_user_delete AS ON DELETE TO actor.usr DO INSTEAD UPDATE actor.usr SET deleted = TRUE WHERE OLD.id = actor.usr.id;
137 CREATE TABLE actor.usr_note (
138 id BIGSERIAL PRIMARY KEY,
139 usr BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
140 creator BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
141 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
142 pub BOOL NOT NULL DEFAULT FALSE,
146 CREATE INDEX actor_usr_note_usr_idx ON actor.usr_note (usr);
148 CREATE TABLE actor.usr_setting (
149 id BIGSERIAL PRIMARY KEY,
150 usr INT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
153 CONSTRAINT usr_once_per_key UNIQUE (usr,name)
155 COMMENT ON TABLE actor.usr_setting IS $$
157 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
158 * Mike Rylander <mrylander@gmail.com>
162 * This table contains any arbitrary settings that a client
163 * program would like to save for a user.
167 * This program is free software; you can redistribute it and/or
168 * modify it under the terms of the GNU General Public License
169 * as published by the Free Software Foundation; either version 2
170 * of the License, or (at your option) any later version.
172 * This program is distributed in the hope that it will be useful,
173 * but WITHOUT ANY WARRANTY; without even the implied warranty of
174 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
175 * GNU General Public License for more details.
179 CREATE INDEX actor_usr_setting_usr_idx ON actor.usr_setting (usr);
182 CREATE TABLE actor.stat_cat (
183 id SERIAL PRIMARY KEY,
186 opac_visible BOOL NOT NULL DEFAULT FALSE,
187 CONSTRAINT sc_once_per_owner UNIQUE (owner,name)
189 COMMENT ON TABLE actor.stat_cat IS $$
191 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
192 * Mike Rylander <mrylander@gmail.com>
194 * User Statistical Catagories
196 * Local data collected about Users is placed into a Statistical
197 * Catagory. Here's where those catagories are defined.
201 * This program is free software; you can redistribute it and/or
202 * modify it under the terms of the GNU General Public License
203 * as published by the Free Software Foundation; either version 2
204 * of the License, or (at your option) any later version.
206 * This program is distributed in the hope that it will be useful,
207 * but WITHOUT ANY WARRANTY; without even the implied warranty of
208 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
209 * GNU General Public License for more details.
214 CREATE TABLE actor.stat_cat_entry (
215 id SERIAL PRIMARY KEY,
216 stat_cat INT NOT NULL,
219 CONSTRAINT sce_once_per_owner UNIQUE (stat_cat,owner,value)
221 COMMENT ON TABLE actor.stat_cat_entry IS $$
223 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
224 * Mike Rylander <mrylander@gmail.com>
226 * User Statistical Catagory Entries
228 * Local data collected about Users is placed into a Statistical
229 * Catagory. Each library can create entries into any of its own
230 * stat_cats, its ancestors' stat_cats, or its descendants' stat_cats.
235 * This program is free software; you can redistribute it and/or
236 * modify it under the terms of the GNU General Public License
237 * as published by the Free Software Foundation; either version 2
238 * of the License, or (at your option) any later version.
240 * This program is distributed in the hope that it will be useful,
241 * but WITHOUT ANY WARRANTY; without even the implied warranty of
242 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
243 * GNU General Public License for more details.
248 CREATE TABLE actor.stat_cat_entry_usr_map (
249 id BIGSERIAL PRIMARY KEY,
250 stat_cat_entry TEXT NOT NULL,
251 stat_cat INT NOT NULL,
252 target_usr INT NOT NULL,
253 CONSTRAINT sc_once_per_usr UNIQUE (target_usr,stat_cat)
255 COMMENT ON TABLE actor.stat_cat_entry_usr_map IS $$
257 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
258 * Mike Rylander <mrylander@gmail.com>
260 * Statistical Catagory Entry to User map
262 * Records the stat_cat entries for each user.
267 * This program is free software; you can redistribute it and/or
268 * modify it under the terms of the GNU General Public License
269 * as published by the Free Software Foundation; either version 2
270 * of the License, or (at your option) any later version.
272 * This program is distributed in the hope that it will be useful,
273 * but WITHOUT ANY WARRANTY; without even the implied warranty of
274 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
275 * GNU General Public License for more details.
279 CREATE INDEX actor_stat_cat_entry_usr_idx ON actor.stat_cat_entry_usr_map (target_usr);
281 CREATE TABLE actor.card (
282 id SERIAL PRIMARY KEY,
283 usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
284 barcode TEXT NOT NULL UNIQUE,
285 active BOOL NOT NULL DEFAULT TRUE
287 COMMENT ON TABLE actor.card IS $$
289 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
290 * Mike Rylander <mrylander@gmail.com>
294 * Each User has one or more library cards. The current "main"
295 * card is linked to here from the actor.usr table, and it is up
296 * to the consortium policy whether more than one card can be
297 * active for any one user at a given time.
302 * This program is free software; you can redistribute it and/or
303 * modify it under the terms of the GNU General Public License
304 * as published by the Free Software Foundation; either version 2
305 * of the License, or (at your option) any later version.
307 * This program is distributed in the hope that it will be useful,
308 * but WITHOUT ANY WARRANTY; without even the implied warranty of
309 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
310 * GNU General Public License for more details.
314 CREATE INDEX actor_card_usr_idx ON actor.card (usr);
316 CREATE TABLE actor.org_unit_type (
317 id SERIAL PRIMARY KEY,
319 opac_label TEXT NOT NULL,
321 parent INT REFERENCES actor.org_unit_type (id) DEFERRABLE INITIALLY DEFERRED,
322 can_have_vols BOOL NOT NULL DEFAULT TRUE,
323 can_have_users BOOL NOT NULL DEFAULT TRUE
325 CREATE INDEX actor_org_unit_type_parent_idx ON actor.org_unit_type (parent);
327 CREATE TABLE actor.org_unit (
328 id SERIAL PRIMARY KEY,
329 parent_ou INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
330 ou_type INT NOT NULL REFERENCES actor.org_unit_type (id) DEFERRABLE INITIALLY DEFERRED,
335 shortname TEXT NOT NULL,
339 opac_visible BOOL NOT NULL DEFAULT TRUE
341 CREATE INDEX actor_org_unit_parent_ou_idx ON actor.org_unit (parent_ou);
342 CREATE INDEX actor_org_unit_ou_type_idx ON actor.org_unit (ou_type);
343 CREATE INDEX actor_org_unit_ill_address_idx ON actor.org_unit (ill_address);
344 CREATE INDEX actor_org_unit_billing_address_idx ON actor.org_unit (billing_address);
345 CREATE INDEX actor_org_unit_mailing_address_idx ON actor.org_unit (mailing_address);
346 CREATE INDEX actor_org_unit_holds_address_idx ON actor.org_unit (holds_address);
348 CREATE TABLE actor.org_lasso (
349 id SERIAL PRIMARY KEY,
353 CREATE TABLE actor.org_lasso_map (
354 id SERIAL PRIMARY KEY,
355 lasso INT NOT NULL REFERENCES actor.org_lasso (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
356 org_unit INT NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
358 CREATE UNIQUE INDEX ou_lasso_lasso_ou_idx ON actor.org_lasso_map (lasso, org_unit);
359 CREATE INDEX ou_lasso_org_unit_idx ON actor.org_lasso_map (org_unit);
361 CREATE TABLE actor.org_unit_proximity (
362 id BIGSERIAL PRIMARY KEY,
367 CREATE INDEX from_prox_idx ON actor.org_unit_proximity (from_org);
369 CREATE TABLE actor.hours_of_operation (
370 id INT PRIMARY KEY REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
371 dow_0_open TIME NOT NULL DEFAULT '09:00',
372 dow_0_close TIME NOT NULL DEFAULT '17:00',
373 dow_1_open TIME NOT NULL DEFAULT '09:00',
374 dow_1_close TIME NOT NULL DEFAULT '17:00',
375 dow_2_open TIME NOT NULL DEFAULT '09:00',
376 dow_2_close TIME NOT NULL DEFAULT '17:00',
377 dow_3_open TIME NOT NULL DEFAULT '09:00',
378 dow_3_close TIME NOT NULL DEFAULT '17:00',
379 dow_4_open TIME NOT NULL DEFAULT '09:00',
380 dow_4_close TIME NOT NULL DEFAULT '17:00',
381 dow_5_open TIME NOT NULL DEFAULT '09:00',
382 dow_5_close TIME NOT NULL DEFAULT '17:00',
383 dow_6_open TIME NOT NULL DEFAULT '09:00',
384 dow_6_close TIME NOT NULL DEFAULT '17:00'
387 CREATE TABLE actor.org_unit_closed (
388 id SERIAL PRIMARY KEY,
389 org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
390 close_start TIMESTAMP WITH TIME ZONE NOT NULL,
391 close_end TIMESTAMP WITH TIME ZONE NOT NULL,
395 -- Workstation registration...
396 CREATE TABLE actor.workstation (
397 id SERIAL PRIMARY KEY,
398 name TEXT NOT NULL UNIQUE,
399 owning_lib INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED
402 CREATE TABLE actor.usr_org_unit_opt_in (
403 id SERIAL PRIMARY KEY,
404 org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
405 usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
406 staff INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
407 opt_in_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
408 opt_in_ws INT NOT NULL REFERENCES actor.workstation (id) DEFERRABLE INITIALLY DEFERRED,
409 CONSTRAINT usr_opt_in_once_per_org_unit UNIQUE (usr,org_unit)
412 CREATE TABLE actor.org_unit_setting (
413 id BIGSERIAL PRIMARY KEY,
414 org_unit INT NOT NULL REFERENCES actor.org_unit ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
417 CONSTRAINT ou_once_per_key UNIQUE (org_unit,name)
419 COMMENT ON TABLE actor.org_unit_setting IS $$
421 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
422 * Mike Rylander <mrylander@gmail.com>
426 * This table contains any arbitrary settings that a client
427 * program would like to save for an org unit.
431 * This program is free software; you can redistribute it and/or
432 * modify it under the terms of the GNU General Public License
433 * as published by the Free Software Foundation; either version 2
434 * of the License, or (at your option) any later version.
436 * This program is distributed in the hope that it will be useful,
437 * but WITHOUT ANY WARRANTY; without even the implied warranty of
438 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
439 * GNU General Public License for more details.
443 CREATE INDEX actor_org_unit_setting_usr_idx ON actor.org_unit_setting (org_unit);
446 CREATE TABLE actor.usr_address (
447 id SERIAL PRIMARY KEY,
448 valid BOOL NOT NULL DEFAULT TRUE,
449 within_city_limits BOOL NOT NULL DEFAULT TRUE,
450 address_type TEXT NOT NULL DEFAULT 'MAILING',
451 usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
452 street1 TEXT NOT NULL,
457 country TEXT NOT NULL,
458 post_code TEXT NOT NULL,
459 replaces INT REFERENCES actor.usr_address (id) DEFERRABLE INITIALLY DEFERRED
462 CREATE INDEX actor_usr_addr_usr_idx ON actor.usr_address (usr);
464 CREATE INDEX actor_usr_addr_street1_idx ON actor.usr_address (lower(street1));
465 CREATE INDEX actor_usr_addr_street2_idx ON actor.usr_address (lower(street2));
467 CREATE INDEX actor_usr_addr_city_idx ON actor.usr_address (lower(city));
468 CREATE INDEX actor_usr_addr_state_idx ON actor.usr_address (lower(state));
469 CREATE INDEX actor_usr_addr_post_code_idx ON actor.usr_address (lower(post_code));
472 CREATE TABLE actor.org_address (
473 id SERIAL PRIMARY KEY,
474 valid BOOL NOT NULL DEFAULT TRUE,
475 address_type TEXT NOT NULL DEFAULT 'MAILING',
476 org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
477 street1 TEXT NOT NULL,
482 country TEXT NOT NULL,
483 post_code TEXT NOT NULL
486 CREATE INDEX actor_org_address_org_unit_idx ON actor.org_address (org_unit);
488 CREATE OR REPLACE FUNCTION public.first5 ( TEXT ) RETURNS TEXT AS $$
489 SELECT SUBSTRING( $1, 1, 5);
492 CREATE TABLE actor.usr_standing_penalty (
493 id SERIAL PRIMARY KEY,
494 org_unit INT NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
495 usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
496 standing_penalty INT NOT NULL REFERENCES config.standing_penalty (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
497 staff INT REFERENCES actor.usr (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
498 set_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
501 COMMENT ON TABLE actor.usr_standing_penalty IS $$
503 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
504 * Mike Rylander <mrylander@gmail.com>
506 * User standing penalties
510 * This program is free software; you can redistribute it and/or
511 * modify it under the terms of the GNU General Public License
512 * as published by the Free Software Foundation; either version 2
513 * of the License, or (at your option) any later version.
515 * This program is distributed in the hope that it will be useful,
516 * but WITHOUT ANY WARRANTY; without even the implied warranty of
517 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
518 * GNU General Public License for more details.
522 CREATE INDEX actor_usr_standing_penalty_usr_idx ON actor.usr_standing_penalty (usr);