-- =============================================================
-- V019: Rename session_audit_log.actor_telegram_id to actor_external_user_id
-- =============================================================
-- Scope: Support platform-agnostic audit log identity.
-- =============================================================

ALTER TABLE session_audit_log
    ADD COLUMN actor_external_user_id VARCHAR(255);

UPDATE session_audit_log
   SET actor_external_user_id = actor_telegram_id::TEXT
 WHERE actor_external_user_id IS NULL;

ALTER TABLE session_audit_log
    ALTER COLUMN actor_external_user_id SET NOT NULL;

ALTER TABLE session_audit_log
    DROP COLUMN actor_telegram_id;
