Files
SPARC/scripts/init_database.py
T
0xWheatyz 44456cb073 feat: add database mode for LLM message storage and analytics
Implements a database mode that stores LLM prompts and responses in PostgreSQL
instead of making API calls. This enables:
- Testing without consuming API credits
- Collecting analytics on usage patterns
- Development and debugging workflows

Changes:
- Added DatabaseClient class for PostgreSQL operations
- Modified LLMAnalyzer to support database/API mode toggle
- Added USE_DATABASE config flag to switch between modes
- Included Docker Compose setup for PostgreSQL
- Added utility scripts for database init and analytics viewing
- Comprehensive documentation in DATABASE_MODE.md

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-10 21:13:13 -04:00

43 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Initialize the SPARC database schema.
This script creates the necessary tables and indexes for storing
LLM messages for testing and analytics.
Usage:
python scripts/init_database.py
"""
import sys
import os
# Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from SPARC import config
from SPARC.database import DatabaseClient
def main():
"""Initialize the database schema."""
print("Initializing SPARC database...")
print(f"Database URL: {config.database_url}")
try:
db_client = DatabaseClient(config.database_url)
db_client.initialize_schema()
print("Database schema initialized successfully!")
print("\nTables created:")
print(" - llm_messages: Stores all LLM prompts and responses")
print("\nIndexes created:")
print(" - idx_messages_timestamp: For time-based queries")
print(" - idx_messages_company: For company-specific queries")
except Exception as e:
print(f"Error initializing database: {e}")
sys.exit(1)
if __name__ == "__main__":
main()