Created
November 21, 2012 10:01
-
-
Save tgk/4124077 to your computer and use it in GitHub Desktop.
Adding schema to database (not connection)
This file contains hidden or 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
(use '[datomic.api :only [q db] :as d]) | |
(def uri "datomic:mem://schema-test") | |
(d/delete-database uri) | |
(d/create-database uri) | |
(def conn (d/connect uri)) | |
(def schema-tx | |
[{:db/id (d/tempid :db.part/db) | |
:db/ident :person/name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db}]) | |
@(d/transact conn schema-tx) | |
(defn latest-transaction-time [] | |
(ffirst | |
(reverse (sort (q '[:find ?when :where [_ :db/txInstant ?when]] | |
(db conn)))))) | |
(def before (latest-transaction-time)) | |
(def migrate-schema-tx | |
[{:db/id (d/tempid :db.part/db) | |
:db/ident :person/debt | |
:db/valueType :db.type/long | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db}]) | |
(let [db (d/as-of (db conn) before)] | |
(d/with db migrate-schema-tx)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment