Skip to content

Commit

Permalink
Merge pull request #33 from Software-Developers-IRL/f/lastlink
Browse files Browse the repository at this point in the history
improved er diagram details
  • Loading branch information
lastlink authored Oct 1, 2022
2 parents 6829c27 + 7962688 commit 95e0014
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions samples/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
print('```mermaid')
print('erDiagram')
print('')
# generate entity tables
for table in catalog.tables:
print(' ' + table.fullName + ' {')
for column in table.columns:
Expand All @@ -28,20 +29,30 @@
# isPartOfIndex
# isPartOfUniqueIndex
keyType = " PK" if column.partOfPrimaryKey else ""
if(keyType != "" and column.partOfForeignKey ):
if(keyType == "" and column.partOfForeignKey ):
keyType = " FK"
# dont need to define FK can get through relationships
# keyType += ("" if keyType == "" else ",") + "FK" if column.partOfForeignKey else ""
extraAttributes = ""
if(columnFullName != ""):
extraAttributes += columnFullName

if(not column.nullable):
extraAttributes += " NOT NULL"
if(extraAttributes != ""):
extraAttributes = " \"" + extraAttributes + "\""
extraAttributes = " \"" + extraAttributes.strip() + "\""
print(' ' + re.sub("[,]", "_",re.sub(r'[()]', '', column.columnDataType.name)) + ' ' + columnShortName + keyType + extraAttributes)
print(' }')
print('')

# generate relationships, need to display keys in the description for sql generation
# https://www.tabnine.com/code/java/methods/schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder/includeGreppedColumns
for table in catalog.tables:
for foreignKeys in table.foreignKeys:
relationshipTxt = str(foreignKeys.primaryKeyTable.primaryKey.columns) + " to " + str(foreignKeys.columns)
relationshipTxt = "\"" + re.sub("[\"]", "\'", relationshipTxt) + "\""
print(' ' + table.fullName + ' ||--o{ ' + str(foreignKeys.foreignKeyTable) + ' : '+ relationshipTxt)
print('')
# old way
for table in catalog.tables:
for childTable in table.getRelatedTables(TableRelationshipType.child):
print(' ' + table.name + ' ||--o{ ' + childTable.name + ' : "foreign key"')
Expand Down

0 comments on commit 95e0014

Please sign in to comment.