#! /bin/sed -f
1i\
/** @page database Database Schema\
\
@dot\
digraph schema {
# remove newlines
:a;N;$!ba;s/\n/ /g
# reduce spaces
s, \+, ,g
s| *CREATE *TABLE *\(if *not *exists\)\? *`\?\([a-z]\+\)`\? *|\n \2\n [shape=none, margin=0, label=<\n
\n \2 |
\n|ig
s/varchar *( *\([0-9]\+\) *)/varchar[\1]/ig
s/ *PRIMARY KEY *( *`\?\([a-z]\+\)`\? *) *[,)]//ig
:b;s/\([a-z]\+\)\([^;]*\)FOREIGN KEY *( *`\?\([a-z]\+\)`\? *) *REFERENCES *`\?\([a-z]\+\)`\? *( *`\?\([a-z]\+\)`\? *) *\([^,)]*\)[,)]\(.*\)/\1\2\7\n \1:\3 -> \4:\5/ig;tb
:c;s|\n[(,] *`\?\([a-z]\+\)`\? *\([^ ]\+\)*\([^,)]*\) *COMMENT *[`"']\([^`"']*\)[`"'] *[,)]|\n \1 | \2 | \3 | \4 |
\n,|ig;tc
s| \+||g
s| \+| | |g
s|\( | ]*>[^<]\{30,40\}\) \+\([^<]\{20,\} | \)|\1
\2|g
:d;s|\(
[^<]\{30,40\}\) \+\([^<]\{20,\}\)|\1
\2|g;td
s| *COMMENT *= *["']\?\([^"']*\)["']\?|\n \1 |
|ig
s| \+||g
s| \+| | |g
s|\( | ]*>[^<]\{60,80\}\) \+\([^<]\{30,\} | \)|\1
\2|g
:e;s|\(
[^<]\{60,80\}\) \+\([^<]\{30,\}\)|\1
\2|g;te
s/\n,[^\n]*/\n/g
s|;|\n
\n >];\n|ig
$a\
}\
@enddot\
*/