Getting closer to datomic cloud
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.api :as d]
|
||||
[datomic.client.api :as dc]
|
||||
[manifold.deferred :as de]
|
||||
[manifold.executor :as ex]
|
||||
[manifold.stream :as s]
|
||||
@@ -471,7 +471,7 @@
|
||||
(log/info ::transforming-settlements)
|
||||
(try
|
||||
(->> (for [settlement settlements
|
||||
:let [best-sales-date (some->> (d/q '[:find ?s4 (count ?s)
|
||||
:let [best-sales-date (some->> (dc/q '[:find ?s4 (count ?s)
|
||||
:in $ ?settlement-id
|
||||
:where
|
||||
[?settlement :expected-deposit/external-id ?settlement-id]
|
||||
@@ -481,7 +481,7 @@
|
||||
[(clj-time.coerce/to-date-time ?sales-date) ?s2]
|
||||
[(auto-ap.time/localize ?s2) ?s3]
|
||||
[(clj-time.coerce/to-local-date ?s3) ?s4]]
|
||||
(d/db conn)
|
||||
(dc/db conn)
|
||||
(str "square/settlement/" (:id settlement)))
|
||||
(sort-by last)
|
||||
last
|
||||
@@ -562,7 +562,7 @@
|
||||
(doseq [x (partition-all 100 results)]
|
||||
(log/info ::loading-orders
|
||||
:count (count x))
|
||||
@(d/transact conn x))))))))
|
||||
(dc/transact conn {:tx-data x}))))))))
|
||||
|
||||
|
||||
(defn upsert-settlements
|
||||
@@ -582,7 +582,7 @@
|
||||
(doseq [x (partition-all 20 settlements)]
|
||||
(log/info ::loading-deposits
|
||||
:count (count x))
|
||||
@(d/transact conn x))
|
||||
(dc/transact conn {:tx-data x}))
|
||||
(log/info ::done-loading-deposits)))))))
|
||||
|
||||
(defn upsert-refunds
|
||||
@@ -603,7 +603,7 @@
|
||||
(log/info ::loading-refunds
|
||||
:count (count x)
|
||||
:sample (first x))
|
||||
@(d/transact conn x))
|
||||
(dc/transact conn {:tx-data x}))
|
||||
|
||||
(catch Throwable e
|
||||
(log/error ::upsert-refunds-failed
|
||||
@@ -618,26 +618,26 @@
|
||||
|
||||
(defn get-square-clients
|
||||
([]
|
||||
(d/q '[:find [(pull ?c [:db/id
|
||||
:client/square-integration-status
|
||||
:client/code
|
||||
:client/square-auth-token
|
||||
{:client/square-locations [:db/id :square-location/name :square-location/square-id :square-location/client-location]}]) ...]
|
||||
:in $
|
||||
:where [?c :client/square-auth-token]
|
||||
[?c :client/feature-flags "new-square"]]
|
||||
(d/db conn)))
|
||||
(map first (dc/q '[:find (pull ?c [:db/id
|
||||
:client/square-integration-status
|
||||
:client/code
|
||||
:client/square-auth-token
|
||||
{:client/square-locations [:db/id :square-location/name :square-location/square-id :square-location/client-location]}])
|
||||
:in $
|
||||
:where [?c :client/square-auth-token]
|
||||
[?c :client/feature-flags "new-square"]]
|
||||
(dc/db conn))))
|
||||
([ & codes]
|
||||
(d/q '[:find [(pull ?c [:db/id
|
||||
:client/code
|
||||
:client/square-auth-token
|
||||
{:client/square-locations [:db/id :square-location/name :square-location/square-id :square-location/client-location]}]) ...]
|
||||
:in $ [?code ...]
|
||||
:where [?c :client/square-auth-token]
|
||||
[?c :client/feature-flags "new-square"]
|
||||
[?c :client/code ?code]]
|
||||
(d/db conn)
|
||||
codes)))
|
||||
(map first (dc/q '[:find (pull ?c [:db/id
|
||||
:client/code
|
||||
:client/square-auth-token
|
||||
{:client/square-locations [:db/id :square-location/name :square-location/square-id :square-location/client-location]}])
|
||||
:in $ [?code ...]
|
||||
:where [?c :client/square-auth-token]
|
||||
[?c :client/feature-flags "new-square"]
|
||||
[?c :client/code ?code]]
|
||||
(dc/db conn)
|
||||
codes))))
|
||||
|
||||
(defn upsert-locations
|
||||
([]
|
||||
@@ -653,30 +653,30 @@
|
||||
(:client/square-locations client)))]
|
||||
(de/chain (client-locations client)
|
||||
(fn [client-locations]
|
||||
@(d/transact conn
|
||||
(for [square-location client-locations]
|
||||
{:db/id (or (square-id->id (:id square-location)) (d/tempid :db.part/user))
|
||||
:client/_square-locations (:db/id client)
|
||||
:square-location/name (:name square-location)
|
||||
:square-location/square-id (:id square-location)})))))))
|
||||
(dc/transact conn
|
||||
{:tx-data (for [square-location client-locations]
|
||||
{:db/id (or (square-id->id (:id square-location)) (str (java.util.UUID/randomUUID)))
|
||||
:client/_square-locations (:db/id client)
|
||||
:square-location/name (:name square-location)
|
||||
:square-location/square-id (:id square-location)})}))))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn reset []
|
||||
(->>
|
||||
(d/query {:query {:find ['?e]
|
||||
(dc/q {:query {:find ['?e]
|
||||
:in ['$]
|
||||
:where ['(or [?e :sales-order/date]
|
||||
[?e :expected-deposit/date])]}
|
||||
:args [(d/db conn)]})
|
||||
:args [(dc/db conn)]})
|
||||
(map first)
|
||||
(map (fn [x] [:db/retractEntity x]))))
|
||||
|
||||
(defn mark-integration-status [client integration-status]
|
||||
@(d/transact conn
|
||||
[{:db/id (:db/id client)
|
||||
:client/square-integration-status (assoc integration-status
|
||||
:db/id (or (-> client :client/square-integration-status :db/id)
|
||||
#db/id [:db.part/user]))}]))
|
||||
(dc/transact conn
|
||||
{:tx-data [{:db/id (:db/id client)
|
||||
:client/square-integration-status (assoc integration-status
|
||||
:db/id (or (-> client :client/square-integration-status :db/id)
|
||||
(str (java.util.UUID/randomUUID))))}]}))
|
||||
|
||||
(defn upsert-all [ & clients]
|
||||
(capture-context->lc
|
||||
|
||||
Reference in New Issue
Block a user