-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_erd.py
53 lines (31 loc) · 1.16 KB
/
generate_erd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sys
import os
# This makes the file executable
if os.environ.get('PROJECT_PATH'):
sys.path.append(os.environ.get('PROJECT_PATH'))
from pathlib import Path
import datetime
from sqlalchemy_schemadisplay import create_schema_graph
# db stuff
from database import metadata
def create_db_ERD():
# Create a path to store your ERD
dt_now = datetime.datetime.now()
dt_now = dt_now.strftime('%Y-%m-%d %H:%M:%S')
save_path = Path(f'tmp/ERDs/Test Database ERD – {dt_now}.png')
# Make the dir if you need to
os.makedirs(os.path.dirname(save_path), exist_ok=True)
# - - - - - - - - - - - - - - - - - - - - - - - - -
graph = create_schema_graph(
metadata=metadata,
show_datatypes=True,
show_indexes=True,
rankdir='TB', # From left to right (instead of top to bottom)
concentrate=True, # Don't try to join the relation lines together
)
graph.write_png(save_path)
# - - - - - - - - - - - - - - - - - - - - - - - - -
print(f'Created an ERD for your curr db here: "{save_path}"')
if __name__ == '__main__':
create_db_ERD()
#