From 83bbfa153dfc36acd50e87e5c76d05f4936fcf43 Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Mon, 22 Jan 2024 10:33:06 +0000 Subject: [PATCH] patch: Reattempt to load migrations at runtime --- .../mallard/src/k16/mallard/loaders/fs.clj | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/mallard/src/k16/mallard/loaders/fs.clj b/packages/mallard/src/k16/mallard/loaders/fs.clj index 26cbe2e..37483e3 100644 --- a/packages/mallard/src/k16/mallard/loaders/fs.clj +++ b/packages/mallard/src/k16/mallard/loaders/fs.clj @@ -13,7 +13,7 @@ (re-find #"^\(ns\s+([^\s);]+)") second)) -(defn- resolve-migration-files [dir] +(defn resolve-migration-files [dir] (->> (or (io/resource dir) (io/file dir)) io/file @@ -31,12 +31,15 @@ also allows loading of migrations when they are bundled as resources within a jar as the full resource paths are known up front." [dir] - (let [namespaces (resolve-migration-files dir)] - `(do (doseq [namespace# ~namespaces] - (require (symbol namespace#))) + (let [namespaces (try (resolve-migration-files dir) + (catch Exception _))] + `(let [namespaces# (or ~namespaces + (resolve-migration-files ~dir))] + (doseq [namespace# namespaces#] + (require (symbol namespace#))) - (->> ~namespaces - (map (fn [namespace#] - {:id (-> namespace# (str/split #"\.") last) - :run-up! (resolve (symbol (str namespace# "/run-up!"))) - :run-down! (resolve (symbol (str namespace# "/run-down!")))})))))) + (->> namespaces# + (map (fn [namespace#] + {:id (-> namespace# (str/split #"\.") last) + :run-up! (resolve (symbol (str namespace# "/run-up!"))) + :run-down! (resolve (symbol (str namespace# "/run-down!")))}))))))