            (sutils/array-to-param "bytea" PGobject hashes)])))))
 
 
-  (log/info (trs "[5/6] Indexing fact_values table..."))
+  (log/info (trs "[6/7] Indexing fact_values table..."))
   (jdbc/do-commands
    "DROP TABLE facts"
    "ALTER TABLE facts_transform rename to facts"


  ;; Handle null fv.value separately; allowing them here leads to an intractable
  ;; query plan
  (log/info (trs "[3/6] Reconstructing facts to refer to fact_value..."))
  (jdbc/do-commands
   "INSERT INTO facts_transform (factset_id, fact_path_id, fact_value_id)
       SELECT f.factset_id, f.fact_path_id, fv.id

   "create index catalogs_job_id_idx on catalogs(job_id) where job_id is not null"))

(defn rededuplicate-facts []
  (log/info (trs "[1/7] Cleaning up unreferenced facts..."))
  (jdbc/do-commands
   "DELETE FROM facts WHERE factset_id NOT IN (SELECT id FROM factsets)")

  (log/info (trs "[2/7] Creating new fact storage tables..."))
  (jdbc/do-commands
   "CREATE SEQUENCE fact_values_id_seq;"

