 
 (defn- start-system
   []
-  (-> (mount/only #{#'uxbox.config/config
-                    #'uxbox.db/datasource
-                    #'uxbox.migrations/migrations})
-      (mount/start)))
+  (mount/start))
 
 (defn- stop-system
   []
   (mount/stop))
 
 (defn- run-importer
-  [directory data]
-  (println "Running importer on:")
-  (pprint data))
+  [conn basedir data]
+  (let [images (:images data)
+        icons (:icons data)]
+    (run! #(process-images-entry conn basedir %) images)))
 
 (defn -main
   [& [path]]
-  (let [[directory data] (read-import-file path)]
+  (let [[basedir data] (read-import-file path)]
     (start-system)
     (try
-      (run-importer directory data)
+      (with-open [conn (db/connection)]
+        (sc/apply-atomic conn run-importer basedir data))
       (finally
         (stop-system)))))

(defn- import-image
  [conn id fpath]
  {:pre [(uuid? id) (fs/path? fpath)]}
  #_(let [imageid (uuid/namespaced +imates-uuid-ns+ (str id fpath))]
    (if-let [image (retrieve-image conn imageid)]
      (do
        (delete-image conn image)


;; --- Colors Collections Importer

(defn- create-image-collection
  "Create or replace image collection by its name."
  [conn {:keys [name] :as entry}]
  (println "Creating image collection:" name)
  (let [id (uuid/namespaced +imates-uuid-ns+ name)
        sqlv (sql/create-image-collection {:id id :name name})]
    (sc/execute conn sqlv)
