Skip to content
Snippets Groups Projects
Unverified Commit 55ecc874 authored by Raimon Grau's avatar Raimon Grau Committed by GitHub
Browse files

add 'jdbc:' prefix to connection-uri if needed (#14573)

parent 8f7ec64a
No related branches found
No related tags found
No related merge requests found
......@@ -50,8 +50,16 @@
(let [db-file-name (config/config-str :mb-db-file)]
(get-db-file db-file-name)))))
(defn- format-connection-uri
"Prepends \"jdbc:\" to the connection-uri string if needed."
[connection-uri]
(if-let [uri connection-uri]
(if (re-find #"^jdbc:" uri)
uri
(str "jdbc:" uri))))
(def ^:private connection-string
(delay (config/config-str :mb-db-connection-uri)))
(delay (format-connection-uri (config/config-str :mb-db-connection-uri))))
(defn- connection-string->db-type [s]
(when s
......
......@@ -20,3 +20,11 @@
clojure.lang.ExceptionInfo
#"Unsupported application database type: \"sqlserver\""
(#'mdb.env/connection-string->db-type "jdbc:sqlserver://bad")))))
(deftest format-connection-uri-test
(let [conn-uri "postgresql://localhost:metabase?username=johndoe"
jdbc-conn-uri (str "jdbc:" conn-uri)]
(doseq [[input expected] [[conn-uri jdbc-conn-uri]
[jdbc-conn-uri jdbc-conn-uri]
[nil nil]]]
(is (= expected (#'mdb.env/format-connection-uri input))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment