From 0cf5cf266d7c65492e7bf75cc33edb80626b5b72 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Fri, 20 Jun 2025 06:26:56 -0600 Subject: [PATCH] IndexedDB migration: don't run activeDid migration twice, include warnings in output, don't automatically compare afterward --- src/services/indexedDBMigrationService.ts | 54 +---------------------- src/views/DatabaseMigration.vue | 35 ++++++++++++--- 2 files changed, 30 insertions(+), 59 deletions(-) diff --git a/src/services/indexedDBMigrationService.ts b/src/services/indexedDBMigrationService.ts index 2cf4441d..27688fcb 100644 --- a/src/services/indexedDBMigrationService.ts +++ b/src/services/indexedDBMigrationService.ts @@ -1081,17 +1081,6 @@ export async function migrateSettings(): Promise { }); const platformService = PlatformServiceFactory.getInstance(); - // Find the master settings (accountDid is null) which contains the activeDid - const masterSettings = dexieSettings.find(setting => !setting.accountDid); - let dexieActiveDid: string | undefined; - - if (masterSettings?.activeDid) { - dexieActiveDid = masterSettings.activeDid; - logger.info("[MigrationService] Found activeDid in Dexie master settings", { - activeDid: dexieActiveDid, - }); - } - // Create an array of promises for all settings migrations const migrationPromises = dexieSettings.map(async (setting) => { logger.info("[MigrationService] Starting to migrate settings", setting); @@ -1152,36 +1141,7 @@ export async function migrateSettings(): Promise { const updatedSettings = await Promise.all(migrationPromises); // Step 2: Migrate the activeDid if it exists in Dexie - if (dexieActiveDid) { - try { - // Verify that the activeDid exists in SQLite accounts - const accountExists = await platformService.dbQuery( - "SELECT did FROM accounts WHERE did = ?", - [dexieActiveDid], - ); - - if (accountExists?.values?.length) { - // Update the master settings with the activeDid - await updateDefaultSettings({ activeDid: dexieActiveDid }); - logger.info("[MigrationService] Successfully migrated activeDid", { - activeDid: dexieActiveDid, - }); - result.warnings.push(`Migrated activeDid: ${dexieActiveDid}`); - } else { - logger.warn("[MigrationService] activeDid from Dexie not found in SQLite accounts", { - activeDid: dexieActiveDid, - }); - result.warnings.push( - `activeDid from Dexie (${dexieActiveDid}) not found in SQLite accounts - skipping activeDid migration`, - ); - } - } catch (error) { - logger.error("[MigrationService] Failed to migrate activeDid:", error); - result.errors.push(`Failed to migrate activeDid: ${error}`); - } - } else { - logger.info("[MigrationService] No activeDid found in Dexie settings"); - } + await migrateActiveDid(); logger.info( "[MigrationService] Finished migrating settings", @@ -1467,18 +1427,6 @@ export async function migrateAll(): Promise { result.settingsMigrated = settingsResult.settingsMigrated; result.warnings.push(...settingsResult.warnings); - // Step 3: Migrate ActiveDid (depends on accounts and settings) - logger.info("[MigrationService] Step 3: Migrating activeDid..."); - const activeDidResult = await migrateActiveDid(); - if (!activeDidResult.success) { - result.errors.push( - `ActiveDid migration failed: ${activeDidResult.errors.join(", ")}`, - ); - // Don't fail the entire migration for activeDid issues - logger.warn("[MigrationService] ActiveDid migration failed, but continuing with migration"); - } - result.warnings.push(...activeDidResult.warnings); - // Step 4: Migrate Contacts (independent, but after accounts for consistency) // ... but which is better done through the contact import view // logger.info("[MigrationService] Step 4: Migrating contacts..."); diff --git a/src/views/DatabaseMigration.vue b/src/views/DatabaseMigration.vue index d5b6ecd8..a0efcb06 100644 --- a/src/views/DatabaseMigration.vue +++ b/src/views/DatabaseMigration.vue @@ -200,6 +200,28 @@ + +
+
+
+ +
+
+

Warning

+
+

{{ warning }}

+
+
+
+
+
| null = null; private successMessage = ""; @@ -1248,6 +1271,7 @@ export default class DatabaseMigration extends Vue { this.successMessage = `Successfully migrated ${totalMigrated} total records: ${result.accountsMigrated} accounts, ${result.settingsMigrated} settings, ${result.contactsMigrated} contacts.`; if (result.warnings.length > 0) { this.successMessage += ` ${result.warnings.length} warnings.`; + this.warning += result.warnings.join(", "); } this.successMessage += " Now finish by migrating contacts."; logger.info( @@ -1255,8 +1279,7 @@ export default class DatabaseMigration extends Vue { result, ); - // Refresh comparison data after successful migration - this.comparison = await compareDatabases(); + this.comparison = null; } else { this.error = `Migration failed: ${result.errors.join(", ")}`; logger.error( @@ -1342,14 +1365,14 @@ export default class DatabaseMigration extends Vue { this.successMessage = `Successfully migrated ${result.settingsMigrated} settings.`; if (result.warnings.length > 0) { this.successMessage += ` ${result.warnings.length} warnings.`; + this.warning += result.warnings.join(", "); } logger.info( "[DatabaseMigration] Settings migration completed successfully", result, ); - // Refresh comparison data after successful migration - this.comparison = await compareDatabases(); + this.comparison = null; } else { this.error = `Migration failed: ${result.errors.join(", ")}`; logger.error( @@ -1385,14 +1408,14 @@ export default class DatabaseMigration extends Vue { this.successMessage = `Successfully migrated ${result.accountsMigrated} accounts.`; if (result.warnings.length > 0) { this.successMessage += ` ${result.warnings.length} warnings.`; + this.warning += result.warnings.join(", "); } logger.info( "[DatabaseMigration] Account migration completed successfully", result, ); - // Refresh comparison data after successful migration - this.comparison = await compareDatabases(); + this.comparison = null; } else { this.error = `Migration failed: ${result.errors.join(", ")}`; logger.error(