Skip to content

fix(db): self-host Postgres dialect translator has no conflict-key entry for orb_reuse_counters #8893

Description

@JSONbored

⚠️ Definition of Done: this issue must be completed in full, in a single PR. Do not split this
work across multiple PRs, and do not defer any Deliverable below to a follow-up issue. A PR that
satisfies only some of the Deliverables, stubs a required test, or leaves a checkbox
partially-done does NOT resolve this issue and will be closed.

Context

src/selfhost/pg-dialect.ts:9-25's REPLACE_CONFLICT_KEYS map requires every table used with INSERT OR REPLACE to have an entry, or translateInsertOr() throws pg_dialect: INSERT OR REPLACE into '<table>' has no known conflict key (line 131). Migration migrations/0177_orb_reuse_counters.sql:16 (#8820) added orb_reuse_counters with PRIMARY KEY (instance_id, day) and a real INSERT OR REPLACE writer at src/orb/ingest.ts:226, but nobody added the matching entry to the map -- every other table that uses INSERT OR REPLACE (system_flags, tunables_overrides, tunables_overrides_shadow, orb_export_cursor, orb_signals, ams_signals) has one. Any self-hosted Postgres instance running the hourly ORB export throws on its first orb_reuse_counters write.

Requirements

Add orb_reuse_counters: ["instance_id", "day"] to REPLACE_CONFLICT_KEYS in src/selfhost/pg-dialect.ts.

Deliverables

  • REPLACE_CONFLICT_KEYS includes orb_reuse_counters: ["instance_id", "day"]
  • A regression test in test/unit/selfhost-pg-dialect.test.ts referencing this table, asserting translateInsertOr succeeds instead of throwing

All of the above Deliverables are required in the same PR unless the deliverable text itself states otherwise.

Test Coverage Requirements

src/** -- 99%+ patch coverage, branch-counted, on the new map entry and its test.

Expected Outcome

A self-hosted Postgres instance's hourly ORB export no longer throws on its first orb_reuse_counters write.

Links & Resources

  • src/selfhost/pg-dialect.ts:9-25,131
  • migrations/0177_orb_reuse_counters.sql:16
  • src/orb/ingest.ts:226
  • test/unit/selfhost-pg-dialect.test.ts

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