From f63f4856bffbe0da602f7f177da29dd686686b7e Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Sun, 31 Aug 2025 05:28:39 +0000 Subject: [PATCH] feat(migration): complete Step 2 of ActiveDid migration - implement dual-write pattern - Add database persistence to $updateActiveDid() method - Implement dual-write to both active_identity and settings tables - Add error handling with graceful fallback to in-memory updates - Include debug logging for migration monitoring --- src/utils/PlatformServiceMixin.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index 7cee0ea2..641912f7 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -212,6 +212,27 @@ export const PlatformServiceMixin = { logger.debug( `[PlatformServiceMixin] ActiveDid updated from ${oldDid} to ${newDid}`, ); + + // Dual-write to both tables for backward compatibility + try { + await this.$dbExec( + "UPDATE active_identity SET activeDid = ?, lastUpdated = datetime('now') WHERE id = 1", + [newDid || ""], + ); + await this.$dbExec("UPDATE settings SET activeDid = ? WHERE id = 1", [ + newDid || "", + ]); + logger.debug( + `[PlatformServiceMixin] ActiveDid dual-write completed for ${newDid}`, + ); + } catch (error) { + logger.error( + `[PlatformServiceMixin] Error in dual-write for activeDid ${newDid}:`, + error, + ); + // Continue with in-memory update even if database write fails + } + // // Clear caches that might be affected by the change // this.$clearAllCaches(); }