Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Support `dbname` for redshift in config files (#64069)

Nathan Voxland3800f7452a30
diff --git a/modules/drivers/redshift/src/metabase/driver/redshift.clj b/modules/drivers/redshift/src/metabase/driver/redshift.clj
index 80d4ccd411f..25c6169fcc8 100644
--- a/modules/drivers/redshift/src/metabase/driver/redshift.clj
+++ b/modules/drivers/redshift/src/metabase/driver/redshift.clj
@@ -463,15 +463,17 @@
;;; +----------------------------------------------------------------------------------------------------------------+
(defmethod sql-jdbc.conn/connection-details->spec :redshift
- [_ {:keys [host port db], :as opts}]
+ [_ {:keys [host port db dbname], :as opts}]
+ (when (and db dbname)
+ (throw (ex-info "Redshift connection details cannot contain both 'db' and 'dbname' options" {})))
(sql-jdbc.common/handle-additional-options
(merge
{:classname "com.amazon.redshift.jdbc42.Driver"
:subprotocol "redshift"
- :subname (str "//" host ":" port "/" db)
+ :subname (str "//" host ":" port "/" (or db dbname))
:ssl true
:OpenSourceSubProtocolOverride false}
- (dissoc opts :host :port :db))))
+ (dissoc opts :host :port :db :dbname))))
(prefer-method
sql-jdbc.execute/read-column-thunk
diff --git a/modules/drivers/redshift/test/metabase/driver/redshift_test.clj b/modules/drivers/redshift/test/metabase/driver/redshift_test.clj
index 7be1bf6dd84..96463cef3a8 100644
--- a/modules/drivers/redshift/test/metabase/driver/redshift_test.clj
+++ b/modules/drivers/redshift/test/metabase/driver/redshift_test.clj
@@ -533,3 +533,13 @@
:type/DateTime [:timestamp]
:type/DateTimeWithTZ [:timestamp-with-time-zone]
:type/Time [:time])))
+
+(deftest ^:parallel alternate-config-options-test
+ (testing "Can configure with either db or dbname"
+ (let [options {:host "test.example.com"}]
+ (is (= {:classname "com.amazon.redshift.jdbc42.Driver", :subprotocol "redshift", :subname "//test.example.com:/test-db", :ssl true, :OpenSourceSubProtocolOverride false}
+ (sql-jdbc.conn/connection-details->spec :redshift (assoc options :db "test-db"))))
+ (is (= {:classname "com.amazon.redshift.jdbc42.Driver", :subprotocol "redshift", :subname "//test.example.com:/test-db", :ssl true, :OpenSourceSubProtocolOverride false}
+ (sql-jdbc.conn/connection-details->spec :redshift (assoc options :dbname "test-db"))))
+ (is (thrown-with-msg? Exception #"Redshift connection details cannot contain both 'db' and 'dbname' options"
+ (sql-jdbc.conn/connection-details->spec :redshift (assoc options :dbname "test-dbname" :db "test-db")))))))