Skip to content

feat(admin): store paid plan conversion total#2112

Merged
riderx merged 1 commit into
mainfrom
codex/admin-paid-plan-conversion-total
May 11, 2026
Merged

feat(admin): store paid plan conversion total#2112
riderx merged 1 commit into
mainfrom
codex/admin-paid-plan-conversion-total

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 10, 2026

Summary (AI generated)

  • Add a stored plan_total_conversion_rate metric to global_stats.
  • Use that metric as the total line in the paid plan conversion chart, alongside Solo, Maker, Team, and Enterprise lines.
  • Update the historical backfill script and focused unit coverage for the new total.

Motivation (AI generated)

The admin dashboard needs a percentage conversion chart that shows total paid plan conversion and plan-by-plan conversion over time.

Business Impact (AI generated)

This makes it easier to compare which paid plans convert best and whether total paid plan conversion is improving or degrading.

Test Plan (AI generated)

  • bunx eslint --no-ignore src/pages/admin/dashboard/revenue.vue supabase/functions/_backend/triggers/logsnag_insights.ts supabase/functions/_backend/utils/pg.ts scripts/backfill_org_conversion_rate_trend.ts tests/admin-stripe-backfill-scripts.unit.test.ts
  • bun test tests/admin-stripe-backfill-scripts.unit.test.ts
  • bun typecheck
  • bun run build

Summary by CodeRabbit

  • New Features

    • Added overall paid plan conversion rate metric to track aggregate conversion across all paid plans.
    • Updated admin revenue dashboard to display "Paid Plan Conversion Rate" with aggregated conversion data.
  • Tests

    • Enhanced test coverage for overall conversion rate calculations.

Review Change Stack

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented May 10, 2026

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing codex/admin-paid-plan-conversion-total (3c412c7) with main (1ef9d26)

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.

@riderx riderx force-pushed the codex/admin-paid-plan-conversion-total branch from 2849292 to 3c412c7 Compare May 10, 2026 23:56
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4d752f7d-bcb5-4a43-9ea5-c968cbc19831

📥 Commits

Reviewing files that changed from the base of the PR and between 1ef9d26 and 3c412c7.

📒 Files selected for processing (7)
  • scripts/backfill_org_conversion_rate_trend.ts
  • src/pages/admin/dashboard/revenue.vue
  • supabase/functions/_backend/triggers/logsnag_insights.ts
  • supabase/functions/_backend/utils/pg.ts
  • supabase/functions/_backend/utils/supabase.types.ts
  • supabase/migrations/20260510235542_add_plan_total_conversion_rate.sql
  • tests/admin-stripe-backfill-scripts.unit.test.ts

📝 Walkthrough

Walkthrough

This PR adds a new aggregated plan_total_conversion_rate metric to track conversion across all paid plans. The field flows through the database schema, type system, computation in backfill and daily insights operations, persistence to global_stats, retrieval via trend queries, and display in the admin revenue dashboard.

Changes

Plan Total Conversion Rate Pipeline

Layer / File(s) Summary
Database Schema
supabase/migrations/20260510235542_add_plan_total_conversion_rate.sql
New non-null plan_total_conversion_rate column (double precision, default 0) added to public.global_stats with descriptive comment.
Type Definitions
supabase/functions/_backend/utils/supabase.types.ts, scripts/backfill_org_conversion_rate_trend.ts
Supabase types extend global_stats Row/Insert/Update with optional/required plan_total_conversion_rate; backfill script PlanConversionRates and GlobalStatsRow interfaces updated with the field.
Backfill Computation
scripts/backfill_org_conversion_rate_trend.ts
calculatePlanConversionRates sums all plan counts to derive aggregated total; getCurrentPlanConversionRates reads existing total from database; havePlanRatesChanged checks for total rate changes.
Backfill Persistence & Logging
scripts/backfill_org_conversion_rate_trend.ts
fetchGlobalStatsRows selects plan_total_conversion_rate from global_stats; updateConversionRate persists computed next_plan_rates.total to the column; sample output logs total rate progression.
Daily Insights Computation
supabase/functions/_backend/triggers/logsnag_insights.ts
PlanConversionRates interface gains total field; new getPaidPlanTotal helper sums paid-plan org counts; getPlanConversionRates computes total conversion rate alongside per-plan rates.
Daily Insights Persistence
supabase/functions/_backend/triggers/logsnag_insights.ts
Global stats upsert payload includes plan_total_conversion_rate populated from computed planConversionRates.total.
Query Layer
supabase/functions/_backend/utils/pg.ts
AdminGlobalStatsTrend interface gains plan_total_conversion_rate field; getAdminGlobalStatsTrend SQL query computes the metric from global_stats JSON with fallback to 0; result mapping populates field on each trend item.
Dashboard Display
src/pages/admin/dashboard/revenue.vue
globalStatsTrendData type includes plan_total_conversion_rate; planConversionSeries chart reads the metric and displays as "All Paid Plans (%)" series; ChartCard title updated to "Paid Plan Conversion Rate".
Test Fixtures & Assertions
tests/admin-stripe-backfill-scripts.unit.test.ts
Input fixtures provide plan_total_conversion_rate; expected outputs assert current_plan_rates.total and next_plan_rates.total for all test date rows.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Cap-go/capgo#2101: Modifies the same admin/global-stats conversion-rate pipeline; this PR extends that work by adding the aggregated plan_total_conversion_rate metric and wiring it through the backfill script, trigger, query layer, and dashboard.
  • Cap-go/capgo#2094: Extends the same global_stats pipeline with new metrics, migrations, type definitions, backfill scripts, and trigger integrations.
  • Cap-go/capgo#2002: Touches the same backfill workflow, database types, and global_stats field extensions in closely related files.

Poem

🐰 A total to crown the converted,
Paid plans aggregated and asserted,
From schema to dashboard so bright,
The pipeline flows left to right!

🚥 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 clearly and concisely summarizes the main change: adding a stored paid plan conversion total metric to the admin system.
Description check ✅ Passed The description includes summary, motivation, business impact, and a comprehensive test plan with specific commands executed. It aligns well with the template's key sections.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/admin-paid-plan-conversion-total

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 SQLFluff (4.1.0)
supabase/migrations/20260510235542_add_plan_total_conversion_rate.sql

User Error: No dialect was specified. You must configure a dialect or specify one on the command line using --dialect after the command. Available dialects:
ansi, athena, bigquery, clickhouse, databricks, db2, doris, duckdb, exasol, flink, greenplum, hive, impala, mariadb, materialize, mysql, oracle, postgres, redshift, snowflake, soql, sparksql, sqlite, starrocks, teradata, trino, tsql, vertica


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

@sonarqubecloud
Copy link
Copy Markdown

@riderx riderx merged commit 531272e into main May 11, 2026
40 checks passed
@riderx riderx deleted the codex/admin-paid-plan-conversion-total branch May 11, 2026 00:05
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