feat(spanner): add spanner-update-database-schema tool - #3819
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the spanner-update-database-schema tool to execute DDL statements on Cloud Spanner databases, along with corresponding updates to prebuilt configurations, tests, and documentation. Feedback on the implementation highlights a potential issue where non-string or empty elements in the statements array are silently skipped, which could lead to partial migration execution; it is recommended to return an error instead.
| case []any: | ||
| for _, elem := range v { | ||
| if str, ok := elem.(string); ok && str != "" { | ||
| statements = append(statements, str) | ||
| } | ||
| } |
There was a problem hiding this comment.
Silently skipping non-string or empty elements in the statements array can lead to partial execution of a DDL migration, which can leave the database schema in an inconsistent or broken state. It is safer to return an error if any element in the array is not a valid, non-empty string.
case []any:
for _, elem := range v {
str, ok := elem.(string)
if !ok {
return nil, util.NewAgentError(fmt.Sprintf("invalid element type in 'statements': expected string, got %T", elem), nil)
}
if str == "" {
return nil, util.NewAgentError("empty statement is not allowed", nil)
}
statements = append(statements, str)
}4b2939c to
79ccea2
Compare
79ccea2 to
913c8a6
Compare
913c8a6 to
851134e
Compare
851134e to
69ac557
Compare
69ac557 to
78e17a7
Compare
78e17a7 to
c79c149
Compare
Description
This PR introduces the
spanner-update-database-schematool for executing DDL schema mutations (CREATE TABLE,ALTER TABLE,CREATE INDEX, etc.) on Cloud Spanner databases, along with automatic agent suppression on read-only sources.Changes:
UpdateDatabaseDdl(ctx, statements, tokenString)on SpannerSourceusingDatabaseAdminClient.UpdateDatabaseDdland waiting for long-running operation completion viaop.Wait(ctx).spanner-update-database-schemawith destructive annotations (readOnlyHint: false,destructiveHint: true).tools.ShouldSuppressso the tool is hidden from MCP agents when connected to a read-only Spanner source.update_database_schemaandget_database_ddlto thedataanddata_with_discoverytoolsets inspanner.yamlandspanner-postgres.yaml.config_test.goand unit tests to validate schema updating and suppression behavior.