read -p "Are you sure you want to load DB from dump? (y/N) " -n 1 -r
echo

DUMP_LOCATION=./../uat.dump

if [ ! -f "$DUMP_LOCATION" ]; then
  echo "Dump does not exist in $DUMP_LOCATION"
  exit 1
fi

if [[ $REPLY =~ ^[Yy]$ ]]; then
  docker exec -it db psql -U postgres -c "DROP SCHEMA public CASCADE;"
  docker exec -it db psql -U postgres -c "CREATE SCHEMA public;"
  docker exec -it db psql -U postgres -c "DROP ROLE IF EXISTS uat_mrktng_user; CREATE ROLE uat_mrktng_user;"
  docker exec -it db psql -U postgres -c "DROP ROLE IF EXISTS uat_deploy_user; CREATE ROLE uat_deploy_user;"
  docker exec -it db psql -U postgres -c "DROP ROLE IF EXISTS uat_mrktng_owner; CREATE ROLE uat_mrktng_owner;"

  docker cp $DUMP_LOCATION db:uat.dump

  docker exec -it db psql -U postgres -f /uat.dump postgres

  docker exec -it db rm -rf /uat.dump

  echo "Done"
fi
