Skip to content

Instantly share code, notes, and snippets.

@marcusirgens
Last active October 21, 2020 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusirgens/6d45755f28505f4f213422c23a7f4a10 to your computer and use it in GitHub Desktop.
Save marcusirgens/6d45755f28505f4f213422c23a7f4a10 to your computer and use it in GitHub Desktop.
Create a throwaway postgres instance
function throwaway-postgres() {
local port
port="$((RANDOM%1000+40000))"
docker info >/dev/null || return 1
if ! docker run \
--rm \
--detach \
--publish "$port:5432" \
--env POSTGRES_DB=throwaway \
--env POSTGRES_PASSWORD=throwaway \
--env POSTGRES_USER=throwaway \
postgres:alpine >/dev/null; then
return 1
fi
if command -v pgwait > /dev/null; then
if ! pgwait -timeout 30 -port "$port" throwaway throwaway throwaway; then
return 1
fi
fi
open "postgresql://throwaway:throwaway@localhost:$port/throwaway?statusColor=DAEBC2&enviroment=test"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment