
-- 게시물 수정 내역: 바꾸기 전에 지금 행을 history 로 복사한다 (posts : post_history = 1 : N)
update :: Post -> Changes -> [History] -> (Post, [History])
update post new history = (post `apply` new { updatedAt = now }, history ++ [snapshot post])
where snapshot p = History (postId p) (title p) (content p) (updatedAt p)
-- INSERT INTO post_history (post_id, title, content, updated_at) SELECT … FROM posts WHERE id = 1;
-- UPDATE posts SET title = '새 제목', updated_at = CURRENT_TIMESTAMP WHERE id = 1;
-- 게시물이 지워지면 ON DELETE CASCADE 로 내역도