diff --git a/src/database/core/db.ts b/src/database/core/db.ts index 7aa4a3ffe940..dd2909e172e0 100644 --- a/src/database/core/db.ts +++ b/src/database/core/db.ts @@ -7,6 +7,7 @@ import { DB_Session } from '@/database/schemas/session'; import { DB_SessionGroup } from '@/database/schemas/sessionGroup'; import { DB_Topic } from '@/database/schemas/topic'; import { DB_User } from '@/database/schemas/user'; +import { MigrationLLMSettings } from '@/migrations/FromV3ToV4'; import { uuid } from '@/utils/uuid'; import { migrateSettingsToUser } from './migrations/migrateSettingsToUser'; @@ -62,6 +63,10 @@ export class LocalDB extends Dexie { .stores(dbSchemaV7) .upgrade((trans) => this.upgradeToV7(trans)); + this.version(8) + .stores(dbSchemaV7) + .upgrade((trans) => this.upgradeToV8(trans)); + this.files = this.table('files'); this.sessions = this.table('sessions'); this.messages = this.table('messages'); @@ -139,6 +144,13 @@ export class LocalDB extends Dexie { plugin.id = plugin.identifier; }); }; + + upgradeToV8 = async (trans: Transaction) => { + const users = trans.table('users'); + users.toCollection().modify((user: DB_User) => { + user.settings = MigrationLLMSettings.migrateSettings(user.settings as any); + }); + }; } export const LocalDBInstance = new LocalDB(); diff --git a/src/database/schemas/user.ts b/src/database/schemas/user.ts index 378007bcaa96..f37f27db4b57 100644 --- a/src/database/schemas/user.ts +++ b/src/database/schemas/user.ts @@ -3,21 +3,6 @@ import { z } from 'zod'; import { AgentSchema } from '@/database/schemas/session'; import { LobeMetaDataSchema } from '@/types/meta'; -const modelProviderSchema = z.object({ - openai: z.object({ - OPENAI_API_KEY: z.string().optional(), - azureApiVersion: z.string().optional(), - customModelName: z.string().optional(), - endpoint: z.string().optional(), - models: z.array(z.string()).optional(), - useAzure: z.boolean().optional(), - }), - // zhipu: z.object({ - // ZHIPU_API_KEY: z.string().optional(), - // enabled: z.boolean().default(false), - // }), -}); - const settingsSchema = z.object({ defaultAgent: z.object({ config: AgentSchema, @@ -25,7 +10,7 @@ const settingsSchema = z.object({ }), fontSize: z.number().default(14), language: z.string(), - languageModel: modelProviderSchema.partial(), + languageModel: z.any().optional(), password: z.string(), themeMode: z.string(), tts: z.object({ @@ -38,19 +23,10 @@ const settingsSchema = z.object({ }), }); -// const patchSchema = z.array( -// z.object({ -// op: z.string(), -// path: z.string(), -// value: z.any(), -// }), -// ); - export const DB_UserSchema = z.object({ avatar: z.string().optional(), settings: settingsSchema.partial(), uuid: z.string(), - // settings: patchSchema, }); export type DB_User = z.infer; diff --git a/src/migrations/FromV3ToV4/index.ts b/src/migrations/FromV3ToV4/index.ts index c8cd3a1c2ba0..ebc0a475ec26 100644 --- a/src/migrations/FromV3ToV4/index.ts +++ b/src/migrations/FromV3ToV4/index.ts @@ -84,3 +84,5 @@ export class MigrationV3ToV4 implements Migration { }; }; } + +export const MigrationLLMSettings = MigrationV3ToV4;