mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 10:33:27 +08:00
This patch locks down search_path in extension install and update scripts to only contain pg_catalog, this requires that any reference in those scripts is fully qualified. Additionally we add explicit create commands to all update scripts for objects added to the public schema. This change will make update scripts fail if a function with identical signature already exists when installing or upgrading instead reusing the existing object.
42 lines
1.5 KiB
PL/PgSQL
42 lines
1.5 KiB
PL/PgSQL
-- This file and its contents are licensed under the Apache License 2.0.
|
|
-- Please see the included NOTICE for copyright information and
|
|
-- LICENSE-APACHE for a copy of the license.
|
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.timescaledb_pre_restore() RETURNS BOOL AS
|
|
$BODY$
|
|
DECLARE
|
|
db text;
|
|
BEGIN
|
|
SELECT current_database() INTO db;
|
|
EXECUTE format($$ALTER DATABASE %I SET timescaledb.restoring ='on'$$, db);
|
|
SET SESSION timescaledb.restoring = 'on';
|
|
PERFORM _timescaledb_internal.stop_background_workers();
|
|
--exported uuid may be included in the dump so backup the version
|
|
UPDATE _timescaledb_catalog.metadata SET key='exported_uuid_bak' WHERE key='exported_uuid';
|
|
RETURN true;
|
|
END
|
|
$BODY$
|
|
LANGUAGE PLPGSQL SET search_path TO pg_catalog;
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.timescaledb_post_restore() RETURNS BOOL AS
|
|
$BODY$
|
|
DECLARE
|
|
db text;
|
|
BEGIN
|
|
SELECT current_database() INTO db;
|
|
EXECUTE format($$ALTER DATABASE %I RESET timescaledb.restoring $$, db);
|
|
RESET timescaledb.restoring;
|
|
PERFORM _timescaledb_internal.restart_background_workers();
|
|
|
|
--try to restore the backed up uuid, if the restore did not set one
|
|
INSERT INTO _timescaledb_catalog.metadata
|
|
SELECT 'exported_uuid', value, include_in_telemetry FROM _timescaledb_catalog.metadata WHERE key='exported_uuid_bak'
|
|
ON CONFLICT DO NOTHING;
|
|
DELETE FROM _timescaledb_catalog.metadata WHERE key='exported_uuid_bak';
|
|
|
|
RETURN true;
|
|
END
|
|
$BODY$
|
|
LANGUAGE PLPGSQL SET search_path TO pg_catalog;
|