Merge ~cgrabowski/maas:add_pgmodeler_svg_generator into maas:master

Proposed by Christian Grabowski
Status: Merged
Approved by: Christian Grabowski
Approved revision: 173e8ab56f3578b4cd58d4652ec44a69b1563724
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~cgrabowski/maas:add_pgmodeler_svg_generator
Merge into: maas:master
Diff against target: 109 lines (+91/-1)
2 files modified
Makefile (+2/-1)
utilities/gen-db-schema-svg (+89/-0)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Alberto Donato (community) Approve
Review via email: mp+402776@code.launchpad.net

Commit message

add gen-db-schema-svg script
add check for display
add to lint-shell make target

Description of the change

This adds a utility script to generate a SVG of the DB schema for easy visualization of tables, relations between tables. indexes, etc.

To post a comment you must log in.
a8be60e... by Christian Grabowski

add print help

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b add_pgmodeler_svg_generator lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 6080e3fbf17a70351c618fe31754a1254d0409be

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b add_pgmodeler_svg_generator lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10075/console
COMMIT: 4bbb5962a9f393e4eef83fd3d37960fa38af2717

review: Needs Fixing
4ba0983... by Christian Grabowski

quote arg

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b add_pgmodeler_svg_generator lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10076/console
COMMIT: 4d588203bbf536ca34f7540d7878b31e65ef0038

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b add_pgmodeler_svg_generator lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10077/console
COMMIT: ce0d3f9988f5499890d1dad5cbf9cdbf85f946c0

review: Needs Fixing
Revision history for this message
Alberto Donato (ack) wrote :

nice, +1!

Just a few comments/nits inline (mostly coding style)

review: Approve
5653ed4... by Christian Grabowski

remove function keywords

835f880... by Christian Grabowski

simplify output dir creation

e57cdd8... by Christian Grabowski

use single square brackets

173e8ab... by Christian Grabowski

use -e instead of && chain

Revision history for this message
Christian Grabowski (cgrabowski) wrote :

Responded to one comment, making code changes for the rest of the feedback.

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b add_pgmodeler_svg_generator lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 173e8ab56f3578b4cd58d4652ec44a69b1563724

review: Approve

Update scan failed

At least one of the branches involved have failed to scan. You can manually schedule a rescan if required.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/Makefile b/Makefile
index 5172f7d..76a2f6c 100644
--- a/Makefile
+++ b/Makefile
@@ -194,7 +194,8 @@ lint-shell: bin/shellcheck
194 snap/hooks/* \194 snap/hooks/* \
195 snap/local/tree/bin/* \195 snap/local/tree/bin/* \
196 snap/local/tree/sbin/* \196 snap/local/tree/sbin/* \
197 utilities/release-*197 utilities/release-* \
198 utilities/gen-db-schema-svg
198.PHONY: lint-shell199.PHONY: lint-shell
199200
200format.parallel:201format.parallel:
diff --git a/utilities/gen-db-schema-svg b/utilities/gen-db-schema-svg
201new file mode 100755202new file mode 100755
index 0000000..02bec98
--- /dev/null
+++ b/utilities/gen-db-schema-svg
@@ -0,0 +1,89 @@
1#!/bin/bash -e
2
3OUTPUT_DIR=${OUTPUT_DIR:-"../tmp"}
4OUTPUT_FILE=${OUTPUT_FILE:-"${OUTPUT_DIR}/db-schema.svg"}
5TMP_DBM=${TMP_DBM:-"${OUTPUT_DIR}/maas.dbm"}
6PG_HOST=${PG_HOST:-localhost}
7PG_PORT=${PG_PORT:-5432}
8PG_DB="maasdb"
9PG_USER=${PG_USER:-maas}
10PG_PASSWORD=${PG_PASSWORD:-""}
11
12print_help () {
13 cat <<EOF
14gen-db-schema-svg
15
16Generates a svg of the database schema, including relations and indexes.
17Requires pgmodeler is installed and DISPLAY must be set.
18
19Variables:
20
21OUTPUT_DIR The directory to output the svg to, defaults to '../tmp'
22OUTPUT_FILE The path to the output file, defaults to '\$\{OUTPUT_DIR\}/db-schema.svg'
23TMP_DBM The path to the intermittent dbm file, gets removed after the svg is generated, defaults to '\$\{OUTPUT_DIR\}/maas.dbm'
24PG_HOST The IP or hostname to connect to postgres with, defaults to 'localhost'
25PG_PORT The port to connect to postgres with, defaults to '5432'
26PG_DB The database to connect to and generate schema of, defaults to 'maasdb'
27PG_USER The user to authenticate to postgres with, defaults to 'maas'
28PG_PASSWORD The password to authenticate to postgres with, must be set
29EOF
30}
31
32check_for_pg_modeler () {
33 if [ -z "$(which pgmodeler-cli)" ]; then
34 echo "please install pgmodeler in order to run this script" && exit 2
35 fi
36}
37
38check_pg_password_is_set () {
39 if [ -z "${PG_PASSWORD}" ]; then
40 echo "please set PG_PASSWORD in order to run this script" && exit 2
41 fi
42}
43
44check_display_set () {
45 if [ -z "${DISPLAY}" ]; then
46 echo "pgmodeler requires a display to run" && exit 2
47 fi
48}
49
50create_output_dir_if_not_exist () {
51 mkdir -p "${OUTPUT_DIR}"
52}
53
54gen_dbm () {
55 pgmodeler-cli --import-db --input-db "${PG_DB}"\
56 --host "${PG_HOST}" --port "${PG_PORT}"\
57 --user "${PG_USER}" --passwd "${PG_PASSWORD}"\
58 -D "${PG_DB}" --output "${TMP_DBM}"
59}
60
61gen_svg () {
62 pgmodeler-cli --host "${PG_HOST}" --port "${PG_PORT}"\
63 --user "${PG_USER}" --passwd "${PG_PASSWORD}"\
64 -D "${PG_DB}" --output "${OUTPUT_FILE}"\
65 --input "${TMP_DBM}" --export-to-svg
66}
67
68remove_dbm () {
69 rm "${TMP_DBM}"
70}
71
72main () {
73 case $1 in
74 -h | --help)
75 print_help
76 ;;
77 *)
78 check_for_pg_modeler
79 check_pg_password_is_set
80 check_display_set
81 create_output_dir_if_not_exist
82 gen_dbm
83 gen_svg
84 remove_dbm
85 ;;
86 esac
87}
88
89main "$1"

Subscribers

People subscribed via source and target branches