`run_process_utility_hook` is tangled everywhere, making logic hard to follow and properly review PRs
Problem
Right now the different modules logic are tangled per statement and the standard hook (run_process_utility_hook) is scattered everywhere. This makes it hard to:
-
maintain the code and to disable modules according to the pg version (https://github.com/supabase/supautils/issues/78, https://github.com/supabase/supautils/issues/50#issuecomment-1728441632).
-
properly review PRs, and we already had a consequence on https://github.com/supabase/supautils/pull/100
- essentially, we have many case statements that have a
returninstead of abreak. It's easy to do areturnin some cases and miss hitting therun_process_utility_hook.
- essentially, we have many case statements that have a
Solution
Refactor the codebase so each module has a single entrypoint and the standard hook is always invoked in one single place. Basically:
static void
supautils_hook(PROCESS_UTILITY_PARAMS)
{
Node *utility_stmt = pstmt->utilityStmt;
ret1 = privileged_role_setup(utility_stmt)
ret2 = reserved_roles_setup(utility_stmt)
ret3 = privileged_extensions_setup(utility_stmt)
ret4 = constrained_extensions_setup(utility_stmt)
run_process_utility_hook(prev_hook);
cleanup(ret1, ret2, ret3, ret4); // or have multiple cleanups depending on the module
Check if the volatile added on https://github.com/supabase/supautils/pull/170/commits/ba8025c9468a2a96ba9d3db45a454f5587cdb897 can be removed when this refactor is done.