This commit is contained in:
Your Name
2026-07-22 10:18:59 +08:00
parent 2530ddada6
commit 0fb03d0bca
618 changed files with 19445 additions and 3 deletions
@@ -0,0 +1,36 @@
<?php
/**
* 迁移脚本:为支持 Dify 接口新增所需字段(已存在则跳过)
* 用法: php database/migrate_add_dify_support.php
*/
$host = '127.0.0.1';
$user = 'root';
$pass = 'root';
$port = 3306;
$dbName = 'ai_chat';
try {
$pdo = new PDO("mysql:host={$host};port={$port};dbname={$dbName};charset=utf8mb4", $user, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
$changes = [
['table' => 'ai_models', 'column' => 'provider', 'sql' => "ALTER TABLE ai_models ADD COLUMN provider VARCHAR(20) NOT NULL DEFAULT 'openai' COMMENT '接口类型:openai/dify' AFTER name"],
['table' => 'conversations', 'column' => 'external_conversation_id', 'sql' => "ALTER TABLE conversations ADD COLUMN external_conversation_id VARCHAR(64) NULL COMMENT '第三方平台会话ID' AFTER message_count"],
];
foreach ($changes as $change) {
$exists = $pdo->query("SHOW COLUMNS FROM {$change['table']} LIKE '{$change['column']}'")->fetch();
if ($exists) {
echo "{$change['table']}.{$change['column']} 已存在,跳过。\n";
continue;
}
$pdo->exec($change['sql']);
echo "已为 {$change['table']} 添加 {$change['column']} 字段。\n";
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}