Skip to content

Commit a282dca

Browse files
author
Sergio García Prado
committed
ISSUE #51
* Add `build_create` method to the `SagaExecutionDatabaseOperationFactory` interface.
1 parent 4ba8533 commit a282dca

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

packages/core/minos-microservice-saga/minos/saga/executions/repositories/database/factories.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
class SagaExecutionDatabaseOperationFactory(DatabaseOperationFactory, ABC):
1616
"""Saga Execution Database Operation Factory class."""
1717

18+
@abstractmethod
19+
def build_create(self) -> DatabaseOperation:
20+
"""Build the database operation to create the delta table.
21+
22+
:return: A ``DatabaseOperation`` instance.s
23+
"""
24+
1825
@abstractmethod
1926
def build_store(self, uuid: UUID, **kwargs) -> DatabaseOperation:
2027
"""Build the database operation to store a saga execution.

packages/core/minos-microservice-saga/minos/saga/executions/repositories/database/impl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ def __init__(self, *args, database_key: Optional[tuple[str]] = None, **kwargs):
3636
database_key = ("saga",)
3737
super().__init__(*args, database_key=database_key, **kwargs)
3838

39+
async def _setup(self) -> None:
40+
await super()._setup()
41+
42+
operation = self.database_operation_factory.build_create()
43+
await self.execute_on_database(operation)
44+
3945
async def _store(self, execution: SagaExecution) -> None:
4046
operation = self.database_operation_factory.build_store(**execution.raw)
4147
await self.execute_on_database(operation)

packages/core/minos-microservice-saga/minos/saga/testing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
class MockedSagaExecutionDatabaseOperationFactory(SagaExecutionDatabaseOperationFactory):
3636
"""For testing purposes"""
3737

38+
def build_create(self) -> DatabaseOperation:
39+
"""For testing purposes"""
40+
return MockedDatabaseOperation("create_table")
41+
3842
def build_store(self, uuid: UUID, **kwargs) -> DatabaseOperation:
3943
"""For testing purposes"""
4044
return MockedDatabaseOperation("create_table")

packages/core/minos-microservice-saga/tests/test_saga/test_executions/test_repositories/test_database/test_factories.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def test_abstract(self):
1616
self.assertTrue(issubclass(SagaExecutionDatabaseOperationFactory, (DatabaseOperationFactory, ABC)))
1717
# noinspection PyUnresolvedReferences
1818
self.assertEqual(
19-
{"build_store", "build_load", "build_delete"}, SagaExecutionDatabaseOperationFactory.__abstractmethods__
19+
{"build_create", "build_store", "build_load", "build_delete"},
20+
SagaExecutionDatabaseOperationFactory.__abstractmethods__,
2021
)
2122

2223

packages/plugins/minos-database-lmdb/minos/plugins/lmdb/factories/saga/executions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
)
44

55
from minos.common import (
6+
ComposedDatabaseOperation,
67
DatabaseOperation,
78
)
89
from minos.saga import (
@@ -29,6 +30,13 @@ def build_table_name(self) -> str:
2930
"""
3031
return "LocalState"
3132

33+
def build_create(self) -> DatabaseOperation:
34+
"""Build the database operation to create the delta table.
35+
36+
:return: A ``DatabaseOperation`` instance.s
37+
"""
38+
return ComposedDatabaseOperation([]) # FIXME: create specific empty operation.
39+
3240
def build_store(self, uuid: UUID, **kwargs) -> DatabaseOperation:
3341
"""Build the database operation to store a saga execution.
3442

0 commit comments

Comments
 (0)