Adopt async SQLAlchemy storage and verified Alembic migrations

Keep the message and idempotency receipt in one Core CTE statement with chat-first locking. Preserve rollback, bounded dependency failures, and domain ports.

Replace the SQL runner with Alembic. Adopt legacy databases only after validating their journal and PostgreSQL schema, retain all data, and verify migrations on fresh and populated databases.
This commit is contained in:
Artyom
2026-11-05 21:38:12 +03:00
parent c376882ce8
commit 71c643c6d1
29 changed files with 1542 additions and 409 deletions
+8 -1
View File
@@ -4,8 +4,10 @@ from uuid import uuid4
import pytest
from httpx import AsyncClient, Response
from sqlalchemy import func, select
from conftest import actor, keyed, make_chat, register, running_app, scalar
from messenger.messaging.infrastructure.postgres import IdempotencyKeyRow
INVALID_KEYS = ["", "k" * 129, "два слова", "a b", "a/b", "ключ"]
@@ -142,4 +144,9 @@ async def test_concurrent_retries_through_two_replicas_store_one_message() -> No
}
assert all(response.json() == responses[0].json() for response in responses)
assert [item["text"] for item in await history(second, chat, alice)] == [text]
assert await scalar("SELECT count(*) FROM idempotency_keys WHERE key = $1", key) == 1
assert (
await scalar(
select(func.count()).select_from(IdempotencyKeyRow).where(IdempotencyKeyRow.key == key)
)
== 1
)