28 lines
899 B
Bash
Executable File
28 lines
899 B
Bash
Executable File
#!/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 |