diff --git a/src/renderer/src/store/index.ts b/src/renderer/src/store/index.ts index cf6a7dbf..7b8f039e 100644 --- a/src/renderer/src/store/index.ts +++ b/src/renderer/src/store/index.ts @@ -22,7 +22,7 @@ const persistedReducer = persistReducer( { key: 'cherry-studio', storage, - version: 33, + version: 34, blacklist: ['runtime'], migrate }, diff --git a/src/renderer/src/store/migrate.ts b/src/renderer/src/store/migrate.ts index bc1b1939..39a83752 100644 --- a/src/renderer/src/store/migrate.ts +++ b/src/renderer/src/store/migrate.ts @@ -1,7 +1,8 @@ import { SYSTEM_MODELS } from '@renderer/config/models' +import db from '@renderer/databases' import i18n from '@renderer/i18n' import { Assistant } from '@renderer/types' -import { uuid } from '@renderer/utils' +import { runAsyncFunction, uuid } from '@renderer/utils' import { isEmpty } from 'lodash' import { createMigrate } from 'redux-persist' @@ -594,6 +595,21 @@ const migrateConfig = { }) } } + }, + '34': (state: RootState) => { + state.assistants.assistants.forEach((assistant) => { + assistant.topics.forEach((topic) => { + topic.assistantId = assistant.id + runAsyncFunction(async () => { + const _topic = await db.topics.get(topic.id) + if (_topic) { + const messages = (_topic?.messages || []).map((message) => ({ ...message, assistantId: assistant.id })) + db.topics.put({ ..._topic, messages }, topic.id) + } + }) + }) + }) + return state } }