{"record":{"id":"050d6f589fe358a2","repo":"OtterMind/Chat2DB","slug":"database-delete-schemanotexists","errorCode":"database.delete.schemaNotExists","errorMessage":"database.delete.schemaNotExists","messagePattern":"database\\.delete\\.schemaNotExists","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":254,"sourceCode":"    }\n\n    private void rejectSystemSchema(String dbType, String schemaName) {\n        if (DatabaseTypeEnum.POSTGRESQL.name().equalsIgnoreCase(dbType)) {\n            String lowerSchemaName = StringUtils.lowerCase(schemaName);\n            if (POSTGRESQL_SYSTEM_SCHEMAS.contains(lowerSchemaName)\n                    || StringUtils.startsWith(lowerSchemaName, \"pg_toast\")\n                    || StringUtils.startsWith(lowerSchemaName, \"pg_temp\")) {\n                throw new BusinessException(\"database.delete.systemSchemaForbidden\");\n            }\n        }\n    }\n\n    private void assertSchemaExists(Connection connection, String databaseName, String schemaName) {\n        List<Schema> schemas = Chat2DBContext.getDbMetaData().schemas(connection, databaseName);\n        boolean exists = schemas != null && schemas.stream()\n                .anyMatch(schema -> StringUtils.equals(schema.getName(), schemaName));\n        if (!exists) {\n            throw new BusinessException(\"database.delete.schemaNotExists\");\n        }\n    }\n\n    private String schemaConfirmName(String schemaName) {\n        return schemaName;\n    }\n\n    private String buildDropSchema(String dbType, String schemaName) {\n        return Chat2DBContext.getDbMetaData(dbType).getSqlBuilder().ddl().schema().buildDropSchema(schemaName);\n    }\n\n    private void assertConfirmName(String actualConfirmName, String expectedConfirmName) {\n        if (!StringUtils.equals(actualConfirmName, expectedConfirmName)) {\n            throw new BusinessException(\"database.delete.confirmNameMismatch\");\n        }\n    }\n\n    private String maintenanceDatabase() {","sourceCodeStart":236,"sourceCodeEnd":272,"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#L236-L272","documentation":"Thrown by assertSchemaExists when the named schema is not present in the database's schema metadata listing (Chat2DBContext.getDbMetaData().schemas(connection, databaseName)). The metadata query succeeds but no Schema.getName() equals the requested schemaName. Prevents dropping a non-existent schema.","triggerScenarios":"Calling prepareSchemaDelete or executeSchemaDelete with a schemaName that does not match any schema returned by schemas(connection, databaseName). Common when the schema was dropped externally or the wrong databaseName was supplied.","commonSituations":"Schema already deleted in another session; wrong databaseName in the request so the schema list is from a different database; case-sensitivity mismatch.","solutions":["Refresh the schema list for the correct databaseName and confirm the schema still exists.","Verify the databaseName in the request matches the connection's active database.","Check case sensitivity of the schemaName parameter."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"List<Schema> schemas = Chat2DBContext.getDbMetaData().schemas(connection, databaseName);\nboolean exists = schemas != null && schemas.stream().anyMatch(s -> StringUtils.equals(s.getName(), schemaName));\nif (!exists) { /* do not call delete */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Refresh the schema list for the correct database before confirming.","Verify the databaseName in the request matches the active connection database."],"tags":["schema-delete","not-found","metadata"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}