"ADD COLUMN `concurrency` INT UNSIGNED NULL COMMENT '并发数:NULL=继承代码默认'", 'trigger_node_id' => "ADD COLUMN `trigger_node_id` VARCHAR(100) NULL COMMENT '手动触发目标节点ID'", 'last_trigger_time' => "ADD COLUMN `last_trigger_time` INT UNSIGNED NULL COMMENT '手动触发设置时间戳,用于TTL自动复位'", ]; public function update() { $this->output->writeln('更新代码'); $this->output->info('v2.3.0:为 system_timer_config 表新增定时器动态管控字段(concurrency / trigger_node_id / last_trigger_time)'); $table = config('database.connections.mysql.prefix', 'ul_') . 'system_timer_config'; // 确认表存在 $tableExists = Db::query( "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?", [$table] ); if (empty($tableExists)) { $this->output->warning("表 {$table} 不存在,跳过字段新增。请先执行 scheme:sync 或 migrate:run 初始化表结构。"); return; } // 幂等:读取现有字段,已存在的跳过 $columns = Db::query("SHOW COLUMNS FROM `{$table}`"); $exists = array_column($columns, 'Field'); $added = 0; $skipped = 0; foreach ($this->newColumns as $field => $sqlFragment) { if (in_array($field, $exists)) { $this->output->writeln(" - 字段 {$field} 已存在,跳过"); ++$skipped; continue; } Db::execute("ALTER TABLE `{$table}` {$sqlFragment}"); $this->output->writeln(" - 新增字段 {$field} 完成"); ++$added; } $this->output->info("本次新增 {$added} 个字段,跳过 {$skipped} 个已存在字段"); $this->output->writeln('更新代码完成'); } }