#!/bin/sh
set -e

export PGPASSWORD="{{cfg.datastore.password}}"

if [ $(psql -lw -U hab -h {{bind.datastore.first.sys.ip}} | grep {{cfg.datastore.database}} | wc -l) -eq 0 ]; then
  createdb -w -h {{bind.datastore.first.sys.ip}} -p {{bind.datastore.first.cfg.port}} -U hab {{cfg.datastore.database}}
fi

bldr-originsrv migrate -c {{pkg.svc_config_path}}/config.toml
