lab2 complete
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
kuruoni
2026-11-14 04:50:02 +03:00
parent 65003b6119
commit 684d00c899
20 changed files with 796 additions and 16 deletions
+25
View File
@@ -0,0 +1,25 @@
import os
import asyncpg
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://messenger:secret_password@postgres:5432/messenger_db")
pool: asyncpg.Pool = None
async def init_db():
global pool
pool = await asyncpg.create_pool(DATABASE_URL, min_size=2, max_size=10)
migration_path = os.path.join(os.path.dirname(__file__), "migrations", "001_init_db.sql")
if os.path.exists(migration_path):
with open(migration_path, "r", encoding="utf-8") as f:
sql = f.read()
async with pool.acquire() as conn:
await conn.execute(sql)
async def close_db():
global pool
if pool:
await pool.close()
def get_pool() -> asyncpg.Pool:
return pool