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

Preview Diff

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

Subscribers

People subscribed via source and target branches