-- -----------------------------------------------------------
-- Share Tokens Table (encrypted document share links)
-- -----------------------------------------------------------
DROP TABLE IF EXISTS `share_tokens`;
CREATE TABLE `share_tokens` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `token` varchar(128) NOT NULL,
  `entity_type` varchar(50) NOT NULL DEFAULT 'style',
  `entity_id` int unsigned NOT NULL,
  `created_by` int unsigned DEFAULT NULL,
  `expires_at` timestamp NULL DEFAULT NULL,
  `access_count` int unsigned NOT NULL DEFAULT 0,
  `max_access` int unsigned DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `token` (`token`),
  KEY `entity` (`entity_type`, `entity_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
