     (when-let [uuid (string->uuid id)]
       (sql/query
         (:connection db)
-        [" select h.*, hs.step_id
-           from histories as h
-           left join history_step as hs on h.id = hs.history_id
-           where h.id = ? and h.owner = ?
-           order by hs.created_at desc " uuid (:user staircase.resources/context)] 
+        (one-history-query uuid)
         :result-set-fn #(if (empty? %) nil (apply build-history %)))))
 
   (update [_ id doc] (staircase.sql/update-owned-entity

    (reduce f init rows)))

(def table-spec (merge schema/histories schema/history-step))

(defrecord HistoryResource [db]
  component/Lifecycle

        [clojure.tools.logging :only (info)])
  (:require staircase.sql
            staircase.resources
            [honeysql.helpers :refer (select from where left-join group order-by)]
            [honeysql.core :as hsql]
            [staircase.resources.schema :as schema]
            [com.stuartsierra.component :as component]
