-- events 도메인 PR-1 (10/11) — events_history 변경 이력 테이블
-- lifecycle op 자동 기록 (create / reschedule / defer / reactivate / complete / cancel).
-- 일반 PATCH (title/description 등) 의 history 는 v1 X (폭증 회피).
-- ON DELETE RESTRICT: 이력은 시점 사실 → 부모 events row 직접 삭제 차단
-- (feedback_history_table_fk_restrict.md). events 자체는 /cancel 로 soft-cancel.

CREATE TABLE IF NOT EXISTS events_history (
    id            BIGSERIAL PRIMARY KEY,
    event_id      BIGINT NOT NULL REFERENCES events(id) ON DELETE RESTRICT,
    changed_at    TIMESTAMPTZ NOT NULL DEFAULT now(),
    changed_by    event_actor NOT NULL,
    change_kind   history_change_kind NOT NULL,
    before        JSONB,                              -- create 시 NULL
    after         JSONB NOT NULL
);
