You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#4939 ("Add tenant-scoping columns to all local ledger schemas") added an additive, nullable tenant_id TEXT column to every local ledger schema as a prerequisite for any future hosted, multi-tenant use of the same ledger logic. packages/loopover-miner/lib/claim-ledger.js, run-state.js, event-ledger.js, and portfolio-queue.js each gained an addTenantIdColumn migration (guarded by a PRAGMA table_info column-presence check) wired into their applySchemaMigrations call, even though #4939 was closed as complete.
Two more of the package's canonical seven local stores (the list packages/loopover-miner/lib/status.js's storeIntegrityChecks and packages/loopover-miner/lib/migrate-cli.js's STORES both track) never received the column:
packages/loopover-miner/lib/governor-ledger.js's governor_events table — initGovernorLedger already calls applySchemaMigrations(db, []) with an empty migrations array.
packages/loopover-miner/lib/plan-store.js's miner_plans table — its open function already calls applySchemaMigrations(db, []) with an empty migrations array.
(prediction-ledger.js's missing tenant_id column is tracked separately, alongside that file's separate missing schema-version call, in a sibling issue — this issue covers only governor-ledger.js and plan-store.js, which already have a working applySchemaMigrations call site.)
Requirements
packages/loopover-miner/lib/governor-ledger.js's governor_events table MUST gain a nullable tenant_id TEXT column, added via a migration function named addTenantIdColumn passed into the existing applySchemaMigrations(db, [...]) call (replacing the current empty array).
packages/loopover-miner/lib/plan-store.js's miner_plans table MUST gain a nullable tenant_id TEXT column, added via a migration function named addTenantIdColumn passed into its existing applySchemaMigrations(db, [...]) call (replacing the current empty array).
Both addTenantIdColumn functions MUST guard the ALTER TABLE ... ADD COLUMN tenant_id TEXT with a PRAGMA table_info(<table>) column-presence check before altering, mirroring event-ledger.js's and run-state.js's existing addTenantIdColumn implementations exactly (idempotent against a file already migrated).
No consumer reads or writes tenant_id yet in either store — self-host behavior MUST be byte-identical (every existing row and every newly-inserted row has tenant_id = NULL), matching Add tenant-scoping columns to all local ledger schemas #4939's own stated behavior for the other four stores.
Opening a fresh governor-ledger.js store MUST result in PRAGMA user_version = 2 (baseline 1 plus the one new migration); opening a fresh plan-store.js store MUST likewise result in user_version = 2, verifiable via schema-version.js's exported readSchemaVersion.
Opening a pre-existing on-disk file for either store (no tenant_id column, user_version at whatever the current baseline is) MUST upgrade it in place with the column added and every existing row preserved.
Deliverables
packages/loopover-miner/lib/governor-ledger.js calling applySchemaMigrations(db, [addTenantIdColumn]), with addTenantIdColumn defined in that file.
packages/loopover-miner/lib/plan-store.js calling applySchemaMigrations(db, [addTenantIdColumn]), with addTenantIdColumn defined in that file.
A test in test/unit/miner-governor-ledger.test.ts asserting readSchemaVersion reports 2 on a fresh store, plus a pre-migration-file upgrade test (old shape, no tenant_id, opened via initGovernorLedger, column added, rows preserved, tenant_id reads back null).
A test in test/unit/miner-plan-store.test.ts asserting the same two things for plan-store.js.
Test Coverage Requirements
Both packages/loopover-miner/lib/governor-ledger.js and packages/loopover-miner/lib/plan-store.js are under packages/**, covered by this repo's 99%+ Codecov patch gate — every line of both new addTenantIdColumn functions must be exercised, including the column-presence guard's both branches (column absent → added; column already present → left alone).
Expected Outcome
governor-ledger.js and plan-store.js carry the same tenant_id hosted-readiness column the other four canonical local stores already have, closing the drift between what #4939 claimed was done and what the code actually had.
Context
#4939 ("Add tenant-scoping columns to all local ledger schemas") added an additive, nullable
tenant_id TEXTcolumn to every local ledger schema as a prerequisite for any future hosted, multi-tenant use of the same ledger logic.packages/loopover-miner/lib/claim-ledger.js,run-state.js,event-ledger.js, andportfolio-queue.jseach gained anaddTenantIdColumnmigration (guarded by aPRAGMA table_infocolumn-presence check) wired into theirapplySchemaMigrationscall, even though #4939 was closed as complete.Two more of the package's canonical seven local stores (the list
packages/loopover-miner/lib/status.js'sstoreIntegrityChecksandpackages/loopover-miner/lib/migrate-cli.js'sSTORESboth track) never received the column:packages/loopover-miner/lib/governor-ledger.js'sgovernor_eventstable —initGovernorLedgeralready callsapplySchemaMigrations(db, [])with an empty migrations array.packages/loopover-miner/lib/plan-store.js'sminer_planstable — its open function already callsapplySchemaMigrations(db, [])with an empty migrations array.(
prediction-ledger.js's missingtenant_idcolumn is tracked separately, alongside that file's separate missing schema-version call, in a sibling issue — this issue covers onlygovernor-ledger.jsandplan-store.js, which already have a workingapplySchemaMigrationscall site.)Requirements
packages/loopover-miner/lib/governor-ledger.js'sgovernor_eventstable MUST gain a nullabletenant_id TEXTcolumn, added via a migration function namedaddTenantIdColumnpassed into the existingapplySchemaMigrations(db, [...])call (replacing the current empty array).packages/loopover-miner/lib/plan-store.js'sminer_planstable MUST gain a nullabletenant_id TEXTcolumn, added via a migration function namedaddTenantIdColumnpassed into its existingapplySchemaMigrations(db, [...])call (replacing the current empty array).addTenantIdColumnfunctions MUST guard theALTER TABLE ... ADD COLUMN tenant_id TEXTwith aPRAGMA table_info(<table>)column-presence check before altering, mirroringevent-ledger.js's andrun-state.js's existingaddTenantIdColumnimplementations exactly (idempotent against a file already migrated).tenant_idyet in either store — self-host behavior MUST be byte-identical (every existing row and every newly-inserted row hastenant_id = NULL), matching Add tenant-scoping columns to all local ledger schemas #4939's own stated behavior for the other four stores.governor-ledger.jsstore MUST result inPRAGMA user_version = 2(baseline 1 plus the one new migration); opening a freshplan-store.jsstore MUST likewise result inuser_version = 2, verifiable viaschema-version.js's exportedreadSchemaVersion.tenant_idcolumn,user_versionat whatever the current baseline is) MUST upgrade it in place with the column added and every existing row preserved.Deliverables
packages/loopover-miner/lib/governor-ledger.jscallingapplySchemaMigrations(db, [addTenantIdColumn]), withaddTenantIdColumndefined in that file.packages/loopover-miner/lib/plan-store.jscallingapplySchemaMigrations(db, [addTenantIdColumn]), withaddTenantIdColumndefined in that file.test/unit/miner-governor-ledger.test.tsassertingreadSchemaVersionreports2on a fresh store, plus a pre-migration-file upgrade test (old shape, notenant_id, opened viainitGovernorLedger, column added, rows preserved,tenant_idreads backnull).test/unit/miner-plan-store.test.tsasserting the same two things forplan-store.js.Test Coverage Requirements
Both
packages/loopover-miner/lib/governor-ledger.jsandpackages/loopover-miner/lib/plan-store.jsare underpackages/**, covered by this repo's 99%+ Codecov patch gate — every line of both newaddTenantIdColumnfunctions must be exercised, including the column-presence guard's both branches (column absent → added; column already present → left alone).Expected Outcome
governor-ledger.jsandplan-store.jscarry the sametenant_idhosted-readiness column the other four canonical local stores already have, closing the drift between what #4939 claimed was done and what the code actually had.Links & Resources
packages/loopover-miner/lib/schema-version.js(Add schema versioning to the local SQLite stores #4832)packages/loopover-miner/lib/event-ledger.js/run-state.js(reference: existingaddTenantIdColumnimplementations)