ALTER TABLE simplix_fgts_cases
    ADD COLUMN tracking_token VARCHAR(64) NULL AFTER cpf,
    ADD COLUMN public_step VARCHAR(50) NULL AFTER tracking_token,
    ADD COLUMN public_status_code VARCHAR(100) NULL AFTER public_step,
    ADD COLUMN public_status_message TEXT NULL AFTER public_status_code,
    ADD COLUMN last_public_action_at DATETIME NULL AFTER public_status_message,
    ADD COLUMN contact_name VARCHAR(150) NULL AFTER last_public_action_at,
    ADD COLUMN contact_phone VARCHAR(30) NULL AFTER contact_name,
    ADD COLUMN contact_email VARCHAR(150) NULL AFTER contact_phone,
    ADD COLUMN followup_required TINYINT(1) NOT NULL DEFAULT 1 AFTER contact_email;

UPDATE simplix_fgts_cases
SET tracking_token = REPLACE(UUID(), '-', '')
WHERE tracking_token IS NULL;

ALTER TABLE simplix_fgts_cases
    MODIFY tracking_token VARCHAR(64) NOT NULL,
    ADD UNIQUE KEY idx_simplix_case_tracking (tracking_token),
    ADD INDEX idx_simplix_case_public_step (public_step);
