-- Audit log table for tag control overrides
CREATE TABLE IF NOT EXISTS `control_write_log` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `tag_id` VARCHAR(190) NOT NULL,
  `tag_name` VARCHAR(190) DEFAULT NULL,
  `mode` VARCHAR(32) DEFAULT NULL,
  `previous_value` DECIMAL(18,6) DEFAULT NULL,
  `new_value` DECIMAL(18,6) DEFAULT NULL,
  `requested_value` DECIMAL(18,6) DEFAULT NULL,
  `delta` DECIMAL(18,6) DEFAULT NULL,
  `status` VARCHAR(190) DEFAULT NULL,
  `message` VARCHAR(255) DEFAULT NULL,
  `username` VARCHAR(190) DEFAULT NULL,
  `session_id` VARCHAR(128) DEFAULT NULL,
  `client_ip` VARCHAR(64) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_control_write_log_created_at` (`created_at`),
  KEY `idx_control_write_log_tag_id` (`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
