#!/usr/bin/env bash

set -euo pipefail

if [[ -z "${1:-}" || "$1" == '--help' || "$1" == '-h' ]]; then
  echo "Usage: $0 MIGRATION_FILE"
  exit 1
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Prod
# USER=ingest_tracker
# PWD=$(vault read -field=value secret/ingest_tracker/production-us-west-1/postgres_password)
# HOST=internal-postgres.cp4rxnpmuhoe.us-west-1.rds.amazonaws.com
# PORT=5432
# DB=ingest_tracker

# Dev
USER=zoox
PWD=zoox2015
HOST=localhost
PORT=5432
DB=ingest_tracker_local

PGPASSWORD=$PWD psql \
  --host $HOST \
  --port $PORT \
  --username $USER \
  --file $1 \
  $DB
