feat(data-api): add the account_events_daily rollup write path to Postgres#4840
Merged
Conversation
…tgres Gap-closure from the #4832 completeness sweep: account_events_daily's Postgres table already existed (mirroring D1's schema) but nothing wrote to it, since indexer-rs writes account_events directly and continuously (unlike the daily neurons snapshot, there's no existing write request to piggyback a rollup onto). - POST /api/v1/internal/rollup-account-events-daily (data-api.mjs): re-rolls the two active UTC days from account_events into account_events_daily, mirroring D1's rollupAccountEventsDaily exactly. Proxied through the main Worker (api.mjs) the same way neurons-sync is; refactored the neurons-sync proxy into a shared proxyToDataApi helper since the two routes are otherwise identical. - New hourly GitHub Actions workflow (rollup-account-events-daily.yml) triggers it -- matches D1's own hourly cadence. - Adds the read route (GET /api/v1/accounts/:ss58/history) with the same cursor/date-range/netuid filtering as its D1 sibling, and wires tryPostgresTier into handleAccountHistory. Refs #4832
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
metagraphed-data-api | 004e829 | Commit Preview URL Branch Preview URL |
Jul 11 2026, 05:01 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 #4840 +/- ##
=======================================
Coverage 97.77% 97.78%
=======================================
Files 162 162
Lines 19137 19189 +52
Branches 7188 7208 +20
=======================================
+ Hits 18712 18764 +52
Misses 59 59
Partials 366 366
🚀 New features to boost your workflow:
|
validate-workflows.mjs requires every workflow to include actions/checkout -- the new rollup-account-events-daily.yml didn't need the repo checked out for its bare curl trigger, but the gate doesn't special-case that, so add it like every other 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_events_daily's Postgres table already existed (schema mirrors D1) but nothing wrote to it, since indexer-rs writesaccount_eventsdirectly and continuously — unlike the daily neurons snapshot (Build the metagraph/neuron pipeline's missing Postgres write path (neurons + neuron_daily) #4771/feat(data-api): migrate account_position_daily to Postgres #4839), there's no existing write request to piggyback a rollup onto.POST /api/v1/internal/rollup-account-events-daily(workers/data-api.mjs): re-rolls the two active UTC days fromaccount_eventsintoaccount_events_daily, mirroring D1'srollupAccountEventsDaily(src/account-events.mjs) exactly. Proxied through the main Worker the same wayneurons-syncis — refactoredhandleNeuronsSyncProxyinto a sharedproxyToDataApihelper since the two routes are otherwise identical (same behavior preserved; the existingtests/neurons-sync-proxy.test.mjspasses unchanged).rollup-account-events-daily.yml) to trigger it, matching D1's own hourly cadence.GET /api/v1/accounts/:ss58/history(netuid/from/to filters + cursor pagination, same shape as its D1 sibling) and wirestryPostgresTierintohandleAccountHistory.Test plan
npx vitest run tests/data-api.test.mjs tests/request-handlers-entities.test.mjs tests/neurons-sync-proxy.test.mjs tests/rollup-account-events-daily-proxy.test.mjs— 199 + 490 + 5 + 5 tests pass (new write-route tests cover auth/not-provisioned/hyperdrive-unavailable/success/DB-failure; new read-route tests cover the happy path, netuid/date-range filters, cursor seek, and full-page next_cursor emission; new wiring tests confirm postgres-wins/falls-back-to-D1)npx vitest run(full repo) — 260 files / 7391+ tests passnpm run lint/npx prettier --checkon touched files — cleannpm run scan:public-safety— cleannpm run test:coverage+ manual branch-coverage isolation on the diff — every uncovered branch confirmed pre-existing/outside the patchDeploy note
After merge: provision
ROLLUP_SYNC_SECRETviawrangler secret put ROLLUP_SYNC_SECRET -c wrangler.data.jsoncand add the same value as aROLLUP_SYNC_SECRETGitHub Actions secret, then manually trigger the new workflow once to verify live before its first scheduled run.Refs #4832