Skip to content

fix: unify added markers for columns and foreign keys in Mermaid ER diagram#1802

Merged
Artuomka merged 1 commit into
mainfrom
backend_mermaid_diagram_fix
May 26, 2026
Merged

fix: unify added markers for columns and foreign keys in Mermaid ER diagram#1802
Artuomka merged 1 commit into
mainfrom
backend_mermaid_diagram_fix

Conversation

@Artuomka
Copy link
Copy Markdown
Collaborator

@Artuomka Artuomka commented May 26, 2026

Summary by CodeRabbit

Release Notes

  • Refactor
    • ER diagram builder now uses a consistent marker to identify newly-added columns and foreign key relationships, improving visual consistency across diagram displays.

Review Change Stack

Copilot AI review requested due to automatic review settings May 26, 2026 15:15
@Artuomka Artuomka enabled auto-merge May 26, 2026 15:16
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

📝 Walkthrough

Walkthrough

This PR refactors the mermaid ER diagram builder to consolidate the marker for newly-added columns and foreign keys. A single ADDED_MARKER constant is introduced, the column comment helper is updated to conditionally inject the marker, and both column rendering and foreign-key labels are updated to use the new shared marker approach.

Changes

ER Diagram Marker Consolidation

Layer / File(s) Summary
Shared marker constant definition
backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts
A new ADDED_MARKER constant ([NEW]) is introduced to replace distinct marker approaches.
Column comment helper refactor
backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts
buildColumnComment now accepts an isAdded boolean and conditionally appends ADDED_MARKER to the comment text.
Column rendering and FK relationship labels
backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts
Column label construction is refactored to compute an isAdded flag and pass it to buildColumnComment; foreign-key relationship labels are updated to append ADDED_MARKER when highlighted as newly added.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • rocket-admin/rocketadmin#1785: Both PRs modify the same ER diagram utility to refactor how column comments and relationship labels are generated, including updates to buildColumnComment and label formatting logic.

Poem

🐰 A marker unified, so clean and bright,
[NEW] tags columns added right,
Refactored helpers, one shared way,
The ER diagrams dance today! ✨

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: unifying added markers for columns and foreign keys in the Mermaid ER diagram builder utility.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Check ✅ Passed Refactoring unifies ADDED_MARKER constant for columns/FK labels; all user inputs properly sanitized; marker is static constant (no injection vectors); complies with OWASP injection prevention rules.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch backend_mermaid_diagram_fix

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 23 to 26
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]';

Comment on lines 81 to 83
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}"`);
Comment on lines +62 to +67
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(' ');
Comment on lines 156 to +167
@@ -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);
}
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts (2)

68-68: 💤 Low value

Prefer nested template literals over string concatenation.

The guideline states to use template literals instead of string concatenation. The expression ' ' + tail inside 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 value

Prefer nested template literals over string concatenation.

The guideline states to use template literals instead of string concatenation. The expression ' ' + ADDED_MARKER inside 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

📥 Commits

Reviewing files that changed from the base of the PR and between fcd29bd and 5e9bdb3.

📒 Files selected for processing (1)
  • backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts

@Artuomka Artuomka merged commit 8c01dfc into main May 26, 2026
20 checks passed
@Artuomka Artuomka deleted the backend_mermaid_diagram_fix branch May 26, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants