Pass existing idents to datoms->schema-fragment, allowing the 'upgrade' of an existing ident to an attribute.
This commit is contained in:
parent
7cf67474a8
commit
8e16bee201
3 changed files with 22 additions and 6 deletions
|
@ -29,9 +29,14 @@
|
|||
4. Map e -> ident; fail if not possible.
|
||||
5. Return the map, with ident keys.
|
||||
|
||||
This would be more pleasant with `q` and pull expressions."
|
||||
This would be more pleasant with `q` and pull expressions.
|
||||
|
||||
[datoms]
|
||||
Note that this function takes as input an existing map of {entid ident}.
|
||||
That's because it's possible for an ident to be established in a separate
|
||||
set of datoms -- we can't re-insert it without uniqueness constraint
|
||||
violations, so we just provide it here."
|
||||
|
||||
[datoms existing-idents]
|
||||
{:pre [(sequential? datoms)]}
|
||||
|
||||
(let [db-install? (fn [datom]
|
||||
|
@ -57,8 +62,13 @@
|
|||
(let [->av (juxt :a :v)
|
||||
;; TODO: transduce!
|
||||
db-avs (into {} (map ->av (filter db-*? datoms)))]
|
||||
;; TODO: get ident from existing datom, to allow [:db.part/db :db.install/attribute existing-id].
|
||||
(if-let [ident (:db/ident db-avs)]
|
||||
(if-let [ident (or (:db/ident db-avs)
|
||||
;; The schema table wants a keyword, not an entid, and
|
||||
;; we need to check the existing idents…
|
||||
(when (contains? existing-idents e)
|
||||
(if (keyword? e)
|
||||
e
|
||||
(get existing-idents e))))]
|
||||
[ident (dissoc db-avs :db/ident)]
|
||||
(raise ":db.install/attribute requires :db/ident, got " db-avs " for " e
|
||||
{:error :schema/db-install :op db-avs}))))))))))
|
||||
|
|
|
@ -691,7 +691,9 @@
|
|||
tx
|
||||
added))
|
||||
datoms (map symbolicate-install-datom (:tx-data report))
|
||||
schema-fragment (datomish.schema-changes/datoms->schema-fragment datoms)]
|
||||
schema-fragment (datomish.schema-changes/datoms->schema-fragment
|
||||
datoms
|
||||
(:ident-map db))]
|
||||
(assoc-in report [:added-attributes] schema-fragment)))
|
||||
|
||||
(defn collect-db-alter-assertions
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
(:require
|
||||
[datomish.api :as d]
|
||||
[datomish.datom :refer [datom]]
|
||||
[datomish.schema-changes :refer [datoms->schema-fragment]]
|
||||
[datomish.schema-changes]
|
||||
[datomish.schema :as ds]
|
||||
[datomish.sqlite :as s]
|
||||
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise cond-let]]
|
||||
|
@ -43,6 +43,10 @@
|
|||
#?(:cljs
|
||||
(def Throwable js/Error))
|
||||
|
||||
;; Wrap this so that we can pass the empty second argument.
|
||||
(defn datoms->schema-fragment [x]
|
||||
(datomish.schema-changes/datoms->schema-fragment x {}))
|
||||
|
||||
(deftest test-datoms->schema-fragment
|
||||
(let [tx 10101
|
||||
->datom (fn [xs]
|
||||
|
|
Loading…
Reference in a new issue