2929from google .api_core import gapic_v1
3030from google .iam .v1 import iam_policy_pb2
3131from google .iam .v1 import options_pb2
32+ from google .protobuf .field_mask_pb2 import FieldMask
3233
3334from google .cloud .spanner_admin_database_v1 import CreateDatabaseRequest
3435from google .cloud .spanner_admin_database_v1 import Database as DatabasePB
@@ -124,6 +125,9 @@ class Database(object):
124125 (Optional) database dialect for the database
125126 :type database_role: str or None
126127 :param database_role: (Optional) user-assigned database_role for the session.
128+ :type drop_protection_enabled: boolean
129+ :param drop_protection_enabled: (Optional) Represents whether the database
130+ has drop protection enabled or not.
127131 """
128132
129133 _spanner_api = None
@@ -138,6 +142,7 @@ def __init__(
138142 encryption_config = None ,
139143 database_dialect = DatabaseDialect .DATABASE_DIALECT_UNSPECIFIED ,
140144 database_role = None ,
145+ drop_protection_enabled = False ,
141146 ):
142147 self .database_id = database_id
143148 self ._instance = instance
@@ -155,6 +160,8 @@ def __init__(
155160 self ._encryption_config = encryption_config
156161 self ._database_dialect = database_dialect
157162 self ._database_role = database_role
163+ self .drop_protection_enabled = drop_protection_enabled
164+ self ._reconciling = False
158165
159166 if pool is None :
160167 pool = BurstyPool (database_role = database_role )
@@ -328,6 +335,15 @@ def database_role(self):
328335 """
329336 return self ._database_role
330337
338+ @property
339+ def reconciling (self ):
340+ """Whether the database is currently reconciling.
341+
342+ :rtype: boolean
343+ :returns: a boolean representing whether the database is reconciling
344+ """
345+ return self ._reconciling
346+
331347 @property
332348 def logger (self ):
333349 """Logger used by the database.
@@ -457,6 +473,7 @@ def reload(self):
457473 self ._encryption_info = response .encryption_info
458474 self ._default_leader = response .default_leader
459475 self ._database_dialect = response .database_dialect
476+ self .drop_protection_enabled = response .enable_drop_protection
460477
461478 def update_ddl (self , ddl_statements , operation_id = "" ):
462479 """Update DDL for this database.
@@ -488,6 +505,42 @@ def update_ddl(self, ddl_statements, operation_id=""):
488505 future = api .update_database_ddl (request = request , metadata = metadata )
489506 return future
490507
508+ def update (self ):
509+ """Update this database.
510+
511+ See
512+ TODO: insert documentation once ready
513+
514+ .. note::
515+
516+ Updates the `drop_protection_enabled` field. To change this value
517+ before updating, set it via
518+
519+ .. code:: python
520+
521+ database.drop_protection_enabled = True
522+
523+ before calling :meth:`update`.
524+
525+ :rtype: :class:`google.api_core.operation.Operation`
526+ :returns: an operation instance
527+ :raises NotFound: if the database does not exist
528+ """
529+ api = self ._instance ._client .database_admin_api
530+ database_pb = DatabasePB (
531+ name = self .name , enable_drop_protection = self .drop_protection_enabled
532+ )
533+
534+ # Only support updating drop protection for now.
535+ field_mask = FieldMask (paths = ["enable_drop_protection" ])
536+ metadata = _metadata_with_prefix (self .name )
537+
538+ future = api .update_database (
539+ database = database_pb , update_mask = field_mask , metadata = metadata
540+ )
541+
542+ return future
543+
491544 def drop (self ):
492545 """Drop this database.
493546
0 commit comments