Skip to content

Commit

Permalink
Check whether Metabase DB is set up before attempting to set site-url…
Browse files Browse the repository at this point in the history
… in middleware
  • Loading branch information
camsaul committed Mar 31, 2017
1 parent e44f4b9 commit 3eca231
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/metabase/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@
(def ^:private setup-db-has-been-called?
(atom false))

(defn db-is-setup?
"True if the Metabase DB is setup and ready."
^Boolean []
@setup-db-has-been-called?)

(def ^:dynamic *allow-potentailly-unsafe-connections*
"We want to make *every* database connection made by the drivers safe -- read-only, only connect if DB file exists, etc.
At the same time, we'd like to be able to use driver functionality like `can-connect-with-details?` to check whether we can
Expand Down Expand Up @@ -360,11 +365,11 @@
[& {:keys [db-details auto-migrate]
:or {db-details @db-connection-details
auto-migrate true}}]
(reset! setup-db-has-been-called? true)
(verify-db-connection db-details)
(run-schema-migrations! auto-migrate db-details)
(create-connection-pool! (jdbc-details db-details))
(run-data-migrations!))
(run-data-migrations!)
(reset! setup-db-has-been-called? true))

(defn setup-db-if-needed!
"Call `setup-db!` if DB is not already setup; otherwise this does nothing."
Expand Down
9 changes: 5 additions & 4 deletions src/metabase/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@
"Middleware to set the `site-url` Setting if it's unset the first time a request is made."
[handler]
(fn [{{:strs [origin host] :as headers} :headers, :as request}]
(when-not (public-settings/site-url)
(when-let [site-url (or origin host)]
(log/info "Setting Metabase site URL to" site-url)
(public-settings/site-url site-url)))
(when (mdb/db-is-setup?)
(when-not (public-settings/site-url)
(when-let [site-url (or origin host)]
(log/info "Setting Metabase site URL to" site-url)
(public-settings/site-url site-url))))
(handler request)))


Expand Down

0 comments on commit 3eca231

Please sign in to comment.