Migrates back to datomic on-prem

This commit is contained in:
2023-04-29 07:12:51 -07:00
parent aca8f7c92c
commit b2ad7790cf
88 changed files with 2289 additions and 2286 deletions

View File

@@ -18,9 +18,9 @@
[clojure.string :as str]
[clojure.tools.logging :as log]
[config.core :refer [env]]
[datomic.client.api :as dc]
[datomic.api :as dc]
[digest]
[iol-ion.tx :refer [propose-invoice random-tempid]]
[iol-ion.tx :refer [random-tempid]]
[ring.middleware.json :refer [wrap-json-response]]
[unilog.context :as lc])
(:import
@@ -114,10 +114,10 @@
{:vendor-code vendor-code})))
(let [vendor-id (or forced-vendor
(->> (dc/q
{:query {:find ['?vendor]
:in ['$ '?vendor-name]
:where ['[?vendor :vendor/name ?vendor-name]]}
:args [(dc/db conn) vendor-code]})
{:find ['?vendor]
:in ['$ '?vendor-name]
:where ['[?vendor :vendor/name ?vendor-name]]}
(dc/db conn) vendor-code)
first
first))]
(when-not vendor-id
@@ -125,9 +125,9 @@
{:vendor-code vendor-code})))
(if-let [matching-vendor (->> (dc/q
{:query {:find [(list 'pull '?vendor-id d-vendors/default-read)]
:in ['$ '?vendor-id]}
:args [(dc/db conn) vendor-id]})
{:find [(list 'pull '?vendor-id d-vendors/default-read)]
:in ['$ '?vendor-id]}
(dc/db conn) vendor-id)
first
first)]
matching-vendor
@@ -231,8 +231,8 @@
:transaction-account/location "A"
:transaction-account/amount (Math/abs (:invoice/total invoice))}]}))
]
[`(propose-invoice ~(d-invoices/code-invoice (validate-invoice (remove-nils invoice)
user)))
[[:propose-invoice (d-invoices/code-invoice (validate-invoice (remove-nils invoice)
user))]
(some-> payment remove-nils)
transaction])))
(filter identity)))
@@ -252,7 +252,7 @@
(map #(validate-invoice % user))
admin-only-if-multiple-clients
(mapv d-invoices/code-invoice)
(mapv (fn [i] `(propose-invoice ~i))))]
(mapv (fn [i] [:propose-invoice i])))]
(log/info "creating invoice" potential-invoices)
(let [tx (audit-transact potential-invoices user)]
@@ -288,21 +288,23 @@
(defn import-account-overrides [customer filename]
(let [[_ & rows] (-> filename (io/reader) csv/read-csv)
[client-id] (first (dc/q (-> {:query {:find ['?e]
:in ['$ '?z]
:where [['?e :client/code '?z]]}
:args [(dc/db conn) customer]})))
code->existing-account (by :account/numeric-code (map first (dc/q {:query {:find ['(pull ?e [:account/numeric-code
{:account/applicability [:db/ident]}
:db/id])]
:in ['$]
:where ['[?e :account/name]]}
:args [(dc/db conn)]})))
[client-id] (first (dc/q (-> {:find ['?e]
:in ['$ '?z]
:where [['?e :client/code '?z]]}
(dc/db conn)
customer)))
code->existing-account (by :account/numeric-code (map first (dc/q {:find ['(pull ?e [:account/numeric-code
{:account/applicability [:db/ident]}
:db/id])]
:in ['$]
:where ['[?e :account/name]]}
(dc/db conn))))
existing-account-overrides (dc/q (-> {:query {:find ['?e]
:in ['$ '?client-id]
:where [['?e :account-client-override/client '?client-id]]}
:args [(dc/db conn) client-id]}))
existing-account-overrides (dc/q (-> {:find ['?e]
:in ['$ '?client-id]
:where [['?e :account-client-override/client '?client-id]]}
(dc/db conn)
client-id))
rows (transduce (comp
(map (fn [[_ account account-name override-name _ type]]
[account account-name override-name type]))
@@ -357,7 +359,7 @@
existing-account-overrides)
rows)]
(dc/transact conn {:tx-data txes})
@(dc/transact conn txes)
txes))
(defn import-transactions-cleared-against [file]