sql(format"SELECT setval('%s', COALESCE((SELECT MAX(id) FROM %s), 1), true) as val"seq-nametable-name)]]
(jdbc/db-query-with-resultset*db-conn*[sql]:val))
(println(color/green"[OK]")))
(defnload-from-h2
"Transfer data from existing H2 database to the newly created (presumably MySQL or Postgres) DB specified by env vars.
Intended as a tool for upgrading from H2 to a 'real' Database.
Defaults to using `@metabase.db/db-file` as the connection string."
[h2-connection-string-or-nil]
(let[filename(orh2-connection-string-or-nil
@metabase.db/db-file)
h2-db(kdb/create-db(db/jdbc-details{:type:h2,:db(strfilename";IFEXISTS=TRUE")}))]; TODO - would be nice to add `ACCESS_MODE_DATA=r` but it doesn't work with `AUTO_SERVER=TRUE`
(db/setup-db)
(kdb/transaction
(doseq[eentities
:let[objs(kdb/with-dbh2-db
(k/select(k/databaseeh2-db)))]
:when(seqobjs)]
(print(u/format-color'blue"Transfering %d instances of %s..."(countobjs)(:namee)))