feat(data-api): migrate account_position_daily to Postgres#4839
Merged
Conversation
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
Deploying with
|
| 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 didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
account_position_dailywas D1-only because its Postgres table didn't exist yet. Its source data (theneuronssnapshot) is already synced into Postgres viahandleNeuronsSync(Build the metagraph/neuron pipeline's missing Postgres write path (neurons + neuron_daily) #4771), so this rolls the account-position rollup into the SAME write transaction rather than standing up new infrastructure.deploy/postgres/schema.sql(mirrors D1migrations/0038_account_position_daily.sql).handleNeuronsSyncto upsertaccount_position_dailyrows (hotkey IS NOT NULL, same filter as the D1 rollup) inside the existingsql.begin()transaction.GET /api/v1/accounts/:ss58/subnets/:netuid/historyand wirestryPostgresTierintohandleAccountPositionHistory.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 passnpm run lint/npx prettier --checkon touched files — cleannpm run test:coverage+ manual branch-coverage isolation on the diff — every uncovered branch confirmed pre-existing/outside the patchDeploy note
This PR does NOT yet apply
deploy/postgres/schema.sqlto the live box — that happens as a separate manual step after merge (idempotentCREATE TABLE IF NOT EXISTS, applied via psql), followed by redeployingmetagraphed-data-api.Refs #4832