A Metric is a saved MBQL 'macro' expanding to a combination of :aggregation and/or :filter clauses. It is passed in as an :aggregation clause but is replaced by the expand-macros middleware with the appropriate clauses.
:aggregation
:filter
expand-macros
(
ns
metabase.models.legacy-metric
:require
[
metabase.api.common
:as
api
]
metabase.models.audit-log
audit-log
metabase.models.database
database
metabase.models.interface
mi
metabase.permissions.core
perms
metabase.util
u
metabase.util.i18n
:refer
tru
methodical.core
methodical
toucan2.core
t2
)
methodical/defmethod
t2/table-name
:model/LegacyMetric
_model
:metric
doto
derive
:metabase/model
:hook/timestamped?
::mi/write-policy.superuser
::mi/create-policy.superuser
defmethod
mi/can-read?
instance
let
table
:table
t2/hydrate
perms/user-has-permission-for-table?
api/*current-user-id*
:perms/manage-table-metadata
:yes
:db_id
u/the-id
model
pk
t2/select-one
t2/deftransforms
{
:definition
mi/transform-legacy-metric-segment-definition
}
t2/define-before-update
:keys
id
,
metric
u/prog1
t2/changes
;; throw an Exception if someone tries to update creator_id
when
contains?
<>
:creator_id
not=
t2/select-one-fn
:id
throw
UnsupportedOperationException.
"You cannot update the creator_id of a Metric."
t2/define-before-delete
_metric
t2/delete!
:model/Revision
:model
"Metric"
:model_id
mi/perms-objects-set
read-or-write
or
'
Table
:schema
:table_id
------------------------------------------------ Audit Log --------------------------------------------------------
audit-log/model-details
_event-type
table-id
db-id
database/table-id->database-id
assoc
select-keys
:name
:description
:revision_message
:database_id