Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'UK' and column comments #7

Merged
merged 4 commits into from
Mar 20, 2024
Merged

Use 'UK' and column comments #7

merged 4 commits into from
Mar 20, 2024

Conversation

justintime
Copy link
Contributor

Mermaid supports a key type of 'UK' for unique key, better to use that instead of adding a comment. Also, if the SQLAlchemy column has a comment assigned, we should add that to the Mermaid comment.

Here's the output for a table has has both a unique key and a comment in SQLAlchemy after the changes in this pull request:

  games {
    INTEGER id PK
    INTEGER away_team_id FK
    INTEGER home_team_id FK
    INTEGER league_id FK "nullable"
    INTEGER season_id FK
    INTEGER tracked_team_id FK
    INTEGER user_id FK
    INTEGER away_score
    VARCHAR(255) cuid UK "These are generated by clients and should be unique"
    DATE game_date
    INTEGER home_score
    VARCHAR(255) location
    BOOLEAN overtime
    BOOLEAN shootout
  }

Mermaid supports a key type of 'UK' for unique key, better to use that instead of adding a comment. Also, if the SQLAlchemy column has a comment assigned, we should add that to the Mermaid comment.
@tedivm
Copy link
Owner

tedivm commented Mar 20, 2024

Can you fix the errors from testing? You should be able to pull down the branch and run make chores to do so.

@justintime
Copy link
Contributor Author

Can you fix the errors from testing? You should be able to pull down the branch and run make chores to do so.

Thanks for the make hint. I was able to get make chores run cleanly on that last commit. I also added a column comment on FK's that describes which table the column refers to. On my ERD with ~ 20 tables and tons of FK's, it can be tedius to trace lines.

@justintime
Copy link
Contributor Author

I can update the test suite as well, brb

Copy link
Owner

@tedivm tedivm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but I put a few comments in for changes. Thanks for putting this together!

@@ -29,15 +30,16 @@ def _column(self, column: Column) -> str:
column_str += " PK"
elif len(column.foreign_keys) > 0:
column_str += " FK"
options.append(f"Foreign key references {column.table.name}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this a separate pull request? I'm not sure I want this comment in there, especially when we have the relationships drawn out already with the diagram itself.


options = []
if column.comment:
options.append(f"{column.comment}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since column.comment is a string the f string and quotes are redundant-

In other words both of these lines are the same, so it should use the succinct one:

options.append(column.comment)
options.append(f"{column.comment}")

@@ -4,6 +4,7 @@
def test_mermaid(metaclass):
mermaid = Mermaid(metaclass=metaclass)
graph_string = str(mermaid)
print(graph_string)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You left a debugging statement here.

@tedivm tedivm merged commit 731fc7f into tedivm:main Mar 20, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants