Skip to content

feat(admin): track 12-month plan upgrade rate#2717

Open
riderx wants to merge 6 commits into
mainfrom
feat/admin-upgrade-rate-12m
Open

feat(admin): track 12-month plan upgrade rate#2717
riderx wants to merge 6 commits into
mainfrom
feat/admin-upgrade-rate-12m

Conversation

@riderx

@riderx riderx commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary (AI generated)

  • Add global_stats.upgrade_rate_12m (single new column) for the share of orgs whose last stripe_info.upgraded_at falls in the trailing 12 months
  • Compute the metric daily in the logsnag_insights revenue shard
  • Surface it on the admin revenue dashboard (latest card + trend chart)
  • Add bun run stripe:backfill-upgrade-rate-12m to backfill historical rows

Motivation (AI generated)

Admin was missing a clear view of how many organizations upgraded their plan over the last 12 months. Daily snapshots plus a backfill script cover both forward and past data without changing other schema surfaces.

Business Impact (AI generated)

Gives Capgo clearer retention/expansion visibility: how much of the org base actively upgraded in the last year, which helps pricing and success decisions.

Test Plan (AI generated)

  • Migration applied locally (upgrade_rate_12m only on global_stats)
  • Local backfill ran with --apply --all and wrote non-zero rates
  • Unit tests for backfill helpers (tests/backfill-upgrade-rate-12m.unit.test.ts)
  • CI green
  • Verify admin revenue page shows the new card/chart after deploy
  • Run production backfill after merge: bun run stripe:backfill-upgrade-rate-12m --apply --all (against prod env)

Generated with AI

Made with Cursor

Review in cubic

Summary by CodeRabbit

  • New Features
    • Added a 12-month upgrade rate metric to global statistics and the admin dashboard (latest value + trend chart).
  • Data & Maintenance
    • Extended stored global stats with upgrade_rate_12m (defaults to 0).
    • Added a maintenance/backfill command to recompute historical values.
  • Localization / UI
    • Added localized label/description for the new metric.
    • Updated password verification hint text for clarity.
  • Tests
    • Added unit tests for rate calculation, rounding, leap-year window handling, and backfill row generation.

Add upgrade_rate_12m so admin revenue can show what share of orgs upgraded in the trailing year, with daily collection and a backfill script for history.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 97d7fbba-0e65-4536-b6ec-f8ad2986abd7

📥 Commits

Reviewing files that changed from the base of the PR and between 25e3c55 and b395ec6.

📒 Files selected for processing (1)
  • tests/logsnag-insights-revenue.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

📝 Walkthrough

Walkthrough

Adds a trailing 12-month upgrade-rate metric to global statistics, snapshot generation, backfill tooling, admin trend data, and the revenue dashboard. It also adds localization and tests, and renames an authentication hint translation key.

Changes

12-month upgrade rate

Layer / File(s) Summary
Metric storage and snapshot generation
supabase/migrations/..., */supabase.types.ts, supabase/functions/_backend/triggers/logsnag_insights.ts
Adds the global_stats.upgrade_rate_12m column and types, computes the rate during revenue shard processing, and persists it in snapshots.
Backfill computation and CLI
scripts/backfill_upgrade_rate_12m.ts, package.json, tests/backfill-upgrade-rate-12m.unit.test.ts
Adds paginated source loading, trailing-window calculations, dry-run/apply CLI behavior, concurrent updates, and helper tests.
Trend delivery and dashboard display
supabase/functions/_backend/utils/pg.ts, src/pages/admin/dashboard/revenue.vue, messages/en.json
Includes the metric in admin trend results and displays its latest value and historical percentage chart with localized text.

Authentication hint translation

Layer / File(s) Summary
Authentication hint key update
messages/en.json, src/pages/settings/account/ChangePassword.vue
Renames the password verification translation key, updates its capitalization, and changes the account page reference.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested labels: codex

Suggested reviewers: dalanir, wcaleniewolny

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: tracking the new 12-month plan upgrade rate.
Description check ✅ Passed The description covers the required summary, test plan, and checklist, and is sufficiently detailed for review.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@codspeed-hq

codspeed-hq Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing feat/admin-upgrade-rate-12m (b395ec6) with main (0edae7f)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Remove duplicate Insert field that broke CLI and frontend typecheck.

Co-authored-by: Cursor <cursoragent@cursor.com>
@riderx
riderx marked this pull request as ready for review July 21, 2026 11:39
@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_a25a7e26-0ff9-4ff7-a2bd-71dce2f3b72e)

@cursor
cursor Bot requested review from Dalanir and WcaleNieWolny July 21, 2026 11:40

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Risk: medium. Not approving: Cursor Bugbot completed as skipped (usage limit reached), so automated review did not run. Human review is needed before merge; assigned Dalanir and WcaleNieWolny.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Risk: medium. Cursor Bugbot did not complete (check skipped; usage limit reached), so automated review is unavailable. Human review is needed for this migration, billing metric, and admin dashboard change.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@coderabbitai coderabbitai Bot added the codex label Jul 21, 2026
Rename the verify-access hint key so PR analysis does not flag a hard-coded credential false positive when en.json changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_0fc257d3-1200-424f-b590-d1499712b5d5)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Risk: medium. Not approving: Cursor Bugbot completed as skipped (usage limit reached), so automated review did not run. Human review is still needed; Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed

