                                 (->> pending
                                      (map (fn [[version migration]]
                                             (let [t0 (now)]
-                                            (log/info (trs "Applying database migration version {0}" version))
-                                            (sql-or-die (fn [] (let [result (migration)]
-                                                                    (record-migration! version)
-                                                                    result)))
-                                            (log/info (trs "Applied database migration version {0} in {1} ms"
-                                                           version (in-millis (interval t0 (now))))))))
+                                              (log/info (trs "Applying database migration version {0}" version))
+                                              (let [result (migration)]
+                                                (record-migration! version)
+                                                result)
+                                              (log/info (trs "Applied database migration version {0} in {1} ms"
+                                                             version (in-millis (interval t0 (now))))))))
                                      (filter map?)
                                      (map ::vacuum-analyze)
                                      (apply set/union small-tables)

    (into (sorted-map)
          (select-keys migrations pending))))

(defn- sql-or-die
  "Calls (f) and returns its result.  If f throws an SQLException,
  logs the exception and its parent and then calls (flush-and-exit 1)"
  [f]
  ;; Here we've preserved existing behavior, but this may warrant
  ;; further consideration later.  If possible, we might want to
  ;; avoid flush-and-exit in favor of careful exception
  ;; handling (cf. PDB-1118).
  (try
    (f)
    (catch java.sql.SQLException e
      (log/error e (trs "Caught SQLException during migration"))
      (when-let [next (.getNextException e)]
        (log/error next (trs "Unravelled exception")))
      (binding [*out* *err*] (flush)) (flush)
      (flush-and-exit 1))))

(defn previous-migrations
  "Returns the list of migration numbers that existed before the
  current known set. These migrations can't be upgraded from, but are

      (do
        (log/info (trs "There are no pending migrations"))
        false))))

(defn migrate! [db-connection-pool]
  "Migrates database to the latest schema version. Does nothing if
  database is already at the latest schema version.  Requires a
  connection pool because some operations may require an indepdendent
  database connection.  Returns true if there were any migrations."
  (try
    (run-migrations db-connection-pool)
    (catch java.sql.SQLException e
      (log/error e (trs "Caught SQLException during migration"))
      (loop [ex (.getNextException e)]
        (when ex
          (log/error ex (trs "Unraveled exception"))
          (recur (.getNextException ex))))
      (throw e))))

;; SPECIAL INDEX HANDLING

