feat: Add PostgreSQL database infrastructure

- Add SQLAlchemy models for User, Translation, ApiKey, UsageLog, PaymentHistory
- Add database connection management with PostgreSQL/SQLite support
- Add repository layer for CRUD operations
- Add Alembic migration setup with initial migration
- Update auth_service to automatically use database when DATABASE_URL is set
- Update docker-compose.yml with PostgreSQL service and Redis (non-optional)
- Add database migration script (scripts/migrate_to_db.py)
- Update .env.example with database configuration
This commit is contained in:
2025-12-31 10:56:19 +01:00
parent c4d6cae735
commit 550f3516db
15 changed files with 1712 additions and 63 deletions

View File

@@ -72,9 +72,16 @@ MAX_REQUEST_SIZE_MB=100
# Request timeout in seconds
REQUEST_TIMEOUT_SECONDS=300
# ============== Database (Production) ==============
# ============== Database ==============
# PostgreSQL connection string (recommended for production)
# DATABASE_URL=postgresql://user:password@localhost:5432/translate_db
# Format: postgresql://user:password@host:port/database
# DATABASE_URL=postgresql://translate_user:secure_password@localhost:5432/translate_db
# SQLite path (used when DATABASE_URL is not set - for development)
SQLITE_PATH=data/translate.db
# Enable SQL query logging (for debugging)
DATABASE_ECHO=false
# Redis for sessions and caching (recommended for production)
# REDIS_URL=redis://localhost:6379/0