Skip to content

fix(admin): restore global stats trend chart#2217

Merged
riderx merged 2 commits into
mainfrom
codex/fix-admin-global-stats-trend
May 11, 2026
Merged

fix(admin): restore global stats trend chart#2217
riderx merged 2 commits into
mainfrom
codex/fix-admin-global-stats-trend

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 11, 2026

Summary (AI generated)

  • Qualify all current-row global_stats metric columns as gs.* in the admin trend self-join.
  • Add an admin stats endpoint test that seeds two global_stats rows and verifies /private/admin_stats returns the trend payload with previous-day MRR.
  • Set the main test job to Node 24 so Wrangler 4.90 can start Cloudflare Workers during CI.

Motivation (AI generated)

The admin dashboard calls /private/admin_stats with metric_category: global_stats_trend. That query self-joins global_stats for previous-day values, but selected columns like apps::int were unqualified. PostgreSQL reports those columns as ambiguous, the helper catches the error, and the API returns success: true with an empty data array. The Cloudflare worker test lane also needs Node 24 because the currently locked Wrangler requires Node.js 22 or newer.

Business Impact (AI generated)

This restores the production admin dashboard charts backed by global_stats_trend, so platform operators can see usage, revenue, conversion, and build metrics again instead of an empty chart. Keeping the Cloudflare CI lane runnable also preserves coverage for the worker path used in production.

Test Plan (AI generated)

  • bun lint:backend
  • bunx eslint tests/admin-stats.test.ts
  • bun typecheck
  • bun run supabase:with-env -- bunx vitest run tests/admin-stats.unit.test.ts tests/admin-stats.test.ts
  • bun run supabase:with-env -- bun test:all
  • bun run supabase:with-env -- bun test:cloudflare:backend
  • git diff --check
  • Verified the old production SQL shape fails with column reference "apps" is ambiguous
  • Verified the patched SQL shape returns 28 prod rows for 2026-04-11 through 2026-05-10
  • GitHub Actions checks (queued on GitHub)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

📝 Walkthrough

Walkthrough

The PR refactors the getAdminGlobalStatsTrend SQL query to use explicit table qualification and COALESCE defaults for numeric field projections. Test infrastructure is extended to seed two fixed global_stats records and validate that the /private/admin_stats endpoint correctly returns trend rows with expected metric values. Node.js 24 is added to the CI test environment.

Changes

Global Stats Trend SQL and Test Coverage

Layer / File(s) Summary
SQL Query Refactoring
supabase/functions/_backend/utils/pg.ts
The stats CTE SELECT list in getAdminGlobalStatsTrend now explicitly qualifies all fields with gs.<field>, adds explicit numeric type casts (::int, ::float), and replaces unqualified column references with COALESCE(gs.<field>, 0) defaults for revenue, credits, and build-related metrics.
Test Data Setup and Cleanup
tests/admin-stats.test.ts
New GLOBAL_STATS_TREND_DATES constant defines two fixed ISO date-ids. beforeAll upserts two global_stats rows for those dates with comprehensive metrics (apps, users, updates, success_rate, revenue fields, previous_mrr). afterAll cleanup deletes those seeded rows.
Test Assertion for Trend Endpoint
tests/admin-stats.test.ts
New concurrent test verifies /private/admin_stats with metric_category: 'global_stats_trend' returns exactly two rows; asserts the latest row matches seeded values for apps, updates, updates_external, and previous_mrr.
CI Node.js Configuration
.github/workflows/tests.yml
Adds "Setup Node.js" step using actions/setup-node@v6 with node-version: 24 in the test_all job after checkout.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Cap-go/capgo#2094: Both PRs modify getAdminGlobalStatsTrend in supabase/functions/_backend/utils/pg.ts; main PR tightens column qualification while the related PR adds new paid-activity columns.
  • Cap-go/capgo#2101: Both PRs modify the same backend global stats trend logic and admin-stats tests.
  • Cap-go/capgo#2117: Both PRs refactor the getAdminGlobalStatsTrend SQL in supabase/functions/_backend/utils/pg.ts (main PR refactors qualification/COALESCE; related PR tightens date filtering).

Suggested reviewers

  • jihadMo

Poem

🐰 A query refined with care and cast,
Column qualifications holding fast,
Test seeds planted, assertions bloom,
Global stats trend lights the room!
hops through Node.js version 24

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main fix: restoring the global stats trend chart by addressing ambiguous column references in the admin query.
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.
Description check ✅ Passed The pull request description is comprehensive, including a clear summary, detailed motivation, business impact, and a thorough test plan with specific commands executed.

✏️ 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/fix-admin-global-stats-trend

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 11, 2026

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing codex/fix-admin-global-stats-trend (d3af1f0) with main (ee54a9c)

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 marked this pull request as ready for review May 11, 2026 16:24
@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.

@sonarqubecloud
Copy link
Copy Markdown

@riderx riderx merged commit 0d6eabd into main May 11, 2026
46 checks passed
@riderx riderx deleted the codex/fix-admin-global-stats-trend branch May 11, 2026 17:42
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