#! /bin/sed -f
1idigraph schema {
# remove newlines
:a;N;$!ba;s/\n/ /g
s| *CREATE TABLE[^("'`]*[`"']\?\([a-z]\+\)[`"']\? *|\n \1\n [shape=none, margin=0, label=<\n
\n \1 |
\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
s| *COMMENT *= *[`"']\?\([^`"']*\)[`"']\?| \1 |
|ig
s| *[`"']\([a-z]\+\)[`"'] *\([^,)]*\) *COMMENT *[`"']\([^`"']*\)[`"'] *[,)]| \1 | \2 | \3 |
\n|ig
s/ *ENGINE *= *\w* *//ig
s/ *DEFAULT *CHARSET *= *\w* *//ig
s/ *CHARACTER *SET *=\? *\w* *//ig
s|;|\n
\n >];\n|ig
s/(//ig
$a}