Last active
October 21, 2020 14:43
-
-
Save marcusirgens/6d45755f28505f4f213422c23a7f4a10 to your computer and use it in GitHub Desktop.
Create a throwaway postgres instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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