 (u/strict-extend RedshiftDriver
   driver/IDriver
   (merge (sql/IDriverSQLDefaultsMixin)
-         {:date-interval       date-interval
-          :describe-table-fks  describe-table-fks
+         {:date-interval       (u/drop-first-arg date-interval)
+          :describe-table-fks  (u/drop-first-arg describe-table-fks)
           :details-fields      (constantly [{:name         "host"
                                              :display-name "Host"
                                              :placeholder  "my-cluster-name.abcd1234.us-east-1.redshift.amazonaws.com"

            [metabase.util :as u]
            [metabase.util.korma-extensions :as kx]))

(defn- connection-details->spec [_ details]
  (kdb/postgres (merge details postgres/ssl-params))) ; always connect to redshift over SSL

(defn- date-interval [_ unit amount]
  (k/raw (format "(GETDATE() + INTERVAL '%d %s')" (int amount) (name unit))))

(defn- unix-timestamp->timestamp [_ expr seconds-or-milliseconds]
  (case seconds-or-milliseconds
    :seconds      (kx/+ (k/raw "TIMESTAMP '1970-01-01T00:00:00Z'")
                        (kx/* expr
                              (k/raw "INTERVAL '1 second'")))
    :milliseconds (recur nil (kx// expr 1000) :seconds)))

;; The Postgres JDBC .getImportedKeys method doesn't work for Redshift, and we're not allowed to access information_schema.constraint_column_usage,
;; so we'll have to use this custom query instead
;; See also: [Related Postgres JDBC driver issue on GitHub](https://github.com/pgjdbc/pgjdbc/issues/79)
;;           [How to access the equivalent of information_schema.constraint_column_usage in Redshift](https://forums.aws.amazon.com/thread.jspa?threadID=133514)
(defn- describe-table-fks [_ database table]
  (set (for [fk (jdbc/query (sql/db->jdbc-connection-spec database)
                            ["SELECT source_column.attname AS \"fk-column-name\",
                                     dest_table.relname    AS \"dest-table-name\",


  sql/ISQLDriver
  (merge postgres/PostgresISQLDriverMixin
         {:connection-details->spec  (u/drop-first-arg connection-details->spec)
          :current-datetime-fn       (constantly (k/sqlfn* :GETDATE))
          :set-timezone-sql          (constantly nil)
          :unix-timestamp->timestamp (u/drop-first-arg unix-timestamp->timestamp)}
         ;; HACK ! When we test against Redshift we use a session-unique schema so we can run simultaneous tests against a single remote host;
         ;; when running tests tell the sync process to ignore all the other schemas
         (when config/is-test?
