mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
refactor: update migration types and imports for consistency
- Replaced core types with shared types in migration files to ensure consistency across the application. - Deleted obsolete core types file and updated imports in migrator and window components to reference the new shared types. - Enhanced the migration process by streamlining type definitions and improving code maintainability.
This commit is contained in:
parent
1685590a07
commit
1ea19adfec
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Core type definitions for the migration system
|
||||
* Shared type definitions for the migration system
|
||||
*/
|
||||
|
||||
// Migration stages for UI flow
|
||||
@ -7,11 +7,6 @@ import { dbService } from '@data/db/DbService'
|
||||
import { appStateTable } from '@data/db/schemas/appState'
|
||||
import { preferenceTable } from '@data/db/schemas/preference'
|
||||
import { loggerService } from '@logger'
|
||||
import { eq, sql } from 'drizzle-orm'
|
||||
import fs from 'fs/promises'
|
||||
|
||||
import type { BaseMigrator } from '../migrators/BaseMigrator'
|
||||
import { createMigrationContext } from './MigrationContext'
|
||||
import type {
|
||||
MigrationProgress,
|
||||
MigrationResult,
|
||||
@ -20,7 +15,12 @@ import type {
|
||||
MigratorResult,
|
||||
MigratorStatus,
|
||||
ValidateResult
|
||||
} from './types'
|
||||
} from '@shared/data/migration/v2/types'
|
||||
import { eq, sql } from 'drizzle-orm'
|
||||
import fs from 'fs/promises'
|
||||
|
||||
import type { BaseMigrator } from '../migrators/BaseMigrator'
|
||||
import { createMigrationContext } from './MigrationContext'
|
||||
|
||||
// TODO: Import these tables when they are created in user data schema
|
||||
// import { assistantTable } from '../../db/schemas/assistant'
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// Core
|
||||
export { createMigrationContext, type MigrationContext } from './core/MigrationContext'
|
||||
export { MigrationEngine, migrationEngine } from './core/MigrationEngine'
|
||||
export * from './core/types'
|
||||
export * from '@shared/data/migration/v2/types'
|
||||
|
||||
// Migrators
|
||||
export { getAllMigrators } from './migrators'
|
||||
|
||||
@ -7,8 +7,8 @@
|
||||
*/
|
||||
|
||||
import { loggerService } from '@logger'
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult } from '@shared/data/migration/v2/types'
|
||||
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult } from '../core/types'
|
||||
import { BaseMigrator } from './BaseMigrator'
|
||||
|
||||
const logger = loggerService.withContext('AssistantMigrator')
|
||||
|
||||
@ -3,8 +3,9 @@
|
||||
* Each migrator handles migration of a specific business domain
|
||||
*/
|
||||
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult } from '@shared/data/migration/v2/types'
|
||||
|
||||
import type { MigrationContext } from '../core/MigrationContext'
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult } from '../core/types'
|
||||
|
||||
export abstract class BaseMigrator {
|
||||
// Metadata - must be implemented by subclasses
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
*/
|
||||
|
||||
import { loggerService } from '@logger'
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult } from '@shared/data/migration/v2/types'
|
||||
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult } from '../core/types'
|
||||
import { BaseMigrator } from './BaseMigrator'
|
||||
|
||||
const logger = loggerService.withContext('ChatMigrator')
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
*/
|
||||
|
||||
import { loggerService } from '@logger'
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult } from '@shared/data/migration/v2/types'
|
||||
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult } from '../core/types'
|
||||
import { BaseMigrator } from './BaseMigrator'
|
||||
|
||||
const logger = loggerService.withContext('KnowledgeMigrator')
|
||||
|
||||
@ -5,11 +5,11 @@
|
||||
import { preferenceTable } from '@data/db/schemas/preference'
|
||||
import { loggerService } from '@logger'
|
||||
import { configManager } from '@main/services/ConfigManager'
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult, ValidationError } from '@shared/data/migration/v2/types'
|
||||
import { DefaultPreferences } from '@shared/data/preference/preferenceSchemas'
|
||||
import { and, eq, sql } from 'drizzle-orm'
|
||||
|
||||
import type { MigrationContext } from '../core/MigrationContext'
|
||||
import type { ExecuteResult, PrepareResult, ValidateResult, ValidationError } from '../core/types'
|
||||
import { BaseMigrator } from './BaseMigrator'
|
||||
import { ELECTRON_STORE_MAPPINGS, REDUX_STORE_MAPPINGS } from './mappings/PreferencesMappings'
|
||||
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
import { loggerService } from '@logger'
|
||||
import BackupManager from '@main/services/BackupManager'
|
||||
import { MigrationIpcChannels, type MigrationProgress } from '@shared/data/migration/v2/types'
|
||||
import { app, dialog, ipcMain } from 'electron'
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
|
||||
import { migrationEngine } from '../core/MigrationEngine'
|
||||
import { MigrationIpcChannels, type MigrationProgress } from '../core/types'
|
||||
import { migrationWindowManager } from './MigrationWindowManager'
|
||||
|
||||
const logger = loggerService.withContext('MigrationIpcHandler')
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { Button, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@cherrystudio/ui'
|
||||
import { AppLogo } from '@renderer/config/env'
|
||||
import { loggerService } from '@renderer/services/LoggerService'
|
||||
import { MigrationIpcChannels } from '@shared/data/migration/v2/types'
|
||||
import { Progress, Space, Steps } from 'antd'
|
||||
import { AlertTriangle, CheckCircle, CheckCircle2, Database, Loader2, Rocket } from 'lucide-react'
|
||||
import React, { useMemo, useState } from 'react'
|
||||
@ -10,7 +11,6 @@ import styled from 'styled-components'
|
||||
import { MigratorProgressList } from './components'
|
||||
import { DexieExporter, ReduxExporter } from './exporters'
|
||||
import { useMigrationActions, useMigrationProgress } from './hooks/useMigrationProgress'
|
||||
import { MigrationIpcChannels } from './types'
|
||||
|
||||
const logger = loggerService.withContext('MigrationApp')
|
||||
|
||||
|
||||
@ -3,10 +3,9 @@
|
||||
*/
|
||||
|
||||
import { Button } from '@cherrystudio/ui'
|
||||
import type { MigrationStage } from '@shared/data/migration/v2/types'
|
||||
import React from 'react'
|
||||
|
||||
import type { MigrationStage } from '../types'
|
||||
|
||||
interface Props {
|
||||
stage: MigrationStage
|
||||
onProceedToBackup: () => void
|
||||
|
||||
@ -3,13 +3,12 @@
|
||||
* Shows the status of each migrator
|
||||
*/
|
||||
|
||||
import type { MigratorProgress as MigratorProgressType, MigratorStatus } from '@shared/data/migration/v2/types'
|
||||
import { CheckCircle2, Circle, Loader2, XCircle } from 'lucide-react'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import styled, { keyframes } from 'styled-components'
|
||||
|
||||
import type { MigratorProgress as MigratorProgressType, MigratorStatus } from '../types'
|
||||
|
||||
interface Props {
|
||||
migrators: MigratorProgressType[]
|
||||
overallProgress: number
|
||||
|
||||
@ -3,11 +3,10 @@
|
||||
* Shows the current migration stage in a stepper format
|
||||
*/
|
||||
|
||||
import type { MigrationStage } from '@shared/data/migration/v2/types'
|
||||
import { CheckCircle2, Database, FileArchive, Rocket } from 'lucide-react'
|
||||
import React from 'react'
|
||||
|
||||
import type { MigrationStage } from '../types'
|
||||
|
||||
interface Props {
|
||||
stage: MigrationStage
|
||||
}
|
||||
|
||||
@ -2,10 +2,14 @@
|
||||
* Hook for subscribing to migration progress updates
|
||||
*/
|
||||
|
||||
import {
|
||||
MigrationIpcChannels,
|
||||
type MigrationProgress,
|
||||
type MigrationStage,
|
||||
type MigratorStatus
|
||||
} from '@shared/data/migration/v2/types'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import { MigrationIpcChannels, type MigrationProgress, type MigrationStage, type MigratorStatus } from '../types'
|
||||
|
||||
// Re-export types for convenience
|
||||
export type { MigrationProgress, MigrationStage, MigratorStatus }
|
||||
|
||||
|
||||
@ -33,8 +33,7 @@ export const zhCN = {
|
||||
},
|
||||
introduction: {
|
||||
title: '将数据迁移到新的架构中',
|
||||
description_1:
|
||||
'Cherry Studio对数据的存储和使用方式进行了重大重构,在新的架构下,效率和安全性将会得到极大提升。',
|
||||
description_1: 'Cherry Studio对数据的存储和使用方式进行了重大重构,在新的架构下,效率和安全性将会得到极大提升。',
|
||||
description_2: '数据必须进行迁移,才能在新版本中使用。',
|
||||
description_3: '我们会指导你完成迁移,迁移过程不会损坏原来的数据,你随时可以取消迁移,并继续使用旧版本。'
|
||||
},
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* Migration types for Renderer process
|
||||
* Duplicated from Main to avoid cross-process imports
|
||||
*/
|
||||
|
||||
export type MigrationStage =
|
||||
| 'introduction'
|
||||
| 'backup_required'
|
||||
| 'backup_progress'
|
||||
| 'backup_confirmed'
|
||||
| 'migration'
|
||||
| 'migration_completed'
|
||||
| 'completed'
|
||||
| 'error'
|
||||
|
||||
export type MigratorStatus = 'pending' | 'running' | 'completed' | 'failed'
|
||||
|
||||
export interface MigratorProgress {
|
||||
id: string
|
||||
name: string
|
||||
status: MigratorStatus
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface MigrationProgress {
|
||||
stage: MigrationStage
|
||||
overallProgress: number
|
||||
currentMessage: string
|
||||
migrators: MigratorProgress[]
|
||||
error?: string
|
||||
}
|
||||
|
||||
// IPC channel names
|
||||
export const MigrationIpcChannels = {
|
||||
CheckNeeded: 'migration:check-needed',
|
||||
GetProgress: 'migration:get-progress',
|
||||
GetLastError: 'migration:get-last-error',
|
||||
GetUserDataPath: 'migration:get-user-data-path',
|
||||
Start: 'migration:start',
|
||||
ProceedToBackup: 'migration:proceed-to-backup',
|
||||
ShowBackupDialog: 'migration:show-backup-dialog',
|
||||
BackupCompleted: 'migration:backup-completed',
|
||||
StartMigration: 'migration:start-migration',
|
||||
Retry: 'migration:retry',
|
||||
Cancel: 'migration:cancel',
|
||||
Restart: 'migration:restart',
|
||||
SendReduxData: 'migration:send-redux-data',
|
||||
DexieExportCompleted: 'migration:dexie-export-completed',
|
||||
Progress: 'migration:progress',
|
||||
ExportProgress: 'migration:export-progress'
|
||||
} as const
|
||||
Loading…
Reference in New Issue
Block a user