←
PPLX-44
Created: 2025-12-21
•
Updated: 2025-12-22
Relationships
Loading...
Attachments
Loading...
Comments (3)
agent
·
2025-12-22
## Database Migration Fix Applied
### Problem
The /api/usage/breakdown endpoint was returning HTTP 500 errors due to missing database column `is_research_report` in the `queries` table.
### Root Cause
The database was created outside of alembic (using SQLAlchemy directly), so the `alembic_version` table was empty. When `alembic upgrade head` was run, it tried to run ALL migrations from scratch, which failed because the tables already existed.
### Solution Applied
1. Stamped the database to the initial migration: `alembic stamp cc9d2f3bc955`
2. Ran remaining migrations: `alembic upgrade head`
This applied the following migrations:
- a534488c3a48: add cost breakdown columns to api_usage_log
- b8c21e4f5d67: add missing API fields to search_results and images
- c9d3e4f6a789: add source field to search_results and title field to images
- d1e2f3a4b5c6: add async_queries table for deep research mode
- e2f3a4b5c6d7: add is_research_report flag to queries table (the critical one)
- f3a4b5c6d7e8: add progress tracking fields to async_queries table
### Verification
- All 414 backend tests pass
- /api/usage/breakdown endpoint now returns valid JSON responses
- /api/usage/summary endpoint continues to work
### Note for Future Deployments
When setting up a new database or environment, always run `alembic upgrade head` after creating the database to ensure all schema migrations are applied.
QA Agent
·
2025-12-22
[QA] FAILED - Database migration required
## Summary
The code implementation and tests are excellent (414/414 tests pass), but the /api/usage/breakdown endpoint is non-functional in production due to a missing database column.
## Critical Issue
- **Error**: sqlite3.OperationalError: no such column: queries.is_research_report
- **Cause**: Production database missing column added in migration e2f3a4b5c6d7
- **Impact**: All requests to /api/usage/breakdown return HTTP 500
## Required Fix
```bash
cd backend
alembic upgrade head
# Then verify: sqlite3 perplexity_clone.db ".schema queries" | grep is_research_report
```
## Test Results
- ✅ All 414 automated tests pass
- ✅ 35 usage endpoint tests pass (18 summary + 17 breakdown)
- ❌ Manual testing fails - endpoint non-functional
- ❌ Database schema doesn't match models
## Details
See full QA report: /tmp/qa-PPLX-44.md
The implementation agent did excellent work. This is a deployment/migration issue, not a code quality issue.
agent
·
2025-12-22
## Implementation Complete
### Summary
Added comprehensive tests for usage endpoints including a new breakdown endpoint.
### Changes Made
**1. New /api/usage/breakdown endpoint** (backend/routers/usage.py:116-235)
- GET endpoint with pagination (page, page_size)
- Sorting by date, cost, or tokens (asc/desc)
- Filtering by model, thread, date range
- Returns individual usage entries with query details
**2. CRUD function** (backend/crud.py:830-945)
- get_usage_breakdown() with full filter/sort/pagination support
- Properly handles null costs and tokens
- Limits page_size to max 100
**3. Schemas** (backend/schemas.py:353-373)
- UsageBreakdownEntry: Individual usage entry
- UsageBreakdownResponse: Paginated response
**4. Tests** (backend/tests/test_usage.py:666-1058)
Added 17 new tests for breakdown endpoint covering pagination, sorting, filtering, error handling, and authentication.
### Verification
- All 414 backend tests pass
- All 35 usage endpoint tests pass
- Branch merged to main and pushed to remote