   version, etc. has already been validated."
   []
   (try
-    (let [migrated? (run-migrations)]
+    (let [tables-to-analyze (run-migrations)]
+      (analyze-tables tables-to-analyze)
       (indexes!)
-      migrated?)
+      (not (empty? tables-to-analyze)))
     (catch java.sql.SQLException e
       (log/error e (trs "Caught SQLException during migration"))
       (loop [ex (.getNextException e)]

                                   result))))
                        (filter map?)
                        (map ::vacuum-analyze)
                        seq)))]
    (when-not tables
      (log/info (trs "There are no pending migrations")))
    ;; Always analyze these since we had a good long period where
    ;; the post-migration analysis above wasn't actually working,
    ;; and since this shouldn't be expensive.
    (analyze-if-exists (apply set/union small-tables tables))
    (not (empty? tables))))


;; SPECIAL INDEX HANDLING

    (apply jdbc/do-commands-outside-txn
           (map #(str "vacuum analyze " %) tables))))

(defn- analyze-tables
  [requested]
  {:pre [(or (nil? requested) (set? requested))]}
  ;; Always analyze these small tables since we had a good long period
  ;; where the post-migration analysis above wasn't actually working,
  ;; and since this shouldn't be expensive.
  (let [small-tables (set ["value_types" "report_statuses"])]
    (analyze-if-exists (set/union small-tables requested))))

(defn run-migrations
  "Migrates database to the latest schema version. Does nothing if
  database is already at the latest schema version.  Returns a set of
  tables that should be analyzed if there were any migrations."
  []
  (require-valid-schema)
  (let [tables (jdbc/with-db-transaction []
                 (when-let [pending (seq (pending-migrations))]
                   (->> pending
                        (map (fn [[version migration]]
