Skip to content

bug(view): /api/rdb/view/delete drops the table instead of the view #2377

Description

@Aias00

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 tableNameviewName) 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions