Repository navigation
Conversation
Exporting or auditing active Spanner table, index, and graph definitions calls DatabaseAdminClient.get_database_ddl. Add a standalone spanner_get_database_ddl sample and test suite.
|
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 module get_database_ddl.py and its associated tests to retrieve and print schema DDL statements for a Google Cloud Spanner database. Feedback on the changes points out a potential IndexError when parsing empty or whitespace-only DDL statements, suggesting a safer check before accessing the first line of the split statement.
| for statement in statements: | ||
| first_line = statement.strip().splitlines()[0] | ||
| print(f"DDL Statement: {first_line}") |
There was a problem hiding this comment.
If a DDL statement is empty or contains only whitespace, statement.strip().splitlines() will return an empty list, causing an IndexError when accessing the first element [0]. It is safer to check if the list is non-empty before accessing its elements.
| for statement in statements: | |
| first_line = statement.strip().splitlines()[0] | |
| print(f"DDL Statement: {first_line}") | |
| for statement in statements: | |
| lines = statement.strip().splitlines() | |
| first_line = lines[0] if lines else "" | |
| print(f"DDL Statement: {first_line}") |
There was a problem hiding this comment.
Thanks! Keeping this as is: the statements returned for a database's schema are not empty, and the extra branching would distract from what the sample shows.
Description
Adds
spanner_get_database_ddlretrieving schema DDL statements viaDatabaseAdminClient.get_database_ddl.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions