Migrates back to datomic on-prem
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[slingshot.slingshot :refer [try+]]
|
||||
[unilog.context :as lc]))
|
||||
|
||||
@@ -395,11 +395,11 @@
|
||||
(upsert client square-location (time/plus (time/now) (time/days -3)) (time/now))))
|
||||
([client location start end]
|
||||
(lc/with-context {:source "Square loading"}
|
||||
(let [existing (->> (dc/q {:query {:find ['?external-id]
|
||||
:in ['$ '?client]
|
||||
:where ['[?o :sales-order/client ?client]
|
||||
'[?o :sales-order/external-id ?external-id]]}
|
||||
:args [(dc/db conn) (:db/id client)]})
|
||||
(let [existing (->> (dc/q {:find ['?external-id]
|
||||
:in ['$ '?client]
|
||||
:where ['[?o :sales-order/client ?client]
|
||||
'[?o :sales-order/external-id ?external-id]]}
|
||||
(dc/db conn) (:db/id client))
|
||||
(map first)
|
||||
set)
|
||||
_ (log/info (count existing) "Sales orders already exist")
|
||||
@@ -407,7 +407,7 @@
|
||||
(daily-results client location start end))]
|
||||
(doseq [x (partition-all 20 to-create)]
|
||||
(log/info "Loading " (count x))
|
||||
(dc/transact conn {:tx-data x}))))))
|
||||
@(dc/transact conn x))))))
|
||||
|
||||
(defn upsert-settlements
|
||||
([client]
|
||||
@@ -419,7 +419,7 @@
|
||||
:client (:client/code client)}
|
||||
(doseq [x (partition-all 20 (daily-settlements client location))]
|
||||
(log/info "Loading expected deposit" (count x))
|
||||
(dc/transact conn {:tx-data x}))
|
||||
@(dc/transact conn x))
|
||||
(log/info "Done loading settlements"))))
|
||||
|
||||
(defn upsert-refunds
|
||||
@@ -433,7 +433,7 @@
|
||||
:location (:square-location/client-location client)}
|
||||
(doseq [x (partition-all 20 (refunds client location))]
|
||||
(log/info "Loading refund" (count x))
|
||||
(dc/transact conn {:tx-data x}))
|
||||
@(dc/transact conn x))
|
||||
(log/info "Done loading refunds"))))
|
||||
|
||||
(def square-read [:db/id
|
||||
@@ -474,29 +474,29 @@
|
||||
[(:square-location/square-id sl)
|
||||
(:db/id sl)])
|
||||
(:client/square-locations client)))]
|
||||
(dc/transact conn {:tx-data (for [square-location (client-locations client)]
|
||||
{:db/id (or (square-id->id (:id square-location)) (random-tempid))
|
||||
:client/_square-locations (:db/id client)
|
||||
:square-location/name (:name square-location)
|
||||
:square-location/square-id (:id square-location)})}))))
|
||||
@(dc/transact conn (for [square-location (client-locations client)]
|
||||
{:db/id (or (square-id->id (:id square-location)) (random-tempid))
|
||||
: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 []
|
||||
(->>
|
||||
(dc/q {:query {:find ['?e]
|
||||
:in ['$]
|
||||
:where ['(or [?e :sales-order/date]
|
||||
[?e :expected-deposit/date])]}
|
||||
:args [(dc/db conn)]})
|
||||
(dc/q {:find ['?e]
|
||||
:in ['$]
|
||||
:where ['(or [?e :sales-order/date]
|
||||
[?e :expected-deposit/date])]}
|
||||
(dc/db conn))
|
||||
(map first)
|
||||
(map (fn [x] [:db/retractEntity x]))))
|
||||
|
||||
(defn mark-integration-status [client integration-status]
|
||||
(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)
|
||||
(random-tempid)))}]}))
|
||||
@(dc/transact conn
|
||||
[{:db/id (:db/id client)
|
||||
:client/square-integration-status (assoc integration-status
|
||||
:db/id (or (-> client :client/square-integration-status :db/id)
|
||||
(random-tempid)))}]))
|
||||
|
||||
(defn upsert-all [ & clients]
|
||||
(doseq [client (apply get-square-clients clients)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[cemerick.url :as url]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[slingshot.slingshot :refer [try+]]
|
||||
[unilog.context :as lc]))
|
||||
|
||||
@@ -399,7 +399,7 @@
|
||||
(lc/with-context {:source "Square loading"}
|
||||
(doseq [x (partition-all 20 (daily-results client location start end))]
|
||||
(log/info "Loading " (count x))
|
||||
(dc/transact conn {:tx-data x})))))
|
||||
@(dc/transact conn x)))))
|
||||
|
||||
(defn upsert-settlements
|
||||
([client]
|
||||
@@ -411,7 +411,7 @@
|
||||
:client (:client/code client)}
|
||||
(doseq [x (partition-all 20 (daily-settlements client location))]
|
||||
(log/info "Loading expected deposit" (count x))
|
||||
(dc/transact conn {:tx-data x}))
|
||||
@(dc/transact conn x))
|
||||
(log/info "Done loading settlements"))))
|
||||
|
||||
(defn upsert-refunds
|
||||
@@ -425,7 +425,7 @@
|
||||
:location (:square-location/client-location client)}
|
||||
(doseq [x (partition-all 20 (refunds client location))]
|
||||
(log/info "Loading refund" (count x))
|
||||
(dc/transact conn {:tx-data x}))
|
||||
@(dc/transact conn x))
|
||||
(log/info "Done loading refunds"))))
|
||||
|
||||
(def square-read [:db/id
|
||||
@@ -466,29 +466,29 @@
|
||||
[(:square-location/square-id sl)
|
||||
(:db/id sl)])
|
||||
(:client/square-locations client)))]
|
||||
(dc/transact conn {:tx-data (for [square-location (client-locations client)]
|
||||
{:db/id (or (square-id->id (:id square-location)) (random-tempid))
|
||||
:client/_square-locations (:db/id client)
|
||||
:square-location/name (:name square-location)
|
||||
:square-location/square-id (:id square-location)})}))))
|
||||
@(dc/transact conn (for [square-location (client-locations client)]
|
||||
{:db/id (or (square-id->id (:id square-location)) (random-tempid))
|
||||
: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 []
|
||||
(->>
|
||||
(dc/q {:query {:find ['?e]
|
||||
:in ['$]
|
||||
:where ['(or [?e :sales-order/date]
|
||||
[?e :expected-deposit/date])]}
|
||||
:args [(dc/db conn)]})
|
||||
(dc/q {:find ['?e]
|
||||
:in ['$]
|
||||
:where ['(or [?e :sales-order/date]
|
||||
[?e :expected-deposit/date])]}
|
||||
(dc/db conn))
|
||||
(map first)
|
||||
(map (fn [x] [:db/retractEntity x]))))
|
||||
|
||||
(defn mark-integration-status [client integration-status]
|
||||
(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)
|
||||
(random-tempid)))}]}))
|
||||
@(dc/transact conn
|
||||
[{:db/id (:db/id client)
|
||||
:client/square-integration-status (assoc integration-status
|
||||
:db/id (or (-> client :client/square-integration-status :db/id)
|
||||
(random-tempid)))}]))
|
||||
|
||||
(defn upsert-all [ & clients]
|
||||
(doseq [client (apply get-square-clients clients)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[manifold.deferred :as de]
|
||||
[manifold.executor :as ex]
|
||||
[manifold.stream :as s]
|
||||
@@ -562,7 +562,7 @@
|
||||
(doseq [x (partition-all 100 results)]
|
||||
(log/info ::loading-orders
|
||||
:count (count x))
|
||||
(dc/transact conn {:tx-data x}))))))))
|
||||
@(dc/transact conn x))))))))
|
||||
|
||||
|
||||
(defn upsert-settlements
|
||||
@@ -582,7 +582,7 @@
|
||||
(doseq [x (partition-all 20 settlements)]
|
||||
(log/info ::loading-deposits
|
||||
:count (count x))
|
||||
(dc/transact conn {:tx-data x}))
|
||||
@(dc/transact conn x))
|
||||
(log/info ::done-loading-deposits)))))))
|
||||
|
||||
(defn upsert-refunds
|
||||
@@ -603,7 +603,7 @@
|
||||
(log/info ::loading-refunds
|
||||
:count (count x)
|
||||
:sample (first x))
|
||||
(dc/transact conn {:tx-data x}))
|
||||
@(dc/transact conn x))
|
||||
|
||||
(catch Throwable e
|
||||
(log/error ::upsert-refunds-failed
|
||||
@@ -653,30 +653,30 @@
|
||||
(:client/square-locations client)))]
|
||||
(de/chain (client-locations client)
|
||||
(fn [client-locations]
|
||||
(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)})}))))))
|
||||
@(dc/transact conn
|
||||
(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 []
|
||||
(->>
|
||||
(dc/q {:query {:find ['?e]
|
||||
:in ['$]
|
||||
:where ['(or [?e :sales-order/date]
|
||||
[?e :expected-deposit/date])]}
|
||||
:args [(dc/db conn)]})
|
||||
(dc/q {:find ['?e]
|
||||
:in ['$]
|
||||
:where ['(or [?e :sales-order/date]
|
||||
[?e :expected-deposit/date])]}
|
||||
(dc/db conn))
|
||||
(map first)
|
||||
(map (fn [x] [:db/retractEntity x]))))
|
||||
|
||||
(defn mark-integration-status [client integration-status]
|
||||
(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))))}]}))
|
||||
@(dc/transact conn
|
||||
[{: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