Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: add support for updateDatabase in Cloud Spanner #917

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions samples/samples/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ def create_database(instance_id, database_id):
# [END spanner_create_database]


# [START spanner_update_database]
def update_database(instance_id, database_id):
"""Updates the drop protection setting for a database."""
spanner_client = spanner.Client()
instance = spanner_client.instance(instance_id)

db = instance.database(database_id)
db.enable_drop_protection = True

operation = db.update(["enable_drop_protection"])

print("Waiting for update operation for {} to complete...".format(
db.name))
operation.result(OPERATION_TIMEOUT_SECONDS)

print("Updated database {}.".format(db.name))


# [END spanner_update_database]


# [START spanner_create_database_with_encryption_key]
def create_database_with_encryption_key(instance_id, database_id, kms_key_name):
"""Creates a database with tables using a Customer Managed Encryption Key (CMEK)."""
Expand Down
13 changes: 13 additions & 0 deletions samples/samples/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ def test_create_instance_with_processing_units(capsys, lci_instance_id):
retry_429(instance.delete)()


def test_update_database(capsys, instance_id, sample_database):
snippets.update_database(
instance_id, sample_database.database_id
)
out, _ = capsys.readouterr()
assert "Updated database {}.".format(sample_database.name) in out

# Cleanup
sample_database.enable_drop_protection = False
op = sample_database.update(["enable_drop_protection"])
op.result()


def test_create_database_with_encryption_config(
capsys, instance_id, cmek_database_id, kms_key_name
):
Expand Down