Backend toon migration#1613
Conversation
- Added FindAllSavedDbQueriesUseCase to retrieve all saved database queries. - Introduced FindSavedDbQueryUseCase for fetching a specific saved query by ID. - Created panel-use-cases.interface.ts to define interfaces for panel operations. - Developed TestDbQueryUseCase to test database queries with safety checks. - Implemented UpdateSavedDbQueryUseCase for updating existing saved queries. - Added utility functions for building DTOs and checking query safety. - Created migration to rename visualization entities in the database. - Added end-to-end tests for AI-generated dashboard widgets, including safety checks for queries.
There was a problem hiding this comment.
Pull request overview
This pull request implements a significant refactoring that renames core visualization entities in the backend codebase. The main changes involve:
-
Database Migration: Renames
saved_db_querytable topanelanddashboard_widgettable topanel_position, along with column renames (widget_type→panel_type,widget_options→panel_options) -
Entity Refactoring: Updates all entity classes, repositories, DTOs, data structures, use cases, and controllers to reflect the new naming convention
-
New AI Feature: Adds AI-powered widget generation capability that creates dashboard widgets from natural language descriptions
Changes:
- Database migration with proper up/down functions for table and column renames
- Comprehensive entity, repository, and use case refactoring from "saved-db-query" to "panel" and "dashboard-widget" to "panel-position"
- New AI widget generation endpoint with query safety validation
- Query safety utility supporting multiple database types (SQL, MongoDB, Elasticsearch, Redis, DynamoDB)
- New end-to-end tests for AI widget generation
- Updates to global database context and module imports
Reviewed changes
Copilot reviewed 58 out of 67 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/src/migrations/1771344994001-RenameVisualisationEntities.ts | Database migration renaming tables and columns |
| backend/src/entities/visualizations/panel/* | Refactored panel entity, DTOs, use cases, and repository (formerly saved-db-query) |
| backend/src/entities/visualizations/panel-position/* | Refactored panel-position entity, DTOs, use cases, and repository (formerly dashboard-widget) |
| backend/src/entities/visualizations/panel/utils/check-query-is-safe.util.ts | New comprehensive query safety validation for multiple database types |
| backend/src/entities/visualizations/panel-position/use-cases/generate-panel-position-with-ai.use.case.ts | New AI-powered widget generation feature |
| backend/src/common/application/global-database-context.ts | Updated repository accessors to use new naming |
| backend/src/common/application/global-database-context.interface.ts | Updated interface with new repository names |
| backend/src/entities/connection/connection.entity.ts | Updated relationship from saved_db_queries to panels |
| backend/src/entities/visualizations/dashboard/* | Updated references to use new entity names |
| backend/src/app.module.ts | Updated module imports to use PanelModule and PanelPositionModule |
| backend/test/ava-tests/saas-tests/saved-database-queries-e2e.test.ts | Updated test imports to use FoundPanelDto |
| backend/test/ava-tests/saas-tests/dashboard-ai-widget-e2e.test.ts | New comprehensive end-to-end tests for AI widget generation |
| backend/src/entities/table-categories/use-cases/find-table-categories-with-tables.use.case.ts | Commented out table sorting logic |
Comments suppressed due to low confidence (8)
backend/src/entities/visualizations/panel/use-cases/delete-panel.use.case.ts:14
- The class name
DeleteSavedDbQueryUseCaseshould be renamed toDeletePanelUseCaseto match the file namedelete-panel.use.case.tsand align with the migration from "saved-db-query" to "panel" terminology.
backend/src/entities/visualizations/panel/use-cases/update-panel.use.case.ts:15 - The class name
UpdateSavedDbQueryUseCaseshould be renamed toUpdatePanelUseCaseto be consistent with the file nameupdate-panel.use.case.tsand the migration from "saved-db-query" to "panel" terminology.
backend/src/entities/visualizations/panel-position/use-cases/update-panel-position.use.case.ts:14 - The class name
UpdateDashboardWidgetUseCaseshould be renamed toUpdatePanelPositionUseCaseto match the file nameupdate-panel-position.use.case.tsand align with the migration from "dashboard-widget" to "panel-position" terminology.
backend/src/entities/visualizations/panel/panel.controller.ts:56 - The class name
SavedDbQueryControllershould be renamed toPanelControllerto match the file namepanel.controller.tsand align with the migration from "saved-db-query" to "panel" terminology throughout the codebase.
backend/src/entities/visualizations/panel-position/panel-position.controller.ts:45 - The class name
DashboardWidgetControllershould be renamed toPanelPositionControllerto match the file namepanel-position.controller.tsand align with the migration from "dashboard-widget" to "panel-position" terminology throughout the codebase.
backend/src/entities/visualizations/panel/use-cases/find-panel.use.case.ts:12 - The class name
FindSavedDbQueryUseCaseshould be renamed toFindPanelUseCaseto be consistent with the file name and the migration from "saved-db-query" to "panel" terminology. This inconsistency could cause confusion for developers working with this codebase.
backend/src/entities/visualizations/panel/use-cases/find-all-panels.use.case.ts:14 - The class name
FindAllSavedDbQueriesUseCaseshould be renamed toFindAllPanelsUseCaseto align with the migration from "saved-db-query" to "panel" terminology and match the file namefind-all-panels.use.case.ts.
backend/src/entities/visualizations/panel/dto/found-saved-db-query.dto.ts:4 - The file name
found-saved-db-query.dto.tsshould be renamed tofound-panel.dto.tsto match the class it contains (FoundPanelDto) and align with the migration from "saved-db-query" to "panel" terminology. This would improve code organization and make it easier for developers to locate the correct file.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // const sortedTables = tablesRO.sort((tableRO1, tableRO2) => { | ||
| // const name1 = tableRO1.display_name || tableRO1.table; | ||
| // const name2 = tableRO2.display_name || tableRO2.table; | ||
| // return name1.localeCompare(name2); | ||
| // }); | ||
|
|
There was a problem hiding this comment.
The commented-out table sorting logic should either be removed or uncommented with an explanation. Leaving commented code without context reduces code maintainability and clarity. If this sorting was intentionally disabled, a comment explaining why would be helpful.
| // const sortedTables = tablesRO.sort((tableRO1, tableRO2) => { | |
| // const name1 = tableRO1.display_name || tableRO1.table; | |
| // const name2 = tableRO2.display_name || tableRO2.table; | |
| // return name1.localeCompare(name2); | |
| // }); |
| import { PanelEntity } from '../panel.entity.js'; | ||
| import { IPanelRepository } from './saved-db-query.repository.interface.js'; | ||
|
|
||
| export const panelCustomRepositoryExtension: IPanelRepository = { | ||
| async findAllQueriesByConnectionId(connectionId: string): Promise<PanelEntity[]> { | ||
| const qb = this.createQueryBuilder('panel'); | ||
| qb.where('panel.connection_id = :connectionId', { connectionId }); | ||
| qb.orderBy('panel.created_at', 'DESC'); | ||
| return await qb.getMany(); | ||
| }, | ||
|
|
||
| async findQueryById(queryId: string): Promise<PanelEntity | null> { | ||
| const qb = this.createQueryBuilder('panel'); | ||
| qb.where('panel.id = :queryId', { queryId }); | ||
| return await qb.getOne(); | ||
| }, | ||
|
|
||
| async findQueryByIdAndConnectionId(queryId: string, connectionId: string): Promise<PanelEntity | null> { | ||
| const qb = this.createQueryBuilder('panel'); | ||
| qb.where('panel.id = :queryId', { queryId }); | ||
| qb.andWhere('panel.connection_id = :connectionId', { connectionId }); | ||
| return await qb.getOne(); | ||
| }, | ||
| }; |
There was a problem hiding this comment.
The file names saved-db-query-custom-repository-extension.ts and saved-db-query.repository.interface.ts should be renamed to panel-custom-repository-extension.ts and panel.repository.interface.ts respectively to align with the migration from "saved-db-query" to "panel" terminology and maintain naming consistency across the repository layer.
No description provided.