feat(config): backup v1 file before v2 migration

- Add timestamped backup at `~/.cc-switch/config.v1.backup.<ts>.json`
- Keep provider files untouched; only cc-switch metadata is backed up
- Remove UI notification plan; backup only as requested
- Update CHANGELOG with migration backup notes
This commit is contained in:
Jason
2025-09-01 10:49:31 +08:00
parent 47b06b7773
commit b00e8de26f
3 changed files with 26 additions and 2 deletions

View File

@@ -44,6 +44,11 @@ For users upgrading from v2.x (Electron version):
- The app will automatically migrate your existing provider configurations
- Window position and size preferences have been reset to defaults
#### Backup on v1→v2 Migration (cc-switch internal config)
- When the app detects an old v1 config structure at `~/.cc-switch/config.json`, it now creates a timestamped backup before writing the new v2 structure.
- Backup location: `~/.cc-switch/config.v1.backup.<timestamp>.json`
- This only concerns cc-switch's own metadata file; your actual provider files under `~/.claude/` and `~/.codex/` are untouched.
### 🛠️ Development
- Added `pnpm typecheck` command for TypeScript validation
- Added `pnpm format` and `pnpm format:check` for code formatting

View File

@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::config::{get_app_config_path, write_json_file};
use crate::config::{copy_file, get_app_config_dir, get_app_config_path, write_json_file};
use crate::provider::ProviderManager;
/// 应用类型
@@ -78,6 +78,23 @@ impl MultiAppConfig {
let config = Self { version: 2, apps };
// 迁移前备份旧版(v1)配置文件
let backup_dir = get_app_config_dir();
let ts = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs();
let backup_path = backup_dir.join(format!("config.v1.backup.{}.json", ts));
match copy_file(&config_path, &backup_path) {
Ok(()) => log::info!(
"已备份旧版配置文件: {} -> {}",
config_path.display(),
backup_path.display()
),
Err(e) => log::warn!("备份旧版配置文件失败: {}", e),
}
// 保存迁移后的配置
config.save()?;
return Ok(config);

View File

@@ -167,6 +167,8 @@ export const tauriAPI = {
}
},
// (保留空位,取消迁移提示)
// 选择配置文件Tauri 暂不实现,保留接口兼容性)
selectConfigFile: async (): Promise<string | null> => {
console.warn("selectConfigFile 在 Tauri 版本中暂不支持");