# -*- coding: utf-8; mode: yaml; indent-tabs-mode: nil; -*-
#
%YAML 1.1
---

globals:
  var1: value1
  var2: value2
  datadir1: &datadir 'E:\home\fag\p\work5\pgdbmgr\_data'
  PGBINDIR: 'E:\APPS64\PostgreSQL-9.4\all\bin'

  PATH: '{{PGBINDIR}}'

  user1:
    name: &rootname 'My Username'
    pwd:  &rootpwd 'My Password'

  user2:
    name: 'myquizowner'
    pwd:  'abcQQQ123456'

  database: myquiz

  dbhost: localhost
  dbport: 5432

  engine0:
    url: 'postgresql+psycopg2://{{user1.name|urlquote}}:{{user1.pwd|urlquote}}@{{dbhost}}:{{dbport}}/postgres'
    echo: false
    echo_pool: false
    encoding: utf-8
    isolation_level: 'SERIALIZABLE'

  engine1:
    url: 'postgresql+psycopg2://{{user2.name|urlquote}}:{{user2.pwd|urlquote}}@{{dbhost}}:{{dbport}}/{{database}}'
    echo: false
    echo_pool: false
    encoding: utf-8
    isolation_level: 'SERIALIZABLE'

section: This is the Root Section
parts:
  - section: This is Section 1
    parts:
      - section: This is Section 2, a subsection of Section 1
        op: initcluster
        params:
          superuser: '{{user1.name}}'
          superpassword: '{{user1.pwd}}'
          # or here also: rootuser: *rootname
          locale: C
          encoding: UTF8
          datadir: *datadir
          # or here also: datadir: '{{datadir1}}'

      - section: Create a User (DB Owner)
        op: createuser
        params:
          name: '{{user2.name}}'
          password: '{{user2.pwd}}'
          login: true
        options:
          connstr: engine0

      - section: Install
        op: createdb
        params:
          name: '{{database}}'
          owner: '{{user2.name}}'
          connection_limit: 30
        options:
          connstr: engine0


  - section: This is another section
    depends: This is Section 1
# OR - if more than one dependency
#   depends:
#     - This is Section 1
#     - Maybe another Section on which this section depends
    op: the_new_operation
    with:
      vars:
        a: '{{var1}}'
        b: 'file://{{user1.name|urlquote}}:{{user1.pwd | urlquote}}@localhost/'
#      cwd: 'E:\what{{a}}'


pool:
  - section: Start Cluster
    op: startcluster
    params:
      datadir: '{{datadir1}}'
      logfile: '{{datadir1}}/_log.log'

  - section: Stop Cluster
    op: stopcluster
    params:
      datadir: '{{datadir1}}'

  - section: Configure
    op: amendconfig
    args:
    - "log_connections = on"
    - "log_disconnections = on"
    - "log_line_prefix = '%m %u@%d %p %r '"
    params:
      datadir: '{{datadir1}}'

  - section: Exit
    op: exit
    params:
      exitcode: 0

  - section: Uninstall
    op: deletedb
    params:
      name: '{{database}}'
    options:
      connstr: engine0
