From 93077fa25de258340494bae9d2f3aa2c335abec7 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 28 Mar 2023 20:18:33 -0700 Subject: [PATCH] change --- config/dev.edn | 2 +- .../clj/auto_ap/jobs}/restore_from_backup.clj | 34 ++++++++----------- 2 files changed, 16 insertions(+), 20 deletions(-) rename {scratch-sessions => src/clj/auto_ap/jobs}/restore_from_backup.clj (85%) diff --git a/config/dev.edn b/config/dev.edn index 224aa5d1..b6d2c2ad 100644 --- a/config/dev.edn +++ b/config/dev.edn @@ -2,7 +2,7 @@ :scheme "http" :client-config {:server-type :dev-local :system "dev"} - :db-name "prod-migration" + :db-name "prod-migration2" :jwt-secret "auto ap invoices are awesome" :aws-access-key-id "AKIAJIS67OSJARD2E6VQ" :aws-secret-access-key "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" diff --git a/scratch-sessions/restore_from_backup.clj b/src/clj/auto_ap/jobs/restore_from_backup.clj similarity index 85% rename from scratch-sessions/restore_from_backup.clj rename to src/clj/auto_ap/jobs/restore_from_backup.clj index dbf1d99b..d4523cde 100644 --- a/scratch-sessions/restore_from_backup.clj +++ b/src/clj/auto_ap/jobs/restore_from_backup.clj @@ -1,9 +1,10 @@ -(ns restore-from-backup +(ns auto-ap.jobs.restore-from-backup (:require [clojure.java.io :as io] [amazonica.aws.s3 :as s3] [config.core :refer [env]] [clojure.core.async :as a] [datomic.client.api :as dc] + [auto-ap.datomic :refer [client]] [lambdaisland.edn-lines :as ednl] [datomic.client.api.async :as dca] [datomic.dev-local :as dl] @@ -11,19 +12,6 @@ [clojure.string :as str] [clj-http.client :as client])) - - -(def client auto-ap.datomic/client) - - - - - - - - - - (defn order-of-insert [entity-dependencies] (loop [entity-dependencies entity-dependencies order []] @@ -96,12 +84,20 @@ +(defn pull-file [backup which] + (with-open [w (io/writer "/tmp/tmp-edn")] + (io/copy (:input-stream (s3/get-object {:bucket-name "data.prod.app.integreatconsult.com" + :key (str "/datomic-backup/" backup "/" which)})) + w)) + "/tmp/tmp-edn") + + (defn load-from-backup ([backup-id connection] (load-from-backup backup-id connection nil)) ([backup-id connection item-list] - (let [schema (clojure.edn/read-string (slurp (str backup-id "/schema.edn"))) - full-dependencies (clojure.edn/read-string (slurp (str backup-id "/full-dependencies.edn"))) - entity-dependencies (clojure.edn/read-string (slurp (str backup-id "/entity-dependencies.edn")))] + (let [schema (clojure.edn/read-string (slurp (pull-file backup-id "schema.edn"))) + full-dependencies (clojure.edn/read-string (slurp (pull-file backup-id "full-dependencies.edn"))) + entity-dependencies (clojure.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 @@ -123,7 +119,7 @@ (doseq [entity (or item-list (filter (complement (conj @loaded "audit")) (order-of-insert entity-dependencies))) :let [_ (swap! loaded conj entity) _ (println "querying for " entity) - entities (ednl/slurp (str backup-id "/" entity ".ednl")) + entities (ednl/slurp (pull-file backup-id (str entity "ednl"))) _ (println "Found some! here's a few: " (take 3 entities)) tx-chan (a/chan 50) @@ -150,5 +146,5 @@ ;; cloud load (comment - (load-from-backup "backups/8e245d3d-be7a-4d90-8e9e-e6a110582658" auto-ap.datomic/conn ["journal-entry-line" "journal-entry"])) + (load-from-backup "a1975512-9091-49d1-a348-ee445363ba34" auto-ap.datomic/conn ["vendor"])) ;; => nil