#!/bin/bash

SESSION_SECRET=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'A-Za-z0-9' | fold -w 64 | head -n 1)

cat <<HERE

INSERT INTO data.config (env, effective, settings) VALUES (
  'ci',
  now(),
  '{
    "databaseUrlDelete": "postgresql://${PROJECT}_ci_delete@postgres/${PROJECT}_ci",
    "databaseUrlWrite": "postgresql://${PROJECT}_ci_write@postgres/${PROJECT}_ci",
    "databaseUrlRead": "postgresql://${PROJECT}_ci_read@postgres/${PROJECT}_ci",
    "hostUrl": "http://localhost:3210/",
    "googleAuthId": "365964374983-6e215tp8rlcpce32mnol7a5om0lvsts6.apps.googleusercontent.com",
    "googleAuthSecret": "hZRSwGXQ_sCzefV2oHVmTIMQ",
    "sessionSecret": "${SESSION_SECRET}"
  }'::JSONB
),
(
  'dev',
  now(),
  '{
    "databaseUrlDelete": "postgresql://${PROJECT}_delete@postgres/${PROJECT}",
    "databaseUrlWrite": "postgresql://${PROJECT}_write@postgres/${PROJECT}",
    "databaseUrlRead": "postgresql://${PROJECT}_read@postgres/${PROJECT}",
    "hostUrl": "http://localhost:8888/",
    "googleAuthId": "365964374983-6e215tp8rlcpce32mnol7a5om0lvsts6.apps.googleusercontent.com",
    "googleAuthSecret": "hZRSwGXQ_sCzefV2oHVmTIMQ",
    "sessionSecret": "${SESSION_SECRET}"
  }'::JSONB
),
(
  'test',
  now(),
  '{
    "databaseUrlDelete": "postgresql://${PROJECT}_test_delete@postgres/${PROJECT}_test",
    "databaseUrlWrite": "postgresql://${PROJECT}_test_write@postgres/${PROJECT}_test",
    "databaseUrlRead": "postgresql://${PROJECT}_test_read@postgres/${PROJECT}_test",
    "hostUrl": "http://localhost:3210/",
    "googleAuthId": "365964374983-6e215tp8rlcpce32mnol7a5om0lvsts6.apps.googleusercontent.com",
    "googleAuthSecret": "hZRSwGXQ_sCzefV2oHVmTIMQ",
    "sessionSecret": "${SESSION_SECRET}"
  }'::JSONB
), (
  '${CONFIG_ENV}',
  now() + INTERVAL '1 second',
  '{
   "hostUrl": "${PROJECT_URL}",
   "databaseUrlRead": "${DATABASE_URL_READ}",
   "databaseUrlWrite": "${DATABASE_URL_WRITE}",
   "databaseUrlDelete": "${DATABASE_URL_DELETE}",
   "googleAuthId": "365964374983-6e215tp8rlcpce32mnol7a5om0lvsts6.apps.googleusercontent.com", 
   "googleAuthSecret": "hZRSwGXQ_sCzefV2oHVmTIMQ",
   "sessionSecret": "${SESSION_SECRET}"
  }'::JSONB
);

HERE
