BUG修复:添加分离式刷新按钮
This commit is contained in:
1 parent
ec5c2db848
commit
00617621f9
4 files changed
+287
-141
No files matched your search
+53
-2
@@ -141,10 +141,61 @@ function initVpsTables($db) {
|
||||
api_key TEXT NOT NULL,
|
||||
auto_monitor BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(site_url, account)
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
");
|
||||
|
||||
// 迁移:如果存在旧的UNIQUE约束,需要重建表
|
||||
migrateConfigsTable($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* 迁移configs表,删除UNIQUE(site_url, account)约束
|
||||
* 允许同一个源添加多个不同的AccessKey
|
||||
*/
|
||||
function migrateConfigsTable($db) {
|
||||
try {
|
||||
// 检查是否存在旧的唯一约束
|
||||
$result = $db->query("PRAGMA index_list(configs)");
|
||||
$hasOldConstraint = false;
|
||||
|
||||
foreach ($result as $index) {
|
||||
if (isset($index['name']) && strpos($index['name'], 'site_url') !== false) {
|
||||
$hasOldConstraint = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasOldConstraint) {
|
||||
// 需要迁移:创建新表 -> 复制数据 -> 删除旧表 -> 重命名
|
||||
$db->execute("ALTER TABLE configs RENAME TO configs_old");
|
||||
|
||||
$db->execute("
|
||||
CREATE TABLE configs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
api_label TEXT NOT NULL UNIQUE,
|
||||
site_type TEXT NOT NULL,
|
||||
site_url TEXT,
|
||||
account TEXT NOT NULL,
|
||||
api_key TEXT NOT NULL,
|
||||
auto_monitor BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
");
|
||||
|
||||
$db->execute("
|
||||
INSERT INTO configs (id, api_label, site_type, site_url, account, api_key, auto_monitor, created_at, updated_at)
|
||||
SELECT id, api_label, site_type, site_url, account, api_key, auto_monitor, created_at, updated_at
|
||||
FROM configs_old
|
||||
");
|
||||
|
||||
$db->execute("DROP TABLE configs_old");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// 迁移失败不影响正常使用,记录日志即可
|
||||
error_log("[迁移警告] configs表迁移失败: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user