Skip to content

feat(spanner): Add GoogleSQL database creation sample - #14943

Open
iennae wants to merge 2 commits into
mainfrom
feat/spanner-create-database
Open

iennae wants to merge 2 commits into
mainfrom
feat/spanner-create-database

Conversation

@iennae

@iennae iennae commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

Scaffolds spanner/database_admin/ and adds spanner_create_database creating a GoogleSQL Spanner database with Singers and Albums DDL.

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

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.
@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

@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 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.

Comment on lines +35 to +51
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",
],

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

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.

Suggested change
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""",
],

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 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
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