Skip to content
Snippets Groups Projects
Commit db63b9f9 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #1529 from metabase/driver-init

Possible tweaks to driver initialization path
parents b9cd2393 546b528a
Branches
Tags
No related merge requests found
......@@ -15,6 +15,7 @@
[medley.core :as m]
(metabase [config :as config]
[db :as db]
[driver :as driver]
[events :as events]
[middleware :as mb-middleware]
[routes :as routes]
......@@ -122,6 +123,9 @@
(.addShutdownHook (Runtime/getRuntime) (Thread. ^Runnable destroy))
(reset! metabase-initialization-progress 0.3)
;; Load up all of our Database drivers, which are used for app db work
(driver/find-and-load-drivers!)
;; startup database. validates connection & runs any necessary migrations
(db/setup-db :auto-migrate (config/config-bool :mb-db-automigrate))
(reset! metabase-initialization-progress 0.5)
......
......@@ -231,23 +231,25 @@
(swap! registered-drivers assoc engine driver-instance)
(log/debug (format "Registered driver %s." engine)))
(def ^:private load-driver-namespaces!
"Search the classpath for metabase driver namespaces and `require` them, so they are \"registered\" and can be used :heart_eyes_cat:"
(delay (doseq [namespce (filter (fn [ns-symb]
(re-matches #"^metabase\.driver\.[a-z0-9_]+$" (name ns-symb)))
(ns-find/find-namespaces (classpath/classpath)))]
(require namespce))))
(defn available-drivers
"Info about available drivers."
[]
@load-driver-namespaces!
(m/map-vals (fn [driver]
{:details-fields (details-fields driver)
:driver-name (name driver)
:features (features driver)})
@registered-drivers))
(defn find-and-load-drivers!
"Search Classpath for namespaces that start with `metabase.driver.`, then `require` them and look for the `driver-init`
function which provides a uniform way for Driver initialization to be done."
[]
(doseq [namespce (filter (fn [ns-symb]
(re-matches #"^metabase\.driver\.[a-z0-9_]+$" (name ns-symb)))
(ns-find/find-namespaces (classpath/classpath)))]
(log/info "loading driver namespace: " namespce)
(require namespce)))
(defn is-engine?
"Is ENGINE a valid driver name?"
[engine]
......
......@@ -6,6 +6,7 @@
[expectations :refer :all]
(metabase [core :as core]
[db :as db]
[driver :as driver]
[util :as u])
(metabase.models [setting :as setting]
[table :refer [Table]])
......@@ -65,6 +66,10 @@
;; # ------------------------------ FUNCTIONS THAT GET RUN ON TEST SUITE START / STOP ------------------------------
;; this is a little odd, but our normal `test-startup` function won't work for loading the drivers because
;; they need to be available at evaluation time for some of the unit tests work work properly, so we put this here
(defonce ^:private loaded-drivers (driver/find-and-load-drivers!))
(defn- load-test-data!
"Call `load-data!` on all the datasets we're testing against."
[]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment