CREATE TABLE IF NOT EXISTS `dxbots_modules` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `bot_id` INT NOT NULL,
  `module_key` VARCHAR(50) NOT NULL,
  `enabled` TINYINT(1) NOT NULL DEFAULT 0,
  `config` JSON NULL,
  `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY `uq_bot_module` (`bot_id`, `module_key`),
  INDEX `idx_bot` (`bot_id`),
  CONSTRAINT `fk_modules_bot` FOREIGN KEY (`bot_id`) REFERENCES `dxbots_bots`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
