mirror of
https://github.com/penpot/penpot.git
synced 2025-02-11 01:28:30 -05:00
✨ Properly use dumped objects on initial data load process.
This commit is contained in:
parent
f57fb5006d
commit
188126a895
4 changed files with 24 additions and 11 deletions
|
@ -172,6 +172,9 @@
|
||||||
|
|
||||||
{:name "0054-add-audit-log-table"
|
{:name "0054-add-audit-log-table"
|
||||||
:fn (mg/resource "app/migrations/sql/0054-add-audit-log-table.sql")}
|
:fn (mg/resource "app/migrations/sql/0054-add-audit-log-table.sql")}
|
||||||
|
|
||||||
|
{:name "0055-mod-file-media-object-table"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0055-mod-file-media-object-table.sql")}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
ALTER TABLE file_media_object
|
||||||
|
DROP CONSTRAINT file_media_object_thumbnail_id_fkey,
|
||||||
|
ADD CONSTRAINT file_media_object_thumbnail_id_fkey
|
||||||
|
FOREIGN KEY (thumbnail_id) REFERENCES storage_object (id) ON DELETE SET NULL;
|
|
@ -91,21 +91,21 @@
|
||||||
(def sql:retrieve-used-media-objects
|
(def sql:retrieve-used-media-objects
|
||||||
"select fmo.*
|
"select fmo.*
|
||||||
from file_media_object as fmo
|
from file_media_object as fmo
|
||||||
inner join storage_object as o on (fmo.media_id = o.id)
|
inner join storage_object as so on (fmo.media_id = so.id)
|
||||||
where fmo.file_id = ?
|
where fmo.file_id = ?
|
||||||
and o.deleted_at is null")
|
and so.deleted_at is null")
|
||||||
|
|
||||||
(defn duplicate-file
|
(defn duplicate-file
|
||||||
[conn {:keys [profile-id file index project-id name]} {:keys [reset-shared-flag] :as opts}]
|
[conn {:keys [profile-id file index project-id name flibs fmeds]} {:keys [reset-shared-flag] :as opts}]
|
||||||
(let [flibs (db/exec! conn [sql:retrieve-used-libraries (:id file)])
|
(let [flibs (or flibs (db/exec! conn [sql:retrieve-used-libraries (:id file)]))
|
||||||
fmeds (db/exec! conn [sql:retrieve-used-media-objects (:id file)])
|
fmeds (or fmeds (db/exec! conn [sql:retrieve-used-media-objects (:id file)]))
|
||||||
|
|
||||||
;; memo uniform creation/modification date
|
;; memo uniform creation/modification date
|
||||||
now (dt/now)
|
now (dt/now)
|
||||||
ignore (dt/plus now (dt/duration {:seconds 5}))
|
ignore (dt/plus now (dt/duration {:seconds 5}))
|
||||||
|
|
||||||
;; add to the index all file media objects.
|
;; add to the index all file media objects.
|
||||||
index (reduce #(assoc %1 (:id %2) (uuid/next)) index fmeds)
|
index (reduce #(assoc %1 (:id %2) (uuid/next)) index fmeds)
|
||||||
|
|
||||||
flibs-xf (comp
|
flibs-xf (comp
|
||||||
(map #(remap-id % index :file-id))
|
(map #(remap-id % index :file-id))
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
(:refer-clojure :exclude [load])
|
(:refer-clojure :exclude [load])
|
||||||
(:require
|
(:require
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cfg]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.rpc.mutations.management :refer [duplicate-file]]
|
[app.rpc.mutations.management :refer [duplicate-file]]
|
||||||
[app.rpc.mutations.projects :refer [create-project create-project-role]]
|
[app.rpc.mutations.projects :refer [create-project create-project-role]]
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
([system project-id {:keys [skey project-name]
|
([system project-id {:keys [skey project-name]
|
||||||
:or {project-name "Penpot Onboarding"}}]
|
:or {project-name "Penpot Onboarding"}}]
|
||||||
(db/with-atomic [conn (:app.db/pool system)]
|
(db/with-atomic [conn (:app.db/pool system)]
|
||||||
(let [skey (or skey (cfg/get :initial-project-skey))
|
(let [skey (or skey (cf/get :initial-project-skey))
|
||||||
files (db/exec! conn [sql:file project-id])
|
files (db/exec! conn [sql:file project-id])
|
||||||
flibs (db/exec! conn [sql:file-library-rel project-id])
|
flibs (db/exec! conn [sql:file-library-rel project-id])
|
||||||
fmeds (db/exec! conn [sql:file-media-object project-id])
|
fmeds (db/exec! conn [sql:file-media-object project-id])
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
(defn load-initial-project!
|
(defn load-initial-project!
|
||||||
([conn profile] (load-initial-project! conn profile nil))
|
([conn profile] (load-initial-project! conn profile nil))
|
||||||
([conn profile opts]
|
([conn profile opts]
|
||||||
(let [skey (or (:skey opts) (cfg/get :initial-project-skey))
|
(let [skey (or (:skey opts) (cf/get :initial-project-skey))
|
||||||
data (retrieve-data conn skey)]
|
data (retrieve-data conn skey)]
|
||||||
(when data
|
(when data
|
||||||
(let [index (reduce #(assoc %1 (:id %2) (uuid/next)) {} (:files data))
|
(let [index (reduce #(assoc %1 (:id %2) (uuid/next)) {} (:files data))
|
||||||
|
@ -82,10 +82,16 @@
|
||||||
:role :owner})
|
:role :owner})
|
||||||
|
|
||||||
(doseq [file (:files data)]
|
(doseq [file (:files data)]
|
||||||
(let [params {:profile-id (:id profile)
|
(let [flibs (filterv #(= (:id file) (:file-id %)) (:flibs data))
|
||||||
|
fmeds (filterv #(= (:id file) (:file-id %)) (:fmeds data))
|
||||||
|
|
||||||
|
params {:profile-id (:id profile)
|
||||||
:project-id (:id project)
|
:project-id (:id project)
|
||||||
:file file
|
:file file
|
||||||
:index index}
|
:index index
|
||||||
|
:flibs flibs
|
||||||
|
:fmeds fmeds}
|
||||||
|
|
||||||
opts {:reset-shared-flag false}]
|
opts {:reset-shared-flag false}]
|
||||||
(duplicate-file conn params opts))))))))
|
(duplicate-file conn params opts))))))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue