change
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
:scheme "http"
|
:scheme "http"
|
||||||
:client-config {:server-type :dev-local
|
:client-config {:server-type :dev-local
|
||||||
:system "dev"}
|
:system "dev"}
|
||||||
:db-name "prod-migration"
|
:db-name "prod-migration2"
|
||||||
:jwt-secret "auto ap invoices are awesome"
|
:jwt-secret "auto ap invoices are awesome"
|
||||||
:aws-access-key-id "AKIAJIS67OSJARD2E6VQ"
|
:aws-access-key-id "AKIAJIS67OSJARD2E6VQ"
|
||||||
:aws-secret-access-key "Z+AOjQU9M4SwKVU2meYtyNxXtz1Axu/9xohvteXf"
|
:aws-secret-access-key "Z+AOjQU9M4SwKVU2meYtyNxXtz1Axu/9xohvteXf"
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
(ns restore-from-backup
|
(ns auto-ap.jobs.restore-from-backup
|
||||||
(:require [clojure.java.io :as io]
|
(:require [clojure.java.io :as io]
|
||||||
[amazonica.aws.s3 :as s3]
|
[amazonica.aws.s3 :as s3]
|
||||||
[config.core :refer [env]]
|
[config.core :refer [env]]
|
||||||
[clojure.core.async :as a]
|
[clojure.core.async :as a]
|
||||||
[datomic.client.api :as dc]
|
[datomic.client.api :as dc]
|
||||||
|
[auto-ap.datomic :refer [client]]
|
||||||
[lambdaisland.edn-lines :as ednl]
|
[lambdaisland.edn-lines :as ednl]
|
||||||
[datomic.client.api.async :as dca]
|
[datomic.client.api.async :as dca]
|
||||||
[datomic.dev-local :as dl]
|
[datomic.dev-local :as dl]
|
||||||
@@ -11,19 +12,6 @@
|
|||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clj-http.client :as client]))
|
[clj-http.client :as client]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(def client auto-ap.datomic/client)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn order-of-insert [entity-dependencies]
|
(defn order-of-insert [entity-dependencies]
|
||||||
(loop [entity-dependencies entity-dependencies
|
(loop [entity-dependencies entity-dependencies
|
||||||
order []]
|
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
|
(defn load-from-backup
|
||||||
([backup-id connection] (load-from-backup backup-id connection nil))
|
([backup-id connection] (load-from-backup backup-id connection nil))
|
||||||
([backup-id connection item-list]
|
([backup-id connection item-list]
|
||||||
(let [schema (clojure.edn/read-string (slurp (str backup-id "/schema.edn")))
|
(let [schema (clojure.edn/read-string (slurp (pull-file backup-id "schema.edn")))
|
||||||
full-dependencies (clojure.edn/read-string (slurp (str backup-id "/full-dependencies.edn")))
|
full-dependencies (clojure.edn/read-string (slurp (pull-file backup-id "full-dependencies.edn")))
|
||||||
entity-dependencies (clojure.edn/read-string (slurp (str backup-id "/entity-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
|
(dc/transact connection {:tx-data [{:db/ident :entity/migration-key
|
||||||
:db/unique :db.unique/identity
|
:db/unique :db.unique/identity
|
||||||
:db/cardinality :db.cardinality/one
|
:db/cardinality :db.cardinality/one
|
||||||
@@ -123,7 +119,7 @@
|
|||||||
(doseq [entity (or item-list (filter (complement (conj @loaded "audit")) (order-of-insert entity-dependencies)))
|
(doseq [entity (or item-list (filter (complement (conj @loaded "audit")) (order-of-insert entity-dependencies)))
|
||||||
:let [_ (swap! loaded conj entity)
|
:let [_ (swap! loaded conj entity)
|
||||||
_ (println "querying for " 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))
|
_ (println "Found some! here's a few: " (take 3 entities))
|
||||||
tx-chan (a/chan 50)
|
tx-chan (a/chan 50)
|
||||||
@@ -150,5 +146,5 @@
|
|||||||
|
|
||||||
;; cloud load
|
;; cloud load
|
||||||
(comment
|
(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
|
;; => nil
|
||||||
Reference in New Issue
Block a user