mirror of
https://github.com/penpot/penpot.git
synced 2025-06-27 16:07:03 +02:00
✨ Reorganize migrations directory
This commit is contained in:
parent
483da5248f
commit
9275f5e5ce
2 changed files with 4 additions and 4 deletions
61
backend/src/app/migrations/clj/migration_0023.clj
Normal file
61
backend/src/app/migrations/clj/migration_0023.clj
Normal file
|
@ -0,0 +1,61 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) UXBOX Labs SL
|
||||
|
||||
(ns app.migrations.clj.migration-0023
|
||||
(:require
|
||||
[app.db :as db]
|
||||
[app.util.blob :as blob]))
|
||||
|
||||
(defn decode-row
|
||||
[{:keys [data] :as row}]
|
||||
(when row
|
||||
(cond-> row
|
||||
data (assoc :data (blob/decode data)))))
|
||||
|
||||
(defn retrieve-files
|
||||
[conn]
|
||||
(->> (db/exec! conn ["select * from file;"])
|
||||
(map decode-row)))
|
||||
|
||||
(defn retrieve-pages
|
||||
[conn file-id]
|
||||
(->> (db/query conn :page {:file-id file-id})
|
||||
(map decode-row)
|
||||
(sort-by :ordering)))
|
||||
|
||||
(def empty-file-data
|
||||
{:version 1
|
||||
:pages []
|
||||
:pages-index {}})
|
||||
|
||||
(defn pages->data
|
||||
[pages]
|
||||
(reduce (fn [acc {:keys [id data name] :as page}]
|
||||
(let [data (-> data
|
||||
(dissoc :version)
|
||||
(assoc :id id :name name))]
|
||||
(-> acc
|
||||
(update :pages (fnil conj []) id)
|
||||
(update :pages-index assoc id data))))
|
||||
empty-file-data
|
||||
pages))
|
||||
|
||||
(defn migrate-file
|
||||
[conn {:keys [id] :as file}]
|
||||
(let [pages (retrieve-pages conn (:id file))
|
||||
data (pages->data pages)]
|
||||
(db/update! conn :file
|
||||
{:data (blob/encode data)}
|
||||
{:id id})))
|
||||
|
||||
(defn migrate
|
||||
[conn]
|
||||
(let [files (retrieve-files conn)]
|
||||
(doseq [file files]
|
||||
(when (nil? (:data file))
|
||||
(migrate-file conn file)))
|
||||
(db/exec-one! conn ["drop table page cascade;"])))
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue