Repository navigation
Conversation
Core Spanner getting-started guides create a GoogleSQL database with Singers and interleaved Albums DDL via DatabaseAdminClient.create_database. Scaffold spanner/database_admin and add spanner_create_database.
|
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 Python sample project for Cloud Spanner Database Administration, including configuration files, a README, and a script to create a Spanner database with Singers and Albums tables. It also includes unit and integration tests. The feedback suggests improving the readability and maintainability of the DDL statements in create_database.py by replacing implicit string concatenation with triple-quoted multi-line strings.
| extra_statements=[ | ||
| "CREATE TABLE Singers (" | ||
| " SingerId INT64 NOT NULL," | ||
| " FirstName STRING(1024)," | ||
| " LastName STRING(1024)," | ||
| " SingerInfo BYTES(MAX)," | ||
| " FullName STRING(2048) AS (" | ||
| " ARRAY_TO_STRING([FirstName, LastName], ' ')" | ||
| " ) STORED" | ||
| ") PRIMARY KEY (SingerId)", | ||
| "CREATE TABLE Albums (" | ||
| " SingerId INT64 NOT NULL," | ||
| " AlbumId INT64 NOT NULL," | ||
| " AlbumTitle STRING(MAX)" | ||
| ") PRIMARY KEY (SingerId, AlbumId)," | ||
| " INTERLEAVE IN PARENT Singers ON DELETE CASCADE", | ||
| ], |
There was a problem hiding this comment.
Using implicit string concatenation across multiple lines with single/double quotes can be error-prone and harder to read. Using triple-quoted multi-line strings for each DDL statement is much cleaner and more maintainable.
| extra_statements=[ | |
| "CREATE TABLE Singers (" | |
| " SingerId INT64 NOT NULL," | |
| " FirstName STRING(1024)," | |
| " LastName STRING(1024)," | |
| " SingerInfo BYTES(MAX)," | |
| " FullName STRING(2048) AS (" | |
| " ARRAY_TO_STRING([FirstName, LastName], ' ')" | |
| " ) STORED" | |
| ") PRIMARY KEY (SingerId)", | |
| "CREATE TABLE Albums (" | |
| " SingerId INT64 NOT NULL," | |
| " AlbumId INT64 NOT NULL," | |
| " AlbumTitle STRING(MAX)" | |
| ") PRIMARY KEY (SingerId, AlbumId)," | |
| " INTERLEAVE IN PARENT Singers ON DELETE CASCADE", | |
| ], | |
| extra_statements=[ | |
| """CREATE TABLE Singers ( | |
| SingerId INT64 NOT NULL, | |
| FirstName STRING(1024), | |
| LastName STRING(1024), | |
| SingerInfo BYTES(MAX), | |
| FullName STRING(2048) AS ( | |
| ARRAY_TO_STRING([FirstName, LastName], ' ') | |
| ) STORED | |
| ) PRIMARY KEY (SingerId)""", | |
| """CREATE TABLE Albums ( | |
| SingerId INT64 NOT NULL, | |
| AlbumId INT64 NOT NULL, | |
| AlbumTitle STRING(MAX) | |
| ) PRIMARY KEY (SingerId, AlbumId), | |
| INTERLEAVE IN PARENT Singers ON DELETE CASCADE""", | |
| ], |
There was a problem hiding this comment.
Good suggestion, done: the DDL statements are now triple-quoted strings (26c014d). The same change was applied to the other samples in this set that built multi-line SQL from adjacent string fragments, so they are consistent.
Problem: multi-line SQL and DDL statements were written as adjacent string fragments. That style is easy to get wrong (a missing trailing space joins two SQL tokens) and is harder to read than the statement itself, and the samples in this set mixed it with triple-quoted SQL. Solution: write each multi-line statement as a single triple-quoted string, matching the layout already used by the other samples. Only whitespace between SQL tokens changes; the statements are otherwise identical. Files updated: - spanner/database_admin/src/spanner_database_admin/create_database.py
Description
Scaffolds
spanner/database_admin/and addsspanner_create_databasecreating a GoogleSQL Spanner database withSingersandAlbumsDDL.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions