#!/bin/bash
set -euo pipefail
#==============================================================#
# File      :   schemaspy
# Desc      :   generate schemaspy report
# Ctime     :   2022-05-17
# Mtime     :   2022-05-17
# Path      :   bin/schemaspy
# Deps      :   ssh, docker: andrewjones/schemaspy-postgres:latest
# License   :   Apache-2.0 @ https://pigsty.io/docs/about/license/
# Copyright :   2018-2026  Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#


#--------------------------------------------------------------#
# Usage
#--------------------------------------------------------------#
# schemaspy [ip] [dbname] [schema] [outdir]
# view from https://i.pigsty/schema


NODE=${1-'10.10.10.10'}
DATABASE=${2-'meta'}
SCHEMA=${3-'public'}
OUTPUT_DIR="/www/schema/${DATABASE}/${SCHEMA}"

echo "generate report from NODE=${NODE} DB=${DATABASE} SCHEMA=${SCHEMA} to ${OUTPUT_DIR}"
# docker pull andrewjones/schemaspy-postgres:latest
docker run --name schemaspy --rm -v ${OUTPUT_DIR}:/output \
	andrewjones/schemaspy-postgres:latest \
	-host ${NODE} -port 5432 \
	-u dbuser_dba -p DBUser.DBA \
	-db ${DATABASE} -s ${SCHEMA}
