Add vendor pre-population for bulk code and individual edit forms
- Add vendor-changed HTMX handlers for both bulk code and individual edit - Pre-populate default account at 100% when vendor is selected and no accounts exist - Fix render-accounts-section to render from step-params correctly - Change bulk code vendor-changed from hx-get to hx-post to include form data - Add routes for vendor-changed endpoints - Update e2e tests to cover vendor pre-population - Run lein cljfmt fix across codebase
This commit is contained in:
@@ -20,32 +20,29 @@
|
||||
(def buffered (ex/fixed-thread-executor 100))
|
||||
|
||||
(defn order-of-insert [entity-dependencies]
|
||||
(loop [entity-dependencies entity-dependencies
|
||||
(loop [entity-dependencies entity-dependencies
|
||||
order []]
|
||||
(let [next-order (for [[entity deps] entity-dependencies
|
||||
:when (not (seq deps))]
|
||||
entity)
|
||||
next-deps (reduce
|
||||
(fn [entity-dependencies next-entity]
|
||||
(into {}
|
||||
(map
|
||||
(fn [[k v]]
|
||||
[k (disj v next-entity)])
|
||||
entity-dependencies)))
|
||||
(apply dissoc entity-dependencies next-order)
|
||||
next-order)]
|
||||
(fn [entity-dependencies next-entity]
|
||||
(into {}
|
||||
(map
|
||||
(fn [[k v]]
|
||||
[k (disj v next-entity)])
|
||||
entity-dependencies)))
|
||||
(apply dissoc entity-dependencies next-order)
|
||||
next-order)]
|
||||
(if (seq next-deps)
|
||||
(recur next-deps (into order next-order))
|
||||
(into order next-order)))))
|
||||
|
||||
|
||||
|
||||
|
||||
(def loaded (atom #{}))
|
||||
|
||||
(defn upsert-batch
|
||||
[batch context]
|
||||
(de/future-with request-pool
|
||||
(de/future-with request-pool
|
||||
(mu/with-context context
|
||||
(transact-with-backoff batch))
|
||||
batch))
|
||||
@@ -68,39 +65,39 @@
|
||||
(mu/with-context {:entity entity}
|
||||
(mu/log ::starting)
|
||||
@(s/consume (fn [batch]
|
||||
(mu/with-context {:entity entity}
|
||||
(try
|
||||
(swap! so-far #(+ % (count batch)))
|
||||
(mu/log ::loaded :count (count batch)
|
||||
:so-far @so-far)
|
||||
(catch Exception e
|
||||
(mu/log ::error
|
||||
:exception e)
|
||||
(throw e)))))
|
||||
(->> (partition-all 1000 entities)
|
||||
(s/->source)
|
||||
(s/onto buffered)
|
||||
(s/map (fn [entities]
|
||||
(when @die?
|
||||
(reset! die? false)
|
||||
(throw (Exception. "dead")))
|
||||
(upsert-batch entities {:entity entity
|
||||
:service "restore-from-backup"
|
||||
:background-job "restore-from-backup"})))
|
||||
(s/buffer 20)
|
||||
(s/realize-each)))
|
||||
(mu/with-context {:entity entity}
|
||||
(try
|
||||
(swap! so-far #(+ % (count batch)))
|
||||
(mu/log ::loaded :count (count batch)
|
||||
:so-far @so-far)
|
||||
(catch Exception e
|
||||
(mu/log ::error
|
||||
:exception e)
|
||||
(throw e)))))
|
||||
(->> (partition-all 1000 entities)
|
||||
(s/->source)
|
||||
(s/onto buffered)
|
||||
(s/map (fn [entities]
|
||||
(when @die?
|
||||
(reset! die? false)
|
||||
(throw (Exception. "dead")))
|
||||
(upsert-batch entities {:entity entity
|
||||
:service "restore-from-backup"
|
||||
:background-job "restore-from-backup"})))
|
||||
(s/buffer 20)
|
||||
(s/realize-each)))
|
||||
(swap! loaded conj entity))))
|
||||
|
||||
(defn load-from-backup
|
||||
(defn load-from-backup
|
||||
([backup-id connection] (load-from-backup backup-id connection nil))
|
||||
([backup-id connection starting-at]
|
||||
(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 [{:db/ident :entity/migration-key
|
||||
:db/unique :db.unique/identity
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/valueType :db.type/long}])
|
||||
: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}))
|
||||
@@ -108,14 +105,13 @@
|
||||
|
||||
;; TEMP - this has been fixed in current export (ezcater-olaciotn)
|
||||
@(dc/transact connection [{:entity/migration-key 17592257603901 :vendor/name "unknown"}
|
||||
{:entity/migration-key 17592232621701}
|
||||
{:entity/migration-key 17592263907739}
|
||||
{:entity/migration-key 17592271516922}])
|
||||
|
||||
{:entity/migration-key 17592232621701}
|
||||
{:entity/migration-key 17592263907739}
|
||||
{:entity/migration-key 17592271516922}])
|
||||
|
||||
(doseq [entity (cond->> (order-of-insert entity-dependencies)
|
||||
true (filter #(not= "audit" %))
|
||||
starting-at (drop-while #(not= starting-at %)))
|
||||
starting-at (drop-while #(not= starting-at %)))
|
||||
:let [_ (reset! so-far 0)
|
||||
_ (mu/log ::querying :entity entity)
|
||||
entities (mu/trace ::file-pulled
|
||||
@@ -136,9 +132,8 @@
|
||||
(mu/log ::refresh-running-balance-cache-complete)
|
||||
(mu/log ::done))
|
||||
|
||||
|
||||
(defn -main [& _]
|
||||
(try
|
||||
(try
|
||||
(println "restore")
|
||||
(execute "restore-from-backup" #(restore-fresh-from-backup (:args env)))
|
||||
(catch Exception e
|
||||
@@ -151,13 +146,11 @@
|
||||
(throw e))))
|
||||
|
||||
;; cloud load
|
||||
#_(comment
|
||||
#_(comment
|
||||
|
||||
;; /datomic-backup/079df203-eae0-4acf-94d5-8608ba8b8a9a
|
||||
(load-from-backup "079df203-eae0-4acf-94d5-8608ba8b8a9a" auto-ap.datomic/conn ["charge"])
|
||||
(load-from-backup "079df203-eae0-4acf-94d5-8608ba8b8a9a" auto-ap.datomic/conn ["charge"])
|
||||
|
||||
(load-entity "charge" (ednl/slurp "/tmp/tmp-edn"))
|
||||
(load-entity "charge" (ednl/slurp "/tmp/tmp-edn")))
|
||||
|
||||
|
||||
)
|
||||
;; => nil
|
||||
|
||||
Reference in New Issue
Block a user