(local re (require "re")) (local path (require "path")) (local inspect (. (require "inspect") :inspect)) (local filename-regex (re.compile "^([0-9]+).*\\.sql$")) (fn migrate [] (local migrations {}) (local seqnums {}) (local zip-paths (GetZipPaths "/migrations/")) (print (inspect zip-paths)) (each [_ filename (ipairs zip-paths)] (let [basename (path.basename filename) (_ seqstr) (filename-regex:search basename) seqnum (tonumber seqstr)] (if (and seqnum (not (. seqnums seqnum))) (do (table.insert seqnums seqnum) (table.insert migrations {: filename : seqnum})) (print (string.format "found weird migration name or duplicate sequence number: %s" filename))))) (table.sort migrations #(< $1.seqnum $2.seqnum)) (print (inspect migrations)) (each [i mig (ipairs migrations)] (print (string.format "%d: %s" i mig.filename)))) {: migrate}