Last active
November 4, 2015 18:00
-
-
Save adamneilson/ca2af300168c9b90f5a5 to your computer and use it in GitHub Desktop.
This dumps the Datomic schema from the user partition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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