29
29
from google .api_core import gapic_v1
30
30
from google .iam .v1 import iam_policy_pb2
31
31
from google .iam .v1 import options_pb2
32
+ from google .protobuf .field_mask_pb2 import FieldMask
32
33
33
34
from google .cloud .spanner_admin_database_v1 import CreateDatabaseRequest
34
35
from google .cloud .spanner_admin_database_v1 import Database as DatabasePB
@@ -124,6 +125,9 @@ class Database(object):
124
125
(Optional) database dialect for the database
125
126
:type database_role: str or None
126
127
: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.
127
131
"""
128
132
129
133
_spanner_api = None
@@ -138,6 +142,7 @@ def __init__(
138
142
encryption_config = None ,
139
143
database_dialect = DatabaseDialect .DATABASE_DIALECT_UNSPECIFIED ,
140
144
database_role = None ,
145
+ drop_protection_enabled = False ,
141
146
):
142
147
self .database_id = database_id
143
148
self ._instance = instance
@@ -155,6 +160,8 @@ def __init__(
155
160
self ._encryption_config = encryption_config
156
161
self ._database_dialect = database_dialect
157
162
self ._database_role = database_role
163
+ self .drop_protection_enabled = drop_protection_enabled
164
+ self ._reconciling = False
158
165
159
166
if pool is None :
160
167
pool = BurstyPool (database_role = database_role )
@@ -328,6 +335,15 @@ def database_role(self):
328
335
"""
329
336
return self ._database_role
330
337
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
+
331
347
@property
332
348
def logger (self ):
333
349
"""Logger used by the database.
@@ -457,6 +473,7 @@ def reload(self):
457
473
self ._encryption_info = response .encryption_info
458
474
self ._default_leader = response .default_leader
459
475
self ._database_dialect = response .database_dialect
476
+ self .drop_protection_enabled = response .enable_drop_protection
460
477
461
478
def update_ddl (self , ddl_statements , operation_id = "" ):
462
479
"""Update DDL for this database.
@@ -488,6 +505,42 @@ def update_ddl(self, ddl_statements, operation_id=""):
488
505
future = api .update_database_ddl (request = request , metadata = metadata )
489
506
return future
490
507
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
+
491
544
def drop (self ):
492
545
"""Drop this database.
493
546
0 commit comments