cartodb-postgresql/scripts-available/CDB_Conf.sql

49 lines
1.4 KiB
MySQL
Raw Normal View History

2015-08-19 17:20:06 +08:00
----------------------------------
-- CONF MANAGEMENT FUNCTIONS
--
-- Meant to be used by superadmin user.
-- Functions needing reading configuration should use SECURITY DEFINER.
----------------------------------
2019-05-31 21:29:28 +08:00
-- This will trigger NOTICE if @extschema@.CDB_CONF already exists
2015-08-14 02:43:17 +08:00
DO LANGUAGE 'plpgsql' $$
BEGIN
2019-05-31 21:29:28 +08:00
CREATE TABLE IF NOT EXISTS @extschema@.CDB_CONF ( KEY TEXT PRIMARY KEY, VALUE JSON NOT NULL );
END
$$;
-- This can only be called from an SQL script executed by CREATE EXTENSION
DO LANGUAGE 'plpgsql' $$
BEGIN
2019-05-31 21:29:28 +08:00
PERFORM pg_catalog.pg_extension_config_dump('@extschema@.CDB_CONF', '');
2015-08-14 02:43:17 +08:00
END
$$;
CREATE OR REPLACE
2019-05-31 21:29:28 +08:00
FUNCTION @extschema@.CDB_Conf_SetConf(key text, value JSON)
2015-08-14 02:43:17 +08:00
RETURNS void AS $$
BEGIN
2019-05-31 21:29:28 +08:00
PERFORM @extschema@.CDB_Conf_RemoveConf(key);
EXECUTE 'INSERT INTO @extschema@.CDB_CONF (KEY, VALUE) VALUES ($1, $2);' USING key, value;
2015-08-14 02:43:17 +08:00
END
2017-10-24 20:16:56 +08:00
$$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
2015-08-14 02:43:17 +08:00
CREATE OR REPLACE
2019-05-31 21:29:28 +08:00
FUNCTION @extschema@.CDB_Conf_RemoveConf(key text)
2015-08-14 02:43:17 +08:00
RETURNS void AS $$
BEGIN
2019-05-31 21:29:28 +08:00
EXECUTE 'DELETE FROM @extschema@.CDB_CONF WHERE KEY = $1;' USING key;
2015-08-14 02:43:17 +08:00
END
2017-10-24 20:16:56 +08:00
$$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
2015-08-14 02:43:17 +08:00
CREATE OR REPLACE
2019-05-31 21:29:28 +08:00
FUNCTION @extschema@.CDB_Conf_GetConf(key text)
2015-08-20 14:44:59 +08:00
RETURNS JSON AS $$
2015-08-14 02:43:17 +08:00
DECLARE
2015-08-20 14:44:59 +08:00
value JSON;
2015-08-14 02:43:17 +08:00
BEGIN
2019-05-31 21:29:28 +08:00
EXECUTE 'SELECT VALUE FROM @extschema@.CDB_CONF WHERE KEY = $1;' INTO value USING key;
2015-08-20 14:44:59 +08:00
RETURN value;
2015-08-14 02:43:17 +08:00
END
2017-10-24 20:16:56 +08:00
$$ LANGUAGE PLPGSQL STABLE PARALLEL SAFE;