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.
|
|
|
|
----------------------------------
|
|
|
|
|
2015-08-20 19:02:02 +08:00
|
|
|
-- This will trigger NOTICE if cartodb.CDB_CONF already exists
|
2015-08-14 02:43:17 +08:00
|
|
|
DO LANGUAGE 'plpgsql' $$
|
|
|
|
BEGIN
|
2015-08-20 14:44:59 +08:00
|
|
|
CREATE TABLE IF NOT EXISTS cartodb.CDB_CONF ( KEY TEXT PRIMARY KEY, VALUE JSON NOT NULL );
|
2015-08-26 19:23:32 +08:00
|
|
|
END
|
|
|
|
$$;
|
|
|
|
|
|
|
|
-- This can only be called from an SQL script executed by CREATE EXTENSION
|
|
|
|
DO LANGUAGE 'plpgsql' $$
|
|
|
|
BEGIN
|
2015-08-20 23:39:28 +08:00
|
|
|
PERFORM pg_catalog.pg_extension_config_dump('cartodb.CDB_CONF', '');
|
2015-08-14 02:43:17 +08:00
|
|
|
END
|
|
|
|
$$;
|
|
|
|
|
|
|
|
CREATE OR REPLACE
|
2015-08-20 18:55:22 +08:00
|
|
|
FUNCTION cartodb.CDB_Conf_SetConf(key text, value JSON)
|
2015-08-14 02:43:17 +08:00
|
|
|
RETURNS void AS $$
|
|
|
|
BEGIN
|
2015-08-20 14:44:59 +08:00
|
|
|
PERFORM cartodb.CDB_Conf_RemoveConf(key);
|
2015-08-20 19:02:02 +08:00
|
|
|
EXECUTE 'INSERT INTO cartodb.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
|
2015-08-20 14:44:59 +08:00
|
|
|
FUNCTION cartodb.CDB_Conf_RemoveConf(key text)
|
2015-08-14 02:43:17 +08:00
|
|
|
RETURNS void AS $$
|
|
|
|
BEGIN
|
2015-08-20 19:02:02 +08:00
|
|
|
EXECUTE 'DELETE FROM cartodb.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
|
2015-08-20 14:44:59 +08:00
|
|
|
FUNCTION cartodb.CDB_Conf_GetConf(key text)
|
|
|
|
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
|
2015-08-20 19:02:02 +08:00
|
|
|
EXECUTE 'SELECT VALUE FROM cartodb.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;
|