mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 11:34:45 +00:00
delete realm file if schemas are incompatible
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
1abd3c1a78
commit
cf03088a51
@ -22,21 +22,36 @@
|
|||||||
(when (cljs.core/exists? js/window)
|
(when (cljs.core/exists? js/window)
|
||||||
(rn-dependencies/realm. (clj->js options)))))
|
(rn-dependencies/realm. (clj->js options)))))
|
||||||
|
|
||||||
|
(defn delete-realm
|
||||||
|
[file-name]
|
||||||
|
(.deleteFile rn-dependencies/realm (clj->js {:path file-name})))
|
||||||
|
|
||||||
(defn close [realm]
|
(defn close [realm]
|
||||||
(when realm
|
(when realm
|
||||||
(.close realm)))
|
(.close realm)))
|
||||||
|
|
||||||
(defn migrate [file-name schemas]
|
(defn migrate-realm [file-name schemas]
|
||||||
(let [current-version (realm-version file-name)]
|
(let [current-version (realm-version file-name)]
|
||||||
(doseq [schema schemas
|
(doseq [schema schemas
|
||||||
:when (> (:schemaVersion schema) current-version)
|
:when (> (:schemaVersion schema) current-version)
|
||||||
:let [migrated-realm (open-realm schema file-name)]]
|
:let [migrated-realm (open-realm schema file-name)]]
|
||||||
(close migrated-realm))))
|
(close migrated-realm)))
|
||||||
|
(open-realm (last schemas) file-name))
|
||||||
|
|
||||||
|
(defn reset-realm [file-name schemas]
|
||||||
|
(delete-realm file-name)
|
||||||
|
(open-realm (last schemas) file-name))
|
||||||
|
|
||||||
(defn open-migrated-realm
|
(defn open-migrated-realm
|
||||||
[file-name schemas]
|
[file-name schemas]
|
||||||
(migrate file-name schemas)
|
;; TODO: remove for release 0.9.18
|
||||||
(open-realm (last schemas) file-name))
|
;; delete the realm file if its schema version is higher
|
||||||
|
;; than existing schema version (this means the previous
|
||||||
|
;; install has incompatible database schemas)
|
||||||
|
(if (> (realm-version file-name)
|
||||||
|
(apply max (map :schemaVersion base/schemas)))
|
||||||
|
(reset-realm file-name schemas)
|
||||||
|
(migrate-realm file-name schemas)))
|
||||||
|
|
||||||
(def new-account-filename "new-account")
|
(def new-account-filename "new-account")
|
||||||
|
|
||||||
@ -105,8 +120,8 @@
|
|||||||
[message]
|
[message]
|
||||||
(let [walk-fn (fn [e]
|
(let [walk-fn (fn [e]
|
||||||
(cond->> e
|
(cond->> e
|
||||||
(to-be-escaped? e)
|
(to-be-escaped? e)
|
||||||
(str transit-escape-char)))]
|
(str transit-escape-char)))]
|
||||||
(walk/postwalk walk-fn message)))
|
(walk/postwalk walk-fn message)))
|
||||||
|
|
||||||
(defn create
|
(defn create
|
||||||
|
Loading…
x
Reference in New Issue
Block a user