Skip to content

Instantly share code, notes, and snippets.

@davidoram
Last active May 31, 2018 01:44
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 davidoram/60dd55b2ef94aaad2484d916a71fc969 to your computer and use it in GitHub Desktop.
Save davidoram/60dd55b2ef94aaad2484d916a71fc969 to your computer and use it in GitHub Desktop.
Run dockerised schemaspy against a postgres database
#!/bin/bash
#
# - Run dockerised schemaspy against a postgres db
# - write the output to a host directory
# - Opens the generated website in your broswer
#
# Assumes you have already got the schemaspy docker image eg: `docker pull schemaspy/schemaspy:snapshot`
#
set -e
if [ $# -ne 6 ]; then
echo "Usage:"
echo ""
echo " `basename $0` <username> <password> <db> <host> <port> <directory>"
echo ""
echo "For example:"
echo ""
echo " `basename $0` postgres password my_db docker.for.mac.localhost 5432 tmp/schemspy"
echo ""
echo "Will create the schemaspy docs for a database, then open those docs on your browser"
echo ""
exit
fi
TYPE=pgsql
USER=$1
PASSWORD=$2
DB=$3
HOST=$4
PORT=$5
mkdir -p $6
# Docker doesn't allow relative paths in Volumes
DIR=$(cd "$(dirname "$6")"; pwd)/$(basename "$6")
docker run -v "${DIR}:/output" schemaspy/schemaspy:snapshot -u ${USER} -p ${PASSWORD} -t ${TYPE} -db ${DB} -host ${HOST} -port ${PORT} -all -hq -ruby
open ${DIR}/index.html
@davidoram
Copy link
Author

Fixed a bug - Crashed if output directory didn't exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment