Skip to content

Instantly share code, notes, and snippets.

@jdf-id-au
Last active June 19, 2023 02:11
Show Gist options
  • Save jdf-id-au/80e3be174de2b3fe1a91894b2ee2f0e3 to your computer and use it in GitHub Desktop.
Save jdf-id-au/80e3be174de2b3fe1a91894b2ee2f0e3 to your computer and use it in GitHub Desktop.
Migrate tricky data between datalevin verisons
(ns datalevin-migration
"Migrate evil prn-incompatible stuff like space-containing keywords.
Simplified from datalevin.core/dump-datalog and load-datalog"
(:require [taoensso.nippy :as nippy]
[datalevin.core :as dtlv]
[datalevin.db]
[datalevin.atom]))
(def db-path "path/to/db.old-version.dtlv")
(def new-db-path "path/to/db.new-version.dtlv")
(def dump-path "path/to/db.dump.nippy")
(def schema {})
(def con (dtlv/get-conn db-path schema))
(comment
;; with old dtlv dep and db-path
(nippy/freeze-to-file dump-path
[(dtlv/opts con)
(dtlv/schema con)
(map #(vector (.-e %) (.-a %) (.-v %)) (dtlv/datoms @con :eav))])
;; with new dtlv dep
(let [[opts schema datoms] (nippy/thaw-from-file dump-path)]
(datalevin.db/init-db
(apply list (for [d datoms] (apply datalevin.datom/datom d)))
new-db-path schema opts)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment