Skip to content

Commit

Permalink
Merge pull request #2806 from metabase/heroku-fix
Browse files Browse the repository at this point in the history
Fix fetching DB type on Heroku 😋
  • Loading branch information
tlrobinson committed Jun 20, 2016
2 parents 5aa8124 + 88aff7c commit 558817c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/metabase/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
;; if we don't have an absolute path then make sure we start from "user.dir"
[(System/getProperty "user.dir") "/" db-file-name options]))))))

(defn- db-type
"The type of backing DB used to run Metabase. `:h2`, `:mysql`, or `:postgres`."
^clojure.lang.Keyword []
(config/config-kw :mb-db-type))

(defn parse-connection-string
"Parse a DB connection URI like `postgres://cam@localhost.com:5432/cams_cool_db?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory` and return a broken-out map."
[uri]
Expand All @@ -61,11 +56,20 @@
codec/form-decode
walk/keywordize-keys))))

(def ^:private connection-string-details
(delay (when-let [uri (config/config-str :mb-db-connection-uri)]
(parse-connection-string uri))))

(defn- db-type
"The type of backing DB used to run Metabase. `:h2`, `:mysql`, or `:postgres`."
^clojure.lang.Keyword []
(or (:type @connection-string-details)
(config/config-kw :mb-db-type)))

(def db-connection-details
"Connection details that can be used when pretending the Metabase DB is itself a `Database`
(e.g., to use the Generic SQL driver functions on the Metabase DB itself)."
(delay (or (when-let [uri (config/config-str :mb-db-connection-uri)]
(parse-connection-string uri))
(delay (or @connection-string-details
(case (db-type)
:h2 {:type :h2 ; TODO - we probably don't need to specifc `:type` here since we can just call (db-type)
:db @db-file}
Expand Down

0 comments on commit 558817c

Please sign in to comment.