fschulze / sqlalchemy_schemadisplay

Other
143 stars 37 forks source link

Display table's schema in diagram #24

Closed RagingRoosevelt closed 2 years ago

RagingRoosevelt commented 3 years ago

If the metadata for the declarative base doesn't include a schema but schema is specified for each table, it is possible that different tables will have different schemas:

from sqlalchemy import MetaData
from sqlalchemy.ext.declarative import declarative_base

meta_data = MetaData()
dec_base = declarative_base(metadata=meta_data)

schemaA = {"schema": "schema_a"}
schemaB = {"schema": "schema_b"}

class Tab_A(dec_base):
    __tablename__ = 'tab_a'
    __table_args__ = (schemaA , )
    ...

class Tab_B(dec_base):
    __tablename__ = 'tab_b'
    __table_args__ = (schemaB , )
    ...

class Tab_C(dec_base):
    __tablename__ = 'tab_c'
    __table_args__ = (schemaB , )
    ...

In such a scenario, it would be nice to be able to view schemas when generating the diagram:

from sqlalchemy_schemadisplay import create_schema_graph
graph = create_schema_graph(metadata=meta_data)

Conceivably, it could be handy to also be able to either specify a per-schema color for the border of each of the member tables, or to place all the tables for a particular schema within a rectangle for that schema (where you could have a different background color for each of the containing rectangles).

RagingRoosevelt commented 2 years ago

Closed by #26