<commit_before>(ns chat.server.migrate
  (:require [chat.server.db :as db]
            [datomic.api :as d]))

(defn migrate-2016-01-01
  "Change email uniqueness to /value, add thread mentions"
  []
  (db/with-conn
    (d/transact db/*conn*
      [{:db/id :user/email
        :db/unique :db.unique/value
        :db.alter/_attribute :db.part/db}
       {:db/ident :thread/mentioned
        :db/valueType :db.type/ref
        :db/cardinality :db.cardinality/many
        :db/id #db/id [:db.part/db]
        :db.install/_attribute :db.part/db}])))

(defn migrate-2015-12-19
  "Add user nicknames"
  []
  (db/with-conn
    (d/transact db/*conn*
      [{:db/ident :user/nickname
        :db/valueType :db.type/string
        :db/cardinality :db.cardinality/one
        :db/unique :db.unique/value
        :db/id #db/id [:db.part/db]
        :db.install/_attribute :db.part/db}])))<commit_msg>add migration to give everyone emails<commit_after>(ns chat.server.migrate
  (:require [chat.server.db :as db]
            [datomic.api :as d]
            [clojure.string :as string]))

(defn migrate-2016-01-14
  "All users must have a nickname"
  []
  (db/with-conn
    (let [give-nicks (->> (d/q '[:find (pull ?u [:user/id :user/email :user/nickname])
                                 :where
                                 [?u :user/id]]
                               (d/db db/*conn*))
                          (map first)
                          (filter (comp nil? :user/nickname))
                          (mapv (fn [u] [:db/add [:user/id (:user/id u)]
                                         :user/nickname (-> (:user/email u) (string/split #"@") first)])))]
      (d/transact db/*conn* give-nicks))))

(defn migrate-2016-01-01
  "Change email uniqueness to /value, add thread mentions"
  []
  (db/with-conn
    (d/transact db/*conn*
      [{:db/id :user/email
        :db/unique :db.unique/value
        :db.alter/_attribute :db.part/db}
       {:db/ident :thread/mentioned
        :db/valueType :db.type/ref
        :db/cardinality :db.cardinality/many
        :db/id #db/id [:db.part/db]
        :db.install/_attribute :db.part/db}])))

(defn migrate-2015-12-19
  "Add user nicknames"
  []
  (db/with-conn
    (d/transact db/*conn*
      [{:db/ident :user/nickname
        :db/valueType :db.type/string
        :db/cardinality :db.cardinality/one
        :db/unique :db.unique/value
        :db/id #db/id [:db.part/db]
        :db.install/_attribute :db.part/db}])))
{'fraction_non_alphanumeric': 0.16275303643724695, 'fraction_numerical': 0.016194331983805668, 'mean_word_length': 1.8599537037037037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3683569', 'n_tokens_mistral': 908, 'n_tokens_neox': 866, 'n_words': 171}