fp/scripts/data-migrations/a.migration.sh

28 lines
899 B
Bash
Raw Normal View History

2024-11-05 19:48:21 +00:00
#!/bin/bash
postgres_pod_name=postgresql-primary-0
if [ -z $POSTGRES_PASSWORD ]; then
echo "POSTGRES_PASSWORD was missing in env. Please run using dotenvx or similar"
exit 5
fi
if [ -z "$1" ]
then
echo "Usage: a.migration.sh /path/to/migraiton.sql"
exit 6
fi
echo "create .pgpass file inside pod"
kubectl -n futureporn exec -i ${postgres_pod_name} -- bash -c "echo *:5432:*:postgres:${POSTGRES_PASSWORD} | tee /tmp/.pgpass"
kubectl -n futureporn exec -i ${postgres_pod_name} -- chmod 0600 /tmp/.pgpass
echo "Copying sql to pod"
kubectl -n futureporn cp ${1} ${postgres_pod_name}:/tmp/migration.sql
echo "Running ${1} inside the pod"
kubectl -n futureporn exec -i ${postgres_pod_name} -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres -d futureporn -f /tmp/migration.sql
echo "rm .pgpass file"
kubectl -n futureporn exec -i ${postgres_pod_name} -- rm -rf /tmp/.pgpass