-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for UpdateDatabase (#1802)
* feat: add support for drop database protection Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
72efb81
commit f4fbe71
Showing
7 changed files
with
322 additions
and
2 deletions.
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
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
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,72 @@ | ||
// 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. | ||
// 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. | ||
|
||
// sample-metadata: | ||
// title: Updates a Cloud Spanner Database. | ||
// usage: node database-update.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID> | ||
|
||
'use strict'; | ||
|
||
function main( | ||
instanceId = 'my-instance', | ||
databaseId = 'my-database', | ||
projectId = 'my-project-id' | ||
) { | ||
// [START spanner_update_database] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const instanceId = 'my-instance'; | ||
// const databaseId = 'my-database'; | ||
// const projectId = 'my-project-id'; | ||
|
||
// Imports the Google Cloud Spanner client library | ||
const {Spanner} = require('@google-cloud/spanner'); | ||
|
||
// Instantiates a client | ||
const spanner = new Spanner({ | ||
projectId: projectId, | ||
}); | ||
|
||
async function updateDatabase() { | ||
// Gets a reference to a Cloud Spanner instance and database | ||
const instance = spanner.instance(instanceId); | ||
const database = instance.database(databaseId); | ||
|
||
try { | ||
console.log(`Updating database ${database.id}.`); | ||
const [operation] = await database.setMetadata({ | ||
enableDropProtection: true, | ||
}); | ||
console.log( | ||
`Waiting for update operation for ${database.id} to complete...` | ||
); | ||
await operation.promise(); | ||
console.log(`Updated database ${database.id}.`); | ||
} catch (err) { | ||
console.log('ERROR:', err); | ||
} finally { | ||
// Close the database when finished. | ||
database.close(); | ||
} | ||
} | ||
updateDatabase(); | ||
// [END spanner_update_database] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
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
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
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
Oops, something went wrong.