Skip to content
Snippets Groups Projects
Unverified Commit 659db87c authored by Cal Herries's avatar Cal Herries Committed by GitHub
Browse files

Add `schemas` driver feature (#30536)


* Add schemas driver feature flag

* Add sql_jdbc schemas test

* Add more general test

* Make schemas feature default to true

* Implement supports? for other drivers

* Add feature to the driver changelog

* Remove redundant schemas from h2

* Spelling fix

Pre-rebase SHA: 8a2c7e0 or 5686b2f

* MySQL does *not* support schemas

* Bad rebase

* Typo?

Co-Authored-By: default avatarTim Macdonald <tim@metabase.com>
parent d8bf730d
Branches
Tags
No related merge requests found
......@@ -6,12 +6,17 @@ title: Driver interface changelog
## Metabase 0.47.0
- The multimethod `metabase.driver/syncable-schemas` has been added. This method is used to list schemas to upload
- The multimethod `metabase.driver/syncable-schemas` has been added. This method is used to list schemas to upload
CSVs to, and it should include all schemas that are able to be synced to. Currently it only needs to be implemented
if the database has schema, and the database supports the `uploads` feature.
- A new driver feature has been added: `:schemas`. This feature signals whether the database organizes tables in
schemas (also known as namespaces) or not. Most databases have schemas so this feature is supported on by default.
An implemention of the multimethod `metabase.driver/database-supports?` for `:schemas` is required only if the
database doesn't store tables in schemas.
- The multimethod `metabase.driver/supports?` has been deprecated in favor of `metabase.driver/database-supports?`. The existing default implementation of `database-supports?` currently calls `supports?`, but it will be removed in 0.55.0.
## Metabase 0.46.0
- The process for building a driver has changed slightly in Metabase 0.46.0. Your build command should now look
......
......@@ -270,6 +270,8 @@
(when-not (get (methods driver/supports?) [:mongo :foreign-keys])
(defmethod driver/supports? [:mongo :foreign-keys] [_ _] true))
(defmethod driver/database-supports? [:mongo :schemas] [_driver _feat _db] false)
(defmethod driver/database-supports? [:mongo :expressions]
[_driver _feature db]
(-> (:dbms_version db)
......
......@@ -38,6 +38,7 @@
:percentile-aggregations false
:advanced-math-expressions false
:standard-deviation-aggregations false
:schemas false
:datetime-diff true
:now true
;; SQLite `LIKE` clauses are case-insensitive by default, and thus cannot be made case-sensitive. So let people know
......
......@@ -493,6 +493,10 @@
;; Does the driver support uploading files
:uploads
;; Does the driver support schemas (aka namespaces) for tables
;; DEFAULTS TO TRUE
:schemas
;; Does the driver support custom writeback actions. Drivers that support this must
;; implement [[execute-write-query!]]
:actions/custom
......@@ -516,6 +520,8 @@
(defmethod supports? :default [_ _] false)
(defmethod supports? [::driver :schemas] [_ _] true)
(defmulti database-supports?
"Does this driver and specific instance of a database support a certain `feature`?
(A feature is a keyword, and can be any of the ones listed above in `driver-features`.
......
......@@ -57,6 +57,7 @@
:percentile-aggregations false
:full-join false
:uploads true
:schemas false
;; MySQL LIKE clauses are case-sensitive or not based on whether the collation of the server and the columns
;; themselves. Since this isn't something we can really change in the query itself don't present the option to the
;; users in the UI
......
......@@ -47,10 +47,11 @@
(driver/register! :postgres, :parent :sql-jdbc)
(doseq [[feature supported?] {:datetime-diff true
:persist-models true
:convert-timezone true
:now true}]
(doseq [[feature supported?] {:convert-timezone true
:datetime-diff true
:now true
:persist-models true
:schemas true}]
(defmethod driver/database-supports? [:postgres feature] [_driver _feature _db] supported?))
(defmethod driver/database-supports? [:postgres :nested-field-columns]
......
......@@ -4,6 +4,7 @@
[metabase.driver :as driver]
[metabase.driver.impl :as driver.impl]
[metabase.plugins.classloader :as classloader]
[metabase.test :as mt]
[metabase.test.data.env :as tx.env]))
(set! *warn-on-reflection* true)
......@@ -53,3 +54,15 @@
props-by-name)
vec
pr-str)))))))
(deftest supports-schemas-matches-describe-database-test
(mt/test-drivers (mt/normal-drivers)
(if (driver/database-supports? driver/*driver* :schemas (mt/db))
(testing "`describe-database` should return schemas with tables if the database supports schemas"
(is (some? (->> (driver/describe-database driver/*driver* (mt/db))
:tables
(some :schema)))))
(testing "`describe-database` should not return schemas with tables if the database doesn't support schemas"
(is (nil? (->> (driver/describe-database driver/*driver* (mt/db))
:tables
(some :schema))))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment