(instanceId, projectId)
| 20 | 'use strict'; |
| 21 | |
| 22 | function main(instanceId, projectId) { |
| 23 | async function updateInstance() { |
| 24 | // [START spanner_update_instance] |
| 25 | |
| 26 | // Imports the Google Cloud client library |
| 27 | const {Spanner, protos} = require('@google-cloud/spanner'); |
| 28 | |
| 29 | /** |
| 30 | * TODO(developer): Uncomment the following lines before running the sample. |
| 31 | */ |
| 32 | // const projectId = 'my-project-id'; |
| 33 | // const instanceId = 'my-instance'; |
| 34 | |
| 35 | // Creates a client |
| 36 | const spanner = new Spanner({ |
| 37 | projectId: projectId, |
| 38 | }); |
| 39 | |
| 40 | const instanceAdminClient = spanner.getInstanceAdminClient(); |
| 41 | |
| 42 | // Updates an instance |
| 43 | try { |
| 44 | const instancePath = instanceAdminClient.instancePath( |
| 45 | projectId, |
| 46 | instanceId |
| 47 | ); |
| 48 | |
| 49 | console.log(`Updating instance ${instancePath}.`); |
| 50 | |
| 51 | const [operation] = await instanceAdminClient.updateInstance({ |
| 52 | instance: { |
| 53 | name: instancePath, |
| 54 | labels: { |
| 55 | updated: 'true', |
| 56 | created: Math.round(Date.now() / 1000).toString(), // current time |
| 57 | }, |
| 58 | edition: |
| 59 | protos.google.spanner.admin.instance.v1.Instance.Edition.ENTERPRISE, //optional |
| 60 | }, |
| 61 | // Field mask specifying fields that should get updated in an Instance |
| 62 | fieldMask: { |
| 63 | paths: ['labels', 'edition'], |
| 64 | }, |
| 65 | }); |
| 66 | |
| 67 | console.log(`Waiting for operation on ${instanceId} to complete...`); |
| 68 | await operation.promise(); |
| 69 | console.log(`Updated instance ${instanceId}.`); |
| 70 | const [metadata] = await instanceAdminClient.getInstance({ |
| 71 | name: instanceAdminClient.instancePath(projectId, instanceId), |
| 72 | }); |
| 73 | console.log( |
| 74 | `Instance ${instanceId} has been updated with the ${metadata.edition} ` + |
| 75 | 'edition.' |
| 76 | ); |
| 77 | } catch (err) { |
| 78 | console.error('Error updating instance:', err); |
| 79 | } finally { |
no test coverage detected