-- Optional helper. Replace ROLE_NAME and ROLE_PASSWORD before running.
-- NOTE: if your password contains a single quote, escape it by doubling: ' -> ''

DO $$
BEGIN
  IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'ROLE_NAME') THEN
    EXECUTE format('CREATE ROLE %I WITH LOGIN PASSWORD %L', 'ROLE_NAME', 'ROLE_PASSWORD');
  END IF;
END $$;

DO $$
BEGIN
  IF NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = 'eterssa') THEN
    EXECUTE format('CREATE DATABASE %I OWNER %I', 'eterssa', 'ROLE_NAME');
  END IF;
END $$;
