总结expert领域的功能
This commit is contained in:
46
sql/patch_expert_field_ai_columns.php
Normal file
46
sql/patch_expert_field_ai_columns.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* 补全 t_expert 缺失的 field_ai 相关字段(可重复执行)
|
||||
* 用法: php sql/patch_expert_field_ai_columns.php
|
||||
*/
|
||||
$config = require __DIR__ . '/../application/database.php';
|
||||
|
||||
$dsn = sprintf(
|
||||
'mysql:host=%s;port=%s;dbname=%s;charset=%s',
|
||||
$config['hostname'],
|
||||
$config['hostport'],
|
||||
$config['database'],
|
||||
$config['charset']
|
||||
);
|
||||
$pdo = new PDO($dsn, $config['username'], $config['password'], [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
]);
|
||||
|
||||
$table = $config['prefix'] . 'expert';
|
||||
$cols = $pdo->query("SHOW COLUMNS FROM `{$table}`")->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$colSet = array_flip($cols);
|
||||
|
||||
$alters = [];
|
||||
if (!isset($colSet['field_ai'])) {
|
||||
$alters[] = "ADD COLUMN `field_ai` VARCHAR(512) NOT NULL DEFAULT '' COMMENT 'AI总结的主要研究领域(中文)' AFTER `affiliation`";
|
||||
}
|
||||
if (!isset($colSet['field_ai_status'])) {
|
||||
$after = isset($colSet['field_ai']) || !empty($alters) ? 'field_ai' : 'affiliation';
|
||||
$alters[] = "ADD COLUMN `field_ai_status` TINYINT NOT NULL DEFAULT 0 COMMENT '0待处理 1已生成 2资料不足 3失败 4无user待AI' AFTER `{$after}`";
|
||||
}
|
||||
if (!isset($colSet['field_ai_utime'])) {
|
||||
$alters[] = "ADD COLUMN `field_ai_utime` INT NOT NULL DEFAULT 0 COMMENT 'field_ai更新时间' AFTER `field_ai_status`";
|
||||
}
|
||||
if (!isset($colSet['field_ai_source'])) {
|
||||
$alters[] = "ADD COLUMN `field_ai_source` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '来源: user_link / ai' AFTER `field_ai_utime`";
|
||||
}
|
||||
|
||||
if (empty($alters)) {
|
||||
echo "OK: all field_ai columns exist on {$table}\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$sql = "ALTER TABLE `{$table}` " . implode(', ', $alters);
|
||||
echo "Running: {$sql}\n";
|
||||
$pdo->exec($sql);
|
||||
echo "Done.\n";
|
||||
Reference in New Issue
Block a user