Skip to content

Instantly share code, notes, and snippets.

@davidoram
Last active May 31, 2018
Embed
What would you like to do?
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

davidoram commented May 29, 2018

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