{"record":{"id":"be60767894e932d2","repo":"OtterMind/Chat2DB","slug":"database-delete-connectiontargetsdeleteddatabase","errorCode":"database.delete.connectionTargetsDeletedDatabase","errorMessage":"database.delete.connectionTargetsDeletedDatabase","messagePattern":"database\\.delete\\.connectionTargetsDeletedDatabase","errorType":"validation","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDatabaseObjectDeleteServiceImpl.java","lineNumber":110,"sourceCode":"            throw e;\n        } catch (Exception e) {\n            throw new BusinessException(\"database.delete.prepareFailed\", new Object[]{e.getMessage()}, e);\n        }\n        return prepareResult(schemaConfirmName(schemaName), buildDropSchema(dbType, schemaName), TYPE_SCHEMA, dbType);\n    }\n\n    @Override\n    public void executeDatabaseDelete(DbDatabaseObjectDeleteExecuteRequest param) {\n        ConnectionProfile profile = requireCurrentProfile();\n        String dbType = requireSupportedDbType(profile);\n        reconnectForDatabaseDelete(dbType);\n        profile = requireCurrentProfile();\n        String databaseName = requireName(param.getDatabaseName(), \"databaseName\");\n        assertDatabaseDeletionSupported(dbType);\n        rejectSystemDatabase(dbType, databaseName);\n        assertConfirmName(param.getConfirmName(), databaseConfirmName(databaseName));\n        if (StringUtils.equals(profile.getDatabaseName(), databaseName)) {\n            throw new BusinessException(\"database.delete.connectionTargetsDeletedDatabase\");\n        }\n        Connection connection = requireConnection();\n        try {\n            assertDatabaseExists(connection, dbType, databaseName);\n            Chat2DBContext.getDbManager(dbType).dropDatabase(connection, databaseName);\n        } catch (BusinessException e) {\n            throw e;\n        } catch (Exception e) {\n            throw new BusinessException(\"database.delete.executeFailed\", new Object[]{e.getMessage()}, e);\n        }\n    }\n\n    @Override\n    public void executeSchemaDelete(DbDatabaseObjectDeleteExecuteRequest param) {\n        ConnectionProfile profile = requireCurrentProfile();\n        String dbType = requireSupportedDbType(profile);\n        String databaseName = requireName(param.getDatabaseName(), \"databaseName\");\n        String schemaName = requireName(param.getSchemaName(), \"schemaName\");","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDatabaseObjectDeleteServiceImpl.java#L92-L128","documentation":"Thrown by executeDatabaseDelete() when the current connection's database (profile.getDatabaseName()) equals the database being deleted. Dropping the database you are currently connected to is refused as a safety guard.","triggerScenarios":"A drop-database execute request targets the same database the connection context is bound to. For PostgreSQL, reconnectForDatabaseDelete rebinds to a maintenance database; if that rebind did not move off the target (or dbType is not PostgreSQL), the guard trips.","commonSituations":"Non-PostgreSQL dialects that don't rebind, or PostgreSQL where the maintenance database equals the target; a stale profile after a failed rebind; the user picks the database the session is logged into.","solutions":["Ensure the connection is rebound to a different maintenance database before drop (reconnectForDatabaseDelete handles PostgreSQL; add equivalent handling for the dialect if missing).","Verify profile.getDatabaseName() differs from the target databaseName before issuing executeDatabaseDelete.","For PostgreSQL confirm maintenanceDatabase() returns a DB other than the target."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before executeDatabaseDelete\nConnectionProfile profile = connectionContextService.currentProfile();\nif (profile != null && StringUtils.equals(profile.getDatabaseName(), param.getDatabaseName())) {\n    // rebind to a maintenance database first (PostgreSQL path), or refuse\n    return Result.fail(\"database.delete.connectionTargetsDeletedDatabase\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rebind the connection to a different maintenance database before dropping a database.","Verify profile.getDatabaseName() differs from the target before execute.","For non-PostgreSQL dialects, add an equivalent rebind step."],"tags":["database","delete","ddl","safety","connection"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}