2 * Copyright (C) 2004-2008 Georgia Public Library Service
3 * Copyright (C) 2008 Equinox Software, Inc.
4 * Mike Rylander <miker@esilibrary.com>
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.
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.
20 DROP SCHEMA stats CASCADE;
21 DROP SCHEMA config CASCADE;
27 COMMENT ON SCHEMA config IS $$
29 * Copyright (C) 2005 Georgia Public Library Service
30 * Mike Rylander <mrylander@gmail.com>
32 * The config schema holds static configuration data for the
33 * Open-ILS installation.
37 * This program is free software; you can redistribute it and/or
38 * modify it under the terms of the GNU General Public License
39 * as published by the Free Software Foundation; either version 2
40 * of the License, or (at your option) any later version.
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
49 CREATE TABLE config.internal_flag (
50 name TEXT PRIMARY KEY,
52 enabled BOOL NOT NULL DEFAULT FALSE
54 INSERT INTO config.internal_flag (name) VALUES ('ingest.metarecord_mapping.skip_on_insert');
55 INSERT INTO config.internal_flag (name) VALUES ('ingest.reingest.force_on_same_marc');
56 INSERT INTO config.internal_flag (name) VALUES ('ingest.reingest.skip_located_uri');
58 CREATE TABLE config.upgrade_log (
59 version TEXT PRIMARY KEY,
60 install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
63 INSERT INTO config.upgrade_log (version) VALUES ('0216'); -- miker
65 CREATE TABLE config.bib_source (
66 id SERIAL PRIMARY KEY,
67 quality INT CHECK ( quality BETWEEN 0 AND 100 ),
68 source TEXT NOT NULL UNIQUE,
69 transcendant BOOL NOT NULL DEFAULT FALSE
71 COMMENT ON TABLE config.bib_source IS $$
73 * Copyright (C) 2005 Georgia Public Library Service
74 * Mike Rylander <mrylander@gmail.com>
76 * Valid sources of MARC records
78 * This is table is used to set up the relative "quality" of each
79 * MARC source, such as OCLC.
83 * This program is free software; you can redistribute it and/or
84 * modify it under the terms of the GNU General Public License
85 * as published by the Free Software Foundation; either version 2
86 * of the License, or (at your option) any later version.
88 * This program is distributed in the hope that it will be useful,
89 * but WITHOUT ANY WARRANTY; without even the implied warranty of
90 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91 * GNU General Public License for more details.
95 CREATE TABLE config.standing (
96 id SERIAL PRIMARY KEY,
97 value TEXT NOT NULL UNIQUE
99 COMMENT ON TABLE config.standing IS $$
101 * Copyright (C) 2005 Georgia Public Library Service
102 * Mike Rylander <mrylander@gmail.com>
106 * This table contains the values that can be applied to a patron
107 * by a staff member. These values should not be changed, other
108 * than for translation, as the ID column is currently a "magic
109 * number" in the source. :(
113 * This program is free software; you can redistribute it and/or
114 * modify it under the terms of the GNU General Public License
115 * as published by the Free Software Foundation; either version 2
116 * of the License, or (at your option) any later version.
118 * This program is distributed in the hope that it will be useful,
119 * but WITHOUT ANY WARRANTY; without even the implied warranty of
120 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
121 * GNU General Public License for more details.
125 CREATE TABLE config.standing_penalty (
126 id SERIAL PRIMARY KEY,
127 name TEXT NOT NULL UNIQUE,
132 INSERT INTO config.standing_penalty (id,name,label,block_list)
133 VALUES (1,'PATRON_EXCEEDS_FINES','Patron exceeds fine threshold','CIRC|HOLD|RENEW');
134 INSERT INTO config.standing_penalty (id,name,label,block_list)
135 VALUES (2,'PATRON_EXCEEDS_OVERDUE_COUNT','Patron exceeds max overdue item threshold','CIRC|HOLD|RENEW');
136 INSERT INTO config.standing_penalty (id,name,label,block_list)
137 VALUES (3,'PATRON_EXCEEDS_CHECKOUT_COUNT','Patron exceeds max checked out item threshold','CIRC');
138 INSERT INTO config.standing_penalty (id,name,label,block_list)
139 VALUES (4,'PATRON_EXCEEDS_COLLECTIONS_WARNING','Patron exceeds pre-collections warning fine threshold','CIRC|HOLD|RENEW');
141 INSERT INTO config.standing_penalty (id,name,label) VALUES (20,'ALERT_NOTE','Alerting Note, no blocks');
142 INSERT INTO config.standing_penalty (id,name,label) VALUES (21,'SILENT_NOTE','Note, no blocks');
143 INSERT INTO config.standing_penalty (id,name,label,block_list) VALUES (22,'STAFF_C','Alerting block on Circ','CIRC');
144 INSERT INTO config.standing_penalty (id,name,label,block_list) VALUES (23,'STAFF_CH','Alerting block on Circ and Hold','CIRC|HOLD');
145 INSERT INTO config.standing_penalty (id,name,label,block_list) VALUES (24,'STAFF_CR','Alerting block on Circ and Renew','CIRC|RENEW');
146 INSERT INTO config.standing_penalty (id,name,label,block_list) VALUES (25,'STAFF_CHR','Alerting block on Circ, Hold and Renew','CIRC|HOLD|RENEW');
147 INSERT INTO config.standing_penalty (id,name,label,block_list) VALUES (26,'STAFF_HR','Alerting block on Hold and Renew','HOLD|RENEW');
148 INSERT INTO config.standing_penalty (id,name,label,block_list) VALUES (27,'STAFF_H','Alerting block on Hold','HOLD');
149 INSERT INTO config.standing_penalty (id,name,label,block_list) VALUES (28,'STAFF_R','Alerting block on Renew','RENEW');
150 INSERT INTO config.standing_penalty (id,name,label) VALUES (29,'INVALID_PATRON_ADDRESS','Patron has an invalid address');
151 INSERT INTO config.standing_penalty (id,name,label) VALUES (30,'PATRON_IN_COLLECTIONS','Patron has been referred to a collections agency');
153 SELECT SETVAL('config.standing_penalty_id_seq', 100);
155 CREATE TABLE config.xml_transform (
156 name TEXT PRIMARY KEY,
157 namespace_uri TEXT NOT NULL,
158 prefix TEXT NOT NULL,
162 CREATE TABLE config.biblio_fingerprint (
163 id SERIAL PRIMARY KEY,
166 first_word BOOL NOT NULL DEFAULT FALSE,
167 format TEXT NOT NULL DEFAULT 'marcxml'
170 INSERT INTO config.biblio_fingerprint (name, xpath, format)
173 '//marc:datafield[@tag="700"]/marc:subfield[@code="t"]|' ||
174 '//marc:datafield[@tag="240"]/marc:subfield[@code="a"]|' ||
175 '//marc:datafield[@tag="242"]/marc:subfield[@code="a"]|' ||
176 '//marc:datafield[@tag="246"]/marc:subfield[@code="a"]|' ||
177 '//marc:datafield[@tag="245"]/marc:subfield[@code="a"]',
181 INSERT INTO config.biblio_fingerprint (name, xpath, format, first_word)
184 '//marc:datafield[@tag="700" and ./*[@code="t"]]/marc:subfield[@code="a"]|'
185 '//marc:datafield[@tag="100"]/marc:subfield[@code="a"]|'
186 '//marc:datafield[@tag="110"]/marc:subfield[@code="a"]|'
187 '//marc:datafield[@tag="111"]/marc:subfield[@code="a"]|'
188 '//marc:datafield[@tag="260"]/marc:subfield[@code="b"]',
193 CREATE TABLE config.metabib_class (
194 name TEXT PRIMARY KEY,
195 label TEXT NOT NULL UNIQUE
198 CREATE TABLE config.metabib_field (
199 id SERIAL PRIMARY KEY,
200 field_class TEXT NOT NULL REFERENCES config.metabib_class (name),
204 weight INT NOT NULL DEFAULT 1,
205 format TEXT NOT NULL DEFAULT 'mods33',
206 search_field BOOL NOT NULL DEFAULT TRUE,
207 facet_field BOOL NOT NULL DEFAULT FALSE
209 COMMENT ON TABLE config.metabib_field IS $$
211 * Copyright (C) 2005 Georgia Public Library Service
212 * Mike Rylander <mrylander@gmail.com>
214 * XPath used for record indexing ingest
216 * This table contains the XPath used to chop up MODS into its
217 * indexable parts. Each XPath entry is named and assigned to
218 * a "class" of either title, subject, author, keyword or series.
223 * This program is free software; you can redistribute it and/or
224 * modify it under the terms of the GNU General Public License
225 * as published by the Free Software Foundation; either version 2
226 * of the License, or (at your option) any later version.
228 * This program is distributed in the hope that it will be useful,
229 * but WITHOUT ANY WARRANTY; without even the implied warranty of
230 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
231 * GNU General Public License for more details.
235 CREATE UNIQUE INDEX config_metabib_field_class_name_idx ON config.metabib_field (field_class, name);
237 CREATE TABLE config.metabib_search_alias (
238 alias TEXT PRIMARY KEY,
239 field_class TEXT NOT NULL REFERENCES config.metabib_class (name),
240 field INT REFERENCES config.metabib_field (id)
243 CREATE TABLE config.non_cataloged_type (
244 id SERIAL PRIMARY KEY,
245 owning_lib INT NOT NULL, -- REFERENCES actor.org_unit (id),
247 circ_duration INTERVAL NOT NULL DEFAULT '14 days'::INTERVAL,
248 in_house BOOL NOT NULL DEFAULT FALSE,
249 CONSTRAINT noncat_once_per_lib UNIQUE (owning_lib,name)
251 COMMENT ON TABLE config.non_cataloged_type IS $$
253 * Copyright (C) 2005 Georgia Public Library Service
254 * Mike Rylander <mrylander@gmail.com>
256 * Types of valid non-cataloged items.
261 * This program is free software; you can redistribute it and/or
262 * modify it under the terms of the GNU General Public License
263 * as published by the Free Software Foundation; either version 2
264 * of the License, or (at your option) any later version.
266 * This program is distributed in the hope that it will be useful,
267 * but WITHOUT ANY WARRANTY; without even the implied warranty of
268 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
269 * GNU General Public License for more details.
273 CREATE TABLE config.identification_type (
274 id SERIAL PRIMARY KEY,
275 name TEXT NOT NULL UNIQUE
277 COMMENT ON TABLE config.identification_type IS $$
279 * Copyright (C) 2005 Georgia Public Library Service
280 * Mike Rylander <mrylander@gmail.com>
282 * Types of valid patron identification.
284 * Each patron must display at least one valid form of identification
285 * in order to get a library card. This table lists those forms.
290 * This program is free software; you can redistribute it and/or
291 * modify it under the terms of the GNU General Public License
292 * as published by the Free Software Foundation; either version 2
293 * of the License, or (at your option) any later version.
295 * This program is distributed in the hope that it will be useful,
296 * but WITHOUT ANY WARRANTY; without even the implied warranty of
297 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
298 * GNU General Public License for more details.
302 CREATE TABLE config.rule_circ_duration (
303 id SERIAL PRIMARY KEY,
304 name TEXT NOT NULL UNIQUE CHECK ( name ~ E'^\\w+$' ),
305 extended INTERVAL NOT NULL,
306 normal INTERVAL NOT NULL,
307 shrt INTERVAL NOT NULL,
308 max_renewals INT NOT NULL
310 COMMENT ON TABLE config.rule_circ_duration IS $$
312 * Copyright (C) 2005 Georgia Public Library Service
313 * Mike Rylander <mrylander@gmail.com>
315 * Circulation Duration rules
317 * Each circulation is given a duration based on one of these rules.
322 * This program is free software; you can redistribute it and/or
323 * modify it under the terms of the GNU General Public License
324 * as published by the Free Software Foundation; either version 2
325 * of the License, or (at your option) any later version.
327 * This program is distributed in the hope that it will be useful,
328 * but WITHOUT ANY WARRANTY; without even the implied warranty of
329 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
330 * GNU General Public License for more details.
334 CREATE TABLE config.rule_max_fine (
335 id SERIAL PRIMARY KEY,
336 name TEXT NOT NULL UNIQUE CHECK ( name ~ E'^\\w+$' ),
337 amount NUMERIC(6,2) NOT NULL,
338 is_percent BOOL NOT NULL DEFAULT FALSE
340 COMMENT ON TABLE config.rule_max_fine IS $$
342 * Copyright (C) 2005 Georgia Public Library Service
343 * Mike Rylander <mrylander@gmail.com>
345 * Circulation Max Fine rules
347 * Each circulation is given a maximum fine based on one of
353 * This program is free software; you can redistribute it and/or
354 * modify it under the terms of the GNU General Public License
355 * as published by the Free Software Foundation; either version 2
356 * of the License, or (at your option) any later version.
358 * This program is distributed in the hope that it will be useful,
359 * but WITHOUT ANY WARRANTY; without even the implied warranty of
360 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
361 * GNU General Public License for more details.
365 CREATE TABLE config.rule_recurring_fine (
366 id SERIAL PRIMARY KEY,
367 name TEXT NOT NULL UNIQUE CHECK ( name ~ E'^\\w+$' ),
368 high NUMERIC(6,2) NOT NULL,
369 normal NUMERIC(6,2) NOT NULL,
370 low NUMERIC(6,2) NOT NULL,
371 recurrence_interval INTERVAL NOT NULL DEFAULT '1 day'::INTERVAL
373 COMMENT ON TABLE config.rule_recurring_fine IS $$
375 * Copyright (C) 2005 Georgia Public Library Service
376 * Mike Rylander <mrylander@gmail.com>
378 * Circulation Recurring Fine rules
380 * Each circulation is given a recurring fine amount based on one of
381 * these rules. The recurrence_interval should not be any shorter
382 * than the interval between runs of the fine_processor.pl script
383 * (which is run from CRON), or you could miss fines.
388 * This program is free software; you can redistribute it and/or
389 * modify it under the terms of the GNU General Public License
390 * as published by the Free Software Foundation; either version 2
391 * of the License, or (at your option) any later version.
393 * This program is distributed in the hope that it will be useful,
394 * but WITHOUT ANY WARRANTY; without even the implied warranty of
395 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
396 * GNU General Public License for more details.
401 CREATE TABLE config.rule_age_hold_protect (
402 id SERIAL PRIMARY KEY,
403 name TEXT NOT NULL UNIQUE CHECK ( name ~ E'^\\w+$' ),
404 age INTERVAL NOT NULL,
407 COMMENT ON TABLE config.rule_age_hold_protect IS $$
409 * Copyright (C) 2005 Georgia Public Library Service
410 * Mike Rylander <mrylander@gmail.com>
412 * Hold Item Age Protection rules
414 * A hold request can only capture new(ish) items when they are
415 * within a particular proximity of the home_ou of the requesting
416 * user. The proximity ('prox' column) is calculated by counting
417 * the number of tree edges between the user's home_ou and the owning_lib
418 * of the copy that could fulfill the hold.
423 * This program is free software; you can redistribute it and/or
424 * modify it under the terms of the GNU General Public License
425 * as published by the Free Software Foundation; either version 2
426 * of the License, or (at your option) any later version.
428 * This program is distributed in the hope that it will be useful,
429 * but WITHOUT ANY WARRANTY; without even the implied warranty of
430 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
431 * GNU General Public License for more details.
435 CREATE TABLE config.copy_status (
436 id SERIAL PRIMARY KEY,
437 name TEXT NOT NULL UNIQUE,
438 holdable BOOL NOT NULL DEFAULT FALSE,
439 opac_visible BOOL NOT NULL DEFAULT FALSE
441 COMMENT ON TABLE config.copy_status IS $$
443 * Copyright (C) 2005 Georgia Public Library Service
444 * Mike Rylander <mrylander@gmail.com>
448 * The available copy statuses, and whether a copy in that
449 * status is available for hold request capture. 0 (zero) is
450 * the only special number in this set, meaning that the item
451 * is available for immediate checkout, and is counted as available
454 * Statuses with an ID below 100 are not removable, and have special
455 * meaning in the code. Do not change them except to translate the
458 * You may add and remove statuses above 100, and these can be used
459 * to remove items from normal circulation without affecting the rest
460 * of the copy's values or its location.
464 * This program is free software; you can redistribute it and/or
465 * modify it under the terms of the GNU General Public License
466 * as published by the Free Software Foundation; either version 2
467 * of the License, or (at your option) any later version.
469 * This program is distributed in the hope that it will be useful,
470 * but WITHOUT ANY WARRANTY; without even the implied warranty of
471 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
472 * GNU General Public License for more details.
476 CREATE TABLE config.net_access_level (
477 id SERIAL PRIMARY KEY,
478 name TEXT NOT NULL UNIQUE
480 COMMENT ON TABLE config.net_access_level IS $$
482 * Copyright (C) 2005 Georgia Public Library Service
483 * Mike Rylander <mrylander@gmail.com>
485 * Patron Network Access level
487 * This will be used to inform the in-library firewall of how much
488 * internet access the using patron should be allowed.
492 * This program is free software; you can redistribute it and/or
493 * modify it under the terms of the GNU General Public License
494 * as published by the Free Software Foundation; either version 2
495 * of the License, or (at your option) any later version.
497 * This program is distributed in the hope that it will be useful,
498 * but WITHOUT ANY WARRANTY; without even the implied warranty of
499 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
500 * GNU General Public License for more details.
505 CREATE TABLE config.remote_account (
506 id SERIAL PRIMARY KEY,
508 host TEXT NOT NULL, -- name or IP, :port optional
509 username TEXT, -- optional, since we could default to $USER
510 password TEXT, -- optional, since we could use SSH keys, or anonymous login.
511 account TEXT, -- aka profile or FTP "account" command
512 path TEXT, -- aka directory
513 owner INT NOT NULL, -- REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
514 last_activity TIMESTAMP WITH TIME ZONE
517 CREATE TABLE config.audience_map (
518 code TEXT PRIMARY KEY,
523 CREATE TABLE config.lit_form_map (
524 code TEXT PRIMARY KEY,
529 CREATE TABLE config.language_map (
530 code TEXT PRIMARY KEY,
534 CREATE TABLE config.item_form_map (
535 code TEXT PRIMARY KEY,
539 CREATE TABLE config.item_type_map (
540 code TEXT PRIMARY KEY,
544 CREATE TABLE config.bib_level_map (
545 code TEXT PRIMARY KEY,
549 CREATE TABLE config.marc21_rec_type_map (
550 code TEXT PRIMARY KEY,
551 type_val TEXT NOT NULL,
552 blvl_val TEXT NOT NULL
555 CREATE TABLE config.marc21_ff_pos_map (
556 id SERIAL PRIMARY KEY,
557 fixed_field TEXT NOT NULL,
559 rec_type TEXT NOT NULL,
560 start_pos INT NOT NULL,
562 default_val TEXT NOT NULL DEFAULT ' '
565 CREATE TABLE config.marc21_physical_characteristic_type_map (
566 ptype_key TEXT PRIMARY KEY,
567 label TEXT NOT NULL -- I18N
570 CREATE TABLE config.marc21_physical_characteristic_subfield_map (
571 id SERIAL PRIMARY KEY,
572 ptype_key TEXT NOT NULL REFERENCES config.marc21_physical_characteristic_type_map (ptype_key) ON DELETE CASCADE ON UPDATE CASCADE,
573 subfield TEXT NOT NULL,
574 start_pos INT NOT NULL,
576 label TEXT NOT NULL -- I18N
579 CREATE TABLE config.marc21_physical_characteristic_value_map (
580 id SERIAL PRIMARY KEY,
582 ptype_subfield INT NOT NULL REFERENCES config.marc21_physical_characteristic_subfield_map (id),
583 label TEXT NOT NULL -- I18N
587 CREATE TABLE config.z3950_source (
588 name TEXT PRIMARY KEY,
589 label TEXT NOT NULL UNIQUE,
593 record_format TEXT NOT NULL DEFAULT 'FI',
594 transmission_format TEXT NOT NULL DEFAULT 'usmarc',
595 auth BOOL NOT NULL DEFAULT TRUE
598 COMMENT ON TABLE config.z3950_source IS $$
601 Each row in this table represents a database searchable via Z39.50.
604 COMMENT ON COLUMN config.z3950_source.record_format IS $$
608 COMMENT ON COLUMN config.z3950_source.transmission_format IS $$
609 Z39.50 preferred record syntax..
613 CREATE TABLE config.z3950_attr (
614 id SERIAL PRIMARY KEY,
615 source TEXT NOT NULL REFERENCES config.z3950_source (name) DEFERRABLE INITIALLY DEFERRED,
620 truncation INT NOT NULL DEFAULT 0,
621 CONSTRAINT z_code_format_once_per_source UNIQUE (code,format,source)
624 CREATE TABLE config.i18n_locale (
625 code TEXT PRIMARY KEY,
626 marc_code TEXT NOT NULL REFERENCES config.language_map (code) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
627 name TEXT UNIQUE NOT NULL,
631 CREATE TABLE config.i18n_core (
632 id BIGSERIAL PRIMARY KEY,
633 fq_field TEXT NOT NULL,
634 identity_value TEXT NOT NULL,
635 translation TEXT NOT NULL REFERENCES config.i18n_locale (code) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
639 CREATE UNIQUE INDEX i18n_identity ON config.i18n_core (fq_field,identity_value,translation);
641 CREATE TABLE config.billing_type (
642 id SERIAL PRIMARY KEY,
644 owner INT NOT NULL, -- REFERENCES actor.org_unit (id)
645 default_price NUMERIC(6,2),
646 CONSTRAINT billing_type_once_per_lib UNIQUE (name, owner)
649 CREATE TABLE config.org_unit_setting_type (
650 name TEXT PRIMARY KEY,
651 label TEXT UNIQUE NOT NULL,
653 datatype TEXT NOT NULL DEFAULT 'string',
658 -- define valid datatypes
660 CONSTRAINT coust_valid_datatype CHECK ( datatype IN
661 ( 'bool', 'integer', 'float', 'currency', 'interval',
662 'date', 'string', 'object', 'array', 'link' ) ),
664 -- fm_class is meaningful only for 'link' datatype
666 CONSTRAINT coust_no_empty_link CHECK
667 ( ( datatype = 'link' AND fm_class IS NOT NULL ) OR
668 ( datatype <> 'link' AND fm_class IS NULL ) )
671 CREATE TABLE config.usr_setting_type (
673 name TEXT PRIMARY KEY,
674 opac_visible BOOL NOT NULL DEFAULT FALSE,
675 label TEXT UNIQUE NOT NULL,
677 datatype TEXT NOT NULL DEFAULT 'string',
681 -- define valid datatypes
683 CONSTRAINT coust_valid_datatype CHECK ( datatype IN
684 ( 'bool', 'integer', 'float', 'currency', 'interval',
685 'date', 'string', 'object', 'array', 'link' ) ),
688 -- fm_class is meaningful only for 'link' datatype
690 CONSTRAINT coust_no_empty_link CHECK
691 ( ( datatype = 'link' AND fm_class IS NOT NULL ) OR
692 ( datatype <> 'link' AND fm_class IS NULL ) )
696 -- Some handy functions, based on existing ones, to provide optional ingest normalization
698 CREATE OR REPLACE FUNCTION public.left_trunc( TEXT, INT ) RETURNS TEXT AS $func$
699 SELECT SUBSTRING($1,$2);
700 $func$ LANGUAGE SQL STRICT IMMUTABLE;
702 CREATE OR REPLACE FUNCTION public.right_trunc( TEXT, INT ) RETURNS TEXT AS $func$
703 SELECT SUBSTRING($1,1,$2);
704 $func$ LANGUAGE SQL STRICT IMMUTABLE;
706 CREATE OR REPLACE FUNCTION public.split_date_range( TEXT ) RETURNS TEXT AS $func$
707 SELECT REGEXP_REPLACE( $1, E'(\\d{4})-(\\d{4})', E'\\1 \\2', 'g' );
708 $func$ LANGUAGE SQL STRICT IMMUTABLE;
710 -- And ... a table in which to register them
712 CREATE TABLE config.index_normalizer (
713 id SERIAL PRIMARY KEY,
714 name TEXT UNIQUE NOT NULL,
717 param_count INT NOT NULL DEFAULT 0
720 CREATE TABLE config.metabib_field_index_norm_map (
721 id SERIAL PRIMARY KEY,
722 field INT NOT NULL REFERENCES config.metabib_field (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
723 norm INT NOT NULL REFERENCES config.index_normalizer (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
725 pos INT NOT NULL DEFAULT 0
728 CREATE OR REPLACE FUNCTION oils_tsearch2 () RETURNS TRIGGER AS $$
733 IF NEW.index_vector = ''::tsvector THEN
739 IF TG_TABLE_NAME::TEXT ~ 'field_entry$' THEN
741 SELECT n.func AS func,
742 n.param_count AS param_count,
744 FROM config.index_normalizer n
745 JOIN config.metabib_field_index_norm_map m ON (m.norm = n.id)
746 WHERE field = NEW.field
749 EXECUTE 'SELECT ' || normalizer.func || '(' ||
750 quote_literal( value ) ||
752 WHEN normalizer.param_count > 0 THEN ',' || BTRIM(normalizer.params,'[]')
760 IF REGEXP_REPLACE(VERSION(),E'^.+?(\\d+\\.\\d+).*?$',E'\\1')::FLOAT > 8.2 THEN
761 NEW.index_vector = to_tsvector((TG_ARGV[0])::regconfig, value);
763 NEW.index_vector = to_tsvector(TG_ARGV[0], value);