                                  key key-value)]
               [(upsert-record session model t lookup-record)]))))))))
 
+(defn copy-unique-keys
+  [^Model model from to]
+  (let [unique-key-tables (:unique-key-tables model)]
+    (reduce (fn [r t]
+              (let [key-col (last (:key t))]
+                (assoc r key-col (get from key-col))))
+            to
+            unique-key-tables)))
+
 (defn upsert
   "upsert a single instance, upserting primary, secondary, unique-key and
    lookup records as required and deleting stale secondary, unique-key and

   [er-cassandra.record-either :as r]
   [er-cassandra.model.types :as t]
   [er-cassandra.model.util :refer [combine-responses create-lookup-record]]
   [er-cassandra.model.unique-key :as uk])
  (:import [er_cassandra.model.types Model]))

(defn delete-record

  ([session ^Model model record]

   (m/with-monad dm/either-deferred-monad
     (m/mlet [old-record-with-keys (unique-key/update-unique-keys
                                    session
                                    model
                                    record)

              new-record-with-keys (m/return
                                    (copy-unique-keys
                                     model
                                     old-record-with-keys
                                     record))

              stale-secondary-responses (delete-stale-secondaries
                                         session
                                         model
                                         old-record-with-keys
                                         new-record-with-keys)

              stale-lookup-responses (delete-stale-lookups
                                      session
                                      model
                                      old-record-with-keys
                                      new-record-with-keys)

              secondary-reponses (upsert-secondaries
                                  session
                                  model
                                  new-record-with-keys)

              lookup-responses (upsert-lookups
                                session
                                model
                                new-record-with-keys)]
             (r/select-one session
                           (get-in model [:primary-table :name])
                           (get-in model [:primary-table :key])
                           (t/extract-uber-key-value model record))))))
