Skip to content

Instantly share code, notes, and snippets.

@adamneilson
Last active November 4, 2015 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamneilson/ca2af300168c9b90f5a5 to your computer and use it in GitHub Desktop.
Save adamneilson/ca2af300168c9b90f5a5 to your computer and use it in GitHub Desktop.
This dumps the Datomic schema from the user partition
;; This dumps the Datomic schema from the user partition
(let [dbval (d/db conn)]
(->> (d/q '[:find ?ident
:in $ ?p
:where
[:db.part/db :db.install/attribute ?attr]
[?attr :db/ident ?ident]]
dbval :db.part/user)
(map (fn [attr] [(d/entity dbval (first attr))]))
(map (fn [attr]
{:db/id #db/id[:db.part/db]
:db/ident (:db/ident (first attr))
:db/valueType (:db/valueType (first attr))
:db/cardinality (:db/cardinality (first attr))
:db/doc (:db/doc (first attr))
:db/isComponent (or (:db/isComponent (first attr)) (not (nil? (:db/isComponent (first attr)))))
:db/fulltext (when (:db/fulltext (first attr)) true)
:db/unique (when (not (nil? (:db/unique (first attr)))) :db.unique/identity)
:db.install/_attribute :db.part/db}))
; remove all the nils
(map (fn [attr] (apply dissoc attr (for [[k v] attr :when (nil? v)] k))))
(filter (fn [attr] (not= (subs (namespace (:db/ident attr)) 0 2) "db")))
(sort-by :db/ident)))
@jeroenvandijk
Copy link

Hi Adam,

I've used your script as an example, Thanks! Here is my schema-dump approach https://gist.github.com/jeroenvandijk/85eb96d68c31c4e48f99 . My goal was to dump to a schema file that can be used in git diffs, and to have a file that can used to quickly load the last database structure instead of running several migrations.

Cheers,
Jeroen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment