Files
mtusi2026lab2/.env.example
T
ricoromaandClaude Opus 5.5 4921afa39d feat: store messenger data in PostgreSQL
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>
2026-10-01 15:33:49 +03:00

44 lines
2.5 KiB
Bash

# Шаблон .env: `make env_setup` создаёт из него .env, не перезаписывая
# существующий файл, и подставляет случайный POSTGRES_PASSWORD. .env не
# коммитить. .env читают compose, Makefile и приложение
# (pydantic-settings); в контейнеры он не попадает.
# Параметры приложения — в формате настроек SECTION__FIELD, без секции —
# только то, что приложение не читает. Комментарии — только отдельными
# строками: make оставляет хвостовой комментарий частью значения.
# Соответствие переменным skeleton (APP_HOST, APP_PORT, APP_ENV,
# SESSION_TTL_SECONDS, DATABASE_URL_FILE, SESSION_STORE, CACHE_URL_FILE) —
# в REPORT.md, «Архитектура и решения».
# порт сервиса ([app] port): на нём слушает приложение, его же
# публикует compose, на нём же healthcheck
APP__PORT=8080
# порт на 127.0.0.1 хоста, куда публикуется сервис; приложение его
# не читает
APP_OUT_PORT=8080
# PostgreSQL. POSTGRES_USER, POSTGRES_PASSWORD и POSTGRES_DB читает и
# образ postgres; пароль задаётся только при первом создании volume.
# Пустой пароль образ postgres не принимает: make env_setup подставляет
# случайный
POSTGRES_USER=messenger
POSTGRES_PASSWORD=
POSTGRES_DB=messenger
# адрес и порт Postgres внутри сети compose: по ним ходят API и миграции
# в docker, порт слушает сам сервер (PGPORT)
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
# порт на 127.0.0.1 хоста, куда публикуется Postgres: к нему подключается
# приложение в console
POSTGRES_OUT_PORT=5433
# мосты для console: приложение на хосте берёт значения отсюда, в docker
# их задаёт environment compose
DATABASE__HOST=127.0.0.1
DATABASE__PORT=${POSTGRES_OUT_PORT}
DATABASE__USER=${POSTGRES_USER}
DATABASE__PASSWORD=${POSTGRES_PASSWORD}
DATABASE__NAME=${POSTGRES_DB}
# make test_isolated: порт на 127.0.0.1, куда публикуется тестовый
# контейнер API
TEST_APP_PORT=18088