CREATE TABLE IF NOT EXISTS `wpjy_tracy_issue_user_state` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `issue_id` BIGINT UNSIGNED NOT NULL,
  `user_id` BIGINT UNSIGNED NOT NULL,
  `state` VARCHAR(20) NOT NULL DEFAULT 'seen',
  `seen_at` DATETIME NULL DEFAULT NULL,
  `started_at` DATETIME NULL DEFAULT NULL,
  `linked_task_id` BIGINT UNSIGNED NULL DEFAULT NULL,
  `linked_ticket_id` BIGINT UNSIGNED NULL DEFAULT NULL,
  `notes` TEXT NULL DEFAULT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uq_tracy_issue_user_state` (`issue_id`, `user_id`) USING BTREE,
  KEY `idx_tracy_issue_user_state_user` (`user_id`, `state`) USING BTREE,
  KEY `idx_tracy_issue_user_state_issue` (`issue_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
