-- SQL to create the exec_sql function -- Open Supabase Dashboard > SQL Editor and execute this script -- Create a function to execute SQL statements -- This function requires superuser privileges -- It should be executed by a Supabase admin CREATE OR REPLACE FUNCTION exec_sql(sql text) RETURNS JSONB LANGUAGE plpgsql SECURITY DEFINER AS $$ DECLARE result JSONB; BEGIN EXECUTE sql; result := jsonb_build_object('success', true, 'message', 'SQL executed successfully'); RETURN result; EXCEPTION WHEN OTHERS THEN result := jsonb_build_object( 'success', false, 'message', 'Error executing SQL', 'error', SQLERRM, 'state', SQLSTATE ); RETURN result; END; $$; -- Grant execute permission to the service_role GRANT EXECUTE ON FUNCTION exec_sql(text) TO service_role; -- Comment on the function COMMENT ON FUNCTION exec_sql(text) IS 'Executes arbitrary SQL. Use with caution - requires service_role key.'; -- After creating this function, you can run: -- npm run supabase:fix-recursion