Skip to content

Commit a8ce6ee

Browse files
committed
Improve ER diagram: full table.column labels on relationships, legend
1 parent 1c3a245 commit a8ce6ee

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

app/web/routes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,10 @@ def _build_mermaid_er(schema: dict) -> str:
544544
if col["name"] in fk_info.get("constrained_columns", []):
545545
fk = "FK"
546546
ref_table = fk_info["referred_table"]
547-
fk_relations.append(f' {ref_table} ||--o{{ {table} : ""')
547+
ref_cols = fk_info.get("referred_columns", [])
548+
ref_col = ref_cols[0] if ref_cols else "?"
549+
label = f"{table}.{col['name']} -> {ref_table}.{ref_col}"
550+
fk_relations.append(f' {ref_table} ||--o{{ {table} : "{label}"')
548551
break
549552
key_marker = f"{pk},{fk}" if pk and fk else (pk or fk)
550553
key_str = f" {key_marker}" if key_marker else ""
@@ -554,5 +557,4 @@ def _build_mermaid_er(schema: dict) -> str:
554557
for rel in fk_relations:
555558
lines.append(rel)
556559

557-
# Add isolated tables (no FK relations) so they still appear
558560
return "\n".join(lines)

app/web/static/styles.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ textarea:hover {
301301
justify-content: center;
302302
}
303303

304+
.er-legend {
305+
display: flex;
306+
gap: 20px;
307+
justify-content: center;
308+
margin-top: 12px;
309+
font-size: 12px;
310+
color: var(--muted);
311+
}
312+
304313
.schema-grid {
305314
display: grid;
306315
gap: 16px;

app/web/templates/schema.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ <h2>Schema</h2>
99
<div class="er-diagram">
1010
<h3>ER Diagram</h3>
1111
<pre class="mermaid">{{ mermaid }}</pre>
12+
<div class="er-legend">
13+
<span><strong>PK</strong> = Primary Key</span>
14+
<span><strong>FK</strong> = Foreign Key</span>
15+
<span>||--o{ = one-to-many</span>
16+
</div>
1217
</div>
1318
{% endif %}
1419

0 commit comments

Comments
 (0)