mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-08-30 12:45:32 +08:00
feat(timer): 新增并发数/触发节点/触发时间三字段及幂等分发
Scheme 定义 concurrency(nullable)/trigger_node_id/last_trigger_time 三字段,Model 声明属性,v2.3.0 分发代码幂等 ALTER 保证升级自动同步。 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
85
extend/base/admin/service/adminUpdateCodeData/v2.3.0.php
Normal file
85
extend/base/admin/service/adminUpdateCodeData/v2.3.0.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* @internal-framework
|
||||
*
|
||||
* 此文件为框架内置功能
|
||||
*
|
||||
* 用途:框架版本更新代码(v2.3.0)- system_timer_config 新增定时器动态管控三字段
|
||||
* 维护者:框架维护者
|
||||
*
|
||||
* 变更:
|
||||
* - concurrency INT UNSIGNED NULL 并发数:NULL=继承代码默认
|
||||
* - trigger_node_id VARCHAR(100) NULL 手动触发目标节点ID
|
||||
* - last_trigger_time INT UNSIGNED NULL 手动触发设置时间戳,用于TTL自动复位
|
||||
*
|
||||
* 三字段均允许 NULL,用于区分"继承代码默认"与"显式覆盖"。
|
||||
*
|
||||
* 注意:此文件属于框架内核,业务开发者不应修改
|
||||
*/
|
||||
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
class UpdateFunction
|
||||
{
|
||||
/**
|
||||
* @var Input
|
||||
*/
|
||||
public $input;
|
||||
|
||||
/**
|
||||
* @var Output
|
||||
*/
|
||||
public $output;
|
||||
|
||||
/**
|
||||
* 待新增字段定义.
|
||||
*/
|
||||
public $newColumns = [
|
||||
'concurrency' => "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('更新代码完成');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user