mirror of
https://github.com/penpot/penpot.git
synced 2025-08-06 14:48:28 +02:00
📎 Add missing changes on lost-colors fix script
This commit is contained in:
parent
207974fe6c
commit
26239a15f2
1 changed files with 40 additions and 23 deletions
|
@ -23,7 +23,7 @@
|
||||||
AND label IS NOT NULL
|
AND label IS NOT NULL
|
||||||
AND data IS NOT NULL
|
AND data IS NOT NULL
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT 1")
|
LIMIT 2")
|
||||||
|
|
||||||
(defn get-affected-migration
|
(defn get-affected-migration
|
||||||
[conn file-id]
|
[conn file-id]
|
||||||
|
@ -33,11 +33,12 @@
|
||||||
|
|
||||||
(defn get-last-valid-snapshot
|
(defn get-last-valid-snapshot
|
||||||
[conn migration]
|
[conn migration]
|
||||||
(when-let [snapshot (db/exec-one! conn [sql:get-matching-snapshot
|
(let [[snapshot] (db/exec! conn [sql:get-matching-snapshot
|
||||||
(:file-id migration)
|
(:file-id migration)
|
||||||
(:created-at migration)])]
|
(:created-at migration)])]
|
||||||
(let [snapshot (assoc snapshot :id (:file-id snapshot))]
|
(when snapshot
|
||||||
(bfc/decode-file h/*system* snapshot))))
|
(let [snapshot (assoc snapshot :id (:file-id snapshot))]
|
||||||
|
(bfc/decode-file h/*system* snapshot)))))
|
||||||
|
|
||||||
(defn restore-color
|
(defn restore-color
|
||||||
[{:keys [data] :as snapshot} color]
|
[{:keys [data] :as snapshot} color]
|
||||||
|
@ -47,25 +48,41 @@
|
||||||
|
|
||||||
(defn restore-missing-colors
|
(defn restore-missing-colors
|
||||||
[{:keys [id] :as file} & _opts]
|
[{:keys [id] :as file} & _opts]
|
||||||
(when-let [colors (-> file :data :colors not-empty)]
|
(l/inf :hint "process file" :file-id (str id) :name (:name file) :has-colors (-> file :data :colors not-empty boolean))
|
||||||
(when-let [migration (get-affected-migration h/*system* id)]
|
(if-let [colors (-> file :data :colors not-empty)]
|
||||||
(when-let [snapshot (get-last-valid-snapshot h/*system* migration)]
|
(let [migration (get-affected-migration h/*system* id)]
|
||||||
(let [colors (reduce-kv (fn [colors color-id color]
|
(if-let [snapshot (get-last-valid-snapshot h/*system* migration)]
|
||||||
(if-let [result (restore-color snapshot color)]
|
(do
|
||||||
(do
|
(l/inf :hint "using snapshot" :snapshot (:label snapshot))
|
||||||
(l/inf :hint "restored color" :file-id (str id) :color-id (str color-id))
|
(let [colors (reduce-kv (fn [colors color-id color]
|
||||||
(assoc colors color-id result))
|
(if-let [result (restore-color snapshot color)]
|
||||||
(do
|
(do
|
||||||
(l/wrn :hint "ignoring color" :file-id (str id) :color (pr-str color))
|
(l/inf :hint "restored color" :file-id (str id) :color-id (str color-id))
|
||||||
colors)))
|
(assoc colors color-id result))
|
||||||
colors
|
(do
|
||||||
colors)
|
(l/wrn :hint "ignoring color" :file-id (str id) :color (pr-str color))
|
||||||
file (-> file
|
colors)))
|
||||||
(update :data assoc :colors colors)
|
colors
|
||||||
(update :migrations disj "0008-fix-library-colors-v2"))]
|
colors)
|
||||||
|
file (-> file
|
||||||
|
(update :data assoc :colors colors)
|
||||||
|
(update :migrations disj "0008-fix-library-colors-v2"))]
|
||||||
|
|
||||||
|
(db/delete! h/*system* :file-migration
|
||||||
|
{:name "0008-fix-library-colors-v2"
|
||||||
|
:file-id (:id file)})
|
||||||
|
file))
|
||||||
|
|
||||||
|
(do
|
||||||
(db/delete! h/*system* :file-migration
|
(db/delete! h/*system* :file-migration
|
||||||
{:name "0008-fix-library-colors-v2"
|
{:name "0008-fix-library-colors-v2"
|
||||||
:file-id (:id file)})
|
:file-id (:id file)})
|
||||||
|
nil)))
|
||||||
|
|
||||||
|
(do
|
||||||
|
(db/delete! h/*system* :file-migration
|
||||||
|
{:name "0008-fix-library-colors-v2"
|
||||||
|
:file-id (:id file)})
|
||||||
|
nil)))
|
||||||
|
|
||||||
|
|
||||||
file)))))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue