-- Migration 050: Add extended columns to crash log tables (MariaDB-compatible)
-- Adds exception_class, error_type, app_version to ftt_crash_logs and crash_logs.
-- Adds tab_id and batch_ts to ftt_app_logs to match add_log_batch.php expectations.
-- Fixes device_id column to NOT NULL with default in ftt_crash_logs.
-- Safe to run multiple times (IF NOT EXISTS).

ALTER TABLE ftt_crash_logs
    ADD COLUMN IF NOT EXISTS exception_class VARCHAR(256) NOT NULL DEFAULT '' AFTER thread_name,
    ADD COLUMN IF NOT EXISTS error_type      VARCHAR(32)  NOT NULL DEFAULT 'crash' AFTER exception_class,
    ADD COLUMN IF NOT EXISTS app_version     VARCHAR(32)  NOT NULL DEFAULT '' AFTER error_type;

ALTER TABLE crash_logs
    ADD COLUMN IF NOT EXISTS device_id       VARCHAR(64)  DEFAULT '' AFTER install_uuid,
    ADD COLUMN IF NOT EXISTS exception_class VARCHAR(256) NOT NULL DEFAULT '' AFTER thread_name,
    ADD COLUMN IF NOT EXISTS error_type      VARCHAR(32)  NOT NULL DEFAULT 'crash' AFTER exception_class,
    ADD COLUMN IF NOT EXISTS app_version     VARCHAR(32)  NOT NULL DEFAULT '' AFTER error_type;

ALTER TABLE ftt_app_logs
    ADD COLUMN IF NOT EXISTS tab_id   VARCHAR(64)       DEFAULT NULL AFTER detail,
    ADD COLUMN IF NOT EXISTS batch_ts BIGINT UNSIGNED   DEFAULT 0   AFTER tab_id;
