DO $$
DECLARE
    r record;
    trigger_name text;
BEGIN
    FOR r IN
        SELECT table_schema, table_name
        FROM information_schema.columns
        WHERE column_name = 'deleted_at'
          AND table_schema = 'public'
        GROUP BY table_schema, table_name
    LOOP
        trigger_name := format('trg_soft_delete_fk_%s', r.table_name);
        EXECUTE format('DROP TRIGGER IF EXISTS %I ON %I.%I', trigger_name, r.table_schema, r.table_name);
    END LOOP;
END $$;

DROP FUNCTION IF EXISTS soft_delete_handle_fk();
