Refactor to allow disabling features according to pg version
steve-chavez opened this issue · comments
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 harder to maintain the code and to disable modules according to the pg version (#78, #50 (comment)).
static void
supautils_hook(PROCESS_UTILITY_PARAMS)
{
Node *utility_stmt = pstmt->utilityStmt;
switch (utility_stmt->type)
{
case T_AlterRoleStmt:
// privileged role logic..
// reserved role logic..
case T_CreateExtensionStmt:
// constrained extensions logic..
// privileged extensions logic..
Solution
Refactor the codebase so each module has a single entrypoint and the standard hook is 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