Skip to content

Commit 8bac936

Browse files
Database schema ERD
1 parent 110c25a commit 8bac936

File tree

4 files changed

+176
-12
lines changed

4 files changed

+176
-12
lines changed

docs/customization.qmd

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Best practices dictate implementing thorough client-side validation via JavaScri
121121
- Improve user experience by avoiding round-trips to the server
122122
- Prevent malformed data from ever reaching the backend
123123

124-
Server-side validation remains essential as a security measure against malicious requests that bypass client-side validation, but it should rarely be encountered during normal user interaction. See `templates/authentication/register.html` for a client-side form validation example.
124+
Server-side validation remains essential as a security measure against malicious requests that bypass client-side validation, but it should rarely be encountered during normal user interaction. See `templates/authentication/register.html` for a client-side form validation example involving both JavaScript and HTML regex `pattern` matching.
125125

126126
### Writing type annotated code
127127

@@ -236,16 +236,34 @@ Our database models are defined in `utils/models.py`. Each model is a Python cla
236236
- `RolePermissionLink`: Maps roles to their allowed permissions
237237
- `PasswordResetToken`: Manages password reset functionality
238238

239-
Models can have relationships with other models using SQLModel's `Relationship` field. For example:
240-
241-
```python
242-
class User(SQLModel, table=True):
243-
# ... other fields ...
244-
organization: Optional["Organization"] = Relationship(back_populates="users")
245-
role: Optional["Role"] = Relationship(back_populates="users")
239+
Here's an entity-relationship diagram (ERD) of the current database schema, automatically generated from our SQLModel definitions:
240+
241+
```{python}
242+
#| echo: false
243+
#| warning: false
244+
import sys
245+
sys.path.append("..")
246+
from utils.models import *
247+
from utils.db import engine
248+
from sqlalchemy import MetaData
249+
from sqlalchemy_schemadisplay import create_schema_graph
250+
251+
# Create the directed graph
252+
graph = create_schema_graph(
253+
engine=engine,
254+
metadata=SQLModel.metadata,
255+
show_datatypes=True,
256+
show_indexes=True,
257+
rankdir='TB',
258+
concentrate=False
259+
)
260+
261+
# Save the graph
262+
graph.write_png('static/schema.png')
246263
```
247264

248-
This creates a many-to-one relationship between users and organizations, and between users and roles.
265+
![Database Schema](static/schema.png)
266+
249267

250268
#### Database operations
251269

@@ -265,4 +283,3 @@ async def get_users(session: Session = Depends(get_session)):
265283
```
266284

267285
The session automatically handles transaction management, ensuring that database operations are atomic and consistent.
268-

docs/static/schema.png

52.4 KB
Loading

poetry.lock

Lines changed: 148 additions & 2 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
@@ -28,6 +28,7 @@ mypy = "^1.11.2"
2828
jupyter = "^1.1.1"
2929
notebook = "^7.2.2"
3030
pytest = "^8.3.3"
31+
sqlalchemy-schemadisplay = "^2.0"
3132

3233
[build-system]
3334
requires = ["poetry-core"]

0 commit comments

Comments
 (0)