Skip to content

fix(admin/analytics): coerce Neon int8 strings to Number() in overvie…#2412

Merged
andrew-bierman merged 1 commit into
mainfrom
fix/neon-int8-string-coercion
May 13, 2026
Merged

fix(admin/analytics): coerce Neon int8 strings to Number() in overvie…#2412
andrew-bierman merged 1 commit into
mainfrom
fix/neon-int8-string-coercion

Conversation

@andrew-bierman
Copy link
Copy Markdown
Collaborator

@andrew-bierman andrew-bierman commented May 13, 2026

…w + ETL summary

Neon returns PostgreSQL BIGINT (int8) as JavaScript strings to avoid precision loss. raw sql is a TS-only hint — COUNT/SUM results from raw SQL come back as strings at runtime. Drizzle's count() adds ::int cast internally, but sqlcount(...) and sqlsum(...) do not.

TypeBox t.Number() rejects string values so response validation failed. Coerce totalBrands, withEmbedding, completed, failed, totalItemsIngested.

Description

Closes #

Type of change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor / code improvement
  • 📝 Documentation update
  • 🔧 CI / configuration change
  • ⬆️ Dependency update
  • 🗄️ Database migration

Area(s) affected

  • Mobile app (apps/expo)
  • API / Backend (packages/api)
  • Landing page (apps/landing)
  • Guides site (apps/guides)
  • CI / CD (.github/)

Testing

  • Added / updated unit tests
  • Manually tested on iOS
  • Manually tested on Android
  • Manually tested on Web
  • API endpoints verified (e.g. curl or Postman)

Screenshots / recordings

Pre-merge checklist

  • bun format && bun lint passes with no errors
  • bun check-types passes with no errors
  • No new secrets or credentials are committed
  • Database migration included (if schema changed)
  • Feature flag added (if this is a new feature)
  • PR title follows conventional commits (feat:, fix:, chore:, etc.)

…w + ETL summary

Neon returns PostgreSQL BIGINT (int8) as JavaScript strings to avoid
precision loss. raw sql<number> is a TS-only hint — COUNT/SUM results
from raw SQL come back as strings at runtime. Drizzle's count() adds
::int cast internally, but sql`count(...)` and sql`sum(...)` do not.

TypeBox t.Number() rejects string values so response validation failed.
Coerce totalBrands, withEmbedding, completed, failed, totalItemsIngested.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Warning

Rate limit exceeded

@andrew-bierman has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 34 seconds before requesting another review.

You’ve run out of usage credits. Purchase more 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5faac43a-e4be-42ef-aae6-ce53732bb5d5

📥 Commits

Reviewing files that changed from the base of the PR and between e1ac84f and 460d151.

📒 Files selected for processing (1)
  • packages/api/src/routes/admin/analytics/catalog.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/neon-int8-string-coercion

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@andrew-bierman andrew-bierman marked this pull request as ready for review May 13, 2026 05:34
Copilot AI review requested due to automatic review settings May 13, 2026 05:34
@github-actions github-actions Bot added the api label May 13, 2026
@andrew-bierman andrew-bierman merged commit 38bb663 into main May 13, 2026
8 of 9 checks passed
@andrew-bierman andrew-bierman deleted the fix/neon-int8-string-coercion branch May 13, 2026 05:34
@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for Expo Unit Tests Coverage (./apps/expo)

Status Category Percentage Covered / Total
🔵 Lines 82.61% 480 / 581
🔵 Statements 82.61% (🎯 75%) 480 / 581
🔵 Functions 92.59% 50 / 54
🔵 Branches 90.9% 170 / 187
File CoverageNo changed files found.
Generated in workflow #1174 for commit 460d151 by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for API Unit Tests Coverage (./packages/api)

Status Category Percentage Covered / Total
🔵 Lines 76.17% 502 / 659
🔵 Statements 76.17% (🎯 65%) 502 / 659
🔵 Functions 95% 38 / 40
🔵 Branches 88.67% 227 / 256
File CoverageNo changed files found.
Generated in workflow #1174 for commit 460d151 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes admin analytics response validation failures caused by Neon returning PostgreSQL BIGINT (int8) aggregate results as strings at runtime (despite sql<number> being a TS-only hint). The change ensures the /admin/analytics/catalog endpoints return actual number values that satisfy the TypeBox response schemas.

Changes:

  • Coerce totalBrands in /catalog/overview to Number(...).
  • Coerce withEmbedding (and use the coerced value in coverage percentage math) in /catalog/overview.
  • Coerce ETL summary aggregates (completed, failed, totalItemsIngested) to Number(...) in /catalog/etl.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants