1414print ('' )
1515# generate entity tables
1616for table in catalog .tables :
17- print (' ' + table .fullName + ' {' )
17+ tableFullName = re .sub ("[\" \' ]" , "" , table .fullName ).replace (" " ,"_" )
18+ print (' ' + tableFullName + ' {' )
1819 for column in table .columns :
1920 # // need to remove quotes and spaces
2021 # get all column attributes for debugging
4748# generate relationships, need to display keys in the description for sql generation
4849# https://www.tabnine.com/code/java/methods/schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder/includeGreppedColumns
4950for table in catalog .tables :
51+ tableOriginal = re .sub ("[\" \' ]" , "" , table .fullName )
52+ tableFullName = tableOriginal .replace (" " ,"_" )
53+ # print (tableFullName)
54+ addSpace = False
5055 for foreignKeys in table .foreignKeys :
51- relationshipTxt = str (foreignKeys .primaryKeyTable .primaryKey .columns ) + " to " + str (foreignKeys .columns )
52- relationshipTxt = "\" " + re .sub ("[\" ]" , "\' " , relationshipTxt ) + "\" "
53- print (' ' + table .fullName + ' ||--o{ ' + str (foreignKeys .foreignKeyTable ) + ' : ' + relationshipTxt )
54- print ('' )
56+ fkTableOriginal = str (foreignKeys .primaryKeyTable )
57+ fkTableFullName = fkTableOriginal .replace (" " , "_" )
58+ if (tableFullName != fkTableFullName ):
59+ addSpace = True
60+ relationshipTxt = str (foreignKeys .primaryKeyTable .primaryKey .columns ) + " to " + str (foreignKeys .columns )
61+ relationshipTxt = "\" " + re .sub ("[\" ]" , "\' " , relationshipTxt ) + "\" "
62+ relationshipTxt = relationshipTxt .replace (tableOriginal ,tableFullName ).replace (fkTableOriginal , fkTableFullName )
63+ # str(foreignKeys.foreignKeyTable)
64+ print (' ' + fkTableOriginal + ' ||--o{ ' + tableFullName + ' : ' + relationshipTxt )
65+ if (addSpace ):
66+ print ('' )
5567# old way
56- for table in catalog .tables :
57- for childTable in table .getRelatedTables (TableRelationshipType .child ):
58- print (' ' + table .name + ' ||--o{ ' + childTable .name + ' : "foreign key"' )
59- print ('' )
60- print ('```' )
68+ # for table in catalog.tables:
69+ # for childTable in table.getRelatedTables(TableRelationshipType.child):
70+ # print(' ' + table.name + ' ||--o{ ' + childTable.name + ' : "foreign key"')
71+ # print('')
72+ # print('```')
0 commit comments