@@ -633,6 +633,188 @@ async def sample_get_database():
633633 # Done; return the response.
634634 return response
635635
636+ async def update_database (
637+ self ,
638+ request : Optional [
639+ Union [spanner_database_admin .UpdateDatabaseRequest , dict ]
640+ ] = None ,
641+ * ,
642+ database : Optional [spanner_database_admin .Database ] = None ,
643+ update_mask : Optional [field_mask_pb2 .FieldMask ] = None ,
644+ retry : OptionalRetry = gapic_v1 .method .DEFAULT ,
645+ timeout : Union [float , object ] = gapic_v1 .method .DEFAULT ,
646+ metadata : Sequence [Tuple [str , str ]] = (),
647+ ) -> operation_async .AsyncOperation :
648+ r"""Updates a Cloud Spanner database. The returned [long-running
649+ operation][google.longrunning.Operation] can be used to track
650+ the progress of updating the database. If the named database
651+ does not exist, returns ``NOT_FOUND``.
652+
653+ While the operation is pending:
654+
655+ - The database's
656+ [reconciling][google.spanner.admin.database.v1.Database.reconciling]
657+ field is set to true.
658+ - Cancelling the operation is best-effort. If the cancellation
659+ succeeds, the operation metadata's
660+ [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time]
661+ is set, the updates are reverted, and the operation
662+ terminates with a ``CANCELLED`` status.
663+ - New UpdateDatabase requests will return a
664+ ``FAILED_PRECONDITION`` error until the pending operation is
665+ done (returns successfully or with error).
666+ - Reading the database via the API continues to give the
667+ pre-request values.
668+
669+ Upon completion of the returned operation:
670+
671+ - The new values are in effect and readable via the API.
672+ - The database's
673+ [reconciling][google.spanner.admin.database.v1.Database.reconciling]
674+ field becomes false.
675+
676+ The returned [long-running
677+ operation][google.longrunning.Operation] will have a name of the
678+ format
679+ ``projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>``
680+ and can be used to track the database modification. The
681+ [metadata][google.longrunning.Operation.metadata] field type is
682+ [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata].
683+ The [response][google.longrunning.Operation.response] field type
684+ is [Database][google.spanner.admin.database.v1.Database], if
685+ successful.
686+
687+ .. code-block:: python
688+
689+ # This snippet has been automatically generated and should be regarded as a
690+ # code template only.
691+ # It will require modifications to work:
692+ # - It may require correct/in-range values for request initialization.
693+ # - It may require specifying regional endpoints when creating the service
694+ # client as shown in:
695+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
696+ from google.cloud import spanner_admin_database_v1
697+
698+ async def sample_update_database():
699+ # Create a client
700+ client = spanner_admin_database_v1.DatabaseAdminAsyncClient()
701+
702+ # Initialize request argument(s)
703+ database = spanner_admin_database_v1.Database()
704+ database.name = "name_value"
705+
706+ request = spanner_admin_database_v1.UpdateDatabaseRequest(
707+ database=database,
708+ )
709+
710+ # Make the request
711+ operation = client.update_database(request=request)
712+
713+ print("Waiting for operation to complete...")
714+
715+ response = (await operation).result()
716+
717+ # Handle the response
718+ print(response)
719+
720+ Args:
721+ request (Optional[Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest, dict]]):
722+ The request object. The request for
723+ [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase].
724+ database (:class:`google.cloud.spanner_admin_database_v1.types.Database`):
725+ Required. The database to update. The ``name`` field of
726+ the database is of the form
727+ ``projects/<project>/instances/<instance>/databases/<database>``.
728+
729+ This corresponds to the ``database`` field
730+ on the ``request`` instance; if ``request`` is provided, this
731+ should not be set.
732+ update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
733+ Required. The list of fields to update. Currently, only
734+ ``enable_drop_protection`` field can be updated.
735+
736+ This corresponds to the ``update_mask`` field
737+ on the ``request`` instance; if ``request`` is provided, this
738+ should not be set.
739+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
740+ should be retried.
741+ timeout (float): The timeout for this request.
742+ metadata (Sequence[Tuple[str, str]]): Strings which should be
743+ sent along with the request as metadata.
744+
745+ Returns:
746+ google.api_core.operation_async.AsyncOperation:
747+ An object representing a long-running operation.
748+
749+ The result type for the operation will be
750+ :class:`google.cloud.spanner_admin_database_v1.types.Database`
751+ A Cloud Spanner database.
752+
753+ """
754+ # Create or coerce a protobuf request object.
755+ # Quick check: If we got a request object, we should *not* have
756+ # gotten any keyword arguments that map to the request.
757+ has_flattened_params = any ([database , update_mask ])
758+ if request is not None and has_flattened_params :
759+ raise ValueError (
760+ "If the `request` argument is set, then none of "
761+ "the individual field arguments should be set."
762+ )
763+
764+ request = spanner_database_admin .UpdateDatabaseRequest (request )
765+
766+ # If we have keyword arguments corresponding to fields on the
767+ # request, apply these.
768+ if database is not None :
769+ request .database = database
770+ if update_mask is not None :
771+ request .update_mask = update_mask
772+
773+ # Wrap the RPC method; this adds retry and timeout information,
774+ # and friendly error handling.
775+ rpc = gapic_v1 .method_async .wrap_method (
776+ self ._client ._transport .update_database ,
777+ default_retry = retries .Retry (
778+ initial = 1.0 ,
779+ maximum = 32.0 ,
780+ multiplier = 1.3 ,
781+ predicate = retries .if_exception_type (
782+ core_exceptions .DeadlineExceeded ,
783+ core_exceptions .ServiceUnavailable ,
784+ ),
785+ deadline = 3600.0 ,
786+ ),
787+ default_timeout = 3600.0 ,
788+ client_info = DEFAULT_CLIENT_INFO ,
789+ )
790+
791+ # Certain fields should be provided within the metadata header;
792+ # add these here.
793+ metadata = tuple (metadata ) + (
794+ gapic_v1 .routing_header .to_grpc_metadata (
795+ (("database.name" , request .database .name ),)
796+ ),
797+ )
798+
799+ # Send the request.
800+ response = await rpc (
801+ request ,
802+ retry = retry ,
803+ timeout = timeout ,
804+ metadata = metadata ,
805+ )
806+
807+ # Wrap the response in an operation future.
808+ response = operation_async .from_gapic (
809+ response ,
810+ self ._client ._transport .operations_client ,
811+ spanner_database_admin .Database ,
812+ metadata_type = spanner_database_admin .UpdateDatabaseMetadata ,
813+ )
814+
815+ # Done; return the response.
816+ return response
817+
636818 async def update_database_ddl (
637819 self ,
638820 request : Optional [
0 commit comments