diff --git a/paracelsus/transformers/dot.py b/paracelsus/transformers/dot.py index 4b90a89..879ba06 100644 --- a/paracelsus/transformers/dot.py +++ b/paracelsus/transformers/dot.py @@ -28,8 +28,8 @@ def __init__(self, metaclass: MetaData, column_sort: str) -> None: for column in table.columns: for foreign_key in column.foreign_keys: key_parts = foreign_key.target_fullname.split(".") - left_table = key_parts[0] - left_column = key_parts[1] + left_table = ".".join(key_parts[:-1]) + left_column = key_parts[-1] # We don't add the connection to the fk table if the latter # is not included in our graph. @@ -40,7 +40,7 @@ def __init__(self, metaclass: MetaData, column_sort: str) -> None: ) continue - edge = pydot.Edge(left_table, table.name) + edge = pydot.Edge(left_table.split(".")[-1], table.name) edge.set_label(column.name) edge.set_dir("both") diff --git a/paracelsus/transformers/mermaid.py b/paracelsus/transformers/mermaid.py index df92674..ac3a8a9 100644 --- a/paracelsus/transformers/mermaid.py +++ b/paracelsus/transformers/mermaid.py @@ -66,8 +66,8 @@ def _relationships(self, column: Column) -> str: for foreign_key in column.foreign_keys: key_parts = foreign_key.target_fullname.split(".") - left_table = key_parts[0] - left_column = key_parts[1] + left_table = ".".join(key_parts[:-1]) + left_column = key_parts[-1] left_operand = "" # We don't add the connection to the fk table if the latter @@ -85,7 +85,7 @@ def _relationships(self, column: Column) -> str: else: left_operand = "}o" - output += f" {left_table} {left_operand}--{right_operand} {right_table} : {column_name}\n" + output += f" {left_table.split('.')[-1]} {left_operand}--{right_operand} {right_table} : {column_name}\n" return output def __str__(self) -> str: diff --git a/tests/conftest.py b/tests/conftest.py index 1ac4664..3d21ab7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -95,7 +95,7 @@ def dot_full_string_preseve_column_sort() -> str: VARCHAR(100)display_name DATETIMEcreated ->, margin=0, shape=none]; +>, shape=none, margin=0]; posts [label=< @@ -105,8 +105,8 @@ def dot_full_string_preseve_column_sort() -> str:
posts
BOOLEANlive
TEXTcontent
->, margin=0, shape=none]; -users -- posts [arrowhead=crow, arrowtail=none, dir=both, label=author]; +>, shape=none, margin=0]; +users -- posts [label=author, dir=both, arrowhead=crow, arrowtail=none]; comments [label=< @@ -117,8 +117,8 @@ def dot_full_string_preseve_column_sort() -> str:
comments
BOOLEANlive
TEXTcontent
->, margin=0, shape=none]; -posts -- comments [arrowhead=crow, arrowtail=none, dir=both, label=post]; -users -- comments [arrowhead=crow, arrowtail=none, dir=both, label=author]; +>, shape=none, margin=0]; +posts -- comments [label=post, dir=both, arrowhead=crow, arrowtail=none]; +users -- comments [label=author, dir=both, arrowhead=crow, arrowtail=none]; } """ diff --git a/tests/utils.py b/tests/utils.py index 403fdaf..0e00b3b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -18,9 +18,9 @@ def dot_assert(output: str) -> None: assert 'posts' in output assert 'comments' in output - assert "users -- posts [arrowhead=crow, arrowtail=none, dir=both, label=author];" in output - assert "posts -- comments [arrowhead=crow, arrowtail=none, dir=both, label=post];" in output - assert "users -- comments [arrowhead=crow, arrowtail=none, dir=both, label=author];" in output + assert "users -- posts [label=author, dir=both, arrowhead=crow, arrowtail=none];" in output + assert "posts -- comments [label=post, dir=both, arrowhead=crow, arrowtail=none];" in output + assert "users -- comments [label=author, dir=both, arrowhead=crow, arrowtail=none];" in output assert 'CHAR(32)authorForeign Key' in output assert 'CHAR(32)postForeign Key' in output