From 646781d519297c0cedab6b9c3829403037e2c5d4 Mon Sep 17 00:00:00 2001 From: nils Date: Thu, 31 Dec 2020 12:41:32 +0100 Subject: [PATCH 1/2] add async schmea apply --- procrastinate/schema.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/procrastinate/schema.py b/procrastinate/schema.py index e4a7fd4a6..7cffe6a85 100644 --- a/procrastinate/schema.py +++ b/procrastinate/schema.py @@ -23,3 +23,7 @@ def get_migrations_path() -> str: def apply_schema(self) -> None: queries = self.get_schema() self.connector.execute_query(query=queries) + + async def apply_schema_async(self) -> None: + queries = self.get_schema() + await self.connector.execute_query_async(query=queries) From 1cf5fdbaa8d10cf02d6203b7a8dccb031b90bd4f Mon Sep 17 00:00:00 2001 From: nils Date: Thu, 31 Dec 2020 12:45:54 +0100 Subject: [PATCH 2/2] add test for async schema apply --- tests/unit/test_schema.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/test_schema.py b/tests/unit/test_schema.py index e7da7083d..014e9fb33 100644 --- a/tests/unit/test_schema.py +++ b/tests/unit/test_schema.py @@ -1,5 +1,7 @@ from collections import defaultdict +import pytest + def test_get_schema(app): assert app.schema_manager.get_schema().startswith("-- Procrastinate Schema") @@ -15,3 +17,12 @@ def test_apply_schema(app, connector): app.schema_manager.apply_schema() assert connector.queries == [("apply_schema", {})] + + +@pytest.mark.asyncio +async def test_apply_schema_async(app, connector): + connector.reverse_queries = defaultdict(lambda: "apply_schema") + connector.set_schema_version_run = lambda *a, **kw: None + await app.schema_manager.apply_schema_async() + + assert connector.queries == [("apply_schema", {})]