Run Backfill
Repairs run.race_id, run.runner_id,
run.jockey_id, run.trainer_id, run.course_id and
run.bonus_scheme_id — the FK columns on run, sourced from
tblruns.WRaceID / WHorseID / WJockeyID / WTrainerID /
WCourseID / WBonusSchemeId. Each can end up wrong the same ways: never resolved at
migration time (the implicit default was left in place), resolved to the wrong row
because the true parent hadn't been auto-copied yet, a cross-entity swap, or correct at
migration time but drifted since. A single rule fixes all of them: for every
already-migrated run row, this re-reads its current source ids,
translates each through the current config_id_mappings,
and corrects whichever column(s) disagree — independently, so one run row can have zero
to six columns corrected at once.
jockey_id and trainer_id are discipline-aware — the
same source jockey/trainer can have more than one destination row, one per discipline it
raced in — so those two are resolved through the run's own WDiscipline, not
a plain source-id lookup. race_id and runner_id are not
discipline-aware and resolve via a plain source-id lookup.
Only already-resolvable columns are touched — a column whose parent genuinely hasn't
migrated yet (or has no mapping for this row's exact discipline) is left alone, never
auto-copied. This overlaps in scope with FK Integrity Repair for
jockey_id/trainer_id/runner_id (that tool already recomputes and corrects those three) —
running both is safe since both are idempotent, but redundant for those three columns.
This feature's one exclusive contribution is race_id, which nothing else
currently repairs. It is also safe alongside Auto Sync and the general value backfill on
run: it only ever reads/updates run rows that already have a durable
config_id_mappings entry, which Auto Sync never touches mid-insert.
- Run → Race FK tblruns.WRaceID → run.race_id
- Run → Runner FK tblruns.WHorseID → run.runner_id
- Run → Jockey FK discipline-aware tblruns.WJockeyID → run.jockey_id
- Run → Trainer FK discipline-aware tblruns.WTrainerID → run.trainer_id
- Run → Course FK tblruns.WCourseID → run.course_id
- Run → Breeding Bonus FK tblruns.WBonusSchemeId → run.bonus_scheme_id
Preview runs the exact same reads and resolves the exact same expected values, but skips the actual write — no column is changed. Use it to see what would change before committing to a real run.
Scheduled Backfill
Runs this same re-resolution pass automatically on a recurring interval instead of only ever running it by hand.