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

docs(samples): Add samples for Cloud Spanner Default Backup Schedules #1238

Merged
merged 6 commits into from
Nov 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion samples/samples/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
google-cloud-spanner==3.49.1
google-cloud-spanner==3.50.0
futures==3.4.0; python_version < "3"
51 changes: 51 additions & 0 deletions samples/samples/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3222,6 +3222,57 @@ def create_instance_with_autoscaling_config(instance_id):
# [END spanner_create_instance_with_autoscaling_config]


# [START spanner_create_instance_without_default_backup_schedule]
def create_instance_without_default_backup_schedules(instance_id):
spanner_client = spanner.Client()
config_name = "{}/instanceConfigs/regional-me-central2".format(
spanner_client.project_name
)

operation = spanner_client.instance_admin_api.create_instance(
parent=spanner_client.project_name,
instance_id=instance_id,
instance=spanner_instance_admin.Instance(
config=config_name,
display_name="This is a display name.",
node_count=1,
default_backup_schedule_type=spanner_instance_admin.Instance.DefaultBackupScheduleType.NONE, # Optional
),
)

print("Waiting for operation to complete...")
operation.result(OPERATION_TIMEOUT_SECONDS)

print("Created instance {} without default backup schedules".format(instance_id))


# [END spanner_create_instance_without_default_backup_schedule]


# [START spanner_update_instance_default_backup_schedule_type]
def update_instance_default_backup_schedule_type(instance_id):
spanner_client = spanner.Client()

name = "{}/instances/{}".format(spanner_client.project_name, instance_id)

operation = spanner_client.instance_admin_api.update_instance(
instance=spanner_instance_admin.Instance(
name=name,
default_backup_schedule_type=spanner_instance_admin.Instance.DefaultBackupScheduleType.AUTOMATIC, # Optional
),
field_mask=field_mask_pb2.FieldMask(
paths=["default_backup_schedule_type"]
),
)

print("Waiting for operation to complete...")
operation.result(OPERATION_TIMEOUT_SECONDS)

print("Updated instance {} to have default backup schedules".format(instance_id))

# [END spanner_update_instance_default_backup_schedule_type]


def add_proto_type_columns(instance_id, database_id):
# [START spanner_add_proto_type_columns]
# instance_id = "your-spanner-instance"
Expand Down
19 changes: 19 additions & 0 deletions samples/samples/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ def test_create_instance_with_autoscaling_config(capsys, lci_instance_id):
retry_429(instance.delete)()


def test_create_and_update_instance_default_backup_schedule_type(capsys, lci_instance_id):
retry_429(snippets.create_instance_without_default_backup_schedules)(
lci_instance_id,
)
create_out, _ = capsys.readouterr()
assert lci_instance_id in create_out
assert "without default backup schedules" in create_out

retry_429(snippets.update_instance_default_backup_schedule_type)(
lci_instance_id,
)
update_out, _ = capsys.readouterr()
assert lci_instance_id in update_out
assert "to have default backup schedules" in update_out
spanner_client = spanner.Client()
instance = spanner_client.instance(lci_instance_id)
retry_429(instance.delete)()


def test_create_instance_partition(capsys, instance_partition_instance_id):
# Unable to use create_instance since it has editions set where partitions are unsupported.
# The minimal requirement for editions is ENTERPRISE_PLUS for the paritions to get supported.
Expand Down