mirror of
https://github.com/penpot/penpot.git
synced 2026-04-28 12:48:31 +00:00
WIP
This commit is contained in:
parent
cc02a4732e
commit
07af88f33b
@ -209,7 +209,6 @@
|
||||
;; STORAGE
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(defmulti resolve-file-data
|
||||
(fn [_cfg file] (or (get file :backend) "db")))
|
||||
|
||||
@ -381,3 +380,63 @@
|
||||
(-> (db/delete! cfg :file-data params)
|
||||
(db/get-update-count)
|
||||
(pos?))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; SCRIPTS
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def sql:get-unmigrated-files
|
||||
"SELECT f.id, f.data,
|
||||
row_number() OVER w AS index
|
||||
FROM file AS f
|
||||
WHERE f.data IS NOT NULL
|
||||
WINDOW w AS (order by f.modified_at ASC)
|
||||
ORDER BY f.modified_at ASC
|
||||
LIMIT 100")
|
||||
|
||||
(defn migrate-to-storage
|
||||
"Migrate the current existing files to store data in new storage
|
||||
tables."
|
||||
[system]
|
||||
(let [timestamp (ct/now)]
|
||||
(db/tx-run! system
|
||||
(fn [{:keys [::db/conn]}]
|
||||
(run! (fn [{:keys [id data index]}]
|
||||
(l/dbg :hint "migrating file" :file-id (str id) :index index)
|
||||
(db/update! conn :file {:data nil} {:id id} ::db/return-keys false)
|
||||
(db/insert! conn :file-data
|
||||
{:backend "db"
|
||||
:metadata nil
|
||||
:type "main"
|
||||
:data data
|
||||
:created-at timestamp
|
||||
:modified-at timestamp
|
||||
:file-id id
|
||||
:id id}
|
||||
{::db/return-keys false}))
|
||||
(db/plan conn [sql:get-unmigrated-files]))))))
|
||||
|
||||
|
||||
(def sql:get-migrated-files
|
||||
"SELECT f.id, f.data,
|
||||
row_number() OVER w AS index
|
||||
FROM file_data AS f
|
||||
WHERE f.data IS NOT NULL
|
||||
AND f.id = f.file_id
|
||||
WINDOW w AS (order by f.id ASC)
|
||||
ORDER BY f.id ASC")
|
||||
|
||||
(defn rollback-from-storage
|
||||
"Migrate back to the file table storage."
|
||||
[system]
|
||||
(db/tx-run! system
|
||||
(fn [{:keys [::db/conn]}]
|
||||
(run! (fn [{:keys [id data index]}]
|
||||
(l/dbg :hint "rollback file" :file-id (str id) :index index)
|
||||
(db/update! conn :file {:data data} {:id id} ::db/return-keys false)
|
||||
(db/delete! conn :file-data {:id id} ::db/return-keys false))
|
||||
(db/plan conn [sql:get-migrated-files])))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -252,8 +252,6 @@
|
||||
(assoc :permissions perms)
|
||||
(check-version!))]
|
||||
|
||||
;; (app.common.pprint/pprint file)
|
||||
|
||||
(-> (cfeat/get-team-enabled-features cf/flags team)
|
||||
(cfeat/check-client-features! (:features params))
|
||||
(cfeat/check-file-features! (:features file)))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user