createerm.py
author Sandro Knauß <bugs@sandroknauss.de>
Tue, 15 Apr 2025 01:20:56 +0200
changeset 313 a88add2b3eea
parent 294 0e75bd39767d
permissions -rw-r--r--
use sqlalchemy_schemadisplay module

# Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net>
# 
# This file is part of Iro.
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
# #Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from iro.model import schema

tables = schema.Base.metadata.sorted_tables

tables_cls={}
for i in dir(schema):
    if i.startswith("__") or i == "Base":
        continue
    try:
        a = getattr(schema,i)
        tables_cls[a.__tablename__] = a
    except AttributeError:
        pass


#schema plot
def createSchemaPlot(fname):
    from sqlalchemy_schemadisplay import create_schema_graph
    graph = create_schema_graph(engine=None,
        metadata=schema.Base.metadata,
        tables=tables,
        show_datatypes=True, # The image too large if datatypes shown
        show_indexes=True, # 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.set_size('6.5,10')
    #graph.set_ratio("fill")
    graph.write_svg(fname)