   "Migrates database to the latest schema version. Does nothing if database is
 already at the latest schema version."
   []
-  (sql/transaction
-    (if-let [pending (seq (pending-migrations))]
+  (if-let [pending (seq (pending-migrations))]
+    (sql/transaction
       (doseq [[version migration] pending]
-        (log/info (format "Migrating to version %d" version))
-        (migration)
-        (record-migration! version))
-      (log/info "There are no pending migrations"))) )
+      (log/info (format "Migrating to version %d" version))
+      (migration)
+      (record-migration! version)))
+    (log/info "There are no pending migrations")))

  []
  (try
    (let [query "SELECT version FROM schema_migrations ORDER BY version DESC LIMIT 1"
          results (query-to-vec query)]
      (:version (first results)))
    (catch java.sql.SQLException e
      0)))

along with the time at which the migration was performed."
  [version]
  {:pre [(integer? version)]}
  (let [timestamp (java.sql.Timestamp. (.getTime (java.util.Date.)))]
    (sql/insert-record :schema_migrations {:version version :time timestamp})))

(defn pending-migrations
  "Returns a collection of pending migrations, ordered from oldest to latest."
