Skip to content

Commit

Permalink
Merge branch 'drop-database-protection-changes' into drop-database-pr…
Browse files Browse the repository at this point in the history
…otection
  • Loading branch information
vishwarajanand committed May 4, 2023
2 parents 4c80591 + 821888a commit 27f84cc
Show file tree
Hide file tree
Showing 11 changed files with 686 additions and 0 deletions.
Binary file modified Spanner/metadata/Admin/Database/V1/SpannerDatabaseAdmin.php
Binary file not shown.
68 changes: 68 additions & 0 deletions Spanner/src/Admin/Database/V1/Database.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Spanner/src/Admin/Database/V1/DatabaseAdminGrpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ public function GetDatabase(\Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseR
$metadata, $options);
}

/**
* @param \Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseRequest $argument input argument
* @param array $metadata metadata
* @param array $options call options
* @return \Grpc\UnaryCall
*/
public function UpdateDatabase(\Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseRequest $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabase',
$argument,
['\Google\LongRunning\Operation', 'decode'],
$metadata, $options);
}

/**
* Updates the schema of a Cloud Spanner database by
* creating/altering/dropping tables, columns, indexes, etc. The returned
Expand Down
82 changes: 82 additions & 0 deletions Spanner/src/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
use Google\Cloud\Spanner\Admin\Database\V1\UpdateBackupRequest;
use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseDdlMetadata;
use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseDdlRequest;
use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseRequest;
use Google\LongRunning\Operation;
use Google\Protobuf\FieldMask;
use Google\Protobuf\GPBEmpty;
Expand Down Expand Up @@ -2016,6 +2017,87 @@ public function updateBackup($backup, $updateMask, array $optionalArgs = [])
)->wait();
}

/**
*
* Sample code:
* ```
* $databaseAdminClient = new DatabaseAdminClient();
* try {
* $database = new Database();
* $updateMask = new FieldMask();
* $operationResponse = $databaseAdminClient->updateDatabase($database, $updateMask);
* $operationResponse->pollUntilComplete();
* if ($operationResponse->operationSucceeded()) {
* $result = $operationResponse->getResult();
* // doSomethingWith($result)
* } else {
* $error = $operationResponse->getError();
* // handleError($error)
* }
* // Alternatively:
* // start the operation, keep the operation name, and resume later
* $operationResponse = $databaseAdminClient->updateDatabase($database, $updateMask);
* $operationName = $operationResponse->getName();
* // ... do other work
* $newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'updateDatabase');
* while (!$newOperationResponse->isDone()) {
* // ... do other work
* $newOperationResponse->reload();
* }
* if ($newOperationResponse->operationSucceeded()) {
* $result = $newOperationResponse->getResult();
* // doSomethingWith($result)
* } else {
* $error = $newOperationResponse->getError();
* // handleError($error)
* }
* } finally {
* $databaseAdminClient->close();
* }
* ```
*
* @param Database $database Required. The database to update.
* The `name` field of the database is of the form
* `projects/<project>/instances/<instance>/databases/<database>`.
* @param FieldMask $updateMask Required. The list of fields to update. Currently, only
* `enable_drop_protection` field can be updated.
* @param array $optionalArgs {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return \Google\ApiCore\OperationResponse
*
* @throws ApiException if the remote call fails
*/
public function updateDatabase(
$database,
$updateMask,
array $optionalArgs = []
) {
$request = new UpdateDatabaseRequest();
$requestParamHeaders = [];
$request->setDatabase($database);
$request->setUpdateMask($updateMask);
$requestParamHeaders['database.name'] = $database->getName();
$requestParams = new RequestParamsHeaderDescriptor(
$requestParamHeaders
);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();
return $this->startOperationsCall(
'UpdateDatabase',
$optionalArgs,
$request,
$this->getOperationsClient()
)->wait();
}

/**
* Updates the schema of a Cloud Spanner database by
* creating/altering/dropping tables, columns, indexes, etc. The returned
Expand Down
174 changes: 174 additions & 0 deletions Spanner/src/Admin/Database/V1/UpdateDatabaseMetadata.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 27f84cc

Please sign in to comment.