(ns metabase.models.collection-permission-graph-revision
  (:require
   [metabase.models.interface :as mi]
   [methodical.core :as methodical]
   [toucan2.core :as t2]))
(methodical/defmethod t2/table-name :model/CollectionPermissionGraphRevision [_model] :collection_permission_graph_revision)
(doto :model/CollectionPermissionGraphRevision
  (derive :metabase/model)
  (derive :hook/created-at-timestamped?))
(t2/deftransforms :model/CollectionPermissionGraphRevision
  {:before mi/transform-json
   :after  mi/transform-json})

Return the ID of the newest CollectionPermissionGraphRevision, or zero if none have been made yet. (This is used by the collection graph update logic that checks for changes since the original graph was fetched).

(defn latest-id
  []
  (or (:id (t2/select-one [:model/CollectionPermissionGraphRevision [:%max.id :id]]))
      0))