-- Device status transition audit table
CREATE TABLE IF NOT EXISTS device_status_transition (
  id BIGINT PRIMARY KEY AUTO_INCREMENT,
  device_id VARCHAR(64) NOT NULL,
  prev_status VARCHAR(32) NULL,
  new_status VARCHAR(32) NOT NULL,
  reason VARCHAR(255) NULL,
  snapshot_val VARCHAR(64) NULL,
  series VARCHAR(16) NULL,
  index_no INT NULL,
  occurred_at DATETIME NOT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_device_created (device_id, created_at),
  INDEX idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


