test: update generated init_scripts
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
-- Core functions for Zabbix partitioning (Create, Drop, Maintain).
|
||||
-- ============================================================================
|
||||
|
||||
-- Function to check if a partition exists
|
||||
CREATE OR REPLACE FUNCTION partitions.partition_exists(p_partition_name text)
|
||||
-- Function to check if a partition exists in a specific schema
|
||||
CREATE OR REPLACE FUNCTION partitions.partition_exists(p_partition_name text, p_schema text)
|
||||
RETURNS boolean AS $$
|
||||
BEGIN
|
||||
RETURN EXISTS (
|
||||
SELECT 1 FROM pg_class c
|
||||
JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||
WHERE c.relname = p_partition_name
|
||||
AND n.nspname = p_schema
|
||||
);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
@@ -32,7 +33,7 @@ BEGIN
|
||||
SELECT n.nspname INTO v_parent_schema
|
||||
FROM pg_class c
|
||||
JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||
WHERE c.relname = p_parent_table;
|
||||
WHERE c.relname = p_parent_table AND pg_table_is_visible(c.oid);
|
||||
|
||||
IF NOT FOUND THEN
|
||||
RAISE EXCEPTION 'Parent table % not found', p_parent_table;
|
||||
@@ -51,15 +52,19 @@ BEGIN
|
||||
|
||||
v_partition_name := p_parent_table || '_p' || v_suffix;
|
||||
|
||||
IF NOT partitions.partition_exists(v_partition_name) THEN
|
||||
IF NOT partitions.partition_exists(v_partition_name, v_parent_schema) THEN
|
||||
BEGIN
|
||||
EXECUTE format(
|
||||
'CREATE TABLE %I.%I PARTITION OF %I.%I FOR VALUES FROM (%s) TO (%s)',
|
||||
v_parent_schema, v_partition_name, v_parent_schema, p_parent_table, v_start_ts, v_end_ts
|
||||
);
|
||||
EXCEPTION WHEN invalid_object_definition THEN
|
||||
-- Ignore overlap errors (e.g., when transitioning from daily to hourly partitioning)
|
||||
RAISE NOTICE 'Partition % overlaps with an existing partition. Skipping.', v_partition_name;
|
||||
EXCEPTION
|
||||
WHEN invalid_object_definition THEN
|
||||
-- Ignore overlap errors (e.g., when transitioning from daily to hourly partitioning)
|
||||
RAISE NOTICE 'Partition % overlaps with an existing partition. Skipping.', v_partition_name;
|
||||
WHEN duplicate_table THEN
|
||||
-- Ignore race condition: another process created the partition concurrently
|
||||
RAISE NOTICE 'Partition % already exists (concurrent creation). Skipping.', v_partition_name;
|
||||
END;
|
||||
END IF;
|
||||
END;
|
||||
@@ -89,7 +94,7 @@ BEGIN
|
||||
JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
|
||||
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
|
||||
JOIN pg_namespace n ON child.relnamespace = n.oid
|
||||
WHERE parent.relname = p_parent_table
|
||||
WHERE parent.relname = p_parent_table AND pg_table_is_visible(parent.oid)
|
||||
LOOP
|
||||
-- Parse partition suffix to determine age
|
||||
-- Format: parent_pYYYYMM or parent_pYYYYMMDD
|
||||
|
||||
Reference in New Issue
Block a user