     (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

  Resource

  (get-all [histories]
    (sql/query (:connection db) (all-history-query)))

  (exists? [_ id] (staircase.sql/exists-with-owner (:connection db) :histories id (:user staircase.resources/context)))

