-- 004 — License audit history (who changed what, when)
-- Idempotent: safe to re-apply.
CREATE TABLE IF NOT EXISTS `sn_license_audit` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `license_id` INT UNSIGNED NOT NULL,
  `actor` VARCHAR(80) NOT NULL,                -- username or 'system'
  `action` VARCHAR(40) NOT NULL,               -- 'edit' | 'reissue' | 'status_change' | 'link_customer' | etc.
  `field` VARCHAR(40) DEFAULT '',
  `old_value` TEXT NULL,
  `new_value` TEXT NULL,
  `note` VARCHAR(500) DEFAULT '',
  `ip` VARCHAR(60) DEFAULT '',
  `created_at` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_license` (`license_id`),
  KEY `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
