ALTER TABLE `webroam_licenses`
  ADD COLUMN IF NOT EXISTS `machine_id` varchar(128) DEFAULT NULL AFTER `serial_number`,
  ADD COLUMN IF NOT EXISTS `installation_id` varchar(128) DEFAULT NULL AFTER `machine_id`,
  ADD COLUMN IF NOT EXISTS `activation_locked` tinyint(1) NOT NULL DEFAULT 0 AFTER `blocked`,
  ADD COLUMN IF NOT EXISTS `activated_at` timestamp NULL DEFAULT NULL AFTER `activation_locked`,
  ADD COLUMN IF NOT EXISTS `last_check_at` timestamp NULL DEFAULT NULL AFTER `activated_at`,
  ADD COLUMN IF NOT EXISTS `last_seen_ip` varchar(64) DEFAULT NULL AFTER `last_check_at`,
  ADD COLUMN IF NOT EXISTS `used_endpoints` int(11) NOT NULL DEFAULT 0 AFTER `allowed_users`,
  ADD COLUMN IF NOT EXISTS `used_users` int(11) NOT NULL DEFAULT 0 AFTER `used_endpoints`,
  ADD COLUMN IF NOT EXISTS `allowed_remote_sessions_per_day` int(11) NOT NULL DEFAULT 0 AFTER `used_users`,
  ADD COLUMN IF NOT EXISTS `features_json` longtext DEFAULT NULL AFTER `allowed_remote_sessions_per_day`;

UPDATE `webroam_licenses`
SET `activation_locked` = 1
WHERE (`serial_number` IS NOT NULL AND `serial_number` <> '') AND `activation_locked` = 0;
