4 SELECT evergreen.upgrade_deps_block_check('0774', :eg_version);
6 CREATE TABLE config.z3950_source_credentials (
8 owner INTEGER NOT NULL REFERENCES actor.org_unit(id),
9 source TEXT NOT NULL REFERENCES config.z3950_source(name) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
10 -- do some Z servers require a username but no password or vice versa?
13 CONSTRAINT czsc_source_once_per_lib UNIQUE (source, owner)
16 -- find the most relevant set of credentials for the Z source and org
17 CREATE OR REPLACE FUNCTION config.z3950_source_credentials_lookup
18 (source TEXT, owner INTEGER)
19 RETURNS config.z3950_source_credentials AS $$
22 FROM config.z3950_source_credentials creds
23 JOIN actor.org_unit aou ON (aou.id = creds.owner)
24 JOIN actor.org_unit_type aout ON (aout.id = aou.ou_type)
25 WHERE creds.source = $1 AND creds.owner IN (
26 SELECT id FROM actor.org_unit_ancestors($2)
28 ORDER BY aout.depth DESC LIMIT 1;
30 $$ LANGUAGE SQL STABLE;
32 -- since we are not exposing config.z3950_source_credentials
33 -- via the IDL, providing a stored proc gives us a way to
34 -- set values in the table via cstore
35 CREATE OR REPLACE FUNCTION config.z3950_source_credentials_apply
36 (src TEXT, org INTEGER, uname TEXT, passwd TEXT)
39 PERFORM 1 FROM config.z3950_source_credentials
40 WHERE owner = org AND source = src;
43 IF COALESCE(uname, '') = '' AND COALESCE(passwd, '') = '' THEN
44 DELETE FROM config.z3950_source_credentials
45 WHERE owner = org AND source = src;
47 UPDATE config.z3950_source_credentials
48 SET username = uname, password = passwd
49 WHERE owner = org AND source = src;
52 IF COALESCE(uname, '') <> '' OR COALESCE(passwd, '') <> '' THEN
53 INSERT INTO config.z3950_source_credentials
54 (source, owner, username, password)
55 VALUES (src, org, uname, passwd);