## Documentation System - Create complete documentation hub at /dashboard/docs with: - Getting Started guide with quick setup and troubleshooting - Hook Setup Guide with platform-specific configurations - API Reference with all endpoints and examples - FAQ with searchable questions and categories - Add responsive design with interactive features - Update navigation in base template ## Tool Call Tracking - Add ToolCall model for tracking Claude Code tool usage - Create /api/tool-calls endpoints for recording and analytics - Add tool_call hook type with auto-session detection - Include tool calls in project statistics and recalculation - Track tool names, parameters, execution time, and success rates ## Project Enhancements - Add project timeline and statistics pages (fix 404 errors) - Create recalculation script for fixing zero statistics - Update project stats to include tool call counts - Enhance session model with tool call relationships ## Infrastructure - Switch from requirements.txt to pyproject.toml/uv.lock - Add data import functionality for claude.json files - Update database connection to include all new models - Add comprehensive API documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
"""
|
|
Database connection management for the Claude Code Project Tracker.
|
|
"""
|
|
|
|
import os
|
|
from typing import AsyncGenerator
|
|
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
|
|
from sqlalchemy.pool import StaticPool
|
|
|
|
from app.models.base import Base
|
|
|
|
# Database configuration
|
|
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///./data/tracker.db")
|
|
|
|
# Create async engine
|
|
engine = create_async_engine(
|
|
DATABASE_URL,
|
|
echo=os.getenv("DEBUG", "false").lower() == "true", # Log SQL queries in debug mode
|
|
connect_args={"check_same_thread": False} if "sqlite" in DATABASE_URL else {},
|
|
poolclass=StaticPool if "sqlite" in DATABASE_URL else None,
|
|
)
|
|
|
|
# Create session factory
|
|
async_session_maker = async_sessionmaker(
|
|
engine,
|
|
class_=AsyncSession,
|
|
expire_on_commit=False
|
|
)
|
|
|
|
|
|
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|
"""
|
|
Dependency function to get database session.
|
|
|
|
Used by FastAPI dependency injection to provide database sessions
|
|
to route handlers.
|
|
"""
|
|
async with async_session_maker() as session:
|
|
try:
|
|
yield session
|
|
except Exception:
|
|
await session.rollback()
|
|
raise
|
|
finally:
|
|
await session.close()
|
|
|
|
|
|
def get_engine():
|
|
"""Get the database engine."""
|
|
return engine
|
|
|
|
|
|
async def init_database():
|
|
"""Initialize the database by creating all tables."""
|
|
async with engine.begin() as conn:
|
|
# Import all models to ensure they're registered
|
|
from app.models import (
|
|
Project, Session, Conversation, Activity,
|
|
WaitingPeriod, GitOperation, ToolCall
|
|
)
|
|
|
|
# Create all tables
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
|
|
print("Database initialized successfully!")
|
|
|
|
|
|
async def close_database():
|
|
"""Close database connections."""
|
|
await engine.dispose()
|
|
print("Database connections closed.") |