From e73b2c8aaedd1678abc78ad40561bb7348652ea3 Mon Sep 17 00:00:00 2001 From: "Daniel R. Little" Date: Wed, 25 Sep 2024 23:10:50 -0400 Subject: [PATCH 1/3] Adjusting the transformers to not assume there is only [table_name].[column_name] --- paracelsus/transformers/dot.py | 4 ++-- paracelsus/transformers/mermaid.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/paracelsus/transformers/dot.py b/paracelsus/transformers/dot.py index 4b90a89..1b55c92 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. diff --git a/paracelsus/transformers/mermaid.py b/paracelsus/transformers/mermaid.py index df92674..4650797 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 From 0a0611043f5125aa94e280f3f667fa3d3684b5a7 Mon Sep 17 00:00:00 2001 From: "Daniel R. Little" Date: Thu, 26 Sep 2024 00:11:33 -0400 Subject: [PATCH 2/3] Fixing the rendering of the graph to not use schema when produing relationships --- paracelsus/transformers/dot.py | 2 +- paracelsus/transformers/mermaid.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/paracelsus/transformers/dot.py b/paracelsus/transformers/dot.py index 1b55c92..10d5c8b 100644 --- a/paracelsus/transformers/dot.py +++ b/paracelsus/transformers/dot.py @@ -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 4650797..2aaacc0 100644 --- a/paracelsus/transformers/mermaid.py +++ b/paracelsus/transformers/mermaid.py @@ -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: From aa436f356ac5ee8e976eb636a89715dc3c9659fa Mon Sep 17 00:00:00 2001 From: "Daniel R. Little" Date: Thu, 26 Sep 2024 12:04:00 -0400 Subject: [PATCH 3/3] Formatting and Tests Update --- paracelsus/transformers/dot.py | 4 ++-- paracelsus/transformers/mermaid.py | 2 +- tests/conftest.py | 12 ++++++------ tests/utils.py | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/paracelsus/transformers/dot.py b/paracelsus/transformers/dot.py index 10d5c8b..879ba06 100644 --- a/paracelsus/transformers/dot.py +++ b/paracelsus/transformers/dot.py @@ -28,7 +28,7 @@ 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 = '.'.join(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 @@ -40,7 +40,7 @@ def __init__(self, metaclass: MetaData, column_sort: str) -> None: ) continue - edge = pydot.Edge(left_table.split('.')[-1], 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 2aaacc0..ac3a8a9 100644 --- a/paracelsus/transformers/mermaid.py +++ b/paracelsus/transformers/mermaid.py @@ -66,7 +66,7 @@ def _relationships(self, column: Column) -> str: for foreign_key in column.foreign_keys: key_parts = foreign_key.target_fullname.split(".") - left_table = '.'.join(key_parts[:-1]) + left_table = ".".join(key_parts[:-1]) left_column = key_parts[-1] left_operand = "" 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