{
  "schema": "vedokrok.public-item.v1",
  "release_id": "MHC-RPUB-20260920-75ad787a",
  "url": "/knowledge/write-invariants-before-the-migration",
  "id": "MHC-D-RESEARCH-0351",
  "version": "0.1.0",
  "title": "Write invariants before the migration",
  "summary": "A migration can be perfectly formatted and completely wrong.",
  "kind": "checklist",
  "body": "Before running the change, write the properties that must remain true across it: uniqueness, required relationships, totals, allowed status transitions, referential links, permission boundaries or another domain invariant. Validate them on staged output and again after application. Prefer checks that fail loudly over manual visual confidence.",
  "limits": [
    "Missing invariants create false confidence; involve domain owners where correctness depends on rules the implementation team may not know."
  ],
  "topics": [
    "union-safe-change-operations"
  ],
  "intents": [],
  "source_ids": [
    "RS-5D6BA8DCC62D671F"
  ],
  "evidence": [
    {
      "claim": "Google SRE's two-phase mutation pattern explicitly separates generating candidate changes from validating their correctness before applying them.",
      "source_id": "RS-5D6BA8DCC62D671F",
      "role": "supports",
      "note": "Validation rules must encode the invariants that actually matter; a passing schema check can still permit a semantically wrong change.",
      "locator": "Two-Phase Mutations"
    }
  ],
  "use_when": [
    "A transformation can produce syntactically valid output while breaking business rules."
  ],
  "avoid_when": [
    "Missing invariants create false confidence; involve domain owners where correctness depends on rules the implementation team may not know."
  ],
  "example": "A business-partner migration may require every active sales-area assignment to keep exactly one valid partner role mapping.",
  "check": "A technically successful transformation still fails the gate when a declared business invariant is violated.",
  "checklist": [
    "Each invariant states what must remain true, not how the script happens to work.",
    "The invariant can be checked automatically or with a defined inspection method.",
    "Pre-change baseline values are captured when comparison matters.",
    "Staged output is checked before commit.",
    "Authoritative post-change state is checked again."
  ],
  "sources": [
    {
      "id": "RS-5D6BA8DCC62D671F",
      "title": "Improve and Optimize Data Processing Pipelines",
      "url": "https://sre.google/workbook/data-processing/"
    }
  ],
  "relations": [
    {
      "from": "MHC-D-RESEARCH-0351",
      "to": "MHC-D-RESEARCH-0343",
      "type": "useful_with",
      "url": "/knowledge/stage-the-mutation-before-committing-it"
    }
  ],
  "collections": [
    {
      "id": "RC-4F77BDBBF2481574",
      "title": "Change live systems without turning one mistake into a large one",
      "url": "/collections/change-live-systems-without-turning-one-mistake-into-a-large-one"
    }
  ]
}
