mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 08:44:41 +08:00
feat(backup): add pre-migration backup, periodic backup, backfill warning, and backup management UI
Four improvements to the database backup mechanism: 1. Auto backup before schema migration - creates a snapshot when upgrading from an older database version, providing a safety net beyond the existing SAVEPOINT rollback mechanism. 2. Periodic startup backup - checks on app launch whether the latest backup is older than 24 hours and creates a new one if needed, ensuring all users have recent backups regardless of usage patterns. 3. Backfill failure notification - switch now returns SwitchResult with warnings instead of silently ignoring backfill errors, so users are informed when their manual config changes may not have been saved. 4. Backup management UI - new BackupListSection in Settings > Data Management showing all backup snapshots with restore capability, including a confirmation dialog and automatic safety backup before restore.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
export type { AppId } from "./types";
|
||||
export { providersApi, universalProvidersApi } from "./providers";
|
||||
export { settingsApi } from "./settings";
|
||||
export { backupsApi } from "./settings";
|
||||
export { mcpApi } from "./mcp";
|
||||
export { promptsApi } from "./prompts";
|
||||
export { skillsApi } from "./skills";
|
||||
|
||||
@@ -17,6 +17,10 @@ export interface ProviderSwitchEvent {
|
||||
providerId: string;
|
||||
}
|
||||
|
||||
export interface SwitchResult {
|
||||
warnings: string[];
|
||||
}
|
||||
|
||||
export const providersApi = {
|
||||
async getAll(appId: AppId): Promise<Record<string, Provider>> {
|
||||
return await invoke("get_providers", { app: appId });
|
||||
@@ -46,7 +50,7 @@ export const providersApi = {
|
||||
return await invoke("remove_provider_from_live_config", { id, app: appId });
|
||||
},
|
||||
|
||||
async switch(id: string, appId: AppId): Promise<boolean> {
|
||||
async switch(id: string, appId: AppId): Promise<SwitchResult> {
|
||||
return await invoke("switch_provider", { id, app: appId });
|
||||
},
|
||||
|
||||
|
||||
@@ -215,3 +215,19 @@ export interface LogConfig {
|
||||
enabled: boolean;
|
||||
level: "error" | "warn" | "info" | "debug" | "trace";
|
||||
}
|
||||
|
||||
export interface BackupEntry {
|
||||
filename: string;
|
||||
sizeBytes: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export const backupsApi = {
|
||||
async listDbBackups(): Promise<BackupEntry[]> {
|
||||
return await invoke("list_db_backups");
|
||||
},
|
||||
|
||||
async restoreDbBackup(filename: string): Promise<string> {
|
||||
return await invoke("restore_db_backup", { filename });
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import { providersApi, settingsApi, type AppId } from "@/lib/api";
|
||||
import type { SwitchResult } from "@/lib/api/providers";
|
||||
import type { Provider, Settings } from "@/types";
|
||||
import { extractErrorMessage } from "@/utils/errorUtils";
|
||||
import { generateUUID } from "@/utils/uuid";
|
||||
@@ -171,7 +172,7 @@ export const useSwitchProviderMutation = (appId: AppId) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (providerId: string) => {
|
||||
mutationFn: async (providerId: string): Promise<SwitchResult> => {
|
||||
return await providersApi.switch(providerId, appId);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
|
||||
Reference in New Issue
Block a user