Pull Request Merged
PR #5 merged: feat: API key authentication and Alembic migrations
Summary
- Add Alembic database migrations for production-ready schema management
- Add API key authentication for secure Laravel ↔ Server communication
- Refine Docker setup with health checks and production config
- Add end-to-end test script
Changes
Database Migrations
- Initialize Alembic with async SQLAlchemy support
- Initial schema migration (
f4937396683c) - captures 16 existing tables - API keys migration (
5e2dee2daae6) - addsapi_keystable - Remove
create_all()- now relies on Alembic migrations
API Key Authentication
APIKeymodel for database-backed keysapi_key_guardfor Litestar route protection- Supports
X-API-Keyheader andAuthorization: Bearertoken - Config-based
API_KEYenv var for simple deployments - All data endpoints (
/users/{user_id}/*) now protected
Docker
.dockerignorefor smaller builds- Health checks for both services
docker-compose.prod.ymlfor production deployment- Dockerfile updated with curl
Testing
scripts/test_e2e.py- comprehensive end-to-end tests- 8 tests covering auth, endpoints, health checks
Test plan
-
alembic upgrade headcreates tables correctly -
alembic downgrade -1andupgrade headworks - API endpoints return 401 without API key
- API endpoints work with valid X-API-Key header
- API endpoints work with Bearer token
- Health endpoint remains public
- Docker containers show "healthy" status
- E2E test script passes (8/8 tests)
Laravel Integration
Http::withHeaders([
'X-API-Key' => config('services.polar_flow.api_key'),
])->get('http://polar-flow-server:8000/users/{$polarUserId}/sleep');
🤖 Generated with Claude Code
+1502
additions
-27
deletions
21
files changed