Refactor code structure for improved readability and maintainability

This commit is contained in:
Artem Kashaev
2026-05-28 11:20:10 +05:00
parent d5a889ed6d
commit e48b1fc0e9
21 changed files with 171 additions and 1068 deletions
+1
View File
@@ -4,3 +4,4 @@ __pycache__/
**/__pycache__/
*.pyc
.pytest_cache/
.ty/
+7 -4
View File
@@ -2,10 +2,13 @@ FROM ghcr.io/astral-sh/uv:python3.14-bookworm-slim
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev
COPY app ./app
COPY alembic.ini ./alembic.ini
COPY alembic ./alembic
COPY bff/pyproject.toml ./bff/pyproject.toml
COPY logic/pyproject.toml ./logic/pyproject.toml
RUN uv sync --frozen --no-dev --all-packages
COPY logic/app ./logic/app
COPY logic/alembic.ini ./logic/alembic.ini
COPY logic/alembic ./logic/alembic
WORKDIR /app/logic
EXPOSE 8000
CMD ["/app/.venv/bin/uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
+1 -2
View File
@@ -1,10 +1,9 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config, pool
from alembic import context
from app.core import settings
from app.models import Base
from sqlalchemy import engine_from_config, pool
config = context.config
config.set_main_option("sqlalchemy.url", settings.database_url)
@@ -8,9 +8,8 @@ Create Date: 2026-05-28 10:00:00.000000
from collections.abc import Sequence
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from alembic import op
from sqlalchemy.dialects import postgresql
revision: str = "0001_initial"
down_revision: str | None = None
+9 -2
View File
@@ -7,20 +7,27 @@ from sqlalchemy.orm import Session, sessionmaker
from app.core import settings
engine = create_engine(settings.database_url, pool_pre_ping=True)
engine = create_engine(
settings.database_url,
pool_pre_ping=True,
connect_args={"connect_timeout": 3},
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def create_schema(metadata: MetaData, attempts: int = 30, delay_seconds: int = 2) -> None:
last_error: OperationalError | None = None
for _ in range(attempts):
for attempt in range(1, attempts + 1):
try:
print(f"Connecting to database, attempt {attempt}/{attempts}", flush=True)
with engine.begin() as connection:
connection.execute(text("SELECT 1"))
metadata.create_all(bind=connection)
print("Database schema is ready", flush=True)
return
except OperationalError as exc:
last_error = exc
print(f"Database is not ready: {exc}", flush=True)
sleep(delay_seconds)
if last_error:
raise last_error
+2 -13
View File
@@ -10,16 +10,5 @@ dependencies = [
"sqlalchemy>=2.0.41",
]
[dependency-groups]
dev = [
"pytest>=8.3.5",
"ruff>=0.11.11",
"ty>=0.0.1a6",
]
[tool.ruff]
line-length = 100
target-version = "py314"
[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B"]
[tool.uv]
package = false
-1001
View File
File diff suppressed because it is too large Load Diff