Show schema version details on migrations failure
Simplifies debugging of migration failures, specifically in cases when more than one migration is applied.
This commit is contained in:
parent
d299713037
commit
83a8d9db27
|
@ -133,15 +133,25 @@
|
||||||
(when realm
|
(when realm
|
||||||
(.close realm)))
|
(.close realm)))
|
||||||
|
|
||||||
|
(defonce schema-migration-log (atom {}))
|
||||||
|
|
||||||
|
(defn migration-log [k v]
|
||||||
|
(swap! schema-migration-log assoc k v))
|
||||||
|
|
||||||
(defn- migrate-schemas
|
(defn- migrate-schemas
|
||||||
"Apply migrations in sequence and open database with the last schema"
|
"Apply migrations in sequence and open database with the last schema"
|
||||||
[file-name schemas encryption-key current-version]
|
[file-name schemas encryption-key current-version]
|
||||||
|
(reset! schema-migration-log {})
|
||||||
|
(migration-log :initial-version current-version)
|
||||||
|
(migration-log :current-version current-version)
|
||||||
|
(migration-log :last-version (:schemaVersion (last schemas)))
|
||||||
(log/info "migrate schemas" current-version)
|
(log/info "migrate schemas" current-version)
|
||||||
(when (pos? current-version)
|
(when (pos? current-version)
|
||||||
(doseq [schema schemas
|
(doseq [schema schemas
|
||||||
:when (> (:schemaVersion schema) current-version)
|
:when (> (:schemaVersion schema) current-version)]
|
||||||
:let [migrated-realm (open-realm schema file-name encryption-key)]]
|
(migration-log :current-version current-version)
|
||||||
(close migrated-realm)))
|
(let [migrated-realm (open-realm schema file-name encryption-key)]
|
||||||
|
(close migrated-realm))))
|
||||||
(open-realm (last schemas) file-name encryption-key))
|
(open-realm (last schemas) file-name encryption-key))
|
||||||
|
|
||||||
(defn keccak512-array [key]
|
(defn keccak512-array [key]
|
||||||
|
@ -258,7 +268,8 @@
|
||||||
(on-success)
|
(on-success)
|
||||||
(catch :default e
|
(catch :default e
|
||||||
(on-error {:message (str e)
|
(on-error {:message (str e)
|
||||||
:error :migrations-failed})))))))
|
:error :migrations-failed
|
||||||
|
:details @schema-migration-log})))))))
|
||||||
|
|
||||||
(declare realm-obj->clj)
|
(declare realm-obj->clj)
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@
|
||||||
|
|
||||||
(fx/defn handle-change-account-error
|
(fx/defn handle-change-account-error
|
||||||
[{:keys [db]} error]
|
[{:keys [db]} error]
|
||||||
(let [{:keys [error message]}
|
(let [{:keys [error message details]}
|
||||||
(if (map? error)
|
(if (map? error)
|
||||||
error
|
error
|
||||||
{:message (str error)})
|
{:message (str error)})
|
||||||
|
@ -120,8 +120,10 @@
|
||||||
{:title (i18n/label :migrations-failed-title)
|
{:title (i18n/label :migrations-failed-title)
|
||||||
:content (i18n/label
|
:content (i18n/label
|
||||||
:migrations-failed-content
|
:migrations-failed-content
|
||||||
|
(merge
|
||||||
{:message message
|
{:message message
|
||||||
:erase-accounts-data-button-text erase-button-text})
|
:erase-accounts-data-button-text erase-button-text}
|
||||||
|
details))
|
||||||
:confirm-button-text erase-button-text
|
:confirm-button-text erase-button-text
|
||||||
:on-cancel #(re-frame/dispatch [:init.ui/data-reset-cancelled ""])
|
:on-cancel #(re-frame/dispatch [:init.ui/data-reset-cancelled ""])
|
||||||
:on-accept #(re-frame/dispatch [:init.ui/account-data-reset-accepted address])}}
|
:on-accept #(re-frame/dispatch [:init.ui/account-data-reset-accepted address])}}
|
||||||
|
|
|
@ -790,6 +790,6 @@
|
||||||
"to-see-this-message": "To see this message,",
|
"to-see-this-message": "To see this message,",
|
||||||
"install-the-extension": "install the extension",
|
"install-the-extension": "install the extension",
|
||||||
"migrations-failed-title": "Migration failed",
|
"migrations-failed-title": "Migration failed",
|
||||||
"migrations-failed-content": "{{message}}\n\nPlease let us know about this problem at #status public chat. If you press \"Cancel\" button, nothing will happen. If you press \"{{erase-accounts-data-button-text}}\" button, account's db will be removed and you will be able to unlock account. All account's data will be lost.",
|
"migrations-failed-content": "{{message}}\nschema version: initial {{initial-version}}, current {{current-version}}, last {{last-version}}\n\nPlease let us know about this problem at #status public chat. If you press \"Cancel\" button, nothing will happen. If you press \"{{erase-accounts-data-button-text}}\" button, account's db will be removed and you will be able to unlock account. All account's data will be lost.",
|
||||||
"migrations-erase-accounts-data-button": "Erase account's db"
|
"migrations-erase-accounts-data-button": "Erase account's db"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue