# DB Service - Quick Start ## Run Tests ```bash # Install test dependencies pip install pytest pytest-asyncio httpx # Run all tests ADMIN_EMAILS="admin@example.com" pytest tests/test_db_service.py -v # Run specific test pytest tests/test_db_service.py::TestPermissions::test_user_can_read_own_data -v # Run with coverage pytest tests/test_db_service.py --cov=services/db_service --cov-report=html -v ``` ## Start Application ```bash # Development (reset DB on startup) RESET_DB=true ADMIN_EMAILS="your@email.com" python app.py # Production (preserve DB) ADMIN_EMAILS="admin@example.com" python app.py ``` ## Verify Integration Check startup logs for: ``` ✅ DB Service configured ✅ Database initialized ✅ Database reset complete (if RESET_DB=true) ``` ## Test Endpoints ```bash # As regular user curl -X GET http://localhost:8000/gemini/jobs \ -H "Authorization: Bearer " # As admin curl -X GET http://localhost:8000/blink/audit-logs \ -H "Authorization: Bearer " ``` ## Troubleshooting **Config not registered:** ``` RuntimeError: DBServiceConfig not registered! ``` → Ensure `register_db_service_config()` is called in app startup **Module not found:** ``` ModuleNotFoundError: No module named 'services.db_service' ``` → Verify `__init__.py` exists in `services/db_service/` **Permission denied:** ``` 403 Forbidden: Only administrators can... ``` → Check `ADMIN_EMAILS` environment variable ## Success Indicators ✅ All files compile without errors ✅ Application starts successfully ✅ Database tables created ✅ Tests pass ✅ Endpoints return data correctly ✅ User isolation working (users see only own data) ✅ Admin access working (admins see all data)