    :write-handlers empty
    :buffer-size    1 MB
    :config         config} "
-  [path  & {:keys [serializer read-handlers write-handlers buffer-size config]
+  [path  & {:keys [serializer read-handlers write-handlers buffer-size config version old-files]
             :or   {serializer     (ser/fressian-serializer)
                    read-handlers  (atom {})
                    write-handlers (atom {})
                    buffer-size    (* 1024 1024)
-                   config         {:fsync true}}}]
-  (let [_     (check-and-create-folder path)
-        store (map->FileSystemStore {:folder         path
-                                     :serializer     serializer
-                                     :read-handlers  read-handlers
-                                     :write-handlers write-handlers
-                                     :buffer-size buffer-size    
-                                     :locks          (atom {})
-                                     :config         config})]
+                   config         {:fsync true}
+                   version        2}}]
+  (let [detect-old-version (when old-files (atom (detect-old-file-schema  "/tmp/konserve-fs-migration-test")))
+        _                  (check-and-create-folder path)
+        store              (map->FileSystemStore {:detect-old-version detect-old-version
+                                                  :folder             path
+                                                  :serializer         serializer
+                                                  :read-handlers      read-handlers
+                                                  :write-handlers     write-handlers
+                                                  :buffer-size        buffer-size    
+                                                  :locks              (atom {})
+                                                  :config             config
+                                                  :version            version})]
     (go store)))
 
 
