mirror of
https://github.com/penpot/penpot.git
synced 2025-05-28 18:26:11 +02:00
✨ Add helper for restoring team after migration to comp-v2
This commit is contained in:
parent
2331647ec6
commit
040b336ef9
2 changed files with 55 additions and 10 deletions
|
@ -1442,7 +1442,7 @@
|
||||||
data)))
|
data)))
|
||||||
(fmg/migrate-file))))
|
(fmg/migrate-file))))
|
||||||
|
|
||||||
(defn- get-team
|
(defn get-team
|
||||||
[system team-id]
|
[system team-id]
|
||||||
(-> (db/get system :team {:id team-id}
|
(-> (db/get system :team {:id team-id}
|
||||||
{::db/remove-deleted false
|
{::db/remove-deleted false
|
||||||
|
@ -1496,17 +1496,19 @@
|
||||||
AND f.deleted_at IS NULL
|
AND f.deleted_at IS NULL
|
||||||
FOR UPDATE")
|
FOR UPDATE")
|
||||||
|
|
||||||
(defn- get-and-lock-files
|
(defn get-and-lock-files
|
||||||
[conn team-id]
|
[conn team-id]
|
||||||
(->> (db/cursor conn [sql:get-and-lock-team-files team-id])
|
(->> (db/cursor conn [sql:get-and-lock-team-files team-id])
|
||||||
(map :id)))
|
(map :id)))
|
||||||
|
|
||||||
(defn- update-team-features!
|
(defn update-team!
|
||||||
[conn team-id features]
|
[conn team]
|
||||||
(let [features (db/create-array conn "text" features)]
|
(let [params (-> team
|
||||||
|
(update :features db/encode-pgarray conn "text")
|
||||||
|
(dissoc :id))]
|
||||||
(db/update! conn :team
|
(db/update! conn :team
|
||||||
{:features features}
|
params
|
||||||
{:id team-id})))
|
{:id (:id team)})))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; PUBLIC API
|
;; PUBLIC API
|
||||||
|
@ -1590,7 +1592,7 @@
|
||||||
:skip-on-graphic-error? skip-on-graphic-error?))
|
:skip-on-graphic-error? skip-on-graphic-error?))
|
||||||
migrate-team
|
migrate-team
|
||||||
(fn [{:keys [::db/conn] :as system} team-id]
|
(fn [{:keys [::db/conn] :as system} team-id]
|
||||||
(let [{:keys [id features name]} (get-team system team-id)]
|
(let [{:keys [id features] :as team} (get-team system team-id)]
|
||||||
(if (contains? features "components/v2")
|
(if (contains? features "components/v2")
|
||||||
(l/inf :hint "team already migrated")
|
(l/inf :hint "team already migrated")
|
||||||
(let [features (-> features
|
(let [features (-> features
|
||||||
|
@ -1601,13 +1603,14 @@
|
||||||
|
|
||||||
(events/tap :progress
|
(events/tap :progress
|
||||||
{:op :migrate-team
|
{:op :migrate-team
|
||||||
:name name
|
:name (:name team)
|
||||||
:id id})
|
:id id})
|
||||||
|
|
||||||
(run! (partial migrate-file system)
|
(run! (partial migrate-file system)
|
||||||
(get-and-lock-files conn id))
|
(get-and-lock-files conn id))
|
||||||
|
|
||||||
(update-team-features! conn id features)))))]
|
(->> (assoc team :features features)
|
||||||
|
(update-team! conn))))))]
|
||||||
|
|
||||||
(binding [*team-stats* (atom {})]
|
(binding [*team-stats* (atom {})]
|
||||||
(try
|
(try
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.features.components-v2 :as feat]
|
[app.features.components-v2 :as feat]
|
||||||
[app.main :as main]
|
[app.main :as main]
|
||||||
|
[app.rpc.commands.files-snapshot :as rpc]
|
||||||
[app.svgo :as svgo]
|
[app.svgo :as svgo]
|
||||||
[app.util.cache :as cache]
|
[app.util.cache :as cache]
|
||||||
[app.util.events :as events]
|
[app.util.events :as events]
|
||||||
|
@ -636,3 +637,44 @@
|
||||||
:file-name (:name file))
|
:file-name (:name file))
|
||||||
(assoc file :deleted-at (dt/now)))
|
(assoc file :deleted-at (dt/now)))
|
||||||
file))
|
file))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; RESTORE SNAPSHOT
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(def ^:private sql:snapshots-with-file
|
||||||
|
"SELECT f.id AS file_id,
|
||||||
|
fc.id AS id
|
||||||
|
FROM file AS f
|
||||||
|
JOIN file_change AS fc ON (fc.file_id = f.id)
|
||||||
|
WHERE fc.label = ? AND f.id = ANY(?)")
|
||||||
|
|
||||||
|
(defn restore-team!
|
||||||
|
[team-id label & {:keys [rollback?] :or {rollback? true}}]
|
||||||
|
(let [team-id (if (string? team-id)
|
||||||
|
(parse-uuid team-id)
|
||||||
|
team-id)
|
||||||
|
|
||||||
|
get-file-snapshots
|
||||||
|
(fn [conn ids]
|
||||||
|
(let [label (str "migration/" label)]
|
||||||
|
(db/exec! conn [sql:snapshots-with-file label
|
||||||
|
(db/create-array conn "uuid" ids)])))
|
||||||
|
|
||||||
|
restore-snapshot
|
||||||
|
(fn [{:keys [::db/conn] :as system}]
|
||||||
|
(let [ids (into #{} (feat/get-and-lock-files conn team-id))
|
||||||
|
snap (get-file-snapshots conn ids)
|
||||||
|
ids' (into #{} (map :file-id) snap)
|
||||||
|
team (-> (feat/get-team conn team-id)
|
||||||
|
(update :features disj "components/v2"))]
|
||||||
|
|
||||||
|
(when (not= ids ids')
|
||||||
|
(throw (RuntimeException. "no uniform snapshot available")))
|
||||||
|
|
||||||
|
(feat/update-team! conn team)
|
||||||
|
(run! (partial rpc/restore-file-snapshot! system) snap)))]
|
||||||
|
|
||||||
|
|
||||||
|
(-> (assoc main/system ::db/rollback rollback?)
|
||||||
|
(db/tx-run! restore-snapshot))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue