fix: unify added markers for columns and foreign keys in Mermaid ER diagram#1802
Conversation
📝 WalkthroughWalkthroughThis PR refactors the mermaid ER diagram builder to consolidate the marker for newly-added columns and foreign keys. A single ChangesER Diagram Marker Consolidation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the Mermaid ER diagram generator to unify how “added/new” entities are marked in the diagram output (columns and foreign key relationships).
Changes:
- Replaces separate column/FK “added” marker constants with a single
ADDED_MARKER. - Changes column rendering so the “added” marker is appended via the column’s quoted comment (instead of as an attribute key marker).
- Keeps FK relationship labels appending the “added” marker to the relationship label text.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const ADDED_CLASS_NAME = 'addedEntity'; | ||
| const ADDED_CLASS_DEF = ` classDef ${ADDED_CLASS_NAME} fill:#d4edda,stroke:#28a745,color:#155724`; | ||
| const ADDED_COLUMN_MARKER = 'NEW'; | ||
| const ADDED_FK_MARKER = '[NEW]'; | ||
| const ADDED_MARKER = '[NEW]'; | ||
|
|
| const isAdded = tableAddedFks.has(fkKey(fk)); | ||
| const labelText = `${sanitizeQuotedText(fk.column_name)} -> ${sanitizeQuotedText(fk.referenced_column_name)}${isAdded ? ' ' + ADDED_FK_MARKER : ''}`; | ||
| const labelText = `${sanitizeQuotedText(fk.column_name)} -> ${sanitizeQuotedText(fk.referenced_column_name)}${isAdded ? ' ' + ADDED_MARKER : ''}`; | ||
| lines.push(` ${sourceAlias} }o--|| ${targetAlias} : "${labelText}"`); |
| const keyMarkers: Array<string> = []; | ||
| if (pkColumnNames.has(column.column_name)) keyMarkers.push('PK'); | ||
| if (fkColumnNames.has(column.column_name)) keyMarkers.push('FK'); | ||
| const isAdded = tableAddedCols.has(normalizeIdent(column.column_name)); | ||
| const comment = buildColumnComment(column, isAdded); | ||
| const tail = [keyMarkers.join(','), comment].filter((p) => p && p.length > 0).join(' '); |
| @@ -163,6 +162,9 @@ function buildColumnComment(column: TableStructureDS): string { | |||
| if (column.character_maximum_length) { | |||
| parts.push(`max length: ${column.character_maximum_length}`); | |||
| } | |||
| if (isAdded) { | |||
| parts.push(ADDED_MARKER); | |||
| } | |||
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts (2)
68-68: 💤 Low valuePrefer nested template literals over string concatenation.
The guideline states to use template literals instead of string concatenation. The expression
' ' + tailinside the interpolation could use a nested template literal for consistency. As per coding guidelines, use template literals instead of string concatenation.♻️ Suggested refinement
- lines.push(` ${dataType} ${colName}${tail ? ' ' + tail : ''}`); + lines.push(` ${dataType} ${colName}${tail ? ` ${tail}` : ''}`);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts` at line 68, The string concatenation inside the template literal should be replaced with a nested template literal for consistency: update the push call that builds column lines (the expression that currently does lines.push(` ${dataType} ${colName}${tail ? ' ' + tail : ''}`) ) to use a nested template literal for the tail (e.g., `${tail ? ` ${tail}` : ''}`), so the entire expression uses template literals rather than `' ' + tail`.
82-82: 💤 Low valuePrefer nested template literals over string concatenation.
The guideline states to use template literals instead of string concatenation. The expression
' ' + ADDED_MARKERinside the interpolation could use a nested template literal for consistency. As per coding guidelines, use template literals instead of string concatenation.♻️ Suggested refinement
- const labelText = `${sanitizeQuotedText(fk.column_name)} -> ${sanitizeQuotedText(fk.referenced_column_name)}${isAdded ? ' ' + ADDED_MARKER : ''}`; + const labelText = `${sanitizeQuotedText(fk.column_name)} -> ${sanitizeQuotedText(fk.referenced_column_name)}${isAdded ? ` ${ADDED_MARKER}` : ''}`;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts` at line 82, The labelText construction uses string concatenation for the added marker; update the interpolation to use a nested template literal instead: in the expression that builds labelText (using sanitizeQuotedText and fk.column_name / fk.referenced_column_name), replace the `' ' + ADDED_MARKER` concatenation with a nested template literal such as `${isAdded ? ` ${ADDED_MARKER}` : ''}` so the whole labelText uses consistent template literals.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts`:
- Line 68: The string concatenation inside the template literal should be
replaced with a nested template literal for consistency: update the push call
that builds column lines (the expression that currently does lines.push(`
${dataType} ${colName}${tail ? ' ' + tail : ''}`) ) to use a nested template
literal for the tail (e.g., `${tail ? ` ${tail}` : ''}`), so the entire
expression uses template literals rather than `' ' + tail`.
- Line 82: The labelText construction uses string concatenation for the added
marker; update the interpolation to use a nested template literal instead: in
the expression that builds labelText (using sanitizeQuotedText and
fk.column_name / fk.referenced_column_name), replace the `' ' + ADDED_MARKER`
concatenation with a nested template literal such as `${isAdded ? `
${ADDED_MARKER}` : ''}` so the whole labelText uses consistent template
literals.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 421c8198-2a80-4ecd-b36e-b35a87455369
📒 Files selected for processing (1)
backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts
Summary by CodeRabbit
Release Notes