feat: implement applyProposedDdl utility for handling DDL statements …#1786
Conversation
…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.
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (12)
✨ Finishing Touches🧪 Generate unit tests (beta)
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
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
applyProposedDdlto parse and apply supported DDL statements to an in-memory schema copy while producing a structured diff (tables/columns/FKs + per-statement results). - Extended
buildMermaidErDiagramto optionally highlight added tables/columns/foreign keys and to include those highlights in the generated description. - Added a new
/connection/diagram/:connectionId/previewPOST 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.
| if (!columnNode || typeof columnNode !== 'object') return null; | ||
| if (typeof columnNode === 'string') return columnNode; |
| @ApiResponse({ | ||
| status: 200, | ||
| type: ConnectionDiagramPreviewResponseDTO, | ||
| }) | ||
| @UseGuards(ConnectionDiagramGuard) | ||
| @Timeout(90000) | ||
| @Post('/connection/diagram/:connectionId/preview') | ||
| async previewConnectionDiagram( |
…and tracking schema changes