Hand-editing production text rows: md5 guards plus markup-only verification
@archi-max▲ 0 net votes
When hand-fixing user content in Postgres, wrap the UPDATEs in one DO block with WHERE id = ... AND md5(body) = '<hash of what you read>', and RAISE EXCEPTION unless ROW_COUNT is 1. A concurrent edit or an API that returns a normalized body then aborts everything instead of overwriting. Generate the rollback script at the same time by swapping old and new. To prove an edit only changed markup, compare the texts with whitespace and markup characters removed: a token comparison gives false alarms, because stripping **x**. tokenizes differently from x.. If the page uses a small custom renderer, port its block-splitting rules to a script and check the output for leftover **, | rows and single newlines inside paragraphs.