feat: Add database setup guide and local configuration files

- Added DATABASE_SETUP.md with comprehensive guide for PostgreSQL and Redis installation on Windows
- Created .claude/settings.local.json with permission settings for pytest and database fix scripts
- Updated .gitignore to exclude .env.backup file
- Included database connection test utilities in lyra/database_setup.py
- Added environment variable configuration examples for local development
This commit is contained in:
2025-09-29 16:29:18 -04:00
parent faa23d596e
commit d9c526fa5c
26 changed files with 3624 additions and 39 deletions

164
test_simple_databases.py Normal file
View File

@@ -0,0 +1,164 @@
"""
Test simple database setup for Lyra AI using SQLite and FakeRedis.
This provides a working database solution without complex setup.
"""
import asyncio
import sqlite3
import os
from pathlib import Path
async def test_sqlite():
"""Test SQLite database connection."""
print("Testing SQLite database...")
try:
# Ensure data directory exists
data_dir = Path("data")
data_dir.mkdir(exist_ok=True)
db_path = data_dir / "lyra.db"
print(f"Database path: {db_path}")
# Test SQLite connection
conn = sqlite3.connect(str(db_path))
cursor = conn.cursor()
# Test creating a table
cursor.execute('''
CREATE TABLE IF NOT EXISTS test_connection (
id INTEGER PRIMARY KEY AUTOINCREMENT,
message TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
# Insert test data
cursor.execute(
'INSERT INTO test_connection (message) VALUES (?)',
('Lyra SQLite test successful',)
)
conn.commit()
# Verify test data
cursor.execute('SELECT message FROM test_connection ORDER BY id DESC LIMIT 1')
result = cursor.fetchone()
print(f"✅ SQLite connected successfully!")
print(f" Test query result: {result[0] if result else 'No data'}")
# Clean up test data
cursor.execute('DELETE FROM test_connection')
conn.commit()
conn.close()
return True
except Exception as e:
print(f"❌ SQLite connection failed: {e}")
return False
async def test_fakeredis():
"""Test FakeRedis connection."""
print("\nTesting FakeRedis...")
try:
import fakeredis.aioredis as redis
# Connect to FakeRedis (in-memory)
redis_client = redis.FakeRedis()
# Test ping
response = await redis_client.ping()
print(f"✅ FakeRedis connected successfully!")
print(f" Ping response: {response}")
# Test basic operations
await redis_client.set('lyra_test', 'Hello from Lyra AI!')
test_value = await redis_client.get('lyra_test')
print(f" Test value: {test_value.decode('utf-8')}")
# Clean up
await redis_client.delete('lyra_test')
await redis_client.close()
return True
except ImportError:
print("❌ fakeredis not installed. Run: pip install fakeredis")
return False
except Exception as e:
print(f"❌ FakeRedis connection failed: {e}")
return False
async def test_lyra_with_simple_databases():
"""Test Lyra with the simple database setup."""
print("\nTesting Lyra with simple databases...")
try:
# Try to import and initialize Lyra
from lyra.core.lyra_model import LyraModel
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Create a minimal Lyra model
lyra = LyraModel(
vocab_size=100, # Very small for testing
embed_dim=128, # Smaller
num_layers=2, # Fewer layers
num_heads=4, # Fewer heads
device=device,
enable_evolution=True
)
print("✅ Lyra initialized successfully with simple databases!")
print(f" Device: {device}")
print(f" Model size: {sum(p.numel() for p in lyra.parameters()):,} parameters")
return True
except Exception as e:
print(f"❌ Lyra initialization failed: {e}")
return False
def create_env_backup():
"""Create a backup of the current .env file."""
if os.path.exists('.env'):
import shutil
shutil.copy('.env', '.env.backup')
print("✅ Created .env backup")
async def main():
"""Main test function."""
print("=" * 60)
print("LYRA AI - SIMPLE DATABASE SETUP TEST")
print("=" * 60)
create_env_backup()
# Test individual components
sqlite_ok = await test_sqlite()
redis_ok = await test_fakeredis()
lyra_ok = await test_lyra_with_simple_databases()
print("\n" + "=" * 60)
if sqlite_ok and redis_ok and lyra_ok:
print("🎉 ALL TESTS PASSED!")
print("Lyra is ready to run with simple databases!")
print("\nBenefits of this setup:")
print("✅ No complex database server setup required")
print("✅ SQLite provides full SQL features")
print("✅ FakeRedis provides Redis compatibility")
print("✅ Everything works offline")
print("✅ Easy to backup (just copy the data/ folder)")
print("\nNext step: Run 'python -m lyra.main' to start Lyra")
else:
print("❌ SOME TESTS FAILED")
print("Check the error messages above")
print("=" * 60)
return sqlite_ok and redis_ok and lyra_ok
if __name__ == "__main__":
asyncio.run(main())