Repository: s3rius/FastAPI-template (language: python)

Issue:
Fix postgres error in docker-compose.
We need to change healthcheck command.

Because healthcheck command is incorrect postgres is constantly write in log "FATAL:  role "root" does not exist".

It must be fixed by providing different healthcheck command.


Discussion / hints:

Fix patch:
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml
index c93d33a..639a7ee 100644
--- a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml
@@ -6,6 +6,7 @@ services:
       context: .
       dockerfile: ./deploy/Dockerfile
     image: {{cookiecutter.project_name}}:{{"${" }}{{cookiecutter.project_name | upper }}_VERSION:-latest{{"}"}}
+    restart: always
     env_file:
       - .env
     {%- if ((cookiecutter.db_info.name != "none" and cookiecutter.db_info.name != "sqlite") or
@@ -51,8 +52,9 @@ services:
       - "POSTGRES_DB={{cookiecutter.project_name}}"
     volumes:
       - {{cookiecutter.project_name}}-db-data:/var/lib/postgresql/data
+    restart: always
     healthcheck:
-      test: ["CMD-SHELL", "pg_isready"]
+      test: pg_isready -U {{cookiecutter.project_name}}
       interval: 2s
       timeout: 3s
       retries: 40
@@ -62,6 +64,7 @@ services:
   db:
     image: {{cookiecutter.db_info.image}}
     hostname: {{cookiecutter.project_name}}-db
+    restart: always
     environment:
       - "ALLOW_EMPTY_PASSWORD=yes"
       - "MYSQL_ROOT_PASSWORD={{cookiecutter.project_name}}"
@@ -115,10 +118,11 @@ services:
   redis:
     image: bitnami/redis:6.2.5
     hostname: {{cookiecutter.project_name}}-redis
+    restart: always
     environment:
       - "ALLOW_EMPTY_PASSWORD=yes"
     healthcheck:
-      test: ["CMD", "redis-cli", "ping"]
+      test: redis-cli ping
       interval: 1s
       timeout: 3s
       retries: 30
diff --git a/pyproject.toml b/pyproject.toml
index 3658f44..39133be 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "fastapi_template"
-version = "3.1.2"
+version = "3.1.3"
 description = "Feature-rich robust FastAPI template"
 authors = ["Pavel Kirilin <win10@list.ru>"]
 packages = [{ include = "fastapi_template" }]


Test patch:
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py
index 8ab5548..245d408 100644
--- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py
@@ -22,8 +22,7 @@
 from {{cookiecutter.project_name}}.db.dependencies import get_db_session
 from {{cookiecutter.project_name}}.db.utils import create_database, drop_database
 {%- elif cookiecutter.orm == "tortoise" %}
-from tortoise.contrib.test import finalizer, initializer, _restore_default  # noqa: WPS450
-from tortoise import Tortoise
+from tortoise.contrib.test import finalizer, initializer
 from {{cookiecutter.project_name}}.db.config import MODELS_MODULES
 {%- endif %}
 {%- endif %}
@@ -124,7 +123,7 @@ async def transaction(_engine: AsyncEngine) -> AsyncGenerator[AsyncConnection, N
         await conn.rollback()
 {%- elif cookiecutter.orm == "tortoise" %}
 
-@pytest.fixture(scope="session", autouse=True)
+@pytest.fixture(autouse=True)
 def initialize_db(event_loop: AbstractEventLoop) -> Generator[None, None, None]:
     """
     Initialize models and database.
@@ -143,25 +142,6 @@ def initialize_db(event_loop: AbstractEventLoop) -> Generator[None, None, None]:
 
     finalizer()
 
-@pytest.fixture(autouse=True)
-@pytest.mark.asyncio
-async def clean_db() -> AsyncGenerator[None, None]:
-    """
-    Removes all data from database after test.
-
-    :yields: Nothing.
-    """
-    yield
-
-    _restore_default()
-    for app in Tortoise.apps.values():
-        for model in app.values():
-            meta = model._meta  # noqa: WPS437
-            quote_char = meta.db.query_class._builder().QUOTE_CHAR  # noqa: WPS437
-            await meta.db.execute_script(
-                f"DELETE FROM {quote_char}{meta.db_table}{quote_char}" # noqa: S608
-            )
-
 {%- endif %}
 {%- endif %}