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 usrgroup SERIAL NOT NULL,
61 claims_returned_count INT NOT NULL DEFAULT 0,
62 credit_forward_balance NUMERIC(6,2) NOT NULL DEFAULT 0.00,
63 last_xact_id TEXT NOT NULL DEFAULT 'none',
65 create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
66 expire_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT (now() + '3 years'::INTERVAL)
68 COMMENT ON TABLE actor.usr IS $$
70 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
71 * Mike Rylander <mrylander@gmail.com>
75 * This table contains the core User objects that describe both
76 * staff members and patrons. The difference between the two
77 * types of users is based on the user's permissions.
81 * This program is free software; you can redistribute it and/or
82 * modify it under the terms of the GNU General Public License
83 * as published by the Free Software Foundation; either version 2
84 * of the License, or (at your option) any later version.
86 * This program is distributed in the hope that it will be useful,
87 * but WITHOUT ANY WARRANTY; without even the implied warranty of
88 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89 * GNU General Public License for more details.
93 CREATE INDEX actor_usr_home_ou_idx ON actor.usr (home_ou);
94 CREATE INDEX actor_usr_mailing_address_idx ON actor.usr (mailing_address);
95 CREATE INDEX actor_usr_billing_address_idx ON actor.usr (billing_address);
97 CREATE INDEX actor_usr_first_given_name_idx ON actor.usr (lower(first_given_name));
98 CREATE INDEX actor_usr_second_given_name_idx ON actor.usr (lower(second_given_name));
99 CREATE INDEX actor_usr_family_name_idx ON actor.usr (lower(family_name));
101 CREATE INDEX actor_usr_email_idx ON actor.usr (lower(email));
103 CREATE INDEX actor_usr_day_phone_idx ON actor.usr (lower(day_phone));
104 CREATE INDEX actor_usr_evening_phone_idx ON actor.usr (lower(evening_phone));
105 CREATE INDEX actor_usr_other_phone_idx ON actor.usr (lower(other_phone));
107 CREATE INDEX actor_usr_ident_value_idx ON actor.usr (lower(ident_value));
108 CREATE INDEX actor_usr_ident_value2_idx ON actor.usr (lower(ident_value2));
110 CREATE FUNCTION actor.crypt_pw_insert () RETURNS TRIGGER AS $$
112 NEW.passwd = MD5( NEW.passwd );
117 CREATE FUNCTION actor.crypt_pw_update () RETURNS TRIGGER AS $$
119 IF NEW.passwd <> OLD.passwd THEN
120 NEW.passwd = MD5( NEW.passwd );
126 CREATE TRIGGER actor_crypt_pw_update_trigger
127 BEFORE UPDATE ON actor.usr FOR EACH ROW
128 EXECUTE PROCEDURE actor.crypt_pw_update ();
130 CREATE TRIGGER actor_crypt_pw_insert_trigger
131 BEFORE INSERT ON actor.usr FOR EACH ROW
132 EXECUTE PROCEDURE actor.crypt_pw_insert ();
134 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;
136 CREATE TABLE actor.usr_note (
137 id BIGSERIAL PRIMARY KEY,
138 usr BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
139 creator BIGINT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
140 create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
141 pub BOOL NOT NULL DEFAULT FALSE,
145 CREATE INDEX actor_usr_note_usr_idx ON actor.usr_note (usr);
147 CREATE TABLE actor.usr_standing_penalty (
148 id SERIAL PRIMARY KEY,
149 usr INT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
150 penalty_type TEXT NOT NULL
152 COMMENT ON TABLE actor.usr_standing_penalty IS $$
154 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
155 * Mike Rylander <mrylander@gmail.com>
157 * User standing penalties
161 * This program is free software; you can redistribute it and/or
162 * modify it under the terms of the GNU General Public License
163 * as published by the Free Software Foundation; either version 2
164 * of the License, or (at your option) any later version.
166 * This program is distributed in the hope that it will be useful,
167 * but WITHOUT ANY WARRANTY; without even the implied warranty of
168 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169 * GNU General Public License for more details.
173 CREATE INDEX actor_usr_standing_penalty_usr_idx ON actor.usr_standing_penalty (usr);
175 CREATE TABLE actor.usr_setting (
176 id BIGSERIAL PRIMARY KEY,
177 usr INT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
180 CONSTRAINT usr_once_per_key UNIQUE (usr,name)
182 COMMENT ON TABLE actor.usr_setting IS $$
184 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
185 * Mike Rylander <mrylander@gmail.com>
189 * This table contains any arbitrary settings that a client
190 * program would like to save for a user.
194 * This program is free software; you can redistribute it and/or
195 * modify it under the terms of the GNU General Public License
196 * as published by the Free Software Foundation; either version 2
197 * of the License, or (at your option) any later version.
199 * This program is distributed in the hope that it will be useful,
200 * but WITHOUT ANY WARRANTY; without even the implied warranty of
201 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
202 * GNU General Public License for more details.
206 CREATE INDEX actor_usr_setting_usr_idx ON actor.usr_setting (usr);
209 CREATE TABLE actor.stat_cat (
210 id SERIAL PRIMARY KEY,
213 opac_visible BOOL NOT NULL DEFAULT FALSE,
214 CONSTRAINT sc_once_per_owner UNIQUE (owner,name)
216 COMMENT ON TABLE actor.stat_cat IS $$
218 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
219 * Mike Rylander <mrylander@gmail.com>
221 * User Statistical Catagories
223 * Local data collected about Users is placed into a Statistical
224 * Catagory. Here's where those catagories are defined.
228 * This program is free software; you can redistribute it and/or
229 * modify it under the terms of the GNU General Public License
230 * as published by the Free Software Foundation; either version 2
231 * of the License, or (at your option) any later version.
233 * This program is distributed in the hope that it will be useful,
234 * but WITHOUT ANY WARRANTY; without even the implied warranty of
235 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
236 * GNU General Public License for more details.
241 CREATE TABLE actor.stat_cat_entry (
242 id SERIAL PRIMARY KEY,
243 stat_cat INT NOT NULL,
246 CONSTRAINT sce_once_per_owner UNIQUE (stat_cat,owner,value)
248 COMMENT ON TABLE actor.stat_cat_entry IS $$
250 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
251 * Mike Rylander <mrylander@gmail.com>
253 * User Statistical Catagory Entries
255 * Local data collected about Users is placed into a Statistical
256 * Catagory. Each library can create entries into any of its own
257 * stat_cats, its ancestors' stat_cats, or its descendants' stat_cats.
262 * This program is free software; you can redistribute it and/or
263 * modify it under the terms of the GNU General Public License
264 * as published by the Free Software Foundation; either version 2
265 * of the License, or (at your option) any later version.
267 * This program is distributed in the hope that it will be useful,
268 * but WITHOUT ANY WARRANTY; without even the implied warranty of
269 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
270 * GNU General Public License for more details.
275 CREATE TABLE actor.stat_cat_entry_usr_map (
276 id BIGSERIAL PRIMARY KEY,
277 stat_cat_entry TEXT NOT NULL,
278 stat_cat INT NOT NULL,
279 target_usr INT NOT NULL,
280 CONSTRAINT sc_once_per_usr UNIQUE (target_usr,stat_cat)
282 COMMENT ON TABLE actor.stat_cat_entry_usr_map IS $$
284 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
285 * Mike Rylander <mrylander@gmail.com>
287 * Statistical Catagory Entry to User map
289 * Records the stat_cat entries for each user.
294 * This program is free software; you can redistribute it and/or
295 * modify it under the terms of the GNU General Public License
296 * as published by the Free Software Foundation; either version 2
297 * of the License, or (at your option) any later version.
299 * This program is distributed in the hope that it will be useful,
300 * but WITHOUT ANY WARRANTY; without even the implied warranty of
301 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
302 * GNU General Public License for more details.
306 CREATE INDEX actor_stat_cat_entry_usr_idx ON actor.stat_cat_entry_usr_map (target_usr);
308 CREATE TABLE actor.card (
309 id SERIAL PRIMARY KEY,
310 usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
311 barcode TEXT NOT NULL UNIQUE,
312 active BOOL NOT NULL DEFAULT TRUE
314 COMMENT ON TABLE actor.card IS $$
316 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
317 * Mike Rylander <mrylander@gmail.com>
321 * Each User has one or more library cards. The current "main"
322 * card is linked to here from the actor.usr table, and it is up
323 * to the consortium policy whether more than one card can be
324 * active for any one user at a given time.
329 * This program is free software; you can redistribute it and/or
330 * modify it under the terms of the GNU General Public License
331 * as published by the Free Software Foundation; either version 2
332 * of the License, or (at your option) any later version.
334 * This program is distributed in the hope that it will be useful,
335 * but WITHOUT ANY WARRANTY; without even the implied warranty of
336 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
337 * GNU General Public License for more details.
341 CREATE INDEX actor_card_usr_idx ON actor.card (usr);
343 CREATE TABLE actor.org_unit_type (
344 id SERIAL PRIMARY KEY,
346 opac_label TEXT NOT NULL,
348 parent INT REFERENCES actor.org_unit_type (id) DEFERRABLE INITIALLY DEFERRED,
349 can_have_vols BOOL NOT NULL DEFAULT TRUE,
350 can_have_users BOOL NOT NULL DEFAULT TRUE
352 CREATE INDEX actor_org_unit_type_parent_idx ON actor.org_unit_type (parent);
354 CREATE TABLE actor.org_unit (
355 id SERIAL PRIMARY KEY,
356 parent_ou INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
357 ou_type INT NOT NULL REFERENCES actor.org_unit_type (id) DEFERRABLE INITIALLY DEFERRED,
362 shortname TEXT NOT NULL,
366 opac_visible BOOL NOT NULL DEFAULT TRUE
368 CREATE INDEX actor_org_unit_parent_ou_idx ON actor.org_unit (parent_ou);
369 CREATE INDEX actor_org_unit_ou_type_idx ON actor.org_unit (ou_type);
370 CREATE INDEX actor_org_unit_ill_address_idx ON actor.org_unit (ill_address);
371 CREATE INDEX actor_org_unit_billing_address_idx ON actor.org_unit (billing_address);
372 CREATE INDEX actor_org_unit_mailing_address_idx ON actor.org_unit (mailing_address);
373 CREATE INDEX actor_org_unit_holds_address_idx ON actor.org_unit (holds_address);
375 CREATE TABLE actor.org_lasso (
376 id SERIAL PRIMARY KEY,
380 CREATE TABLE actor.org_lasso_map (
381 id SERIAL PRIMARY KEY,
382 lasso INT NOT NULL REFERENCES actor.org_lasso (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
383 org_unit INT NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
385 CREATE UNIQUE INDEX ou_lasso_lasso_ou_idx ON actor.org_lasso_map (lasso, org_unit);
386 CREATE INDEX ou_lasso_org_unit_idx ON actor.org_lasso_map (org_unit);
388 CREATE TABLE actor.org_unit_proximity (
389 id BIGSERIAL PRIMARY KEY,
394 CREATE INDEX from_prox_idx ON actor.org_unit_proximity (from_org);
396 CREATE TABLE actor.hours_of_operation (
397 id INT PRIMARY KEY REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
398 dow_0_open TIME NOT NULL DEFAULT '09:00',
399 dow_0_close TIME NOT NULL DEFAULT '17:00',
400 dow_1_open TIME NOT NULL DEFAULT '09:00',
401 dow_1_close TIME NOT NULL DEFAULT '17:00',
402 dow_2_open TIME NOT NULL DEFAULT '09:00',
403 dow_2_close TIME NOT NULL DEFAULT '17:00',
404 dow_3_open TIME NOT NULL DEFAULT '09:00',
405 dow_3_close TIME NOT NULL DEFAULT '17:00',
406 dow_4_open TIME NOT NULL DEFAULT '09:00',
407 dow_4_close TIME NOT NULL DEFAULT '17:00',
408 dow_5_open TIME NOT NULL DEFAULT '09:00',
409 dow_5_close TIME NOT NULL DEFAULT '17:00',
410 dow_6_open TIME NOT NULL DEFAULT '09:00',
411 dow_6_close TIME NOT NULL DEFAULT '17:00'
414 CREATE TABLE actor.org_unit_closed (
415 id SERIAL PRIMARY KEY,
416 org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
417 close_start TIMESTAMP WITH TIME ZONE NOT NULL,
418 close_end TIMESTAMP WITH TIME ZONE NOT NULL,
422 -- Workstation registration...
423 CREATE TABLE actor.workstation (
424 id SERIAL PRIMARY KEY,
425 name TEXT NOT NULL UNIQUE,
426 owning_lib INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED
429 CREATE TABLE actor.usr_org_unit_opt_in (
430 id SERIAL PRIMARY KEY,
431 org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
432 usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
433 staff INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
434 opt_in_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
435 opt_in_ws INT NOT NULL REFERENCES actor.workstation (id) DEFERRABLE INITIALLY DEFERRED,
436 CONSTRAINT usr_opt_in_once_per_org_unit UNIQUE (usr,org_unit)
439 CREATE TABLE actor.org_unit_setting (
440 id BIGSERIAL PRIMARY KEY,
441 org_unit INT NOT NULL REFERENCES actor.org_unit ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
444 CONSTRAINT ou_once_per_key UNIQUE (org_unit,name)
446 COMMENT ON TABLE actor.org_unit_setting IS $$
448 * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service
449 * Mike Rylander <mrylander@gmail.com>
453 * This table contains any arbitrary settings that a client
454 * program would like to save for an org unit.
458 * This program is free software; you can redistribute it and/or
459 * modify it under the terms of the GNU General Public License
460 * as published by the Free Software Foundation; either version 2
461 * of the License, or (at your option) any later version.
463 * This program is distributed in the hope that it will be useful,
464 * but WITHOUT ANY WARRANTY; without even the implied warranty of
465 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
466 * GNU General Public License for more details.
470 CREATE INDEX actor_org_unit_setting_usr_idx ON actor.org_unit_setting (org_unit);
473 CREATE TABLE actor.usr_address (
474 id SERIAL PRIMARY KEY,
475 valid BOOL NOT NULL DEFAULT TRUE,
476 within_city_limits BOOL NOT NULL DEFAULT TRUE,
477 address_type TEXT NOT NULL DEFAULT 'MAILING',
478 usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
479 street1 TEXT NOT NULL,
484 country TEXT NOT NULL,
485 post_code TEXT NOT NULL
488 CREATE INDEX actor_usr_addr_usr_idx ON actor.usr_address (usr);
490 CREATE INDEX actor_usr_addr_street1_idx ON actor.usr_address (lower(street1));
491 CREATE INDEX actor_usr_addr_street2_idx ON actor.usr_address (lower(street2));
493 CREATE INDEX actor_usr_addr_city_idx ON actor.usr_address (lower(city));
494 CREATE INDEX actor_usr_addr_state_idx ON actor.usr_address (lower(state));
495 CREATE INDEX actor_usr_addr_post_code_idx ON actor.usr_address (lower(post_code));
498 CREATE TABLE actor.org_address (
499 id SERIAL PRIMARY KEY,
500 valid BOOL NOT NULL DEFAULT TRUE,
501 address_type TEXT NOT NULL DEFAULT 'MAILING',
502 org_unit INT NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
503 street1 TEXT NOT NULL,
508 country TEXT NOT NULL,
509 post_code TEXT NOT NULL
512 CREATE INDEX actor_org_address_org_unit_idx ON actor.org_address (org_unit);
514 CREATE OR REPLACE FUNCTION public.first5 ( TEXT ) RETURNS TEXT AS $$
515 SELECT SUBSTRING( $1, 1, 5);