Skip to content

fix(view): /api/rdb/view/delete drops the view instead of the table - #2380

Merged
openai0229 merged 4 commits into
OtterMind:mainfrom
Aias00:fix/view-delete-drops-table-2377
Aug 3, 2026
Merged

openai0229 merged 4 commits into
OtterMind:mainfrom
Aias00:fix/view-delete-drops-table-2377

Conversation

@Aias00

@Aias00 Aias00 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What

POST /api/rdb/view/delete was documented as deleting a database view but called tableService.dropTable(param), which generates DROP TABLE against a same-named object — destroying a table instead of removing the view. The sibling /drop endpoint correctly calls viewService.drop.

Location

DbViewController.java:115-120

Fix

Build a DbViewDeleteRequest from the TableDeleteRequest (mapping tableNameviewName, since a view's object name is carried in tableName on this request type) and delegate to viewService.drop, mirroring the /drop endpoint. The TableDeleteRequest input contract is preserved so existing callers are unaffected.

Verification

  • DbViewDeleteRequest has an @AllArgsConstructor with field order dataSourceId, databaseName, schemaName, viewName; the controller already imports it.
  • TableDeleteRequest extends DataSourceBaseRequest, which provides dataSourceId / databaseName / schemaName, and adds tableName.
  • The tableService field and DbTableQueryRequest import remain in use by columnList, so no dead-code was introduced.

Manual/runtime verification against a datasource with a same-named view and table is recommended before merge.

Fixes #2377

🤖 Generated with Claude Code

…tterMind#2377)

The /delete endpoint was documented as deleting a database view but called
tableService.dropTable, which generates DROP TABLE against a same-named
object — destroying a table instead of removing the view. Build a
DbViewDeleteRequest (tableName -> viewName) and delegate to viewService.drop,
mirroring the /drop endpoint. The TableDeleteRequest input contract is
preserved so existing callers are unaffected.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: liuhy <liuhongyu@apache.org>
Copilot AI review requested due to automatic review settings August 3, 2026 05:51
@Aias00
Aias00 requested a review from openai0229 as a code owner August 3, 2026 05:51
@openai0229 openai0229 moved this to In Review in Chat2DB Community Aug 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes POST /api/rdb/view/delete so it drops a view (via viewService.drop) instead of incorrectly dropping a table (via tableService.dropTable), preventing destructive DROP TABLE behavior when deleting views.

Findings (blocking):

  • chat2db-community-server/chat2db-community-web/src/main/java/ai/chat2db/community/web/api/controller/DbViewController.java:116 — The /delete endpoint still lacks @RequestBody for TableDeleteRequest, unlike /drop and other /delete endpoints; JSON clients may fail to bind/validate the request.

Changes:

  • Replace tableService.dropTable(...) with viewService.drop(...) for /api/rdb/view/delete.
  • Map TableDeleteRequest.tableName to DbViewDeleteRequest.viewName to preserve the existing input contract.
  • Add clarifying inline comments documenting why the mapping is required.

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

@openai0229 openai0229 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the view-deletion delegation and request-body binding after syncing with the latest main. DbViewControllerTest executes successfully and verifies all four mapped fields passed to viewService.drop.

@openai0229
openai0229 merged commit d1d35f1 into OtterMind:main Aug 3, 2026
16 of 17 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

3 participants