--- System Setup
SET application_name="container_setup";

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS pgaudit;

CREATE USER PGHA_USER LOGIN;
ALTER USER PGHA_USER PASSWORD 'PGHA_USER_PASSWORD';

CREATE DATABASE PGHA_DATABASE;
GRANT ALL PRIVILEGES ON DATABASE PGHA_DATABASE TO PGHA_USER;

--- PGHA_DATABASE Setup

\c PGHA_DATABASE

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS pgaudit;

CREATE SCHEMA IF NOT EXISTS PGHA_USER;

--- System Setup
SET application_name="container_setup";

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS pgaudit;

CREATE USER PGHA_USER LOGIN;
ALTER USER PGHA_USER PASSWORD 'PGHA_USER_PASSWORD';

CREATE DATABASE PGHA_DATABASE;
GRANT ALL PRIVILEGES ON DATABASE PGHA_DATABASE TO PGHA_USER;

--- PGHA_DATABASE Setup

\c PGHA_DATABASE

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS pgaudit;

CREATE SCHEMA IF NOT EXISTS AUTHORIZATION PGHA_USER;

Allow regular PostgreSQL user to create objects in its own schema
Allow regular PostgreSQL user to create objects in its own schema

The "setup.sql" script that runs several bootstrap commands for a
PostgreSQL database that is deployed by the Operator includes adding
a user schema (a standard part of the search patch[1], but makes the
mistake of not allowing the user to access the schema. This patch
adds the "AUTHORIZATION" directive to the "CREATE SCHEMA" command to
ensure that the user can actual utilize the schema, making the feature
actually useful.

Issue: CrunchyData/postgres-operator#1334

[1] https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH
