Phase 3-A: Add Claude Usage Snapshot DB Model + Migration #46
Labels
No Label
admin
agent-api
api
api-client
audit
backend
boards
cost-accounting
database
design
forgejo
frontend
issues
metrics
mutation
navigation
optional
phase:1
phase:2
phase:3
phase:4
phase:5
phase:6
polish
priority:high
priority:low
priority:medium
service
sync
usage-accuracy
validation
webhooks
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: null/Pipeline#46
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Source plan:
/home/kaspa/.claude/plans/with-our-backend-created-precious-owl.mdFeature context: Feature 3: Daily Cost Snapshot (Historical Trending)
Scope
Phase 3-A — Backend, Batch 1: DB Model + Migration
Summary
Add a
ClaudeUsageSnapshotdatabase model and Alembic migration to persist daily cost and token totals.Problem
Cost data is recalculated fresh from JSONL on every API request. There is no historical record — impossible to chart "how much did I spend this week vs last week."
Affected area
claude_usage_snapshotsAffected files
backend/app/models/claude_usage.py— new file,ClaudeUsageSnapshotSQLModelbackend/alembic/versions/XXXX_add_claude_usage_snapshots.py— new migrationExpected behavior
Table
claude_usage_snapshotswith columns:id(uuid pk)snapshot_date(date, unique per org — one row per day)org_id(fk to organizations)total_cost_usd(float)total_tokens(int)session_count(int)per_model(JSON —{"claude-sonnet-4-6": {"cost": 1.23, "tokens": 45000}, ...})created_at(datetime)Steps to reproduce (acceptance criteria)
alembic upgrade head— no errors3-A: Backend, Batch 1: DB Model + Migrationto Phase 3-A: Add Claude Usage Snapshot DB Model + Migration