mirror of
https://github.com/fleetbase/fleetbase.git
synced 2025-12-19 14:18:57 +00:00
now use schemacrawler in conjunction to generate database.mmd as well as erd diagrams
This commit is contained in:
13
create-erd.sh
Normal file
13
create-erd.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit the script as soon as a command fails
|
||||
set -e
|
||||
|
||||
# Run schemacrawler
|
||||
# To use schemacrawler see https://www.schemacrawler.com/downloads.html
|
||||
schemacrawler.sh --server mysql --host localhost --database fleetbase --user root --info-level standard --command script --script-language python --script mermaid.py --output-file database.mmd
|
||||
schemacrawler.sh --server mysql --host localhost --database fleetbase --user root --info-level standard --command=schema --grep-tables="^(?!fleetbase_sandbox\.).*" --output-format=svg --output-file=erd.svg
|
||||
|
||||
# Generate a SVG ERD diagram using `dark` theme
|
||||
# To use mmdc see https://github.com/mermaid-js/mermaid-cli
|
||||
mmdc -i database.mmd -o erd-dark.svg -t dark -b transparent --configFile="mmdc.json"
|
||||
1676
database.mmd
Normal file
1676
database.mmd
Normal file
File diff suppressed because it is too large
Load Diff
1
erd-dark.svg
Normal file
1
erd-dark.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 1.3 MiB |
6804
erd.svg
Normal file
6804
erd.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 726 KiB |
43
mermaid.py
Normal file
43
mermaid.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from __future__ import print_function
|
||||
import re
|
||||
|
||||
def cleanname(name):
|
||||
return re.sub(r'[^\d\w_]', '', name)
|
||||
|
||||
def format_table_name(full_name):
|
||||
parts = full_name.split('.')
|
||||
if len(parts) == 2 and not parts[0].endswith('_sandbox'):
|
||||
return cleanname(parts[0] + '_' + parts[1])
|
||||
else:
|
||||
return None
|
||||
|
||||
print('erDiagram')
|
||||
print('')
|
||||
for table in catalog.tables:
|
||||
formatted_name = format_table_name(table.fullName)
|
||||
if formatted_name:
|
||||
print(' ' + formatted_name + ' {')
|
||||
for column in table.columns:
|
||||
print(' ' + cleanname(column.columnDataType.name) + ' ' + cleanname(column.name),
|
||||
end='')
|
||||
if column.isPartOfPrimaryKey():
|
||||
print(' PK', end='')
|
||||
elif column.isPartOfForeignKey():
|
||||
print(' FK', end='')
|
||||
elif column.isPartOfUniqueIndex():
|
||||
print(' UK', end='')
|
||||
if column.hasRemarks():
|
||||
print(' "' + ' '.join(column.remarks.splitlines()) + '"',
|
||||
end='')
|
||||
print()
|
||||
print(' }')
|
||||
print('')
|
||||
|
||||
for table in catalog.tables:
|
||||
formatted_name = format_table_name(table.fullName)
|
||||
if formatted_name:
|
||||
for childTable in table.referencingTables:
|
||||
child_formatted_name = format_table_name(childTable.fullName)
|
||||
if child_formatted_name:
|
||||
print(' ' + formatted_name + ' ||--o{ ' +
|
||||
child_formatted_name + ' : "foreign key"')
|
||||
Reference in New Issue
Block a user