-- Triggers and event triggers -- Generated: 2025-10-15T12:24:56.582392 -- Event triggers -- Event trigger: prevent_series_drops CREATE OR REPLACE FUNCTION meta.prevent_direct_drop() RETURNS event_trigger LANGUAGE plpgsql AS $function$ DECLARE obj record; BEGIN -- Get the current context IF current_setting('application.dropping_series', true) = 'true' THEN -- Allow the drop if it's coming from our procedures RETURN; END IF; FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects() WHERE object_type = 'table' LOOP IF EXISTS ( SELECT 1 FROM meta.series WHERE table_name = obj.object_name AND db_schema = obj.schema_name ) THEN RAISE EXCEPTION 'Table %.% is registered in series and can only be dropped using TimeseriesDB.drop_series()', obj.schema_name, obj.object_name; END IF; END LOOP; END; $function$; CREATE EVENT TRIGGER prevent_series_drops ON sql_drop EXECUTE FUNCTION meta.prevent_direct_drop();