Ryan Malloy 50c80596d0 Add comprehensive Docker deployment and file upload functionality
Features Added:
• Docker containerization with multi-stage Python 3.12 build
• Caddy reverse proxy integration with automatic SSL
• File upload interface for .claude.json imports with preview
• Comprehensive hook system with 39+ hook types across 9 categories
• Complete documentation system with Docker and import guides

Technical Improvements:
• Enhanced database models with hook tracking capabilities
• Robust file validation and error handling for uploads
• Production-ready Docker compose configuration
• Health checks and resource limits for containers
• Database initialization scripts for containerized deployments

Documentation:
• Docker Deployment Guide with troubleshooting
• Data Import Guide with step-by-step instructions
• Updated Getting Started guide with new features
• Enhanced documentation index with responsive grid layout

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 08:02:09 -06:00

78 lines
2.3 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,
HookEvent, ToolError, WaitingPeriodNew, PerformanceMetric,
CodeQualityEvent, WorkflowEvent, LearningEvent,
EnvironmentEvent, CollaborationEvent, ProjectIntelligence
)
# Initialize hook relationships
from app.models.hooks import add_hook_relationships
add_hook_relationships()
# 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.")