feat: idempotent seeding — add stable SIDs to all mock seed files #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "development_idempotent_seeding"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Every time hero_osis restarts with
--seed-dir, it creates duplicate records for all seeded entities. This is because seed TOML files have nosidfield, soseed_domain()injectssid = "0000"(global_id=0), which causesdb.set()to generate a brand new random SID on every restart.Visible impact: the Companies list (and all other entity lists) shows N copies of each seeded entity after N restarts.
Root Cause
Solution
Add a stable
sidfield to all 608 mock seed TOML files. Example:The
s-prefix SIDs (base36 starting at global_id=1,306,369) are safely above the auto-increment range (starting at global_id=2). Sincedb.set()already performs an upsert whenglobal_id != 0, restarting the server now overwrites existing records instead of creating duplicates.SID Convention
s001,s002, ...,s00a,s00b, ... (base36, s-prefixed)scripts/add_seed_sids.pyfor reproducibilityChanges
sid = "sXXX"after_type)scripts/add_seed_sids.pydb.set()upsert behaviorFollow-up: Seed Mode (create-only vs upsert)
Currently, seeding always upserts — meaning user edits to seeded entities get overwritten on restart. A future enhancement would add a
--seed-modeflag:upsert(current behavior): always overwrite seed data on restartcreate-only: skip seeding if the entity already exists, preserving user editsThis requires changes in both hero_lib (skip-if-exists logic in
seed_domain()) and hero_osis (CLI flag + passthrough). Tracked as separate issues:feat: idempotent seeding — add stable SIDs to all mock seed filesto WIP: feat: idempotent seeding — add stable SIDs to all mock seed filesE2E Test Results
Tested locally with a full clean-slate boot + restart cycle to confirm idempotent seeding.
Test Setup
cargo build --release --no-default-features --features all-domains)--seed-dir ... --contexts default)Test 1: First Boot (seed into empty DB)
All 608 seed files ingested. Queried
company.list+company.getacross 3 contexts via JSON-RPC:All SIDs unique, all company names unique within each context.
Test 2: Restart (re-seed into existing DB)
Stopped hero_osis, restarted it (same
--seed-dirflag, same data). Seeding ran again automatically on startup. Queried the same endpoints:Counts identical. Zero duplicates. Seeding is idempotent.
How It Works
sidfield (e.g.sid = "s001")seed_domain()in herolib-osis sees the existingsid, passes it through todb.set()SmartId::parse("s001")yieldsglobal_id = 1,306,369(non-zero)db.set()with non-zeroglobal_idperforms an upsert instead of generating a new IDCleanup
After testing, stopped all processes and restored original seed files from backup. No changes were made to the branch during testing — the PR is exactly as committed.
WIP: feat: idempotent seeding — add stable SIDs to all mock seed filesto feat: idempotent seeding — add stable SIDs to all mock seed files01f8e63fe715ec978f86