Description
POST /api/rdb/view/delete is documented as "Deletes database views", but its implementation calls tableService.dropTable(param) — i.e. it drops a table, not a view. The sibling endpoint POST /api/rdb/view/drop correctly calls viewService.drop(param).
So a user who deletes a view via the /delete path actually triggers DROP TABLE against an object that resolves by name under the same schema/database, destroying data instead of removing the view.
Location
chat2db-community-server/chat2db-community-web/src/main/java/ai/chat2db/community/web/api/controller/DbViewController.java:115-120
@PostMapping("/delete")
public ActionResult delete(@Valid TableDeleteRequest request) {
DbTableQueryRequest param = dbWebConverter.tableRequest2param(request);
tableService.dropTable(param); // ← generates DROP TABLE, should drop a VIEW
return ActionResult.isSuccess();
}
The correct path (already present at :161-166) builds a DbViewDeleteRequest and calls viewService.drop(...).
Impact
- Data loss / availability: deleting a view silently drops a same-named table object in the same schema/database.
- If no same-named table exists, the request fails with a misleading error rather than deleting the view.
- The endpoint returns success while the wrong object is destroyed.
Suggested fix
Build a DbViewDeleteRequest from the TableDeleteRequest (mapping tableName → viewName) and call viewService.drop(param), mirroring the /drop endpoint. Keep the TableDeleteRequest input contract so existing callers are unaffected.
@PostMapping("/delete")
public ActionResult delete(@Valid TableDeleteRequest request) {
DbViewDeleteRequest param = new DbViewDeleteRequest(
request.getDataSourceId(),
request.getDatabaseName(),
request.getSchemaName(),
request.getTableName());
viewService.drop(param);
return ActionResult.isSuccess();
}
(DbViewDeleteRequest has an @AllArgsConstructor with field order dataSourceId, databaseName, schemaName, viewName; the controller already imports it.)
Related existing
None. Repo-audit (main @ e5bd63f) found no prior issue describing view-delete dropping a table.
Description
POST /api/rdb/view/deleteis documented as "Deletes database views", but its implementation callstableService.dropTable(param)— i.e. it drops a table, not a view. The sibling endpointPOST /api/rdb/view/dropcorrectly callsviewService.drop(param).So a user who deletes a view via the
/deletepath actually triggersDROP TABLEagainst an object that resolves by name under the same schema/database, destroying data instead of removing the view.Location
chat2db-community-server/chat2db-community-web/src/main/java/ai/chat2db/community/web/api/controller/DbViewController.java:115-120The correct path (already present at
:161-166) builds aDbViewDeleteRequestand callsviewService.drop(...).Impact
Suggested fix
Build a
DbViewDeleteRequestfrom theTableDeleteRequest(mappingtableName→viewName) and callviewService.drop(param), mirroring the/dropendpoint. Keep theTableDeleteRequestinput contract so existing callers are unaffected.(
DbViewDeleteRequesthas an@AllArgsConstructorwith field orderdataSourceId, databaseName, schemaName, viewName; the controller already imports it.)Related existing
None. Repo-audit (main @ e5bd63f) found no prior issue describing view-delete dropping a table.