Skip to content

Commit f9a725c

Browse files
potiuktseaver
authored andcommitted
Add 'operation_id' parameter to 'Database.update_ddl'. (googleapis#6825)
1 parent d363d23 commit f9a725c

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

spanner/google/cloud/spanner_v1/database.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def reload(self):
254254
response = api.get_database_ddl(self.name, metadata=metadata)
255255
self._ddl_statements = tuple(response.statements)
256256

257-
def update_ddl(self, ddl_statements):
257+
def update_ddl(self, ddl_statements, operation_id=''):
258258
"""Update DDL for this database.
259259
260260
Apply any configured schema from :attr:`ddl_statements`.
@@ -264,6 +264,8 @@ def update_ddl(self, ddl_statements):
264264
265265
:type ddl_statements: Sequence[str]
266266
:param ddl_statements: a list of DDL statements to use on this database
267+
:type operation_id: str
268+
:param operation_id: (optional) a string ID for the long-running operation
267269
268270
:rtype: :class:`google.api_core.operation.Operation`
269271
:returns: an operation instance
@@ -274,7 +276,7 @@ def update_ddl(self, ddl_statements):
274276
metadata = _metadata_with_prefix(self.name)
275277

276278
future = api.update_database_ddl(
277-
self.name, ddl_statements, "", metadata=metadata
279+
self.name, ddl_statements, operation_id=operation_id, metadata=metadata
278280
)
279281
return future
280282

spanner/tests/system/test_system.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import threading
2222
import time
2323
import unittest
24+
import uuid
2425

2526
import pytest
2627

@@ -323,20 +324,23 @@ def test_table_not_found(self):
323324
"5629"
324325
)
325326
)
326-
def test_update_database_ddl(self):
327+
def test_update_database_ddl_with_operation_id(self):
327328
pool = BurstyPool(labels={"testcase": "update_database_ddl"})
328329
temp_db_id = "temp_db" + unique_resource_id("_")
329330
temp_db = Config.INSTANCE.database(temp_db_id, pool=pool)
330331
create_op = temp_db.create()
331332
self.to_delete.append(temp_db)
332333

333334
# We want to make sure the operation completes.
334-
create_op.result(120) # raises on failure / timeout.
335+
create_op.result(240) # raises on failure / timeout.
336+
# random but shortish always start with letter
337+
operation_id = 'a' + str(uuid.uuid4())[:8]
338+
operation = temp_db.update_ddl(DDL_STATEMENTS, operation_id=operation_id)
335339

336-
operation = temp_db.update_ddl(DDL_STATEMENTS)
340+
self.assertEqual(operation_id, operation.operation.name.split('/')[-1])
337341

338342
# We want to make sure the operation completes.
339-
operation.result(120) # raises on failure / timeout.
343+
operation.result(240) # raises on failure / timeout.
340344

341345
temp_db.reload()
342346

spanner/tests/unit/test_database.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,28 @@ def test_update_ddl(self):
588588
metadata=[("google-cloud-resource-prefix", database.name)],
589589
)
590590

591+
def test_update_ddl_w_operation_id(self):
592+
from tests._fixtures import DDL_STATEMENTS
593+
594+
op_future = object()
595+
client = _Client()
596+
api = client.database_admin_api = self._make_database_admin_api()
597+
api.update_database_ddl.return_value = op_future
598+
instance = _Instance(self.INSTANCE_NAME, client=client)
599+
pool = _Pool()
600+
database = self._make_one(self.DATABASE_ID, instance, pool=pool)
601+
602+
future = database.update_ddl(DDL_STATEMENTS, operation_id='someOperationId')
603+
604+
self.assertIs(future, op_future)
605+
606+
api.update_database_ddl.assert_called_once_with(
607+
self.DATABASE_NAME,
608+
DDL_STATEMENTS,
609+
"someOperationId",
610+
metadata=[("google-cloud-resource-prefix", database.name)],
611+
)
612+
591613
def test_drop_grpc_error(self):
592614
from google.api_core.exceptions import Unknown
593615

0 commit comments

Comments
 (0)