diff --git a/src/datomish/db.cljc b/src/datomish/db.cljc index 714a160e..b16bf633 100644 --- a/src/datomish/db.cljc +++ b/src/datomish/db.cljc @@ -446,63 +446,60 @@ (declare = current-tx 0) + current-tx (max current-tx tx0)] + (when-not bootstrapped + ;; We need to bootstrap the DB. + (let [fail-alter-ident (fn [old new] (if-not (= old new) + (raise "Altering idents is not yet supported, got " new " altering existing ident " old + {:error :schema/alter-idents :old old :new new}) + new)) + fail-alter-attr (fn [old new] (if-not (= old new) + (raise "Altering schema attributes is not yet supported, got " new " altering existing schema attribute " old + {:error :schema/alter-schema :old old :new new}) + new))] + (-> (map->DB + {:sqlite-connection sqlite-connection + :idents bootstrap-idents + :symbolic-schema bootstrap-symbolic-schema + :schema (ds/schema (into {} (map (fn [[k v]] [(k bootstrap-idents) v]) bootstrap-symbolic-schema))) ;; TODO: fail if ident missing. + :current-tx current-tx}) + ;; We use = current-tx 0) - current-tx (max current-tx tx0)] - (when-not bootstrapped - ;; We need to bootstrap the DB. - (let [fail-alter-ident (fn [old new] (if-not (= old new) - (raise "Altering idents is not yet supported, got " new " altering existing ident " old - {:error :schema/alter-idents :old old :new new}) - new)) - fail-alter-attr (fn [old new] (if-not (= old new) - (raise "Altering schema attributes is not yet supported, got " new " altering existing schema attribute " old - {:error :schema/alter-schema :old old :new new}) - new))] - (-> (map->DB - {:sqlite-connection sqlite-connection - :idents bootstrap-idents - :symbolic-schema bootstrap-symbolic-schema - :schema (ds/schema (into {} (map (fn [[k v]] [(k bootstrap-idents) v]) bootstrap-symbolic-schema))) ;; TODO: fail if ident missing. - :current-tx current-tx}) - ;; We use DB - {:sqlite-connection sqlite-connection - :idents idents - :symbolic-schema symbolic-schema - :schema (ds/schema (into {} (map (fn [[k v]] [(k idents) v]) symbolic-schema))) ;; TODO: fail if ident missing. - :current-tx (inc current-tx)})))))) + ;; We just bootstrapped, or we are returning to an already bootstrapped DB. + (let [idents (DB + {:sqlite-connection sqlite-connection + :idents idents + :symbolic-schema symbolic-schema + :schema (ds/schema (into {} (map (fn [[k v]] [(k idents) v]) symbolic-schema))) ;; TODO: fail if ident missing. + :current-tx (inc current-tx)}))))) (defn connection-with-db [db] (map->Connection {:current-db (atom db)})) diff --git a/test/datomish/db_test.cljc b/test/datomish/db_test.cljc index cd79b55b..8d650643 100644 --- a/test/datomish/db_test.cljc +++ b/test/datomish/db_test.cljc @@ -123,7 +123,7 @@ (deftest-async test-add-one (with-tempfile [t (tempfile)] (let [c (