diff --git a/lein-plugins/include-drivers/project.clj b/lein-plugins/include-drivers/project.clj index 20e65a450a54a34bd291bf3ddeb0accdbaf72c40..d4e7eedd9cb8021eb5eac3f613ca17a5962ee16b 100644 --- a/lein-plugins/include-drivers/project.clj +++ b/lein-plugins/include-drivers/project.clj @@ -1,4 +1,4 @@ -(defproject metabase/lein-include-drivers "1.0.4" +(defproject metabase/lein-include-drivers "1.0.5" :min-lein-version "2.5.0" :eval-in-leiningen true :deploy-repositories [["clojars" {:sign-releases false}]]) diff --git a/lein-plugins/include-drivers/src/leiningen/include_drivers.clj b/lein-plugins/include-drivers/src/leiningen/include_drivers.clj index a02be895c6dbeaed8689ce76fdce16988bc0ebaf..89184c8dd94d968a8abeacf2e9c52e0a9b00651a 100644 --- a/lein-plugins/include-drivers/src/leiningen/include_drivers.clj +++ b/lein-plugins/include-drivers/src/leiningen/include_drivers.clj @@ -1,7 +1,7 @@ (ns leiningen.include-drivers (:require [clojure.string :as str] [leiningen.core.project :as p]) - (import java.io.File)) + (:import java.io.File)) (defn- file-exists? [^String filename] (.exists (File. filename))) diff --git a/project.clj b/project.clj index f1c638bc30bf46a6ef993c65d3d50064f3475c0a..cd653c89fa08682c1457c11fe42d8f0b4c3c5092 100644 --- a/project.clj +++ b/project.clj @@ -112,7 +112,7 @@ [org.eclipse.jetty/jetty-server "9.4.14.v20181114"] ; We require JDK 8 which allows us to run Jetty 9.4, ring-jetty-adapter runs on 1.7 which forces an older version [ring/ring-json "0.4.0"] ; Ring middleware for reading/writing JSON automatically [stencil "0.5.0"] ; Mustache templates for Clojure - [toucan "1.11.0-SNAPSHOT" :exclusions [org.clojure/java.jdbc honeysql]]] ; Model layer, hydration, and DB utilities + [toucan "1.11.0" :exclusions [org.clojure/java.jdbc honeysql]]] ; Model layer, hydration, and DB utilities :main ^:skip-aot metabase.core @@ -154,10 +154,7 @@ [lein-bikeshed "0.4.1"] ; Linting [lein-check-namespace-decls "1.0.1"] ; lints namespace declarations [lein-environ "1.1.0"] ; easy access to environment variables - [lein-expectations "0.0.8"] ; run unit tests with 'lein expectations' - ;; TODO - should this be moved to the new RING profile? - [lein-ring "0.12.3" ; start the HTTP server with 'lein ring server' - :exclusions [org.clojure/clojure]]] + [lein-expectations "0.0.8"]] ; run unit tests with 'lein expectations' :env {:mb-run-mode "dev"} :jvm-opts ["-Dlogfile.path=target/log"] @@ -183,11 +180,13 @@ [:exclude-tests {}] :ring - [:exclude-tests {}] + [:exclude-tests + {:dependencies + [[lein-ring "0.12.5" :exclusions [org.clojure/clojure]]]}] ; start the HTTP server with 'lein ring server' :with-include-drivers-middleware {:plugins - [[metabase/lein-include-drivers "1.0.4"]] + [[metabase/lein-include-drivers "1.0.5"]] :middleware [leiningen.include-drivers/middleware]} diff --git a/src/metabase/db.clj b/src/metabase/db.clj index 659a51fe61ed204305fea54a413112a4fe686d98..d757df7ec0aa39c16eb961e7be53a8765b2bba72 100644 --- a/src/metabase/db.clj +++ b/src/metabase/db.clj @@ -30,21 +30,22 @@ (def db-file "Path to our H2 DB file from env var or app config." ;; see http://h2database.com/html/features.html for explanation of options - (delay (if (config/config-bool :mb-db-in-memory) - ;; In-memory (i.e. test) DB - "mem:metabase;DB_CLOSE_DELAY=-1" - ;; File-based DB - (let [db-file-name (config/config-str :mb-db-file) - db-file (io/file db-file-name) - ;; we need to enable MVCC for Quartz JDBC backend to work! Quartz depends on row-level locking, which - ;; means without MVCC we "will experience dead-locks". MVCC is the default for everyone using the - ;; MVStore engine anyway so this only affects people still with legacy PageStore databases - options ";DB_CLOSE_DELAY=-1;MVCC=TRUE;"] - (apply str "file:" (if (.isAbsolute db-file) - ;; when an absolute path is given for the db file then don't mess with it - [db-file-name options] - ;; if we don't have an absolute path then make sure we start from "user.dir" - [(System/getProperty "user.dir") "/" db-file-name options])))))) + (delay + (if (config/config-bool :mb-db-in-memory) + ;; In-memory (i.e. test) DB + "mem:metabase;DB_CLOSE_DELAY=-1" + ;; File-based DB + (let [db-file-name (config/config-str :mb-db-file) + ;; we need to enable MVCC for Quartz JDBC backend to work! Quartz depends on row-level locking, which + ;; means without MVCC we "will experience dead-locks". MVCC is the default for everyone using the + ;; MVStore engine anyway so this only affects people still with legacy PageStore databases + ;; + ;; Tell H2 to defrag when Metabase is shut down -- can reduce DB size by multiple GIGABYTES -- see #6510 + options ";DB_CLOSE_DELAY=-1;MVCC=TRUE;DEFRAG_ALWAYS=TRUE"] + ;; H2 wants file path to always be absolute + (str "file:" + (.getAbsolutePath (io/file db-file-name)) + options))))) (def ^:private jdbc-connection-regex #"^(jdbc:)?([^:/@]+)://(?:([^:/@]+)(?::([^:@]+))?@)?([^:@]+)(?::(\d+))?/([^/?]+)(?:\?(.*))?$") @@ -88,25 +89,34 @@ (or (:type @connection-string-details) (config/config-kw :mb-db-type))) -(def db-connection-details +(def ^:private 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 @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} - :mysql {:type :mysql - :host (config/config-str :mb-db-host) - :port (config/config-int :mb-db-port) - :dbname (config/config-str :mb-db-dbname) - :user (config/config-str :mb-db-user) - :password (config/config-str :mb-db-pass)} - :postgres {:type :postgres - :host (config/config-str :mb-db-host) - :port (config/config-int :mb-db-port) - :dbname (config/config-str :mb-db-dbname) - :user (config/config-str :mb-db-user) - :password (config/config-str :mb-db-pass)})))) + (delay + (when (= (db-type) :h2) + (log/warn + (u/format-color 'red + (str + (trs "WARNING: Using Metabase with an H2 application database is not recomended for production deployments.") + (trs "For production deployments, we highly recommend using Postgres, MySQL, or MariaDB instead.") + (trs "If you decide to continue to use H2, please be sure to back up the database file regularly.") + (trs "See https://metabase.com/docs/latest/operations-guide/start.html#migrating-from-using-the-h2-database-to-mysql-or-postgres for more information."))))) + (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} + :mysql {:type :mysql + :host (config/config-str :mb-db-host) + :port (config/config-int :mb-db-port) + :dbname (config/config-str :mb-db-dbname) + :user (config/config-str :mb-db-user) + :password (config/config-str :mb-db-pass)} + :postgres {:type :postgres + :host (config/config-str :mb-db-host) + :port (config/config-int :mb-db-port) + :dbname (config/config-str :mb-db-dbname) + :user (config/config-str :mb-db-user) + :password (config/config-str :mb-db-pass)})))) (defn jdbc-details "Takes our own MB details map and formats them properly for connection details for JDBC." diff --git a/src/metabase/plugins.clj b/src/metabase/plugins.clj index 893736cebb3e4a320ea64e8355828d2f5b28bdc0..fca00b8c8c54ccd9bde7d25be43979c17075e527 100644 --- a/src/metabase/plugins.clj +++ b/src/metabase/plugins.clj @@ -10,14 +10,11 @@ [metabase.util :as u] [metabase.util.i18n :refer [trs]] [yaml.core :as yaml]) - (:import java.io.File - [java.nio.file Files Path])) + (:import [java.nio.file Files Path])) (defn- plugins-dir-filename ^String [] (or (env/env :mb-plugins-dir) - (str (System/getProperty "user.dir") - File/separator - "plugins"))) + (.getAbsolutePath (io/file "plugins")))) ;; logic for determining plugins dir -- see below (defonce ^:private plugins-dir* diff --git a/test/metabase/sync/analyze/fingerprint/insights_test.clj b/test/metabase/sync/analyze/fingerprint/insights_test.clj index 634729525ac2a0c4f12ba55807aefa56a86f8621..7837e1d11e3086ff538a9f4e31ee673bc5ae0169 100644 --- a/test/metabase/sync/analyze/fingerprint/insights_test.clj +++ b/test/metabase/sync/analyze/fingerprint/insights_test.clj @@ -1,6 +1,6 @@ (ns metabase.sync.analyze.fingerprint.insights-test (:require [expectations :refer :all] - [metabase.sync.analyze.fingerprint.insights :refer :all :as i])) + [metabase.sync.analyze.fingerprint.insights :as i :refer :all])) (def ^:private cols [{:base_type :type/DateTime} {:base_type :type/Number}])