   [args]
   ;; wrap in a try-catch since there is not easy way to check for the existence of the DB
   (try
-    (j/db-do-commands db "CREATE TABLE METADATA_DB.schema_version (version INTEGER NOT NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT sysdate NOT NULL)")
+    (j/db-do-commands db "CREATE TABLE METADATA_DB.schema_version (version INTEGER NOT NULL, created_at TIMESTAMP(9) WITH TIME ZONE DEFAULT sysdate NOT NULL)")
     (catch Exception e)))
 
 (defn current-db-version []
-  (println "Start")
-  (int (or (:version (first (j/query db ["select version from METADATA_DB.schema_version order by version DESC"]))) 0)))
+  (int (or (:version (first (j/query db ["select version from METADATA_DB.schema_version order by created_at desc"]))) 0)))
 
 (defn update-db-version [version]
-  (j/insert! db "METADATA_DB.schema_version" ["version"] [version]))
+  (j/insert! db "METADATA_DB.schema_version" ["version"] [version])
+  ; sleep a second to workaround timestamp precision issue
+  (Thread/sleep 1000))
 
 (defn migrate-config []
   {:directory "src/migrations/"

(def db-host (get (System/getenv) "MDB_DB_HOST" "localhost"))
(def db-port (get (System/getenv) "MDB_DB_PORT" "1521"))
(def db-sid (get (System/getenv) "MDB_DB_SID" "orcl"))
    

(def db {:classname "oracle.jdbc.driver.OracleDriver"
         :subprotocol "oracle"

   :init maybe-create-schema-table
   :current-version current-db-version
   :update-version update-db-version })
