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
Problem: reviewers of this sample set asked for stricter and clearer tests and for a single source of truth for dependencies. Mocks were created without a spec, so a renamed client argument would pass silently; the mocked wait timeout was raised from the API call instead of from the operation's result; live tests did not say which environment variables they need; and some tests carried leftover or repeated lines. Package dependencies were pinned in both pyproject.toml and requirements.txt. Solution: where applicable to the files below, patch client classes with autospec=True, raise the mocked TimeoutError from operation.result(), document the required environment variables above each live test and skip when one is missing, remove unused or duplicated test lines, and join string literals that the formatter had left split on one line. For package scaffolding, read dependencies from requirements.txt and update the README install command to match. 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