<commit_before>CREATE OR REPLACE FUNCTION cron.Is_Valid_Function(_Function regprocedure)
RETURNS boolean
LANGUAGE sql
STABLE
SET search_path TO public, pg_temp
AS $FUNC$
SELECT TRUE FROM pg_catalog.pg_proc
-- All functions registered in Jobs must return BATCHJOBSTATE which is just an ENUM 'AGAIN' or 'DONE',
-- to indicate whether or not cron.Run() should run the function again or if the job is done.
-- This is to avoid accidents and to force the user to be explicit about what to do,
-- instead of using a plain boolean as return value, which could be misinterpreted.
WHERE oid = $1::oid
AND prorettype::regtype::text = 'batchjobstate'
AND EXISTS (
    -- It's not enough to just register the function using cron.Register().
    -- The user must also explicitly grant execute on the function to the pgcronjob role,
    -- using the command: GRANT EXECUTE ON FUNCTION ... TO pgcronjob.
    -- This is to reduce the risk of accidents from happening, in case of human errors.
    SELECT 1 FROM aclexplode(pg_catalog.pg_proc.proacl)
    WHERE aclexplode.privilege_type = 'EXECUTE'
    AND aclexplode.grantee = (
        SELECT pg_catalog.pg_user.usesysid FROM pg_catalog.pg_user
        WHERE pg_catalog.pg_user.usename = 'pgcronjob'
    )
)
$FUNC$;

ALTER FUNCTION cron.Is_Valid_Function(_Function regprocedure) OWNER TO pgcronjob;<commit_msg>Allow batchjobstate type to exist in any schema, not just public<commit_after>CREATE OR REPLACE FUNCTION cron.Is_Valid_Function(_Function regprocedure)
RETURNS boolean
LANGUAGE sql
STABLE
SET search_path TO public, pg_temp
AS $FUNC$
SELECT TRUE FROM pg_catalog.pg_proc
-- All functions registered in Jobs must return BATCHJOBSTATE which is just an ENUM 'AGAIN' or 'DONE',
-- to indicate whether or not cron.Run() should run the function again or if the job is done.
-- This is to avoid accidents and to force the user to be explicit about what to do,
-- instead of using a plain boolean as return value, which could be misinterpreted.
WHERE oid = $1::oid
AND prorettype::regtype::text ~ '(^|\.)batchjobstate$'
AND EXISTS (
    -- It's not enough to just register the function using cron.Register().
    -- The user must also explicitly grant execute on the function to the pgcronjob role,
    -- using the command: GRANT EXECUTE ON FUNCTION ... TO pgcronjob.
    -- This is to reduce the risk of accidents from happening, in case of human errors.
    SELECT 1 FROM aclexplode(pg_catalog.pg_proc.proacl)
    WHERE aclexplode.privilege_type = 'EXECUTE'
    AND aclexplode.grantee = (
        SELECT pg_catalog.pg_user.usesysid FROM pg_catalog.pg_user
        WHERE pg_catalog.pg_user.usename = 'pgcronjob'
    )
)
$FUNC$;

ALTER FUNCTION cron.Is_Valid_Function(_Function regprocedure) OWNER TO pgcronjob;
{'fraction_non_alphanumeric': 0.06919155134741442, 'fraction_numerical': 0.0014566642388929353, 'mean_word_length': 3.985480943738657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5807519', 'n_tokens_mistral': 843, 'n_tokens_neox': 807, 'n_words': 339}