File size: 1,728 Bytes
50c20bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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 <user_token>"

# As admin
curl -X GET http://localhost:8000/blink/audit-logs \
  -H "Authorization: Bearer <admin_token>"
```

## 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)