             [colorize.core :as color]
             (korma [core :as k]
                    [db :as kdb])
+            [medley.core :as m]
             [metabase.config :as config]
             [metabase.db :as db]
             (metabase.models [activity :refer [Activity]]

  [h2-connection-string-or-nil]
  (db/setup-db)
  (let [h2-filename (or h2-connection-string-or-nil @metabase.db/db-file)]
    ;; TODO - would be nice to add `ACCESS_MODE_DATA=r` but it doesn't work with `AUTO_SERVER=TRUE`
    (jdbc/with-db-connection [h2-spec (db/jdbc-details {:type :h2, :db (str h2-filename ";IFEXISTS=TRUE")})]
      (kdb/transaction
        (doseq [e     entities
                :let  [objs (jdbc/query h2-spec [(str "SELECT * FROM " (:table e))])]
                :when (seq objs)]
          (if-not (contains? self-referencing-entities e)
            (insert-entity e objs)


    ;; if we are loading into a postgres db then we need to update sequence nextvals
    (when (= (config/config-str :mb-db-type) "postgres")
      (jdbc/with-db-transaction [targetdb-conn (db/jdbc-details @db/db-connection-details)]
        (binding [*db-conn* targetdb-conn]
          (set-postgres-sequence-values))))))
