diff --git a/project.clj b/project.clj index 7ec1f23021a4fd7b3e2362790405c4a3436b990b..184c7261ebce6431a22150d57ce4692d68c49623 100644 --- a/project.clj +++ b/project.clj @@ -82,7 +82,7 @@ [org.slf4j/slf4j-log4j12 "1.7.25"] ; abstraction for logging frameworks -- allows end user to plug in desired logging framework at deployment time [org.yaml/snakeyaml "1.18"] ; YAML parser (required by liquibase) [org.xerial/sqlite-jdbc "3.16.1"] ; SQLite driver - [postgresql "9.3-1102.jdbc41"] ; Postgres driver + [org.postgresql/postgresql "42.1.4.jre7"] ; Postgres driver [io.crate/crate-jdbc "2.1.6"] ; Crate JDBC driver [prismatic/schema "1.1.5"] ; Data schema declaration and validation library [redux "0.1.4"] ; Utility functions for building and composing transducers @@ -91,8 +91,10 @@ [ring/ring-json "0.4.0"] ; Ring middleware for reading/writing JSON automatically [stencil "0.5.0"] ; Mustache templates for Clojure [toucan "1.0.3" ; Model layer, hydration, and DB utilities - :exclusions [honeysql]]] - :repositories [["bintray" "https://dl.bintray.com/crate/crate"]] ; Repo for Crate JDBC driver + :exclusions [honeysql]] + [com.amazon.redshift/redshift-jdbc41 "1.2.8.1005"]] ; Redshift JDBC driver + :repositories [["bintray" "https://dl.bintray.com/crate/crate"] + ["redshift" "http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release"]] ; Repo for Crate JDBC driver :plugins [[lein-environ "1.1.0"] ; easy access to environment variables [lein-ring "0.11.0" ; start the HTTP server with 'lein ring server' :exclusions [org.clojure/clojure]]] ; TODO - should this be a dev dependency ? diff --git a/src/metabase/db/spec.clj b/src/metabase/db/spec.clj index 3b7454c891e447494a631bfe51742e9f8cb3720c..a0ccb450bdc159e85727c5b41c553a6bbda21d45 100644 --- a/src/metabase/db/spec.clj +++ b/src/metabase/db/spec.clj @@ -23,7 +23,7 @@ :as opts}] (merge {:classname "org.postgresql.Driver" ; must be in classpath :subprotocol "postgresql" - :subname (str "//" host ":" port "/" db)} + :subname (str "//" host ":" port "/" db "?OpenSourceSubProtocolOverride=true")} (dissoc opts :host :port :db))) (defn mysql @@ -38,3 +38,15 @@ :subname (str "//" host ":" port "/" db) :delimiters "`"} (dissoc opts :host :port :db))) + +(defn redshift + "Create a database specification for a redshift database. Opts should include + keys for :db, :user, and :password. You can also optionally set host and + port." + [{:keys [host port db] + :as opts}] + (merge {:classname "com.amazon.redshift.jdbc.Driver" ; must be in classpath + :subprotocol "redshift" + :subname (str "//" host ":" port "/" db "?OpenSourceSubProtocolOverride=false") + :ssl true} + (dissoc opts :host :port :db))) diff --git a/src/metabase/driver/redshift.clj b/src/metabase/driver/redshift.clj index 472360d5344774b09c95fdccfec7ed5c353aa867..8c25b1524d1413a49e1783a30b472b5dbe62b525 100644 --- a/src/metabase/driver/redshift.clj +++ b/src/metabase/driver/redshift.clj @@ -16,7 +16,7 @@ [ssh :as ssh]])) (defn- connection-details->spec [details] - (dbspec/postgres (merge details postgres/ssl-params))) ; always connect to redshift over SSL + (dbspec/redshift details)) (defn- date-interval [unit amount] (hsql/call :+ :%getdate (hsql/raw (format "INTERVAL '%d %s'" (int amount) (name unit))))) diff --git a/test/metabase/driver/postgres_test.clj b/test/metabase/driver/postgres_test.clj index 69c5f499fd3912366c41aa9305c68ff9f9f5b996..e2adf5e1881604a85eba25c041ded3aeeeab55ee 100644 --- a/test/metabase/driver/postgres_test.clj +++ b/test/metabase/driver/postgres_test.clj @@ -33,7 +33,7 @@ {:user "camsaul" :classname "org.postgresql.Driver" :subprotocol "postgresql" - :subname "//localhost:5432/bird_sightings" + :subname "//localhost:5432/bird_sightings?OpenSourceSubProtocolOverride=true" :sslmode "disable"} (sql/connection-details->spec pg-driver {:ssl false :host "localhost" @@ -49,7 +49,7 @@ :subprotocol "postgresql" :user "camsaul" :sslfactory "org.postgresql.ssl.NonValidatingFactory" - :subname "//localhost:5432/bird_sightings"} + :subname "//localhost:5432/bird_sightings?OpenSourceSubProtocolOverride=true"} (sql/connection-details->spec pg-driver {:ssl true :host "localhost" :port 5432 @@ -268,7 +268,7 @@ ;; make sure connection details w/ extra params work as expected (expect - "//localhost:5432/cool?prepareThreshold=0" + "//localhost:5432/cool?OpenSourceSubProtocolOverride=true&prepareThreshold=0" (:subname (sql/connection-details->spec pg-driver {:host "localhost" :port "5432" :dbname "cool" diff --git a/test/metabase/test/data.clj b/test/metabase/test/data.clj index 6d52a97638b92007e00afea10546666e19cd2a7a..7050b89e90330065ccc5cdd8151e739eb3a3ed66 100644 --- a/test/metabase/test/data.clj +++ b/test/metabase/test/data.clj @@ -155,9 +155,13 @@ (:id (db))) ([table-name] + ;; Ensure the database has been created + (db) (get-table-id-or-explode (id) table-name)) ([table-name field-name & nested-field-names] + ;; Ensure the database has been created + (db) (let [table-id (id table-name)] (loop [parent-id (get-field-id-or-explode table-id field-name), [nested-field-name & more] nested-field-names] (if-not nested-field-name