chore: release v1.0.0 — каркас FastAPI, ingress Grafana, интеграции, документация

Made-with: Cursor
This commit is contained in:
Alexandr
2026-04-03 08:30:56 +03:00
commit 4da9b13a86
34 changed files with 1049 additions and 0 deletions

32
onguard24/db.py Normal file
View File

@ -0,0 +1,32 @@
import asyncpg
from onguard24.config import Settings
def normalize_dsn(url: str) -> str:
if url.startswith("postgres://"):
return url.replace("postgres://", "postgresql://", 1)
return url
async def create_pool(settings: Settings) -> asyncpg.Pool | None:
if not settings.database_url.strip():
return None
dsn = normalize_dsn(settings.database_url.strip())
return await asyncpg.create_pool(dsn=dsn, min_size=1, max_size=10)
MIGRATION_001 = """
CREATE TABLE IF NOT EXISTS ingress_events (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
source text NOT NULL,
received_at timestamptz NOT NULL DEFAULT now(),
body jsonb NOT NULL
);
CREATE INDEX IF NOT EXISTS ingress_events_received_at_idx ON ingress_events (received_at DESC);
"""
async def migrate(pool: asyncpg.Pool) -> None:
async with pool.acquire() as conn:
await conn.execute(MIGRATION_001)