mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
✨ Parametrize exception handling behavior of components migration
This commit is contained in:
parent
cfdf7766e3
commit
3eb987897a
1 changed files with 16 additions and 14 deletions
|
@ -659,7 +659,7 @@
|
||||||
(update fdata :options assoc :components-v2 true)))))
|
(update fdata :options assoc :components-v2 true)))))
|
||||||
|
|
||||||
(defn- process-file
|
(defn- process-file
|
||||||
[{:keys [id] :as file} & {:keys [validate?]}]
|
[{:keys [id] :as file} & {:keys [validate? throw-on-validate?]}]
|
||||||
(let [conn (::db/conn *system*)]
|
(let [conn (::db/conn *system*)]
|
||||||
(binding [pmap/*tracked* (atom {})
|
(binding [pmap/*tracked* (atom {})
|
||||||
pmap/*load-fn* (partial files/load-pointer conn id)
|
pmap/*load-fn* (partial files/load-pointer conn id)
|
||||||
|
@ -696,17 +696,18 @@
|
||||||
{:id (:id file)})
|
{:id (:id file)})
|
||||||
|
|
||||||
(when validate?
|
(when validate?
|
||||||
(let [errors (cfv/validate-file file libs)]
|
(if throw-on-validate?
|
||||||
(when (seq errors)
|
(cfv/validate-file! file libs)
|
||||||
|
(doseq [error (cfv/validate-file file libs)]
|
||||||
(l/wrn :hint "migrate:file:validation-error"
|
(l/wrn :hint "migrate:file:validation-error"
|
||||||
:file-id (str (:id file))
|
:file-id (str (:id file))
|
||||||
:file-name (:name file)
|
:file-name (:name file)
|
||||||
:errors errors))))
|
:error error))))
|
||||||
|
|
||||||
(dissoc file :data)))))
|
(dissoc file :data)))))
|
||||||
|
|
||||||
(defn migrate-file!
|
(defn migrate-file!
|
||||||
[system file-id & {:keys [validate?]}]
|
[system file-id & {:keys [validate? throw-on-validate?]}]
|
||||||
|
|
||||||
(let [tpoint (dt/tpoint)
|
(let [tpoint (dt/tpoint)
|
||||||
file-id (if (string? file-id)
|
file-id (if (string? file-id)
|
||||||
|
@ -720,11 +721,11 @@
|
||||||
(db/tx-run! system
|
(db/tx-run! system
|
||||||
(fn [{:keys [::db/conn] :as system}]
|
(fn [{:keys [::db/conn] :as system}]
|
||||||
(binding [*system* system]
|
(binding [*system* system]
|
||||||
(fsnap/take-file-snapshot! system {:file-id file-id
|
(fsnap/take-file-snapshot! system {:file-id file-id :label "migration/components-v2"})
|
||||||
:label "migration/components-v2"})
|
|
||||||
(-> (db/get conn :file {:id file-id})
|
(-> (db/get conn :file {:id file-id})
|
||||||
(update :features db/decode-pgarray #{})
|
(update :features db/decode-pgarray #{})
|
||||||
(process-file :validate? validate?))))))
|
(process-file :validate? validate?
|
||||||
|
:throw-on-validate? throw-on-validate?))))))
|
||||||
|
|
||||||
(finally
|
(finally
|
||||||
(let [elapsed (tpoint)
|
(let [elapsed (tpoint)
|
||||||
|
@ -741,7 +742,7 @@
|
||||||
(some-> *team-stats* (swap! update :processed/files (fnil inc 0)))))))))
|
(some-> *team-stats* (swap! update :processed/files (fnil inc 0)))))))))
|
||||||
|
|
||||||
(defn migrate-team!
|
(defn migrate-team!
|
||||||
[system team-id & {:keys [validate?]}]
|
[system team-id & {:keys [validate? throw-on-validate?]}]
|
||||||
(let [tpoint (dt/tpoint)
|
(let [tpoint (dt/tpoint)
|
||||||
team-id (if (string? team-id)
|
team-id (if (string? team-id)
|
||||||
(parse-uuid team-id)
|
(parse-uuid team-id)
|
||||||
|
@ -771,12 +772,13 @@
|
||||||
"SELECT f.id FROM file AS f "
|
"SELECT f.id FROM file AS f "
|
||||||
" JOIN project AS p ON (p.id = f.project_id) "
|
" JOIN project AS p ON (p.id = f.project_id) "
|
||||||
"WHERE p.team_id = ? AND f.deleted_at IS NULL AND p.deleted_at IS NULL "
|
"WHERE p.team_id = ? AND f.deleted_at IS NULL AND p.deleted_at IS NULL "
|
||||||
"FOR UPDATE")
|
"FOR UPDATE")]
|
||||||
|
|
||||||
rows (->> (db/exec! conn [sql team-id])
|
(doseq [file-id (->> (db/exec! conn [sql team-id])
|
||||||
(map :id))]
|
(map :id))]
|
||||||
|
(migrate-file! system file-id
|
||||||
(run! #(migrate-file! system % :validate? validate?) rows)
|
:validate? validate?
|
||||||
|
:throw-on-validate? throw-on-validate?))
|
||||||
|
|
||||||
(let [features (-> features
|
(let [features (-> features
|
||||||
(disj "ephimeral/v2-migration")
|
(disj "ephimeral/v2-migration")
|
||||||
|
|
Loading…
Add table
Reference in a new issue