Skip to content

feat: Add support for UpdateDatabase in Cloud Spanner #2429

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

Merged
merged 10 commits into from
May 15, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ branchProtectionRules:
- dependencies (8)
- dependencies (11)
- lint
- clirr
- units (8)
- units (11)
- 'Kokoro - Test: Integration'
Expand Down Expand Up @@ -74,7 +73,6 @@ branchProtectionRules:
requiresStrictStatusChecks: false
requiredStatusCheckContexts:
- lint
- clirr
- units (8)
- units (11)
- 'Kokoro - Test: Integration'
Expand All @@ -87,7 +85,6 @@ branchProtectionRules:
requiresStrictStatusChecks: false
requiredStatusCheckContexts:
- lint
- clirr
- units (8)
- units (11)
- 'Kokoro - Test: Integration'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/samples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
java-version: 11
distribution: zulu
- name: Compile Spanner
run: mvn clean install
run: mvn clean install -Dclirr.skip=true
- uses: actions/setup-java@v3
with:
java-version: 8
Expand All @@ -44,7 +44,7 @@ jobs:
java-version: ${{matrix.java}}
distribution: zulu
- name: Compile Spanner
run: mvn clean install
run: mvn clean install -Dclirr.skip=true
- name: Compile samples
run: mvn compile
working-directory: samples
working-directory: samples
7 changes: 2 additions & 5 deletions git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@

set -e

# Checks for:
# - Formatting errors
# - Clirr errors
mvn com.coveo:fmt-maven-plugin:check clirr:check

