Replace the in-memory store with PostgreSQL 18.6: SQLAlchemy 2.1 async engine on asyncpg, alembic migrations with an async env.py, repos on AsyncSession and services that own the transaction. Username uniqueness is enforced by the database (ON CONFLICT), a chat and its members are created in one transaction, member order is kept in chat_members.position, and a composite foreign key makes the sender a member of the chat. History and chat lists use keyset pagination on (chat_id, created_at, id) and (user_id, created_at, chat_id). The compose stand runs postgres, a one-shot migrate service on the API image and the API. All Postgres addresses come from .env without literals; only the 127.0.0.1 publish address stays literal. make run_dev starts Postgres and applies migrations before the server, and make env_setup generates a random Postgres password. Unavailable PostgreSQL yields 503: get_db_session bounds the request with asyncio and classifies driver errors. BoundedCloseConnection limits asyncpg's graceful close, which otherwise waited without limit on a frozen server and held the request until it was resumed. Add scripts/restart.sh for make test-persistence and make test_isolated, which runs the image on a throwaway test database. Remove make run_no_compose. X-User-Id identification is unchanged until the session-auth change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
1.4 KiB
TOML
26 lines
1.4 KiB
TOML
# Шаблон config.toml: `make env_setup` копирует его, не перезаписывая
|
||
# существующий файл. Приоритет: окружение > .env > config.toml >
|
||
# значения по умолчанию. Любой параметр можно задать и через
|
||
# окружение: SECTION__FIELD, например APP__LOG_LEVEL.
|
||
|
||
[app]
|
||
# Режим (console / docker) задают Makefile, Dockerfile и compose через
|
||
# APP__RUN_MODE, а порт — APP__PORT в .env; здесь их не указывать.
|
||
log_level = "INFO"
|
||
# сколько секунд uvicorn ждёт текущие запросы после SIGTERM
|
||
graceful_shutdown_seconds = 8
|
||
|
||
[database]
|
||
# Адрес, порт, пользователь, пароль и имя базы приходят из .env (мосты к
|
||
# POSTGRES_*) и из environment compose; здесь их не указывать.
|
||
pool_size = 10
|
||
max_overflow = 5
|
||
# секунды ожидания свободного соединения пула
|
||
pool_timeout_seconds = 5
|
||
# секунды на установку соединения
|
||
connect_timeout_seconds = 3
|
||
# миллисекунды, серверный statement_timeout; 0 — без ограничения
|
||
statement_timeout_ms = 5000
|
||
# секунды на всю работу запроса с БД: зависший сервер, обрыв сети
|
||
request_timeout_seconds = 6
|