Skip to content

[codex] Backfill admin revenue dashboard metrics#2039

Merged
riderx merged 5 commits into
mainfrom
codex/backfill-admin-revenue-dashboard
May 7, 2026
Merged

[codex] Backfill admin revenue dashboard metrics#2039
riderx merged 5 commits into
mainfrom
codex/backfill-admin-revenue-dashboard

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 6, 2026

Summary (AI generated)

  • Added a named Stripe backfill script for admin revenue dashboard metrics.
  • Extended the existing revenue trend backfill to recompute total paying organizations and upgraded orgs from Stripe subscription history.
  • Added unit coverage for paying organization counts and monthly-to-yearly upgrade detection.

Motivation (AI generated)

The admin revenue dashboard had false data for subscription type, subscription flow, MRR, ARR, ARR by plan, churn revenue, total paying organizations, and upgraded organizations. The backfill needs to derive these values from Stripe subscription state instead of keeping incomplete dashboard rows.

Business Impact (AI generated)

This improves revenue reporting accuracy for internal business decisions, especially subscription mix, ARR by plan, churn impact, and upgrade trends.

Test Plan (AI generated)

  • bunx eslint --no-ignore scripts/backfill_revenue_trend_metrics.ts scripts/backfill_admin_revenue_dashboard_metrics.ts tests/backfill-revenue-trend-metrics.unit.test.ts
  • bunx vitest run tests/backfill-revenue-trend-metrics.unit.test.ts
  • Commit hook ran bun run cli:build and vue-tsc --noEmit

Generated with AI

Summary by CodeRabbit

  • New Features

    • Added admin revenue dashboard backfill capability for comprehensive revenue metrics tracking.
    • Extended revenue metrics to track paying customer counts and subscription upgrade information.
  • Tests

    • Updated unit tests to validate new paying customer and subscription upgrade metrics collection.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 53 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d2ab443-1d4c-4019-8c7c-9bb3ba080063

📥 Commits

Reviewing files that changed from the base of the PR and between 9c0237f and 61d6b4e.

📒 Files selected for processing (3)
  • package.json
  • scripts/backfill_revenue_trend_metrics.ts
  • tests/backfill-revenue-trend-metrics.unit.test.ts
📝 Walkthrough

Walkthrough

This PR extends the revenue backfill metrics to track paying customer counts and organization upgrades, introduces a new admin dashboard backfill script that reuses the enhanced core logic, and updates tests to verify the new metrics.

Changes

Revenue Metrics Backfill Enhancement

Layer / File(s) Summary
Type Shape
scripts/backfill_revenue_trend_metrics.ts
RevenueTrendMetricValues and GlobalStatsRow types gain paying and upgraded_orgs fields to track paying customer counts and upgrade events.
Upgrade Detection & Tracking
scripts/backfill_revenue_trend_metrics.ts
Daily counters add upgradedCustomerIds set; logic detects subscription plan transitions and records them as upgrades in aggregation.
Metric Computation
scripts/backfill_revenue_trend_metrics.ts
Paying customers are accumulated across subscription states; final revenue snapshot includes computed paying and upgraded_orgs values.
Data I/O
scripts/backfill_revenue_trend_metrics.ts
Database fetch now selects paying and upgraded_orgs; update path propagates both fields to global_stats table.
Admin Dashboard Script
package.json, scripts/backfill_admin_revenue_dashboard_metrics.ts
New npm script stripe:backfill-admin-revenue-dashboard added; script file imports and executes shared backfill logic via top-level await.
Tests & Verification
tests/backfill-revenue-trend-metrics.unit.test.ts
Unit tests updated to mock new fields in globalStatsRow and assert paying and upgraded_orgs in multiple test scenarios, including upgrade-detection case.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Cap-go/capgo#2010: Directly related — modifies the same revenue backfill scripts, types, and test files to track new metrics in the admin dashboard tooling.

Poem

🐰 Upgrades hop from month to year,
Paying counts now crystal clear,
Dashboard metrics grow so bright,
Revenue trends in perfect light!
Scripts backfill the truth we seek, 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a backfill script for admin revenue dashboard metrics.
Description check ✅ Passed The description includes a comprehensive summary, motivation, business impact, and detailed test plan execution with specific commands run and results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/backfill-admin-revenue-dashboard

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented May 6, 2026

Merging this PR will not alter performance

✅ 28 untouched benchmarks


Comparing codex/backfill-admin-revenue-dashboard (61d6b4e) with main (6a0eefa)

Open in CodSpeed

@riderx riderx marked this pull request as ready for review May 6, 2026 11:33
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/backfill-revenue-trend-metrics.unit.test.ts (1)

319-338: ⚡ Quick win

Tighten the yearly-upgrade assertion.

This only proves upgraded_orgs was incremented. A regression that leaves the monthly state active, or keeps the monthly MRR, would still pass. Please also assert the post-upgrade snapshot (mrr: 10, paying_monthly: 0, and the yearly plan counters) so this test locks down the migration behavior more fully.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/backfill-revenue-trend-metrics.unit.test.ts` around lines 319 - 338,
The test currently only asserts upgraded_orgs; update the assertions after
building rows (using buildRevenueTrendBackfillRows and the subscriptionEvent for
'evt_yearly_upgrade') to also verify the post-upgrade snapshot: assert rows[0]
has mrr: 10, paying_monthly: 0, paying_yearly: 1 (or the expected yearly plan
counters), and any other plan-specific yearly counters you rely on; this ensures
the monthly state and MRR were correctly replaced by the yearly subscription
rather than just incrementing upgraded_orgs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/backfill-revenue-trend-metrics.unit.test.ts`:
- Around line 319-338: The test currently only asserts upgraded_orgs; update the
assertions after building rows (using buildRevenueTrendBackfillRows and the
subscriptionEvent for 'evt_yearly_upgrade') to also verify the post-upgrade
snapshot: assert rows[0] has mrr: 10, paying_monthly: 0, paying_yearly: 1 (or
the expected yearly plan counters), and any other plan-specific yearly counters
you rely on; this ensures the monthly state and MRR were correctly replaced by
the yearly subscription rather than just incrementing upgraded_orgs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 13dadc72-bb00-491e-83d1-5ddeeda52d09

📥 Commits

Reviewing files that changed from the base of the PR and between 5b76c59 and 9c0237f.

📒 Files selected for processing (4)
  • package.json
  • scripts/backfill_admin_revenue_dashboard_metrics.ts
  • scripts/backfill_revenue_trend_metrics.ts
  • tests/backfill-revenue-trend-metrics.unit.test.ts

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fcb8d01dfe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/backfill_revenue_trend_metrics.ts
Comment thread scripts/backfill_revenue_trend_metrics.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review


P2 Badge Count cadence upgrades before early-returning new activations

When a customer.subscription.updated event both activates a subscription and changes cadence from monthly to yearly (for example, previous status incomplete with a monthly item, then active yearly), this branch returns before upgrade detection runs, so upgraded_orgs is not incremented. That diverges from the webhook path (shouldTrackOrganizationUpgrade) which records cadence upgrades regardless of whether this is the first paid activation, causing backfill to undercount upgrades for these mixed activation+upgrade events.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

@riderx riderx merged commit db92c9c into main May 7, 2026
50 checks passed
@riderx riderx deleted the codex/backfill-admin-revenue-dashboard branch May 7, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant