 
 (defn add-resources!
   "Persist the given resource and associate it with the given catalog."
-  [catalog-hash refs-to-resources refs-to-hashes]
+  [catalog-id refs-to-resources refs-to-hashes]
   (let [persisted?      (resources-exist? (utils/valset refs-to-hashes))
         resource-values (for [[ref resource] refs-to-resources
                               :let [hash (refs-to-hashes ref)]]
-                          (resource->values catalog-hash resource hash (persisted? hash)))
+                          (resource->values catalog-id resource hash (persisted? hash)))
         lookup-table    [[:parameters_cache "INSERT INTO resource_params_cache (resource, parameters) VALUES (?, ?)"]
-                         [:resource "INSERT INTO catalog_resources (catalog_id,resource,type,title,tags,exported,file,line) SELECT id,?,?,?,?,?,?,? FROM catalogs WHERE hash = ?"]
+                         [:resource "INSERT INTO catalog_resources (catalog_id,resource,type,title,tags,exported,file,line) VALUES (?,?,?,?,?,?,?,?)"]
                          [:parameters "INSERT INTO resource_params (resource,name,value) VALUES (?,?,?)"]]]
     (sql/transaction
      (doseq [[lookup the-sql] lookup-table


  The result map has the following format:

    {:resource [[<resouce hash> <type> <title> <tags> <exported?> <sourcefile> <sourceline> <catalog hash>] ...]
     :parameters [[<resource hash> <name> <value>] ...]
     :parameters_cache [[<resource hash> <parameters>] ...]}


    (pos? (first replaced))))

(defn add-catalog-metadata!
  "Given some catalog metadata, persist it in the db. Returns a map of the
  inserted data including any autogenerated columns."
  [hash api-version catalog-version transaction-uuid]
  {:pre [(string? hash)
         (number? api-version)
         (string? catalog-version)
         ((some-fn nil? string?) transaction-uuid)]
   :post [(map? %)]}
  (sql/insert-values :catalogs
    [:hash :api_version :catalog_version :transaction_uuid]
    [hash api-version catalog-version transaction-uuid]))

(defn update-catalog-metadata!
  "Given some catalog metadata, update the db"
