Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metabase.util.schema to Malli #27471

Merged
merged 19 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,34 @@
;; :shadowed-var {:level :warning}
:deprecated-var
{:exclude
{metabase.cmd/dump {:namespaces ["metabase\\.cmd-test" "metabase-enterprise\\.serialization\\.cmd-test"]}
metabase.cmd/load {:namespaces ["metabase\\.cmd-test" "metabase-enterprise\\.serialization\\.cmd-test"]}
{metabase.cmd/dump {:namespaces ["metabase.cmd-test" "metabase-enterprise.serialization.cmd-test"]}
metabase.cmd/load {:namespaces ["metabase.cmd-test" "metabase-enterprise.serialization.cmd-test"]}
metabase.api.common/defendpoint-schema {:namespaces ["metabase.api.*" "metabase-enterprise.*.api" "metabase.util.schema-test"]}
metabase.api.common/defendpoint-async-schema {:namespaces ["metabase.api.*"]}
metabase.db.data-migrations/data-migrations {:namespaces ["metabase.db.data-migrations"]}
metabase.db.data-migrations/defmigration {:namespaces ["metabase.db.data-migrations"]}
metabase.db.data-migrations/run-migration-if-needed! {:namespaces ["metabase.db.data-migrations"]}
metabase.driver.common/ThreadSafeSimpleDateFormat {:namespaces ["metabase\\.driver.*"]}
metabase.driver.common/create-db-time-formatters {:namespaces ["metabase\\.driver.*"]}
metabase.driver.common/ThreadSafeSimpleDateFormat {:namespaces ["metabase.driver.*"]}
metabase.driver.common/create-db-time-formatters {:namespaces ["metabase.driver.*"]}
qnkhuat marked this conversation as resolved.
Show resolved Hide resolved
metabase.driver.common/current-db-time {:namespaces ["metabase.*"]}
metabase.driver.common/current-db-time-date-formatters {:namespaces ["metabase\\.driver.*"]}
metabase.driver.common/current-db-time-native-query {:namespaces ["metabase\\.driver.*"]}
metabase.driver.common/first-successful-parse {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql-jdbc.execute.old-impl/read-column {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql-jdbc.execute.old-impl/set-timezone-sq {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql-jdbc.execute.old-impl/set-timezone-sql {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql-jdbc.execute/set-time-zone-if-supported! {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql-jdbc.sync.interface/syncable-schemas {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql.query-processor.deprecated/*field-options* {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql.query-processor.deprecated/*source-query* {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql.query-processor.deprecated/*table-alias* {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql.query-processor.deprecated/escape-alias {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql.query-processor.deprecated/field->alias {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql.query-processor.deprecated/field->identifier {:namespaces ["metabase\\.driver.*"]}
metabase.driver.sql.query-processor.deprecated/prefix-field-alias {:namespaces ["metabase\\.driver.*"]}
metabase.driver.common/current-db-time-date-formatters {:namespaces ["metabase.driver.*"]}
metabase.driver.common/current-db-time-native-query {:namespaces ["metabase.driver.*"]}
metabase.driver.common/first-successful-parse {:namespaces ["metabase.driver.*"]}
metabase.driver.sql-jdbc.execute.old-impl/read-column {:namespaces ["metabase.driver.*"]}
metabase.driver.sql-jdbc.execute.old-impl/set-timezone-sq {:namespaces ["metabase.driver.*"]}
metabase.driver.sql-jdbc.execute.old-impl/set-timezone-sql {:namespaces ["metabase.driver.*"]}
metabase.driver.sql-jdbc.execute/set-time-zone-if-supported! {:namespaces ["metabase.driver.*"]}
metabase.driver.sql-jdbc.sync.interface/syncable-schemas {:namespaces ["metabase.driver.*"]}
metabase.driver.sql.query-processor.deprecated/*field-options* {:namespaces ["metabase.driver.*"]}
metabase.driver.sql.query-processor.deprecated/*source-query* {:namespaces ["metabase.driver.*"]}
metabase.driver.sql.query-processor.deprecated/*table-alias* {:namespaces ["metabase.driver.*"]}
metabase.driver.sql.query-processor.deprecated/escape-alias {:namespaces ["metabase.driver.*"]}
metabase.driver.sql.query-processor.deprecated/field->alias {:namespaces ["metabase.driver.*"]}
metabase.driver.sql.query-processor.deprecated/field->identifier {:namespaces ["metabase.driver.*"]}
metabase.driver.sql.query-processor.deprecated/prefix-field-alias {:namespaces ["metabase.driver.*"]}
metabase.driver/current-db-time {:namespaces ["metabase.*"]}
metabase.driver/supports? {:namespaces ["metabase.*"]}
metabase.public-settings.premium-features/enable-enhancements? {:namespaces ["metabase\\.models.*"]}
metabase.public-settings.premium-features/enable-enhancements? {:namespaces ["metabase.models.*"]}
metabase.query-processor.middleware.resolve-joins/maybe-resolve-source-table {:namespaces ["metabase.*"]}
metabase.query-processor.util/normalize-token {:namespaces ["metabase.*"]}
metabase.util/key-by {:namespaces ["metabase(?:-enterprise)?.*"]}
Expand Down Expand Up @@ -430,6 +432,7 @@
metabase.api.common/defendpoint-schema hooks.metabase.api.common/defendpoint
metabase.api.common/defendpoint hooks.metabase.api.common/defendpoint
metabase.api.common/defendpoint-async hooks.metabase.api.common/defendpoint
metabase.api.common/defendpoint-async-schema hooks.metabase.api.common/defendpoint
metabase.api.dashboard-test/with-chain-filter-fixtures hooks.common/let-one-with-optional-value
metabase.api.embed-test/do-response-formats hooks.common/with-two-bindings
metabase.api.embed-test/with-chain-filter-fixtures hooks.common/let-one-with-optional-value
Expand Down
4 changes: 2 additions & 2 deletions .lsp/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
:clean {:ns-inner-blocks-indentation :keep}
:linters {:clojure-lsp/unused-public-var {:level :warning
:exclude-when-defined-by
#{metabase.api.common/defendpoint
metabase.api.common/malli-defendpoint}}}}
#{metabase.api.common/defendpoint-schema
metabase.api.common/defendpoint}}}}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
- Permissions have three levels: full, limited, and none.
- Native query download permissions are fully inferred from the non-native download permissions. For more details,
see the docstring for [[metabase.models.permissions/update-native-download-permissions!]]."
[group-id :- su/IntGreaterThanZero db-id :- su/IntGreaterThanZero new-download-perms :- perms/DownloadPermissionsGraph]
[group-id :- su/IntGreaterThanZeroPlumatic db-id :- su/IntGreaterThanZeroPlumatic new-download-perms :- perms/DownloadPermissionsGraph]
(when-not (premium-features/enable-advanced-permissions?)
(throw (perms/ee-permissions-exception :download)))
(when-let [schemas (:schemas new-download-perms)]
Expand Down Expand Up @@ -157,7 +157,7 @@

(s/defn update-db-data-model-permissions!
"Update the data model permissions graph for a database."
[group-id :- su/IntGreaterThanZero db-id :- su/IntGreaterThanZero new-data-model-perms :- perms/DataModelPermissionsGraph]
[group-id :- su/IntGreaterThanZeroPlumatic db-id :- su/IntGreaterThanZeroPlumatic new-data-model-perms :- perms/DataModelPermissionsGraph]
(when-not (premium-features/enable-advanced-permissions?)
(throw (perms/ee-permissions-exception :data-model)))
(when-let [schemas (:schemas new-data-model-perms)]
Expand Down Expand Up @@ -188,7 +188,7 @@

(s/defn update-db-details-permissions!
"Update the DB details permissions for a database."
[group-id :- su/IntGreaterThanZero db-id :- su/IntGreaterThanZero new-perms :- perms/DetailsPermissions]
[group-id :- su/IntGreaterThanZeroPlumatic db-id :- su/IntGreaterThanZeroPlumatic new-perms :- perms/DetailsPermissions]
(when-not (premium-features/enable-advanced-permissions?)
(throw (perms/ee-permissions-exception :details)))
(case new-perms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

(def ^:private ApplicationPermissionsGraph
{:revision s/Int
:groups {su/IntGreaterThanZero GroupPermissionsGraph}})
:groups {su/IntGreaterThanZeroPlumatic GroupPermissionsGraph}})

;; -------------------------------------------------- Fetch Graph ---------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
(def ResultsMetadata
"Schema for the expected format for `:metadata` returned by an internal query function."
(su/non-empty
[[(s/one su/KeywordOrString "field name")
(s/one {:base_type su/FieldType, :display_name su/NonBlankString, s/Keyword s/Any}
[[(s/one su/KeywordOrStringPlumatic "field name")
(s/one {:base_type su/FieldTypePlumatic, :display_name su/NonBlankStringPlumatic, s/Keyword s/Any}
"field metadata")]]))

(defmulti internal-query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
;; ORDER BY {{group-fn(timestamp}} ASC
(s/defn views-by-time
"Get views of a Card or Dashboard broken out by a time `unit`, e.g. `day` or `day-of-week`."
[model :- ModelName, model-id :- su/IntGreaterThanZero, unit :- common/DateTimeUnitStr]
[model :- ModelName, model-id :- su/IntGreaterThanZeroPlumatic, unit :- common/DateTimeUnitStr]
{:metadata [[:date {:display_name "Date", :base_type (common/datetime-unit-str->base-type unit)}]
[:views {:display_name "Views", :base_type :type/Integer}]]
:results (let [grouped-timestamp (common/grouped-datetime unit :timestamp)]
Expand All @@ -40,7 +40,7 @@
(s/defn cached-views-by-time
"Get number of views of a Card broken out by a time `unit`, e.g. `day` or `day-of-week` and by cache status.
Still here instead of in cards because of similarity to views-by-time"
[card-id :- su/IntGreaterThanZero, unit :- common/DateTimeUnitStr]
[card-id :- su/IntGreaterThanZeroPlumatic, unit :- common/DateTimeUnitStr]
{:metadata [[:date {:display_name "Date",
:base_type (common/datetime-unit-str->base-type unit)}]
[:cached-views {:display_name "Cached Views",
Expand All @@ -64,7 +64,7 @@
(s/defn avg-execution-time-by-time
"Get average execution time of a Card broken out by a time `unit`, e.g. `day` or `day-of-week`.
Still here instead of in cards because of similarity to views-by-time"
[card-id :- su/IntGreaterThanZero, unit :- common/DateTimeUnitStr]
[card-id :- su/IntGreaterThanZeroPlumatic, unit :- common/DateTimeUnitStr]
{:metadata [[:date {:display_name "Date", :base_type (common/datetime-unit-str->base-type unit)}]
[:avg_runtime {:display_name "Average Runtime", :base_type :type/Number}]]
:results (let [grouped-timestamp (common/grouped-datetime unit :started_at)]
Expand All @@ -80,7 +80,7 @@
(s/defn revision-history
"Get a revision history table for a Card or Dashboard."
[model-entity :- (s/cond-pre (mi/InstanceOf Card) (mi/InstanceOf Dashboard))
model-id :- su/IntGreaterThanZero]
model-id :- su/IntGreaterThanZeroPlumatic]
{:metadata [[:timestamp {:display_name "Edited on", :base_type :type/DateTime}]
[:user_id {:display_name "User ID", :base_type :type/Integer, :remapped_to :user_name}]
[:user_name {:display_name "Edited by", :base_type :type/Name, :remapped_from :user_id}]
Expand All @@ -95,7 +95,7 @@

(s/defn audit-log
"Get a view log for a Card or Dashboard."
[model :- ModelName, model-id :- su/IntGreaterThanZero]
[model :- ModelName, model-id :- su/IntGreaterThanZeroPlumatic]
{:metadata [[:when {:display_name "When", :base_type :type/DateTime}]
[:user_id {:display_name "User ID", :base_type :type/Integer, :remapped_to :who}]
[:who {:display_name "Who", :base_type :type/Name, :remapped_from :user_id}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@

;; Get views of a Dashboard broken out by a time `unit`, e.g. `day` or `day-of-week`.
(s/defmethod audit.i/internal-query ::views-by-time
[_ dashboard-id :- su/IntGreaterThanZero datetime-unit :- common/DateTimeUnitStr]
[_ dashboard-id :- su/IntGreaterThanZeroPlumatic datetime-unit :- common/DateTimeUnitStr]
(card-and-dash-detail/views-by-time "dashboard" dashboard-id datetime-unit))

;; Revision history for a specific Dashboard.
(s/defmethod audit.i/internal-query ::revision-history
[_ dashboard-id :- su/IntGreaterThanZero]
[_ dashboard-id :- su/IntGreaterThanZeroPlumatic]
(card-and-dash-detail/revision-history Dashboard dashboard-id))

;; View log for a specific Dashboard.
(s/defmethod audit.i/internal-query ::audit-log
[_ dashboard-id :- su/IntGreaterThanZero]
[_ dashboard-id :- su/IntGreaterThanZeroPlumatic]
(card-and-dash-detail/audit-log "dashboard" dashboard-id))

;; Information about the Saved Questions (Cards) in this instance.
(s/defmethod audit.i/internal-query ::cards
[_ dashboard-id :- su/IntGreaterThanZero]
[_ dashboard-id :- su/IntGreaterThanZeroPlumatic]
{:metadata [[:card_id {:display_name "Card ID", :base_type :type/Integer, :remapped_to :card_name}]
[:card_name {:display_name "Title", :base_type :type/Name, :remapped_from :card_id}]
[:collection_id {:display_name "Collection ID", :base_type :type/Integer, :remapped_to :collection_name}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

;; Query execution history for queries against this Database.
(s/defmethod audit.i/internal-query ::audit-log
[_ database-id :- su/IntGreaterThanZero]
[_ database-id :- su/IntGreaterThanZeroPlumatic]
{:metadata [[:started_at {:display_name "Viewed on", :base_type :type/DateTime}]
[:card_id {:display_name "Card ID", :base_type :type/Integer, :remapped_to :query}]
[:query_hash {:display_name "Query Hash", :base_type :type/Text}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

;; Details about a specific query (currently just average execution time).
(s/defmethod audit.i/internal-query ::details
[_ query-hash :- su/NonBlankString]
[_ query-hash :- su/NonBlankStringPlumatic]
{:metadata [[:query {:display_name "Query", :base_type :type/Dictionary}]
[:average_execution_time {:display_name "Avg. Exec. Time (ms)", :base_type :type/Number}]]
:results (common/reducible-query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@

;; Get views of a Card broken out by a time `unit`, e.g. `day` or `day-of-week`.
(s/defmethod audit.i/internal-query ::views-by-time
[_ card-id :- su/IntGreaterThanZero datetime-unit :- common/DateTimeUnitStr]
[_ card-id :- su/IntGreaterThanZeroPlumatic datetime-unit :- common/DateTimeUnitStr]
(card-and-dash-detail/views-by-time "card" card-id datetime-unit))

;; Get cached views of a Card broken out by a time `unit`, e.g. `day` or `day-of-week`.
(s/defmethod audit.i/internal-query ::cached-views-by-time
[_ card-id :- su/IntGreaterThanZero, datetime-unit :- common/DateTimeUnitStr]
[_ card-id :- su/IntGreaterThanZeroPlumatic, datetime-unit :- common/DateTimeUnitStr]
(card-and-dash-detail/cached-views-by-time card-id datetime-unit))

;; Get the revision history for a Card.
(s/defmethod audit.i/internal-query ::revision-history
[_ card-id :- su/IntGreaterThanZero]
[_ card-id :- su/IntGreaterThanZeroPlumatic]
(card-and-dash-detail/revision-history Card card-id))

;; Get a view log for a Card.
(s/defmethod audit.i/internal-query ::audit-log
[_ card-id :- su/IntGreaterThanZero]
[_ card-id :- su/IntGreaterThanZeroPlumatic]
(card-and-dash-detail/audit-log "card" card-id))

;; Average execution time broken out by period
(s/defmethod audit.i/internal-query ::avg-execution-time-by-time
[_ card-id :- su/IntGreaterThanZero datetime-unit :- common/DateTimeUnitStr]
[_ card-id :- su/IntGreaterThanZeroPlumatic datetime-unit :- common/DateTimeUnitStr]
(card-and-dash-detail/avg-execution-time-by-time card-id datetime-unit))
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

;; View log for a specific Table.
(s/defmethod audit.i/internal-query ::audit-log
[_ table-id :- su/IntGreaterThanZero]
[_ table-id :- su/IntGreaterThanZeroPlumatic]
{:metadata [[:started_at {:display_name "Viewed on", :base_type :type/DateTime}]
[:card_id {:display_name "Card ID", :base_type :type/Integer, :remapped_to :query}]
[:query {:display_name "Query", :base_type :type/Text, :remapped_from :card_id}]
Expand Down
Loading