Skip to content

feat: implement applyProposedDdl utility for handling DDL statements …#1786

Merged
Artuomka merged 2 commits into
mainfrom
bakcned_mermain_diagram_fixes
May 19, 2026
Merged

feat: implement applyProposedDdl utility for handling DDL statements …#1786
Artuomka merged 2 commits into
mainfrom
bakcned_mermain_diagram_fixes

Conversation

@Artuomka
Copy link
Copy Markdown
Collaborator

…and tracking schema changes

  • Added applyProposedDdl function to apply SQL commands and track added/dropped tables, columns, and foreign keys.
  • Introduced MermaidDiagramHighlight interface to manage highlighting of added elements in ER diagrams.
  • Enhanced buildMermaidErDiagram function to support highlighting new tables, columns, and foreign keys.
  • Created comprehensive tests for applyProposedDdl and buildMermaidErDiagram functionalities, covering various DDL operations and their effects on the schema.
  • Added end-to-end tests for previewing connection diagrams, ensuring correct handling of SQL commands and validation of responses.

…and tracking schema changes

- Added applyProposedDdl function to apply SQL commands and track added/dropped tables, columns, and foreign keys.
- Introduced MermaidDiagramHighlight interface to manage highlighting of added elements in ER diagrams.
- Enhanced buildMermaidErDiagram function to support highlighting new tables, columns, and foreign keys.
- Created comprehensive tests for applyProposedDdl and buildMermaidErDiagram functionalities, covering various DDL operations and their effects on the schema.
- Added end-to-end tests for previewing connection diagrams, ensuring correct handling of SQL commands and validation of responses.
Copilot AI review requested due to automatic review settings May 19, 2026 12:20
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Warning

Rate limit exceeded

@Artuomka has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 58 minutes and 15 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3ef5d646-c029-4a52-b0c5-3340c63ad2ab

📥 Commits

Reviewing files that changed from the base of the PR and between 9d2bdc8 and 14a4893.

📒 Files selected for processing (12)
  • backend/src/common/data-injection.tokens.ts
  • backend/src/entities/connection/application/data-structures/preview-connection-diagram.ds.ts
  • backend/src/entities/connection/application/dto/connection-diagram-preview-request.dto.ts
  • backend/src/entities/connection/application/dto/connection-diagram-preview-response.dto.ts
  • backend/src/entities/connection/connection.controller.ts
  • backend/src/entities/connection/connection.module.ts
  • backend/src/entities/connection/use-cases/preview-connection-diagram.use.case.ts
  • backend/src/entities/connection/use-cases/use-cases.interfaces.ts
  • backend/src/entities/connection/utils/apply-proposed-ddl.util.ts
  • backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts
  • backend/test/ava-tests/connection-diagram-preview.test.ts
  • backend/test/ava-tests/non-saas-tests/non-saas-connection-diagram-preview-e2e.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bakcned_mermain_diagram_fixes

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.

@Artuomka Artuomka enabled auto-merge May 19, 2026 12:21
@coderabbitai coderabbitai Bot requested review from gugu and lyubov-voloshko May 19, 2026 12:21
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

Adds a “diagram preview” capability for SQL connections by parsing proposed DDL (without executing it) and generating an updated Mermaid ER diagram with visual highlighting of newly added schema elements.

Changes:

  • Introduced applyProposedDdl to parse and apply supported DDL statements to an in-memory schema copy while producing a structured diff (tables/columns/FKs + per-statement results).
  • Extended buildMermaidErDiagram to optionally highlight added tables/columns/foreign keys and to include those highlights in the generated description.
  • Added a new /connection/diagram/:connectionId/preview POST endpoint (controller + use case + DTOs) plus unit and e2e tests validating behavior and error handling.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
backend/src/entities/connection/utils/apply-proposed-ddl.util.ts New utility to parse/apply proposed DDL and produce a schema diff + statement results.
backend/src/entities/connection/utils/build-mermaid-er-diagram.util.ts Adds optional highlighting for new tables/columns/FKs and enriches description output.
backend/src/entities/connection/use-cases/preview-connection-diagram.use.case.ts New use case that loads current schema, applies proposed DDL in-memory, and returns preview diagram + diff.
backend/src/entities/connection/use-cases/use-cases.interfaces.ts Exposes a new IPreviewConnectionDiagram use-case interface.
backend/src/entities/connection/connection.module.ts Wires the new preview use case provider and ensures auth middleware covers the new route.
backend/src/entities/connection/connection.controller.ts Adds the new preview endpoint and Swagger annotations.
backend/src/entities/connection/application/dto/connection-diagram-preview-request.dto.ts Request DTO for SQL command batch validation.
backend/src/entities/connection/application/dto/connection-diagram-preview-response.dto.ts Response DTO for preview diagram + diff + statement results.
backend/src/entities/connection/application/data-structures/preview-connection-diagram.ds.ts New DS for passing preview inputs through the use-case layer.
backend/src/common/data-injection.tokens.ts Adds a new UseCaseType token for preview diagram functionality.
backend/test/ava-tests/connection-diagram-preview.test.ts Unit tests for DDL application and Mermaid highlight behavior.
backend/test/ava-tests/non-saas-tests/non-saas-connection-diagram-preview-e2e.test.ts End-to-end coverage for preview endpoint behavior and validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +384 to +385
if (!columnNode || typeof columnNode !== 'object') return null;
if (typeof columnNode === 'string') return columnNode;
Comment on lines +769 to +776
@ApiResponse({
status: 200,
type: ConnectionDiagramPreviewResponseDTO,
})
@UseGuards(ConnectionDiagramGuard)
@Timeout(90000)
@Post('/connection/diagram/:connectionId/preview')
async previewConnectionDiagram(
@Artuomka Artuomka merged commit fe0b43a into main May 19, 2026
19 checks passed
@Artuomka Artuomka deleted the bakcned_mermain_diagram_fixes branch May 19, 2026 12:30
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