             [puppetlabs.puppetdb.scf.storage :as scf]
             [puppetlabs.puppetdb.scf.partitioning :as partitioning])
   (:import [org.postgresql.util PGobject]
-           [java.time LocalDate ZonedDateTime ZoneId]
+           [java.time LocalDate ZonedDateTime ZoneId OffsetDateTime]
            (java.sql Timestamp)
-           (java.time.temporal ChronoUnit)))
+           (java.time.temporal ChronoUnit)
+           (java.time.format DateTimeFormatter)))
 
 (defn init-through-2-3-8
   []


   ;; pre-create partitions
   (log/info (trs "Creating partitions based on unique days in resource_events"))
   (jdbc/call-with-query-rows
    ["select distinct date_trunc('day', \"timestamp\") as rowdate
      from resource_events_premigrate"]
    (fn [rows]
      (doseq [row rows]
        (partitioning/create-resource-events-partition (-> (:rowdate row)
                                                           (.toInstant)
                                                           (ZonedDateTime/ofInstant (ZoneId/of "UTC"))
                                                           (.truncatedTo (ChronoUnit/DAYS)))))))

  (let [event-count (-> "select count(*) from resource_events_premigrate"
                        jdbc/query-to-vec first :count)


  (jdbc/do-commands
   ;; Indexes are created on the individual partitions, not on the base table
   "DROP TABLE resource_events_premigrate"
   "DROP FUNCTION find_resource_events_unique_dates()")))

(def migrations
  "The available migrations, as a map from migration version to migration function."
