File: render-pdb-schema

package info (click to toggle)
puppetdb 8.8.1-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 19,692 kB
  • sloc: javascript: 23,285; ruby: 5,620; sh: 3,457; python: 389; xml: 114; makefile: 38
file content (91 lines) | stat: -rwxr-xr-x 2,295 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash

set -euo pipefail

usage() {
    cat <<EOF
Usage: [PDB_JAR=JAR] $(basename "$0") [--pgbin PGBIN] [--pgport PGPORT] DEST"

  Write an SVG graph of the pdb schema to DEST.

  The pgbin and pgport settings will be picked up from the current
  tree if they've been set via test-config, and the pgbin setting may
  be guessed.  Otherwise, you'll need to specify them.

  The version of pdb will be the one run via ./pdb which defaults to
  the uberjar in target/.  

EOF
}

misuse() { usage 1>&2; exit 2; }

argv=("$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" "$@")
declare -A opt

while test $# -gt 0; do
    case "$1" in
        --pgbin|--pgport)
            test $# -gt 1 || misuse
            opt["${1:2}"]="$2"
            shift 2
            ;;
        *)
            break
            ;;
    esac
done

if test $# -ne 1; then
    misuse
fi
dest="$1"

if ! command -v postgresql_autodoc; then
    echo "postgresql_autodoc does not appear to be in the PATH"
    exit 2
fi

if ! command -v dot; then
    echo "graphviz dot does not appear to be in the PATH"
    exit 2
fi

if test -z "${opt[pgbin]:-}"; then
    opt[pgbin]="$(ext/bin/test-config --get pgbin)"
    if test  -z "${opt[pgbin]:-}"; then
        echo 'Please specify --pgbin or set pgbin with ext/bin/test-config' 1>&2
        exit 2
    fi
fi

if test -z "${opt[pgport]:-}"; then
    opt[pgport]="$(ext/bin/test-config --get pgport)"
     if test  -z "${opt[pgport]:-}"; then
        echo 'Please specify --pgport or set pgport with ext/bin/test-config' 1>&2
        exit 2
    fi
fi

set -x

if test -z "${PDBBOX:-}"; then
    # No PDBBOX, set one up and run ourselves again
    tmpdir="$(mktemp -d "render-pdb-schema-XXXXXX")"
    tmpdir="$(cd "$tmpdir" && pwd)"
    trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT
    # Don't exec (or we'll never run the trap)
    ext/bin/with-pdbbox --box "$tmpdir/box" \
                        --pgbin "${opt[pgbin]}" --pgport "${opt[pgport]}" \
                        -- "${argv[@]}"
    exit 0
fi

tmpdir="$(mktemp -d "test-upgrade-and-exit-XXXXXX")"
tmpdir="$(cd "$tmpdir" && pwd)"
trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT

./pdb upgrade -c "$PDBBOX/conf.d"

postgresql_autodoc -t dot -u puppetdb -d puppetdb -f "$tmpdir/pdb"
dot -Tsvg "$tmpdir/pdb.dot" -o "$dest"