Migrates back to datomic on-prem
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
result->page]]
|
||||
[auto-ap.search :as search]
|
||||
[auto-ap.utils :refer [heartbeat]]
|
||||
[datomic.client.api :as dc]
|
||||
[iol-ion.tx :refer [random-tempid upsert-entity]]
|
||||
[datomic.api :as dc]
|
||||
[iol-ion.tx :refer [random-tempid]]
|
||||
[mount.core :as mount]
|
||||
[yang.scheduler :as scheduler]))
|
||||
|
||||
@@ -38,36 +38,36 @@
|
||||
(defn upsert-account [context args _]
|
||||
(let [{{:keys [id client-overrides numeric-code location applicability account-set name invoice-allowance vendor-allowance type]} :account} (<-graphql args)]
|
||||
(when-not id
|
||||
(when (seq (dc/q {:query {:find ['?e]
|
||||
:in '[$ ?account-set ?numeric-code]
|
||||
:where ['[?e :account/account-set ?account-set]
|
||||
'[?e :account/numeric-code ?numeric-code]]}
|
||||
:args [(dc/db conn) account-set numeric-code]}))
|
||||
(when (seq (dc/q {:find ['?e]
|
||||
:in '[$ ?account-set ?numeric-code]
|
||||
:where ['[?e :account/account-set ?account-set]
|
||||
'[?e :account/numeric-code ?numeric-code]]}
|
||||
(dc/db conn) account-set numeric-code))
|
||||
|
||||
(throw (ex-info (str "Account set " account-set " already has an account for code " numeric-code)
|
||||
{} ))))
|
||||
(let [result (audit-transact [`(upsert-entity
|
||||
~(cond-> {:db/id (or id "new-account")
|
||||
:account/name name
|
||||
:account/search-terms name
|
||||
:account/type (keyword "account-type" (clojure.core/name type))
|
||||
:account/applicability (or (enum->keyword applicability "account-applicability")
|
||||
:account-applicability/global)
|
||||
:account/invoice-allowance (some-> invoice-allowance (enum->keyword "allowance"))
|
||||
:account/vendor-allowance (some-> vendor-allowance (enum->keyword "allowance"))
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/account-set account-set
|
||||
:account/location location
|
||||
:account/numeric-code numeric-code
|
||||
:account/code (str numeric-code)
|
||||
:account/client-overrides (mapv
|
||||
(fn [client-override]
|
||||
{:db/id (or (:id client-override) (random-tempid))
|
||||
:account-client-override/client (:client-id client-override)
|
||||
:account-client-override/name (:name client-override)
|
||||
:account-client-override/search-terms (:name client-override)})
|
||||
client-overrides)}
|
||||
id (dissoc :account/numeric-code :account/code)))]
|
||||
(let [result (audit-transact [[:upsert-entity
|
||||
(cond-> {:db/id (or id "new-account")
|
||||
:account/name name
|
||||
:account/search-terms name
|
||||
:account/type (keyword "account-type" (clojure.core/name type))
|
||||
:account/applicability (or (enum->keyword applicability "account-applicability")
|
||||
:account-applicability/global)
|
||||
:account/invoice-allowance (some-> invoice-allowance (enum->keyword "allowance"))
|
||||
:account/vendor-allowance (some-> vendor-allowance (enum->keyword "allowance"))
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/account-set account-set
|
||||
:account/location location
|
||||
:account/numeric-code numeric-code
|
||||
:account/code (str numeric-code)
|
||||
:account/client-overrides (mapv
|
||||
(fn [client-override]
|
||||
{:db/id (or (:id client-override) (random-tempid))
|
||||
:account-client-override/client (:client-id client-override)
|
||||
:account-client-override/name (:name client-override)
|
||||
:account-client-override/search-terms (:name client-override)})
|
||||
client-overrides)}
|
||||
id (dissoc :account/numeric-code :account/code))]]
|
||||
(:id context))]
|
||||
(->graphql
|
||||
(d-accounts/get-by-id (or id (get-in result [:tempids "new-account"])))))))
|
||||
@@ -149,12 +149,12 @@
|
||||
|
||||
(defn rebuild-search-index []
|
||||
(search/full-index-query
|
||||
(for [result (map first (dc/qseq '[:find (pull ?aco [:account-client-override/search-terms :account-client-override/client :db/id {:account/_client-overrides [:account/numeric-code :account/location :db/id]}])
|
||||
:in $
|
||||
:where [?aco :account-client-override/client ]
|
||||
[?aco :account-client-override/search-terms ]
|
||||
[_ :account/client-overrides ?aco]]
|
||||
(dc/db conn)))
|
||||
(for [result (map first (dc/qseq {:query '[:find (pull ?aco [:account-client-override/search-terms :account-client-override/client :db/id {:account/_client-overrides [:account/numeric-code :account/location :db/id]}])
|
||||
:in $
|
||||
:where [?aco :account-client-override/client ]
|
||||
[?aco :account-client-override/search-terms ]
|
||||
[_ :account/client-overrides ?aco]]
|
||||
:args [(dc/db conn)]}))
|
||||
:when (:account/numeric-code (:account/_client-overrides result))]
|
||||
{:id (:db/id (:account/_client-overrides result))
|
||||
:account-client-override-id (:db/id result)
|
||||
@@ -165,14 +165,14 @@
|
||||
"account-client-override")
|
||||
|
||||
(search/full-index-query
|
||||
(for [result (map first (dc/qseq '[:find (pull ?a [:account/numeric-code
|
||||
:account/search-terms
|
||||
{:account/applicability [:db/ident]}
|
||||
:db/id
|
||||
:account/location])
|
||||
:in $
|
||||
:where [?a :account/search-terms ]]
|
||||
(dc/db conn)))
|
||||
(for [result (map first (dc/qseq {:query '[:find (pull ?a [:account/numeric-code
|
||||
:account/search-terms
|
||||
{:account/applicability [:db/ident]}
|
||||
:db/id
|
||||
:account/location])
|
||||
:in $
|
||||
:where [?a :account/search-terms ]]
|
||||
:args [(dc/db conn)]}))
|
||||
:when (:account/search-terms result)
|
||||
]
|
||||
{:id (:db/id result)
|
||||
@@ -183,11 +183,11 @@
|
||||
"account"))
|
||||
|
||||
#_(dc/transact conn
|
||||
{:tx-data [{:db/ident :account-client-override/k2
|
||||
:db/valueType :db.type/tuple
|
||||
:db/tupleAttrs [:account/_client-overrides :account-client-override/client ]
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/unique :db.unique/identity}]})
|
||||
[{:db/ident :account-client-override/k2
|
||||
:db/valueType :db.type/tuple
|
||||
:db/tupleAttrs [:account/_client-overrides :account-client-override/client ]
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/unique :db.unique/identity}])
|
||||
|
||||
#_(dc/q '[:find ?o
|
||||
:where [_ :account-client-override/k ?o]]
|
||||
|
||||
Reference in New Issue
Block a user