fix(miner): stamp prediction-ledger schema version and add tenant_id column#6702
Conversation
…column prediction-ledger.js was the one canonical local store that never called applySchemaMigrations, so it carried no PRAGMA user_version stamp and lacked the additive nullable tenant_id column its four sibling ledgers already have (JSONbored#4939). Add an addTenantIdColumn migration (guarded by a PRAGMA table_info column-presence check, idempotent like its siblings) and run it via applySchemaMigrations right after the bootstrap schema, matching event-ledger.js/run-state.js. A fresh store now stamps user_version 2 and an existing file upgrades in place; tenant_id is NULL for every row and no consumer reads or writes it, so self-host behavior is byte-identical. Closes JSONbored#6596
|
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 #6702 +/- ##
=======================================
Coverage 93.65% 93.65%
=======================================
Files 682 682
Lines 68112 68117 +5
Branches 18708 18708
=======================================
+ Hits 63788 63793 +5
Misses 3347 3347
Partials 977 977
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-16 19:59:50 UTC
Review summary Nits — 2 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
Summary
packages/loopover-miner/lib/prediction-ledger.jswas the one canonical local store that never calledapplySchemaMigrations(#4832): it carried noPRAGMA user_versionstamp, and itspredictionstable lacked the additive, nullabletenant_id TEXTcolumn its four sibling ledgers already received (#4939).migrate-cli.js's doc claim that "every store already applies its own pending migrations as a side effect of being opened" was therefore false for this one file.Change
initPredictionLedgernow callsapplySchemaMigrations(db, [addTenantIdColumn])immediately after the bootstrap schema, matching the call-site position inevent-ledger.js/run-state.js.addTenantIdColumnaddstenant_id TEXTguarded by aPRAGMA table_info(predictions)column-presence check, idempotent against an already-migrated file -- mirroringevent-ledger.js's andrun-state.js's ownaddTenantIdColumnexactly.tenant_id:appendPredictionstill inserts without it androwToEntrystill ignores it, so every existing and new row hastenant_id = NULLand self-host behavior is byte-identical (Add tenant-scoping columns to all local ledger schemas #4939's stated contract for the other four stores).A fresh store now stamps
user_version = 2(baseline 1 + the one migration); a pre-existing file upgrades in place with every row preserved.Tests (
test/unit/miner-prediction-ledger.test.ts)readSchemaVersion2 and has thetenant_idcolumn.user_version0, one existing row) upgrades in place: the column is added, the old row survives, andtenant_idreads backnullfor both the old and a newly-appended row.Reproduce-first verified: with only the tests applied, all three fail (
user_version0, not 2); with the fix, they pass.Validation
npm run typecheck-- 0 errors.npx vitest run test/unit/miner-prediction-ledger.test.ts-- 11/11 pass.miner-migrate-cli,miner-status,miner-schema-version,miner-store-maintenance-- 80/80.npm run build:miner-- passes (node --check).codecov/patchgate.git diff --checkclean; rebased on latestmain.Closes #6596