migrations for command-requests and commands wit nil :bot
This commit is contained in:
parent
1e9ed89a7f
commit
21a80d71ad
|
@ -16,7 +16,8 @@
|
||||||
[status-im.data-store.realm.schemas.account.v5.group-contact :as group-contact]
|
[status-im.data-store.realm.schemas.account.v5.group-contact :as group-contact]
|
||||||
[status-im.data-store.realm.schemas.account.v8.local-storage :as local-storage]
|
[status-im.data-store.realm.schemas.account.v8.local-storage :as local-storage]
|
||||||
[status-im.data-store.realm.schemas.account.v13.handler-data :as handler-data]
|
[status-im.data-store.realm.schemas.account.v13.handler-data :as handler-data]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]
|
||||||
|
[cljs.reader :as reader]))
|
||||||
|
|
||||||
(def schema [chat/schema
|
(def schema [chat/schema
|
||||||
chat-contact/schema
|
chat-contact/schema
|
||||||
|
@ -36,15 +37,34 @@
|
||||||
local-storage/schema
|
local-storage/schema
|
||||||
handler-data/schema])
|
handler-data/schema])
|
||||||
|
|
||||||
|
(defn chat-by-id [realm chat-id]
|
||||||
|
(some-> realm
|
||||||
|
(.objects "chat")
|
||||||
|
(.filtered (str "chat-id = \"" chat-id "\""))
|
||||||
|
(aget 0)))
|
||||||
|
|
||||||
|
(defn migrate-commands [realm content-type]
|
||||||
|
(some-> realm
|
||||||
|
(.objects "message")
|
||||||
|
(.filtered (str "content-type = \"" content-type "\""))
|
||||||
|
(.map (fn [object _ _]
|
||||||
|
(let [group-id (aget object "group-id")
|
||||||
|
{:keys [bot] :as content} (reader/read-string (aget object "content"))]
|
||||||
|
(when-not bot
|
||||||
|
(let [chat-id (aget object "chat-id")
|
||||||
|
chat (chat-by-id realm chat-id)
|
||||||
|
group? (aget chat "group-chat")
|
||||||
|
bot-name (if group?
|
||||||
|
"transactor-group"
|
||||||
|
"transactor-personal")
|
||||||
|
content' (assoc content :bot bot-name)]
|
||||||
|
(aset object "content" (pr-str content')))))))))
|
||||||
|
|
||||||
(defn migration [old-realm new-realm]
|
(defn migration [old-realm new-realm]
|
||||||
(log/debug "migrating v16 account database: " old-realm new-realm)
|
(log/debug "migrating v16 account database: " old-realm new-realm)
|
||||||
(when-let [wallet-chat (some-> new-realm
|
(when-let [wallet-chat (chat-by-id new-realm "wallet")]
|
||||||
(.objects "chat")
|
|
||||||
(.filtered "chat-id = \"wallet\"")
|
|
||||||
(aget 0))]
|
|
||||||
(.delete new-realm wallet-chat))
|
(.delete new-realm wallet-chat))
|
||||||
(when-let [wallet-contact (some-> new-realm
|
(when-let [wallet-contact (chat-by-id new-realm "wallet")]
|
||||||
(.objects "contact")
|
(.delete new-realm wallet-contact))
|
||||||
(.filtered "whisper-identity = \"wallet\"")
|
(migrate-commands new-realm "command-request")
|
||||||
(aget 0))]
|
(migrate-commands new-realm "command"))
|
||||||
(.delete new-realm wallet-contact)))
|
|
||||||
|
|
|
@ -156,7 +156,7 @@
|
||||||
"Removes duplicates by [jail path] keys, remains the last one."
|
"Removes duplicates by [jail path] keys, remains the last one."
|
||||||
[[all-keys calls] {:keys [jail-id path] :as call}]
|
[[all-keys calls] {:keys [jail-id path] :as call}]
|
||||||
(if (and (contains? all-keys [jail-id path])
|
(if (and (contains? all-keys [jail-id path])
|
||||||
(not= (second path) :subscription))
|
(not (#{:subscription :preview} (last path))))
|
||||||
[all-keys calls]
|
[all-keys calls]
|
||||||
[(conj all-keys [jail-id path])
|
[(conj all-keys [jail-id path])
|
||||||
(conj calls call)]))
|
(conj calls call)]))
|
||||||
|
|
Loading…
Reference in New Issue