Skip to content

Commit

Permalink
Merge pull request #23 from LittleDan9/transformer-schema-support
Browse files Browse the repository at this point in the history
Adjusting the transformers for schema support
  • Loading branch information
tedivm authored Sep 26, 2024
2 parents 33adc44 + aa436f3 commit 455e0fc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions paracelsus/transformers/dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")

Expand Down
6 changes: 3 additions & 3 deletions paracelsus/transformers/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def dot_full_string_preseve_column_sort() -> str:
<tr><td align="left">VARCHAR(100)</td><td align="left">display_name</td><td></td></tr>
<tr><td align="left">DATETIME</td><td align="left">created</td><td></td></tr>
</table>
>, margin=0, shape=none];
>, shape=none, margin=0];
posts [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td colspan="3" bgcolor="lightblue"><b>posts</b></td></tr>
Expand All @@ -105,8 +105,8 @@ def dot_full_string_preseve_column_sort() -> str:
<tr><td align="left">BOOLEAN</td><td align="left">live</td><td></td></tr>
<tr><td align="left">TEXT</td><td align="left">content</td><td></td></tr>
</table>
>, 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=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td colspan="3" bgcolor="lightblue"><b>comments</b></td></tr>
Expand All @@ -117,8 +117,8 @@ def dot_full_string_preseve_column_sort() -> str:
<tr><td align="left">BOOLEAN</td><td align="left">live</td><td></td></tr>
<tr><td align="left">TEXT</td><td align="left">content</td><td></td></tr>
</table>
>, 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];
}
"""
6 changes: 3 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def dot_assert(output: str) -> None:
assert '<tr><td colspan="3" bgcolor="lightblue"><b>posts</b></td></tr>' in output
assert '<tr><td colspan="3" bgcolor="lightblue"><b>comments</b></td></tr>' 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 '<tr><td align="left">CHAR(32)</td><td align="left">author</td><td>Foreign Key</td></tr>' in output
assert '<tr><td align="left">CHAR(32)</td><td align="left">post</td><td>Foreign Key</td></tr>' in output
Expand Down

0 comments on commit 455e0fc

Please sign in to comment.