apiVersion: v1
kind: ConfigMap
metadata:
  name: config-with-primary-init-script
  namespace: default
  labels:
    environment: acceptancetesting

data:

  primary_init_script.sh: |
    #!/bin/bash
    set -e

    dt=$(date '+%d/%m/%Y %H:%M:%S');
    echo "$dt - Running init script the 1st time Primary Kubegres container is created...";

    echo "$dt - Running: psql -v ON_ERROR_STOP=1 --username $POSTGRES_USER --dbname $POSTGRES_DB ...";

    psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE TABLE account(user_id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);
    INSERT INTO account VALUES (1, 'username1');
    INSERT INTO account VALUES (2, 'username2');
    EOSQL

    echo "$dt - Init script is completed";
