Skip to content

Instantly share code, notes, and snippets.

@mszajna
Last active September 23, 2018 09:58
Show Gist options
  • Save mszajna/aaf9c9a0fe796087ed6e997b0b9b98bd to your computer and use it in GitHub Desktop.
Save mszajna/aaf9c9a0fe796087ed6e997b0b9b98bd to your computer and use it in GitHub Desktop.
Datomic transaction function for migration
(def run-once
(d/function '{:lang "clojure"
:requires [[datomic.api :as d]]
:params [db db-fn]
:code (when-not (d/pull db [:data.migration/done] db-fn)
[[db-fn]
[:db/add db-fn :data.migration/done "datomic.tx"]])}))
(def schema-tx
[{:db/ident :data.migration/run-once
:db/fn run-once
:db/doc "First time when this function is called with a given no-param function will run that function and annotate it with :data.migration/done. Subsequent calls with the same function are no-ops."}
{:db/ident :data.migration/done
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "If function has been run with :data.migration/run-once this attribute will reference the transaction where it happened."}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment