[codex] Fix Stripe admin revenue backfill#2254
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Merging this PR will not alter performance
Comparing Footnotes
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughTwo separate Stripe backfill scripts are consolidated into a single unified script that rebuilds admin revenue dashboard metrics from Stripe subscription and invoice data. Both npm scripts now invoke the consolidated implementation, and test coverage is updated accordingly. ChangesStripe Revenue Backfill Consolidation
Sequence DiagramsequenceDiagram
participant Main as Script Entrypoint
participant Stripe as Stripe API
participant Supabase as Supabase (plans, global_stats)
participant Compute as Metrics Computation
Main->>Supabase: Fetch plan definitions
Main->>Supabase: Fetch existing global_stats rows (2022-01-01 → today)
Main->>Stripe: Fetch active & inactive Stripe prices
Main->>Compute: Build price lookup (interval, plan, MRR)
rect rgba(100, 150, 200, 0.5)
note over Stripe,Compute: Retrieve Revenue Intervals
Main->>Stripe: Fetch paid invoices (subscription line items)
Stripe-->>Main: Invoice list
Main->>Stripe: Fetch active/trialing/past_due subscriptions
Stripe-->>Main: Subscription list
Main->>Compute: Parse intervals, dedupe by subscription
Compute-->>Main: Sorted revenue intervals
end
rect rgba(150, 200, 100, 0.5)
note over Compute,Supabase: Daily State & Metrics Loop
Main->>Compute: For each day: extract state as of date
Compute->>Compute: Record transitions (new, churn, upgrades)
Compute->>Compute: Summarize into StripeRevenueMetricValues
Compute->>Compute: Compare vs. existing global_stats row
Compute-->>Main: Backfill row (changed, current, date_id, exists)
end
Main->>Supabase: Write only changed rows (update or insert) with bounded concurrency
Supabase-->>Main: Rows updated/inserted
Main->>Main: Log progress & sample rows
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|



Summary (AI generated)
Motivation (AI generated)
The old backfill path only handled recent Stripe Events by default, required apply/date/event-file options for older ranges, skipped missing global_stats dates, and only mapped current plan price IDs. That left admin revenue dashboard charts incomplete back to 2022.
Business Impact (AI generated)
This gives Capgo a reliable repair command for revenue dashboards, improving visibility into plan distribution, subscription flow, churn, MRR, and ARR history. Accurate historical revenue reporting makes business analysis and recovery from bad backfills less fragile.
Test Plan (AI generated)
Generated with AI
Summary by CodeRabbit
Refactor
Tests