Skip to content

governor-ledger.js and plan-store.js are missing the tenant_id column #4939 was supposed to add everywhere #6597

Description

@JSONbored

Context

#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.

Links & Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions