-- If PostgREST is continually returning a 503, it's often because the base
-- `authenticator` role used by the API gateway lost privileges to switch to the
-- `anon` or `authenticated` roles, which breaks OpenAPI cache generation.

-- 1. Ensure the authenticator role has permission to assume the anon and authenticated roles
GRANT anon TO authenticator;
GRANT authenticated TO authenticator;

-- 2. Ensure authenticator can access the public schema
GRANT USAGE ON SCHEMA public TO authenticator;

-- 3. In some setups, the API explicitly needs the 'service_role' granted to authenticator as well
GRANT service_role TO authenticator;

-- 4. Reload the cache one last time
NOTIFY pgrst, 'reload schema';
