Skip to content

feat(data-api): migrate account_position_daily to Postgres#4839

Merged
JSONbored merged 1 commit into
mainfrom
feat/account-position-daily-postgres
Jul 11, 2026
Merged

feat(data-api): migrate account_position_daily to Postgres#4839
JSONbored merged 1 commit into
mainfrom
feat/account-position-daily-postgres

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

Test plan

  • npx vitest run tests/data-api.test.mjs tests/request-handlers-entities.test.mjs — 189 + 490 tests pass (new write-path tests confirm the INSERT + null-hotkey skip; new read-route tests cover the happy path + ?window=all; new wiring tests confirm postgres-wins/falls-back-to-D1)
  • npx vitest run (full repo) — 259 files / 7374 tests pass
  • npm run lint / npx prettier --check on touched files — clean
  • npm run test:coverage + manual branch-coverage isolation on the diff — every uncovered branch confirmed pre-existing/outside the patch

Deploy note

This PR does NOT yet apply deploy/postgres/schema.sql to the live box — that happens as a separate manual step after merge (idempotent CREATE TABLE IF NOT EXISTS, applied via psql), followed by redeploying metagraphed-data-api.

Refs #4832

Gap-closure from the #4832 completeness sweep: account_position_daily
was D1-only because its Postgres table didn't exist yet. Its source
data (the `neurons` snapshot) is already synced into Postgres via
handleNeuronsSync (#4771), so this rolls it into the SAME write
transaction rather than standing up new infrastructure — no new
external trigger needed.

- Add the table + indexes to deploy/postgres/schema.sql (mirrors D1
  migrations/0038_account_position_daily.sql).
- Extend handleNeuronsSync to upsert account_position_daily rows
  (hotkey IS NOT NULL, same filter as the D1 rollup) in the same
  sql.begin() transaction as neurons/neuron_daily.
- Add the read route (GET /api/v1/accounts/:ss58/subnets/:netuid/history)
  and wire tryPostgresTier into handleAccountPositionHistory.

Refs #4832
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
metagraphed-data-api a493ae3 Commit Preview URL

Branch Preview URL
Jul 11 2026, 04:33 AM

@superagent-security

Copy link
Copy Markdown

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.77%. Comparing base (e3246cf) to head (a493ae3).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4839   +/-   ##
=======================================
  Coverage   97.77%   97.77%           
=======================================
  Files         162      162           
  Lines       19124    19137   +13     
  Branches     7185     7188    +3     
=======================================
+ Hits        18699    18712   +13     
  Misses         59       59           
  Partials      366      366           
Files with missing lines Coverage Δ
workers/data-api.mjs 99.57% <100.00%> (+<0.01%) ⬆️
workers/request-handlers/entities.mjs 99.34% <100.00%> (-0.01%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored JSONbored merged commit 46a0e13 into main Jul 11, 2026
14 checks passed
@JSONbored JSONbored deleted the feat/account-position-daily-postgres branch July 11, 2026 04:37
@github-actions github-actions Bot mentioned this pull request Jul 11, 2026
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