Skip to content

Commit 77d5d91

Browse files
authored
Merge pull request #102 from NHSDigital/add-schema-diagrams
Add entity relationship diagram generation
2 parents b322560 + df146fb commit 77d5d91

6 files changed

Lines changed: 201 additions & 12 deletions

File tree

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ repos:
77
args: ['check=staged-changes']
88
language: script
99
pass_filenames: false
10+
- id: generate-erd
11+
name: Generate ERD
12+
entry: make erd
13+
language: system
14+
pass_filenames: false
15+
files: '.*models\.py$|.*models/.*\.py$'
16+
1017
- repo: https://github.com/astral-sh/ruff-pre-commit
1118
# Ruff version.
1219
rev: v0.11.12

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ models:
7676
shell:
7777
poetry run ./manage.py shell
7878

79+
erd:
80+
poetry run python -m django_diagram --settings manage_breast_screening.config.settings --output docs/diagrams/erd.md
81+
sed -i '' '1s/^/```mermaid\n/' docs/diagrams/erd.md && printf '\n```\n' >> docs/diagrams/erd.md
82+
7983
_install-poetry:
8084
if ! command -v poetry >/dev/null 2>&1; then \
8185
pip install poetry; \

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ To generate a new app, run:
110110
poetry run ./manage.py startapp <app_name> manage_breast_screening/`
111111
```
112112

113+
### Entity relationship
114+
115+
[Mermaid ERD](docs/diagrams/erd.md)
116+
113117
## Manual Deployment
114118

115119
The build pipeline builds and pushes a docker image to [Github container registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry). The app is deployed to an [Azure container app](https://azure.microsoft.com/en-us/products/container-apps) using terraform.

docs/diagrams/erd.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
```mermaid
2+
---
3+
Django ER Diagram
4+
---
5+
erDiagram
6+
LogEntry {
7+
AutoField id
8+
DateTimeField action_time
9+
ForeignKey user
10+
ForeignKey content_type
11+
TextField object_id
12+
CharField object_repr
13+
PositiveSmallIntegerField action_flag
14+
TextField change_message
15+
}
16+
Permission {
17+
AutoField id
18+
CharField name
19+
ForeignKey content_type
20+
CharField codename
21+
}
22+
Group {
23+
AutoField id
24+
CharField name
25+
ManyToManyField permissions
26+
}
27+
User {
28+
AutoField id
29+
CharField password
30+
DateTimeField last_login
31+
BooleanField is_superuser
32+
CharField username
33+
CharField first_name
34+
CharField last_name
35+
CharField email
36+
BooleanField is_staff
37+
BooleanField is_active
38+
DateTimeField date_joined
39+
ManyToManyField groups
40+
ManyToManyField user_permissions
41+
}
42+
ContentType {
43+
AutoField id
44+
CharField app_label
45+
CharField model
46+
}
47+
Session {
48+
CharField session_key
49+
TextField session_data
50+
DateTimeField expire_date
51+
}
52+
AuditLog {
53+
UUIDField id
54+
DateTimeField created_at
55+
ForeignKey content_type
56+
UUIDField object_id
57+
CharField operation
58+
JSONField snapshot
59+
ForeignKey actor
60+
CharField system_update_id
61+
}
62+
Provider {
63+
UUIDField id
64+
DateTimeField created_at
65+
DateTimeField updated_at
66+
TextField name
67+
}
68+
Setting {
69+
UUIDField id
70+
DateTimeField created_at
71+
DateTimeField updated_at
72+
TextField name
73+
ForeignKey provider
74+
}
75+
Clinic {
76+
UUIDField id
77+
DateTimeField created_at
78+
DateTimeField updated_at
79+
ForeignKey setting
80+
DateTimeField starts_at
81+
DateTimeField ends_at
82+
CharField type
83+
CharField risk_type
84+
}
85+
ClinicSlot {
86+
UUIDField id
87+
DateTimeField created_at
88+
DateTimeField updated_at
89+
ForeignKey clinic
90+
DateTimeField starts_at
91+
IntegerField duration_in_minutes
92+
}
93+
ClinicStatus {
94+
UUIDField id
95+
DateTimeField created_at
96+
CharField state
97+
ForeignKey clinic
98+
}
99+
Participant {
100+
UUIDField id
101+
DateTimeField created_at
102+
DateTimeField updated_at
103+
TextField first_name
104+
TextField last_name
105+
TextField gender
106+
TextField nhs_number
107+
TextField phone
108+
CharField email
109+
DateField date_of_birth
110+
CharField ethnic_group
111+
TextField risk_level
112+
JSONField extra_needs
113+
}
114+
ParticipantAddress {
115+
UUIDField id
116+
OneToOneField participant
117+
ArrayField lines
118+
CharField postcode
119+
}
120+
ScreeningEpisode {
121+
UUIDField id
122+
DateTimeField created_at
123+
DateTimeField updated_at
124+
ForeignKey participant
125+
}
126+
Appointment {
127+
UUIDField id
128+
DateTimeField created_at
129+
DateTimeField updated_at
130+
ForeignKey screening_episode
131+
ForeignKey clinic_slot
132+
BooleanField reinvite
133+
JSONField stopped_reasons
134+
}
135+
AppointmentStatus {
136+
CharField state
137+
UUIDField id
138+
DateTimeField created_at
139+
ForeignKey appointment
140+
}
141+
LogEntry }|--|| User : user
142+
LogEntry }|--|| ContentType : content_type
143+
Permission }|--|| ContentType : content_type
144+
Group }|--|{ Permission : permissions
145+
User }|--|{ Group : groups
146+
User }|--|{ Permission : user_permissions
147+
AuditLog }|--|| ContentType : content_type
148+
AuditLog }|--|| User : actor
149+
Setting }|--|| Provider : provider
150+
Clinic }|--|| Setting : setting
151+
ClinicSlot }|--|| Clinic : clinic
152+
ClinicStatus }|--|| Clinic : clinic
153+
ParticipantAddress ||--|| Participant : participant
154+
ScreeningEpisode }|--|| Participant : participant
155+
Appointment }|--|| ScreeningEpisode : screening_episode
156+
Appointment }|--|| ClinicSlot : clinic_slot
157+
AppointmentStatus }|--|| Appointment : appointment
158+
```

poetry.lock

Lines changed: 27 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ipdb = "^0.13.13"
3131
axe-playwright-python = "^0.1.5"
3232
ruff = "^0.12.0"
3333
django-debug-toolbar = "^5.2.0"
34+
django-diagram = "^0.0.1"
3435

3536
[build-system]
3637
requires = ["poetry-core>=2.0.0,<3.0.0"]

0 commit comments

Comments
 (0)