Commit 53a9e39c authored by Thanassis Tsiodras's avatar Thanassis Tsiodras
Browse files

Add a new utility in DMT, to create a diagram from the PostgreSQL DB.

parent f6a77f0b
Pipeline #5086 passed with stage
in 3 minutes and 20 seconds
#!/usr/bin/env python3
import sys
from sqlalchemy import MetaData
from sqlalchemy_schemadisplay import create_schema_graph
def main():
if len(sys.argv) < 2:
print("Usage: " + sys.argv[0] + ' <database_name>')
sys.exit(1)
# create the pydot graph object by autoloading all tables via a bound metadata object
graph = create_schema_graph(
metadata=MetaData(
'postgresql+psycopg2://taste:tastedb@localhost/' + sys.argv[1]),
show_datatypes=False, # The image would get too big if we'd show the datatypes
show_indexes=False, # ditto for indexes
rankdir='LR', # From left to right (instead of top to bottom)
concentrate=True # Don't try to join the relation lines together
)
graph.write_png(sys.argv[1] + '.png') # write out the file
if __name__ == "__main__":
main()
......@@ -42,7 +42,8 @@ setup(
'msgPrinter = dmt.msgPrinter:main',
'msgPrinterASN1 = dmt.msgPrinterASN1:main',
'smp2asn = dmt.smp2asn:main',
'dmt = dmt.commonPy:print_version'
'dmt = dmt.commonPy:print_version',
'taste-db-diagram = dmt.diagram:main'
]
}
)
#!/usr/bin/env python3
import sys
from sqlalchemy import MetaData
from sqlalchemy_schemadisplay import create_schema_graph
if len(sys.argv) < 2:
print("Usage: " + sys.argv[0] + ' <database_name>')
sys.exit(1)
# create the pydot graph object by autoloading all tables via a bound metadata object
graph = create_schema_graph(
metadata=MetaData(
'postgresql+psycopg2://taste:tastedb@localhost/' + sys.argv[1]),
show_datatypes=False, # The image would get too big if we'd show the datatypes
show_indexes=False, # ditto for indexes
rankdir='LR', # From left to right (instead of top to bottom)
concentrate=True # Don't try to join the relation lines together
)
graph.write_png(sys.argv[1] + '.png') # write out the file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment