         (update-in [:depth] parse-int)
         (assoc :periodical_number
                (when-not (string/blank? periodical_number) periodical_number))
-        (assoc :library_signature (get production-id-to-library-signature-map id))
+        (assoc :library_signature (get @production-id-to-library-signature-map id))
         (dissoc :Produktestatus))))
 
 (defn productions


;; production id to library signature mapping
(def production-id-to-library-signature-map
  (reduce (fn [m {:keys [production_id library_signature]}]
            (let [k (production-id? production_id)
                  v (library-signature? library_signature)]
              (if (and k v) (assoc m k v) m)))
          {}
          (jdbc/query archive-db
                      "SELECT m.value AS production_id, m2.value AS library_signature FROM meta m, meta m2 WHERE m.id_container = m2.id_container AND m.element='idMaster' AND m2.element='idAusleihe'")))

(defn fix-date [s]
  (when (not (string/blank? s))

        (assoc :language language)
        (assoc :volumes volumes)
        (assoc :total_time total_time)
        (assoc :library_signature (get @production-id-to-library-signature-map (:id m)))
        (select-keys [:id :creator :date :depth :language :library_number :library_signature
                        :narrator :state :produced_date :production_type
                        :revision_date :source :source_date :source_publisher
                        :subject :title :total_time :volumes]))))

(def all-commercial-productions
  (delay
   (let [statement (string/join
                    "\n"
                    ["SELECT d.tm, d.identifier AS id, d.title, d.process_status, m.element, m.value"
                     "FROM madras.document d, madras.meta m"
                     "WHERE d.id IN (SELECT id_document FROM madras.meta WHERE element='idVorstufe' AND value regexp '^PNX [2-9][0-9][0-9][0-9]')"
                     "AND d.id = m.id_document"])]
     (->> (jdbc/query old-db statement)
          (map normalize-commercial-production)
          (group-by :id)
          (map (fn [[k v]] [k (apply merge v)]))
          (map second)
          (map cleanup-commercial-production)
          (map prod/parse)
          (map #(merge (prod/default-meta-data) %))))))

(defn get-all-files
  "Get all files for a `production`"
  [{id :id}]
  (get @all-files-by-id id))

(defn ready? [production] (= (:state production) "ready"))
(defn archived? [production] (= (:state production) "archived"))
