From 82f56c37cda180afbac8f8dcbc8e54548cbd4d8a Mon Sep 17 00:00:00 2001 From: BC Date: Thu, 20 Sep 2018 20:49:38 -0700 Subject: [PATCH] adding approach to fixing sql. --- scratch-sessions/fix-account-id.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 scratch-sessions/fix-account-id.sql diff --git a/scratch-sessions/fix-account-id.sql b/scratch-sessions/fix-account-id.sql new file mode 100644 index 00000000..1e41da23 --- /dev/null +++ b/scratch-sessions/fix-account-id.sql @@ -0,0 +1,18 @@ + + +(defn original-base-id [{:keys [date bank-account-id description-original company-id amount]} index] + (str (t/to-time-zone date (t/time-zone-for-offset -7)) "-" description-original "-" (double amount) "-" index "-" company-id)) + +(defn new-base-id [{:keys [date bank-account-id description-original company-id amount]} index] + (str (t/to-time-zone date (t/time-zone-for-offset -7)) "-" bank-account-id "-" description-original "-" (double amount) "-" index "-" company-id)) + +(defn replacements [] + (loop [rows (get-graphql {:limit 100000}) + replacements [] + i 0] + (let [result (->> rows + (filter #(= (:id %) (sha-256 (original-base-id % i)))) + (map #(assoc % :new-id (sha-256 (new-base-id % i)))))] + (if (= 10 i) + (into replacements result) + (recur rows (into replacements result ) (inc i))))))