-- Webroam License Cloud v4 schema patch
ALTER TABLE webroam_licenses
  ADD COLUMN IF NOT EXISTS allowed_remote_sessions_per_day INT NOT NULL DEFAULT 0 AFTER allowed_users,
  ADD COLUMN IF NOT EXISTS used_endpoints INT NOT NULL DEFAULT 0 AFTER allowed_remote_sessions_per_day,
  ADD COLUMN IF NOT EXISTS used_users INT NOT NULL DEFAULT 0 AFTER used_endpoints,
  ADD COLUMN IF NOT EXISTS activation_locked TINYINT(1) NOT NULL DEFAULT 0 AFTER blocked,
  ADD COLUMN IF NOT EXISTS machine_id VARCHAR(128) DEFAULT NULL AFTER activation_locked,
  ADD COLUMN IF NOT EXISTS installation_id VARCHAR(128) DEFAULT NULL AFTER machine_id,
  ADD COLUMN IF NOT EXISTS hostname VARCHAR(255) DEFAULT NULL AFTER installation_id,
  ADD COLUMN IF NOT EXISTS first_activated_at DATETIME DEFAULT NULL AFTER hostname,
  ADD COLUMN IF NOT EXISTS last_seen_at DATETIME DEFAULT NULL AFTER first_activated_at,
  ADD COLUMN IF NOT EXISTS last_check_at DATETIME DEFAULT NULL AFTER last_seen_at,
  ADD COLUMN IF NOT EXISTS last_action VARCHAR(64) DEFAULT NULL AFTER last_check_at,
  ADD COLUMN IF NOT EXISTS features TEXT DEFAULT NULL AFTER notes;

CREATE INDEX IF NOT EXISTS idx_webroam_licenses_product_key ON webroam_licenses(product_key);
CREATE INDEX IF NOT EXISTS idx_webroam_licenses_machine_id ON webroam_licenses(machine_id);
CREATE INDEX IF NOT EXISTS idx_webroam_licenses_installation_id ON webroam_licenses(installation_id);
