--liquibase formatted sql

--changeset fpsms:client_presence_event
--preconditions onFail:MARK_RAN
--precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'client_presence_event'
--comment: Historical device presence samples (offline / poor connection)
CREATE TABLE `client_presence_event` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `device_id` varchar(64) NOT NULL,
  `user_id` bigint DEFAULT NULL,
  `username` varchar(100) DEFAULT NULL,
  `display_name` varchar(128) DEFAULT NULL,
  `client_type` varchar(16) NOT NULL DEFAULT 'unknown',
  `status` varchar(16) NOT NULL,
  `connection_quality` varchar(16) DEFAULT NULL,
  `rtt_ms` int DEFAULT NULL,
  `navigator_online` tinyint(1) NOT NULL DEFAULT 1,
  `current_path` varchar(512) DEFAULT NULL,
  `recorded_at` datetime NOT NULL,
  `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_cpe_recorded_at` (`recorded_at`),
  KEY `idx_cpe_device_recorded` (`device_id`, `recorded_at`),
  KEY `idx_cpe_status_recorded` (`status`, `recorded_at`),
  KEY `idx_cpe_client_type_recorded` (`client_type`, `recorded_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
