-- Phase 14 S4  -  Mobile security + audit source column
-- Adds org_id to audit_logs (for per-org mobile audit filtering),
-- adds apns_token to mobile_devices, and adds a per-device push_badge_count.
-- Note: IF NOT EXISTS on ADD COLUMN is MariaDB-only; removed for MySQL 8.4 compat.
-- Migration runner ensures each file runs exactly once, so plain ADD COLUMN is safe.

ALTER TABLE audit_logs
    ADD COLUMN org_id BIGINT UNSIGNED NULL AFTER user_id,
    ADD COLUMN source VARCHAR(40) NULL AFTER meta_json;

ALTER TABLE mobile_devices
    ADD COLUMN apns_token VARCHAR(255) NULL AFTER device_token,
    ADD COLUMN push_badge_count INT UNSIGNED NOT NULL DEFAULT 0 AFTER device_label;
