Skip to content

Commit

Permalink
Process MIGRATUS_CONFIG and the other env vars, merge them
Browse files Browse the repository at this point in the history
  • Loading branch information
ieugen committed Nov 6, 2023
1 parent 77311c9 commit cb0c76e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
32 changes: 15 additions & 17 deletions src/migratus/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions test/migratus/test/cli_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit cb0c76e

Please sign in to comment.