diff --git a/src/migratus/cli.clj b/src/migratus/cli.clj index c8e40e9..dc6e81f 100644 --- a/src/migratus/cli.clj +++ b/src/migratus/cli.clj @@ -60,7 +60,6 @@ Looks and processes the following env vars: - MIGRATUS_CONFIG - read string as edn and return config. - Do not process any other migratus env var. - MIGRATUS_STORE - apply clojure.core/keyword fn to value - MIGRATUS_MIGRATION_DIR - expect string, use as is @@ -72,22 +71,21 @@ ([] (env->config! (System/getenv))) ([env] - (let [config (get env "MIGRATUS_CONFIG")] - (if config - (edn/read-string config) - ;; we don't have MIGRATUS_CONFIG - check the other vars - (let [store (get env "MIGRATUS_STORE") - migration-dir (get env "MIGRATUS_MIGRATION_DIR") - table (get env "MIGRATUS_TABLE_NAME") - init-in-transaction (get env "MIGRATUS_INIT_IN_TRANSACTION") - db (get env "MIGRATUS_DB_SPEC")] - (cond-> {} - store (assoc :store (keyword store)) - migration-dir (assoc :migration-dir migration-dir) - table (assoc :migration-table-name table) - init-in-transaction (assoc :init-in-transaction - (my-parse-boolean init-in-transaction)) - db (assoc :db (edn/read-string db)))))))) + (let [config (get env "MIGRATUS_CONFIG") + ;; parse config from env + config (if config (edn/read-string config) {}) + store (get env "MIGRATUS_STORE") + migration-dir (get env "MIGRATUS_MIGRATION_DIR") + table (get env "MIGRATUS_TABLE_NAME") + init-in-transaction (get env "MIGRATUS_INIT_IN_TRANSACTION") + db (get env "MIGRATUS_DB_SPEC")] + (cond-> config + store (assoc :store (keyword store)) + migration-dir (assoc :migration-dir migration-dir) + table (assoc :migration-table-name table) + init-in-transaction (assoc :init-in-transaction + (my-parse-boolean init-in-transaction)) + db (assoc :db (edn/read-string db)))))) (defn cli-args->config "Parse any migratus configuration options from cli args. diff --git a/test/migratus/test/cli_test.clj b/test/migratus/test/cli_test.clj index 9fd0802..b840382 100644 --- a/test/migratus/test/cli_test.clj +++ b/test/migratus/test/cli_test.clj @@ -8,10 +8,11 @@ (let [env (doto (HashMap.) (.put "MIGRATUS_CONFIG" "{:store :database :migration-dir \"my-migrations\"}") (.put "MIGRATUS_DB_SPEC" - "{:jdbcUrl \"config-whould-be-ignored\"}")) + "{:jdbcUrl \"config-could-be-ignored\"}")) config (cli/env->config! env)] (is (= {:store :database - :migration-dir "my-migrations"} + :migration-dir "my-migrations" + :db {:jdbcUrl "config-could-be-ignored"}} config)))) (testing "Test load config from env - empty when no env vars present"