Repository navigation
Conversation
Zero-downtime schema evolution guides add nullable columns such as Albums.MarketingBudget via DatabaseAdminClient.update_database_ddl. Add a standalone spanner_add_column sample.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
| 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"], | |
| ) | |
| ) |
There was a problem hiding this comment.
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
Description
Adds
spanner_add_columnaddingMarketingBudget INT64online viaDatabaseAdminClient.update_database_ddl.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions