Skip to content

[Enhancement] Populate parent_simulation_id from Case Canonical + Surface in Simulation Details #127

@tomvothecoder

Description

@tomvothecoder

Summary

Backfill and maintain parent_simulation_id on Simulation records by referencing the canonical_simulation_id of the associated Case.

Expose parent_simulation_id on the Simulation Details page for non-canonical simulations, with a link to the parent (canonical) simulation.

Motivation

  • The canonical simulation acts as the baseline for a Case.
  • Non-canonical simulations conceptually derive from the canonical configuration.
  • Explicitly storing parent_simulation_id improves:
    • Data clarity
    • Query simplicity
    • UI linking
    • Future diff/comparison workflows

Currently, this relationship is implicit via case.canonical_simulation_id. It should be materialized on the Simulation model.

Proposed Changes

1. Backend: Backfill Logic

For all existing simulations:

  • If simulation.id == case.canonical_simulation_id
    parent_simulation_id = NULL
  • Else
    parent_simulation_id = case.canonical_simulation_id

Implementation options:

  • Data migration (preferred)
  • One-time script executed in migration context

Edge cases:

  • Cases with canonical_simulation_id IS NULL
    • Do not populate parent_simulation_id
  • Orphaned simulations (should not exist; validate)

2. Backend: Ingestion Logic

On simulation creation:

  • Fetch the associated Case
  • If:
    • No canonical exists → this simulation becomes canonical → parent_simulation_id = NULL
    • Canonical exists → set parent_simulation_id = case.canonical_simulation_id

Ensure this logic runs atomically within the same transaction.

3. API Updates

Include parent_simulation_id in:

  • Simulation detail response
  • Simulation list responses (optional but recommended for consistency)

4. Frontend: Simulation Details Page

If simulation is non-canonical:

Display:

Parent Simulation: <execution_id> (linked)

Link target:
/simulations/{parent_simulation_id}

If canonical:

  • Do not show parent field.

Placement:

  • Configuration or Metadata section
  • Do not elevate to badge or header

Acceptance Criteria

  • All non-canonical simulations have parent_simulation_id populated.
  • Canonical simulations have parent_simulation_id = NULL.
  • Simulation Details page displays parent link only when applicable.
  • No change to existing canonical logic or promotion rules.

Non-Goals

  • No support for multi-level ancestry.
  • No diff computation changes.
  • No case modeling changes.
  • No automatic canonical reassignment logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions