feat(viewer): erDiagram shows real column types when present; ArtifactView accepts a {content} sql wrapper

erDiagram reads data_type/type from the candidate (top-level or signals),
falling back to the generic 'col' token Mermaid needs — real types render as
soon as schema_linking.json carries them. ArtifactView gains a defensive
{content} fallback for sql-kind artifacts, verified against real session shapes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 14:13:02 +02:00
co-authored by Claude Opus 4.8
parent c3e8f14ad9
commit e4ada07dab
4 changed files with 33 additions and 1 deletions
+14 -1
View File
@@ -33,6 +33,19 @@ function reasonFor(c: Candidate): string {
return "";
}
// The real DB type for a promoted column, when the schema-linking data carries it
// (`data_type`/`type`, at top level or under `signals`). Today's schema_linking.json
// has no column types, so this falls back to the generic `col` token that Mermaid
// still needs as the attribute type; a real type shows as soon as the pipeline
// provides one. The token is sanitized to keep the erDiagram valid.
function attrType(c: Candidate): string {
const sig = (c.signals ?? {}) as Record<string, unknown>;
const rec = c as unknown as Record<string, unknown>;
const raw = sig["data_type"] ?? sig["type"] ?? rec["data_type"] ?? rec["type"];
const t = typeof raw === "string" && raw.trim() ? raw.trim() : "col";
return t.replace(/[^a-zA-Z0-9]/g, "_");
}
export function buildErDiagram(promoted: Candidate[], joins: Join[]): string {
const sanitize = (name: string) => name.replace(/[^a-zA-Z0-9]/g, "_");
const tables = promoted.filter((c) => c.kind === "table");
@@ -46,7 +59,7 @@ export function buildErDiagram(promoted: Candidate[], joins: Join[]): string {
const cols = columns.filter((col) => col.name.startsWith(t.name + "."));
lines.push(` ${id} {`);
for (const col of cols) {
lines.push(` col ${sanitize(col.name.slice(t.name.length + 1))}`);
lines.push(` ${attrType(col)} ${sanitize(col.name.slice(t.name.length + 1))}`);
}
lines.push(` }`);
}