From 2e82f5da4997e938d305f619d9fc447a3bc3b762 Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Sat, 25 Nov 2023 23:11:09 +0100
Subject: [PATCH] fix migrate identity to non-existing account

and identity name on creation
---
 src/main.ts | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main.ts b/src/main.ts
index 244aa29..c923822 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -348,6 +348,7 @@ async function createIdentities(ctx: ProcessorContext<StoreWithCache>, newData:
     let newI = new Identity({
       id: String(i.index),
       index: i.index,
+      name: i.id, // identities created but not confirmed have no name, we use the id of the creation event
       account,
     });
     data.identities.set(i.index, newI);
@@ -365,7 +366,7 @@ async function confirmIdentities(ctx: ProcessorContext<StoreWithCache>, newData:
 async function changeIdtyOwnerKey(ctx: ProcessorContext<StoreWithCache>, newData: NewData, data: PreparedData) {
   for (let icok of newData.idtyChangedOwnerKey) {
     let idty = await ctx.store.getOrFail(Identity, String(icok.index));
-    let account = await ctx.store.getOrFail(Account, icok.account);
+    let account = data.accounts.get(icok.account) ?? (await ctx.store.getOrFail(Account, icok.account));
     idty.account = account;
     data.identities.set(idty.index, idty);
   }
-- 
GitLab