mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 01:53:41 +08:00
To increase schema security we do not want to mix our own internal objects with user objects. Since chunks are created in the _timescaledb_internal schema our internal functions should live in a different dedicated schema. This patch make the necessary adjustments for the following functions: - chunk_constraint_add_table_constraint(_timescaledb_catalog.chunk_constraint) - chunk_drop_replica(regclass,name) - chunk_index_clone(oid) - chunk_index_replace(oid,oid) - create_chunk_replica_table(regclass,name) - drop_stale_chunks(name,integer[]) - health() - hypertable_constraint_add_table_fk_constraint(name,name,name,integer) - process_ddl_event() - wait_subscription_sync(name,name,integer,numeric)
42 lines
1.6 KiB
PL/PgSQL
42 lines
1.6 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.
|
|
|
|
-- Clone fk constraint from a hypertable
|
|
CREATE OR REPLACE FUNCTION _timescaledb_functions.hypertable_constraint_add_table_fk_constraint(
|
|
user_ht_constraint_name NAME,
|
|
user_ht_schema_name NAME,
|
|
user_ht_table_name NAME,
|
|
compress_ht_id INTEGER
|
|
)
|
|
RETURNS VOID LANGUAGE PLPGSQL AS
|
|
$BODY$
|
|
DECLARE
|
|
compressed_ht_row _timescaledb_catalog.hypertable;
|
|
constraint_oid OID;
|
|
check_sql TEXT;
|
|
def TEXT;
|
|
BEGIN
|
|
SELECT * INTO STRICT compressed_ht_row FROM _timescaledb_catalog.hypertable h
|
|
WHERE h.id = compress_ht_id;
|
|
IF user_ht_constraint_name IS NOT NULL THEN
|
|
SELECT oid INTO STRICT constraint_oid FROM pg_constraint
|
|
WHERE conname=user_ht_constraint_name AND contype = 'f' AND
|
|
conrelid = format('%I.%I', user_ht_schema_name, user_ht_table_name)::regclass::oid;
|
|
def := pg_get_constraintdef(constraint_oid);
|
|
ELSE
|
|
RAISE 'unknown constraint type';
|
|
END IF;
|
|
IF def IS NOT NULL THEN
|
|
-- to allow for custom types with operators outside of pg_catalog
|
|
-- we set search_path to @extschema@
|
|
SET LOCAL search_path TO @extschema@, pg_temp;
|
|
EXECUTE pg_catalog.format(
|
|
$$ ALTER TABLE %I.%I ADD CONSTRAINT %I %s $$,
|
|
compressed_ht_row.schema_name, compressed_ht_row.table_name, user_ht_constraint_name, def
|
|
);
|
|
END IF;
|
|
|
|
END
|
|
$BODY$ SET search_path TO pg_catalog, pg_temp;
|