(ns oc.storage.db.migrations.add-bookmarks-index
  (:require [rethinkdb.query :as r]
            [oc.lib.db.migrations :as m]
            [oc.storage.config :as config]
            [oc.storage.resources.entry :as entry]))

(defn up [conn]
  (println (m/create-compound-index conn entry/table-name "org-uuid-status-bookmark-user-id-map-multi"
    (r/fn [row] (r/map (r/get-field row "bookmarks")
                   (r/fn [user-id]
                     [(r/get-field row "org-uuid")
                      (r/get-field row "status")
                      user-id])))
    {:multi true}))
  true) ; return true on success

(ns oc.storage.db.migrations.add-bookmarks-index
  (:require [rethinkdb.query :as r]
            [oc.lib.db.migrations :as m]
            [oc.storage.config :as config]
            [oc.storage.resources.entry :as entry]))

(defn up [conn]
  (println (m/create-compound-index conn entry/table-name "org-uuid-status-bookmark-user-id-map-multi"
    (r/fn [row] (r/map (r/get-field row "bookmarks")
                  (r/fn [bm-row]
                    [(r/get-field row "status")
                     (r/get-field row "org-uuid")
                     (r/get-field bm-row "user-id")])))
    {:multi true}))
  true) ; return true on success
