Skip to content

Commit

Permalink
🗃️ fix: fix db migration
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Apr 10, 2024
1 parent ecd1d25 commit 4e75074
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/database/core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class LocalDB extends Dexie {

upgradeToV8 = async (trans: Transaction) => {
const users = trans.table('users');
users.toCollection().modify((user: DB_User) => {
await users.toCollection().modify((user: DB_User) => {
if (user.settings) {
user.settings = MigrationLLMSettings.migrateSettings(user.settings as any);
}
Expand Down
14 changes: 10 additions & 4 deletions src/migrations/FromV3ToV4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ export class MigrationV3ToV4 implements Migration {
languageModel: {
...res,
azure,
ollama: this.migrateProvider(ollama),
ollama: ollama && this.migrateProvider(ollama),
openai,
openrouter: this.migrateProvider(openrouter),
togetherai: this.migrateProvider(togetherai),
openrouter: openrouter && this.migrateProvider(openrouter),
togetherai: togetherai && this.migrateProvider(togetherai),
},
};
};

static migrateOpenAI = (
openai: V3OpenAIConfig,
openai?: V3OpenAIConfig,
): { azure: V4AzureOpenAIConfig; openai: V4ProviderConfig } => {
if (!openai)
return {
azure: { apiKey: '', enabled: false },
openai: { apiKey: '', enabled: true },
};

if (openai.useAzure) {
return {
azure: {
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/FromV3ToV4/types/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface V3Settings {
defaultAgent: any;
fontSize: number;
language: string;
languageModel: V3LLMConfig;
languageModel?: Partial<V3LLMConfig>;
neutralColor?: string;
password: string;
primaryColor?: string;
Expand Down
10 changes: 5 additions & 5 deletions src/migrations/FromV3ToV4/types/v4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export interface V4AzureOpenAIConfig extends V4ProviderConfig {
}

export interface V4lLLMConfig
extends Omit<V3LLMConfig, 'ollama' | 'openAI' | 'openrouter' | 'togetherai'> {
azure: V4AzureOpenAIConfig;
ollama: V4ProviderConfig;
extends Omit<Partial<V3LLMConfig>, 'ollama' | 'openAI' | 'openrouter' | 'togetherai'> {
azure?: V4AzureOpenAIConfig;
ollama?: V4ProviderConfig;
openai: V4ProviderConfig;
openrouter: V4ProviderConfig;
togetherai: V4ProviderConfig;
openrouter?: V4ProviderConfig;
togetherai?: V4ProviderConfig;
}

/**
Expand Down

0 comments on commit 4e75074

Please sign in to comment.