# Checks for Formatting errors
mvn com.coveo:fmt-maven-plugin:check
2 changes: 1 addition & 1 deletion google-cloud-spanner-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
<configuration>
<descriptors>
<descriptor>assembly-descriptor.xml</descriptor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseRequest;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -725,6 +727,235 @@ public final UnaryCallable<GetDatabaseRequest, Database> getDatabaseCallable() {
return stub.getDatabaseCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* 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`.
*
* <p>While the operation is pending:
*
* <p>&#42; The database's [reconciling][google.spanner.admin.database.v1.Database.reconciling]
* field is set to true. &#42; 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. &#42; New
* UpdateDatabase requests will return a `FAILED_PRECONDITION` error until the pending operation
* is done (returns successfully or with error). &#42; Reading the database via the API continues
* to give the pre-request values.
*
* <p>Upon completion of the returned operation:
*
* <p>&#42; The new values are in effect and readable via the API. &#42; The database's
* [reconciling][google.spanner.admin.database.v1.Database.reconciling] field becomes false.
*
* <p>The returned [long-running operation][google.longrunning.Operation] will have a name of the
* format
* `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;/operations/&lt;operation_id&gt;`
* 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.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
* Database database = Database.newBuilder().build();
* FieldMask updateMask = FieldMask.newBuilder().build();
* Database response = databaseAdminClient.updateDatabaseAsync(database, updateMask).get();
* }
* }</pre>
*
* @param database Required. The database to update. The `name` field of the database is of the
* form `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;`.
* @param updateMask Required. The list of fields to update. Currently, only
* `enable_drop_protection` field can be updated.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Database, UpdateDatabaseMetadata> updateDatabaseAsync(
Database database, FieldMask updateMask) {
UpdateDatabaseRequest request =
UpdateDatabaseRequest.newBuilder().setDatabase(database).setUpdateMask(updateMask).build();
return updateDatabaseAsync(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* 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`.
*
* <p>While the operation is pending:
*
* <p>&#42; The database's [reconciling][google.spanner.admin.database.v1.Database.reconciling]
* field is set to true. &#42; 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. &#42; New
* UpdateDatabase requests will return a `FAILED_PRECONDITION` error until the pending operation
* is done (returns successfully or with error). &#42; Reading the database via the API continues
* to give the pre-request values.
*
* <p>Upon completion of the returned operation:
*
* <p>&#42; The new values are in effect and readable via the API. &#42; The database's
* [reconciling][google.spanner.admin.database.v1.Database.reconciling] field becomes false.
*
* <p>The returned [long-running operation][google.longrunning.Operation] will have a name of the
* format
* `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;/operations/&lt;operation_id&gt;`
* 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.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
* UpdateDatabaseRequest request =
* UpdateDatabaseRequest.newBuilder()
* .setDatabase(Database.newBuilder().build())
* .setUpdateMask(FieldMask.newBuilder().build())
* .build();
* Database response = databaseAdminClient.updateDatabaseAsync(request).get();
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Database, UpdateDatabaseMetadata> updateDatabaseAsync(
UpdateDatabaseRequest request) {
return updateDatabaseOperationCallable().futureCall(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* 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`.
*
* <p>While the operation is pending:
*
* <p>&#42; The database's [reconciling][google.spanner.admin.database.v1.Database.reconciling]
* field is set to true. &#42; 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. &#42; New
* UpdateDatabase requests will return a `FAILED_PRECONDITION` error until the pending operation
* is done (returns successfully or with error). &#42; Reading the database via the API continues
* to give the pre-request values.
*
* <p>Upon completion of the returned operation:
*
* <p>&#42; The new values are in effect and readable via the API. &#42; The database's
* [reconciling][google.spanner.admin.database.v1.Database.reconciling] field becomes false.
*
* <p>The returned [long-running operation][google.longrunning.Operation] will have a name of the
* format
* `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;/operations/&lt;operation_id&gt;`
* 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.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
* UpdateDatabaseRequest request =
* UpdateDatabaseRequest.newBuilder()
* .setDatabase(Database.newBuilder().build())
* .setUpdateMask(FieldMask.newBuilder().build())
* .build();
* OperationFuture<Database, UpdateDatabaseMetadata> future =
* databaseAdminClient.updateDatabaseOperationCallable().futureCall(request);
* // Do something.
* Database response = future.get();
* }
* }</pre>
*/
public final OperationCallable<UpdateDatabaseRequest, Database, UpdateDatabaseMetadata>
updateDatabaseOperationCallable() {
return stub.updateDatabaseOperationCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* 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`.
*
* <p>While the operation is pending:
*
* <p>&#42; The database's [reconciling][google.spanner.admin.database.v1.Database.reconciling]
* field is set to true. &#42; 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. &#42; New
* UpdateDatabase requests will return a `FAILED_PRECONDITION` error until the pending operation
* is done (returns successfully or with error). &#42; Reading the database via the API continues
* to give the pre-request values.
*
* <p>Upon completion of the returned operation:
*
* <p>&#42; The new values are in effect and readable via the API. &#42; The database's
* [reconciling][google.spanner.admin.database.v1.Database.reconciling] field becomes false.
*
* <p>The returned [long-running operation][google.longrunning.Operation] will have a name of the
* format
* `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;/operations/&lt;operation_id&gt;`
* 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.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
* UpdateDatabaseRequest request =
* UpdateDatabaseRequest.newBuilder()
* .setDatabase(Database.newBuilder().build())
* .setUpdateMask(FieldMask.newBuilder().build())
* .build();
* ApiFuture<Operation> future =
* databaseAdminClient.updateDatabaseCallable().futureCall(request);
* // Do something.
* Operation response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<UpdateDatabaseRequest, Operation> updateDatabaseCallable() {
return stub.updateDatabaseCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseRequest;
import java.io.IOException;
import java.util.List;
import javax.annotation.Generated;
Expand Down Expand Up @@ -137,6 +139,17 @@ public UnaryCallSettings<GetDatabaseRequest, Database> getDatabaseSettings() {
return ((DatabaseAdminStubSettings) getStubSettings()).getDatabaseSettings();
}

/** Returns the object with the settings used for calls to updateDatabase. */
public UnaryCallSettings<UpdateDatabaseRequest, Operation> updateDatabaseSettings() {
return ((DatabaseAdminStubSettings) getStubSettings()).updateDatabaseSettings();
}

/** Returns the object with the settings used for calls to updateDatabase. */
public OperationCallSettings<UpdateDatabaseRequest, Database, UpdateDatabaseMetadata>
updateDatabaseOperationSettings() {
return ((DatabaseAdminStubSettings) getStubSettings()).updateDatabaseOperationSettings();
}

/** Returns the object with the settings used for calls to updateDatabaseDdl. */
public UnaryCallSettings<UpdateDatabaseDdlRequest, Operation> updateDatabaseDdlSettings() {
return ((DatabaseAdminStubSettings) getStubSettings()).updateDatabaseDdlSettings();
Expand Down Expand Up @@ -391,6 +404,17 @@ public UnaryCallSettings.Builder<GetDatabaseRequest, Database> getDatabaseSettin
return getStubSettingsBuilder().getDatabaseSettings();
}

/** Returns the builder for the settings used for calls to updateDatabase. */
public UnaryCallSettings.Builder<UpdateDatabaseRequest, Operation> updateDatabaseSettings() {
return getStubSettingsBuilder().updateDatabaseSettings();
}

/** Returns the builder for the settings used for calls to updateDatabase. */
public OperationCallSettings.Builder<UpdateDatabaseRequest, Database, UpdateDatabaseMetadata>
updateDatabaseOperationSettings() {
return getStubSettingsBuilder().updateDatabaseOperationSettings();
}

/** Returns the builder for the settings used for calls to updateDatabaseDdl. */
public UnaryCallSettings.Builder<UpdateDatabaseDdlRequest, Operation>
updateDatabaseDdlSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
"UpdateBackup": {
"methods": ["updateBackup", "updateBackup", "updateBackupCallable"]
},
"UpdateDatabase": {
"methods": ["updateDatabaseAsync", "updateDatabaseAsync", "updateDatabaseOperationCallable", "updateDatabaseCallable"]
},
"UpdateDatabaseDdl": {
"methods": ["updateDatabaseDdlAsync", "updateDatabaseDdlAsync", "updateDatabaseDdlAsync", "updateDatabaseDdlOperationCallable", "updateDatabaseDdlCallable"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseRequest;
import javax.annotation.Generated;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
Expand Down Expand Up @@ -103,6 +105,15 @@ public UnaryCallable<GetDatabaseRequest, Database> getDatabaseCallable() {
throw new UnsupportedOperationException("Not implemented: getDatabaseCallable()");
}

public OperationCallable<UpdateDatabaseRequest, Database, UpdateDatabaseMetadata>
updateDatabaseOperationCallable() {
throw new UnsupportedOperationException("Not implemented: updateDatabaseOperationCallable()");
}

public UnaryCallable<UpdateDatabaseRequest, Operation> updateDatabaseCallable() {
throw new UnsupportedOperationException("Not implemented: updateDatabaseCallable()");
}

public OperationCallable<UpdateDatabaseDdlRequest, Empty, UpdateDatabaseDdlMetadata>
updateDatabaseDdlOperationCallable() {
throw new UnsupportedOperationException(
Expand Down
Loading