Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add port param and respect empty password #26

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
:examples [["FORCE_MB_DB_CONNECTION_URI=mysql://localhost:3308/metabase_test?user=root bb metabuild -d mysql"
"Connect to MYSQL, running against run-mariadb-latest.sh"]]
:task (let [_ (println (c/red "Welcome to " (c/on-white (c/blue " MetaBuilder "))))
{:keys [app-db user-name password extensions db-name] :as p}
{:keys [app-db user-name password extensions db-name db-port] :as p}
(cli/menu! (current-task)
{:id :app-db
:short "-d"
Expand All @@ -51,9 +51,11 @@
:long "--name DB_NAME"
:default "metabase"
:title "Name of the database to connect to."
:prompt :text})]
:prompt :text}
;; `nil` port signals intent to use default port number for a database type
{:id :db-port :title "Port the database is running on" :long "--port NUMBER" :default nil})]
;; (prn p)
(meta/build app-db user-name password extensions db-name))}
(meta/build app-db user-name password extensions db-name db-port))}

quick-test
{:doc "Quickly run a test against a namespace."
Expand Down
17 changes: 12 additions & 5 deletions bb/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@
(println (c/green "[bb metabuild] 🔁 " (t/nrepl-eval nrepl-port repl-cmd)))
(println (c/green "[bb metabuild] ✅ Done."))))

(defn build [app-db user-name password extensions db-name]
(defn app-db-connection-str [app-db user-name password db-name db-port]
(if (= "h2" app-db)
""
(let [;; scheme = mysql or postgres
scheme app-db
password-part (when (seq password) (str ":" password))
db-port (or db-port (case app-db "mysql" 3306 "postgres" 5432))
db-name (or db-name (case app-db "mysql" "metabase_test" "postgres" "metabase"))]
(str scheme "://" user-name password-part "@localhost:" db-port "/" db-name))))

(defn build [app-db user-name password extensions db-name db-port]
(let [env+ (assoc (t/env)
"MB_DB_CONNECTION_URI"
(or (t/env "FORCE_MB_DB_CONNECTION_URI" (constantly false))
(case app-db
"mysql" (str "mysql://" user-name ":" password "@localhost:3306/" (or db-name "metabase_test"))
"postgres" (str "postgres://" user-name ":" password "@localhost:5432/" (or db-name "metabase"))
"h2" "" ))
(app-db-connection-str app-db user-name password db-name db-port))
"MB_DB_TYPE" app-db)
cmd (str "clj -M" (str/join (map (fn [s-or-kw] (keyword (name s-or-kw))) extensions)))]
(println (:out (shell {:out :string} "java -version")))
Expand Down