claude-code-tracker/init_db.py

49 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
Database initialization script for Claude Code Tracker.
This script ensures the database is properly initialized before the application starts.
"""
import asyncio
import os
import sys
from pathlib import Path
# Add the app directory to the Python path
sys.path.append(str(Path(__file__).parent))
from app.database.connection import init_database, engine
async def ensure_database_initialized():
"""Ensure the database is properly initialized."""
try:
print("Initializing database...")
# Create data directory if it doesn't exist
data_dir = Path("/app/data")
data_dir.mkdir(parents=True, exist_ok=True)
# Set permissions on data directory
os.chmod(str(data_dir), 0o777)
# Initialize database
await init_database()
print("Database initialization completed successfully!")
return True
except Exception as e:
print(f"Database initialization failed: {e}")
# Don't exit - let the app try to continue
return False
finally:
# Clean up engine
try:
await engine.dispose()
except:
pass
if __name__ == "__main__":
asyncio.run(ensure_database_initialized())