+                                        ;set => 
+;system time for meta data => java function
+;seperate migrate function
+
+(comment
+
+  (def store (<!! (new-fs-store "/tmp/konserve-fs-migration-test" :old-files true)))
+
+
+  @(:detect-old-version store)
+
+  (<!! (-get store 5))
+
+
+  (<!! (-assoc-in store ["old_x"] x))
+
+  (<!! (-get-meta store :foo))
+
+  (<!! (-get-meta store :byte-array))
+
+  (<!! (-get-meta store (str "B_" 4)))
+
+  (<!! (-get store 4))
+
+  (def folder-name "/tmp/konserve-fs-migration-test")
+
+  (def serializer (ser/fressian-serializer))
+
+  (def read-handler (atom {}))
+
+
+
+  (def write-handler (atom {}))
+
+  (defn completion-read-old-handler [res-ch bb serializer read-handlers msg]
+    (proxy [CompletionHandler] []
+      (completed [res att]
+        (let [bais (ByteArrayInputStream. (.array bb))]
+          (try
+            (let [value (-deserialize serializer read-handlers bais)]
+              (put! res-ch value)
+              (close! res-ch))
+            (catch Exception e
+              (ex-info "Could not read key."
+                       (assoc msg :exception e))))))))
+
+  ;add key and up-fn, up-meta-fn
+  (defn migrate-file-v2 [folder up-fn buffer-size version new-path meta-path data-path serializer read-handlers write-handlers]
+    (let [standard-open-option (into-array StandardOpenOption [StandardOpenOption/READ])
+          ac-meta-file         (AsynchronousFileChannel/open meta-path standard-open-option)
+          ac-data-file         (AsynchronousFileChannel/open data-path standard-open-option)
+          file-name            (str folder "/" (-> data-path .getFileName .toString) ".ksv")
+          size-meta            (.size ac-meta-file)
+          bb-meta              (ByteBuffer/allocate size-meta)
+          res-ch-data          (chan)
+          res-ch-meta          (chan)]
+      (go-try
+          (.read ac-meta-file bb-meta 0 size-meta
+                 (completion-read-old-handler res-ch-meta bb-meta serializer read-handlers
+                                              {:type :read-meta-old-error
+                                               :path meta-path}))
+        (let [{:keys [format key]} (<? res-ch-meta)]
+          (when (= :edn format)
+            (let [size-data (.size ac-data-file)
+                  bb-data   (ByteBuffer/allocate size-data)]
+              (.read ac-data-file bb-data 0 size-data
+                     (completion-read-old-handler res-ch-data bb-data serializer read-handlers
+                                                  {:type :read-data-old-error
+                                                   :path data-path}))))
+          (let [data (when (= :edn format) (<? res-ch-data))
+                env  (if (= :edn format)
+                       {:operation  :write-edn
+                        :version    version
+                        :file-name   file-name 
+                        :up-fn      (fn [_] data)
+                        :up-fn-meta (fn [_] {:key key :type format ::timestamp (java.util.Date.)})
+                        :msg        {:type :write-edn-error 
+                                     :key  key}}
+                       {:operation  :write-binary
+                        :version    version
+                        :file-name  file-name 
+                        :input      (FileInputStream. (-> data-path .toString))
+                        :up-fn-meta (fn [_] {:key key :type format ::timestamp (java.util.Date.)})
+                        :msg        {:type :write-binary-error 
+                                     :key  key}})]
+            (<? (update-file folder nil new-path serializer write-handlers buffer-size [key] env [nil nil]))))
+        (finally
+          ;delete old file
+          (close! res-ch-data)
+          (.clear bb-meta)
+          (.close ac-data-file)
+          (.close ac-meta-file)))))
+
+  ;add key and up-fn and up-meta function
+(defn migrate-file-v1 [folder buffer-size version new-path data-path serializer read-handlers write-handlers]
+  (let [standard-open-option (into-array StandardOpenOption [StandardOpenOption/READ])
+        ac-data-file         (AsynchronousFileChannel/open data-path standard-open-option)
+        file-name            (str folder "/" (-> data-path .getFileName .toString) ".ksv")
+        binary?              (clojure.string/includes? file-name "B_")
+        res-ch               (chan)
+        size-data            (.size ac-data-file)
+        bb-data              (when-not binary? (ByteBuffer/allocate size-data))
+        res-ch-data          (chan)]
+      (go-try
+          (when-not binary?
+            (.read ac-data-file bb-data 0 size-data
+                   (completion-read-old-handler res-ch-data bb-data serializer read-handlers
+                                                {:type :read-data-old-error
+                                                 :path data-path})))
+        (let [[[key] data] (when-not binary? (<? res-ch-data))
+              env  (if binary?
+                     {:operation  :write-binary
+                      :version    version
+                      :file-name  (clojure.string/replace file-name #"B_" "")
+                      :input      (FileInputStream. (-> data-path .toString))
+                      :up-fn-meta (fn [_] {:key (-> data-path .toString) :type :binary ::timestamp (java.util.Date.)})
+                      :msg        {:type :write-binary-error
+                                   :key  key}}
+                     {:operation  :write-edn
+                      :version    version
+                      :file-name  file-name 
+                      :up-fn      (fn [_] data)
+                      :up-fn-meta (fn [_] {:key key :type :edn ::timestamp (java.util.Date.)})
+                      :msg        {:type :write-edn-error 
+                                   :key  key}})]
+            (<? (update-file folder nil new-path serializer write-handlers buffer-size [key] env [nil nil])))
+        (finally
+          ;delete old file
+          (when-not binary? (.clear bb-data))
+          (close! res-ch-data)
+          (.close ac-data-file)))))
+;clj kondo => linter
+                                        ;=> set old files
+                                        ;life update
+(defn detect-old-file-schema [folder]
+  (reduce
+   (fn [black-list path]
+     (let [file-name (-> path .toString)]
+       (if (clojure.string/includes? (-> path .getFileName .toString) "meta")
+         (into black-list (detect-old-file-schema file-name))
+         (if (clojure.string/includes? file-name ".ksv")
+           black-list
+           (into black-list [file-name])))))
+   #{}
+   (Files/newDirectoryStream (Paths/get folder (into-array String [])))))
+
+
+  (defn check-old-version [folder buffer-size version serializer read-handlers write-handlers]
+    (let [meta-path    (Paths/get (str folder "/meta") (into-array String []))
+          meta-exists? (Files/exists meta-path (into-array LinkOption []))
+          file-paths   (when meta-exists? (Files/newDirectoryStream meta-path))]
+      (if meta-exists?
+        (doseq [file-path file-paths]
+          (when (Files/exists file-path (into-array LinkOption []))
+            (let [file-name    (-> file-path .getFileName .toString)
+                  data-path    (Paths/get (str folder "/data/" file-name) (into-array String []))
+                  data-exists? (Files/exists data-path (into-array LinkOption []))]
+              (migrate-file-v2 folder buffer-size version (Paths/get (str folder "/" file-name) (into-array String [])) file-path data-path serializer read-handlers write-handlers))))
+        (doseq [file-path (Files/newDirectoryStream (Paths/get folder (into-array String [])))]
+          (let [file-name (-> file-path .toString)]
+            (when-not (clojure.string/includes? file-name ".ksv")
+              (migrate-file-v1 folder buffer-size version (Paths/get (clojure.string/replace (str file-name ".ksv") #"B_" "") (into-array String [])) file-path serializer read-handlers write-handlers)))))))
+
+  (check-old-version folder-name (* 1024 1024) 1 serializer read-handler write-handler)
+
+  (<!! (new-fs-store "/tmp/konserve-fs-migration-test"))
+
+  (def detect-old-file (atom (detect-old-file-schema  "/tmp/konserve-fs-migration-test")))
+
+  (when (empty (filter #(clojure.string/includes? % "04145bdb-c294-5dec-95a8-4ed14d9e98f4")))
+    "e")
+
+  (empty? (filter #(clojure.string/includes? % "04145bdb-c294-5dec-95a8-4ed14d9e98f4") @detect-old-file))
+
+  (<!! (-assoc-in store [:bar2] (fn [_] "meta") {:bar :baz}))
+
+  (<!! (-get store :bar2))
+
+  (<!! (-get-meta store :bar2))
+
+  (<!! (-get-version store :bar2))
+
+)

   [java.nio.file Files StandardCopyOption FileSystems Path Paths OpenOption LinkOption
    StandardOpenOption FileVisitOption]))




(defn- sync-folder
  "Helper Function to Synchrenize the Folder of the Filestore"
  [folder]
  (let [p (.getPath (FileSystems/getDefault) folder (into-array String []))
        fc (FileChannel/open p (into-array OpenOption []))]
    (.force fc true)
    (.close fc)))


      (<? res-ch)
      (finally
        (.clear bb)))))
                                        ;TODO here trigger for version or after?
                                        ;TODO migrate namespace => automate migration
(defn completion-read-meta-size-handler
  "Callback Function for io/operation. Return the Meta-size that are stored in the ByteBuffer."
  [res-ch ^ByteBuffer bb msg]
  (proxy [CompletionHandler] []
    (completed [res att]
      (let [bais      (ByteArrayInputStream. (.array bb) 1 7)
            meta-size (.read bais)
            _         (.close bais)]
        (try
