|
1 | 1 | (ns repl.emoji-cleanup
|
2 | 2 | (:require [clojurians-log.datomic :as d]
|
| 3 | + [clojurians-log.application :as app] |
3 | 4 | [clojurians-log.repl :as repl]
|
4 | 5 | [clojurians-log.slack-api :as slack]))
|
5 | 6 |
|
| 7 | +(defn conn |
| 8 | + "Reach into the system for the datomic connection. |
| 9 | +
|
| 10 | + Not 100% kosher but remember this is not production code as such." |
| 11 | + [] |
| 12 | + (get-in (app/system) [:datomic :conn])) |
| 13 | + |
| 14 | +(defn db [] |
| 15 | + (d/db (conn))) |
| 16 | + |
6 | 17 | ;; Our :emoji/shortcode property did not originally have an index, meaning we
|
7 | 18 | ;; kept creating more entities for emojis, instead of upserting them.
|
8 | 19 | ;;
|
|
11 | 22 |
|
12 | 23 | ;; Do the following before deploying the new schema changes:
|
13 | 24 |
|
14 |
| -(def shortcodes (d/q '[:find ?i ?s :where [?i :emoji/shortcode ?s]] (repl/db))) |
| 25 | +(def shortcodes (d/q '[:find ?i ?s :where [?i :emoji/shortcode ?s]] (db))) |
15 | 26 | (def tx-data (for [[i s] shortcodes]
|
16 | 27 | [:db/retract i :emoji/shortcode s]))
|
17 | 28 |
|
18 |
| -(run! (partial d/transact (repl/conn)) (partition-all 1000 tx-data)) |
| 29 | +(run! (partial d/transact (conn)) (partition-all 1000 tx-data)) |
19 | 30 |
|
20 |
| -@(d/transact (repl/conn) [{:db/ident :emoji/shortcode |
21 |
| - :db/valueType :db.type/string |
22 |
| - :db/cardinality :db.cardinality/one |
23 |
| - :db/unique :db.unique/identity}]) |
| 31 | +@(d/transact (conn) [{:db/ident :emoji/shortcode |
| 32 | + :db/valueType :db.type/string |
| 33 | + :db/cardinality :db.cardinality/one |
| 34 | + :db/unique :db.unique/identity}]) |
24 | 35 |
|
25 |
| -(slack/import-emojis! (repl/conn)) |
| 36 | +(slack/import-emojis! (conn)) |
26 | 37 |
|
27 | 38 | ;; After deploying the new version, re-import the data to get the emoji reactions in there
|
28 | 39 |
|
|
34 | 45 | (Thread/sleep 2000))
|
35 | 46 | (println :done))
|
36 | 47 |
|
| 48 | +;; Check vincent's message, should have +4 -1 hearts (= 3 hearts) |
| 49 | + |
37 | 50 | (group-by second
|
38 | 51 | (map (juxt :reaction/type
|
39 | 52 | (comp :emoji/shortcode :reaction/emoji))
|
40 | 53 | (:reaction/_message
|
41 |
| - (datomic.api/entity (repl/db) |
| 54 | + (datomic.api/entity (db) |
42 | 55 | [:message/key "C0GLTDB2T--1608789973.125700"]))))
|
| 56 | + |
| 57 | + |
| 58 | +;; Re-do reactions but now including the key |
| 59 | + |
| 60 | + |
| 61 | +(def reactions (d/q '[:find [?r ?m] :where [?r :reaction/message ?m]] (db))) |
| 62 | +(def tx-data (for [[r m] reactions] |
| 63 | + [:db/retract r :reaction/message ?m])) |
| 64 | + |
| 65 | +(run! (partial d/transact (conn)) (partition-all 1000 tx-data)) |
| 66 | + |
| 67 | +(count (d/q '[:find [?r ?m] :where [?r :reaction/message ?m]] (db))) |
0 commit comments