change to TUI

This commit is contained in:
2025-09-12 09:08:10 -07:00
parent 7c7dcb5b10
commit e0e70f6508
165 changed files with 3438 additions and 16154 deletions

View File

@@ -1,10 +1,19 @@
import os
from pathlib import Path
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import declarative_base, sessionmaker
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql+asyncpg://postgres:password@db:5432/cycling")
# Use SQLite database in data directory
DATA_DIR = Path("data")
DATABASE_PATH = DATA_DIR / "cycling_coach.db"
DATABASE_URL = os.getenv("DATABASE_URL", f"sqlite+aiosqlite:///{DATABASE_PATH}")
engine = create_async_engine(
DATABASE_URL,
echo=False, # Set to True for SQL debugging
connect_args={"check_same_thread": False} if "sqlite" in DATABASE_URL else {}
)
engine = create_async_engine(DATABASE_URL, echo=True)
AsyncSessionLocal = sessionmaker(
bind=engine,
class_=AsyncSession,
@@ -15,4 +24,19 @@ Base = declarative_base()
async def get_db() -> AsyncSession:
async with AsyncSessionLocal() as session:
yield session
yield session
async def init_db():
"""Initialize the database by creating all tables."""
# Ensure data directory exists
DATA_DIR.mkdir(exist_ok=True)
# Import all models to ensure they are registered
from .models import (
user, rule, plan, plan_rule, workout,
analysis, route, section, garmin_sync_log, prompt
)
# Create all tables
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)