-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Spanner): add sample for update database (#1793)
- Loading branch information
1 parent
384a0f0
commit 0d8f29d
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"require": { | ||
"google/cloud-spanner": "^1.54.0" | ||
"google/cloud-spanner": "^1.62.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Copyright 2023 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* For instructions on how to run the full sample: | ||
* | ||
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md | ||
*/ | ||
|
||
namespace Google\Cloud\Samples\Spanner; | ||
|
||
// [START spanner_update_database] | ||
use Google\Cloud\Spanner\SpannerClient; | ||
|
||
/** | ||
* Updates the drop protection setting for a database. | ||
* Example: | ||
* ``` | ||
* update_database($instanceId, $databaseId); | ||
* ``` | ||
* | ||
* @param string $instanceId The Spanner instance ID. | ||
* @param string $databaseId The Spanner database ID. | ||
*/ | ||
function update_database(string $instanceId, string $databaseId): void | ||
{ | ||
$spanner = new SpannerClient(); | ||
$instance = $spanner->instance($instanceId); | ||
$database = $instance->database($databaseId); | ||
printf( | ||
'Updating database %s', | ||
$database->name(), | ||
); | ||
$op = $database->updateDatabase(['enableDropProtection' => true]); | ||
$op->pollUntilComplete(); | ||
$database->reload(); | ||
printf( | ||
'Updated the drop protection for %s to %s' . PHP_EOL, | ||
$database->name(), | ||
$database->info()['enableDropProtection'] | ||
); | ||
} | ||
// [END spanner_update_database] | ||
|
||
// The following 2 lines are only needed to run the samples | ||
require_once __DIR__ . '/../../testing/sample_helpers.php'; | ||
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters