feat: add --seed-mode CLI flag (create-only vs upsert) #3

Open
opened 2026-02-11 15:14:17 +00:00 by mik-tf · 0 comments
Owner

Context

PR #2 fixed duplicate seeding by adding stable SIDs to all mock TOML files. With stable SIDs, db.set() performs an upsert instead of creating new records on every restart.

However, the current seeding behavior always overwrites existing records. In production, this means user edits to seeded entities get reset on every server restart.

Proposed Change

Add a --seed-mode CLI flag to src/bin/server.rs:

/// Seed mode: "upsert" (default, always overwrite) or "create-only" (skip existing)
#[arg(long, env = "HERO_OSIS_SEED_MODE", default_value = "upsert")]
seed_mode: String,

Pass this through to seed_from_config_dir() / seed_domain() in herolib-osis.

This also requires a corresponding change in hero_lib to support the mode in seed_domain() — tracked as lhumina_code/hero_lib#98

Behavior

  • --seed-mode=upsert (default): current behavior, always overwrite seed data on restart
  • --seed-mode=create-only: check if entity exists before seeding, skip if it does — preserves user edits

hero_zero integration

Once implemented, the hero_zero service template (services/hero_osis.toml) could be updated:

# Development: always refresh mock data
exec = "hero_osis --seed-dir ... --seed-mode upsert"

# Production: only seed once, preserve user data
exec = "hero_osis --seed-dir ... --seed-mode create-only"
## Context PR #2 fixed duplicate seeding by adding stable SIDs to all mock TOML files. With stable SIDs, `db.set()` performs an upsert instead of creating new records on every restart. However, the current seeding behavior always **overwrites** existing records. In production, this means user edits to seeded entities get reset on every server restart. ## Proposed Change Add a `--seed-mode` CLI flag to `src/bin/server.rs`: ```rust /// Seed mode: "upsert" (default, always overwrite) or "create-only" (skip existing) #[arg(long, env = "HERO_OSIS_SEED_MODE", default_value = "upsert")] seed_mode: String, ``` Pass this through to `seed_from_config_dir()` / `seed_domain()` in herolib-osis. This also requires a corresponding change in hero_lib to support the mode in `seed_domain()` — tracked as https://forge.ourworld.tf/lhumina_code/hero_lib/issues/98 ## Behavior - `--seed-mode=upsert` (default): current behavior, always overwrite seed data on restart - `--seed-mode=create-only`: check if entity exists before seeding, skip if it does — preserves user edits ## hero_zero integration Once implemented, the hero_zero service template (`services/hero_osis.toml`) could be updated: ```toml # Development: always refresh mock data exec = "hero_osis --seed-dir ... --seed-mode upsert" # Production: only seed once, preserve user data exec = "hero_osis --seed-dir ... --seed-mode create-only" ``` ## Related - hero_lib seed_domain() changes: https://forge.ourworld.tf/lhumina_code/hero_lib/issues/98 - Idempotent seeding PR: #2
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_osis#3
No description provided.