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

feat: Add support for UpdateDatabase in Cloud Spanner #1848

Merged
merged 2 commits into from
May 12, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@ import "google/iam/v1/iam_policy.proto";
import "google/iam/v1/policy.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
import "google/spanner/admin/database/v1/backup.proto";
import "google/spanner/admin/database/v1/common.proto";
Expand Down Expand Up @@ -89,6 +90,55 @@ service DatabaseAdmin {
option (google.api.method_signature) = "name";
}

// Updates a Cloud Spanner database. The returned
// [long-running operation][google.longrunning.Operation] can be used to track
// the progress of updating the database. If the named database does not
// exist, returns `NOT_FOUND`.
//
// While the operation is pending:
//
// * The database's
// [reconciling][google.spanner.admin.database.v1.Database.reconciling]
// field is set to true.
// * Cancelling the operation is best-effort. If the cancellation succeeds,
// the operation metadata's
// [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time]
// is set, the updates are reverted, and the operation terminates with a
// `CANCELLED` status.
// * New UpdateDatabase requests will return a `FAILED_PRECONDITION` error
// until the pending operation is done (returns successfully or with
// error).
// * Reading the database via the API continues to give the pre-request
// values.
//
// Upon completion of the returned operation:
//
// * The new values are in effect and readable via the API.
// * The database's
// [reconciling][google.spanner.admin.database.v1.Database.reconciling]
// field becomes false.
//
// The returned [long-running operation][google.longrunning.Operation] will
// have a name of the format
// `projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>`
// and can be used to track the database modification. The
// [metadata][google.longrunning.Operation.metadata] field type is
// [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata].
// The [response][google.longrunning.Operation.response] field type is
// [Database][google.spanner.admin.database.v1.Database], if successful.
rpc UpdateDatabase(UpdateDatabaseRequest)
returns (google.longrunning.Operation) {
option (google.api.http) = {
patch: "/v1/{database.name=projects/*/instances/*/databases/*}"
body: "database"
};
option (google.api.method_signature) = "database,update_mask";
option (google.longrunning.operation_info) = {
response_type: "Database"
metadata_type: "UpdateDatabaseMetadata"
};
}

// Updates the schema of a Cloud Spanner database by
// creating/altering/dropping tables, columns, indexes, etc. The returned
// [long-running operation][google.longrunning.Operation] will have a name of
Expand Down Expand Up @@ -449,6 +499,14 @@ message Database {

// Output only. The dialect of the Cloud Spanner Database.
DatabaseDialect database_dialect = 10 [(google.api.field_behavior) = OUTPUT_ONLY];

// Whether drop protection is enabled for this database. Defaults to false,
// if not set.
bool enable_drop_protection = 11;

// Output only. If true, the database is being updated. If false, there are no
// ongoing update operations for the database.
bool reconciling = 12 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// The request for [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases].
Expand Down Expand Up @@ -537,6 +595,37 @@ message GetDatabaseRequest {
];
}

// The request for
// [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase].
message UpdateDatabaseRequest {
// Required. The database to update.
// The `name` field of the database is of the form
// `projects/<project>/instances/<instance>/databases/<database>`.
Database database = 1 [(google.api.field_behavior) = REQUIRED];

// Required. The list of fields to update. Currently, only
// `enable_drop_protection` field can be updated.
google.protobuf.FieldMask update_mask = 2
[(google.api.field_behavior) = REQUIRED];
}

// Metadata type for the operation returned by
// [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase].
message UpdateDatabaseMetadata {
// The request for
// [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase].
UpdateDatabaseRequest request = 1;

// The progress of the
// [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]
// operation.
OperationProgress progress = 2;

// The time at which this operation was cancelled. If set, this operation is
// in the process of undoing itself (which is best-effort).
google.protobuf.Timestamp cancel_time = 3;
}

// Enqueues the given DDL statements to be applied, in order but not
// necessarily all at once, to the database schema at some point (or
// points) in the future. The server checks that the statements
Expand Down