            full-execution-log []]
       (if (empty? transformations)
         (let [new-dataset-version-id (str (util/squuid))]
-          (clear-dataset-version-data-table tx-conn {:id (:id current-dataset-version)})
-          (new-dataset-version tx-conn
+          (clear-dataset-version-data-table tenant-conn {:id (:id current-dataset-version)})
+          (new-dataset-version tenant-conn
                                {:id new-dataset-version-id
                                 :dataset-id dataset-id
                                 :job-execution-id job-id

(ns org.akvo.lumen.transformation.engine
  (:require [clojure.java.jdbc :as jdbc]
            [hugsql.core :as hugsql]
            [org.akvo.lumen.util :as util])
  (:import java.sql.SQLException))



(defn execute-undo [completion-promise tenant-conn job-id dataset-id]
  (try
    (let [current-dataset-version (latest-dataset-version-by-dataset-id tenant-conn
                                                                        {:dataset-id dataset-id})
          current-version (:version current-dataset-version)]
      (if (= current-version 1)
        (nothing-to-undo completion-promise
                         tenant-conn
                         dataset-id
                         (:id current-dataset-version)
                         job-id)
        (apply-undo completion-promise
                    tenant-conn
                    job-id
                    dataset-id
                    current-dataset-version)))

    (catch Exception e
      (execute-transformation-failed completion-promise
                                     tenant-conn