Confidence score: 5/5

  • Safe to merge after the addressed issues were fixed.

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread scripts/backfill_upgrade_rate_12m.ts
Comment thread scripts/backfill_upgrade_rate_12m.ts Outdated
Comment thread scripts/backfill_upgrade_rate_12m.ts
Comment thread supabase/migrations/20260721110632_admin_upgrade_rate_12m.sql
Comment thread supabase/functions/_backend/triggers/logsnag_insights.ts Outdated
Comment thread scripts/backfill_upgrade_rate_12m.ts
Comment thread supabase/functions/_backend/triggers/logsnag_insights.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Risk: medium. Cursor Bugbot did not complete (check skipped; usage limit reached), so automated review is unavailable. Human review is still needed for this migration and billing metric change; Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

Rethrow shard SQL failures, use calendar-year windows, stabilize pagination ordering, and validate backfill date args.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_3086c008-2641-4fb5-99a6-91d629bcd377)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Risk: medium. Not approving: Cursor Bugbot completed as skipped (usage limit reached), so automated review did not run. Human review is still needed; Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Risk: medium. Not approving: Cursor Bugbot completed as skipped (usage limit reached), so automated review did not run. Human review is still needed for this migration and billing metric change; Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@supabase/migrations/20260721110632_admin_upgrade_rate_12m.sql`:
- Line 5: Wrap the PostgreSQL column comment string in the migration’s IS clause
using adjacent string literals so no line exceeds SQLFluff’s length limit.
Preserve the exact stored comment text and meaning while only changing its
formatting.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9819090d-0ae9-491d-9db1-25301b9a52b5

📥 Commits

Reviewing files that changed from the base of the PR and between 8910a3b and ce152dc.

📒 Files selected for processing (3)
  • scripts/backfill_upgrade_rate_12m.ts
  • supabase/functions/_backend/triggers/logsnag_insights.ts
  • supabase/migrations/20260721110632_admin_upgrade_rate_12m.sql
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread supabase/migrations/20260721110632_admin_upgrade_rate_12m.sql Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread scripts/backfill_upgrade_rate_12m.ts
Comment thread scripts/backfill_upgrade_rate_12m.ts Outdated
Wrap the migration comment for SQLFluff, keyset-paginate the backfill sources, and clamp leap-year trailing windows.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_d41283e5-1acf-4bcb-b235-8f17f0f9d68c)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Risk: medium. Not approving: Cursor Bugbot completed as skipped (usage limit reached), so automated review did not run, and this migration plus billing metric change exceeds the low-risk approval threshold. Human review is still needed; Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: medium. Not approving: Cursor Bugbot completed as skipped (usage limit reached), so automated review did not run. Human review is still needed for this migration and billing metric change; Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread supabase/functions/_backend/triggers/logsnag_insights.ts
Keep the daily shard window helper aligned with the backfill leap-day behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
@riderx
riderx deployed to deepsec-pr July 21, 2026 12:50 — with GitHub Actions Active
@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_0f887bb4-6ebf-44d8-a8a4-89b7e88b472d)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: medium. Not approving: Cursor Bugbot completed as skipped (usage limit reached), so automated review did not run, and this migration plus billing metric change exceeds the low-risk approval threshold. Human review is still needed; Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: medium. Not approving: Cursor Bugbot completed as skipped (usage limit reached), so automated review did not run. Human review is still needed for this migration and billing metric change; Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@sonarqubecloud

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 5 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/backfill_upgrade_rate_12m.ts">

<violation number="1" location="scripts/backfill_upgrade_rate_12m.ts:207">
P3: An interruption after scanning millions of rows still forces both source scans to restart because these cursors exist only in memory. Persisting checkpoints plus fetched/processed batches, or moving the bounded computation into the database, would make the backfill actually resumable.</violation>

<violation number="2" location="scripts/backfill_upgrade_rate_12m.ts:213">
P2: A live production scan can omit orgs inserted during pagination because random UUIDs may sort below `lastId` after that cursor has passed. A repeatable-read database snapshot would keep the org and `stripe_info` inputs internally consistent.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

let query = supabase
.from('orgs')
.select('id, created_at, customer_id')
.order('id', { ascending: true })

@cubic-dev-ai cubic-dev-ai Bot Jul 21, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: A live production scan can omit orgs inserted during pagination because random UUIDs may sort below lastId after that cursor has passed. A repeatable-read database snapshot would keep the org and stripe_info inputs internally consistent.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/backfill_upgrade_rate_12m.ts, line 213:

<comment>A live production scan can omit orgs inserted during pagination because random UUIDs may sort below `lastId` after that cursor has passed. A repeatable-read database snapshot would keep the org and `stripe_info` inputs internally consistent.</comment>

<file context>
@@ -188,17 +204,19 @@ async function fetchGlobalStatsRows(supabase: SupabaseClient, fromDateId: string
       .select('id, created_at, customer_id')
-      .order('created_at', { ascending: true })
-      .range(offset, offset + DEFAULT_PAGE_SIZE - 1)
+      .order('id', { ascending: true })
+      .limit(DEFAULT_PAGE_SIZE)
 
</file context>
Fix with cubic

@@ -0,0 +1,343 @@
/*

@cubic-dev-ai cubic-dev-ai Bot Jul 21, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: An interruption after scanning millions of rows still forces both source scans to restart because these cursors exist only in memory. Persisting checkpoints plus fetched/processed batches, or moving the bounded computation into the database, would make the backfill actually resumable.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/backfill_upgrade_rate_12m.ts, line 207:

<comment>An interruption after scanning millions of rows still forces both source scans to restart because these cursors exist only in memory. Persisting checkpoints plus fetched/processed batches, or moving the bounded computation into the database, would make the backfill actually resumable.</comment>

<file context>
@@ -188,17 +204,19 @@ async function fetchGlobalStatsRows(supabase: SupabaseClient, fromDateId: string
 async function fetchOrgRows(supabase: SupabaseClient, toDateId: string | null) {
   const rows: OrgRow[] = []
-  let offset = 0
+  let lastId: string | null = null
 
   while (true) {
</file context>
Fix with cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant