Skip to content

feat(spanner): Add GoogleSQL online ALTER TABLE ADD COLUMN sample - #14951

Open
iennae wants to merge 2 commits into
feat/spanner-create-databasefrom
feat/spanner-add-column
Open

iennae wants to merge 2 commits into
feat/spanner-create-databasefrom
feat/spanner-add-column

Conversation

@iennae

@iennae iennae commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

Adds spanner_add_column adding MarketingBudget INT64 online via DatabaseAdminClient.update_database_ddl.

Note: Stacked on #14943 (feat/spanner-create-database) so this PR shows only this sample's diff. It will merge into main after #14943.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. Unit and live integration tests pass on Python 3.13.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

Zero-downtime schema evolution guides add nullable columns such as Albums.MarketingBudget via DatabaseAdminClient.update_database_ddl. Add a standalone spanner_add_column sample.
@iennae
iennae requested review from a team as code owners November 18, 2026 22:18
@snippet-bot

snippet-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples. labels Nov 18, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new script and tests for adding a MarketingBudget column to a Spanner database table using DDL. The implementation includes robust error handling and a CLI entrypoint. The feedback suggests enhancing the unit tests by explicitly asserting that the update_database_ddl API call is made with the expected request parameters, ensuring the test is more robust.

f"projects/{PROJECT_ID}/instances/{INSTANCE_ID}/databases/{DATABASE_ID}"
)

add_column.add_column(PROJECT_ID, INSTANCE_ID, DATABASE_ID)

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.

medium

The test currently only asserts the printed output but does not verify that the update_database_ddl method was actually called with the correct parameters. Adding an assertion for the API call makes the test much more robust against accidental changes to the SQL statement or request parameters.

Suggested change
add_column.add_column(PROJECT_ID, INSTANCE_ID, DATABASE_ID)
add_column.add_column(PROJECT_ID, INSTANCE_ID, DATABASE_ID)
mock_client_class.return_value.update_database_ddl.assert_called_once_with(
request=spanner_admin_database_v1.UpdateDatabaseDdlRequest(
database=f"projects/{PROJECT_ID}/instances/{INSTANCE_ID}/databases/{DATABASE_ID}",
statements=["ALTER TABLE Albums ADD COLUMN MarketingBudget INT64"],
)
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion, done: the unit test now asserts the database path and DDL statement in the request (3c790f1).

Problem: review of this sample identified correctness and robustness
improvements in the sample and its tests.

Solution: apply the accepted review suggestions and extend the tests to
cover the updated behavior. Details are in the review thread replies.

Files updated:
  - spanner/database_admin/tests/add_column_test.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant