set client_encoding=utf8;

\connect %FROM_DBNAME%;

DO $$ 
declare
begin 
  if lower('%FROM_DBUSER%') = 'postgres' then
      GRANT ALL PRIVILEGES ON SCHEMA public TO %TO_DBUser% ;
      GRANT SELECT ON ALL TABLES IN SCHEMA public TO %TO_DBUser% ;
  else
    GRANT ALL PRIVILEGES ON SCHEMA %FROM_DBUser% TO %TO_DBUser% ;
    GRANT SELECT ON ALL TABLES IN SCHEMA %FROM_DBUser% TO %TO_DBUser% ;
  end if;
END  $$;

