transformations.sh 576 Bytes
#!/bin/bash

set -ex

touch /tmp/pgpass
chmod 0600 /tmp/pgpass
echo "*:*:*:*:CHANGEME" > /tmp/pgpass
export PGPASSFILE=/tmp/pgpass

_import() {
	psql -w -h ${POSTGRESQL_HOST} -U postgres "$1"
}

ls -alR /workspace
for file in /workspace/transformations/*; do
	[[ -e $file ]] || continue
	case "$file" in
		(*.sql.gz)
			database="$(basename "$file" .sql.gz)"
			zcat "$file" | _import "$database"
			;;
		(*.sql)
			database="$(basename "$file" .sql)"
			cat "$file" | _import "$database"
			;;
		(*.sh)
			"$file"
			;;
		(*)
			echo "Ignoring file: $file"
			;;
	esac
done