diff --git a/src/metabase/driver/generic_sql/util.clj b/src/metabase/driver/generic_sql/util.clj index 603a6de3780ab7cc1785110695fa8e79a9f01bbf..c749b07a43577157fd7d6a0abffe992690dba234 100644 --- a/src/metabase/driver/generic_sql/util.clj +++ b/src/metabase/driver/generic_sql/util.clj @@ -10,14 +10,15 @@ [metabase.driver.query-processor :as qp])) ;; Cache the Korma DB connections for a given Database for 60 seconds instead of creating new ones every single time -(defn- db->connection-spec [database] +(defn- db->connection-spec [{{:keys [short-lived?]} :details, :as database}] (let [driver (driver/engine->driver (:engine database)) database->connection-details (:database->connection-details driver) connection-details->connection-spec (:connection-details->connection-spec driver)] - (-> database - database->connection-details - connection-details->connection-spec - (assoc :make-pool? true)))) ; need to make a pool or the connection will be closed before we get a chance to unCLOB-er the results during JSON serialization + (merge (-> database database->connection-details connection-details->connection-spec) + ;; unless this is a temp DB, we need to make a pool or the connection will be closed before we get a chance to unCLOB-er the results during JSON serialization + ;; TODO - what will we do once we have CLOBS in temp DBs? + (when-not short-lived? + {:make-pool? true})))) (def ^{:arglists '([database])} db->korma-db diff --git a/test/metabase/test/data/h2.clj b/test/metabase/test/data/h2.clj index 3a6e869dc4364310e930ca5fc3f5a24b7399712b..928207f7242c96002f5015b324d97ef5775cc6f9 100644 --- a/test/metabase/test/data/h2.clj +++ b/test/metabase/test/data/h2.clj @@ -33,10 +33,11 @@ (defn- connection-details "Return a Metabase `Database.details` for H2 database defined by DATABASE-DEFINITION." - [^DatabaseDefinition database-definition] - {:db (format (if (:short-lived? database-definition) "file:%s" ; for short-lived connections don't create a server thread and don't use a keep-alive connection + [^DatabaseDefinition {:keys [short-lived?], :as database-definition}] + {:db (format (if short-lived? "file:%s" ; for short-lived connections don't create a server thread and don't use a keep-alive connection "file:%s;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1") - (filename database-definition))}) + (filename database-definition)) + :short-lived? short-lived?}) (defn- korma-connection-pool "Return an H2 korma connection pool to H2 database defined by DATABASE-DEFINITION." diff --git a/test/metabase/test/data/postgres.clj b/test/metabase/test/data/postgres.clj index a77e13c5b17ba4a64427c9b96c118cdbb25941ff..8372b13fcb9c9315272e14c1a6cd2920c805b1c6 100644 --- a/test/metabase/test/data/postgres.clj +++ b/test/metabase/test/data/postgres.clj @@ -23,9 +23,10 @@ :TextField "TEXT" :TimeField "TIME"}) -(defn- pg-connection-details [^DatabaseDefinition database-definition] - (merge {:host "localhost" - :port 5432} +(defn- pg-connection-details [^DatabaseDefinition {:keys [short-lived?]}] + (merge {:host "localhost" + :port 5432 + :short-lived? short-lived?} ;; HACK (when (env :circleci) {:user "ubuntu"})))