From 14d6a93f2c53b3dce116089194badce717b9f5d9 Mon Sep 17 00:00:00 2001 From: Ryan Senior <ryan@metabase.com> Date: Wed, 20 Sep 2017 16:53:58 -0700 Subject: [PATCH] Switch from the PostgreSQL driver to Redshift Previously we were using the PostgreSQL driver for connecting to Redshift. Newer versions of PostgreSQL require newer drivers that are no longer compatible with Redshift which has prevented us from upgrading. By switching to the AWS Redshift driver, we can upgrade the PostgreSQL driver independently. --- project.clj | 6 ++++-- src/metabase/db/spec.clj | 12 ++++++++++++ src/metabase/driver/redshift.clj | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/project.clj b/project.clj index 7ec1f23021a..340d44bbe54 100644 --- a/project.clj +++ b/project.clj @@ -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 3b7454c891e..057c82c7f3e 100644 --- a/src/metabase/db/spec.clj +++ b/src/metabase/db/spec.clj @@ -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) + :ssl true} + (dissoc opts :host :port :db))) diff --git a/src/metabase/driver/redshift.clj b/src/metabase/driver/redshift.clj index 472360d5344..8c25b1524d1 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))))) -- GitLab