From 6ca3933b71b3d84ac3a39d3a40c3aa81fafbac24 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 22 Nov 2018 19:46:52 +0200 Subject: [PATCH] fix user-statuses after migration from #6722 --- .../realm/schemas/account/core.cljs | 5 ++++- .../realm/schemas/account/migrations.cljs | 20 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/status_im/data_store/realm/schemas/account/core.cljs b/src/status_im/data_store/realm/schemas/account/core.cljs index cfad6b5a3a..233aad42eb 100644 --- a/src/status_im/data_store/realm/schemas/account/core.cljs +++ b/src/status_im/data_store/realm/schemas/account/core.cljs @@ -340,4 +340,7 @@ :migration migrations/v24} {:schema v25 :schemaVersion 25 - :migration migrations/v25}]) + :migration migrations/v25} + {:schema v25 + :schemaVersion 26 + :migration migrations/v26}]) diff --git a/src/status_im/data_store/realm/schemas/account/migrations.cljs b/src/status_im/data_store/realm/schemas/account/migrations.cljs index 6fc8c12bde..977b85e307 100644 --- a/src/status_im/data_store/realm/schemas/account/migrations.cljs +++ b/src/status_im/data_store/realm/schemas/account/migrations.cljs @@ -203,8 +203,8 @@ (let [user-status (aget user-statuses i) message-id (aget user-status "message-id") new-message-id (get @old-ids->new-ids message-id) - whisper-id (aget user-status "whisper-identity") - new-status-id (str new-message-id "-" whisper-id)] + public-key (aget user-status "public-key") + new-status-id (str new-message-id "-" public-key)] (if (contains? @updated-message-statuses-ids new-status-id) (vswap! statuses-to-be-deleted conj user-status) (do @@ -214,3 +214,19 @@ (doseq [status @statuses-to-be-deleted] (.delete new-realm status)))) + +(defn v26 [old-realm new-realm] + (let [user-statuses (.objects new-realm "user-status")] + (dotimes [i (.-length user-statuses)] + (let [user-status (aget user-statuses i) + status-id (aget user-status "message-id") + message-id (aget user-status "message-id") + public-key (aget user-status "public-key") + new-status-id (str message-id "-" public-key)] + (when (and (= "-" (last status-id))) + (if (.objectForPrimaryKey + new-realm + "user-status" + new-status-id) + (.delete new-realm user-status) + (aset user-status "status-id" new-status-id)))))))