feat(sqlite_schema_manager): dynamic historical sync ranges for custom event imports - #370
Merged
2 commits merged intoAug 30, 2026
Conversation
|
@solaawojobi00-bit Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…m event imports Add validated start/end ledger range support to the schema manager so operators can import a custom historical window of events without disturbing the live indexer pointer, plus a helper to assert indexed event counts for that range.
Rebasing onto upstream/main pulled in migrations 4-6, exposing two pre-existing bugs in this branch's copy of sqlite-schema-manager.test.ts that predate this PR: an undefined SCHEMA_MANAGER_INDEXES reference (now exported from db.ts) and a stale hardcoded migration-version assertion (now derived from getShippedMigrationVersions()).
solaawojobi00-bit
force-pushed
the
fix/issue-263-sqlite-schema-manager-historical-ranges
branch
from
August 30, 2026 03:09
fb5f3c8 to
7d85833
Compare
9e42e6f
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.
Configure dynamic historical sync ranges in
sqlite_schema_managerProblem
sqlite_schema_manager(src/indexer/db.ts) had no way to accept an arbitrary, caller-supplied start/end ledger range for a one-off historical event import. Any bulk/backfill import had to go through the live insert path (insertEventBatch), which unconditionally advancesindexer_state.last_ledger_sequence— so there was no safe way to import a custom historical window without risking corruption of the live indexer pointer, and no built-in way to verify the imported event counts for that window.insertHistoricalEventBatch()accepts an explicit{ startLedger, endLedger }rangevalidateHistoricalRange()rejects non-integers, values < 1, andstart > endadvanceLivePointer: trueis passed, and never moves backwardsgetHistoricalEventCounts()returns total + per-type counts for a rangeledger_sequencefalls outside the declared range throws before any row is writtenSolution
Added a small, self-contained "dynamic historical sync ranges" section to
sqlite_schema_manager(src/indexer/db.ts) mirroring the range-validation semantics already used elsewhere in the indexer (inclusive[startLedger, endLedger], reject onstart > end), but scoped to custom event imports rather than live RPC polling.Changes
src/indexer/db.tsHistoricalRangeError— dedicated error type for invalid historical ranges.validateHistoricalRange(startLedger, endLedger)— validates an inclusive ledger range (positive integers,start <= end).insertHistoricalEventBatch(events, range, options?)— atomically inserts a batch of events for a custom historical range. Rejects the whole batch up front if any event'sledger_sequenceis outside the declared range. Only advanceslast_ledger_sequencewhenoptions.advanceLivePointeristrue, and never moves it backwards.getHistoricalEventCounts(startLedger, endLedger)— returns{ totalEvents, eventsByType }for a range, so a custom import can be asserted against expected block event counts.__tests__/sqlite-schema-manager.test.tsdescribeblock "SQLite Schema Manager – dynamic historical sync ranges (Configure dynamic historical sync ranges in sqlite_schema_manager #263)" covering range validation, historical import (including live-pointer behavior), idempotency, out-of-range rejection, and event-count assertions.Regression Tests
insertHistoricalEventBatchtests: "imports events within the declared range without advancing the live pointer"validateHistoricalRangedescribe block (valid range, single-ledger range, non-integer/negative start, non-numeric end,start > end)getHistoricalEventCountsdescribe block: "asserts correct block event counts are indexed for a custom range", "throws for an invalid range"Testing
Full suite (
npm test) also run for regression:The 5 pre-existing failures are unrelated to this change and reproduce identically on
mainbefore this branch's commit:__tests__/failover-recovery-backoff-retry.test.tsand__tests__/failover-recovery-poll-diagnostics.test.ts— missingjestimport (ReferenceError: jest is not defined).__tests__/sqlite-schema-manager.test.ts— a pre-existingcreates all schema-manager lookup indexes (#259)test references an undefinedSCHEMA_MANAGER_INDEXES, and a pre-existing#186rollback test asserts a stale migration-version list ([1,2,3]) that predates migrations 4 and 5.None of these are touched by this PR's diff and are out of scope for #263.
Notes for Reviewers
insertEventBatch,getLastIndexedLedger, etc.) were modified, so the live poll path is unaffected.ledger-range-tracker.ts'svalidateLedgerRange/resolveHistoricalLedgerRange—ledger-range-tracker.tsimports fromdb.ts, so importing back would create a circular dependency. The validation logic here is intentionally small and scoped to this module.Closes #263