Migrates back to datomic on-prem
This commit is contained in:
@@ -6,23 +6,23 @@
|
||||
[auto-ap.time :as time]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.client.api :as dc]))
|
||||
[datomic.api :as dc]))
|
||||
|
||||
(defn close-auto-invoices []
|
||||
(let [invoices-to-close (dc/q {:query {:find ['?e]
|
||||
:in ['$ '?today]
|
||||
:where ['[?e :invoice/scheduled-payment ?d]
|
||||
'[?e :invoice/status :invoice-status/unpaid]
|
||||
'[(<= ?d ?today)]]}
|
||||
:args [(dc/db conn) (coerce/to-date (time/local-now))]})]
|
||||
(let [invoices-to-close (dc/q {:find ['?e]
|
||||
:in ['$ '?today]
|
||||
:where ['[?e :invoice/scheduled-payment ?d]
|
||||
'[?e :invoice/status :invoice-status/unpaid]
|
||||
'[(<= ?d ?today)]]}
|
||||
(dc/db conn) (coerce/to-date (time/local-now)))]
|
||||
(log/info "Closing " (count invoices-to-close) "scheduled invoices")
|
||||
(dc/transact conn {:tx-data (some->> invoices-to-close
|
||||
seq
|
||||
@(dc/transact conn (some->> invoices-to-close
|
||||
seq
|
||||
|
||||
(mapv (fn [[i]] {:db/id i
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/paid}))
|
||||
)})
|
||||
(mapv (fn [[i]] {:db/id i
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/paid}))
|
||||
))
|
||||
(log/info "Closed " (count invoices-to-close) "scheduled invoices")))
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(ns auto-ap.jobs.core
|
||||
(:require [auto-ap.utils :refer [heartbeat]]
|
||||
[mount.core :as mount]
|
||||
[auto-ap.datomic :refer [conn client]]
|
||||
[auto-ap.datomic :refer [conn ]]
|
||||
[clojure.tools.logging :as log]
|
||||
[nrepl.server :refer [start-server]]
|
||||
[auto-ap.background.metrics :refer [metrics-setup container-tags container-data logging-context]]
|
||||
@@ -13,7 +13,7 @@
|
||||
(lc/with-context {:background-job name}
|
||||
(mu/with-context {:background-job name
|
||||
:service name}
|
||||
(mount/start (mount/only #{#'conn #'client #'metrics-setup #'container-tags #'logging-context #'container-data }))
|
||||
(mount/start (mount/only #{#'conn #'metrics-setup #'container-tags #'logging-context #'container-data }))
|
||||
(start-server :port 9000 :bind "0.0.0.0" #_#_:handler (cider-nrepl-handler))
|
||||
((heartbeat f name))
|
||||
(log/info "Stopping " name)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
[clj-time.periodic :as per]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[unilog.context :as lc]))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
[clojure.string :as str]
|
||||
[clojure.xml :as xml]
|
||||
[clojure.zip :as zip]
|
||||
[datomic.client.api :as d]
|
||||
[iol-ion.tx :refer [propose-invoice random-tempid]])
|
||||
[datomic.api :as d]
|
||||
[iol-ion.tx :refer [random-tempid]])
|
||||
(:import
|
||||
(java.util UUID)))
|
||||
|
||||
@@ -249,7 +249,7 @@
|
||||
:invoice i)
|
||||
i))
|
||||
(mapv (fn [i]
|
||||
`(propose-invoice ~(assoc i :invoice/source-url invoice-url))))))) (catch Exception e
|
||||
[:propose-invoice (assoc i :invoice/source-url invoice-url)]))))) (catch Exception e
|
||||
(log/error ::cant-load-file
|
||||
:key k
|
||||
:exception e)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]
|
||||
[datomic.client.api :as dc])
|
||||
[datomic.api :as dc])
|
||||
(:import
|
||||
(java.util UUID)))
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
[clojure.set :as set]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[config.core :refer [env]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[lambdaisland.edn-lines :as ednl]
|
||||
[manifold.deferred :as de]
|
||||
[manifold.executor :as ex]
|
||||
@@ -97,20 +97,20 @@
|
||||
(let [schema (edn/read-string (slurp (pull-file backup-id "schema.edn")))
|
||||
full-dependencies (edn/read-string (slurp (pull-file backup-id "full-dependencies.edn")))
|
||||
entity-dependencies (edn/read-string (slurp (pull-file backup-id "entity-dependencies.edn")))]
|
||||
(dc/transact connection {:tx-data [{:db/ident :entity/migration-key
|
||||
:db/unique :db.unique/identity
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/valueType :db.type/long}]})
|
||||
(dc/transact connection {:tx-data (map
|
||||
(fn [s]
|
||||
(set/rename-keys s {:db/id :entity/migration-key}))
|
||||
schema)})
|
||||
@(dc/transact connection [{:db/ident :entity/migration-key
|
||||
:db/unique :db.unique/identity
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/valueType :db.type/long}])
|
||||
@(dc/transact connection (map
|
||||
(fn [s]
|
||||
(set/rename-keys s {:db/id :entity/migration-key}))
|
||||
schema))
|
||||
|
||||
;; TEMP - this has been fixed in current export (ezcater-olaciotn)
|
||||
(dc/transact connection {:tx-data [{:entity/migration-key 17592257603901 :vendor/name "unknown"}
|
||||
{:entity/migration-key 17592232621701}
|
||||
{:entity/migration-key 17592263907739}
|
||||
{:entity/migration-key 17592271516922}]})
|
||||
@(dc/transact connection [{:entity/migration-key 17592257603901 :vendor/name "unknown"}
|
||||
{:entity/migration-key 17592232621701}
|
||||
{:entity/migration-key 17592263907739}
|
||||
{:entity/migration-key 17592271516922}])
|
||||
|
||||
|
||||
(doseq [entity (cond->> (order-of-insert entity-dependencies)
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
[auto-ap.datomic :refer [audit-transact]]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.invoices :refer [code-invoice]]
|
||||
[iol-ion.tx :refer [propose-invoice]]
|
||||
[auto-ap.parse :as parse]
|
||||
[auto-ap.time :as t]
|
||||
[clj-time.coerce :as coerce]
|
||||
@@ -16,7 +15,7 @@
|
||||
[clojure.tools.logging :as log]
|
||||
[com.unbounce.dogstatsd.core :as statsd]
|
||||
[config.core :refer [env]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[auto-ap.datomic.vendors :as d-vendors])
|
||||
(:import
|
||||
(java.util UUID)))
|
||||
@@ -134,11 +133,11 @@
|
||||
:destination-bucket-name (:data-bucket env)
|
||||
:source-key k
|
||||
:destination-key invoice-key})
|
||||
[`(propose-invoice
|
||||
~(-> k
|
||||
[[:propose-invoice
|
||||
(-> k
|
||||
read-sysco-csv
|
||||
(extract-invoice-details sysco-vendor)
|
||||
(assoc :invoice/source-url invoice-url)))])
|
||||
(assoc :invoice/source-url invoice-url))]])
|
||||
(catch Exception e
|
||||
(log/error (str "Cannot load file " k) e)
|
||||
(log/info
|
||||
|
||||
@@ -3,29 +3,29 @@
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.jobs.core :refer [execute]]
|
||||
[datomic.client.api :as dc]))
|
||||
[datomic.api :as dc]))
|
||||
|
||||
(defn refresh-vendor-usages []
|
||||
(dc/transact conn {:tx-data (->> (dc/q '[:find ?v ?c (count ?e)
|
||||
:in $
|
||||
:where
|
||||
[?v :vendor/name]
|
||||
(or-join [?v ?c ?e]
|
||||
(and
|
||||
[?e :invoice/vendor ?v]
|
||||
[?e :invoice/client ?c])
|
||||
(and
|
||||
[?e :transaction/vendor ?v]
|
||||
[?e :transaction/client ?c])
|
||||
(and
|
||||
[?e :journal-entry/vendor ?v]
|
||||
[?e :journal-entry/client ?c]))]
|
||||
(dc/db conn))
|
||||
(map (fn [[v c cnt]]
|
||||
#:vendor-usage {:vendor v
|
||||
:client c
|
||||
:key (str v "-" c)
|
||||
:count cnt})))}))
|
||||
@(dc/transact conn (->> (dc/q '[:find ?v ?c (count ?e)
|
||||
:in $
|
||||
:where
|
||||
[?v :vendor/name]
|
||||
(or-join [?v ?c ?e]
|
||||
(and
|
||||
[?e :invoice/vendor ?v]
|
||||
[?e :invoice/client ?c])
|
||||
(and
|
||||
[?e :transaction/vendor ?v]
|
||||
[?e :transaction/client ?c])
|
||||
(and
|
||||
[?e :journal-entry/vendor ?v]
|
||||
[?e :journal-entry/client ?c]))]
|
||||
(dc/db conn))
|
||||
(map (fn [[v c cnt]]
|
||||
#:vendor-usage {:vendor v
|
||||
:client c
|
||||
:key (str v "-" c)
|
||||
:count cnt})))))
|
||||
|
||||
(defn -main [& _]
|
||||
(execute "vendor-usages" refresh-vendor-usages))
|
||||
|
||||
Reference in New Issue
Block a user