Migrates back to datomic on-prem
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
(ns auto-ap.datomic
|
||||
(:require
|
||||
[iol-ion.tx.pay]
|
||||
[iol-ion.tx.plus]
|
||||
[iol-ion.tx.propose-invoice]
|
||||
[iol-ion.tx.reset-rels]
|
||||
[iol-ion.tx.reset-scalars]
|
||||
[iol-ion.tx.upsert-entity]
|
||||
[iol-ion.tx.upsert-invoice]
|
||||
[iol-ion.tx.upsert-ledger]
|
||||
[iol-ion.tx.upsert-transaction]
|
||||
[com.github.ivarref.gen-fn :refer [gen-fn! datomic-fn]]
|
||||
[auto-ap.utils :refer [default-pagination-size by]]
|
||||
[clojure.tools.logging :as log]
|
||||
[clojure.edn :as edn]
|
||||
[config.core :refer [env]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[mount.core :as mount]
|
||||
[clojure.java.io :as io])
|
||||
@@ -13,12 +23,12 @@
|
||||
|
||||
(def uri (:datomic-url env))
|
||||
|
||||
(mount/defstate client
|
||||
#_(mount/defstate client
|
||||
:start (dc/client (:client-config env))
|
||||
:stop nil)
|
||||
|
||||
(mount/defstate conn
|
||||
:start (dc/connect client {:db-name (:db-name env)})
|
||||
:start (dc/connect "datomic:ddb://us-east-1/iol-dev/dev")
|
||||
:stop nil)
|
||||
|
||||
#_(def uri "datomic:mem://datomic-transactor:4334/invoice")
|
||||
@@ -627,7 +637,7 @@
|
||||
_ (mu/log ::transacting-batch
|
||||
:batch batch-id
|
||||
:count (count batch))
|
||||
tx-result (dc/transact conn {:tx-data batch})]
|
||||
tx-result @(dc/transact conn batch)]
|
||||
|
||||
(cond-> full-tx
|
||||
(:tx-data full-tx) (update :tx-data #(into % (:tx-data tx-result)))
|
||||
@@ -641,8 +651,8 @@
|
||||
|
||||
(defn audit-transact [txes id]
|
||||
(try
|
||||
(dc/transact conn {:tx-data (conj txes {:db/id "datomic.tx"
|
||||
:audit/user (str (:user/role id) "-" (:user/name id))})})
|
||||
@(dc/transact conn (conj txes {:db/id "datomic.tx"
|
||||
:audit/user (str (:user/role id) "-" (:user/name id))}))
|
||||
(catch Exception e
|
||||
(mu/log ::transaction-error
|
||||
:exception e
|
||||
@@ -821,15 +831,24 @@
|
||||
|
||||
)
|
||||
|
||||
|
||||
(defn install-functions []
|
||||
@(datomic.api/transact auto-ap.datomic/conn [(datomic-fn :pay #'iol-ion.tx.pay/pay)
|
||||
(datomic-fn :plus #'iol-ion.tx.plus/plus)
|
||||
(datomic-fn :propose-invoice #'iol-ion.tx.propose-invoice/propose-invoice)
|
||||
(datomic-fn :reset-rels #'iol-ion.tx.reset-rels/reset-rels)
|
||||
(datomic-fn :reset-scalars #'iol-ion.tx.reset-scalars/reset-scalars)
|
||||
(datomic-fn :upsert-entity #'iol-ion.tx.upsert-entity/upsert-entity)
|
||||
(datomic-fn :upsert-invoice #'iol-ion.tx.upsert-invoice/upsert-invoice)
|
||||
(datomic-fn :upsert-ledger #'iol-ion.tx.upsert-ledger/upsert-ledger)
|
||||
(datomic-fn :upsert-transaction #'iol-ion.tx.upsert-transaction/upsert-transaction)]))
|
||||
|
||||
(defn transact-schema [conn]
|
||||
(dc/transact conn
|
||||
{:tx-data (edn/read-string (slurp (io/resource "schema.edn")))})
|
||||
@(dc/transact conn
|
||||
(edn/read-string (slurp (io/resource "schema.edn"))))
|
||||
|
||||
;; this is temporary for any new stuff that needs to be asserted for cloud migration.
|
||||
(dc/transact conn
|
||||
{:tx-data (edn/read-string (slurp (io/resource "cloud-migration-schema.edn")))}))
|
||||
@(dc/transact conn
|
||||
(edn/read-string (slurp (io/resource "cloud-migration-schema.edn")))))
|
||||
|
||||
(defn backoff [n]
|
||||
(let [base-timeout 500
|
||||
@@ -842,7 +861,7 @@
|
||||
([tx ] (transact-with-backoff tx 0))
|
||||
([tx attempt]
|
||||
(try
|
||||
(dc/transact conn {:tx-data tx})
|
||||
@(dc/transact conn tx)
|
||||
(catch Exception e
|
||||
(if (< attempt 10)
|
||||
(do
|
||||
@@ -870,3 +889,8 @@
|
||||
(#{"manager" "user" "power-user"} (:user/role id))
|
||||
(into #{}
|
||||
(map :db/id (:user/clients id [])))))
|
||||
|
||||
|
||||
(defn query2 [query]
|
||||
(apply dc/q (:query query) (:args query)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user