Skip to content

Commit

Permalink
Merge pull request #7 from justintime/patch-1
Browse files Browse the repository at this point in the history
Use 'UK' and column comments
  • Loading branch information
tedivm authored Mar 20, 2024
2 parents df6ebce + 41b3a19 commit 731fc7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions paracelsus/transformers/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _table(self, table: Table) -> str:
return output

def _column(self, column: Column) -> str:
options = []
column_str = f"{column.type} {column.name}"

if column.primary_key:
Expand All @@ -29,15 +30,15 @@ def _column(self, column: Column) -> str:
column_str += " PK"
elif len(column.foreign_keys) > 0:
column_str += " FK"
elif column.unique:
column_str += " UK"

options = []
if column.comment:
options.append(column.comment)

if column.nullable:
options.append("nullable")

if column.unique:
options.append("unique")

if column.index:
options.append("indexed")

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Post(Base):
id = mapped_column(Uuid, primary_key=True, default=uuid4())
author = mapped_column(ForeignKey(User.id), nullable=False)
created = mapped_column(DateTime, nullable=False, default=datetime.utcnow())
live = mapped_column(Boolean, default=False)
live = mapped_column(Boolean, default=False, comment="True if post is published")
content = mapped_column(Text, default="")

class Comment(Base):
Expand Down
1 change: 1 addition & 0 deletions tests/transformers/test_mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ def test_mermaid(metaclass):

assert "CHAR(32) author FK" in graph_string
assert 'CHAR(32) post FK "nullable"' in graph_string
assert 'BOOLEAN live "True if post is published,nullable"' in graph_string
assert "DATETIME created" in graph_string

0 comments on commit 731fc7f

Please sign in to comment.