The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Select models by id through their module's db fn (#85694)
Alexander Polyankin568578ecd702
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex dd568acdcec..0f96145d945 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -118,7 +118,8 @@usersutilwarehouse-schema-overlay- warehouses}+ warehouses+ warehouses.schema}:model-exports #{:model/Action :model/ImplicitAction :model/QueryAction}:model-imports #{:model/Card:model/Collection@@ -147,7 +148,7 @@permissionspublic-sharingutil}- :model-imports #{:model/Action :model/Card :model/Database}}+ :model-imports #{:model/Action :model/Card}}activity-feed{:team "UX West"@@ -157,13 +158,17 @@:uses #{apibatch-processingcollections+ dashboards+ documentseventslib.schemamodelspermissions+ queriesutilutil.config- warehouse-schema-overlay}+ warehouse-schema-overlay+ warehouses.schema}:model-imports #{:model/Card:model/Collection:model/Dashboard@@ -397,7 +402,7 @@task.historytracingutil- warehouse-schema-overlay}+ warehouses.schema}:model-exports #{:model/AuditLog}:model-imports #{:model/ApiKey:model/Card@@ -435,6 +440,7 @@lib.schemamodelspremium-features+ queriesquery-permissionsutil}:model-exports #{:model/ViewLog}@@ -523,6 +529,7 @@channel{:team "Gadget":api #{metabase.channel.core+ metabase.channel.dbmetabase.channel.emailmetabase.channel.email.messagesmetabase.channel.init@@ -563,12 +570,11 @@tilestimelineutil- util.config}+ util.config+ warehouses}:model-exports #{:model/Channel :model/ChannelTemplate}- :model-imports #{:model/Dashboard- :model/DashboardCard+ :model-imports #{:model/DashboardCard:model/DashboardTab- :model/Database:model/PulseChannel:model/User}}@@ -616,6 +622,7 @@:api #{metabase.collections.childrenmetabase.collections.coremetabase.collections.curation+ metabase.collections.dbmetabase.collections.initmetabase.collections.models.collectionmetabase.collections.models.collection.root@@ -688,7 +695,9 @@:uses #{analyticsapichannel+ documentsevents+ explorationsliblib.schemamodels@@ -769,6 +778,7 @@{:team "UX West":api #{metabase.dashboards.autoplacemetabase.dashboards.constants+ metabase.dashboards.dbmetabase.dashboards.initmetabase.dashboards.models.dashboardmetabase.dashboards.models.dashboard-card@@ -849,6 +859,7 @@query-processorrequestrevisions+ usersutilxrays}:model-imports #{:model/Action@@ -891,6 +902,7 @@syncutilwarehouse-schema-overlay+ warehouseswarehouses.schema}:model-imports #{:model/Database:model/Dimension@@ -912,6 +924,7 @@{:team "UX West":api #{metabase.documents.apimetabase.documents.core+ metabase.documents.dbmetabase.documents.initmetabase.documents.prose-mirrormetabase.documents.schema}@@ -921,6 +934,7 @@audit-app.view-logbatch-processingcollections+ dashboardseventsliblib.be@@ -936,7 +950,7 @@settingsstalenessutil- warehouse-schema-overlay}+ warehouses.schema}:model-exports #{:model/Document}:model-imports #{:model/Card:model/Collection@@ -1061,7 +1075,6 @@util}:model-imports #{:model/Card:model/Dashboard- :model/DashboardCard:model/EmbeddingSdkReact18Host:model/EmbeddingTheme}}@@ -1085,7 +1098,11 @@explorations{:team "UX West"- :api #{metabase.explorations.api metabase.explorations.core metabase.explorations.init metabase.explorations.schema}+ :api #{metabase.explorations.api+ metabase.explorations.core+ metabase.explorations.db+ metabase.explorations.init+ metabase.explorations.schema}:uses #{analyticsanalytics.interfaceapi@@ -1111,6 +1128,7 @@query-processorrequestsearch+ segmentssettingstasktask.history@@ -1197,6 +1215,7 @@{:team "UX West":api #{metabase.indexed-entities.apimetabase.indexed-entities.core+ metabase.indexed-entities.dbmetabase.indexed-entities.init}:uses #{analyticsapi@@ -1205,12 +1224,13 @@lib.schemamodelspermissions+ queriesquery-processorsearchsynctaskutil}- :model-exports #{:model/ModelIndex :model/ModelIndexValue}+ :model-exports #{:model/ModelIndexValue}:model-imports #{:model/Card :model/Collection}}interestingness@@ -1320,10 +1340,12 @@lib.metadatalib.schemalib.types+ queriessettingsutil- warehouse-schema-overlay}- :model-imports #{:model/Card :model/Field :model/Table}}+ warehouse-schema-overlay+ warehouses.schema}+ :model-imports #{:model/Field}}lib.schema{:team "Querying Platform"@@ -1453,7 +1475,6 @@:model/Field:model/Measure:model/NativeQuerySnippet- :model/Notification:model/Pulse:model/Segment:model/Table@@ -1487,7 +1508,7 @@measures{:team "Graphy"- :api #{metabase.measures.api metabase.measures.schema}+ :api #{metabase.measures.api metabase.measures.db metabase.measures.schema}:uses #{apicollectionsevents@@ -1542,6 +1563,7 @@audit-appchannelcollections+ dashboardsdata-appsdocumentsdriver@@ -1554,6 +1576,7 @@lib.belib.metadatalib.schema+ measuresmetabot.llmmetabot.slackbotmetrics@@ -1571,6 +1594,7 @@requestsearchsearch.entity-retrieval+ segmentsserversettingssql-tools@@ -1579,10 +1603,12 @@tasktimelinetransforms+ usersutilutil.configwarehouse-schema-overlaywarehouses+ warehouses.schemaxrays}:model-exports #{:model/AiUsageLog:model/Metabot@@ -1637,7 +1663,6 @@sso.auth-identityutil}:model-imports #{:model/Card- :model/Collection:model/Dashboard:model/DashboardCard:model/DashboardTab@@ -1678,11 +1703,9 @@startuputilutil.config- warehouse-schema-overlay}- :model-imports #{:model/Card- :model/Database- :model/Field- :model/Table}}+ warehouse-schema-overlay+ warehouses}+ :model-imports #{:model/Card :model/Field :model/Table}}metabot.slackbot{:team "Metabot"@@ -1700,6 +1723,7 @@metabotmetabot.llmpermissions+ queriesquery-processorrequestserver@@ -1708,7 +1732,7 @@systemuploadutil}- :model-imports #{:model/AuthIdentity :model/Card :model/MetabotMessage}}+ :model-imports #{:model/AuthIdentity :model/MetabotMessage}}metrics{:team "UX West"@@ -1723,15 +1747,18 @@lib.metadatalib.metriclib.schema+ measuresmodelsparameterspermissions+ queriesquery-processorrequestserverutil- warehouse-schema-overlay}- :model-imports #{:model/Card :model/Field :model/Measure}}+ warehouse-schema-overlay+ warehouses.schema}+ :model-imports #{:model/Card :model/Field}}mfa{:team "UX West"@@ -1867,6 +1894,7 @@:api #{metabase.notification.apimetabase.notification.cardmetabase.notification.core+ metabase.notification.dbmetabase.notification.initmetabase.notification.modelsmetabase.notification.payload.core}@@ -1908,7 +1936,6 @@:model-imports #{:model/Card:model/Channel:model/ChannelTemplate- :model/Dashboard:model/DashboardCard:model/DashboardTab:model/TaskHistory@@ -1952,6 +1979,7 @@lib.schemamodelsparameters.schema+ queriesquery-processorutilutil.classloader@@ -2134,6 +2162,7 @@app-dbchannelcollections+ dashboardsdriverembeddingevents@@ -2144,11 +2173,13 @@parameters.schemapermissionspremium-features+ queriesquery-processorrequesttasktask.historytracing+ usersutilutil.classloaderutil.config@@ -2170,8 +2201,9 @@{:team "Graphy":api #{metabase.queries.card-schemametabase.queries.core+ metabase.queries.dbmetabase.queries.init- metabase.queries.models.query ; TODO FIXME+ metabase.queries.models.querymetabase.queries.schema}:uses #{analyticsanalytics.interface@@ -2212,6 +2244,7 @@util.configutil.graphwarehouse-schema-overlay+ warehouseswarehouses.schema}:model-exports #{:model/Card:model/ParameterCard@@ -2269,7 +2302,6 @@:model/Collection:model/Dashboard:model/Database- :model/StoredResult:model/StoredResultUse:model/Table}}@@ -2284,6 +2316,7 @@lib.schemamodelspermissions+ queriesquery-processorrequestutil@@ -2369,13 +2402,12 @@usersutilutil.config- warehouse-schema-overlay}+ warehouses.schema}:model-imports #{:model/Card:model/DashboardCardSeries:model/Database:model/QueryCache- :model/QueryExecution- :model/Table}}+ :model/QueryExecution}}query-processor.cache-backend{:team "Querying Platform"@@ -2595,7 +2627,7 @@segments{:team "Graphy":module-exports #{segments.rest}- :api #{metabase.segments.schema}+ :api #{metabase.segments.db metabase.segments.schema}:uses #{apicollectionslib@@ -2689,6 +2721,7 @@systemtasktracing+ usersutilutil.config}:model-exports #{:model/Session}@@ -2751,12 +2784,12 @@apiappearanceevents- lib.schemarequestsettingssetupsso.auth-identitysystem+ usersutil}:model-imports #{:model/User}}@@ -2984,17 +3017,18 @@metabase.tiles.initmetabase.tiles.settings}:uses #{api+ dashboardsliblib.belib.legacy-mbqllib.schemaparameters.schemapremium-features+ queriesquery-processorsettingsstartup- util}- :model-imports #{:model/Card :model/Dashboard :model/DashboardCard}}+ util}}timeline{:team "UX West"@@ -3028,6 +3062,7 @@transforms.indexestransforms.inspector}:api #{metabase.transforms.core+ metabase.transforms.dbmetabase.transforms.initmetabase.transforms.instrumentationmetabase.transforms.interface@@ -3062,11 +3097,11 @@transforms.feature-gatingtransforms.indexesutil- warehouse-schema-overlay}+ warehouse-schema-overlay+ warehouses+ warehouses.schema}:model-exports #{:model/Transform- :model/TransformDagRun:model/TransformJob- :model/TransformJobRun:model/TransformJobTransformTag:model/TransformRun:model/TransformTag@@ -3109,7 +3144,8 @@synctransforms.indexesutil- warehouse-schema-overlay}}+ warehouse-schema-overlay+ warehouses.schema}}transforms.feature-gating{:team "Graphy"@@ -3159,9 +3195,7 @@transforms.baseutil}:model-imports #{:model/Transform- :model/TransformDagRun:model/TransformJob- :model/TransformJobRun:model/TransformJobTransformTag:model/TransformRun:model/TransformTag}}@@ -3189,6 +3223,7 @@syncutilwarehouse-schema-overlay+ warehouseswarehouses.schema}:model-imports #{:model/Card:model/Database@@ -3229,6 +3264,7 @@{:team "UX West":module-exports #{users.tenants}:api #{metabase.users.core+ metabase.users.dbmetabase.users.initmetabase.users.models.usermetabase.users.models.user-parameter-value@@ -3266,6 +3302,7 @@api-scopeappearancecollections+ dashboardseventslib.schemamodels@@ -3334,6 +3371,7 @@:module-exports #{warehouses.schemawarehouses.secrets}:api #{metabase.warehouses.core+ metabase.warehouses.dbmetabase.warehouses.initmetabase.warehouses.models.databasemetabase.warehouses.schema}@@ -3403,6 +3441,7 @@{:team "UX West":ns-prefix "metabase.warehouse-schema":api #{metabase.warehouse-schema.core+ metabase.warehouse-schema.dbmetabase.warehouse-schema.fieldmetabase.warehouse-schema.field-values.distinct-batchmetabase.warehouse-schema.humanization@@ -3482,11 +3521,10 @@uploadutilwarehouse-schema-overlay+ warehouseswarehouses.schemaxrays}- :model-imports #{:model/Collection- :model/Database- :model/Dimension+ :model-imports #{:model/Dimension:model/Field:model/FieldValues:model/Table}}@@ -3530,6 +3568,7 @@sync.analyzeutilwarehouse-schema-overlay+ warehouseswarehouses.schema}:model-imports #{:model/Card:model/Collection@@ -3537,7 +3576,6 @@:model/DashboardCard:model/Database:model/Field- :model/ModelIndex:model/Query:model/Revision:model/Segment@@ -3559,11 +3597,10 @@query-processorsyncutil- warehouse-schema-overlay}- :model-imports #{:model/Database- :model/Field- :model/FieldValues- :model/Table}}+ warehouse-schema-overlay+ warehouses+ warehouses.schema}+ :model-imports #{:model/Field :model/FieldValues}}enterprise/advanced-config{:team "UX West"@@ -3688,9 +3725,9 @@{:team "UX West":api #{metabase-enterprise.billing.api.routes}:uses #{api- lib.schemapremium-featuresstore-api+ usersutil}:model-imports #{:model/User}}@@ -3698,6 +3735,7 @@{:team "UX West":api #{metabase-enterprise.cache.init}:uses #{cache+ dashboardslib.schemapremium-featuresquery-processor@@ -3706,7 +3744,6 @@util}:model-imports #{:model/CacheConfig:model/Card- :model/Dashboard:model/DatabaseRouter:model/Query:model/QueryCache@@ -3738,12 +3775,11 @@:api #{metabase-enterprise.database-replication.api metabase-enterprise.database-replication.init}:uses #{apidriver- lib.schemapremium-featuressettingsutil- enterprise/cloud}- :model-imports #{:model/Database}}+ warehouses+ enterprise/cloud}}enterprise/cloud.gsheets{:team "Cloud"@@ -3895,14 +3931,14 @@modelspermissionspremium-features+ usersutilwarehouse-schema-overlaywarehouses.schema}:model-imports #{:model/AuditLog:model/Collection:model/Dimension- :model/Table- :model/User}}+ :model/Table}}enterprise/database-routing{:team "UX West"@@ -3932,6 +3968,7 @@app-dbbatch-processingcollections+ dashboardsdata-appsdatabase-routingdocuments@@ -3960,6 +3997,7 @@utilutil.graphwarehouse-schema-overlay+ warehouses.schemaenterprise/permissions.sandbox}:model-imports #{:model/Action:model/Card@@ -4182,6 +4220,7 @@settingsssosso.auth-identity+ usersutilutil.config}:model-imports #{:model/AuthIdentity :model/User}}@@ -4189,8 +4228,7 @@enterprise/native-query-snippets{:team "Graphy":ns-prefix "metabase-enterprise.snippet-collections"- :uses #{lib.schema- models+ :uses #{modelsnative-query-snippetspermissionspremium-features@@ -4217,14 +4255,14 @@utilwarehouse-schema-overlaywarehouses+ warehouses.schemaenterprise/permissions.impersonation}:model-imports #{:model/ApplicationPermissionsRevision:model/ConnectionImpersonation:model/DataPermissions:model/Permissions:model/PermissionsGroupMembership- :model/Sandbox- :model/Table}}+ :model/Sandbox}}enterprise/permissions.debug{:team "UX West"@@ -4235,10 +4273,12 @@lib.schemamodelspermissions+ queriesquery-processor+ usersutilwarehouse-schema-overlay}- :model-imports #{:model/Card :model/User}}+ :model-imports #{:model/Card}}enterprise/permissions.impersonation{:team "Graphy"@@ -4381,9 +4421,11 @@collectionshealth-inspectorlib.schema+ measurespremium-featuressearchsearch.entity-retrieval+ segmentstaskutilwarehouse-schema-overlay@@ -4589,6 +4631,7 @@requestsettingssso.auth-identity+ usersutil}:model-exports #{:model/Tenant}:model-imports #{:model/Collection :model/User}}@@ -4611,6 +4654,7 @@sql-toolssql-tools.parsingtask+ transformstransforms.baseutil}:model-exports #{:model/TransformTest}@@ -4649,11 +4693,9 @@transformstransforms.baseutil- warehouse-schema-overlay}- :model-imports #{:model/Database- :model/Field- :model/Table- :model/Transform}}+ warehouse-schema-overlay+ warehouses}+ :model-imports #{:model/Field :model/Table :model/Transform}}enterprise/transforms.python{:team "Graphy"@@ -4679,12 +4721,11 @@transforms.baseutilutil.config- warehouse-schema-overlay}+ warehouse-schema-overlay+ warehouses+ warehouses.schema}:model-exports #{:model/PythonLibrary}- :model-imports #{:model/Database- :model/Field- :model/Table- :model/TransformRun}}+ :model-imports #{:model/Field :model/Table :model/TransformRun}}enterprise/upload{:team "UX West"@@ -4697,7 +4738,8 @@premium-featuresuploadutil- warehouse-schema-overlay}+ warehouse-schema-overlay+ warehouses.schema}:model-imports #{:model/Database :model/Table}}enterprise/warehousesdiff --git a/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.clj b/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.cljindex eb30653cbda..9ad58b07633 100644--- a/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.clj+++ b/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.clj@@ -13,7 +13,8 @@[metabase.query-processor.core :as qp][metabase.sync.field-values :as sync.field-values][metabase.util :as u]- [metabase.util.queue :as queue])+ [metabase.util.queue :as queue]+ [metabase.warehouse-schema.db :as warehouse-schema.db])(:import(java.util.concurrent ArrayBlockingQueue)))@@ -88,7 +89,7 @@(assert (seq pk-fields) "Table must have at least one primary key column");; TODO pass in the db-id from above rather(when (seq rows)- (let [{:keys [db_id]} (api/check-404 (action-v2.db/table table-id))+ (let [{:keys [db_id]} (api/check-404 (warehouse-schema.db/table table-id))row-pks (seq (map (partial get-row-pks pk-fields) rows))](assert (every? valid-pks row-pks) "All rows must have valid primary keys")(let [mp (lib-be/application-database-metadata-provider db_id)diff --git a/enterprise/backend/src/metabase_enterprise/action_v2/db.clj b/enterprise/backend/src/metabase_enterprise/action_v2/db.cljindex 0e0ad9ab67d..db1d75f3b4b 100644--- a/enterprise/backend/src/metabase_enterprise/action_v2/db.clj+++ b/enterprise/backend/src/metabase_enterprise/action_v2/db.clj@@ -10,21 +10,6 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))--(mu/defn active-table- "The active Table with `table-id`, or nil."- [table-id :- ::lib.schema.id/table]- (t2/select-one :model/Table :id table-id :active true {:from [(warehouse-schema-overlay/table-query)]}))--(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))-(mu/defn fields"The Fields with `field-ids`."[field-ids :- [:sequential ::lib.schema.id/field]]diff --git a/enterprise/backend/src/metabase_enterprise/action_v2/execute_form.clj b/enterprise/backend/src/metabase_enterprise/action_v2/execute_form.cljindex 85f6074ac20..eaaf1939a90 100644--- a/enterprise/backend/src/metabase_enterprise/action_v2/execute_form.clj+++ b/enterprise/backend/src/metabase_enterprise/action_v2/execute_form.clj@@ -10,6 +10,8 @@[metabase.util :as u][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]+ [metabase.warehouse-schema.db :as warehouse-schema.db]+ [metabase.warehouses.db :as warehouses.db][toucan2.core :as t2]))(def ^:private strip-namespace-hack (comp keyword name))@@ -103,8 +105,10 @@row-data]}](when-not table-id(throw (ex-info "Must provide table-id" {:status-code 400})))- (let [table (api/read-check (action-v2.db/active-table table-id))- database (action-v2.db/database (:db_id table))+ (let [table (api/read-check (let [table (warehouse-schema.db/table table-id)]+ (when (:active table)+ table)))+ database (warehouses.db/database (:db_id table))_ (actions/check-data-editing-enabled-for-database database)fields (-> (action-v2.db/active-fields-in-position-order table-id)(t2/hydrate :dimensions :has_field_values :values))diff --git a/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj b/enterprise/backend/src/metabase_enterprise/advanced_config/db.cljindex 9e9ba0d51c3..317d08b9670 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj@@ -73,11 +73,6 @@[database-name :- :string](t2/select-one [:model/Database :id :is_stub] :name database-name))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database database-id))-(mu/defn insert-database!"Insert `database` and return the new instance."[database :- ::warehouses.schema/database.update]diff --git a/enterprise/backend/src/metabase_enterprise/advanced_config/file/databases.clj b/enterprise/backend/src/metabase_enterprise/advanced_config/file/databases.cljindex 7bdfafab2d5..5b4c852fc1b 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_config/file/databases.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_config/file/databases.clj@@ -11,7 +11,8 @@[metabase.sync.core :as sync][metabase.util :as u][metabase.util.log :as log]- [metabase.util.quick-task :as quick-task]))+ [metabase.util.quick-task :as quick-task]+ [metabase.warehouses.db :as warehouses.db]))(s/def :metabase-enterprise.advanced-config.file.databases.config-file-spec/namestring?)@@ -141,7 +142,7 @@(:is_stub existing) (assoc :is_stub false:initial_sync_status "incomplete")))(when (:is_stub existing)- (sync-if-configured! (advanced-config.db/database (:id existing)))))+ (sync-if-configured! (warehouses.db/database (:id existing))))):else(let [db (advanced-config.db/insert-database! (cond-> (normalize-settings database)diff --git a/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.clj b/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.cljindex a9ccf826173..6d3f9646c14 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.clj@@ -7,6 +7,7 @@[metabase.premium-features.core :refer [defenterprise]][metabase.remote-sync.core :as remote-sync][metabase.util :as u]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouses.models.database :as database]))(defenterprise current-user-can-write-field?@@ -16,7 +17,7 @@:feature :advanced-permissions[instance](let [table (or (:table instance)- (advanced-permissions.db/table (:table_id instance)))]+ (warehouse-schema.db/table (:table_id instance)))](and (remote-sync/table-editable? table)(let [db-id (or (:db_id table)(database/table-id->database-id (:table_id instance)))]diff --git a/enterprise/backend/src/metabase_enterprise/advanced_permissions/db.clj b/enterprise/backend/src/metabase_enterprise/advanced_permissions/db.cljindex 410e640a766..50d13aa50a0 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_permissions/db.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_permissions/db.clj@@ -9,11 +9,6 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn group-manager?"Whether the User with `user-id` manages the PermissionsGroup with `group-id`."[user-id :- ::lib.schema.id/userdiff --git a/enterprise/backend/src/metabase_enterprise/billing/api.clj b/enterprise/backend/src/metabase_enterprise/billing/api.cljindex 3a04a7b1865..890d6b6a2f2 100644--- a/enterprise/backend/src/metabase_enterprise/billing/api.clj+++ b/enterprise/backend/src/metabase_enterprise/billing/api.clj@@ -10,6 +10,7 @@[metabase.api.macros :as api.macros][metabase.premium-features.core :as premium-features][metabase.store-api.core :as store-api]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.date-2.parse :as u.date.parse][metabase.util.i18n :as i18n]@@ -66,7 +67,7 @@using the embedding token and signed in user's email to fetch the billing information."[](let [token (premium-features/premium-embedding-token)- email (billing.db/user-email api/*current-user-id*)+ email (:email (users.db/user api/*current-user-id*))language (i18n/user-locale-string)](if (and token (str/starts-with? token "airgap_"))(billing-status)diff --git a/enterprise/backend/src/metabase_enterprise/billing/db.clj b/enterprise/backend/src/metabase_enterprise/billing/db.cljindex 51ee5ea0fbc..e68d9acd16c 100644--- a/enterprise/backend/src/metabase_enterprise/billing/db.clj+++ b/enterprise/backend/src/metabase_enterprise/billing/db.clj@@ -2,7 +2,6 @@"Application database queries for the billing module. Every function here is a direct Toucan 2 call with noadditional logic, so the rest of the module never talks to `toucan2.core` itself."(:require- [metabase.lib.schema.id :as lib.schema.id][metabase.util.malli :as mu][toucan2.core :as t2]))@@ -10,8 +9,3 @@"The number of active personal Users."[](t2/count :model/User :is_active true :type :personal))--(mu/defn user-email- "The email of the User with `user-id`."- [user-id :- ::lib.schema.id/user]- (t2/select-one-fn :email :model/User :id user-id))diff --git a/enterprise/backend/src/metabase_enterprise/cache/db.clj b/enterprise/backend/src/metabase_enterprise/cache/db.cljindex 2bb3785343d..3bb28a1f327 100644--- a/enterprise/backend/src/metabase_enterprise/cache/db.clj+++ b/enterprise/backend/src/metabase_enterprise/cache/db.clj@@ -147,11 +147,6 @@[query-hashes :- [:sequential bytes?]](t2/delete! :model/QueryCache :query_hash [:in query-hashes]))-(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id dashboard-id))-(mu/defn cache-configs-ready-to-run"The CacheConfigs of `strategy` whose next run is unset or due at `now`."[strategy :- :keyworddiff --git a/enterprise/backend/src/metabase_enterprise/cache/task/refresh_cache_configs.clj b/enterprise/backend/src/metabase_enterprise/cache/task/refresh_cache_configs.cljindex 49e2bb2a95e..7e7b9c2a22a 100644--- a/enterprise/backend/src/metabase_enterprise/cache/task/refresh_cache_configs.clj+++ b/enterprise/backend/src/metabase_enterprise/cache/task/refresh_cache_configs.clj@@ -6,6 +6,7 @@[java-time.api :as t][metabase-enterprise.cache.db :as cache.db][metabase-enterprise.cache.strategies :as strategies]+ [metabase.dashboards.db :as dashboards.db][metabase.premium-features.core :as premium-features :refer [defenterprise]][metabase.query-processor.core :as qp][metabase.task.core :as task]@@ -186,7 +187,7 @@[{:keys [model_id model]}](case model"question" [model_id]- "dashboard" (let [dashboard (-> (cache.db/dashboard model_id)+ "dashboard" (let [dashboard (-> (dashboards.db/dashboard model_id)(t2/hydrate :dashcards))](distinct (keep :card_id (:dashcards dashboard))))))diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.cljindex 58b06a10777..1b734ca488b 100644--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj@@ -225,7 +225,7 @@(api.macros/defendpoint :delete "/:id" :- :nil"Remove a custom visualization plugin and evict its on-disk cache."[{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]]- (let [plugin (api/write-check (custom-viz-plugin.db/non-blob-plugin id))]+ (let [plugin (api/write-check (custom-viz-plugin.db/custom-viz-plugin id))](custom-viz-plugin.db/delete-plugin! id)(cache/purge-plugin-cache! plugin)(events/publish-event! :event/custom-viz-plugin-delete {:object plugin@@ -238,11 +238,11 @@_query-paramsbody :- [:map {:closed true}[:enabled {:optional true} [:maybe :boolean]]]]- (let [existing (api/write-check (custom-viz-plugin.db/non-blob-plugin id))+ (let [existing (api/write-check (custom-viz-plugin.db/custom-viz-plugin id))updates (select-keys body [:enabled])](when (seq updates)(custom-viz-plugin.db/update-plugin! id updates))- (let [result (custom-viz-plugin.db/non-blob-plugin id)]+ (let [result (custom-viz-plugin.db/custom-viz-plugin id)](events/publish-event! :event/custom-viz-plugin-update {:object result:previous-object existing:user-id api/*current-user-id*})@@ -257,7 +257,7 @@[{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params{:keys [file]} :- BundleUploadParts]- (let [existing (api/write-check (custom-viz-plugin.db/non-blob-plugin id))+ (let [existing (api/write-check (custom-viz-plugin.db/custom-viz-plugin id))_ (api/check-400 (nil? (manifest/identifier-error (:identifier existing)))(format (str "This plugin's identifier (\"%s\") contains \":\", which is no longer allowed. ""Delete the plugin and upload the bundle under a name without \":\".")@@ -288,7 +288,7 @@respondraise](try- (let [plugin (api/read-check (custom-viz-plugin.db/non-blob-plugin id))+ (let [plugin (api/read-check (custom-viz-plugin.db/custom-viz-plugin id))dev-url (cache/resolve-dev-bundle id)entry (cache/resolve-bundle plugin)](if entry@@ -321,7 +321,7 @@respondraise](try- (let [plugin (api/read-check (custom-viz-plugin.db/non-blob-plugin id))+ (let [plugin (api/read-check (custom-viz-plugin.db/custom-viz-plugin id))content-type (or (manifest/asset-content-type path)(throw (ex-info "Unsupported asset type" {:status-code 404})))dev? (cache/resolve-dev-bundle id)@@ -349,7 +349,7 @@[{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params{:keys [dev_bundle_url]} :- [:map {:closed true} [:dev_bundle_url [:maybe :string]]]]- (api/write-check (custom-viz-plugin.db/non-blob-plugin id))+ (api/write-check (custom-viz-plugin.db/custom-viz-plugin id))(check-dev-mode-enabled!)(cache/set-or-clear-dev-bundle! id dev_bundle_url){:dev_bundle_url (cache/resolve-dev-bundle id)})@@ -397,7 +397,7 @@plugins this is a no-op — to update an upload-backed plugin, PUT a new bundleto `/:id/bundle`."[{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]]- (let [plugin (api/write-check (custom-viz-plugin.db/non-blob-plugin id))]+ (let [plugin (api/write-check (custom-viz-plugin.db/custom-viz-plugin id))](api/check-400 (dev-only-plugin? plugin)"Refresh is only supported for dev-only plugins; upload a new bundle to update an upload-backed plugin.")(let [dev-url (or (cache/resolve-dev-bundle id)@@ -410,7 +410,7 @@:icon (:icon manifest):manifest manifest:metabase_version version-str})- (let [result (custom-viz-plugin.db/non-blob-plugin id)]+ (let [result (custom-viz-plugin.db/custom-viz-plugin id)](events/publish-event! :event/custom-viz-plugin-update {:object result:previous-object plugin:user-id api/*current-user-id*})diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/cache.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/cache.cljindex 7967de46de9..ba72bb1a5e7 100644--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/cache.clj+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/cache.clj@@ -253,7 +253,7 @@[{:keys [id]} validated](custom-viz-plugin.db/update-plugin! id (derived-columns validated))(purge-plugin-cache! {:id id})- (custom-viz-plugin.db/non-blob-plugin id))+ (custom-viz-plugin.db/custom-viz-plugin id))(defn insert-bundle!"Insert a new plugin row from a validated bundle and an `:identifier`. Returns@@ -437,7 +437,7 @@Always returns nil when dev mode is disabled."[id](when (custom-viz.settings/custom-viz-plugin-dev-mode-enabled)- (not-empty (custom-viz-plugin.db/plugin-dev-bundle-url id))))+ (not-empty (:dev_bundle_url (custom-viz-plugin.db/custom-viz-plugin id)))));;; ------------------------------------------------ Resolve ------------------------------------------------diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.cljindex 2c149b59f8c..86f6e1c15ac 100644--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.clj+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.clj@@ -7,26 +7,44 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(def ^:private non-blob-columns- "Columns to select for normal plugin reads, excluding the bundle blob."- [:model/CustomVizPlugin :id :identifier :display_name :icon :status :error_message :enabled- :manifest :metabase_version :bundle_hash :dev_bundle_url- :created_at :updated_at])+(def non-blob-columns+ "Every CustomVizPlugin column except the raw bundle blob."+ [:id :identifier :display_name :icon :status :error_message :enabled :manifest :metabase_version :bundle_hash+ :dev_bundle_url :created_at :updated_at])-(mu/defn non-blob-plugin- "The CustomVizPlugin with `plugin-id` without its bundle, or nil."+(def ^:private non-blob-model+ (into [:model/CustomVizPlugin] non-blob-columns))++(mu/defn custom-viz-plugin :- [:maybe ::custom-viz-plugin.schema/custom-viz-plugin]+ "The ::custom-viz-plugin.schema/custom-viz-plugin with `custom-viz-plugin-id`, or nil."+ [custom-viz-plugin-id :- ms/PositiveInt]+ (t2/select-one :model/CustomVizPlugin :id [:auto/param custom-viz-plugin-id]))++(mu/defn plugin-bundle+ "The bundle bytes of the CustomVizPlugin with `plugin-id`."[plugin-id :- ms/PositiveInt]- (t2/select-one non-blob-columns :id plugin-id))+ (t2/select-one-fn :bundle [:model/CustomVizPlugin :bundle] :id [:auto/param plugin-id]))++(mu/defn reducible-plugins-with-bundles+ "A reducible of the CustomVizPlugin rows, bundles included, whose `filter-column` is one of `filter-ids` (every row+ when `filter-column` is nil), ordered ascending by `order-columns`."+ [filter-column :- [:maybe :keyword]+ filter-ids :- [:maybe [:sequential [:maybe [:or :int :string]]]]+ order-columns :- [:maybe [:sequential :keyword]]]+ (t2/reducible-select [:model/CustomVizPlugin :*]+ (cond-> {}+ filter-column (assoc :where [:in filter-column filter-ids])+ (seq order-columns) (assoc :order-by (mapv (fn [column] [column :asc]) order-columns)))))(mu/defn non-blob-plugins"Every CustomVizPlugin without its bundle, ordered by display name."[]- (t2/select non-blob-columns {:order-by [[:display_name :asc]]}))+ (t2/select non-blob-model {:order-by [[:display_name :asc]]}))(mu/defn active-enabled-non-blob-plugins"The active, enabled CustomVizPlugins without their bundle, ordered by display name."[]- (t2/select non-blob-columns :status :active :enabled true {:order-by [[:display_name :asc]]}))+ (t2/select non-blob-model :status :active :enabled true {:order-by [[:display_name :asc]]}))(mu/defn plugin-by-identifier"The CustomVizPlugin with `identifier`, or nil."@@ -38,16 +56,6 @@[identifier :- :string](t2/exists? :model/CustomVizPlugin :identifier identifier))-(mu/defn plugin-bundle- "The bundle bytes of the CustomVizPlugin with `plugin-id`."- [plugin-id :- ms/PositiveInt]- (t2/select-one-fn :bundle :model/CustomVizPlugin :id plugin-id))--(mu/defn plugin-dev-bundle-url- "The dev bundle URL of the CustomVizPlugin with `plugin-id`."- [plugin-id :- ms/PositiveInt]- (t2/select-one-fn :dev_bundle_url :model/CustomVizPlugin :id plugin-id))-(mu/defn insert-plugin!"Insert `plugin` and return the new instance."[plugin :- ::custom-viz-plugin.schema/custom-viz-plugin.update]diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin.cljindex ff2993f661c..c6c2eb5b6cf 100644--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin.clj+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin.clj@@ -8,7 +8,8 @@[metabase.models.interface :as mi][metabase.models.serialization :as serdes][methodical.core :as methodical]- [toucan2.core :as t2])+ [toucan2.core :as t2]+ [toucan2.tools.default-fields :as t2.default-fields])(:import(java.sql Blob)))@@ -36,11 +37,8 @@(derive :metabase/model)(derive :hook/timestamped?))-(def non-blob-columns- "Columns to select for normal plugin metadata reads, excluding the raw bundle blob."- [:id :identifier :display_name :icon :status :error_message :enabled- :manifest :metabase_version :bundle_hash :dev_bundle_url- :created_at :updated_at])+(t2.default-fields/define-default-fields :model/CustomVizPlugin+ custom-viz-plugin.db/non-blob-columns)(defmethod mi/can-read? :model/CustomVizPlugin([_instance] (some? api/*current-user-id*))@@ -91,6 +89,11 @@{:status :error:error_message (ex-message e)})))+(defmethod serdes/extract-query "CustomVizPlugin"+ [model-name {:keys [filter-column filter-ids] :as opts}]+ (custom-viz-plugin.db/reducible-plugins-with-bundles filter-column filter-ids+ (serdes/extract-order-columns model-name opts)))+(defmethod serdes/load-insert! "CustomVizPlugin"[_model-name ingested](custom-viz-plugin.db/insert-plugin! (merge ingested (bundle-columns ingested))))@@ -99,7 +102,7 @@[_model-name ingested {:keys [id]}](custom-viz-plugin.db/update-plugin! id (merge ingested (bundle-columns ingested)))(cache/purge-plugin-cache! {:id id})- (custom-viz-plugin.db/non-blob-plugin id))+ (custom-viz-plugin.db/custom-viz-plugin id))(defmethod serdes/entity-id "CustomVizPlugin" [_ {:keys [identifier]}]identifier)diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/db.clj b/enterprise/backend/src/metabase_enterprise/data_apps/db.cljindex 4a66546d67d..f55f7f9fa55 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/db.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/db.clj@@ -19,10 +19,10 @@(def ^:private non-blob-model(into [:model/DataApp] non-blob-columns))-(mu/defn data-app- "The DataApp with `data-app-id` without its bundle, or nil."+(mu/defn data-app :- [:maybe ::data-apps.schema/data-app]+ "The ::data-apps.schema/data-app with `data-app-id`, or nil."[data-app-id :- ms/PositiveInt]- (t2/select-one non-blob-model :id data-app-id))+ (t2/select-one :model/DataApp :id [:auto/param data-app-id]))(mu/defn data-app-by-slug"The DataApp named `slug` without its bundle, or nil."@@ -87,11 +87,6 @@[](t2/select-fn-set :resource_collection_id :model/DataApp :resource_collection_id [:not= nil]))-(mu/defn resource-collection-id- "The ID of the resource collection owned by the DataApp with `data-app-id`."- [data-app-id :- ms/PositiveInt]- (t2/select-one-fn :resource_collection_id :model/DataApp :id data-app-id))-(defn collection-card-ids"The IDs of the cards in the collection with `collection-id`."[collection-id]@@ -102,11 +97,6 @@[collection-id](t2/select-pks-vec :model/Action :collection_id collection-id))-(defn resource-collection- "The resource collection with `collection-id`, or nil."- [collection-id]- (t2/select-one :model/Collection :id collection-id))-(defn delete-resource-collection!"Delete the resource collection with `collection-id`."[collection-id]diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/group_access.clj b/enterprise/backend/src/metabase_enterprise/data_apps/group_access.cljindex c891d0d9490..73b49a83691 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/group_access.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/group_access.clj@@ -3,6 +3,7 @@[metabase-enterprise.data-apps.db :as data-apps.db][metabase-enterprise.dependencies.models.dependency :as models.dependency][metabase.api.common :as api]+ [metabase.collections.db :as collections.db][metabase.graph.core :as graph][metabase.permissions.core :as perms][metabase.settings.core :as setting]@@ -35,7 +36,7 @@(defn- app-collection"The resource collection of `app`, or a 404."[app]- (api/check-404 (some-> (:resource_collection_id app) data-apps.db/resource-collection)))+ (api/check-404 (some-> (:resource_collection_id app) collections.db/collection)))(defn add-groups!"Grant groups read access to the resource collection of `app`."diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/models/data_app.clj b/enterprise/backend/src/metabase_enterprise/data_apps/models/data_app.cljindex d51e0723eec..85f767ad666 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/models/data_app.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/models/data_app.clj@@ -3,6 +3,7 @@[metabase-enterprise.data-apps.config :as data-app.config][metabase-enterprise.data-apps.db :as data-apps.db][metabase.api.common :as api]+ [metabase.collections.db :as collections.db][metabase.data-apps.schema :as data-apps.schema][metabase.events.core :as events][metabase.lib.core :as lib]@@ -77,7 +78,7 @@new app: a top-level collection of data apps, not archived, official, typed or the sample, that no other app has;remote sync may sync it."[collection-id app-id]- (let [collection (data-apps.db/resource-collection collection-id)]+ (let [collection (some-> collection-id collections.db/collection)](when-not (and collection(= "data-apps" (some-> (:namespace collection) name))(= "/" (:location collection))@@ -213,7 +214,7 @@(defmethod serdes/descendants "DataApp" [_model-name id _opts];; An app's resource collection, and through it the copies it holds, travel with the app.- (when-let [collection-id (data-apps.db/resource-collection-id id)]+ (when-let [collection-id (:resource_collection_id (data-apps.db/data-app id))]{["Collection" collection-id] {"DataApp" id}}))(defmethod serdes/storage-path "DataApp" [app _ctx]diff --git a/enterprise/backend/src/metabase_enterprise/data_complexity_score/complexity.clj b/enterprise/backend/src/metabase_enterprise/data_complexity_score/complexity.cljindex a707de73f0c..be59d8e845e 100644--- a/enterprise/backend/src/metabase_enterprise/data_complexity_score/complexity.clj+++ b/enterprise/backend/src/metabase_enterprise/data_complexity_score/complexity.clj@@ -12,6 +12,7 @@[metabase.audit-app.core :as audit][metabase.collections.core :as collections][metabase.collections.curation :as curation]+ [metabase.collections.db :as collections.db][metabase.util :as u][metabase.util.log :as log]))@@ -173,7 +174,7 @@[collection-id](when collection-id(into #{collection-id}- (when-let [root (data-complexity-score.db/collection collection-id)]+ (when-let [root (collections.db/collection collection-id)](collections/descendant-ids root)))))(defn- verified-card-id-setdiff --git a/enterprise/backend/src/metabase_enterprise/data_complexity_score/db.clj b/enterprise/backend/src/metabase_enterprise/data_complexity_score/db.cljindex c5eae3c0024..c84470429f2 100644--- a/enterprise/backend/src/metabase_enterprise/data_complexity_score/db.clj+++ b/enterprise/backend/src/metabase_enterprise/data_complexity_score/db.clj@@ -28,11 +28,6 @@[table-ids :- [:sequential ::lib.schema.id/table]](t2/select [:model/Measure :table_id :name] :archived false :table_id [:in table-ids]))-(mu/defn collection- "The Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one :model/Collection :id collection-id))-(mu/defn verified-card-ids"The IDs of the Cards whose most recent moderation review is verified."[]@@ -78,10 +73,10 @@source :- :string](t2/select-one :model/DataComplexityScore :fingerprint fingerprint :source source {:order-by [[:id :desc]]}))-(mu/defn score-entry- "The DataComplexityScore with `id`, or nil."+(mu/defn data-complexity-score :- [:maybe ::data-complexity-score.schema/data-complexity-score]+ "The ::data-complexity-score.schema/data-complexity-score with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/DataComplexityScore :id id))+ (t2/select-one :model/DataComplexityScore :id [:auto/param id]))(mu/defn scored-within-hours?"Whether a DataComplexityScore of `source` for `fingerprint` was created within the last `hours` hours ofdiff --git a/enterprise/backend/src/metabase_enterprise/data_complexity_score/models/data_complexity_score.clj b/enterprise/backend/src/metabase_enterprise/data_complexity_score/models/data_complexity_score.cljindex 620bc5da350..e389d79e527 100644--- a/enterprise/backend/src/metabase_enterprise/data_complexity_score/models/data_complexity_score.clj+++ b/enterprise/backend/src/metabase_enterprise/data_complexity_score/models/data_complexity_score.clj@@ -58,5 +58,5 @@:source source:score_data score})](if id- (score-with-calculated-at (data-complexity-score.db/score-entry id))+ (score-with-calculated-at (data-complexity-score.db/data-complexity-score id))(latest-score fingerprint source))))diff --git a/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj b/enterprise/backend/src/metabase_enterprise/data_studio/api/table.cljindex ebef4c0ec07..4aaf8cfae28 100644--- a/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj+++ b/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj@@ -7,9 +7,11 @@[metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]][metabase.collections.core :as collection]+ [metabase.collections.db :as collections.db][metabase.events.core :as events][metabase.models.interface :as mi][metabase.premium-features.core :refer [defenterprise]]+ [metabase.users.db :as users.db][metabase.util.i18n :refer [tru]][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]))@@ -137,7 +139,7 @@(when (= topic :table-publish){:published_at timestamp:published_by (when user-id- (some-> (data-studio.db/user-name-and-email user-id)+ (some-> (users.db/user user-id)(select-keys [:id :common_name])))})))(api.macros/defendpoint :get "/:id/publishing-info" :- [:maybe PublishingInfo]@@ -170,7 +172,7 @@_query-paramsbody :- ::publish-table-selectors](api/check-data-studio-access)- (let [target-collection (api/check-404 (data-studio.db/collection (:collection_id body)))+ (let [target-collection (api/check-404 (collections.db/collection (:collection_id body)))_ (api/check-400 (= (:type target-collection) collection/library-data-collection-type)(tru "Tables can only be published to Semantic layer/Data collections."))_ (api/write-check target-collection)@@ -201,7 +203,7 @@table-ids-to-update (data-studio.db/table-ids-matching-selectors selectors downstream-ids :any)](api/check-403 (can-publish-all-tables? table-ids-to-update))(when (seq table-ids-to-update)- (run! (comp api/write-check data-studio.db/collection)+ (run! (comp api/write-check collections.db/collection)(into #{} (keep :collection_id) (data-studio.db/tables table-ids-to-update)))(data-studio.db/unpublish-tables! table-ids-to-update);; Publish events for audit log and remote sync trackingdiff --git a/enterprise/backend/src/metabase_enterprise/data_studio/db.clj b/enterprise/backend/src/metabase_enterprise/data_studio/db.cljindex 93d7f9829ab..4f2426664cd 100644--- a/enterprise/backend/src/metabase_enterprise/data_studio/db.clj+++ b/enterprise/backend/src/metabase_enterprise/data_studio/db.clj@@ -86,11 +86,6 @@[table-ids :- [:set ::lib.schema.id/table]](t2/select :model/Table :id [:in table-ids] {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn collection- "The Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one :model/Collection collection-id))-(mu/defn latest-table-publishing-event"The most recent publish or unpublish AuditLog event for `table-id`, or nil."[table-id :- ::lib.schema.id/table]@@ -100,11 +95,6 @@:model_id table-id{:order-by [[:timestamp :desc] [:id :desc]]}))-(mu/defn user-name-and-email- "The id, first name, last name, and email of the User with `user-id`, or nil."- [user-id :- ::lib.schema.id/user]- (t2/select-one [:model/User :id :first_name :last_name :email] user-id))-(mu/defn publish-tables!"Publish the Tables with `table-ids` into the Collection with `collection-id`, returning the number updated."[table-ids :- [:set ::lib.schema.id/table]diff --git a/enterprise/backend/src/metabase_enterprise/database_replication/api.clj b/enterprise/backend/src/metabase_enterprise/database_replication/api.cljindex e6c8c78968a..3aee9cebb13 100644--- a/enterprise/backend/src/metabase_enterprise/database_replication/api.clj+++ b/enterprise/backend/src/metabase_enterprise/database_replication/api.clj@@ -3,7 +3,6 @@[clojure.core.memoize :as memoize][clojure.set :as set][medley.core :as m]- [metabase-enterprise.database-replication.db :as database-replication.db][metabase-enterprise.database-replication.settings :as database-replication.settings][metabase-enterprise.harbormaster.client :as hm.client][metabase.api.common :as api]@@ -13,7 +12,8 @@[metabase.premium-features.core :as premium-features][metabase.util :as u][metabase.util.log :as log]- [metabase.util.malli.schema :as ms])+ [metabase.util.malli.schema :as ms]+ [metabase.warehouses.db :as warehouses.db])(:import(java.util.regex PatternSyntaxException)))@@ -147,7 +147,7 @@(api.macros/defendpoint :post "/connection/:database-id/preview""Return info about pg-replication connection that is about to be created."[{:keys [database-id]} :- [:map {:closed true} [:database-id ms/PositiveInt]] _ {:keys [replicationSchemaFilters]} :- body-schema]- (let [database (database-replication.db/database database-id)+ (let [database (warehouses.db/database database-id)secret (->secret database)replication-schema-filters (m->schema-filter replicationSchemaFilters)](u/recursive-map-keys u/->camelCaseEn (preview-replication (premium-features/quotas) (preview-tables secret replication-schema-filters)))))@@ -160,7 +160,7 @@"Create a new PG replication connection for the specified database."[{:keys [database-id]} :- [:map {:closed true} [:database-id ms/PositiveInt]] _ {:keys [replicationSchemaFilters]} :- body-schema](api/check-400 (database-replication.settings/database-replication-enabled) "PG replication integration is not enabled.")- (let [database (database-replication.db/database database-id)+ (let [database (warehouses.db/database database-id)db-details (:details database)](api/check-404 database)(api/check-400 (= :postgres (:engine database)) "PG replication is only supported for PostgreSQL databases.")diff --git a/enterprise/backend/src/metabase_enterprise/database_replication/db.clj b/enterprise/backend/src/metabase_enterprise/database_replication/db.cljdeleted file mode 100644index c01168868d7..00000000000--- a/enterprise/backend/src/metabase_enterprise/database_replication/db.clj+++ /dev/null@@ -1,12 +0,0 @@-(ns metabase-enterprise.database-replication.db- "Application database queries for the database-replication module. Every function here is a direct Toucan 2 call with no- additional logic, so the rest of the module never talks to `toucan2.core` itself."- (:require- [metabase.lib.schema.id :as lib.schema.id]- [metabase.util.malli :as mu]- [toucan2.core :as t2]))--(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))diff --git a/enterprise/backend/src/metabase_enterprise/database_routing/api.clj b/enterprise/backend/src/metabase_enterprise/database_routing/api.cljindex 1ed6d05b2a3..4bb3b575d80 100644--- a/enterprise/backend/src/metabase_enterprise/database_routing/api.clj+++ b/enterprise/backend/src/metabase_enterprise/database_routing/api.clj@@ -10,7 +10,8 @@[metabase.settings.core :as setting][metabase.util :as u][metabase.util.malli.schema :as ms]- [metabase.warehouses.core :as warehouses]))+ [metabase.warehouses.core :as warehouses]+ [metabase.warehouses.db :as warehouses.db]));; TODO (Cam 10/28/25) -- fix this endpoint so it uses kebab-case for query parameters for consistency with the rest;; of the REST API@@ -39,7 +40,7 @@(api/check-400 (database-routing.db/router-exists? router_database_id))(api/check-400 (not (database-routing.db/destination-name-exists? router_database_id (map :name destinations)))"A destination database with that name already exists.")- (let [{:keys [engine auto_run_queries is_on_demand] :as router-db} (database-routing.db/database router_database_id)]+ (let [{:keys [engine auto_run_queries is_on_demand] :as router-db} (warehouses.db/database router_database_id)](if-let [invalid-destinations (->> destinations(keep (fn [{details :details n :name}](try@@ -74,7 +75,7 @@(defn- delete-router![db-id]- (let [db (database-routing.db/database db-id)]+ (let [db (warehouses.db/database db-id)](events/publish-event! :event/database-update {:object db:previous-object db:user-id api/*current-user-id*@@ -83,7 +84,7 @@(defn- create-or-update-router![db-id user-attribute]- (let [db (database-routing.db/database db-id)]+ (let [db (warehouses.db/database db-id)](when-not (driver.u/supports? (:engine db) :database-routing db)(throw (ex-info "This database does not support DB routing" {:status-code 400})))(events/publish-event! :event/database-update {:object db@@ -108,7 +109,7 @@[{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params{:keys [user_attribute]} :- [:map {:closed true} [:user_attribute {:optional true} [:maybe ms/NonBlankString]]]]- (let [db (database-routing.db/database id)]+ (let [db (warehouses.db/database id)](api/check-404 db)(api/check-400 (not (:router_database_id db)) "Cannot make a destination database a router database")(api/check-400 (not (:uploads_enabled db)) "Cannot enable database routing for a database with uploads enabled")diff --git a/enterprise/backend/src/metabase_enterprise/database_routing/db.clj b/enterprise/backend/src/metabase_enterprise/database_routing/db.cljindex c984737f513..c65811aab82 100644--- a/enterprise/backend/src/metabase_enterprise/database_routing/db.clj+++ b/enterprise/backend/src/metabase_enterprise/database_routing/db.clj@@ -7,11 +7,6 @@[metabase.warehouses.schema :as warehouses.schema][toucan2.core :as t2]))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))-(mu/defn destination-database-id"The ID of the destination Database of the router with `router-database-id` named `database-name`, or nil."[router-database-id :- ::lib.schema.id/databasediff --git a/enterprise/backend/src/metabase_enterprise/dependencies/db.clj b/enterprise/backend/src/metabase_enterprise/dependencies/db.cljindex 767f0c2597b..23b0eecc53d 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/db.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/db.clj@@ -679,11 +679,6 @@collection-ids :- [:sequential ::lib.schema.id/collection]](t2/select [model :id :collection_id] :collection_id [:in collection-ids]))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(mu/defn card-types-by-id"A map of Card ID to type for `card-ids`."[card-ids :- [:sequential ::lib.schema.id/card]]@@ -694,16 +689,6 @@[table-ids :- [:set ::lib.schema.id/table]](t2/select :model/Table :id [:in table-ids] {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn dashcard-dashboard-id :- [:maybe ::lib.schema.id/dashboard]- "The `:dashboard_id` of the DashboardCard with `dashcard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard]- (t2/select-one-fn :dashboard_id :model/DashboardCard :id dashcard-id))--(mu/defn field-table-id :- [:maybe ::lib.schema.id/table]- "The `:table_id` of the Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one-fn :table_id :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))-(mu/defn source-database-transform-ids :- [:set ::lib.schema.id/transform]"The IDs of the Transforms reading from the Database with `db-id`."[db-id :- ::lib.schema.id/database]diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/hooks.clj b/enterprise/backend/src/metabase_enterprise/dependencies/hooks.cljindex db82d3d3229..fc3a2f697a9 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/hooks.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/hooks.clj@@ -11,10 +11,12 @@[metabase-enterprise.dependencies.task.result-metadata :as task.result-metadata][metabase.app-db.core :as mdb][metabase.batch-processing.core :as grouper]+ [metabase.dashboards.db :as dashboards.db][metabase.premium-features.core :refer [defenterprise]][metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -118,10 +120,11 @@(case model(:model/DashboardCard :model/DashboardTab) [:dashboard (:dashboard_id row)]:model/DashboardCardSeries [:dashboard (some-> (:dashboardcard_id row)- dependencies.db/dashcard-dashboard-id)]+ dashboards.db/dashboard-card+ :dashboard_id)](:model/QueryAction :model/ImplicitAction) [:action (:action_id row)](:model/Field :model/TableUserSettings) [:table (:table_id row)]- :model/FieldUserSettings [:table (some-> (:field_id row) dependencies.db/field-table-id)]+ :model/FieldUserSettings [:table (some-> (:field_id row) warehouse-schema.db/field :table_id)]nil))(def ^:private part-columns@@ -169,7 +172,7 @@(mu/defn- mark-dimension!"Mark what reads the remap of the Dimension `row`, whose Field's Table's entities show it."[row :- [:maybe Row]]- (when-let [table-id (some-> (:field_id row) dependencies.db/field-table-id)]+ (when-let [table-id (some-> (:field_id row) warehouse-schema.db/field :table_id)](mark-remapped-tables! #{table-id})))(mu/defn- mark-field-values! :- :booleandiff --git a/enterprise/backend/src/metabase_enterprise/dependencies/result_metadata.clj b/enterprise/backend/src/metabase_enterprise/dependencies/result_metadata.cljindex d6a2c2690ad..45087146191 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/result_metadata.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/result_metadata.clj@@ -14,6 +14,7 @@[metabase.lib.schema.id :as lib.schema.id][metabase.lib.schema.metadata :as lib.schema.metadata][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.types.core :as types][metabase.util :as u][metabase.util.log :as log]@@ -128,7 +129,7 @@"Re-derive the result metadata of the MBQL Card with `card-id` and store it when it changed."[card-id :- ::lib.schema.id/card](let [state (dependencies.db/card-state card-id false)- card (dependencies.db/card card-id)+ card (queries.db/card card-id)metadata (lib-be/with-metadata-provider-cache(when (and card (not= :native (:query_type card)) (seq (:dataset_query card)))(rederived-result-metadata card)))]diff --git a/enterprise/backend/src/metabase_enterprise/impersonation/api.clj b/enterprise/backend/src/metabase_enterprise/impersonation/api.cljindex ab5b3e493f9..c7c81483779 100644--- a/enterprise/backend/src/metabase_enterprise/impersonation/api.clj+++ b/enterprise/backend/src/metabase_enterprise/impersonation/api.clj@@ -34,6 +34,6 @@[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-superuser)- (api/check-404 (impersonation.db/impersonation id))+ (api/check-404 (impersonation.db/connection-impersonation id))(impersonation.db/delete-impersonation! id)api/generic-204-no-content)diff --git a/enterprise/backend/src/metabase_enterprise/impersonation/db.clj b/enterprise/backend/src/metabase_enterprise/impersonation/db.cljindex 4dbd0765ddb..a409dcd0422 100644--- a/enterprise/backend/src/metabase_enterprise/impersonation/db.clj+++ b/enterprise/backend/src/metabase_enterprise/impersonation/db.clj@@ -9,10 +9,10 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(mu/defn impersonation- "The ConnectionImpersonation with `impersonation-id`, or nil."+(mu/defn connection-impersonation :- [:maybe ::impersonation.schema/connection-impersonation]+ "The ::impersonation.schema/connection-impersonation with `impersonation-id`, or nil."[impersonation-id :- ms/PositiveInt]- (t2/select-one :model/ConnectionImpersonation :id impersonation-id))+ (t2/select-one :model/ConnectionImpersonation :id [:auto/param impersonation-id]))(mu/defn impersonation-for-group-and-database"The ConnectionImpersonation of the group with `group-id` on the Database with `database-id`, or nil."diff --git a/enterprise/backend/src/metabase_enterprise/library/db.clj b/enterprise/backend/src/metabase_enterprise/library/db.cljindex 9697de137e4..b03791f2951 100644--- a/enterprise/backend/src/metabase_enterprise/library/db.clj+++ b/enterprise/backend/src/metabase_enterprise/library/db.clj@@ -37,11 +37,6 @@:archive-operation-id nil})]:order-by [[:%lower.name :asc]]}))-(mu/defn collection-type- "The type of the Collection with `collection-id`."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one-fn :type [:model/Collection :type] :id collection-id))-(mu/defn unarchived-card-collection-types-reducible"Reducible distinct Collection ID and Card type pairs of the unarchived Cards."[]diff --git a/enterprise/backend/src/metabase_enterprise/library/validation.clj b/enterprise/backend/src/metabase_enterprise/library/validation.cljindex 18d0b1e3a76..886108dbd55 100644--- a/enterprise/backend/src/metabase_enterprise/library/validation.clj+++ b/enterprise/backend/src/metabase_enterprise/library/validation.clj@@ -1,7 +1,7 @@(ns metabase-enterprise.library.validation(:require[clojure.set :as set]- [metabase-enterprise.library.db :as library.db]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.premium-features.core :refer [defenterprise]][toucan2.core :as t2]))@@ -36,7 +36,7 @@:feature :library[content-type collection-id](when collection-id- (let [collection-type (library.db/collection-type collection-id)]+ (let [collection-type (:type (collections.db/collection collection-id))](when-let [{:keys [allowed-content-types error-message]} (some-> collection-typelibrary-collection-content-specs)](when-not (allowed-content-types content-type)@@ -58,6 +58,6 @@(when (and (collection/is-library-collection? (:id collection))(contains? change-keys :location)(when-let [parent-id (collection/location-path->parent-id (:location collection))]- (not= (:type collection) (library.db/collection-type parent-id))))+ (not= (:type collection) (:type (collections.db/collection parent-id)))))(throw (ex-info "Cannot move a semantic layer collection outside the semantic layer" {}))))true)diff --git a/enterprise/backend/src/metabase_enterprise/mcp/db.clj b/enterprise/backend/src/metabase_enterprise/mcp/db.cljindex 42bddcbe804..96dd8785c6c 100644--- a/enterprise/backend/src/metabase_enterprise/mcp/db.clj+++ b/enterprise/backend/src/metabase_enterprise/mcp/db.clj@@ -19,11 +19,6 @@[session-id :- :string](t2/exists? :model/McpSessionLog :id session-id))-(mu/defn session-client-identity- "The client name and version of the McpSessionLog with `session-id`, or nil."- [session-id :- :string]- (t2/select-one [:model/McpSessionLog :client_name :client_version] :id session-id))-(mu/defn insert-session-log!"Insert the McpSessionLog `row`."[row :- [:map {:closed true}diff --git a/enterprise/backend/src/metabase_enterprise/mcp/usage.clj b/enterprise/backend/src/metabase_enterprise/mcp/usage.cljindex d466cf565b5..f37e4523c99 100644--- a/enterprise/backend/src/metabase_enterprise/mcp/usage.clj+++ b/enterprise/backend/src/metabase_enterprise/mcp/usage.clj@@ -8,9 +8,10 @@best-effort: a failure is logged and swallowed so logging never fails the MCP request andadds negligible latency."(:require- [metabase-enterprise.mcp.db :as mcp.db]+ [metabase-enterprise.mcp.db :as ee.mcp.db][metabase.analytics.core :as analytics][metabase.analytics.settings :as analytics.settings]+ [metabase.mcp.db :as mcp.db][metabase.mcp.usage :as mcp.usage][metabase.premium-features.core :refer [defenterprise]][metabase.util.log :as log]))@@ -52,7 +53,7 @@(when (and session-id;; mcp-remote fires a throwaway transport-probe handshake; never record it(not (mcp.usage/proxy-probe? (:name client-info)))- (not (mcp.db/session-log-exists? session-id)))+ (not (ee.mcp.db/session-log-exists? session-id)))(let [;; `pii-fields-from` returns the gated PII columns only when;; `analytics-pii-retention-enabled` is on (nil otherwise). Allowlist the two columns;; `mcp_session_log` actually has — selecting explicitly (rather than dissoc-ing the@@ -61,7 +62,7 @@pii (select-keys (analytics/pii-fields-from {:user-agent user-agent:ip-address ip-address})[:user_agent :ip_address])]- (mcp.db/insert-session-log!+ (ee.mcp.db/insert-session-log!(merge {:id session-id:user_id user-id:tenant_id tenant-id@@ -78,7 +79,7 @@[session-id](try(when session-id- (mcp.db/end-session-log! session-id))+ (ee.mcp.db/end-session-log! session-id))(catch Throwable e(log/warnf "Failed to record MCP session end: %s" (ex-message e)))))@@ -96,7 +97,8 @@:client_version (truncate (:version client-info) client-version-max-length)}session-id- (mcp.db/session-client-identity session-id)+ (some-> (mcp.db/mcp-session-log session-id)+ (select-keys [:client_name :client_version])):else nil))@@ -118,7 +120,7 @@pii (select-keys (analytics/pii-fields-from {:user-agent user-agent:ip-address ip-address})[:user_agent :ip_address :sanitized_user_agent])]- (mcp.db/insert-tool-call-log!+ (ee.mcp.db/insert-tool-call-log!(merge {:tool_name (or (not-empty (truncate tool-name tool-name-max-length))unknown-tool-name):user_id user-iddiff --git a/enterprise/backend/src/metabase_enterprise/metabot_analytics/conversations.clj b/enterprise/backend/src/metabase_enterprise/metabot_analytics/conversations.cljindex db12962ae89..4cdf4e03b42 100644--- a/enterprise/backend/src/metabase_enterprise/metabot_analytics/conversations.clj+++ b/enterprise/backend/src/metabase_enterprise/metabot_analytics/conversations.clj@@ -9,6 +9,7 @@[metabase-enterprise.metabot-analytics.db :as metabot-analytics.db][metabase-enterprise.metabot-analytics.queries :as analytics.queries][metabase.api.common :as api]+ [metabase.metabot.db :as metabot.db][metabase.metabot.persistence :as metabot-persistence][metabase.metabot.tools :as metabot.tools][metabase.slackbot.api :as slackbot.api]@@ -120,7 +121,7 @@(defn fetch-conversation-detail"Fetch a conversation detail or throw a 404."[conversation-id]- (let [conversation (metabot-analytics.db/conversation conversation-id)]+ (let [conversation (metabot.db/metabot-conversation conversation-id)](api/check-404 conversation)(let [all-messages (metabot-analytics.db/messages-for-conversation conversation-id)forked-from (:forked_from_conversation_id conversation)diff --git a/enterprise/backend/src/metabase_enterprise/metabot_analytics/db.clj b/enterprise/backend/src/metabase_enterprise/metabot_analytics/db.cljindex 8f126d255da..1df92d3b741 100644--- a/enterprise/backend/src/metabase_enterprise/metabot_analytics/db.clj+++ b/enterprise/backend/src/metabase_enterprise/metabot_analytics/db.clj@@ -11,11 +11,6 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(mu/defn conversation- "The MetabotConversation with `conversation-id`, or nil."- [conversation-id :- :string]- (t2/select-one :model/MetabotConversation :id conversation-id))-(defn- date-range-expr"A half-open predicate on `col` from the serialized date-param string `date-string`. Throws 400 on a malformedstring. Returns nil when no bound is produced."diff --git a/enterprise/backend/src/metabase_enterprise/mfa/core.clj b/enterprise/backend/src/metabase_enterprise/mfa/core.cljindex a6d82efc4e6..a11bcefb830 100644--- a/enterprise/backend/src/metabase_enterprise/mfa/core.clj+++ b/enterprise/backend/src/metabase_enterprise/mfa/core.clj@@ -4,7 +4,6 @@Consumers outside this module must go through this namespace; they must not require mfa.gate,or mfa.settings directly."(:require- [metabase-enterprise.mfa.db :as mfa.db][metabase-enterprise.mfa.enrollment :as enrollment][metabase-enterprise.mfa.gate :as gate][metabase-enterprise.mfa.settings]@@ -12,6 +11,7 @@[metabase.channel.email.messages :as messages][metabase.mfa.settings][metabase.premium-features.core :refer [defenterprise]]+ [metabase.users.db :as users.db][metabase.util.i18n :refer [tru]][metabase.util.log :as log][potemkin :as p]))@@ -94,7 +94,7 @@;; nil = no confirmed enrollment — same message, no oracle semantics(throw (ex-info (tru "Authentication session expired. Please log in again."){:status-code 401})))- user-email (mfa.db/user-email user-id)]+ user-email (:email (users.db/user user-id))](try(messages/send-mfa-login-code-email! user-email code)(catch Throwable ediff --git a/enterprise/backend/src/metabase_enterprise/mfa/db.clj b/enterprise/backend/src/metabase_enterprise/mfa/db.cljindex 8e9981cb6d7..6662c86bfed 100644--- a/enterprise/backend/src/metabase_enterprise/mfa/db.clj+++ b/enterprise/backend/src/metabase_enterprise/mfa/db.clj@@ -58,16 +58,6 @@[:like :%lower.last_name pattern][:like :%lower.email pattern]]))))-(mu/defn user- "The User with `user-id`, or nil."- [user-id :- ::lib.schema.id/user]- (t2/select-one :model/User :id user-id))--(mu/defn user-email- "The email of the User with `user-id`."- [user-id :- ::lib.schema.id/user]- (t2/select-one-fn :email :model/User :id user-id))-(mu/defn lock-user"The `:id` row of the User with `user-id`, locked for update."[user-id :- ::lib.schema.id/user]diff --git a/enterprise/backend/src/metabase_enterprise/mfa/management.clj b/enterprise/backend/src/metabase_enterprise/mfa/management.cljindex 2b31b4cc7bb..a20323a2b97 100644--- a/enterprise/backend/src/metabase_enterprise/mfa/management.clj+++ b/enterprise/backend/src/metabase_enterprise/mfa/management.clj@@ -23,6 +23,7 @@[metabase.premium-features.core :as premium-features][metabase.request.core :as request][metabase.sso.core :as sso]+ [metabase.users.db :as users.db][metabase.util.encryption :as encryption][metabase.util.i18n :refer [tru]][metabase.util.log :as log]@@ -71,7 +72,7 @@;; an unreachable directory fails closed: re-auth is denied (the user retries when the;; directory is back; admin/remove needs no re-auth), never an unhandled 500(try- (when-let [user-email (mfa.db/user-email user-id)]+ (when-let [user-email (:email (users.db/user user-id))](when-let [user-info (sso/find-user user-email)](sso/verify-password user-info password)))(catch Exception e@@ -126,7 +127,7 @@(fn [](or (enrollment/confirm-enrollment! api/*current-user-id* code)(throw (invalid-code-ex)))))- user (mfa.db/user api/*current-user-id*)]+ user (users.db/user api/*current-user-id*)](messages/send-mfa-enabled-email! (:email user))(events/publish-event! :event/mfa-enrolled {:object user}){:recovery_codes recovery-codes}))@@ -144,7 +145,7 @@(when-not (verification/verify-attempt! api/*current-user-id* code nil)(throw (invalid-code-ex)))(enrollment/disable! api/*current-user-id*))))- (let [user (mfa.db/user api/*current-user-id*)]+ (let [user (users.db/user api/*current-user-id*)](messages/send-mfa-disabled-email! (:email user))(events/publish-event! :event/mfa-disabled {:object user}))api/generic-204-no-content)@@ -186,7 +187,7 @@(throw (ex-info (tru "You cannot administratively remove your own two-factor authentication. Please use the normal removal method in your account settings."){:status-code 400})))(when (enrollment/disable! user-id)- (let [user (mfa.db/user user-id)]+ (let [user (users.db/user user-id)](messages/send-mfa-removed-by-admin-email! (:email user))(events/publish-event! :event/mfa-disabled {:object user})))api/generic-204-no-content)diff --git a/enterprise/backend/src/metabase_enterprise/permission_debug/db.clj b/enterprise/backend/src/metabase_enterprise/permission_debug/db.cljindex dc793fbb982..917530c3220 100644--- a/enterprise/backend/src/metabase_enterprise/permission_debug/db.clj+++ b/enterprise/backend/src/metabase_enterprise/permission_debug/db.clj@@ -8,16 +8,6 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn user-superuser?- "Whether the User with `user-id` is a superuser."- [user-id :- ::lib.schema.id/user]- (t2/select-one-fn :is_superuser :model/User :id user-id))--(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(defn- blocked-tables-select[user-id tables-expr permissions-blocking permissions-granting]{:select [[:db.name :db_name] :blocked.schema [:blocked.name :table_name] [:pg.name :group_name]]diff --git a/enterprise/backend/src/metabase_enterprise/permission_debug/impl.clj b/enterprise/backend/src/metabase_enterprise/permission_debug/impl.cljindex c5846426dfb..bcd9f8d21e1 100644--- a/enterprise/backend/src/metabase_enterprise/permission_debug/impl.clj+++ b/enterprise/backend/src/metabase_enterprise/permission_debug/impl.clj@@ -17,7 +17,9 @@[metabase.lib.core :as lib][metabase.models.interface :as mi][metabase.permissions.core :as perms]+ [metabase.queries.db :as queries.db][metabase.query-processor.preprocess :as qp.preprocess]+ [metabase.users.db :as users.db][metabase.util.i18n :refer [tru]][metabase.util.malli :as mu][metabase.util.match :as match]))@@ -65,7 +67,7 @@Returns a map conforming to the DebuggerSchema defined in the API."{:arglists '([debug-info-map])}(fn [{:keys [action-type user-id]}]- (let [user-is-superuser? (permission-debug.db/user-superuser? user-id)]+ (let [user-is-superuser? (:is_superuser (users.db/user user-id))](if user-is-superuser?::is-superuseraction-type))))@@ -199,7 +201,7 @@[{:keys [user-id model-id] :as debug-info} :- DebuggerArguments](merge-permission-check(debug-permissions (assoc debug-info :action-type :card/read))- (let [card (permission-debug.db/card model-id)+ (let [card (queries.db/card model-id)blocked-by-group (check-table-permissions user-id card{:perms/view-data :blocked}{:perms/view-data :legacy-no-self-service})]@@ -218,7 +220,7 @@[{:keys [user-id model-id] :as debug-info} :- DebuggerArguments](merge-permission-check(debug-permissions (assoc debug-info :action-type :card/query))- (let [card (permission-debug.db/card model-id)+ (let [card (queries.db/card model-id)limited-by-group (check-table-permissions user-id card{:perms/download-results :ten-thousand-rows}{:perms/download-results :one-million-rows})diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/core.cljindex 565faf77ece..6a5b284dbaf 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj@@ -10,6 +10,7 @@[metabase-enterprise.remote-sync.spec :as spec][metabase.api.common :as api][metabase.collections.core :as collections]+ [metabase.collections.db :as collections.db][metabase.events.core :as events][metabase.premium-features.core :refer [defenterprise]][metabase.util :as u]@@ -38,7 +39,7 @@{:namespace (if (and (map? collection) (contains? collection :namespace))(:namespace collection);; the root collection has no ID, and nothing in it is synced- (some-> (u/id collection) remote-sync.db/collection-namespace))}))))))+ (some-> (u/id collection) collections.db/collection :namespace))}))))))(defenterprise collection-syncable?"Whether `collection` can be remote-synced: a Collection of a namespace remote sync syncs, the Library and every Collection inside it, and any other once custom collections are on."diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/db.cljindex a1b4b2d624b..64506d751e8 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj@@ -400,11 +400,6 @@[collection-ids :- [:sequential ::lib.schema.id/collection]](t2/select [:model/Collection :id :is_remote_synced] :id [:in collection-ids]))-(mu/defn collection-name-and-id- "The `:name` and `:collection_id` (its own ID) of the Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one [:model/Collection :name [:id :collection_id]] :id collection-id))-(mu/defn library-collection"The Library Collection of `library-type`, or nil."[library-type :- :string]@@ -451,12 +446,6 @@[namespace-name :- :string](t2/select-pks-vec :model/Collection :namespace namespace-name))-(mu/defn collection-namespace- "The namespace of the Collection with `collection-id`, nil for the default namespace or no such Collection."- [collection-id :- [:maybe ms/PositiveInt]]- (when collection-id- (t2/select-one-fn :namespace :model/Collection :id collection-id)))-(mu/defn remote-synced-collection-ids"The IDs of the remote-synced Collections."[]@@ -756,21 +745,16 @@[](t2/delete! :model/RemoteSyncObject))-(mu/defn task- "The RemoteSyncTask with `task-id`, or nil."+(mu/defn remote-sync-task :- [:maybe ::remote-sync.schema/remote-sync-task]+ "The ::remote-sync.schema/remote-sync-task with `task-id`, or nil."[task-id :- ms/PositiveInt]- (t2/select-one :model/RemoteSyncTask task-id))+ (t2/select-one :model/RemoteSyncTask :id [:auto/param task-id]))(mu/defn lock-task"The RemoteSyncTask with `task-id`, locked for update, or nil."[task-id :- ms/PositiveInt](t2/select-one :model/RemoteSyncTask :id task-id {:for :update}))-(mu/defn task-cancelled?- "The cancelled flag of the RemoteSyncTask with `task-id`."- [task-id :- ms/PositiveInt]- (t2/select-one-fn :cancelled :model/RemoteSyncTask :id task-id))-(def ^:private last-alive-at"The time the task's owning thread last proved it was alive: its heartbeat, or its last progress write forrows that predate the heartbeat column or whose worker died before its first beat."diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/events.cljindex df3550bcc76..ed48a26285a 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj@@ -24,6 +24,7 @@[metabase-enterprise.remote-sync.spec :as spec][metabase.app-db.cluster-lock :as cluster-lock][metabase.collections.core :as collections]+ [metabase.collections.db :as collections.db][metabase.events.core :as events][metabase.util.log :as log][methodical.core :as methodical]@@ -473,7 +474,8 @@(defn- hydrate-collection-details"Hydrates details for a Collection."[id]- (remote-sync.db/collection-name-and-id id))+ (when-let [collection (collections.db/collection id)]+ {:name (:name collection) :collection_id (:id collection)}))(defn- handle-library-sync-status-change!"When the Library collection's is_remote_synced status changes, trigger Library content sync tracking.diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.cljindex e557c74a344..83eab1fa7b2 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj@@ -1513,7 +1513,7 @@(e.g. `{:branch \"main\"}`, plus `:auto true` for system-triggered syncs); `user-id` is nil forsystem-triggered syncs."[topic task-id details user-id]- (let [task (remote-sync.db/task task-id)]+ (let [task (remote-sync.db/remote-sync-task task-id)](events/publish-event! topic{:object task:details details@@ -1546,7 +1546,7 @@is still open may be that the app DB is unreachable."[task-id](try- (when (some-> (remote-sync.db/task task-id) remote-sync.task/running?)+ (when (some-> (remote-sync.db/remote-sync-task task-id) remote-sync.task/running?)(log/warnf "Remote sync task %d ended without recording a result; failing it" task-id)(handle-task-result! {:status :error :message "Task ended without recording a result"} task-id))(catch Throwable tdiff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_task.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_task.cljindex 76fd6574c65..153c997d1d8 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_task.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_task.clj@@ -78,7 +78,7 @@Throws ExceptionInfo if the task has been marked as cancelled."[task-id progress]- (when (true? (remote-sync.db/task-cancelled? task-id))+ (when (true? (:cancelled (remote-sync.db/remote-sync-task task-id)))(throw (ex-info "Remote sync task has been cancelled" {:task-id task-id:cancelled? true})))(remote-sync.db/report-task-progress! task-id progress))diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/spec.cljindex d7cdb5be96e..e3134b31936 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj@@ -17,6 +17,7 @@[metabase-enterprise.remote-sync.settings :as rs-settings][metabase-enterprise.transforms-python.core :as transforms-python][metabase.collections.core :as collections]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.models.serialization :as serdes][metabase.settings.core :as setting]@@ -878,7 +879,7 @@(and (library-synced-object? spec object)(or (nil? collection-id)(= collections/data-actions-ns- (some-> (remote-sync.db/collection-namespace collection-id) keyword))))))+ (some-> (collections.db/collection collection-id) :namespace keyword))))))(defmethod check-eligibility-by-type :collection[{:keys [eligibility] :as spec} object]@@ -887,7 +888,7 @@;; what sits in a data app's collection is synced with the app, an action without a model included: the;; app's copies belong to no model, and are the app's rather than the Library'sin-data-app? (and (some? collection-id)- (data-apps-namespace-collection? {:namespace (remote-sync.db/collection-namespace collection-id)}))]+ (data-apps-namespace-collection? {:namespace (:namespace (collections.db/collection collection-id))}))](if (and (library-synced-object? spec object) (not in-data-app?))(and (rs-settings/library-is-remote-synced?)(library-content? spec object))diff --git a/enterprise/backend/src/metabase_enterprise/replacement/api.clj b/enterprise/backend/src/metabase_enterprise/replacement/api.cljindex 5194525bd8b..a6b612e22f0 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/api.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/api.clj@@ -11,6 +11,7 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]]+ [metabase.queries.db :as queries.db][metabase.transforms.core :as transforms][metabase.transforms.schema :as transforms.schema][ring.util.response :as response]))@@ -103,7 +104,7 @@[:transform_tag_ids {:optional true} [:maybe [:sequential pos-int?]]]]](api/check-superuser)(let [user-id api/*current-user-id*- card (api/check-404 (replacement.db/card card_id))+ card (api/check-404 (queries.db/card card_id))transform (transforms/create-transform!{:name transform_name:source {:type :query@@ -146,14 +147,14 @@"Get the status of a source replacement run."[{:keys [id]} :- [:map {:closed true} [:id ::replacement.schema/run-id]]](api/check-superuser)- (or (replacement.db/run id)+ (or (replacement.db/replacement-run id)(throw (ex-info "Run not found" {:status-code 404}))))(api.macros/defendpoint :post "/runs/:id/cancel" :- [:map [:success boolean?]]"Cancel a running source replacement."[{:keys [id]} :- [:map {:closed true} [:id ::replacement.schema/run-id]]](api/check-superuser)- (let [run (replacement.db/run id)]+ (let [run (replacement.db/replacement-run id)](when-not run(throw (ex-info "Run not found" {:status-code 404})))(when-not (:is_active run)diff --git a/enterprise/backend/src/metabase_enterprise/replacement/db.clj b/enterprise/backend/src/metabase_enterprise/replacement/db.cljindex a657fc412e2..2072fe768c2 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/db.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/db.clj@@ -16,10 +16,10 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn run- "The ReplacementRun with `run-id`, or nil."+(mu/defn replacement-run :- [:maybe ::replacement.schema/replacement-run]+ "The ::replacement.schema/replacement-run with `run-id`, or nil."[run-id :- ms/PositiveInt]- (t2/select-one :model/ReplacementRun :id run-id))+ (t2/select-one :model/ReplacementRun :id [:auto/param run-id]))(mu/defn runs"The ReplacementRuns, newest first, restricted to the `is-active` flag when given."@@ -33,11 +33,6 @@[](t2/select-one :model/ReplacementRun :is_active true))-(mu/defn run-active-flag- "The `:is_active` row of the ReplacementRun with `run-id`, or nil."- [run-id :- ms/PositiveInt]- (t2/select-one [:model/ReplacementRun :is_active] :id run-id))-(mu/defn insert-run!"Insert `run` and return the new instance."[run :- ::replacement.schema/replacement-run.update]@@ -97,21 +92,11 @@[ids :- [:sequential ms/PositiveInt]](t2/select :model/Measure :id [:in ids]))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(mu/defn cards-by-id"A map of Card ID to Card for `card-ids`."[card-ids :- [:set ::lib.schema.id/card]](t2/select-pk->fn identity :model/Card :id [:in card-ids]))-(mu/defn card-database-id- "The Database ID of the Card with `card-id`."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :database_id :model/Card :id card-id))-(mu/defn card-with-table-exists?"Whether one of the Cards with `card-ids` is on the Table with `table-id`."[card-ids :- [:set ::lib.schema.id/card]@@ -124,44 +109,24 @@changes :- ::queries.schema/card.update](t2/update! :model/Card card-id changes))-(mu/defn transform- "The Transform with `transform-id`, or nil."- [transform-id :- ::lib.schema.id/transform]- (t2/select-one :model/Transform :id transform-id))-(mu/defn update-transform!"Apply `changes` to the Transform with `transform-id`, returning the number updated."[transform-id :- ::lib.schema.id/transformchanges :- ::transforms.schema/transform.update](t2/update! :model/Transform transform-id changes))-(mu/defn segment- "The Segment with `segment-id`, or nil."- [segment-id :- ::lib.schema.id/segment]- (t2/select-one :model/Segment :id segment-id))-(mu/defn update-segment!"Apply `changes` to the Segment with `segment-id`, returning the number updated."[segment-id :- ::lib.schema.id/segmentchanges :- ::segments.schema/segment.update](t2/update! :model/Segment segment-id changes))-(mu/defn measure- "The Measure with `measure-id`, or nil."- [measure-id :- ::lib.schema.id/measure]- (t2/select-one :model/Measure :id measure-id))-(mu/defn update-measure!"Apply `changes` to the Measure with `measure-id`, returning the number updated."[measure-id :- ::lib.schema.id/measurechanges :- ::measures.schema/measure.update](t2/update! :model/Measure measure-id changes))-(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id dashboard-id))-(mu/defn update-dashboard!"Apply `changes` to the Dashboard with `dashboard-id`, returning the number updated."[dashboard-id :- ::lib.schema.id/dashboard@@ -179,11 +144,6 @@changes :- ::dashboards.schema/dashboard-card.update](t2/update! :model/DashboardCard dashcard-id changes))-(mu/defn table-database-id- "The Database ID of the Table with `table-id`."- [table-id :- ::lib.schema.id/table]- (t2/select-one-fn :db_id :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(mu/defn active-fields-of-table"The active Fields of the Table with `table-id`."[table-id :- ::lib.schema.id/table]diff --git a/enterprise/backend/src/metabase_enterprise/replacement/field_refs.clj b/enterprise/backend/src/metabase_enterprise/replacement/field_refs.cljindex ab183a99c9e..1a37bff8966 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/field_refs.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/field_refs.clj@@ -3,10 +3,15 @@[metabase-enterprise.replacement.db :as replacement.db][metabase-enterprise.replacement.util :as replacement.util][metabase-enterprise.replacement.walk :as replacement.walk]+ [metabase.dashboards.db :as dashboards.db][metabase.lib.core :as lib][metabase.lib.util :as lib.util]+ [metabase.measures.db :as measures.db][metabase.models.visualization-settings :as vs]- [metabase.source-swap.core :as source-swap]))+ [metabase.queries.db :as queries.db]+ [metabase.segments.db :as segments.db]+ [metabase.source-swap.core :as source-swap]+ [metabase.transforms.db :as transforms.db]))(set! *warn-on-reflection* true)@@ -160,11 +165,11 @@`entity` is an optional pre-fetched entity from bulk-load-metadata-for-entities!."([[entity-type entity-id :as entity-ref]](upgrade-field-refs! entity-ref (case entity-type- :card (replacement.db/card entity-id)- :transform (replacement.db/transform entity-id)- :segment (replacement.db/segment entity-id)- :measure (replacement.db/measure entity-id)- :dashboard (replacement.db/dashboard entity-id)+ :card (queries.db/card entity-id)+ :transform (transforms.db/transform entity-id)+ :segment (segments.db/segment entity-id)+ :measure (measures.db/measure entity-id)+ :dashboard (dashboards.db/dashboard entity-id)nil)))([[entity-type _entity-id] entity](case entity-typediff --git a/enterprise/backend/src/metabase_enterprise/replacement/models/replacement_run.clj b/enterprise/backend/src/metabase_enterprise/replacement/models/replacement_run.cljindex 1d270b899e1..541de50a04a 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/models/replacement_run.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/models/replacement_run.clj@@ -124,7 +124,7 @@(deliver on-complete :run/cancelled))(throw (ex-info "Run canceled" {:run-id run-id})))))))(canceled? [_]- (not (:is_active (replacement.db/run-active-flag run-id))))+ (not (:is_active (replacement.db/replacement-run run-id))))(start-run! [_](start-run! run-id))(succeed-run! [_]diff --git a/enterprise/backend/src/metabase_enterprise/replacement/runner.clj b/enterprise/backend/src/metabase_enterprise/replacement/runner.cljindex 6fae87f12bf..fdcade76250 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/runner.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/runner.clj@@ -12,10 +12,13 @@[metabase.lib.core :as lib][metabase.lib.metadata.protocols :as lib.metadata.protocols][metabase.model-persistence.core :as model-persistence]+ [metabase.queries.db :as queries.db][metabase.source-swap.util :as source-swap.util][metabase.transforms.core :as transforms]+ [metabase.transforms.db :as transforms.db][metabase.util :as u][metabase.util.log :as log]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.models.field-user-settings :as field-user-settings]))(set! *warn-on-reflection* true)@@ -110,8 +113,8 @@(count all-transitive-dependents))) ;; phase 2: swap(let [db-id (case (first old-source)- :card (replacement.db/card-database-id (second old-source))- :table (replacement.db/table-database-id (second old-source)))+ :card (:database_id (queries.db/card (second old-source)))+ :table (:db_id (warehouse-schema.db/table (second old-source))))batch-size 500];; phase 1: Upgrade field refs for ALL transitive dependents(doseq [batch (partition-all batch-size all-transitive-dependents)]@@ -172,7 +175,7 @@"Copy user-edited metadata from a model's result_metadata onto the FieldUserSettings of theoutput table's Fields, so the overrides keep showing on the new Fields after the swap."[card-id table-id]- (let [card (replacement.db/card card-id)+ (let [card (queries.db/card card-id)result-metadata (:result_metadata card)fields (replacement.db/active-fields-of-table table-id)field-by-name (m/index-by :name fields)]@@ -192,7 +195,7 @@([card-id transform-id](run-swap-model-with-transform! card-id transform-id noop-progress))([card-id transform-id progress & {:keys [user-id]}]- (let [transform (or (replacement.db/transform transform-id)+ (let [transform (or (transforms.db/transform transform-id)(throw (ex-info "Transform not found" {:transform-id transform-id})))];; phase 1: execute the transform(transforms/execute! transform (cond-> {:run-method :manual}diff --git a/enterprise/backend/src/metabase_enterprise/replacement/source_check.clj b/enterprise/backend/src/metabase_enterprise/replacement/source_check.cljindex b56ece1d476..f15d80cbb49 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/source_check.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/source_check.clj@@ -6,10 +6,12 @@[metabase.lib-be.core :as lib-be][metabase.lib.schema.id :as lib.schema.id][metabase.lib.schema.metadata :as lib.schema.metadata]+ [metabase.queries.db :as queries.db][metabase.source-swap.core :as source-swap][metabase.source-swap.schema :as source-swap.schema][metabase.util :as u]- [metabase.util.malli :as mu]))+ [metabase.util.malli :as mu]+ [metabase.warehouse-schema.db :as warehouse-schema.db]))(set! *warn-on-reflection* true)@@ -44,8 +46,8 @@[entity-type :- ::replacement.schema/source-entity-typeentity-id :- ::replacement.schema/source-entity-id](case entity-type- :card (replacement.db/card-database-id entity-id)- :table (replacement.db/table-database-id entity-id)))+ :card (:database_id (queries.db/card entity-id))+ :table (:db_id (warehouse-schema.db/table entity-id))))(mu/defn- format-column-mappings :- [:sequential ::replacement.schema/column-mapping]"Format column mappings by applying format-column to source and target columns."diff --git a/enterprise/backend/src/metabase_enterprise/replacement/source_swap.clj b/enterprise/backend/src/metabase_enterprise/replacement/source_swap.cljindex 90906469119..792dd5e9396 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/source_swap.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/source_swap.clj@@ -16,11 +16,16 @@[metabase-enterprise.replacement.util :as replacement.util][metabase-enterprise.replacement.walk :as replacement.walk][metabase.api.common :as api]+ [metabase.dashboards.db :as dashboards.db][metabase.events.core :as events][metabase.lib.core :as lib]+ [metabase.measures.db :as measures.db][metabase.models.visualization-settings :as vs]+ [metabase.queries.db :as queries.db][metabase.queries.models.query :as queries.query]- [metabase.source-swap.core :as source-swap]))+ [metabase.segments.db :as segments.db]+ [metabase.source-swap.core :as source-swap]+ [metabase.transforms.db :as transforms.db]))(set! *warn-on-reflection* true)@@ -175,7 +180,7 @@(replacement.db/update-dashboard! (:id dashboard) {:parameters parameters'}))(when (or any-dashcard-changed? params-changed?)(events/publish-event!- :event/dashboard-update {:object (replacement.db/dashboard (:id dashboard))+ :event/dashboard-update {:object (dashboards.db/dashboard (:id dashboard)):user-id api/*current-user-id*}))))(defn swap-source!@@ -186,11 +191,11 @@([[entity-type entity-id :as entity-ref] old-source new-source](swap-source! entity-ref(case entity-type- :card (replacement.db/card entity-id)- :transform (replacement.db/transform entity-id)- :segment (replacement.db/segment entity-id)- :measure (replacement.db/measure entity-id)- :dashboard (replacement.db/dashboard entity-id)+ :card (queries.db/card entity-id)+ :transform (transforms.db/transform entity-id)+ :segment (segments.db/segment entity-id)+ :measure (measures.db/measure entity-id)+ :dashboard (dashboards.db/dashboard entity-id)nil)old-source new-source))([[entity-type _entity-id] entity old-source new-source]diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj b/enterprise/backend/src/metabase_enterprise/sandbox/api/table.cljindex 382d0fbe032..9a3bcfa4aa8 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj@@ -2,7 +2,6 @@(:require[metabase-enterprise.sandbox.api.column-filter :as col-filter][metabase-enterprise.sandbox.api.util :as sandbox.api.util]- [metabase-enterprise.sandbox.db :as sandbox.db][metabase.api-scope.data-app :as api-scope][metabase.api.common :as api][metabase.api.macros :as api.macros]@@ -12,6 +11,7 @@[metabase.util :as u][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.table :as schema.table]))(mu/defn only-sandboxed-perms? :- :boolean@@ -31,7 +31,7 @@`include-hidden-fields?` and `include-editable-data-model?` can be either booleans or boolean strings.":feature :sandboxes[id opts]- (let [table (api/check-404 (sandbox.db/table id))+ (let [table (api/check-404 (warehouse-schema.db/table id))thunk (fn [] (schema.table/fetch-query-metadata* table opts))](if (only-sandboxed-perms? table)(filter-fields-for-sandboxingdiff --git a/enterprise/backend/src/metabase_enterprise/sandbox/db.clj b/enterprise/backend/src/metabase_enterprise/sandbox/db.cljindex 5e5318edc56..4ee93d117bf 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/db.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/db.clj@@ -15,10 +15,10 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn sandbox- "The Sandbox with `sandbox-id`, or nil."+(mu/defn sandbox :- [:maybe ::sandbox.schema/sandbox]+ "The ::sandbox.schema/sandbox with `sandbox-id`, or nil."[sandbox-id :- ::lib.schema.id/sandbox]- (t2/select-one :model/Sandbox :id sandbox-id))+ (t2/select-one :model/Sandbox :id [:auto/param sandbox-id]))(mu/defn sandboxes"Every Sandbox, in ID order."@@ -150,11 +150,6 @@[:not= :login_attributes nil][:not= :login_attributes "{}"]]]}))-(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn tables-of-database"The `:id`, `:db_id`, and `:schema` of the Tables of the Database with `db-id`, restricted to `schema` when`schema-only?`."@@ -192,11 +187,6 @@[card-ids :- [:set ::lib.schema.id/card]](queries/cards-queries-info card-ids))-(mu/defn card-result-metadata- "The result metadata of the Card with `card-id`."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :result_metadata :model/Card :id card-id))-(mu/defn sandboxing-cards"The `:id`, `:dataset_query`, and `:database_id` of the Cards Sandboxes are built on."[]diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.clj b/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.cljindex 9cee0d59b82..84da0bab360 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.clj@@ -19,6 +19,7 @@[metabase.models.interface :as mi][metabase.permissions.core :as perms][metabase.premium-features.core :refer [defenterprise]]+ [metabase.queries.db :as queries.db][metabase.queries.schema :as queries.schema][metabase.query-processor.error-type :as qp.error-type][metabase.query-processor.preprocess :as qp.preprocess]@@ -135,7 +136,7 @@;; not all sandboxes have Cards(when card-id;; not all Cards have saved result metadata- (when-let [result-metadata (not-empty (sandbox.db/card-result-metadata card-id))]+ (when-let [result-metadata (not-empty (:result_metadata (queries.db/card card-id)))](check-columns-match-table table-id result-metadata))))([table-id :- ::lib.schema.id/table@@ -194,7 +195,7 @@Card cannot add fields or change types vs. the original Table."[card-id new-result-metadata](when-let [gtaps-using-this-card (not-empty (sandbox.db/sandboxes-using-card card-id))]- (let [original-result-metadata (sandbox.db/card-result-metadata card-id)]+ (let [original-result-metadata (:result_metadata (queries.db/card card-id))](when-not (= original-result-metadata new-result-metadata)(doseq [{table-id :table_id} gtaps-using-this-card](trydiff --git a/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/db.clj b/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/db.cljindex 229092cf05c..9d186849a23 100644--- a/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/db.clj+++ b/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/db.clj@@ -55,16 +55,6 @@[:= :archived false](when id [:= :id id])]}))-(mu/defn measure-table-id- "The Table ID of the Measure with `id`."- [id :- ::lib.schema.id/measure]- (t2/select-one-fn :table_id :model/Measure :id id))--(mu/defn segment-table-id- "The Table ID of the Segment with `id`."- [id :- ::lib.schema.id/segment]- (t2/select-one-fn :table_id :model/Segment :id id))-(mu/defn ai-contexts"The entity type, entity ID, and AI context of every OsiAiContext."[]diff --git a/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/reconcile.clj b/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/reconcile.cljindex 2da0be24d66..ddf0fa28c99 100644--- a/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/reconcile.clj+++ b/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/reconcile.clj@@ -29,7 +29,9 @@[metabase-enterprise.search.entity-retrieval.index-table :as index-table][metabase-enterprise.search.semantic.embedding :as embedding][metabase.collections.core :as collections]+ [metabase.measures.db :as measures.db][metabase.search.entity-retrieval.core :as entity-retrieval]+ [metabase.segments.db :as segments.db][metabase.util :as u][metabase.util.log :as log][next.jdbc :as jdbc]@@ -204,8 +206,8 @@(#{"measure" "segment"} entity-type);; A measure/segment is a member only when its parent table is a current library table.(when-let [table-id (if (= entity-type "measure")- (entity-retrieval.db/measure-table-id entity-local-id)- (entity-retrieval.db/segment-table-id entity-local-id))]+ (:table_id (measures.db/measure entity-local-id))+ (:table_id (segments.db/segment entity-local-id)))](when (seq (library-tables lib-ids table-id))(first (if (= entity-type "measure")(library-measures [table-id] entity-local-id)diff --git a/enterprise/backend/src/metabase_enterprise/security_center/db.clj b/enterprise/backend/src/metabase_enterprise/security_center/db.cljindex a4bf059c3c1..29697fb052a 100644--- a/enterprise/backend/src/metabase_enterprise/security_center/db.clj+++ b/enterprise/backend/src/metabase_enterprise/security_center/db.clj@@ -10,10 +10,10 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(mu/defn advisory- "The SecurityAdvisory with `id`, or nil."+(mu/defn security-advisory :- [:maybe ::security-center.schema/security-advisory]+ "The ::security-center.schema/security-advisory with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/SecurityAdvisory :id id))+ (t2/select-one :model/SecurityAdvisory :id [:auto/param id]))(mu/defn advisory-by-advisory-id"The SecurityAdvisory with the external `advisory-id`, or nil."diff --git a/enterprise/backend/src/metabase_enterprise/security_center/models/security_advisory.clj b/enterprise/backend/src/metabase_enterprise/security_center/models/security_advisory.cljindex 0768d9430b4..b5672e68650 100644--- a/enterprise/backend/src/metabase_enterprise/security_center/models/security_advisory.clj+++ b/enterprise/backend/src/metabase_enterprise/security_center/models/security_advisory.clj@@ -57,7 +57,7 @@(analytics/track-event! :snowplow/simple_event{:event "security_advisory_acknowledged":event_detail (name (:severity advisory))})- (-> (security-center.db/advisory (:id advisory))+ (-> (security-center.db/security-advisory (:id advisory))(t2/hydrate :acknowledged_by_user)))(defn acknowledge-many!diff --git a/enterprise/backend/src/metabase_enterprise/snippet_collections/db.clj b/enterprise/backend/src/metabase_enterprise/snippet_collections/db.cljdeleted file mode 100644index 2957a93b0ea..00000000000--- a/enterprise/backend/src/metabase_enterprise/snippet_collections/db.clj+++ /dev/null@@ -1,14 +0,0 @@-(ns metabase-enterprise.snippet-collections.db- "Application database queries for the snippet-collections module. Every function here is a direct Toucan 2 call with no- additional logic, so the rest of the module never talks to `toucan2.core` itself."- (:require- [metabase.lib.schema.id :as lib.schema.id]- [metabase.util.malli :as mu]- [toucan2.core :as t2]))--(mu/defn snippet-with-collection-id- "The `:collection_id` of the NativeQuerySnippet with `id`, or nil if no such NativeQuerySnippet exists. Unlike a- bare column lookup, this distinguishes a missing snippet (nil) from one filed under the root collection- (`{:collection_id nil}`)."- [id :- ::lib.schema.id/native-query-snippet]- (t2/select-one [:model/NativeQuerySnippet :collection_id] :id id))diff --git a/enterprise/backend/src/metabase_enterprise/snippet_collections/models/native_query_snippet/permissions.clj b/enterprise/backend/src/metabase_enterprise/snippet_collections/models/native_query_snippet/permissions.cljindex 6b5a55c38eb..cb2810dc067 100644--- a/enterprise/backend/src/metabase_enterprise/snippet_collections/models/native_query_snippet/permissions.clj+++ b/enterprise/backend/src/metabase_enterprise/snippet_collections/models/native_query_snippet/permissions.clj@@ -1,9 +1,9 @@(ns metabase-enterprise.snippet-collections.models.native-query-snippet.permissions"EE implementation of NativeQuerySnippet permissions."(:require- [metabase-enterprise.snippet-collections.db :as snippet-collections.db][metabase.models.interface :as mi][metabase.native-query-snippets.core :as snippets]+ [metabase.native-query-snippets.db :as native-query-snippets.db][metabase.native-query-snippets.schema :as snippets.schema][metabase.permissions.core :as perms][metabase.premium-features.core :refer [defenterprise]]@@ -28,7 +28,7 @@(snippets/has-any-native-permissions?)(has-parent-collection-perms? snippet :read)))([_model id]- (can-read? (snippet-collections.db/snippet-with-collection-id id))))+ (can-read? (native-query-snippets.db/native-query-snippet id))))(defenterprise can-write?"Can the current User edit this `snippet`?"@@ -40,7 +40,7 @@(has-parent-collection-perms? snippet :write)(remote-sync/model-editable? :model/NativeQuerySnippet snippet)))([_model id]- (can-write? (snippet-collections.db/snippet-with-collection-id id))))+ (can-write? (native-query-snippets.db/native-query-snippet id))))(defenterprise can-create?"Can the current User save a new Snippet with the values in `m`?"diff --git a/enterprise/backend/src/metabase_enterprise/sso/db.clj b/enterprise/backend/src/metabase_enterprise/sso/db.cljindex ae3d303e0ef..980836d947d 100644--- a/enterprise/backend/src/metabase_enterprise/sso/db.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/db.clj@@ -2,10 +2,16 @@"Application database queries for the sso module. Every function here is a direct Toucan 2 call with noadditional logic, so no other namespace in the module runs a query itself."(:require+ [metabase-enterprise.sso.schema :as sso.schema][metabase.util.malli :as mu][metabase.util.malli.schema :as ms][toucan2.core :as t2]))+(mu/defn sso-relay-state :- [:maybe ::sso.schema/sso-relay-state]+ "The ::sso.schema/sso-relay-state with `hashed-key`, or nil."+ [hashed-key :- :string]+ (t2/select-one :model/SsoRelayState :id [:auto/param hashed-key]))+(mu/defn session-user-email-and-source"The email and SSO source of the Session with `session-key-hashed`, plus the identifiers the IdPused for it, or nil.@@ -34,12 +40,6 @@[:expires_at ms/TemporalInstant]]](t2/insert! :model/SsoRelayState row))-(mu/defn unexpired-relay-state- "The SsoRelayState with `hashed-key` expiring after `now`, or nil."- [hashed-key :- :string- now :- ms/TemporalInstant]- (t2/select-one :model/SsoRelayState :id hashed-key :expires_at [:> now]))-(mu/defn delete-relay-state!"Delete the SsoRelayState with `hashed-key`, returning the number deleted."[hashed-key :- :string]diff --git a/enterprise/backend/src/metabase_enterprise/sso/models/relay_state.clj b/enterprise/backend/src/metabase_enterprise/sso/models/relay_state.cljindex b12547ba1d9..54faad2346e 100644--- a/enterprise/backend/src/metabase_enterprise/sso/models/relay_state.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/models/relay_state.clj@@ -75,7 +75,9 @@retried callback doesn't burn the key."[key](when (relay-state-key? key)- (sso.db/unexpired-relay-state (hash-key key) (t/offset-date-time))))+ (when-let [relay-state (sso.db/sso-relay-state (hash-key key))]+ (when (t/after? (t/instant (:expires_at relay-state)) (t/instant (t/offset-date-time)))+ relay-state))))(defn delete!"Consume (delete) the RelayState entry for the (plaintext) `key`. Called after a successful login; the singlediff --git a/enterprise/backend/src/metabase_enterprise/stale/api.clj b/enterprise/backend/src/metabase_enterprise/stale/api.cljindex 8529d70061b..9b12ecd5ccd 100644--- a/enterprise/backend/src/metabase_enterprise/stale/api.clj+++ b/enterprise/backend/src/metabase_enterprise/stale/api.clj@@ -10,6 +10,7 @@[metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]][metabase.collections.core :as collections]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.premium-features.core :as premium-features][metabase.queries.core :as queries]@@ -114,7 +115,7 @@(t/minus (t/local-date) (t/months 6)))collection (if (= id :root)collection/root-collection- (stale.db/collection id))+ (collections.db/collection id))_ (api/read-check collection)collection-ids (->> (if is_recursive(conj (effective-children-ids collection @api/*current-user-permissions-set*)diff --git a/enterprise/backend/src/metabase_enterprise/stale/db.clj b/enterprise/backend/src/metabase_enterprise/stale/db.cljindex 416f03a9020..e5ad79f7fc3 100644--- a/enterprise/backend/src/metabase_enterprise/stale/db.clj+++ b/enterprise/backend/src/metabase_enterprise/stale/db.clj@@ -7,11 +7,6 @@[metabase.util.malli :as mu][toucan2.core :as t2]))-(mu/defn collection- "The Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one :model/Collection collection-id))-(mu/defn collections-by-id"A map of ID to Collection for `collection-ids`."[collection-ids :- [:set ::lib.schema.id/collection]]diff --git a/enterprise/backend/src/metabase_enterprise/support_access_grants/core.clj b/enterprise/backend/src/metabase_enterprise/support_access_grants/core.cljindex 6c3553d433a..a21c1dfc3d8 100644--- a/enterprise/backend/src/metabase_enterprise/support_access_grants/core.clj+++ b/enterprise/backend/src/metabase_enterprise/support_access_grants/core.clj@@ -79,7 +79,7 @@- Grant doesn't exist- Grant is already revoked"[user-id grant-id]- (let [grant (support-access-grants.db/grant grant-id)]+ (let [grant (support-access-grants.db/support-access-grant-log grant-id)](when-not grant(throw (ex-info (tru "Grant not found"){:status-code 404})))@@ -90,7 +90,7 @@(support-access-grants.db/update-grant! grant-id{:revoked_at now:revoked_by_user_id user-id})- (-> (support-access-grants.db/grant grant-id)+ (-> (support-access-grants.db/support-access-grant-log grant-id)(t2/hydrate :user_info)))))(defn expire-ended-grants!diff --git a/enterprise/backend/src/metabase_enterprise/support_access_grants/db.clj b/enterprise/backend/src/metabase_enterprise/support_access_grants/db.cljindex e52cf47bde5..817e7e945f5 100644--- a/enterprise/backend/src/metabase_enterprise/support_access_grants/db.clj+++ b/enterprise/backend/src/metabase_enterprise/support_access_grants/db.clj@@ -16,10 +16,10 @@[now :- ms/TemporalInstant](t2/exists? :model/SupportAccessGrantLog :revoked_at nil :grant_end_timestamp [:> now]))-(mu/defn grant- "The SupportAccessGrantLog with `grant-id`, or nil."+(mu/defn support-access-grant-log :- [:maybe ::support-access-grants.schema/support-access-grant-log]+ "The ::support-access-grants.schema/support-access-grant-log with `grant-id`, or nil."[grant-id :- ms/PositiveInt]- (t2/select-one :model/SupportAccessGrantLog :id grant-id))+ (t2/select-one :model/SupportAccessGrantLog :id [:auto/param grant-id]))(mu/defn current-grant"The newest unrevoked SupportAccessGrantLog that has not ended, or nil."@@ -75,11 +75,6 @@changes :- (mut/select-keys ::support-access-grants.schema/support-access-grant-log.update [:revoked_at :revoked_by_user_id])](t2/update! :model/SupportAccessGrantLog grant-id changes))-(mu/defn user- "The User with `user-id`, or nil."- [user-id :- ::lib.schema.id/user]- (t2/select-one :model/User user-id))-(mu/defn user-by-email"The User with `email`, or nil."[email :- :string]diff --git a/enterprise/backend/src/metabase_enterprise/support_access_grants/provider.clj b/enterprise/backend/src/metabase_enterprise/support_access_grants/provider.cljindex 08c480077f2..13d78b776d5 100644--- a/enterprise/backend/src/metabase_enterprise/support_access_grants/provider.clj+++ b/enterprise/backend/src/metabase_enterprise/support_access_grants/provider.clj@@ -9,6 +9,7 @@[metabase-enterprise.support-access-grants.db :as support-access-grants.db][metabase-enterprise.support-access-grants.schema :as schema][metabase.auth-identity.core :as auth-identity]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.log :as log][metabase.util.malli :as mu]@@ -72,7 +73,7 @@{:status-code 400})))(u/prog1 (auth-identity/generate-reset-token user-id)(t2/with-transaction [_]- (let [user (support-access-grants.db/user user-id)+ (let [user (users.db/user user-id)auth-identity {:user_id user-id:provider "support-access-grant":provider_id (:email user)diff --git a/enterprise/backend/src/metabase_enterprise/tenants/api.clj b/enterprise/backend/src/metabase_enterprise/tenants/api.cljindex ee8a77234e3..0bc414fffb6 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/api.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/api.clj@@ -6,6 +6,7 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.events.core :as events][metabase.request.core :as request]@@ -82,6 +83,13 @@[:attributes {:optional true} [:maybe tenant/Attributes]][:is_active {:optional true} [:maybe ms/BooleanValue]]])+(defn- collection-with-archived-state+ "The Collection with `collection-id` if its archived flag is `archived?`, or nil."+ [collection-id archived?]+ (let [coll (collections.db/collection collection-id)]+ (when (= archived? (:archived coll))+ coll)))+(mu/defn update-tenant!"Updates a tenant, publishing any necessary events after doing so"[tenant-id :- ms/PositiveInt@@ -93,11 +101,11 @@tenant-after-update (tenants.db/tenant tenant-id)](when (false? is_active)(tenants.db/deactivate-tenant-users! tenant-id)- (some-> (tenants.db/collection-with-archived-state (:tenant_collection_id tenant-before-update) false)+ (some-> (collection-with-archived-state (:tenant_collection_id tenant-before-update) false)collection/archive-collection!))(when (true? is_active)(tenants.db/reactivate-tenant-users! tenant-id)- (some-> (tenants.db/collection-with-archived-state (:tenant_collection_id tenant-before-update) true)+ (some-> (collection-with-archived-state (:tenant_collection_id tenant-before-update) true)(collection/unarchive-collection! {})))(events/publish-event! :event/tenant-update {:object tenant-after-update:previous-object tenant-before-update})diff --git a/enterprise/backend/src/metabase_enterprise/tenants/auth_provider.clj b/enterprise/backend/src/metabase_enterprise/tenants/auth_provider.cljindex 00aaacada06..ddf006af2db 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/auth_provider.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/auth_provider.clj@@ -27,14 +27,14 @@user-has-tenant?)(throw (ex-info "Tenant claim required for external user"{:user/tenant-id tenant_id- :user/tenant-slug (tenants.db/tenant-slug tenant_id)+ :user/tenant-slug (:slug (tenants.db/tenant tenant_id)):status-code 403}))(and user-exists?(not= tenant_id (u/id existing-tenant)))(throw (ex-info "Tenant ID mismatch with existing user"{:user/tenant-id tenant_id- :user/tenant-slug (tenants.db/tenant-slug tenant_id)+ :user/tenant-slug (:slug (tenants.db/tenant tenant_id)):tenant-slug/tenant-id (:id existing-tenant):tenant-slug/slug (:slug existing-tenant):status-code 403})))))diff --git a/enterprise/backend/src/metabase_enterprise/tenants/db.clj b/enterprise/backend/src/metabase_enterprise/tenants/db.cljindex a313550118b..b06eb3c9b8d 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/db.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/db.clj@@ -10,26 +10,16 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(mu/defn tenant- "The Tenant with `tenant-id`, or nil."+(mu/defn tenant :- [:maybe ::tenants.schema/tenant]+ "The ::tenants.schema/tenant with `tenant-id`, or nil."[tenant-id :- ms/PositiveInt]- (t2/select-one :model/Tenant :id tenant-id))+ (t2/select-one :model/Tenant :id [:auto/param tenant-id]))(mu/defn tenant-by-slug"The Tenant with `slug`, or nil."[slug :- :string](t2/select-one :model/Tenant :slug slug))-(mu/defn tenant-slug- "The slug of the Tenant with `tenant-id`."- [tenant-id :- ms/PositiveInt]- (t2/select-one-fn :slug :model/Tenant :id tenant-id))--(mu/defn tenant-collection-id- "The root Collection ID of the Tenant with `tenant-id`."- [tenant-id :- ms/PositiveInt]- (t2/select-one-fn :tenant_collection_id :model/Tenant :id tenant-id))-(mu/defn tenants-page"The Tenants in ID order, restricted by `status` (`\"all\"`, `\"active\"`, or `\"deactivated\"`) and paged by theoptional `limit` and `offset`."@@ -109,17 +99,6 @@(t2/update! :model/User {:is_active false :tenant_id tenant-id :deactivated_with_tenant true}{:is_active true :deactivated_with_tenant nil}))-(mu/defn user-tenant-id- "The Tenant ID of the User with `user-id`."- [user-id :- ::lib.schema.id/user]- (t2/select-one-fn :tenant_id :model/User :id user-id))--(mu/defn collection-with-archived-state- "The Collection with `collection-id` if its archived flag is `archived?`, or nil."- [collection-id :- ::lib.schema.id/collection- archived? :- :boolean]- (t2/select-one :model/Collection :id collection-id :archived archived?))-(mu/defn descendant-collection-ids"The IDs of the Collections under the Collection with `collection-id`."[collection-id :- ::lib.schema.id/collection]diff --git a/enterprise/backend/src/metabase_enterprise/tenants/models.clj b/enterprise/backend/src/metabase_enterprise/tenants/models.cljindex 51b5762f6ef..b0330bd1dc7 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/models.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/models.clj@@ -7,6 +7,7 @@[metabase.lib.schema.parameter :as lib.schema.parameter][metabase.models.interface :as mi][metabase.premium-features.core :refer [defenterprise]]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.i18n :refer [deferred-tru tru]][metabase.util.malli :as mu]@@ -88,8 +89,8 @@:feature :tenants[user-or-id](into []- (when-let [tenant-id (tenants.db/user-tenant-id (u/the-id user-or-id))]- (when-let [tenant-collection-id (tenants.db/tenant-collection-id tenant-id)]+ (when-let [tenant-id (:tenant_id (users.db/user (u/the-id user-or-id)))]+ (when-let [tenant-collection-id (:tenant_collection_id (tenants.db/tenant tenant-id))](let [descendant-ids (tenants.db/descendant-collection-ids tenant-collection-id)](conj descendant-ids tenant-collection-id))))))diff --git a/enterprise/backend/src/metabase_enterprise/transform_testing/db.clj b/enterprise/backend/src/metabase_enterprise/transform_testing/db.cljindex d99a8ef622f..8fd47881d67 100644--- a/enterprise/backend/src/metabase_enterprise/transform_testing/db.clj+++ b/enterprise/backend/src/metabase_enterprise/transform_testing/db.clj@@ -16,9 +16,9 @@transform-id (assoc :where [:= :transform_id transform-id]))))(mu/defn transform-test :- [:maybe ::transform-testing.schema/transform-test]- "The TransformTest with `id`, or nil."+ "The ::transform-testing.schema/transform-test with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/TransformTest :id id))+ (t2/select-one :model/TransformTest :id [:auto/param id]))(mu/defn insert-transform-test! :- ::transform-testing.schema/transform-test"Insert the TransformTest `transform-test` and return the inserted instance."@@ -112,11 +112,6 @@[transform-id :- ::lib.schema.id/transform](t2/delete! :model/TransformTest :transform_id transform-id))-(mu/defn transform- "The Transform with `transform-id`, or nil."- [transform-id :- ::lib.schema.id/transform]- (t2/select-one :model/Transform :id transform-id))-(mu/defn database-exists?"Whether a Database with `database-id` exists."[database-id :- ::lib.schema.id/database]diff --git a/enterprise/backend/src/metabase_enterprise/transform_testing/runner.clj b/enterprise/backend/src/metabase_enterprise/transform_testing/runner.cljindex 64da975f4d9..a187dc4ed24 100644--- a/enterprise/backend/src/metabase_enterprise/transform_testing/runner.clj+++ b/enterprise/backend/src/metabase_enterprise/transform_testing/runner.clj@@ -37,6 +37,7 @@[metabase.lib.schema.metadata :as lib.schema.metadata][metabase.sql-parsing.core :as sql-parsing][metabase.transforms-base.util :as transforms-base.u]+ [metabase.transforms.db :as transforms.db][metabase.util.i18n :refer [tru]][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]))@@ -119,7 +120,7 @@(defn- testable-transform"The transform `transform-id` names, if it is one a test can run."[transform-id]- (let [transform (api/check-404 (transform-testing.db/transform transform-id))]+ (let [transform (api/check-404 (transforms.db/transform transform-id))](when-not (transforms-base.u/query-transform? transform)(throw (transform-testing.errors/ex::transform-testing.errors/unsupported-transformdiff --git a/enterprise/backend/src/metabase_enterprise/transforms_inspector/context.clj b/enterprise/backend/src/metabase_enterprise/transforms_inspector/context.cljindex cb1706ce1c5..6dc08d4e9b9 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_inspector/context.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_inspector/context.clj@@ -19,7 +19,8 @@[metabase.util.honey-sql-2 :as h2x][metabase.util.log :as log][metabase.util.malli :as mu]- [metabase.util.malli.registry :as mr]))+ [metabase.util.malli.registry :as mr]+ [metabase.warehouses.db :as warehouses.db]))(set! *warn-on-reflection* true)@@ -56,7 +57,7 @@transforms-base.u/massage-sql-queryqp.preprocess/preprocess)db-id (transforms-base.u/transform-source-database transform)- driver (keyword (transforms-inspector.db/database-engine db-id))+ driver (keyword (:engine (warehouses.db/database db-id)))deps (driver/native-query-deps driver query)table-ids (keep :table deps)](table-ids->source-info table-ids))@@ -321,7 +322,7 @@:target target-info:db-id db-id:driver (or (:driver query-info)- (keyword (transforms-inspector.db/database-engine db-id)))+ (keyword (:engine (warehouses.db/database db-id)))):from-table-id (:from-table-id query-info):has-joins? (boolean (seq join-structure)):visited-fields (:visited-fields query-info)diff --git a/enterprise/backend/src/metabase_enterprise/transforms_inspector/db.clj b/enterprise/backend/src/metabase_enterprise/transforms_inspector/db.cljindex 1c0c94f98c5..64b24037406 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_inspector/db.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_inspector/db.clj@@ -12,11 +12,6 @@[table-ids :- [:or [:set ::lib.schema.id/table] [:sequential ::lib.schema.id/table]]](t2/select [:model/Table [:id :table-id] [:name :table-name] :schema [:db_id :db-id]] :id [:in table-ids] {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn database-engine- "The engine of the Database with `database-id`."- [database-id :- ::lib.schema.id/database]- (t2/select-one-fn :engine :model/Database :id database-id))-(mu/defn active-fields-for-table"The active Fields of the Table with `table-id`."[table-id :- ::lib.schema.id/table]diff --git a/enterprise/backend/src/metabase_enterprise/transforms_inspector/query_analysis.clj b/enterprise/backend/src/metabase_enterprise/transforms_inspector/query_analysis.cljindex 56d46f840fc..49bd4278a30 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_inspector/query_analysis.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_inspector/query_analysis.clj@@ -12,7 +12,6 @@;; TODO (Bronsa 16/02/26): get rid of macaw[macaw.ast :as macaw.ast][macaw.core :as macaw]- [metabase-enterprise.transforms-inspector.db :as transforms-inspector.db][metabase.driver :as driver][metabase.driver.sql.normalize :as sql.normalize][metabase.lib.core :as lib]@@ -21,7 +20,8 @@[metabase.transforms-base.util :as transforms-base.u][metabase.util :as u][metabase.util.honey-sql-2 :as h2x]- [metabase.util.log :as log]))+ [metabase.util.log :as log]+ [metabase.warehouses.db :as warehouses.db]))(set! *warn-on-reflection* true)@@ -216,7 +216,7 @@qp.preprocess/preprocess)sql (lib/raw-native-query native-query)db-id (transforms-base.u/transform-source-database transform)- driver (keyword (transforms-inspector.db/database-engine db-id))+ driver (keyword (:engine (warehouses.db/database db-id)))parsed (macaw-parsed-query sql driver)ast (macaw.ast/->ast parsed {:with-instance? false})](when (and ast (= (:type ast) :macaw.ast/select))diff --git a/enterprise/backend/src/metabase_enterprise/transforms_python/db.clj b/enterprise/backend/src/metabase_enterprise/transforms_python/db.cljindex 7b3220bf549..d90f70ec78f 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_python/db.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/db.clj@@ -2,6 +2,7 @@"Application database queries for the transforms-python module. Every function here is a direct Toucan 2 call with noadditional logic, so the rest of the module only touches `toucan2.core` for model definitions and hydration methods."(:require+ [metabase-enterprise.transforms-python.schema :as transforms-python.schema][metabase.app-db.core :as mdb][metabase.lib.schema.id :as lib.schema.id][metabase.util.malli :as mu]@@ -14,26 +15,16 @@[table-ids :- [:sequential ::lib.schema.id/table]](t2/select-fn-set :db_id [:model/Table :db_id] :id [:in table-ids] {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(mu/defn table-database-id- "The Database ID of the raw table row with `table-id`."- [table-id :- ::lib.schema.id/table]- (t2/select-one-fn :db_id (t2/table-name :model/Table) :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))--(mu/defn database-engine- "The engine of the Database with `database-id`."- [database-id :- ::lib.schema.id/database]- (t2/select-one-fn :engine :model/Database database-id))-(mu/defn update-run-message!"Set the message of the TransformRun with `run-id`."[run-id :- ms/PositiveIntmessage :- [:maybe :string]](t2/update! :model/TransformRun :id run-id {:message message}))-(mu/defn python-library- "The PythonLibrary with `library-id`, or nil."+(mu/defn python-library :- [:maybe ::transforms-python.schema/python-library]+ "The ::transforms-python.schema/python-library with `library-id`, or nil."[library-id :- ms/PositiveInt]- (t2/select-one :model/PythonLibrary library-id))+ (t2/select-one :model/PythonLibrary :id [:auto/param library-id]))(mu/defn python-library-by-path"The PythonLibrary at `path`, or nil."diff --git a/enterprise/backend/src/metabase_enterprise/transforms_python/python_runner.clj b/enterprise/backend/src/metabase_enterprise/transforms_python/python_runner.cljindex de46a2e34e7..26a1896708e 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_python/python_runner.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/python_runner.clj@@ -21,7 +21,9 @@[metabase.util.i18n :as i18n][metabase.util.json :as json][metabase.util.log :as log]- [metabase.util.malli :as mu])+ [metabase.util.malli :as mu]+ [metabase.warehouse-schema.db :as warehouse-schema.db]+ [metabase.warehouses.db :as warehouses.db])(:import(clojure.lang PersistentQueue)(java.io BufferedWriter File InputStream OutputStream OutputStreamWriter)@@ -290,7 +292,7 @@(defn- build-table-query"Build a mbql query for table, might add a proper filter for incremental transforms."[table-id source-incremental-strategy source-range-params limit]- (let [db-id (transforms-python.db/table-database-id table-id)+ (let [db-id (:db_id (warehouse-schema.db/table table-id))metadata-provider (lib-be/application-database-metadata-provider db-id)table-metadata (lib.metadata/table metadata-provider table-id)](cond-> (-> (lib/query metadata-provider table-metadata)@@ -318,8 +320,8 @@(let [tmp-data-file (File/createTempFile data-path "")tmp-meta-file (File/createTempFile manifest-path "")](try- (let [db-id (transforms-python.db/table-database-id table_id)- driver (transforms-python.db/database-engine db-id)+ (let [db-id (:db_id (warehouse-schema.db/table table_id))+ driver (:engine (warehouses.db/database db-id))fields-meta (fields-metadata driver table_id)manifest (generate-manifest table_id fields-meta)](transforms.instrumentation/with-stage-timing [run-id [:export :dwh-to-file]]diff --git a/enterprise/backend/src/metabase_enterprise/upload_management/api.clj b/enterprise/backend/src/metabase_enterprise/upload_management/api.cljindex aa9ace26508..d0282bd3763 100644--- a/enterprise/backend/src/metabase_enterprise/upload_management/api.clj+++ b/enterprise/backend/src/metabase_enterprise/upload_management/api.clj@@ -9,7 +9,8 @@[metabase.premium-features.core :as premium-features][metabase.upload.core :as upload][metabase.util.i18n :refer [tru]]- [metabase.util.malli.schema :as ms]))+ [metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db]))(defn- attached-dwh-tables"Used for adding attached DWH tables to the list of tables visible to the user. In practice these are to manage@@ -49,7 +50,7 @@[:archive-cards {:optional true} [:maybe {:default false} ms/BooleanValue]]]](try;; To be idempotent, we do not check whether the table has already been deactivated.- (let [table (api/check-404 (upload-management.db/table id))+ (let [table (api/check-404 (warehouse-schema.db/table id))result (upload/delete-upload! table :archive-cards? archive-cards)]{:status 200:body (= :done result)})diff --git a/enterprise/backend/src/metabase_enterprise/upload_management/db.clj b/enterprise/backend/src/metabase_enterprise/upload_management/db.cljindex 6666afe3347..7a208f1f053 100644--- a/enterprise/backend/src/metabase_enterprise/upload_management/db.clj+++ b/enterprise/backend/src/metabase_enterprise/upload_management/db.clj@@ -22,8 +22,3 @@[](t2/select :model/Table :active true :is_upload true {:from [(warehouse-schema-overlay/table-query)]:order-by [[:name :asc]]}))--(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.cljindex 512a18bfa9c..216b1ec7219 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.clj@@ -12,6 +12,7 @@[metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.query-processor :as qp][metabase.query-processor.db :as qp.db][metabase.test :as mt]@@ -644,8 +645,8 @@(mt/with-temp [:model/Card {card-id :id} {:dataset_query (table-query :venues)}](run-jobs!)(reprocess! card-id)- (let [card (mt/original-fn #'dependencies.db/card)]- (mt/with-dynamic-fn-redefs [dependencies.db/card (fn [id] (assoc (card id) :result_metadata nil))]+ (let [card (mt/original-fn #'queries.db/card)]+ (mt/with-dynamic-fn-redefs [queries.db/card (fn [id] (assoc (card id) :result_metadata nil))](do-with-inference (fn [infer query card] (rename-column (infer query card) "NAME" "Changed"))rederive!)))(is (= "Changed" (:display_name (column card-id "NAME"))))diff --git a/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.clj b/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.cljindex fd1751a22b1..68630098046 100644--- a/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.clj+++ b/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.clj@@ -6,6 +6,7 @@[metabase.lib.metadata :as lib.metadata][metabase.test :as mt][metabase.util.json :as json]+ [metabase.util.malli :as mu][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -319,7 +320,7 @@(t2/query-one {:update :transform:set {:source "{\"type\":\"query\",\"query\":{}}"}:where [:= :id transform-id]})- (is (nil? (replacement.field-refs/upgrade-field-refs! [:transform transform-id])))))))+ (is (nil? (mu/disable-enforcement (replacement.field-refs/upgrade-field-refs! [:transform transform-id]))))))))(deftest transform-upgrade-field-refs!-no-changes-test(testing "should not update a transform when there are no changes"diff --git a/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.clj b/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.cljindex ad757017ed0..bd5bae7ecfe 100644--- a/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.clj+++ b/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.clj@@ -11,6 +11,7 @@[metabase.lib.metadata :as lib.metadata][metabase.test :as mt][metabase.util.json :as json]+ [metabase.util.malli :as mu][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -179,9 +180,10 @@(t2/query-one {:update :transform:set {:source "{\"type\":\"query\",\"query\":{}}"}:where [:= :id transform-id]})- (is (nil? (replacement.source-swap/swap-source! [:transform transform-id]- [:table (mt/id :orders)]- [:table (mt/id :reviews)])))))))))+ (is (nil? (mu/disable-enforcement+ (replacement.source-swap/swap-source! [:transform transform-id]+ [:table (mt/id :orders)]+ [:table (mt/id :reviews)]))))))))));;; ------------------------------------------------- Segment ----------------------------------------------------------diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.cljindex a37afcfa56c..a96cd05884d 100644--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj@@ -2668,7 +2668,7 @@;; Uncomment to regenerate baseline:;; (round-trip-test/add-to-baseline!)(testing "custom viz plugin extraction"- (let [ser (serdes/extract-one "CustomVizPlugin" {} (t2/select-one :model/CustomVizPlugin :id plugin-id))]+ (let [ser (serdes/extract-one "CustomVizPlugin" {} (t2/select-one [:model/CustomVizPlugin :*] :id plugin-id))](is (=? {:serdes/meta [{:model "CustomVizPlugin":id "test-plugin"}]:display_name "Test Plugin"diff --git a/enterprise/backend/test/metabase_enterprise/transform_testing/api_e2e_test.clj b/enterprise/backend/test/metabase_enterprise/transform_testing/api_e2e_test.cljindex dd28cf1ac08..525540bf3a7 100644--- a/enterprise/backend/test/metabase_enterprise/transform_testing/api_e2e_test.clj+++ b/enterprise/backend/test/metabase_enterprise/transform_testing/api_e2e_test.clj@@ -108,7 +108,7 @@(with-transforms-enabled #{:transforms-basic :transforms-python :transforms-testing}(testing "422 — the environment prevents a run: not a query transform"(mt/with-temp [:model/Transform {transform-id :id}- {:source {:type "python" :source-database (mt/id)}}+ {:source {:type "python" :source-database (mt/id) :source-tables [] :body "def transform():\n pass"}}:model/TransformTest {test-id :id} {:transform_id transform-id}](let [response (mt/user-http-request :crowberto :post 422(format "ee/transform-test/%d/run" test-id))]diff --git a/enterprise/backend/test/metabase_enterprise/transforms/core_test.clj b/enterprise/backend/test/metabase_enterprise/transforms/core_test.cljindex 13a059e68f4..cfe4865f289 100644--- a/enterprise/backend/test/metabase_enterprise/transforms/core_test.clj+++ b/enterprise/backend/test/metabase_enterprise/transforms/core_test.clj@@ -50,7 +50,9 @@:database (mt/id)}}:model/Transform {python-id :id}{:source {:type "python"- :source-database (mt/id)}+ :source-database (mt/id)+ :source-tables []+ :body "def transform():\n pass"}:target {:type "table":name (str "test_python_" (random-uuid)):database (mt/id)}}]diff --git a/src/metabase/actions/actions.clj b/src/metabase/actions/actions.cljindex 793446c4b1a..8144b83821d 100644--- a/src/metabase/actions/actions.clj+++ b/src/metabase/actions/actions.clj@@ -29,6 +29,7 @@[metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][methodical.core :as methodical])(:import(clojure.lang ExceptionInfo)))@@ -256,7 +257,7 @@"Uses cache to prevent redundant look-ups with an action call chain."[table-id](assert table-id "Id cannot be nil")- (cached-database (cached-value [:table-by-db-ids table-id] #(actions.db/table-database-id table-id))))+ (cached-database (cached-value [:table-by-db-ids table-id] #(:db_id (warehouse-schema.db/table table-id)))))(mu/defn- check-permissions[policy :- :keyworddiff --git a/src/metabase/actions/args.clj b/src/metabase/actions/args.cljindex 65832617001..93a396bb1fa 100644--- a/src/metabase/actions/args.clj+++ b/src/metabase/actions/args.clj@@ -1,6 +1,5 @@(ns ^:instrument/always metabase.actions.args(:require- [metabase.actions.db :as actions.db][metabase.actions.hierarchy :as actions.hierarchy];; legacy usage, do not use this in new code^{:clj-kondo/ignore [:discouraged-namespace]} [metabase.legacy-mbql.normalize :as mbql.normalize]@@ -8,7 +7,8 @@[metabase.lib.schema.parameter :as lib.schema.parameter][metabase.util :as u][metabase.util.log :as log]- [metabase.util.malli.registry :as mr]))+ [metabase.util.malli.registry :as mr]+ [metabase.warehouse-schema.db :as warehouse-schema.db]))(defmulti action-arg-map-schema"Return the appropriate malli schema to use to validate the arg map passed to [[perform-action!*]].@@ -177,7 +177,7 @@(when (seq row-arg)(log/warn ":arg is deprecated, use :row instead"));; TODO it would be nice to use cached-database-via-table-id here, but need to solve circular dependency.- {:database (or database (when table-id (actions.db/table-database-id table-id)))+ {:database (or database (when table-id (:db_id (warehouse-schema.db/table table-id)))):table-id table-id:row (update-keys (or row row-arg) u/qualified-name)})diff --git a/src/metabase/actions/db.clj b/src/metabase/actions/db.cljindex 0067cffe317..09de96c712c 100644--- a/src/metabase/actions/db.clj+++ b/src/metabase/actions/db.clj@@ -10,6 +10,11 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))+(mu/defn action :- [:maybe ::actions.schema/action]+ "The ::actions.schema/action with `action-id`, or nil."+ [action-id :- ::lib.schema.id/action]+ (t2/select-one :model/Action :id [:auto/param action-id]))+(defn- action-database-joins"The joins from `action` to the Database `db` of its query, or for an implicit action of its model Card or its table."[]@@ -28,21 +33,6 @@:left-join (action-database-joins):where [:and [:= :action.id action-id] [:not= :db.id nil]]}))-(mu/defn table-database-id- "The Database id of the Table with `table-id`, or nil."- [table-id :- ::lib.schema.id/table]- (t2/select-one-fn :db_id [:model/Table :db_id] :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))--(mu/defn card-query- "The query of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :dataset_query :model/Card :id card-id))--(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(mu/defn cards"The Cards with `card-ids`."[card-ids :- [:set ::lib.schema.id/card]]@@ -53,16 +43,6 @@[card-ids :- [:sequential ::lib.schema.id/card]](t2/select-pk->fn identity :model/Card :id [:in card-ids]))-(mu/defn card-type- "The type of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :type [:model/Card :type] :id card-id))--(mu/defn card-collection-id- "The Collection id of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :collection_id [:model/Card :collection_id] :id card-id))-(mu/defn card-ids-outside-collection"Among `card-ids`, the IDs of the Cards that are not in the Collection with `collection-id`."[card-ids :- [:set ::lib.schema.id/card]@@ -76,11 +56,6 @@[collection-id :- ::lib.schema.id/collection](t2/exists? :model/Collection :id collection-id))-(mu/defn collection-namespace- "The namespace of the Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one-fn :namespace [:model/Collection :namespace] :id collection-id))-(mu/defn collection-namespace-with-entity-id"The namespace of the Collection with `entity-id`, or nil."[entity-id :- :string]@@ -91,47 +66,11 @@[collection-id :- ::lib.schema.id/collection](t2/exists? :model/Collection :id collection-id :archived false))-(mu/defn action-collection-id- "The Collection id of the Action with `action-id`, or nil."- [action-id :- ::lib.schema.id/action]- (t2/select-one-fn :collection_id [:model/Action :collection_id] :id action-id))--(mu/defn action-model-id- "The model Card id of the Action with `action-id`, or nil."- [action-id :- ::lib.schema.id/action]- (t2/select-one-fn :model_id [:model/Action :model_id] :id action-id))--(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn tables"The Tables with `table-ids`."[table-ids :- [:sequential ::lib.schema.id/table]](t2/select :model/Table :id [:in table-ids] {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))--(mu/defn dashcard-in-dashboard- "The DashboardCard with `dashcard-id` on the Dashboard with `dashboard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard- dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/DashboardCard :id dashcard-id :dashboard_id dashboard-id))--(mu/defn dashcard-dashboard-id- "The `:dashboard_id` of the DashboardCard with `dashcard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard]- (t2/select-one-fn :dashboard_id [:model/DashboardCard :dashboard_id] dashcard-id))--(mu/defn dashcard-action-id- "The Action id of the DashboardCard with `dashcard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard]- (t2/select-one-fn :action_id :model/DashboardCard :id dashcard-id))-(mu/defn delete-dashcards-for-action!"Delete the DashboardCards of the Action with `action-id`, returning the number deleted."[action-id :- ::lib.schema.id/action]@@ -200,12 +139,6 @@[action-id :- ::lib.schema.id/action](t2/select-one-fn :table_id [:model/ImplicitAction :table_id] :action_id action-id))-(mu/defn table-published? :- :boolean- "Whether the Table with `table-id` is published to the Library."- [table-id :- ::lib.schema.id/table]- (some? (t2/select-one-fn :id [:model/Table :id] :id table-id :is_published true- {:from [(warehouse-schema-overlay/table-query)]})))-(mu/defn tables-with-fields"The Tables with `table-ids`, with their Fields hydrated."[table-ids :- [:sequential ::lib.schema.id/table]]@@ -257,11 +190,6 @@;; dependency-free namespace that exists for exactly this.(t2/select-one (queries.card-schema/selection [:collection_id :database_id :display]) :id card-id))-(mu/defn dashboard-collection-id- "The Collection id of the Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one-fn :collection_id [:model/Dashboard :collection_id] dashboard-id))-(mu/defn destination-database-exists-for-router?"Whether the Database with `database-id` has routing destinations."[database-id :- ::lib.schema.id/database]@@ -276,3 +204,24 @@"Whether the Database with `database-id` has a Table whose writability is unknown."[database-id :- ::lib.schema.id/database](t2/exists? :model/Table :db_id database-id :is_writable nil {:from [(warehouse-schema-overlay/table-query)]}))++(mu/defn dashcard-in-dashboard+ "The DashboardCard with `dashcard-id` on the Dashboard with `dashboard-id`, or nil."+ [dashcard-id :- ::lib.schema.id/dashcard+ dashboard-id :- ::lib.schema.id/dashboard]+ (t2/select-one :model/DashboardCard :id [:auto/param dashcard-id] :dashboard_id [:auto/param dashboard-id]))++(mu/defn dashcard-dashboard-id+ "The `:dashboard_id` of the DashboardCard with `dashcard-id`, or nil."+ [dashcard-id :- ::lib.schema.id/dashcard]+ (t2/select-one-fn :dashboard_id [:model/DashboardCard :dashboard_id] :id [:auto/param dashcard-id]))++(mu/defn dashcard-action-id+ "The Action id of the DashboardCard with `dashcard-id`, or nil."+ [dashcard-id :- ::lib.schema.id/dashcard]+ (t2/select-one-fn :action_id :model/DashboardCard :id [:auto/param dashcard-id]))++(mu/defn dashboard-collection-id+ "The Collection id of the Dashboard with `dashboard-id`, or nil."+ [dashboard-id :- ::lib.schema.id/dashboard]+ (t2/select-one-fn :collection_id [:model/Dashboard :collection_id] :id [:auto/param dashboard-id]))diff --git a/src/metabase/actions/execution.clj b/src/metabase/actions/execution.cljindex e59065797a1..24dfb36efa3 100644--- a/src/metabase/actions/execution.clj+++ b/src/metabase/actions/execution.clj@@ -18,6 +18,7 @@[metabase.model-persistence.core :as model-persistence][metabase.models.interface :as mi][metabase.parameters.schema :as parameters.schema]+ [metabase.queries.db :as queries.db][metabase.queries.models.query :as query][metabase.query-processor.card :as qp.card][metabase.query-processor.core :as qp]@@ -94,7 +95,7 @@"The Table, with its Fields, that the implicit `action` writes to: its model's source Table when it has a model."[{model-id :model_id, table-id :table_id} :- ::actions.schema/action](let [table-id (if model-id- (:table-id (query/query->database-and-table-ids (actions.db/card-query model-id)))+ (:table-id (query/query->database-and-table-ids (:dataset_query (queries.db/card model-id))))table-id)](first (when table-id (actions.db/tables-with-fields [table-id])))))@@ -301,7 +302,7 @@(qp/process-query(qp/userland-query(if-let [model-id (:model_id action)]- (qp.card/query-for-card (actions.db/card model-id) prefetch-parameters nil nil)+ (qp.card/query-for-card (queries.db/card model-id) prefetch-parameters nil nil)query)info)));; only expose values for fields that are not hiddendiff --git a/src/metabase/actions/models.clj b/src/metabase/actions/models.cljindex d66dbcf5bba..af8fbe57f92 100644--- a/src/metabase/actions/models.clj+++ b/src/metabase/actions/models.clj@@ -6,6 +6,7 @@[metabase.actions.db :as actions.db][metabase.actions.schema :as actions.schema][metabase.api.common :as api]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.lib-be.core :as lib-be][metabase.lib.core :as lib]@@ -15,6 +16,7 @@[metabase.parameters.core :as parameters][metabase.permissions.core :as perms][metabase.public-sharing.core :as public-sharing]+ [metabase.queries.db :as queries.db][metabase.queries.models.query :as query][metabase.remote-sync.core :as remote-sync][metabase.search.core :as search]@@ -22,6 +24,8 @@[metabase.util.i18n :refer [tru]][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db]+ [metabase.warehouses.db :as warehouses.db][methodical.core :as methodical][toucan2.core :as t2][toucan2.tools.hydrate :as t2.hydrate]))@@ -98,7 +102,7 @@(defn- check-implicit-action-model"Throws a 400 unless the Card with `model-id` is a model."[model-id]- (when-not (= (actions.db/card-type model-id) :model)+ (when-not (= (:type (queries.db/card model-id)) :model)(throw (ex-info (tru "Actions must be made with models, not cards."){:status-code 400}))))@@ -107,7 +111,7 @@[{model-id :model_id, :as action}](when (and (implicit? action)model-id- (not (query/supports-implicit-actions? (actions.db/card-query model-id))))+ (not (query/supports-implicit-actions? (:dataset_query (queries.db/card model-id)))))(throw (ex-info (tru "Implicit actions are not supported for models with clauses."){:status-code 400}))))@@ -124,7 +128,7 @@(defn- collection-namespace"The namespace of the Collection with `collection-id` as a keyword, or nil."[collection-id]- (some-> collection-id actions.db/collection-namespace keyword))+ (some-> collection-id collections.db/collection :namespace keyword))(defn- check-model-less-collection"Throws a 400 unless an Action without a model is in the data actions root or a data actions or data app Collection."@@ -151,7 +155,7 @@(defn- set-model-collection"`action` with the `:collection_id` of its model Card; throws a 400 when it is given another Collection."[{model-id :model_id, collection-id :collection_id, :as action}]- (let [model-collection-id (actions.db/card-collection-id model-id)]+ (let [model-collection-id (:collection_id (queries.db/card model-id))](when (and (some? collection-id) (not= collection-id model-collection-id))(throw (model-collection-error)))(assoc action :collection_id model-collection-id)))@@ -206,7 +210,7 @@(some? table-id)(not mi/*deserializing?*)(perms/data-app-collection? collection-id)- (not (actions.db/table-published? table-id)))+ (not (:is_published (warehouse-schema.db/table table-id))))(throw (data-app-action-error (tru "An implicit action in a data app''s collection can write only to a table published to the Library.")))))(t2/define-before-insert :model/Action@@ -225,7 +229,7 @@(throw (ex-info (tru "An action''s model can''t be changed.") {:status-code 400})))(when (and model-id(changed? :collection_id)- (not= (:collection_id action) (actions.db/card-collection-id model-id)))+ (not= (:collection_id action) (:collection_id (queries.db/card model-id))))(throw (model-collection-error)))(u/prog1 (public-sharing/add-public-uuid-prefix-if-changed action)(when (and (implicit? action) model-id (changed? :type))@@ -251,19 +255,19 @@(t2/define-before-insert :model/QueryAction[query-action](u/prog1 (set-query-database query-action)- (check-data-app-action-query (actions.db/action-collection-id (:action_id <>)) (:dataset_query <>))))+ (check-data-app-action-query (:collection_id (actions.db/action (:action_id <>))) (:dataset_query <>))))(t2/define-before-update :model/QueryAction[query-action](u/prog1 (set-query-database query-action)(when (contains? (t2/changes query-action) :dataset_query)- (check-data-app-action-query (actions.db/action-collection-id (:action_id <>)) (:dataset_query <>)))))+ (check-data-app-action-query (:collection_id (actions.db/action (:action_id <>))) (:dataset_query <>)))))(defn- check-implicit-action-table"Throws a 400 unless `implicit-action` has a Table exactly when its Action has no model, as an action of a model writesto the table its model reads when it runs."[{table-id :table_id, action-id :action_id}]- (if (actions.db/action-model-id action-id)+ (if (:model_id (actions.db/action action-id))(when (some? table-id)(throw (ex-info (tru "An action of a model writes to the model''s table, so it can''t be given one."){:status-code 400})))@@ -290,7 +294,7 @@the action is in a data app's collection."[{table-id :table_id, action-id :action_id}](when table-id- (check-data-app-action-table (actions.db/action-collection-id action-id) table-id)))+ (check-data-app-action-table (:collection_id (actions.db/action action-id)) table-id)))(t2/define-before-update :model/ImplicitAction[implicit-action]@@ -312,7 +316,8 @@:implicit [(if model-id(:database_id (actions.db/card-scope-columns model-id))(some-> (or table-id (some-> action-id actions.db/implicit-action-table-id))- actions.db/table-database-id))]+ warehouse-schema.db/table+ :db_id))]:query [(:database query)][]))@@ -321,7 +326,7 @@[action](doseq [database-id (action-database-ids action):when database-id]- (actions/check-actions-enabled-for-database (actions.db/database database-id))))+ (actions/check-actions-enabled-for-database (warehouses.db/database database-id))))(defn- effective-collection-id"The id of the Collection `action` goes in, its model's when it has one; throws a 404 when either does not exist."@@ -778,7 +783,7 @@(serdes/mbql-deps true dataset_query)))))))(defmethod serdes/descendants "Action" [_model-name id _opts]- (when-let [model-id (actions.db/action-model-id id)]+ (when-let [model-id (:model_id (actions.db/action id))]{["Card" model-id] {"Action" id}}));;;; ------------------------------------------------- Search ----------------------------------------------------------diff --git a/src/metabase/actions/scope.clj b/src/metabase/actions/scope.cljindex 243c158ecd7..31ae5244456 100644--- a/src/metabase/actions/scope.clj+++ b/src/metabase/actions/scope.clj@@ -3,7 +3,8 @@[metabase.actions.db :as actions.db][metabase.actions.types :as types][metabase.lib.core :as lib]- [metabase.util.malli :as mu]))+ [metabase.util.malli :as mu]+ [metabase.warehouse-schema.db :as warehouse-schema.db]));; TODO Perhaps we will prefer the FE just sending this explicitly instead?;; For now, it is not doing this, so we infer it.@@ -45,7 +46,7 @@(:model-id scope) (hydrate-from-card (:model-id scope))(:table-id scope)- (update :database-id #(or % (actions.db/table-database-id (:table-id scope)) missing-id))))+ (update :database-id #(or % (:db_id (warehouse-schema.db/table (:table-id scope))) missing-id))))(defn- strip-nils"Remove any keys corresponding to nil values from the given map."diff --git a/src/metabase/actions_rest/db.clj b/src/metabase/actions_rest/db.cljindex 44f484c1f1b..5a3a6eb7c43 100644--- a/src/metabase/actions_rest/db.clj+++ b/src/metabase/actions_rest/db.clj@@ -45,11 +45,6 @@[action-id :- ::lib.schema.id/action](t2/delete! :model/Action :id action-id))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))-(mu/defn set-action-public-uuid!"Set the public uuid of the Action with `action-id` and the User who made it public."[action-id :- ::lib.schema.id/actiondiff --git a/src/metabase/activity_feed/api.clj b/src/metabase/activity_feed/api.cljindex 1e1204f7a58..fbb4ea135e5 100644--- a/src/metabase/activity_feed/api.clj+++ b/src/metabase/activity_feed/api.clj@@ -5,9 +5,14 @@[metabase.activity-feed.models.recent-views :as recent-views][metabase.api.common :as api :refer [*current-user-id*]][metabase.api.macros :as api.macros]+ [metabase.collections.db :as collections.db]+ [metabase.dashboards.db :as dashboards.db]+ [metabase.documents.db :as documents.db][metabase.models.interface :as mi]+ [metabase.queries.db :as queries.db][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][toucan2.core :as t2]))(defn- models-query@@ -111,11 +116,11 @@:model/Collection (activity-feed.db/collection-exists? model-id):model/Document (activity-feed.db/document-exists? model-id))entity (fn [] (case model-type- :model/Card (activity-feed.db/card model-id)- :model/Dashboard (activity-feed.db/dashboard model-id)- :model/Table (activity-feed.db/table model-id)- :model/Collection (activity-feed.db/collection model-id)- :model/Document (activity-feed.db/document model-id)))]+ :model/Card (queries.db/card model-id)+ :model/Dashboard (dashboards.db/dashboard model-id)+ :model/Table (warehouse-schema.db/table model-id)+ :model/Collection (collections.db/collection model-id)+ :model/Document (documents.db/document model-id)))](when-not exists?(throw (ex-info "Model not found" {:model model :model_id model-id})))(api/read-check (entity))@@ -133,7 +138,7 @@in the last 24 hours."[](if-let [dashboard-id (recent-views/most-recently-viewed-dashboard-id *current-user-id*)]- (let [dashboard (-> (activity-feed.db/dashboard dashboard-id)+ (let [dashboard (-> (dashboards.db/dashboard dashboard-id)api/check-404(t2/hydrate [:collection :is_personal]))](if (mi/can-read? dashboard)diff --git a/src/metabase/activity_feed/db.clj b/src/metabase/activity_feed/db.cljindex f8b6429e11c..df7999dc0b3 100644--- a/src/metabase/activity_feed/db.clj+++ b/src/metabase/activity_feed/db.clj@@ -113,36 +113,6 @@[id :- ms/PositiveInt](t2/exists? :model/Document :id id))-(mu/defn card- "The Card with `id`, or nil."- [id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id id))--(mu/defn table- "The Table with `id`, or nil."- [id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id id {:from [(warehouse-schema-overlay/table-query)]}))--(mu/defn collection- "The Collection with `id`, or nil."- [id :- ::lib.schema.id/collection]- (t2/select-one :model/Collection :id id))--(mu/defn document- "The Document with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/Document :id id))--(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id dashboard-id))--(mu/defn card-document-id- "The Document id of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :document_id :model/Card :id card-id))-(mu/defn recent-views-for-user-context"The RecentViews of the User with `user-id` in `context`, newest first."[user-id :- ::lib.schema.id/userdiff --git a/src/metabase/activity_feed/events/recent_views.clj b/src/metabase/activity_feed/events/recent_views.cljindex e2379eeb81a..b77d55d91e7 100644--- a/src/metabase/activity_feed/events/recent_views.clj+++ b/src/metabase/activity_feed/events/recent_views.clj@@ -1,10 +1,10 @@(ns metabase.activity-feed.events.recent-views"This namespace is responsible for subscribing to events which should update the recent views for a user."(:require- [metabase.activity-feed.db :as activity-feed.db][metabase.activity-feed.models.recent-views :as recent-views][metabase.api.common :as api][metabase.events.core :as events]+ [metabase.queries.db :as queries.db][metabase.util :as u][metabase.util.log :as log][methodical.core :as m]@@ -52,7 +52,7 @@;; we don't want to count pinned card views or document cards(when (and user-id(not (#{:collection :dashboard :dashboard-subscription} context))- (not (activity-feed.db/card-document-id card-id)))+ (not (:document_id (queries.db/card card-id))))(recent-views/update-users-recent-views! user-id :model/Card card-id :view)))(catch Throwable e(log/warnf "Failed to process recent_views event %s: %s" topic (ex-message e)))))@@ -78,7 +78,7 @@(let [user-id (or user-id api/*current-user-id*)](when (and user-id(= context :question)- (nil? (activity-feed.db/card-document-id object-id)))+ (nil? (:document_id (queries.db/card object-id))))(try(recent-views/update-users-recent-views! user-id :model/Card object-id :view)(catch Throwable ediff --git a/src/metabase/agent_api/api.clj b/src/metabase/agent_api/api.cljindex 66fca434770..e3f300cfc36 100644--- a/src/metabase/agent_api/api.clj+++ b/src/metabase/agent_api/api.clj@@ -17,8 +17,10 @@[metabase.auth-identity.core :as auth-identity][metabase.channel.urls :as channel.urls][metabase.collections.core :as collections]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.dashboards.autoplace :as autoplace]+ [metabase.dashboards.db :as dashboards.db][metabase.dashboards.models.dashboard :as dashboard][metabase.dashboards.models.dashboard-card :as dashboard-card][metabase.events.core :as events]@@ -35,6 +37,7 @@[metabase.metabot.tools.search :as metabot-search][metabase.metabot.util :as metabot.u][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.query-permissions.core :as query-perms][metabase.query-processor.card :as qp.card][metabase.query-processor.core :as qp]@@ -81,7 +84,7 @@[collection-id](if-not collection-id(:name (collection/root-collection-with-ui-details nil))- (let [coll (agent-api.db/collection-breadcrumb-columns collection-id)+ (let [coll (collections.db/collection collection-id);; `:effective_ancestors` is the app breadcrumb: it leads with the "Our analytics" root and;; drops ancestors the caller can't read. A personal subtree leads with the personal;; collection instead, so drop that root crumb for them.@@ -915,7 +918,7 @@:card-updates card-updates:actor @api/*current-user*:delete-old-dashcards? false})- (update-card-response (agent-api.db/card id))))+ (update-card-response (queries.db/card id))))(mr/def ::create-question-request[:map {:closed true}@@ -1373,6 +1376,13 @@(update :placed conj new-dashcard)(update :added conj new-dashcard)))))+(defn- dashcard-in-dashboard+ "The DashboardCard with `dashcard-id` if it is on the Dashboard with `dashboard-id`, or nil."+ [dashcard-id dashboard-id]+ (let [dashcard (dashboards.db/dashboard-card dashcard-id)]+ (when (= dashboard-id (:dashboard_id dashcard))+ dashcard)))+(defn- apply-dashcard-mutations!"Apply a sequence of LLM-friendly dashcard mutations. Returns {:added [...] :removed [...] :moved [...]}.@@ -1386,7 +1396,7 @@[dashboard-id mutations](let [current (agent-api.db/dashcards dashboard-id);; the dashboard row is the same for every mutation in the batch- dashboard (agent-api.db/dashboard dashboard-id)+ dashboard (dashboards.db/dashboard dashboard-id);; one fetch serves the default tab, per-mutation tab_id validation, and collision groupingtab-ids (agent-api.db/dashboard-tab-ids dashboard-id);; new dashcards land on the first tab, alongside any nil-tab dashcards, which the@@ -1449,7 +1459,7 @@"update_text"(let [existing (api/check-404- (agent-api.db/dashcard-in-dashboard dashcard_id dashboard-id))+ (dashcard-in-dashboard dashcard_id dashboard-id))vs (:visualization_settings existing)display (some-> (get-in vs [:virtual_card :display]) name)](api/check (or (contains? #{"heading" "text"} display)@@ -1464,7 +1474,7 @@"remove"(let [existing (api/check-404- (agent-api.db/dashcard-in-dashboard dashcard_id dashboard-id))]+ (dashcard-in-dashboard dashcard_id dashboard-id))];; Model-level delete also cleans up orphaned inline parameters and pulse cards.(dashboard-card/delete-dashboard-cards! [dashcard_id])(swap! state #(-> %@@ -1473,7 +1483,7 @@"move"(let [existing (api/check-404- (agent-api.db/dashcard-in-dashboard dashcard_id dashboard-id))+ (dashcard-in-dashboard dashcard_id dashboard-id));; A move only makes sense relative to the moved card's own tab: collision checks;; and the move-to-top reflow must not touch cards on other tabs. Compared via;; `effective-tab` so nil-tab dashcards group with the first tab they render on.@@ -1611,7 +1621,7 @@{:object current-dash:user-id api/*current-user-id*:dashcards (:removed result)}))- (let [updated (agent-api.db/dashboard id)]+ (let [updated (dashboards.db/dashboard id)](events/publish-event! :event/dashboard-update{:object updated :user-id api/*current-user-id*}){:id (:id updated)diff --git a/src/metabase/agent_api/db.clj b/src/metabase/agent_api/db.cljindex da7bc14d7ab..0e8de431e08 100644--- a/src/metabase/agent_api/db.clj+++ b/src/metabase/agent_api/db.clj@@ -9,22 +9,6 @@[metabase.util.malli :as mu][toucan2.core :as t2]))-(mu/defn collection-breadcrumb-columns- "The id, name, location, owner, namespace, and archival of the Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one [:model/Collection :id :name :location :personal_owner_id :namespace :archived_directly]- collection-id))--(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))--(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id dashboard-id))-(mu/defn dashboard-tab-names"The id and name of the DashboardTabs of the Dashboard with `dashboard-id`, in position order."[dashboard-id :- ::lib.schema.id/dashboard]@@ -55,12 +39,6 @@[dashboard-id :- ::lib.schema.id/dashboard](t2/select :model/DashboardCard :dashboard_id dashboard-id))-(mu/defn dashcard-in-dashboard- "The DashboardCard with `dashcard-id` on the Dashboard with `dashboard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard- dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/DashboardCard :id dashcard-id :dashboard_id dashboard-id))-(mu/defn update-dashcard!"Apply `changes` to the DashboardCard with `dashcard-id`, returning the number updated."[dashcard-id :- ::lib.schema.id/dashcarddiff --git a/src/metabase/api_keys/db.clj b/src/metabase/api_keys/db.cljindex 402a50c1716..bd5e5c96fb0 100644--- a/src/metabase/api_keys/db.clj+++ b/src/metabase/api_keys/db.clj@@ -28,10 +28,10 @@(:postgres :h2) :desc-nulls-last:mysql :desc)]]}))-(mu/defn api-key- "The ApiKey with `id`, or nil."+(mu/defn api-key :- [:maybe ::api-keys.schema/api-key]+ "The ::api-keys.schema/api-key with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/ApiKey id))+ (t2/select-one :model/ApiKey :id [:auto/param id]))(def ^:private ApiKeyWithGroupId"An ApiKey instance possibly carrying the `::api-keys/group-id` the before-update hook consumes."diff --git a/src/metabase/audit_app/db.clj b/src/metabase/audit_app/db.cljindex 40ed57777ac..650c8cd88b7 100644--- a/src/metabase/audit_app/db.clj+++ b/src/metabase/audit_app/db.clj@@ -6,7 +6,6 @@[metabase.lib.schema.id :as lib.schema.id][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]- [metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))(mu/defn cards@@ -34,11 +33,6 @@[card-id :- ::lib.schema.id/card](t2/select-one [:model/Card :name :description], :id card-id))-(mu/defn table-database-id- "The Database id of the Table with `table-id`, or nil."- [table-id :- ::lib.schema.id/table]- (t2/select-one-fn :db_id :model/Table, :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(mu/defn insert-audit-log!"Insert an AuditLog entry."[topic :- :keyworddiff --git a/src/metabase/audit_app/models/audit_log.clj b/src/metabase/audit_app/models/audit_log.cljindex 53c07b04faf..7133ee28e6f 100644--- a/src/metabase/audit_app/models/audit_log.clj+++ b/src/metabase/audit_app/models/audit_log.clj@@ -14,6 +14,7 @@[metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][methodical.core :as m][steffan-westcott.clj-otel.api.trace.span :as span][toucan2.core :as t2]))@@ -117,7 +118,7 @@[metric _event-type](let [table-id (:table_id metric)db-id (when table-id- (audit-app.db/table-database-id table-id))]+ (:db_id (warehouse-schema.db/table table-id)))](assoc(select-keys metric [:name :description :revision_message]):table_id table-iddiff --git a/src/metabase/auth_identity/db.clj b/src/metabase/auth_identity/db.cljindex c7ae56d517e..28390a606a8 100644--- a/src/metabase/auth_identity/db.clj+++ b/src/metabase/auth_identity/db.clj@@ -22,11 +22,16 @@[:expires_at {:optional true} [:maybe ms/TemporalInstant]][:confirmed_at {:optional true} [:maybe ms/TemporalInstant]]])-(mu/defn auth-identity+(mu/defn auth-identity :- [:maybe ::auth-identity.schema/auth-identity]+ "The ::auth-identity.schema/auth-identity with `auth-identity-id`, or nil."+ [auth-identity-id :- ms/PositiveInt]+ (t2/select-one :model/AuthIdentity :id [:auto/param auth-identity-id]))++(mu/defn auth-identity-for-user-and-provider"The AuthIdentity of the User with `user-id` at `provider`, or nil."[user-id :- ::lib.schema.id/userprovider :- :string]- (t2/select-one :model/AuthIdentity :user_id (long user-id) :provider [:auto/param provider]))+ (t2/select-one :model/AuthIdentity :user_id [:auto/param (long user-id)] :provider [:auto/param provider]))(mu/defn auth-identity-id"The id of the AuthIdentity of the User with `user-id` at `provider`, or nil."@@ -82,11 +87,6 @@:ended_by_user_id ended-by:key_hashed nil}))-(mu/defn user- "The User with `user-id`, or nil."- [user-id :- ::lib.schema.id/user]- (t2/select-one :model/User user-id))-(mu/defn user-by-email"The User whose email matches `email` case-insensitively, or nil."[email :- :string]diff --git a/src/metabase/auth_identity/models/auth_identity.clj b/src/metabase/auth_identity/models/auth_identity.cljindex 35ac3aff61b..bc25cb97085 100644--- a/src/metabase/auth_identity/models/auth_identity.clj+++ b/src/metabase/auth_identity/models/auth_identity.clj@@ -122,7 +122,7 @@(t2/with-transaction [_](let [attrs {:credentials {:plaintext_password password}:expires_at (:expires-at opts)}]- (if-let [pw-auth-identity (auth-identity.db/auth-identity user-id "password")]+ (if-let [pw-auth-identity (auth-identity.db/auth-identity-for-user-and-provider user-id "password")](auth-identity.db/update-auth-identity! (u/the-id pw-auth-identity) attrs)(auth-identity.db/insert-auth-identity! (merge {:user_id user-id, :provider "password"} attrs))))(auth-identity.db/delete-auth-identities! user-id "emailed-secret-password-reset")@@ -133,5 +133,5 @@AuthIdentity (the authoritative store), or nil if they have none. Lets callers include the token in audit eventswithout reading the legacy `core_user.reset_token` column."[user-id :- ms/PositiveInt]- (get-in (auth-identity.db/auth-identity user-id "emailed-secret-password-reset")+ (get-in (auth-identity.db/auth-identity-for-user-and-provider user-id "emailed-secret-password-reset")[:credentials :token_hash]))diff --git a/src/metabase/auth_identity/provider.clj b/src/metabase/auth_identity/provider.cljindex b9db2e78226..e171d63ea92 100644--- a/src/metabase/auth_identity/provider.clj+++ b/src/metabase/auth_identity/provider.clj@@ -64,6 +64,7 @@[metabase.premium-features.core :refer [defenterprise]][metabase.request.schema :as request.schema][metabase.settings.core :as setting]+ [metabase.users.db :as users.db][metabase.users.schema :as users.schema][metabase.util :as u][metabase.util.i18n :refer [deferred-tru]]@@ -429,7 +430,7 @@[{user-id :id}](when (setting/get :send-new-sso-user-admin-email?)(try- (messages/send-user-joined-admin-notification-email! (auth-identity.db/user user-id) :sso-auth? true)+ (messages/send-user-joined-admin-notification-email! (users.db/user user-id) :sso-auth? true)(catch Exception e(log/errorf e "Error sending new SSO user notification to admins for user %d" user-id)))))@@ -510,7 +511,7 @@(auth-identity.db/insert-auth-identity! (cond-> {:user_id (:id <>) :provider (name provider)}(:provider-id user-data) (assoc :provider_id (:provider-id user-data))))(notification/with-skip-sending-notification true- (events/publish-event! :event/user-invited {:object (assoc (auth-identity.db/user (:id <>))+ (events/publish-event! :event/user-invited {:object (assoc (users.db/user (:id <>)):sso_source (name provider))}))))))(defn- create-or-update-user!diff --git a/src/metabase/auth_identity/providers/emailed_secret.clj b/src/metabase/auth_identity/providers/emailed_secret.cljindex 1a592a819c3..60e283b726d 100644--- a/src/metabase/auth_identity/providers/emailed_secret.clj+++ b/src/metabase/auth_identity/providers/emailed_secret.clj@@ -9,6 +9,7 @@[metabase.auth-identity.schema :as auth-identity.schema][metabase.channel.email.messages :as messages][metabase.events.core :as events]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.log :as log][metabase.util.malli :as mu]@@ -108,7 +109,7 @@[user-id :- ms/PositiveInt](u/prog1 (generate-reset-token user-id)(t2/with-transaction [_]- (let [user (auth-identity.db/user user-id)+ (let [user (users.db/user user-id)auth-identity {:user_id user-id:provider "emailed-secret-password-reset":provider_id (:email user)@@ -146,7 +147,7 @@:else(try(if-let [user-id (parse-token-user-id token)]- (if-let [auth-identity (auth-identity.db/auth-identity user-id (name provider))]+ (if-let [auth-identity (auth-identity.db/auth-identity-for-user-and-provider user-id (name provider))](let [verification-result (verify-reset-token token (:credentials auth-identity))](case verification-result:valid@@ -193,7 +194,7 @@(do(if (:last_login user)(events/publish-event! :event/password-reset-successful {:object (assoc user :token (auth-identity/reset-token-hash (:id user)))})- (messages/send-user-joined-admin-notification-email! (auth-identity.db/user (:id user))))+ (messages/send-user-joined-admin-notification-email! (users.db/user (:id user))));; the person resetting proved they own the account, so they are who ends its sessions(auth-identity/set-password! (:id user) password {:ended-by (:id user)});; The session cannot belong to the reset identity: `set-password!` has just deleted it, and its `expires_at` isdiff --git a/src/metabase/auth_identity/providers/password.clj b/src/metabase/auth_identity/providers/password.cljindex d61e1c26db3..077ab30c078 100644--- a/src/metabase/auth_identity/providers/password.clj+++ b/src/metabase/auth_identity/providers/password.clj@@ -42,7 +42,7 @@"Find an AuthIdentity record by email address."[email :- ms/NonBlankString](when-let [user (auth-identity.db/user-by-email email)]- (auth-identity.db/auth-identity (:id user) "password")))+ (auth-identity.db/auth-identity-for-user-and-provider (:id user) "password")))(methodical/defmethod provider/authenticate :provider/password"Authenticate a user with email and password.diff --git a/src/metabase/cache/db.clj b/src/metabase/cache/db.cljindex 64c6df86256..4bab6229841 100644--- a/src/metabase/cache/db.clj+++ b/src/metabase/cache/db.clj@@ -35,10 +35,10 @@[card-id :- ::lib.schema.id/card](t2/select-one [:model/Card :collection_id] :id card-id))-(mu/defn cache-config- "The CacheConfig with primary key `pk`, or nil."+(mu/defn cache-config :- [:maybe ::cache.schema/cache-config]+ "The ::cache.schema/cache-config with `pk`, or nil."[pk :- ms/PositiveInt]- (t2/select-one :model/CacheConfig pk))+ (t2/select-one :model/CacheConfig :id [:auto/param pk]))(mu/defn root-ttl-cache-config"The root TTL CacheConfig, or nil."diff --git a/src/metabase/channel/db.clj b/src/metabase/channel/db.cljindex 456e10073db..34ba5c124e2 100644--- a/src/metabase/channel/db.clj+++ b/src/metabase/channel/db.clj@@ -9,6 +9,11 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))+(mu/defn channel-template :- [:maybe ::channel.schema/channel-template]+ "The ::channel.schema/channel-template with `channel-template-id`, or nil."+ [channel-template-id :- ms/PositiveInt]+ (t2/select-one :model/ChannelTemplate :id [:auto/param channel-template-id]))+(def ^:private ChannelRow"A whole Channel row for insert or update."::channel.schema/channel.update)@@ -33,10 +38,10 @@[row :- ChannelRow](t2/insert-returning-instance! :model/Channel row))-(mu/defn channel- "The Channel with `id`, or nil."+(mu/defn channel :- [:maybe ::channel.schema/channel]+ "The ::channel.schema/channel with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Channel id))+ (t2/select-one :model/Channel :id [:auto/param id]))(mu/defn update-channel!"Apply `changes` to the Channel with `id`, returning the number updated."@@ -90,16 +95,6 @@[channel-name :- :string](t2/select-one :model/Channel :name channel-name))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))--(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id dashboard-id))-(mu/defn dashboard-tabs"The DashboardTabs of the Dashboard with `dashboard-id`, in position order."[dashboard-id :- ::lib.schema.id/dashboard]diff --git a/src/metabase/channel/render/card.clj b/src/metabase/channel/render/card.cljindex 2e9aaed21c6..3f579c9408b 100644--- a/src/metabase/channel/render/card.clj+++ b/src/metabase/channel/render/card.clj@@ -1,7 +1,6 @@(ns metabase.channel.render.card(:require[hiccup.core :refer [h]]- [metabase.channel.db :as channel.db][metabase.channel.render.body :as body][metabase.channel.render.image-bundle :as image-bundle][metabase.channel.render.markdown :as markdown]@@ -16,7 +15,8 @@[metabase.util.i18n :refer [tru]][metabase.util.log :as log][metabase.util.malli :as mu]- [metabase.util.malli.registry :as mr]))+ [metabase.util.malli.registry :as mr]+ [metabase.warehouses.db :as warehouses.db]))(defn- card-href[card]@@ -374,5 +374,5 @@(mu/defn defaulted-timezone :- :string"Returns the timezone ID for the given `card`. Either the report timezone (if applicable) or the JVM timezone."[card :- [:maybe ::body/card]]- (or (some->> card :database_id channel.db/database qp.timezone/results-timezone-id)+ (or (some->> card :database_id warehouses.db/database qp.timezone/results-timezone-id)(qp.timezone/system-timezone-id)))diff --git a/src/metabase/channel/render/pdf.clj b/src/metabase/channel/render/pdf.cljindex 3594251ea32..4412f7995bd 100644--- a/src/metabase/channel/render/pdf.clj+++ b/src/metabase/channel/render/pdf.clj@@ -51,6 +51,7 @@[metabase.channel.render.table :as table][metabase.channel.render.util :as render.util][metabase.channel.shared :as channel.shared]+ [metabase.dashboards.db :as dashboards.db][metabase.dashboards.models.dashboard-card :as dashboard-card][metabase.notification.payload.core :as notification.payload][metabase.parameters.shared :as shared.params]@@ -1507,7 +1508,7 @@(map (juxt #(-> % :dashcard :id) identity)))parts)dims (paper-dims paper-key)- dash (channel.db/dashboard dashboard-id)+ dash (dashboards.db/dashboard dashboard-id)tabs (channel.db/dashboard-tabs dashboard-id)dcs (t2/hydrate (channel.db/dashcards dashboard-id) :card);; only treat a dashboard as tabbed when there's more than one tab -- a lone tab isn't shown as a tab indiff --git a/src/metabase/channel/render/preview.clj b/src/metabase/channel/render/preview.cljindex b8910184a3f..c9ddf8412bb 100644--- a/src/metabase/channel/render/preview.clj+++ b/src/metabase/channel/render/preview.clj@@ -16,6 +16,7 @@[metabase.channel.render.markdown :as markdown][metabase.channel.render.png :as png][metabase.channel.render.style :as style]+ [metabase.dashboards.db :as dashboards.db][metabase.notification.payload.core :as notification.payload][metabase.system.core :as system][metabase.util :as u]))@@ -83,7 +84,7 @@"Given a dashboard ID, renders all of the dashcards to hiccup datastructure."[dashboard-id](let [user (channel.db/any-user)- dashboard (channel.db/dashboard dashboard-id)+ dashboard (dashboards.db/dashboard dashboard-id)dashboard-results (notification.payload/execute-dashboard (:id dashboard) (:id user) nil)render (->> (map render-one-dashcard (map #(assoc % :dashboard-id dashboard-id) dashboard-results))(into [[:trdiff --git a/src/metabase/collections/db.clj b/src/metabase/collections/db.cljindex a55625783d4..902b9d65413 100644--- a/src/metabase/collections/db.clj+++ b/src/metabase/collections/db.clj@@ -24,15 +24,15 @@;;; ---------------------------------------------- Single Collections -----------------------------------------------(mu/defn collection+(mu/defn collection :- [:maybe ::collections.schema/collection]"The ::collections.schema/collection with `collection-id`, or nil."[collection-id :- ::lib.schema.id/collection]- (t2/select-one :model/Collection :id collection-id))+ (t2/select-one :model/Collection :id [:auto/param collection-id]))-(mu/defn collection-id-and-namespace- "The ID and namespace of the ::collections.schema/collection with `collection-id`, or nil."+(mu/defn collection-location-columns+ "The location, id, and type of the Collection with `collection-id`, or nil."[collection-id :- ::lib.schema.id/collection]- (t2/select-one [:model/Collection :id :namespace] :id collection-id))+ (t2/select-one [:model/Collection :location :id :type] :id [:auto/param collection-id]))(mu/defn collection-of-type"The ::collections.schema/collection of `type`, or nil."@@ -75,32 +75,6 @@[collection-id :- ::lib.schema.id/collection](t2/exists? :model/Collection :id collection-id :personal_owner_id [:not= nil]))-(mu/defn collection-remote-synced?- "Whether the ::collections.schema/collection with `collection-id` is remote-synced, or nil if `collection-id` is nil (the root- ::collections.schema/collection) or the ::collections.schema/collection does not exist."- [collection-id :- [:maybe ::lib.schema.id/collection]]- (t2/select-one-fn :is_remote_synced :model/Collection :id collection-id))--(mu/defn collection-namespace- "The namespace of the ::collections.schema/collection with `collection-id`."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one-fn :namespace :model/Collection :id collection-id))--(mu/defn collection-location- "The location of the ::collections.schema/collection with `collection-id`."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one-fn :location :model/Collection :id collection-id))--(defn collection-location-columns- "The location, id, and type of the Collection with `collection-id`, or nil."- [collection-id]- (t2/select-one [:model/Collection :location :id :type] :id collection-id))--(mu/defn root-collection-type-by-id- "The type of the top-level Collection with `collection-id`, or nil if it is not top-level."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one-fn :type :model/Collection :id collection-id :location "/"))-;;; ---------------------------------------------- ::collections.schema/collection sets ----------------------------------------------(mu/defn collections-by-iddiff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.cljindex bb2314ca001..f515f56ea56 100644--- a/src/metabase/collections/models/collection.clj+++ b/src/metabase/collections/models/collection.clj@@ -158,7 +158,7 @@(cond(nil? collection-or-id) false ;; the root collection is never remote-synced(map? collection-or-id) (boolean (get collection-or-id :is_remote_synced))- :else (collections.db/collection-remote-synced? (u/the-id collection-or-id))))+ :else (:is_remote_synced (collections.db/collection (u/the-id collection-or-id)))))(defn- is-library?"Is this the Library collection?"@@ -215,7 +215,9 @@^{::memoize/args-fn (fn [[id]] [(mdb/unique-identifier) id])}(fn [id](when id- (collections.db/root-collection-type-by-id id)))+ (let [collection (collections.db/collection id)]+ (when (= "/" (:location collection))+ (:type collection))))):ttl/threshold (* 60 60 1000)))(defn root-collection-type@@ -584,7 +586,7 @@(throw (ex-info "Can't create a tenant collection without tenants enabled." {:type (:type collection)})))(when location(when-let [parent-id (location-path->parent-id location)]- (let [parent-namespace (collections.db/collection-namespace parent-id)]+ (let [parent-namespace (:namespace (collections.db/collection parent-id))](when-not (= (keyword collection-namespace) (keyword parent-namespace))(let [msg (tru "Collection must be in the same namespace as its parent")](throw (ex-info msg {:status-code 400, :errors {:location msg}})))))))@@ -599,7 +601,7 @@If a collection's parent is remote-synced, it must also be remote-synced."[{:keys [location is_remote_synced]}](when-let [parent-id (and location (location-path->parent-id location))]- (let [parent-is-remote-synced? (collections.db/collection-remote-synced? parent-id)]+ (let [parent-is-remote-synced? (:is_remote_synced (collections.db/collection parent-id))](when (and (or parent-is-remote-synced? is_remote_synced)(not= parent-is-remote-synced? is_remote_synced))(let [msg (if is_remote_synced@@ -1873,7 +1875,7 @@(let [orig-children-location (children-location collection)new-children-location (children-location (assoc collection :location new-location))will-be-in-trash? (str/starts-with? new-location (trash-path))- will-be-in-remote-synced? (collections.db/collection-remote-synced? (parent-id* {:location new-location}))]+ will-be-in-remote-synced? (some-> (parent-id* {:location new-location}) collections.db/collection :is_remote_synced)](when will-be-in-trash?(throw (ex-info "Cannot `move-collection!` into the Trash. Call `archive-collection!` instead."{:collection collection@@ -2190,7 +2192,7 @@(defmethod mi/perms-objects-set :model/Collection[collection-or-id read-or-write](let [collection (if (integer? collection-or-id)- (collections.db/collection-id-and-namespace collection-or-id)+ (collections.db/collection collection-or-id)collection-or-id)](if (and (= (u/qualified-name (:namespace collection)) "snippets")(not (premium-features/enable-snippet-collections?)))@@ -2244,7 +2246,7 @@{["Collection" (u/last path)] {"Collection" id}}))))(defmethod serdes/descendants "Collection" [_model-name id {:keys [skip-archived]}]- (let [location (when id (collections.db/collection-location id))+ (let [location (when id (:location (collections.db/collection id)))child-colls (when id ; traversing root coll will return all (even personal) colls, do not do it(into {} (for [child-id (collections.db/child-collection-ids (str location id "/")trash-collection-type@@ -2362,7 +2364,7 @@(check-collection-namespace Card new-collection-id)"[model collection-id](when collection-id- (let [collection (or (collections.db/collection-id-and-namespace collection-id)+ (let [collection (or (collections.db/collection collection-id)(let [msg (tru "Collection does not exist.")](throw (ex-info msg {:status-code 404:errors {:collection_id msg}}))))diff --git a/src/metabase/collections_rest/api.clj b/src/metabase/collections_rest/api.cljindex 47a5f978b44..1e911051612 100644--- a/src/metabase/collections_rest/api.clj+++ b/src/metabase/collections_rest/api.clj@@ -12,6 +12,7 @@[metabase.collections-rest.db :as collections-rest.db][metabase.collections.children :as collections.children][metabase.collections.core :as collections]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.collections.models.collection.root :as collection.root][metabase.data-apps.core :as data-apps]@@ -637,7 +638,7 @@[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-403 api/*is-superuser?*)- (let [collection (collections-rest.db/collection id)+ (let [collection (collections.db/collection id)old-children-location (collection/children-location collection)new-children-location (:location collection)](api/check-400 (:archived collection)diff --git a/src/metabase/collections_rest/db.clj b/src/metabase/collections_rest/db.cljindex c8bca4c826d..578a7ef5231 100644--- a/src/metabase/collections_rest/db.clj+++ b/src/metabase/collections_rest/db.clj@@ -7,11 +7,6 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn collection- "The Collection with `id`, or nil."- [id :- [:maybe ::lib.schema.id/collection]]- (t2/select-one :model/Collection :id id))-(mu/defn directly-archived-descendant-collections"The directly archived Collections whose location starts with `location-prefix`."[location-prefix :- :string]diff --git a/src/metabase/comments/api.clj b/src/metabase/comments/api.cljindex 857d7541fbd..51faf59a403 100644--- a/src/metabase/comments/api.clj+++ b/src/metabase/comments/api.clj@@ -12,7 +12,9 @@[metabase.comments.models.comment-reaction :as comment-reaction][metabase.comments.render :as comments.render][metabase.comments.schema :as comments.schema]+ [metabase.documents.db :as documents.db][metabase.events.core :as events]+ [metabase.explorations.db :as explorations.db][metabase.models.interface :as mi][metabase.request.core :as request][metabase.util :as u]@@ -153,10 +155,10 @@& [{:keys [entity parent];; if you don't pass them we'll try to fetch them:or {entity (case target_type- "document" (comments.db/document target_id)- "exploration" (comments.db/exploration target_id))+ "document" (documents.db/document target_id)+ "exploration" (explorations.db/exploration target_id))parent (when parent_comment_id- (comments.db/comment-by-id parent_comment_id))}}]]+ (comments.db/comment parent_comment_id))}}]](let [mentions (->> (comment/mentions (:content comment))(mentioned-ids-who-can-read entity));; TODO: when we expand to more entity types, add dispatch here if not everyone has `creator_id`@@ -180,7 +182,7 @@(defn notify-comment-id!"Send a notification using only comment id"[comment-id]- (notify-comment! (-> (comments.db/comment-by-id comment-id)+ (notify-comment! (-> (comments.db/comment comment-id)(t2/hydrate :creator :reactions))));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -197,7 +199,7 @@"Cannot comment on archived entities")));; If this is a reply, validate the parent comment exists and belongs to same entityparent (when parent_comment_id- (-> (api/check-404 (comments.db/comment-by-id parent_comment_id))+ (-> (api/check-404 (comments.db/comment parent_comment_id))(u/prog1 (api/check-400 (and (= (:target_type <>) target_type)(= (:target_id <>) target_id)(= (:child_target_id <>) child_target_id))@@ -228,7 +230,7 @@[{:keys [comment-id]} :- [:map {:closed true} [:comment-id ms/PositiveInt]]_query-params{:keys [content is_resolved]} :- UpdateComment]- (let [comment (api/check-404 (comments.db/comment-by-id comment-id))+ (let [comment (api/check-404 (comments.db/comment comment-id))entity (-> (api/read-check (type->model (:target_type comment)) (:target_id comment))(u/prog1 (api/check-400 (not (entity-archived? <>))"Cannot edit comments on archived entities")))]@@ -246,7 +248,7 @@u/remove-nilsnot-empty)](comments.db/update-comment! comment-id updates))- (let [updated-comment (-> (comments.db/comment-by-id comment-id)+ (let [updated-comment (-> (comments.db/comment comment-id)(t2/hydrate :creator :reactions))](events/publish-event! :event/comment-update{:object updated-comment@@ -261,7 +263,7 @@"Soft delete a comment"[{:keys [comment-id]} :- [:map {:closed true} [:comment-id ms/PositiveInt]]_query-params]- (let [comment (api/check-404 (comments.db/comment-by-id comment-id))]+ (let [comment (api/check-404 (comments.db/comment comment-id))](-> (api/read-check (type->model (:target_type comment)) (:target_id comment))(u/prog1 (api/check-400 (not (entity-archived? <>))"Cannot delete comments on archived entities")))@@ -286,7 +288,7 @@[{:keys [comment-id]} :- [:map {:closed true} [:comment-id ms/PositiveInt]]_query-params{:keys [emoji]} :- [:map {:closed true} [:emoji ::comments.schema/reaction-emoji]]]- (let [comment (api/check-404 (comments.db/comment-by-id comment-id))]+ (let [comment (api/check-404 (comments.db/comment comment-id))](api/check-400 (not (:deleted_at comment))"Cannot react to deleted comments")(-> (api/read-check (type->model (:target_type comment)) (:target_id comment))diff --git a/src/metabase/comments/db.clj b/src/metabase/comments/db.cljindex 55aef5f3cd9..7df1b978b0b 100644--- a/src/metabase/comments/db.clj+++ b/src/metabase/comments/db.clj@@ -1,6 +1,7 @@(ns metabase.comments.db"Application database queries for the comments module. Every function here is a direct Toucan 2 call with noadditional logic, so no other namespace in the module runs a query itself (model definitions still use `toucan2.core`)."+ (:refer-clojure :exclude [comment])(:require[honey.sql.helpers :as sql.helpers][malli.util :as mut]@@ -50,20 +51,10 @@[user-ids :- [:sequential ::lib.schema.id/user]](t2/select-pks-set :model/User :id [:in user-ids] :is_active true))-(mu/defn document- "The Document with `id`, or nil."+(mu/defn comment :- [:maybe ::comments.schema/comment]+ "The ::comments.schema/comment with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Document :id id))--(mu/defn exploration- "The Exploration with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/Exploration :id id))--(mu/defn comment-by-id- "The Comment with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/Comment :id id))+ (t2/select-one :model/Comment :id [:auto/param id]))(mu/defn comment-recipient-emails"The emails of the Users to notify about a comment: the authors of the Comment with `parent-comment-id` and of itsdiff --git a/src/metabase/dashboards/db.clj b/src/metabase/dashboards/db.cljindex 6725388f55a..667ebdd313b 100644--- a/src/metabase/dashboards/db.clj+++ b/src/metabase/dashboards/db.clj@@ -8,17 +8,17 @@[metabase.dashboards.schema :as dashboards.schema][metabase.lib.schema.id :as lib.schema.id][metabase.models.serialization :as serdes]- [metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.queries.schema :as queries.schema][metabase.util.honey-sql-2 :as h2x][metabase.util.malli :as mu][metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."+(mu/defn dashboard :- [:maybe ::dashboards.schema/dashboard]+ "The ::dashboards.schema/dashboard with `dashboard-id`, or nil."[dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id dashboard-id))+ (t2/select-one :model/Dashboard :id [:auto/param dashboard-id]))(mu/defn insert-dashboard!"Insert the Dashboard `row` and return the inserted instance."@@ -113,15 +113,10 @@collection-id :- [:maybe ::lib.schema.id/collection]](t2/update! :model/Card :dashboard_id dashboard-id {:collection_id collection-id}))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(mu/defn card-query-columns"The query-relevant columns of the Card with `card-id`, or nil."[card-id :- ::lib.schema.id/card]- (queries/card-query-info card-id))+ (queries.db/card-query-info card-id))(mu/defn card-queries"A map of Card id to query for the Cards with `card-ids`."@@ -179,10 +174,10 @@:where [:in :series.dashboardcard_id dashcard-ids]:order-by [[:series.position :asc]]}))-(mu/defn dashcard- "The DashboardCard with `dashcard-id`, or nil."+(mu/defn dashboard-card :- [:maybe ::dashboards.schema/dashboard-card]+ "The ::dashboards.schema/dashboard-card with `dashcard-id`, or nil."[dashcard-id :- ::lib.schema.id/dashcard]- (t2/select-one :model/DashboardCard :id dashcard-id))+ (t2/select-one :model/DashboardCard :id [:auto/param dashcard-id]))(mu/defn multi-cards-for-dashcard"The unarchived Cards added to the DashboardCard with `dashcard-id` as series (the 'add series' feature)."@@ -376,10 +371,10 @@[link-card-model->ids :- [:sequential [:tuple :string [:or [:set [:or :int :string]] [:sequential [:or :int :string]]]]]](t2/query (link-card-info-query link-card-model->ids)))-(mu/defn dashboard-tab- "The DashboardTab with `tab-id`, or nil."+(mu/defn dashboard-tab :- [:maybe ::dashboards.schema/dashboard-tab]+ "The ::dashboards.schema/dashboard-tab with `tab-id`, or nil."[tab-id :- ms/PositiveInt]- (t2/select-one :model/DashboardTab :id tab-id))+ (t2/select-one :model/DashboardTab :id [:auto/param tab-id]))(mu/defn insert-dashboard-tabs!"Insert the DashboardTab `rows` and return their ids."diff --git a/src/metabase/dashboards/models/dashboard.clj b/src/metabase/dashboards/models/dashboard.cljindex f1ac4df8d8d..4fa53f052cf 100644--- a/src/metabase/dashboards/models/dashboard.clj+++ b/src/metabase/dashboards/models/dashboard.clj@@ -22,6 +22,7 @@[metabase.permissions.core :as perms][metabase.public-sharing.core :as public-sharing][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.queries.schema :as queries.schema][metabase.query-permissions.core :as query-perms][metabase.query-processor.metadata :as qp.metadata]@@ -293,7 +294,7 @@[card](cond;; If this is a pre-existing card, just return it- (and (integer? (:id card)) (dashboards.db/card (:id card)))+ (and (integer? (:id card)) (queries.db/card (:id card)))(do(api/read-check :model/Card (:id card))card)diff --git a/src/metabase/dashboards/models/dashboard_card.clj b/src/metabase/dashboards/models/dashboard_card.cljindex 46eaf032df4..f108270e7f2 100644--- a/src/metabase/dashboards/models/dashboard_card.clj+++ b/src/metabase/dashboards/models/dashboard_card.clj@@ -155,7 +155,7 @@(mu/defn retrieve-dashboard-card"Fetch a single DashboardCard by its ID value."[id :- ms/PositiveInt]- (-> (dashboards.db/dashcard id)+ (-> (dashboards.db/dashboard-card id)(t2/hydrate :series)))(defn dashcard->multi-cardsdiff --git a/src/metabase/dashboards/write.clj b/src/metabase/dashboards/write.cljindex d1f345ca8e4..e7bf057cfeb 100644--- a/src/metabase/dashboards/write.clj+++ b/src/metabase/dashboards/write.clj@@ -25,6 +25,7 @@[metabase.parameters.schema :as parameters.schema][metabase.pulse.broken-subscriptions :as pulse.broken-subscriptions][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.query-permissions.core :as query-perms][metabase.util :as u][metabase.util.i18n :refer [tru]]@@ -187,7 +188,7 @@(defn- create-dashcards (filter pos-int?)) dashcards)]- (api/check-not-archived (dashboards.db/card card-id)))+ (api/check-not-archived (queries.db/card card-id)))(check-parameter-mapping-permissions (for [{:keys [card_id parameter_mappings]} dashcardsmapping parameter_mappings](assoc mapping :card-id card_id)))diff --git a/src/metabase/dashboards_rest/api.clj b/src/metabase/dashboards_rest/api.cljindex dd95d92f5ee..10f4cffa1bf 100644--- a/src/metabase/dashboards_rest/api.clj+++ b/src/metabase/dashboards_rest/api.clj@@ -15,9 +15,11 @@[metabase.channel.render.core :as channel.render][metabase.collections.children :as collections.children][metabase.collections.core :as collections]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.collections.models.collection.root :as collection.root][metabase.dashboards-rest.db :as dashboards-rest.db]+ [metabase.dashboards.db :as dashboards.db][metabase.dashboards.models.dashboard :as dashboard][metabase.dashboards.models.dashboard-card :as dashboard-card][metabase.dashboards.models.dashboard-tab :as dashboard-tab]@@ -40,6 +42,7 @@[metabase.public-sharing.validation :as public-sharing.validation][metabase.pulse.core :as pulse][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.queries.schema :as queries.schema][metabase.query-permissions.core :as query-perms][metabase.query-processor.api :as api.dataset]@@ -51,6 +54,7 @@[metabase.query-processor.util :as qp.util][metabase.request.core :as request][metabase.revisions.core :as revisions]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.i18n :refer [deferred-tru tru]][metabase.util.log :as log]@@ -363,7 +367,7 @@(fn [card](when card(let [dataset-query (or (:dataset_query card)- (dashboards-rest.db/card-query (:id card)))+ (some-> (:id card) queries.db/card :dataset_query))download-level (when (seq dataset-query)(perms/download-perms-level dataset-query api/*current-user-id*))](assoc card :download_perms (case download-level@@ -389,7 +393,7 @@(span/with-span!{:name "get-dashboard":attributes {:dashboard/id id}}- (-> (dashboards-rest.db/dashboard id)+ (-> (dashboards.db/dashboard id)api/read-checkhydrate-dashboard-detailscollection.root/hydrate-root-collection@@ -750,7 +754,7 @@cards (dashboards-rest.db/dashboard-item-cards id (request/paged?) (request/limit) (request/offset))]{:total (count cards):data (collections.children/post-process-rows {}- (dashboards-rest.db/collection (:collection_id dashboard))+ (some-> (:collection_id dashboard) collections.db/collection)cards):limit (request/limit):offset (request/offset)@@ -846,7 +850,7 @@(defn- create-dashcards (filter pos-int?)) dashcards)]- (api/check-not-archived (dashboards-rest.db/card card-id)))+ (api/check-not-archived (queries.db/card card-id)))(check-parameter-mapping-permissions (for [{:keys [card_id parameter_mappings]} dashcardsmapping parameter_mappings](assoc mapping :card-id card_id)))@@ -955,7 +959,7 @@- The user info for the creator of the pulse- The users affected by the pulse"[{bad-pulse-id :id pulse-name :name :keys [parameters creator_id]}]- (let [creator (dashboards-rest.db/user-name-and-email creator_id)]+ (let [creator (select-keys (users.db/user creator_id) [:first_name :last_name :email])]{:pulse-id bad-pulse-id:pulse-name pulse-name:bad-parameters parameters@@ -982,7 +986,7 @@"Identify and return any pulses used in a subscription that contain parameters that are no longer on the dashboard."[dashboard-id original-dashboard-params](when (seq original-dashboard-params)- (let [{:keys [resolved-params]} (t2/hydrate (dashboards-rest.db/dashboard-parameters dashboard-id) :resolved-params)+ (let [{:keys [resolved-params]} (t2/hydrate (dashboards.db/dashboard dashboard-id) :resolved-params)dashboard-params (set (keys resolved-params))];; ordered so the notifications go out in a stable order rather than whatever order the rows come back in(->> (dashboards-rest.db/unarchived-pulses-for-dashboard dashboard-id)@@ -1005,7 +1009,7 @@(when-some [broken-pulses (broken-pulses dashboard-id original-dashboard-params)](let [{dashboard-name :namedashboard-description :description- dashboard-creator :creator} (t2/hydrate (dashboards-rest.db/dashboard-name-columns dashboard-id) :creator)]+ dashboard-creator :creator} (t2/hydrate (dashboards.db/dashboard dashboard-id) :creator)](for [broken-pulse broken-pulses](assoc(bad-pulse-notification-data broken-pulse)@@ -1039,7 +1043,7 @@;; If there are parameters in the update, we want the old params so that we can do a check to see if any of;; the notifications were broken by the update.{original-params :resolved-params} (when parameters- (t2/hydrate (dashboards-rest.db/dashboard id) [:dashcards :card] :resolved-params))+ (t2/hydrate (dashboards.db/dashboard id) [:dashcards :card] :resolved-params))changes-stats (atom nil);; tabs are always sent in production as well when dashcards are updated, but there are lots of;; tests that exclude it. so this only checks for dashcards@@ -1105,7 +1109,7 @@(select-keys dashcards-changes-stats [:created-dashcards :deleted-dashcards])))))(collections/check-for-remote-sync-update current-dash))true))- (let [dashboard (dashboards-rest.db/dashboard id)]+ (let [dashboard (dashboards.db/dashboard id)];; skip publishing the event if it's just a change in its collection position(when-not (= #{:collection_position}(set (keys dash-updates)))@@ -1225,7 +1229,7 @@(api/check-superuser)(public-sharing.validation/check-public-sharing-enabled)(api/check-not-archived (api/read-check :model/Dashboard dashboard-id))- (let [existing-public-uuid (dashboards-rest.db/dashboard-public-uuid dashboard-id)+ (let [existing-public-uuid (:public_uuid (dashboards.db/dashboard dashboard-id))uuid (or existing-public-uuid(u/prog1 (str (random-uuid));; one transaction, so a failing handler cannot leave a saved link that a retry never reports@@ -1234,7 +1238,7 @@{:public_uuid <>:made_public_by_id api/*current-user-id*})(events/publish-event! :event/dashboard-public-link-created- {:object (dashboards-rest.db/dashboard dashboard-id)+ {:object (dashboards.db/dashboard dashboard-id):object-id dashboard-id:user-id api/*current-user-id*}))))]{:uuid uuid}))@@ -1258,7 +1262,7 @@{:public_uuid nil:made_public_by_id nil})(events/publish-event! :event/dashboard-public-link-deleted- {:object (dashboards-rest.db/dashboard dashboard-id)+ {:object (dashboards.db/dashboard dashboard-id):object-id dashboard-id:user-id api/*current-user-id*})){:status 204, :body nil})@@ -1271,7 +1275,7 @@"Return related entities."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (-> (dashboards-rest.db/dashboard id) api/read-check xrays/related))+ (-> (dashboards.db/dashboard id) api/read-check xrays/related));;; ---------------------------------------------- Transient dashboards ----------------------------------------------@@ -1471,7 +1475,8 @@request](some-> (data-apps/request-data-app request) (data-apps/check-dashboard dashboard-id))(api/read-check :model/Dashboard dashboard-id)- (let [dashcard (api/check-404 (dashboards-rest.db/dashcard-in-dashboard dashcard-id dashboard-id))]+ (let [dashcard (dashboards.db/dashboard-card dashcard-id)]+ (api/check-404 (= (:dashboard_id dashcard) dashboard-id))(actions/fetch-values(api/check-404 (actions/dashcard->action dashcard))parameters)))@@ -1521,9 +1526,9 @@(m/mapply qp.dashboard/process-query-for-dashcard(merge(dissoc body :dashboard_load_id)- {:dashboard (api/check-404 (dashboards-rest.db/dashboard dashboard-id))- :card (api/check-404 (dashboards-rest.db/card card-id))- :dashcard (api/check-404 (dashboards-rest.db/dashcard dashcard-id))}))))+ {:dashboard (api/check-404 (dashboards.db/dashboard dashboard-id))+ :card (api/check-404 (queries.db/card card-id))+ :dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))}))));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happen@@ -1552,9 +1557,9 @@request](some-> (data-apps/request-data-app request) (data-apps/check-dashboard dashboard-id))(m/mapply qp.dashboard/process-query-for-dashcard- {:dashboard (api/check-404 (dashboards-rest.db/dashboard dashboard-id))- :card (api/check-404 (dashboards-rest.db/card card-id))- :dashcard (api/check-404 (dashboards-rest.db/dashcard dashcard-id))+ {:dashboard (api/check-404 (dashboards.db/dashboard dashboard-id))+ :card (api/check-404 (queries.db/card card-id))+ :dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id)):export-format export-format:parameters parameters:context (api.dataset/export-format->context export-format)@@ -1588,7 +1593,7 @@(m/mapply qp.dashboard/process-query-for-dashcard(mergebody- {:dashboard (api/check-404 (dashboards-rest.db/dashboard dashboard-id))- :card (api/check-404 (dashboards-rest.db/card card-id))- :dashcard (api/check-404 (dashboards-rest.db/dashcard dashcard-id))+ {:dashboard (api/check-404 (dashboards.db/dashboard dashboard-id))+ :card (api/check-404 (queries.db/card card-id))+ :dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id)):qp qp.pivot/run-pivot-query})))diff --git a/src/metabase/dashboards_rest/db.clj b/src/metabase/dashboards_rest/db.cljindex 95cb07bafa1..a9f6e5f10ea 100644--- a/src/metabase/dashboards_rest/db.clj+++ b/src/metabase/dashboards_rest/db.clj@@ -21,26 +21,6 @@[:= :archived archived?]]:order-by [:%lower.name]}))-(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id dashboard-id))--(mu/defn dashboard-parameters- "The id and parameters of the Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one [:model/Dashboard :id :parameters] dashboard-id))--(mu/defn dashboard-name-columns- "The name, description, and creator of the Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one [:model/Dashboard :name :description :creator_id] dashboard-id))--(mu/defn dashboard-public-uuid- "The public uuid of the Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one-fn :public_uuid :model/Dashboard :id dashboard-id))-(mu/defn public-dashboards"The name, id, and public uuid of the unarchived Dashboards that are publicly shared."[]@@ -133,16 +113,6 @@[query-hashes :- [:sequential bytes?]](t2/select-fn->fn :query_hash :average_execution_time :model/Query :query_hash [:in query-hashes]))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))--(mu/defn card-query- "The query of the Card with `card-id`, or nil (also nil for virtual dashcards, which have no Card id)."- [card-id :- [:maybe ::lib.schema.id/card]]- (t2/select-one-fn :dataset_query :model/Card :id card-id))-(mu/defn card-queries"A map of Card id to query for the Cards with `card-ids`."[card-ids :- [:set ::lib.schema.id/card]]@@ -168,27 +138,11 @@[rows :- [:sequential (mut/select-keys ::dashboards.schema/dashboard-tab.update [:dashboard_id :name :position])]](t2/insert-returning-pks! :model/DashboardTab rows))-(mu/defn collection- "The Collection with `collection-id`, or nil."- [collection-id :- [:maybe ::lib.schema.id/collection]]- (t2/select-one :model/Collection :id collection-id))-(mu/defn personal-collection-for-user"The personal Collection of the User with `user-id`, or nil."[user-id :- ::lib.schema.id/user](t2/select-one :model/Collection :personal_owner_id user-id))-(mu/defn dashcard- "The DashboardCard with `dashcard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard]- (t2/select-one :model/DashboardCard dashcard-id))--(mu/defn dashcard-in-dashboard- "The DashboardCard with `dashcard-id` on the Dashboard with `dashboard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard- dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/DashboardCard :id dashcard-id :dashboard_id dashboard-id))-(mu/defn dashcards-by-ids"The DashboardCards with `dashcard-ids`."[dashcard-ids :- [:sequential ::lib.schema.id/dashcard]]@@ -206,11 +160,6 @@dashcard-ids :- [:set ::lib.schema.id/dashcard]](t2/select-pk->fn :card_id :model/DashboardCard :dashboard_id dashboard-id :id [:in dashcard-ids]))-(mu/defn user-name-and-email- "The name and email of the User with `user-id`, or nil."- [user-id :- ::lib.schema.id/user]- (t2/select-one [:model/User :first_name :last_name :email] user-id))-(mu/defn user-names-and-emails"The names and emails of the Users with `user-ids`."[user-ids :- [:sequential ::lib.schema.id/user]]diff --git a/src/metabase/data_studio/api/table.clj b/src/metabase/data_studio/api/table.cljindex 396ee4a3c8d..854f6192575 100644--- a/src/metabase/data_studio/api/table.clj+++ b/src/metabase/data_studio/api/table.clj@@ -19,7 +19,8 @@[metabase.util.malli.schema :as ms][metabase.util.quick-task :as quick-task][metabase.warehouse-schema.models.table :as table]- [metabase.warehouse-schema.models.table-user-settings :as schema.table-user-settings]))+ [metabase.warehouse-schema.models.table-user-settings :as schema.table-user-settings]+ [metabase.warehouses.db :as warehouses.db]))(set! *warn-on-reflection* true)@@ -134,7 +135,7 @@(u.jvm/in-virtual-thread*(fn [](doseq [[db-id tables] (group-by :db_id newly-unhidden)]- (let [database (data-studio.db/database db-id)]+ (let [database (warehouses.db/database db-id)];; it's okay to allow testing H2 connections during sync. We only want to disallow you from testing them for the;; purposes of creating a new H2 database.(if (binding [driver.settings/*allow-testing-h2-connections* truediff --git a/src/metabase/data_studio/db.clj b/src/metabase/data_studio/db.cljindex ce2fb0773bb..ac189a870f3 100644--- a/src/metabase/data_studio/db.clj+++ b/src/metabase/data_studio/db.clj@@ -70,11 +70,6 @@:from [(warehouse-schema-overlay/table-query)]:where [:and where [:= :id output-table-id]]}]]]})))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database database-id))-(mu/defn databases"The Databases with `database-ids`."[database-ids :- [:sequential ::lib.schema.id/database]]diff --git a/src/metabase/documents/api/document.clj b/src/metabase/documents/api/document.cljindex 49a2a436cd9..2ab861cf8ae 100644--- a/src/metabase/documents/api/document.clj+++ b/src/metabase/documents/api/document.clj@@ -13,6 +13,7 @@[metabase.models.interface :as mi][metabase.parameters.schema :as parameters.schema][metabase.public-sharing.validation :as public-sharing.validation]+ [metabase.queries.db :as queries.db][metabase.query-processor.api :as api.dataset][metabase.query-processor.card :as qp.card][metabase.util :as u]@@ -38,6 +39,13 @@:body m.document/CardCreateSchema %)))))}[:map-of key-schema m.document/CardCreateSchema]])+(defn- unarchived-document+ "The Document with `document-id` if it is not archived, or nil."+ [document-id]+ (let [document (documents.db/document document-id)]+ (when-not (:archived document)+ document)))+(def ^:private DocumentCreateOptions[:map {:closed true}[:name m.document/DocumentName]@@ -197,7 +205,7 @@(api/create-check :model/Document {:collection_id collection_id})(let [existing-document (api/check-404(api/read-check- (documents.db/unarchived-document from-document-id)))+ (unarchived-document from-document-id)))document-data {:name (or name (:name existing-document)):document (:document existing-document):content_type (:content_type existing-document)@@ -256,14 +264,14 @@;; Use a transaction to prevent race conditions when two requests arrive simultaneously.;; Only one request will successfully create the UUID; both will return the same value.(t2/with-transaction [_conn]- (if-let [existing-uuid (documents.db/document-public-uuid document-id)]+ (if-let [existing-uuid (:public_uuid (documents.db/document document-id))]{:uuid existing-uuid}(do(documents.db/update-document! document-id{:public_uuid (str (random-uuid)):made_public_by_id api/*current-user-id*});; Always select after update to ensure we return what's actually stored- {:uuid (documents.db/document-public-uuid document-id)}))))+ {:uuid (:public_uuid (documents.db/document document-id))}))));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happen@@ -315,7 +323,7 @@Throws a 404 exception via `api/check-404` if any validation fails. Returns card-id on success."[document-id card-id]- (let [document (api/check-404 (documents.db/unarchived-document document-id))]+ (let [document (api/check-404 (unarchived-document document-id))](api/read-check document)(api/check-404 (and (contains? (set (prose-mirror/card-ids document)) card-id)(documents.db/unarchived-card-in-document-exists? card-id document-id)))))@@ -354,7 +362,7 @@[:pivot_results {:default false} ms/BooleanValue]]](validate-card-in-document document-id card-id)(qp.card/process-query-for-card- (api/check-404 (documents.db/card card-id)) export-format+ (api/check-404 (queries.db/card card-id)) export-format:parameters parameters:constraints nil:context (api.dataset/export-format->context export-format)diff --git a/src/metabase/documents/db.clj b/src/metabase/documents/db.cljindex c27e61f1bd2..c4bdd219dd4 100644--- a/src/metabase/documents/db.clj+++ b/src/metabase/documents/db.clj@@ -10,18 +10,12 @@[metabase.queries.schema :as queries.schema][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]- [metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn document- "The Document with `id`, or nil."+(mu/defn document :- [:maybe ::documents.schema/document]+ "The ::documents.schema/document with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Document :id id))--(mu/defn unarchived-document- "The Document with `id` if it is not archived, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/Document :id id :archived false))+ (t2/select-one :model/Document :id [:auto/param id]))(mu/defn visible-unarchived-documents"The unarchived Documents not attached to an Exploration, in a Collection visible to the current user."@@ -73,26 +67,11 @@[id :- ms/PositiveInt](t2/delete! :model/Document :id id))-(mu/defn document-public-uuid- "The public uuid of the Document with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one-fn :public_uuid :model/Document :id id))--(mu/defn document-exploration-id- "The Exploration id of the Document with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one-fn :exploration_id :model/Document :id id))-(mu/defn public-documents"The name, id, and public uuid of the unarchived Documents that are publicly shared."[](t2/select [:model/Document :name :id :public_uuid], :public_uuid [:not= nil], :archived false))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card card-id))-(mu/defn cards-not-in-document"The Cards with `card-ids` that do not belong to the Document with `document-id`."[card-ids :- [:sequential ::lib.schema.id/card]@@ -139,16 +118,6 @@[user-ids :- [:sequential ::lib.schema.id/user]](t2/select [:model/User :id :email :first_name :last_name] :id [:in user-ids]))-(mu/defn table- "The Table with `id`, or nil."- [id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id id {:from [(warehouse-schema-overlay/table-query)]}))--(mu/defn dashboard- "The Dashboard with `id`, or nil."- [id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id id))-(mu/defn update-documents-last-viewed-at!"Move `last_viewed_at` of each Document in `document-id->timestamp` forward to its timestamp, without touching`updated_at`, returning the number updated (as a one-element sequence -- `t2/query` on an UPDATE, unlikediff --git a/src/metabase/documents/models/document.clj b/src/metabase/documents/models/document.cljindex b54e98662d8..24ba054cdd9 100644--- a/src/metabase/documents/models/document.clj+++ b/src/metabase/documents/models/document.clj@@ -4,6 +4,7 @@[metabase.api.common :as api][metabase.collections.core :as collections][metabase.collections.models.collection :as collection]+ [metabase.dashboards.db :as dashboards.db][metabase.documents.db :as documents.db][metabase.documents.prose-mirror :as prose-mirror][metabase.documents.schema :as documents.schema]@@ -15,6 +16,7 @@[metabase.parameters.schema :as parameters.schema][metabase.public-sharing.core :as public-sharing][metabase.queries.core :as card]+ [metabase.queries.db :as queries.db][metabase.queries.schema :as queries.schema][metabase.query-permissions.core :as query-perms][metabase.search.config :as search.config]@@ -28,6 +30,7 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][methodical.core :as methodical][toucan2.core :as t2][toucan2.instance :as t2.instance]))@@ -589,9 +592,9 @@\"dashboard\") and `id`, or nil."[model id](case model- ("card" "dataset") (documents.db/card id)- "table" (documents.db/table id)- "dashboard" (documents.db/dashboard id)))+ ("card" "dataset") (queries.db/card id)+ "table" (warehouse-schema.db/table id)+ "dashboard" (dashboards.db/dashboard id)))(def ^:private model->serdes-model{"card" "Card"diff --git a/src/metabase/documents/schema.clj b/src/metabase/documents/schema.cljindex e7185b0b917..9d22af3c584 100644--- a/src/metabase/documents/schema.clj+++ b/src/metabase/documents/schema.clj@@ -15,12 +15,13 @@::prose-mirror/ast)(mr/def ::document- "A Document as selected from the app DB: every column of `:document`, plus `:creator` and `:collection` some- callers hydrate onto it."+ "A Document as selected from the app DB: every column of `:document`, with `:document` as stored rather than as+ written, plus `:creator` and `:collection` some callers hydrate onto it."[:merge::document.update[:map {:closed true}[:id ms/PositiveInt]+ [:document {:optional true} [:maybe [:map {::mr/deliberately-open true, :description "the column as stored"}]]][:creator {:optional true} [:maybe :metabase.users.schema/user]][:collection {:optional true} [:maybe :metabase.collections.schema/collection-or-root]][:can_write {:optional true} :boolean]diff --git a/src/metabase/documents/view_log.clj b/src/metabase/documents/view_log.cljindex 07feac2f3e1..2d21a7df0ce 100644--- a/src/metabase/documents/view_log.clj+++ b/src/metabase/documents/view_log.clj@@ -59,7 +59,7 @@;; Exploration documents aren't first-class content — they're surfaced only through their;; owning Exploration, and are hidden from search and collection listings. Skip recording;; recent views for them so they don't crowd out real document views in the bucket cap.- (when (nil? (documents.db/document-exploration-id object-id))+ (when (nil? (:exploration_id (documents.db/document object-id)))(activity-feed/update-users-recent-views! user-id :model/Document object-id :view))(catch Throwable e(log/warnf "Failed to process document view event. %s: %s" topic (ex-message e))))))diff --git a/src/metabase/embedding/db.clj b/src/metabase/embedding/db.cljindex 815907e83a6..69f49406038 100644--- a/src/metabase/embedding/db.clj+++ b/src/metabase/embedding/db.clj@@ -3,10 +3,16 @@additional logic, so the rest of the module never talks to `toucan2.core` itself."(:require[metabase.app-db.core :as mdb]+ [metabase.embedding.schema :as embedding.schema][metabase.util.malli :as mu][metabase.util.malli.schema :as ms][toucan2.core :as t2]))+(mu/defn embedding-theme :- [:maybe ::embedding.schema/embedding-theme]+ "The ::embedding.schema/embedding-theme with `embedding-theme-id`, or nil."+ [embedding-theme-id :- ms/PositiveInt]+ (t2/select-one :model/EmbeddingTheme :id [:auto/param embedding-theme-id]))+(mu/defn count-embedded-cards"Number of Cards that have embedding enabled."[]diff --git a/src/metabase/embedding_rest/api/common.clj b/src/metabase/embedding_rest/api/common.cljindex 1df2eada4ce..114fc07f216 100644--- a/src/metabase/embedding_rest/api/common.clj+++ b/src/metabase/embedding_rest/api/common.clj@@ -4,10 +4,10 @@[clojure.string :as str][medley.core :as m][metabase.api.common :as api]+ [metabase.dashboards.db :as dashboards.db][metabase.dashboards.schema :as dashboards.schema][metabase.database-routing.core :as database-routing][metabase.eid-translation.core :as eid-translation]- [metabase.embedding-rest.db :as embedding-rest.db][metabase.embedding.jwt :as embed][metabase.embedding.validation :as embedding.validation][metabase.lib.schema.parameter :as lib.schema.parameter]@@ -18,6 +18,7 @@[metabase.parameters.schema :as parameters.schema][metabase.public-sharing-rest.api :as api.public][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.query-processor.card :as qp.card][metabase.query-processor.middleware.constraints :as qp.constraints][metabase.query-processor.parameters.operators :as params.ops]@@ -350,13 +351,19 @@(->> (embed/get-in-unsigned-token-or-throw unsigned-token [:resource :question])(eid-translation/->id :model/Card)))+(defn active-card+ "The Card with `card-id` unless it is archived, in which case nil; a trashed Card keeps its DashboardCard rows."+ [card-id]+ (let [card (queries.db/card card-id)]+ (when-not (:archived card) card)))+(defn card-for-unsigned-token"Return the info needed for embedding about Card specified in `token`."[unsigned-token & {:keys [embedding-params enable-embedding?]}](let [card-id (unsigned-token->card-id unsigned-token)token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])resolved-embedding-params (or embedding-params- (embedding-rest.db/card-embedding-params card-id))]+ (:embedding_params (queries.db/card card-id)))](-> (api.public/public-card card-id :enable-embedding? enable-embedding?)api.public/combine-parameters-and-template-tags(remove-token-parameters token-params)@@ -469,7 +476,7 @@[:enable-embedding? {:optional true} [:maybe :boolean]]]]](let [dashboard-id (unsigned-token->dashboard-id unsigned-token)embedding-params (or embedding-params- (embedding-rest.db/dashboard-embedding-params dashboard-id))+ (:embedding_params (dashboards.db/dashboard dashboard-id)))token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])](-> (api.public/public-dashboard dashboard-id :enable-embedding? enable-embedding?)(substitute-token-parameters-in-text token-params)@@ -623,7 +630,7 @@& {:keys [preview] :or {preview false}}](let [unsigned-token (embed/unsign token)dashboard-id (unsigned-token->dashboard-id unsigned-token)- dashboard (embedding-rest.db/dashboard dashboard-id)+ dashboard (dashboards.db/dashboard dashboard-id)_ (when-not preview (check-embedding-enabled-for-dashboard dashboard))slug-token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params]){parameters :parameters@@ -678,7 +685,7 @@([token param-key value {:keys [preview] :or {preview false}}](let [unsigned-token (embed/unsign token)dashboard-id (unsigned-token->dashboard-id unsigned-token)- dashboard (embedding-rest.db/dashboard dashboard-id)+ dashboard (dashboards.db/dashboard dashboard-id)_ (when-not preview (check-embedding-enabled-for-dashboard dashboard))slug-token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])parameters (:parameters dashboard)diff --git a/src/metabase/embedding_rest/api/embed.clj b/src/metabase/embedding_rest/api/embed.cljindex 13c2cb2c341..110b7af8b9e 100644--- a/src/metabase/embedding_rest/api/embed.clj+++ b/src/metabase/embedding_rest/api/embed.clj@@ -18,12 +18,13 @@[malli.core :as mc][metabase.api.common :as api][metabase.api.macros :as api.macros]+ [metabase.dashboards.db :as dashboards.db][metabase.eid-translation.core :as eid-translation][metabase.embedding-rest.api.common :as api.embed.common]- [metabase.embedding-rest.db :as embedding-rest.db][metabase.embedding.jwt :as embedding.jwt][metabase.events.core :as events][metabase.parameters.schema :as parameters.schema]+ [metabase.queries.db :as queries.db][metabase.query-processor.card :as qp.card][metabase.query-processor.middleware.constraints :as qp.constraints][metabase.query-processor.pivot :as qp.pivot]@@ -85,7 +86,7 @@[:token api.embed.common/EncodedToken]]](let [unsigned (unsign-and-translate-ids token)card-id (api.embed.common/unsigned-token->card-id unsigned)]- (api.embed.common/check-embedding-enabled-for-card (api/check-404 (embedding-rest.db/card-embedding-flags card-id)))+ (api.embed.common/check-embedding-enabled-for-card (api/check-404 (queries.db/card card-id)))(api.embed.common/card-for-unsigned-token unsigned :enable-embedding? true)))(defn ^:private run-query-for-unsigned-token-async@@ -96,7 +97,7 @@qp qp.card/process-query-for-card-default-qp}:as options}](let [card-id (api.embed.common/unsigned-token->card-id unsigned-token)- card (api/check-404 (embedding-rest.db/card card-id))]+ card (api/check-404 (queries.db/card card-id))](api.embed.common/check-embedding-enabled-for-card card)(api.embed.common/process-query-for-card-with-params:export-format export-format@@ -169,7 +170,7 @@[:token api.embed.common/EncodedToken]]](let [unsigned (unsign-and-translate-ids token)dashboard-id (api.embed.common/unsigned-token->dashboard-id unsigned)]- (api.embed.common/check-embedding-enabled-for-dashboard (api/check-404 (embedding-rest.db/dashboard-embedding-flags dashboard-id)))+ (api.embed.common/check-embedding-enabled-for-dashboard (api/check-404 (dashboards.db/dashboard dashboard-id)))(u/prog1 (api.embed.common/dashboard-for-unsigned-token unsigned :enable-embedding? true)(events/publish-event! :event/dashboard-read {:object-id (:id <>), :user-id api/*current-user-id*}))))@@ -191,9 +192,9 @@qp qp.card/process-query-for-card-default-qp}}](let [unsigned-token (unsign-and-translate-ids token)dashboard-id (api.embed.common/unsigned-token->dashboard-id unsigned-token)- dashboard (api/check-404 (embedding-rest.db/dashboard dashboard-id))- dashcard (api/check-404 (embedding-rest.db/dashcard dashcard-id))- card (api/check-404 (embedding-rest.db/active-card card-id))]+ dashboard (api/check-404 (dashboards.db/dashboard dashboard-id))+ dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))+ card (api/check-404 (api.embed.common/active-card card-id))](api.embed.common/check-embedding-enabled-for-dashboard dashboard)(api.embed.common/process-query-for-dashcard:export-format export-format@@ -317,7 +318,7 @@[:param-key ms/NonBlankString]]](let [unsigned (unsign-and-translate-ids token)card-id (api.embed.common/unsigned-token->card-id unsigned)- card (api/check-404 (embedding-rest.db/card card-id))]+ card (api/check-404 (queries.db/card card-id))](api.embed.common/check-embedding-enabled-for-card card)(api.embed.common/card-param-values {:unsigned-token unsigned:card card@@ -332,7 +333,7 @@[{:keys [token param-key prefix]} :- api.embed.common/SearchParams](let [unsigned (unsign-and-translate-ids token)card-id (api.embed.common/unsigned-token->card-id unsigned)- card (api/check-404 (embedding-rest.db/card card-id))]+ card (api/check-404 (queries.db/card card-id))](api.embed.common/check-embedding-enabled-for-card card)(api.embed.common/card-param-values {:unsigned-token unsigned:card card@@ -352,7 +353,7 @@[:value :string]]](let [unsigned (unsign-and-translate-ids token)card-id (api.embed.common/unsigned-token->card-id unsigned)- card (api/check-404 (embedding-rest.db/card card-id))]+ card (api/check-404 (queries.db/card card-id))](api.embed.common/check-embedding-enabled-for-card card)(api.embed.common/card-param-remapped-value {:unsigned-token unsigned:card card@@ -412,7 +413,7 @@[:lonField ::api.tiles/legacy-ref]]](let [unsigned (unsign-and-translate-ids token)card-id (api.embed.common/unsigned-token->card-id unsigned)- card (api/check-404 (embedding-rest.db/card card-id))]+ card (api/check-404 (queries.db/card card-id))](api.embed.common/check-embedding-enabled-for-card card)(request/as-admin(api.embed.common/process-tiles-query-for-card@@ -442,9 +443,9 @@[:lonField ::api.tiles/legacy-ref]]](let [unsigned (unsign-and-translate-ids token)dashboard-id (api.embed.common/unsigned-token->dashboard-id unsigned)- dashboard (api/check-404 (embedding-rest.db/dashboard dashboard-id))- dashcard (api/check-404 (embedding-rest.db/dashcard dashcard-id))- card (api/check-404 (embedding-rest.db/active-card card-id))]+ dashboard (api/check-404 (dashboards.db/dashboard dashboard-id))+ dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))+ card (api/check-404 (api.embed.common/active-card card-id))](api.embed.common/check-embedding-enabled-for-dashboard dashboard)(api.embed.common/process-tiles-query-for-dashcarddashboard dashcard carddiff --git a/src/metabase/embedding_rest/api/preview_embed.clj b/src/metabase/embedding_rest/api/preview_embed.cljindex db2ff6af66f..4ef039d0d94 100644--- a/src/metabase/embedding_rest/api/preview_embed.clj+++ b/src/metabase/embedding_rest/api/preview_embed.clj@@ -11,11 +11,12 @@(:require[metabase.api.common :as api][metabase.api.macros :as api.macros]+ [metabase.dashboards.db :as dashboards.db][metabase.embedding-rest.api.common :as api.embed.common]- [metabase.embedding-rest.db :as embedding-rest.db][metabase.embedding.jwt :as embed][metabase.embedding.validation :as embedding.validation][metabase.parameters.schema :as parameters.schema]+ [metabase.queries.db :as queries.db][metabase.query-processor.pivot :as qp.pivot][metabase.request.core :as request][metabase.tiles.api :as api.tiles]@@ -59,7 +60,7 @@query-params :- api.embed.common/QueryParams](let [unsigned-token (check-and-unsign token)card-id (embed/get-in-unsigned-token-or-throw unsigned-token [:resource :question])- card (api/check-404 (embedding-rest.db/card card-id))]+ card (api/check-404 (queries.db/card card-id))](api.embed.common/process-query-for-card-with-params:export-format :api:card card@@ -75,7 +76,7 @@from the token, so a preview reflects the settings being edited rather than the published ones."[unsigned-token](let [card-id (api.embed.common/unsigned-token->card-id unsigned-token)]- (-> (api/check-404 (embedding-rest.db/card card-id))+ (-> (api/check-404 (queries.db/card card-id))(assoc :embedding_params (token-embedding-params unsigned-token)))))(api.macros/defendpoint :get "/card/:token/params/:param-key/values" :- ms/FieldValuesResult@@ -176,9 +177,9 @@query-params :- api.embed.common/QueryParams](let [unsigned-token (check-and-unsign token)dashboard-id (embed/get-in-unsigned-token-or-throw unsigned-token [:resource :dashboard])- dashboard (api/check-404 (embedding-rest.db/dashboard dashboard-id))- dashcard (api/check-404 (embedding-rest.db/dashcard dashcard-id))- card (api/check-404 (embedding-rest.db/active-card card-id))+ dashboard (api/check-404 (dashboards.db/dashboard dashboard-id))+ dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))+ card (api/check-404 (api.embed.common/active-card card-id))embedding-params (token-embedding-params unsigned-token)token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])](api.embed.common/process-query-for-dashcard@@ -201,7 +202,7 @@query-params :- api.embed.common/QueryParams](let [unsigned-token (check-and-unsign token)card-id (embed/get-in-unsigned-token-or-throw unsigned-token [:resource :question])- card (api/check-404 (embedding-rest.db/card card-id))]+ card (api/check-404 (queries.db/card card-id))](api.embed.common/process-query-for-card-with-params:export-format :api:card card@@ -223,9 +224,9 @@query-params :- api.embed.common/QueryParams](let [unsigned-token (check-and-unsign token)dashboard-id (embed/get-in-unsigned-token-or-throw unsigned-token [:resource :dashboard])- dashboard (api/check-404 (embedding-rest.db/dashboard dashboard-id))- dashcard (api/check-404 (embedding-rest.db/dashcard dashcard-id))- card (api/check-404 (embedding-rest.db/active-card card-id))+ dashboard (api/check-404 (dashboards.db/dashboard dashboard-id))+ dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))+ card (api/check-404 (api.embed.common/active-card card-id))embedding-params (token-embedding-params unsigned-token)token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])](api.embed.common/process-query-for-dashcard@@ -257,7 +258,7 @@[:lonField ::api.tiles/legacy-ref]]](let [unsigned-token (check-and-unsign token)card-id (api.embed.common/unsigned-token->card-id unsigned-token)- card (api/check-404 (embedding-rest.db/card card-id))]+ card (api/check-404 (queries.db/card card-id))](request/as-admin(api.embed.common/process-tiles-query-for-cardcard@@ -286,9 +287,9 @@[:lonField ::api.tiles/legacy-ref]]](let [unsigned-token (check-and-unsign token)dashboard-id (embed/get-in-unsigned-token-or-throw unsigned-token [:resource :dashboard])- dashboard (api/check-404 (embedding-rest.db/dashboard dashboard-id))- dashcard (api/check-404 (embedding-rest.db/dashcard dashcard-id))- card (api/check-404 (embedding-rest.db/active-card card-id))]+ dashboard (api/check-404 (dashboards.db/dashboard dashboard-id))+ dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))+ card (api/check-404 (api.embed.common/active-card card-id))](api.embed.common/process-tiles-query-for-dashcarddashboard dashcard card(api.embed.common/tile-parameters-for-dashboarddiff --git a/src/metabase/embedding_rest/api/theme.clj b/src/metabase/embedding_rest/api/theme.cljindex 38e1aa8e66a..0ce97d08af2 100644--- a/src/metabase/embedding_rest/api/theme.clj+++ b/src/metabase/embedding_rest/api/theme.clj@@ -4,6 +4,7 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.embedding-rest.db :as embedding-rest.db]+ [metabase.embedding.db :as embedding.db][metabase.embedding.settings :as embedding.settings][metabase.util.i18n :refer [tru]][metabase.util.malli.registry :as mr]@@ -35,7 +36,7 @@"Fetch a single embedding theme by ID."[{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](api/check-404 (embedding-rest.db/embedding-theme-exists? id))- (embedding-rest.db/embedding-theme id))+ (embedding.db/embedding-theme id))(api.macros/defendpoint :post "/" :- ::EmbeddingTheme"Create a new embedding theme."@@ -59,7 +60,7 @@(cond-> {}name (assoc :name name)settings (assoc :settings settings)))- (embedding-rest.db/embedding-theme id))+ (embedding.db/embedding-theme id))(api.macros/defendpoint :delete "/:id" :- :nil"Delete an embedding theme."@@ -72,7 +73,7 @@"Copy an embedding theme."[{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](api/check-404 (embedding-rest.db/embedding-theme-exists? id))- (let [source-theme (embedding-rest.db/embedding-theme id)]+ (let [source-theme (embedding.db/embedding-theme id)](embedding-rest.db/insert-embedding-theme! {:name (tru "Copy of {0}" (:name source-theme)):settings (:settings source-theme)})))diff --git a/src/metabase/embedding_rest/db.clj b/src/metabase/embedding_rest/db.cljindex 73ed769e641..22916b6913e 100644--- a/src/metabase/embedding_rest/db.clj+++ b/src/metabase/embedding_rest/db.clj@@ -4,52 +4,10 @@(:require[malli.util :as mut][metabase.embedding.schema :as embedding.schema]- [metabase.lib.schema.id :as lib.schema.id][metabase.util.malli :as mu][metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card card-id))--(mu/defn active-card- "The non-archived Card with `card-id`, or nil. A trashed Card keeps its DashboardCard rows, so the dashcard routes- select it as absent rather than checking `:archived` after the fact."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id :archived false))--(mu/defn card-embedding-params- "The embedding parameters of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :embedding_params :model/Card :id card-id))--(mu/defn card-embedding-flags- "The embedding-enabled and archived flags of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one [:model/Card :enable_embedding :archived] :id card-id))--(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard dashboard-id))--(mu/defn dashboard-embedding-params- "The embedding parameters of the Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one-fn :embedding_params :model/Dashboard, :id dashboard-id))--(mu/defn dashboard-embedding-flags- "The embedding-enabled and archived flags of the Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one [:model/Dashboard :enable_embedding :archived] :id dashboard-id))--(mu/defn dashcard- "The DashboardCard with `dashcard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard]- (t2/select-one :model/DashboardCard dashcard-id))-(mu/defn embedding-themes"The id, entity id, name, settings, default flag, and timestamps of every EmbeddingTheme, oldest first."[]@@ -61,11 +19,6 @@[id :- ms/PositiveInt](t2/exists? :model/EmbeddingTheme :id id))-(mu/defn embedding-theme- "The EmbeddingTheme with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/EmbeddingTheme :id id))-(mu/defn insert-embedding-theme!"Insert the EmbeddingTheme `row` and return the inserted instance."[row :- (mut/select-keys ::embedding.schema/embedding-theme.update [:name :settings])]diff --git a/src/metabase/explorations/api.clj b/src/metabase/explorations/api.cljindex 242bce23832..e69ffa924e9 100644--- a/src/metabase/explorations/api.clj+++ b/src/metabase/explorations/api.clj@@ -8,6 +8,7 @@[metabase.api.routes.common :refer [+auth]][metabase.collections.models.collection :as collection][metabase.documents.core :as documents]+ [metabase.documents.db :as documents.db][metabase.events.core :as events][metabase.explorations.blocks :as explorations.blocks][metabase.explorations.core :as explorations]@@ -19,10 +20,12 @@[metabase.explorations.query-plan.context :as qp.context][metabase.explorations.queues :as explorations.queues][metabase.lib-be.core :as lib-be]+ [metabase.lib.schema.common :as lib.schema.common][metabase.lib.schema.parameter :as lib.schema.parameter][metabase.metrics.core :as metrics][metabase.permissions.core :as perms][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.query-permissions.core :as query-perms][metabase.query-processor.core :as qp][metabase.query-processor.pipeline :as qp.pipeline]@@ -273,17 +276,6 @@(explorations.queues/start-thread! thread-id)true)))-(defn- stringify-dim-types- "Prepare a block's `:dimensions` for re-insertion. The model's read transform keywordizes- `:effective-type`/`:semantic-type` (e.g. `:type/Date`); the JSON write transform would- otherwise drop the namespace on a bare keyword, so stringify them first."- [dimensions]- (mapv (fn [dim]- (cond-> dim- (keyword? (:effective-type dim)) (update :effective-type u/qualified-name)- (keyword? (:semantic-type dim)) (update :semantic-type u/qualified-name)))- dimensions))-(defn- format-explore-filter-for-thread-name"Format one explore filter for a thread name. `:display_value` is FE-authored and is thesole source of truth for the value label."@@ -356,8 +348,8 @@[:map {:closed true :decode/api {:enter #(cond-> % (map? %) (update-keys u/->kebab-case-en))}}[:dimension-id ms/UUIDString][:display-name {:optional true} [:maybe :string]]- [:effective-type {:optional true} [:maybe :string]]- [:semantic-type {:optional true} [:maybe :string]]])+ [:effective-type {:optional true} [:maybe ::lib.schema.common/base-type]]+ [:semantic-type {:optional true} [:maybe ::lib.schema.common/semantic-or-relation-type]]])(def ^:private BlockSelection"One Research-plan area on the FE — a metric plus its chosen dimensions. Persisted verbatim as@@ -685,10 +677,10 @@{:keys [page_id explore_filters]} :- ExploreFurther](let [exploration (get-exploration-or-404 id)](api/write-check exploration)- (let [page (api/check-404 (explorations.db/page page_id))- block (api/check-404 (explorations.db/block (:exploration_block_id page)))+ (let [page (api/check-404 (explorations.db/exploration-page page_id))+ block (api/check-404 (explorations.db/exploration-block (:exploration_block_id page)))src-thread-id (:exploration_thread_id block)- src-thread (explorations.db/thread src-thread-id)+ src-thread (explorations.db/exploration-thread src-thread-id);; The clicked page must live in *this* exploration — a page keys off a block off a;; thread off an exploration, and "Explore further" only ever drills a chart the caller;; is already viewing here. Reject anything else with a 404: without this check a caller@@ -702,7 +694,7 @@metric-selection (first metric-selections)cards (mapv (fn [{:keys [card_id]}](api/read-check- (api/check-404 (when card_id (explorations.db/card card_id)))))+ (api/check-404 (when card_id (queries.db/card card_id)))))metric-selections)card (api/check-404 (first cards))card-name (:name card)@@ -729,7 +721,7 @@tid (:id thread)](explorations.db/insert-blocks! {:exploration_thread_id tid:metrics metrics'- :dimensions (stringify-dim-types (:dimensions block))+ :dimensions (:dimensions block):position 0})(insert-thread-timelines! tid timeline-ids);; Stamp `started_at` last — it's the signal the planning worker claims on.@@ -821,12 +813,12 @@(defn- get-exploration-page-or-404[page-id]- (api/check-404 (explorations.db/page page-id)))+ (api/check-404 (explorations.db/exploration-page page-id)))(defn- get-thread-or-404"Fetch the thread, or 404."[thread-id]- (api/check-404 (explorations.db/thread thread-id)))+ (api/check-404 (explorations.db/exploration-thread thread-id)))(defn- write-check-thread [thread-id](let [thread (get-thread-or-404 thread-id)]@@ -886,13 +878,13 @@(let [pending-ids (explorations.db/lock-pending-query-ids-for-thread thread-id)](when (seq pending-ids)(explorations.db/cancel-queries! pending-ids)))))- (explorations.db/thread-terminal-state thread-id))+ (select-keys (explorations.db/exploration-thread thread-id) [:id :canceled_at :completed_at]))(defn- get-exploration-query-or-404"Fetch an `ExplorationQuery` by id and read-check it. The model's `can-read?` delegates upthrough `ExplorationThread` to the parent `Exploration`."[query-id]- (api/read-check (api/check-404 (explorations.db/query query-id))))+ (api/read-check (api/check-404 (explorations.db/exploration-query query-id))))(defn- stream-stored-result"Replay a worker-serialized QP result (gzipped+nippy bytes from `:model/StoredResult.result_data`)@@ -927,7 +919,7 @@;; creator included, whose own permissions may have narrowed since the snapshot — against the;; stored data-access token (sandbox/impersonation/routing) + basic data perms.(queries/assert-can-view-cached-result! sr)- (stream-stored-result format (:result_data sr)))+ (stream-stored-result format (queries.db/stored-result-data (:id sr))));; Pending / errored: no result blob exists. The status payload (id/status/timestamps) rides;; the exploration's collection perms (already enforced by `get-exploration-query-or-404`'s@@ -977,14 +969,16 @@(defn- document-summary"Project a Document onto the `::ExplorationDocument` wire shape."[doc-id]- (explorations.db/summary-document-columns doc-id))+ (some-> (documents.db/document doc-id)+ (select-keys [:id :name :exploration_id :creator_id :content_type+ :created_at :updated_at :archived :is_placeholder])))(defn- page-explore-filters"Hydrated explore-further filters on the block that owns `page-id`, or nilwhen the page is unfiltered."[page-id]- (when-let [block-id (explorations.db/page-block-id page-id)]- (-> (explorations.db/block-metrics block-id)+ (when-let [block-id (:exploration_block_id (explorations.db/exploration-page page-id))]+ (-> (:metrics (explorations.db/exploration-block block-id))first:explore_filtersnot-empty)))diff --git a/src/metabase/explorations/db.clj b/src/metabase/explorations/db.cljindex 9f4a4604e6b..0a2cd92d73b 100644--- a/src/metabase/explorations/db.clj+++ b/src/metabase/explorations/db.clj@@ -19,10 +19,10 @@;;; ----------------------------------------------- Exploration ------------------------------------------------(mu/defn exploration- "The Exploration with `exploration-id`, or nil."+(mu/defn exploration :- [:maybe ::explorations.schema/exploration]+ "The ::explorations.schema/exploration with `exploration-id`, or nil."[exploration-id :- ms/PositiveInt]- (t2/select-one :model/Exploration :id exploration-id))+ (t2/select-one :model/Exploration :id [:auto/param exploration-id]))(defn- my-explorations-query"The query for the Explorations `user-id` created or edited, ordered by that user's most-recent@@ -110,40 +110,10 @@;;; ------------------------------------------------- Threads --------------------------------------------------(mu/defn thread- "The ExplorationThread with `thread-id`, or nil."+(mu/defn exploration-thread :- [:maybe ::explorations.schema/exploration-thread]+ "The ::explorations.schema/exploration-thread with `thread-id`, or nil."[thread-id :- ms/PositiveInt]- (t2/select-one :model/ExplorationThread :id thread-id))--(mu/defn thread-exploration-id-row- "The `:exploration_id` row of the ExplorationThread with `thread-id`, or nil."- [thread-id :- ms/PositiveInt]- (t2/select-one [:model/ExplorationThread :exploration_id] :id thread-id))--(mu/defn thread-terminal-state- "The ID, cancel time, and completion time of the ExplorationThread with `thread-id`."- [thread-id :- ms/PositiveInt]- (t2/select-one [:model/ExplorationThread :id :canceled_at :completed_at] :id thread-id))--(mu/defn thread-planning-state- "The ID, cancel time, and analysis start time of the ExplorationThread with `thread-id`, or nil."- [thread-id :- ms/PositiveInt]- (t2/select-one [:model/ExplorationThread :id :canceled_at :analysis_started_at] :id thread-id))--(mu/defn thread-exploration-id- "The Exploration ID of the ExplorationThread with `thread-id`."- [thread-id :- ms/PositiveInt]- (t2/select-one-fn :exploration_id :model/ExplorationThread :id thread-id))--(mu/defn thread-prompt- "The prompt of the ExplorationThread with `thread-id`."- [thread-id :- ms/PositiveInt]- (t2/select-one-fn :prompt :model/ExplorationThread :id thread-id))--(mu/defn thread-transcript- "The query-plan transcript of the ExplorationThread with `thread-id`."- [thread-id :- ms/PositiveInt]- (t2/select-one-fn :query_plan_transcript :model/ExplorationThread :id thread-id))+ (t2/select-one :model/ExplorationThread :id [:auto/param thread-id]))(mu/defn thread-in-exploration?"Whether the ExplorationThread with `thread-id` belongs to the Exploration with `exploration-id`."@@ -253,20 +223,10 @@;;; ------------------------------------------------- Blocks --------------------------------------------------(mu/defn block- "The ExplorationBlock with `block-id`, or nil."- [block-id :- ms/PositiveInt]- (t2/select-one :model/ExplorationBlock :id block-id))--(mu/defn block-thread-id-row- "The `:exploration_thread_id` row of the ExplorationBlock with `block-id`, or nil."- [block-id :- ms/PositiveInt]- (t2/select-one [:model/ExplorationBlock :exploration_thread_id] :id block-id))--(mu/defn block-metrics- "The metric selections of the ExplorationBlock with `block-id`."+(mu/defn exploration-block :- [:maybe ::explorations.schema/exploration-block]+ "The ::explorations.schema/exploration-block with `block-id`, or nil."[block-id :- ms/PositiveInt]- (t2/select-one-fn :metrics :model/ExplorationBlock :id block-id))+ (t2/select-one :model/ExplorationBlock :id [:auto/param block-id]))(mu/defn block-for-page"The ExplorationBlock owning the ExplorationPage with `page-id`, or nil."@@ -316,20 +276,10 @@;;; -------------------------------------------------- Pages ---------------------------------------------------(mu/defn page- "The ExplorationPage with `page-id`, or nil."+(mu/defn exploration-page :- [:maybe ::explorations.schema/exploration-page]+ "The ::explorations.schema/exploration-page with `page-id`, or nil."[page-id :- ms/PositiveInt]- (t2/select-one :model/ExplorationPage :id page-id))--(mu/defn page-block-id-row- "The `:exploration_block_id` row of the ExplorationPage with `page-id`, or nil."- [page-id :- ms/PositiveInt]- (t2/select-one [:model/ExplorationPage :exploration_block_id] :id page-id))--(mu/defn page-block-id- "The block ID of the ExplorationPage with `page-id`."- [page-id :- ms/PositiveInt]- (t2/select-one-fn :exploration_block_id :model/ExplorationPage :id page-id))+ (t2/select-one :model/ExplorationPage :id [:auto/param page-id]))(mu/defn page-id-for-key"The ID of the ExplorationPage of the given block, Card, dimension, and query type, or nil."@@ -390,26 +340,10 @@;;; ------------------------------------------------- Queries --------------------------------------------------(mu/defn query- "The ExplorationQuery with `query-id`, or nil."- [query-id :- ms/PositiveInt]- (t2/select-one :model/ExplorationQuery :id query-id))--(mu/defn query-thread-id-row- "The `:exploration_thread_id` row of the ExplorationQuery with `query-id`, or nil."- [query-id :- ms/PositiveInt]- (t2/select-one [:model/ExplorationQuery :exploration_thread_id] :id query-id))--(mu/defn query-thread-id- "The thread ID of the ExplorationQuery with `query-id`."- [query-id :- ms/PositiveInt]- (t2/select-one-fn :exploration_thread_id :model/ExplorationQuery :id query-id))--(mu/defn finished-query-thread-id- "The thread ID of the ExplorationQuery with `query-id` if it has finished, or nil."+(mu/defn exploration-query :- [:maybe ::explorations.schema/exploration-query]+ "The ::explorations.schema/exploration-query with `query-id`, or nil."[query-id :- ms/PositiveInt]- (t2/select-one-fn :exploration_thread_id :model/ExplorationQuery- :id query-id :status [:in ["done" "error" "canceled"]]))+ (t2/select-one :model/ExplorationQuery :id [:auto/param query-id]))(mu/defn runnable-query"The pending ExplorationQuery with `query-id` on an uncanceled thread, or nil."@@ -582,11 +516,6 @@;;; ---------------------------------------------- Stored results -----------------------------------------------(mu/defn stored-result- "The StoredResult with `stored-result-id`, or nil."- [stored-result-id :- ms/PositiveInt]- (t2/select-one :model/StoredResult :id stored-result-id))-(mu/defn orphaned-stored-result-ids"Up to `limit` `:id` rows of the StoredResults created before `created-before` that no ExplorationQueryResult orCard embed reaches, in ID order."@@ -693,14 +622,6 @@;;; ------------------------------------------------ Documents -------------------------------------------------(mu/defn summary-document-columns- "The wire-shape columns of the Document with `document-id`, or nil."- [document-id :- ms/PositiveInt]- (t2/select-one [:model/Document- :id :name :exploration_id :creator_id :content_type- :created_at :updated_at :archived :is_placeholder]- :id document-id))-(mu/defn summary-documents-for-explorations"The wire-shape columns of the Summary Documents of the Explorations with `exploration-ids`, oldest first."[exploration-ids :- [:sequential ms/PositiveInt]]@@ -715,11 +636,6 @@[exploration-id :- ms/PositiveInt](t2/select-one :model/Document :exploration_id exploration-id :archived false))-(mu/defn document-exploration-id- "The Exploration ID of the Document with `document-id`."- [document-id :- ms/PositiveInt]- (t2/select-one-fn :exploration_id :model/Document :id document-id))-(mu/defn insert-document!"Insert `document`."[document :- ::documents.schema/document.update]@@ -750,26 +666,11 @@;;; ------------------------------------------------ Other models -------------------------------------------------(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(mu/defn card-names"The ID and name of the Cards with `card-ids`."[card-ids :- [:sequential ::lib.schema.id/card]](t2/select [:model/Card :id :name] :id [:in card-ids]))-(mu/defn card-description- "The description of the Card with `card-id`."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :description :model/Card :id card-id))--(mu/defn card-presentation- "The name, description, display, and visualization settings of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one [:model/Card :name :description :display :visualization_settings] :id card-id))-(mu/defn card-queries"The query-relevant columns of the Cards with `card-ids`."[card-ids :- [:sequential ::lib.schema.id/card]]@@ -820,11 +721,6 @@[segment-ids :- [:set ::lib.schema.id/segment]](t2/select-pk->fn :name [:model/Segment :id :name] :id [:in segment-ids]))-(mu/defn segment-name- "The name of the Segment with `segment-id`."- [segment-id :- ::lib.schema.id/segment]- (t2/select-one-fn :name :model/Segment :id segment-id))-(mu/defn user-summaries-by-id"A map of ID to the ID, email, and names of the Users with `user-ids`."[user-ids :- [:sequential ::lib.schema.id/user]]diff --git a/src/metabase/explorations/derived_perms.clj b/src/metabase/explorations/derived_perms.cljindex 04827c11b17..98a079c4fdc 100644--- a/src/metabase/explorations/derived_perms.clj+++ b/src/metabase/explorations/derived_perms.clj@@ -20,6 +20,7 @@(:require[clojure.set :as set][metabase.api.common :as api]+ [metabase.documents.db :as documents.db][metabase.explorations.db :as explorations.db][metabase.lib-be.core :as lib-be][metabase.queries.core :as queries]@@ -193,7 +194,7 @@(:id document)(exploration-content-visible?- (explorations.db/document-exploration-id (:id document)))+ (:exploration_id (documents.db/document (:id document)))):elsefalse))diff --git a/src/metabase/explorations/models/exploration_block.clj b/src/metabase/explorations/models/exploration_block.cljindex 79da67b0a2b..47366b94431 100644--- a/src/metabase/explorations/models/exploration_block.clj+++ b/src/metabase/explorations/models/exploration_block.clj@@ -14,6 +14,7 @@[metabase.lib.schema.parameter :as lib.schema.parameter][metabase.metrics.core :as metrics][metabase.models.interface :as mi]+ [metabase.util :as u][methodical.core :as methodical][toucan2.core :as t2]))@@ -36,8 +37,19 @@(:semantic-type dim) (update :semantic-type keyword)))dimensions)))+(defn- stringify-dim-types+ "Write `effective-type`/`semantic-type` as namespaced strings (`\"type/Date\"`), the shape [[keywordize-dim-types]]+ reads back."+ [dimensions]+ (when dimensions+ (mapv (fn [dim]+ (cond-> dim+ (keyword? (:effective-type dim)) (update :effective-type u/qualified-name)+ (keyword? (:semantic-type dim)) (update :semantic-type u/qualified-name)))+ dimensions)))+(def ^:private transform-dimensions- {:in (:in mi/transform-json)+ {:in (comp (:in mi/transform-json) stringify-dim-types):out (comp keywordize-dim-types (:out mi/transform-json))})(defn- normalize-explore-filters@@ -88,14 +100,14 @@([instance](mi/can-read? :model/ExplorationThread (:exploration_thread_id instance)))([_model pk]- (when-let [g (explorations.db/block-thread-id-row pk)]+ (when-let [g (explorations.db/exploration-block pk)](mi/can-read? :model/ExplorationThread (:exploration_thread_id g)))))(defmethod mi/can-write? :model/ExplorationBlock([instance](mi/can-write? :model/ExplorationThread (:exploration_thread_id instance)))([_model pk]- (when-let [g (explorations.db/block-thread-id-row pk)]+ (when-let [g (explorations.db/exploration-block pk)](mi/can-write? :model/ExplorationThread (:exploration_thread_id g)))))(defn dimension-labeldiff --git a/src/metabase/explorations/models/exploration_page.clj b/src/metabase/explorations/models/exploration_page.cljindex 286f1032efd..8f3422789e3 100644--- a/src/metabase/explorations/models/exploration_page.clj+++ b/src/metabase/explorations/models/exploration_page.clj@@ -18,12 +18,12 @@([instance](mi/can-read? :model/ExplorationBlock (:exploration_block_id instance)))([_model pk]- (when-let [p (explorations.db/page-block-id-row pk)]+ (when-let [p (explorations.db/exploration-page pk)](mi/can-read? :model/ExplorationBlock (:exploration_block_id p)))))(defmethod mi/can-write? :model/ExplorationPage([instance](mi/can-write? :model/ExplorationBlock (:exploration_block_id instance)))([_model pk]- (when-let [p (explorations.db/page-block-id-row pk)]+ (when-let [p (explorations.db/exploration-page pk)](mi/can-write? :model/ExplorationBlock (:exploration_block_id p)))))diff --git a/src/metabase/explorations/models/exploration_query.clj b/src/metabase/explorations/models/exploration_query.cljindex 3007ccbcf5c..de4644ee77c 100644--- a/src/metabase/explorations/models/exploration_query.clj+++ b/src/metabase/explorations/models/exploration_query.clj@@ -1,6 +1,7 @@(ns metabase.explorations.models.exploration-query(:require[metabase.explorations.db :as explorations.db]+ [metabase.lib-be.core :as lib-be][metabase.models.interface :as mi][metabase.permissions.core :as perms][metabase.util :as u]@@ -16,7 +17,7 @@(t2/deftransforms :model/ExplorationQuery{:visualization_settings mi/transform-json- :dataset_query mi/transform-json+ :dataset_query lib-be/transform-query:params mi/transform-json:data_access_token perms/data-access-token-transform})@@ -24,14 +25,14 @@([instance](mi/can-read? :model/ExplorationThread (:exploration_thread_id instance)))([_model pk]- (when-let [q (explorations.db/query-thread-id-row pk)]+ (when-let [q (explorations.db/exploration-query pk)](mi/can-read? :model/ExplorationThread (:exploration_thread_id q)))))(defmethod mi/can-write? :model/ExplorationQuery([instance](mi/can-write? :model/ExplorationThread (:exploration_thread_id instance)))([_model pk]- (when-let [q (explorations.db/query-thread-id-row pk)]+ (when-let [q (explorations.db/exploration-query pk)](mi/can-write? :model/ExplorationThread (:exploration_thread_id q)))))(defn- hydrate-score-from-result [score-key queries]diff --git a/src/metabase/explorations/models/exploration_query_result.clj b/src/metabase/explorations/models/exploration_query_result.cljindex 42c3787d9f8..2910d963b7f 100644--- a/src/metabase/explorations/models/exploration_query_result.clj+++ b/src/metabase/explorations/models/exploration_query_result.clj@@ -6,6 +6,7 @@[metabase.interestingness.core :as interestingness][metabase.models.interface :as mi][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.query-permissions.core :as query-perms][metabase.query-processor.core :as qp][metabase.util.i18n :refer [tru]]@@ -39,7 +40,7 @@still pending/errored)."[eq-id](when-let [sr-id (explorations.db/query-result-stored-result-id eq-id)]- (explorations.db/stored-result sr-id)))+ (queries.db/stored-result sr-id)))(defn- deserialize-stored-result"Inverse of [[qp/do-with-serialization]] for a stored_result's@@ -69,10 +70,10 @@[eq-ids](mapv(fn [eq-id]- (let [eq (api/check-404 (t2/hydrate (explorations.db/query eq-id) :segment_name))+ (let [eq (api/check-404 (t2/hydrate (explorations.db/exploration-query eq-id) :segment_name))eqr (api/check-404 (explorations.db/query-result eq-id))- sr (api/check-404 (explorations.db/stored-result (:stored_result_id eqr)))- qp-result (api/check-404 (deserialize-stored-result (:result_data sr)))]+ sr (api/check-404 (queries.db/stored-result (:stored_result_id eqr)))+ qp-result (api/check-404 (deserialize-stored-result (queries.db/stored-result-data (:id sr))))]{:eq eq :eqr eqr :sr sr :qp-result qp-result}))eq-ids))@@ -131,7 +132,7 @@first-eq (:eq (first eq-results))first-sr (:sr (first eq-results))src-card (when-let [card-id (:card_id first-eq)]- (explorations.db/card-presentation card-id))+ (queries.db/card card-id))composite-qp (composite/combine eq-results (or visualization-settings {}))dataset-query (:dataset_query first-eq)creator-id (:id creator)]diff --git a/src/metabase/explorations/models/exploration_thread.clj b/src/metabase/explorations/models/exploration_thread.cljindex 4f9134ef25e..289313e4849 100644--- a/src/metabase/explorations/models/exploration_thread.clj+++ b/src/metabase/explorations/models/exploration_thread.clj@@ -23,14 +23,14 @@([instance](mi/can-read? :model/Exploration (:exploration_id instance)))([_model pk]- (when-let [thread (explorations.db/thread-exploration-id-row pk)]+ (when-let [thread (explorations.db/exploration-thread pk)](mi/can-read? :model/Exploration (:exploration_id thread)))))(defmethod mi/can-write? :model/ExplorationThread([instance](mi/can-write? :model/Exploration (:exploration_id instance)))([_model pk]- (when-let [thread (explorations.db/thread-exploration-id-row pk)]+ (when-let [thread (explorations.db/exploration-thread pk)](mi/can-write? :model/Exploration (:exploration_id thread)))))(methodical/defmethod t2/batched-hydrate [:model/ExplorationThread :timelines]diff --git a/src/metabase/explorations/query_plan.clj b/src/metabase/explorations/query_plan.cljindex 281e88a648f..364c970e260 100644--- a/src/metabase/explorations/query_plan.clj+++ b/src/metabase/explorations/query_plan.clj@@ -282,7 +282,7 @@(defn- thread-prompt-for[thread-id]- (explorations.db/thread-prompt thread-id))+ (:prompt (explorations.db/exploration-thread thread-id)))(defn- creator-id-for-thread[thread-id]@@ -415,4 +415,4 @@(defn debug-transcript"Return the persisted query-plan transcript for `thread-id`."[thread-id]- (explorations.db/thread-transcript thread-id))+ (:query_plan_transcript (explorations.db/exploration-thread thread-id)))diff --git a/src/metabase/explorations/query_plan/context.clj b/src/metabase/explorations/query_plan/context.cljindex 85c28ebabfc..9599a1dcc05 100644--- a/src/metabase/explorations/query_plan/context.clj+++ b/src/metabase/explorations/query_plan/context.clj@@ -20,6 +20,7 @@[metabase.lib-be.core :as lib-be][metabase.lib.core :as lib][metabase.metrics.core :as metrics]+ [metabase.queries.db :as queries.db][metabase.util :as u]))(set! *warn-on-reflection* true)@@ -348,7 +349,7 @@`ExplorationBlock`, reached via the row's `ExplorationPage`, not fromper-thread metric/dimension tables. The runner calls this per claimed row."[{:keys [card_id dimension_id segment_id params page_id]}]- (let [card (explorations.db/card card_id)+ (let [card (queries.db/card card_id)block (when page_id(explorations.db/block-for-page page_id))metric (some #(when (= card_id (:card_id %)) %) (:metrics block))diff --git a/src/metabase/explorations/runner.clj b/src/metabase/explorations/runner.cljindex d860257179d..5cc9ea3656b 100644--- a/src/metabase/explorations/runner.clj+++ b/src/metabase/explorations/runner.clj@@ -20,9 +20,11 @@[metabase.interestingness.core :as interestingness][metabase.lib.core :as lib][metabase.permissions.core :as perms]+ [metabase.queries.db :as queries.db][metabase.query-permissions.core :as query-perms][metabase.query-processor.core :as qp][metabase.request.core :as request]+ [metabase.segments.db :as segments.db][metabase.util.log :as log][toucan2.core :as t2])(:import@@ -189,7 +191,7 @@(defn- exploration-id"Walk EQ → ExplorationThread → Exploration.id for recording the stored_result_use reference."[exploration-query]- (explorations.db/thread-exploration-id (:exploration_thread_id exploration-query)))+ (:exploration_id (explorations.db/exploration-thread (:exploration_thread_id exploration-query))))(defn- variant-note"Human phrase for a chart's breakdown variant + params, or nil for the plain `default`@@ -215,7 +217,7 @@Returns nil for a plain unsegmented default breakdown (nothing to call out)."[row](let [segment-name (when-let [sid (:segment_id row)]- (explorations.db/segment-name sid))+ (:name (segments.db/segment sid)))variant (variant-note (:query_type row) (:params row))parts (cond-> []variant (conj variant)@@ -231,7 +233,7 @@charts that won't be scored."[exploration-query]{:card-description (when-let [card-id (:card_id exploration-query)]- (some-> (explorations.db/card-description card-id)+ (some-> (:description (queries.db/card card-id))str/trimnot-empty)):sql (contextual-interestingness/dataset-query->sql (:dataset_query exploration-query))})@@ -257,7 +259,7 @@(if (nil? creator-id)(log/warnf "Skipping contextual interestingness for ExplorationQuery %d: no creator-id on exploration"(:id exploration-query))- (let [prompt (explorations.db/thread-prompt thread-id)]+ (let [prompt (:prompt (explorations.db/exploration-thread thread-id))](when-not (str/blank? prompt)(let [{:keys [card-description sql]} (build-score-context exploration-query)](request/with-current-user creator-id@@ -372,7 +374,9 @@(when (persist-query-result! row started computed)(record-query-outcome! "done"))(:exploration_thread_id row))))- (explorations.db/finished-query-thread-id query-id)))+ (let [query (explorations.db/exploration-query query-id)]+ (when (contains? #{"done" "error" "canceled"} (:status query))+ (:exploration_thread_id query)))))(defn fail-query!"Terminally mark `query-id` as `error` with `message`, the user-visible failure state the UI@@ -380,7 +384,7 @@No-ops on a row that is no longer `pending` (a later delivery succeeded, or it was canceled)."[query-id message]- (let [thread-id (explorations.db/query-thread-id query-id)]+ (let [thread-id (:exploration_thread_id (explorations.db/exploration-query query-id))](when (pos? (explorations.db/fail-pending-query! query-id message (OffsetDateTime/now)))(record-query-outcome! "error"))thread-id))@@ -397,7 +401,7 @@(defn plan-thread!"Run the LLM planner for `thread-id`, materializing its `ExplorationQuery` rows. Idempotent for MQ."[thread-id]- (let [thread (explorations.db/thread-planning-state thread-id)+ (let [thread (explorations.db/exploration-thread thread-id)planned? (cond;; `restart` deletes and re-creates a thread's work; a message for a thread that;; no longer exists is a no-op.diff --git a/src/metabase/explorations/schema.clj b/src/metabase/explorations/schema.cljindex cd87bc3a792..9efc4f50cda 100644--- a/src/metabase/explorations/schema.clj+++ b/src/metabase/explorations/schema.clj@@ -2,7 +2,8 @@"Malli schemas for the explorations module."(:require[metabase.interestingness.chart.types :as chart.types]- [metabase.lib.schema :as lib.schema]+ [metabase.lib-be.schema :as lib-be.schema]+ [metabase.lib.schema.common :as lib.schema.common][metabase.lib.schema.id :as lib.schema.id][metabase.metrics.core :as metrics][metabase.util.malli.registry :as mr]@@ -58,8 +59,8 @@[:map {:closed true}[:dimension-id ms/UUIDString][:display-name {:optional true} [:maybe :string]]- [:effective-type {:optional true} [:maybe :string]]- [:semantic-type {:optional true} [:maybe :string]]])+ [:effective-type {:optional true} [:maybe ::lib.schema.common/base-type]]+ [:semantic-type {:optional true} [:maybe ::lib.schema.common/semantic-or-relation-type]]])(mr/def ::exploration-block"A ExplorationBlock as selected from the app DB: every column of `:exploration_block`."@@ -104,8 +105,8 @@ms/VisualizationSettings)(mr/def ::exploration-query.dataset-query- "The `:dataset_query` column of a ExplorationQuery, decoded."- ::lib.schema/query)+ "The `:dataset_query` a ExplorationQuery create or update accepts: an MBQL query, possibly legacy, never empty."+ ::lib-be.schema/maybe-legacy-query)(mr/def ::exploration-query.params"The `:params` column of a ExplorationQuery, decoded."@@ -119,11 +120,13 @@::exploration-thread.data-access-token)(mr/def ::exploration-query- "A ExplorationQuery as selected from the app DB: every column of `:exploration_query`."+ "A ExplorationQuery as selected from the app DB: every column of `:exploration_query`, with an unreadable+ `:dataset_query` read back as an empty query."[:merge::exploration-query.update[:map {:closed true}- [:id ms/PositiveInt]]])+ [:id ms/PositiveInt]+ [:dataset_query {:optional true} [:maybe ::lib-be.schema/maybe-legacy-or-empty-query]]]])(mr/def ::exploration-query.update"What an update (or insert) of a ExplorationQuery accepts: every column of `:exploration_query` except `id`, all optional."diff --git a/src/metabase/glossary/core.clj b/src/metabase/glossary/core.cljindex 4db1c677597..29beeaac619 100644--- a/src/metabase/glossary/core.clj+++ b/src/metabase/glossary/core.clj@@ -36,9 +36,9 @@[user-id :- ::lib.schema.id/userid :- ms/PositiveInt{:keys [term definition]} :- ::entry-fields]- (when-let [previous (glossary.db/glossary-entry id)]+ (when-let [previous (glossary.db/glossary id)](glossary.db/update-glossary-entry! id term definition)- (let [entry (glossary.db/glossary-entry id)]+ (let [entry (glossary.db/glossary id)](events/publish-event! :event/glossary-update {:object entry:previous-object previous:user-id user-id})@@ -49,7 +49,7 @@deleted entry, or nil when no entry has `id`."[user-id :- ::lib.schema.id/userid :- ms/PositiveInt]- (when-let [entry (glossary.db/glossary-entry id)]+ (when-let [entry (glossary.db/glossary id)](glossary.db/delete-glossary-entry! id)(events/publish-event! :event/glossary-delete {:object entry :user-id user-id})entry))diff --git a/src/metabase/glossary/db.clj b/src/metabase/glossary/db.cljindex 6f8295e8762..3af4d1e6173 100644--- a/src/metabase/glossary/db.clj+++ b/src/metabase/glossary/db.clj@@ -25,10 +25,10 @@[row :- ::glossary.schema/glossary.update](t2/insert-returning-instance! :model/Glossary row))-(mu/defn glossary-entry- "The Glossary entry with `id`, or nil."+(mu/defn glossary :- [:maybe ::glossary.schema/glossary]+ "The ::glossary.schema/glossary with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Glossary :id id))+ (t2/select-one :model/Glossary :id [:auto/param id]))(mu/defn update-glossary-entry!"Set the term and definition of the Glossary entry with `id`."diff --git a/src/metabase/indexed_entities/db.clj b/src/metabase/indexed_entities/db.cljindex 149a33412bc..5978a0533cf 100644--- a/src/metabase/indexed_entities/db.clj+++ b/src/metabase/indexed_entities/db.clj@@ -4,15 +4,14 @@(:require[malli.util :as mut][metabase.indexed-entities.schema :as indexed-entities.schema]- [metabase.lib.schema.id :as lib.schema.id][metabase.util.malli :as mu][metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(mu/defn model-index- "The ModelIndex with `id`, or nil."+(mu/defn model-index :- [:maybe ::indexed-entities.schema/model-index]+ "The ::indexed-entities.schema/model-index with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/ModelIndex :id id))+ (t2/select-one :model/ModelIndex :id [:auto/param id]))(mu/defn model-indexes-for-model"The ModelIndexes of the model Card with `model-id`."@@ -34,11 +33,6 @@[id :- ms/PositiveInt](t2/delete! :model/ModelIndex id))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(mu/defn model-index-values"The ModelIndexValues of the ModelIndex with `model-index-id`."[model-index-id :- ms/PositiveInt]diff --git a/src/metabase/indexed_entities/models/model_index.clj b/src/metabase/indexed_entities/models/model_index.cljindex 10698d86fbc..1b7e346c019 100644--- a/src/metabase/indexed_entities/models/model_index.clj+++ b/src/metabase/indexed_entities/models/model_index.clj@@ -12,6 +12,7 @@[metabase.lib.schema.common :as lib.schema.common][metabase.models.interface :as mi][metabase.permissions.core :as perms]+ [metabase.queries.db :as queries.db][metabase.query-processor.core :as qp][metabase.search.core :as search][metabase.sync.schedules :as sync.schedules]@@ -91,7 +92,7 @@the record with that primary key."[model-index :- ::indexed-entities.schema/model-indexpk :- [:maybe :int]]- (let [model (indexed-entities.db/card (:model_id model-index))+ (let [model (queries.db/card (:model_id model-index))fix (mu/fn [field-ref :- ::mbql.s/FieldOrExpressionRefbase-type :- ::lib.schema.common/base-type];; stored value/pk refs are legacy MBQL; normalize as legacy before usediff --git a/src/metabase/indexed_entities/task/index_values.clj b/src/metabase/indexed_entities/task/index_values.cljindex 142f70931fc..86c66ec58ed 100644--- a/src/metabase/indexed_entities/task/index_values.clj+++ b/src/metabase/indexed_entities/task/index_values.clj@@ -7,6 +7,7 @@[metabase.driver :as driver][metabase.indexed-entities.db :as indexed-entities.db][metabase.indexed-entities.models.model-index :as model-index]+ [metabase.queries.db :as queries.db][metabase.query-processor.timezone :as qp.timezone][metabase.task.core :as task][metabase.util :as u]@@ -34,7 +35,7 @@[model-index-id](let [model-index (indexed-entities.db/model-index model-index-id)model (when model-index- (indexed-entities.db/card (:model_id model-index)))]+ (queries.db/card (:model_id model-index)))](if (should-deindex? model model-index)(u/ignore-exceptions(let [trigger-key (model-index/trigger-key model-index-id)]diff --git a/src/metabase/indexes/db.clj b/src/metabase/indexes/db.cljindex 6e65ae2dc9a..ad6dd9f9e7a 100644--- a/src/metabase/indexes/db.clj+++ b/src/metabase/indexes/db.clj@@ -2,11 +2,17 @@"Application database queries for the indexes module. Every function here is a direct Toucan 2 call with noadditional logic, so no other namespace in the module runs a query itself (model definitions still use `toucan2.core`)."(:require+ [metabase.indexes.schema :as indexes.schema][metabase.lib.schema.id :as lib.schema.id][metabase.util.malli :as mu][metabase.util.malli.schema :as ms][toucan2.core :as t2]))+(mu/defn table-index :- [:maybe ::indexes.schema/table-index]+ "The ::indexes.schema/table-index with `table-index-id`, or nil."+ [table-index-id :- ms/PositiveInt]+ (t2/select-one :model/TableIndex :id [:auto/param table-index-id]))+(def ^:private Status"Lifecycle states for a table index request. Mirrors `metabase.indexes.schema/statuses`; duplicated here (ratherthan required) to keep this namespace free of module-internal logic dependencies."@@ -43,11 +49,6 @@:status :delete-pending{:order-by [[:id :asc]]}))-(mu/defn applicable-table-index- "The TableIndex with `id` if it is not pending deletion, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/TableIndex :id id :status [:not= :delete-pending]))-(mu/defn table-index-with-status-exists?"Whether the Transform with `transform-id` has a TableIndex in one of `statuses`."[transform-id :- ::lib.schema.id/transformdiff --git a/src/metabase/indexes/models/table_index.clj b/src/metabase/indexes/models/table_index.cljindex 6c42eddd982..48d67d89fe6 100644--- a/src/metabase/indexes/models/table_index.clj+++ b/src/metabase/indexes/models/table_index.clj@@ -102,7 +102,9 @@(defn select-applicable-by-id"Fetch a single applicable index request by id."[id]- (indexes.db/applicable-table-index id))+ (let [table-index (indexes.db/table-index id)]+ (when-not (= :delete-pending (:status table-index))+ table-index)))(defn pending-changes-for-transform?"True when `transform-id` has index changes that require a full rebuild to apply."diff --git a/src/metabase/indexes_rest/api.clj b/src/metabase/indexes_rest/api.cljindex c93810a0881..158d391bb22 100644--- a/src/metabase/indexes_rest/api.clj+++ b/src/metabase/indexes_rest/api.clj@@ -9,6 +9,7 @@[metabase.api.macros :as api.macros][metabase.driver.util :as driver.u][metabase.indexes-rest.db :as indexes-rest.db]+ [metabase.indexes.db :as indexes.db][metabase.indexes.models.table-index :as table-index][metabase.indexes.reconcile :as reconcile][metabase.indexes.schema :as schema]@@ -90,7 +91,7 @@(api.macros/defendpoint :get "/request/:id" :- RequestIndex"Fetch a single index request (e.g. to poll its status)."[{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]]- (doto (api/check-404 (indexes-rest.db/table-index id))+ (doto (api/check-404 (indexes.db/table-index id))(read-check-owner!)))(api.macros/defendpoint :post "/request" :- RequestIndex@@ -138,7 +139,7 @@;; toucan2 has no instance-returning update, so re-select; in a tx so we return exactly what we wrote.(t2/with-transaction [_conn](indexes-rest.db/set-table-index-structured! id structured)- (indexes-rest.db/table-index id))))+ (indexes.db/table-index id))))#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/request/:id"diff --git a/src/metabase/indexes_rest/db.clj b/src/metabase/indexes_rest/db.cljindex 83484c14f21..c917281e2c4 100644--- a/src/metabase/indexes_rest/db.clj+++ b/src/metabase/indexes_rest/db.clj@@ -13,11 +13,6 @@[database-id :- ::lib.schema.id/database](t2/exists? :model/Database :id database-id))-(mu/defn table-index- "The TableIndex with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/TableIndex :id id))-(mu/defn insert-table-index!"Insert the TableIndex `row` and return the inserted instance."[row :- ::indexes.schema/table-index.update]diff --git a/src/metabase/lib_metric/db.clj b/src/metabase/lib_metric/db.cljindex 9ed565f6e38..d66a6f3ab36 100644--- a/src/metabase/lib_metric/db.clj+++ b/src/metabase/lib_metric/db.clj@@ -14,16 +14,6 @@[field-ids :- [:set ::lib.schema.id/field]](t2/select :model/Field :id [:in field-ids] {:from [(warehouse-schema-overlay/field-query)]}))-(mu/defn card-table-and-database-id- "The `:table_id` and `:database_id` of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one [:model/Card :table_id :database_id] card-id))--(mu/defn table-database-id- "The Database id of the Table with `table-id`, or nil."- [table-id :- ::lib.schema.id/table]- (t2/select-one-fn :db_id :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(defn- metric-where"The `:where` map for the metric Cards picked out by `metadata-spec` (its `:id`, `:name`,`:table-ids`, and `:card-ids` keys), or unarchived ones when neither `:id` nor `:name` is given."diff --git a/src/metabase/lib_metric/dimension/jvm.clj b/src/metabase/lib_metric/dimension/jvm.cljindex 3bdfce1c7b8..ea9ccb785c4 100644--- a/src/metabase/lib_metric/dimension/jvm.clj+++ b/src/metabase/lib_metric/dimension/jvm.clj@@ -9,6 +9,7 @@[metabase.lib-metric.metadata.provider :as lib-metric.provider][metabase.lib.core :as lib][metabase.lib.util :as lib.util]+ [metabase.queries.db :as queries.db][metabase.util.performance :as perf])(:import (java.util UUID)))@@ -129,7 +130,7 @@(lib-metric.provider/database-provider-for-table mp table-id))(when-let [card-id (lib.util/source-card-id query-with-mp)](when-let [{:keys [table_id database_id]}- (lib-metric.db/card-table-and-database-id card-id)]+ (queries.db/card card-id)](or (when table_id(lib-metric.provider/database-provider-for-table mp table_id))(when database_iddiff --git a/src/metabase/lib_metric/metadata/jvm.clj b/src/metabase/lib_metric/metadata/jvm.cljindex 667f6e4f158..bde558c1fb7 100644--- a/src/metabase/lib_metric/metadata/jvm.clj+++ b/src/metabase/lib_metric/metadata/jvm.clj@@ -14,7 +14,8 @@[metabase.lib.metadata.protocols :as lib.metadata.protocols][metabase.settings.core :as setting][metabase.util.malli :as mu]- [metabase.util.memoize :as memoize]))+ [metabase.util.memoize :as memoize]+ [metabase.warehouse-schema.db :as warehouse-schema.db]))(set! *warn-on-reflection* true)@@ -23,7 +24,7 @@[](memoize/lru(fn [table-id]- (lib-metric.db/table-database-id table-id))+ (:db_id (warehouse-schema.db/table table-id))):lru/threshold 1000))(defn- fetch-metricsdiff --git a/src/metabase/llm/context.clj b/src/metabase/llm/context.cljindex b430bf236ef..b9142b94d3e 100644--- a/src/metabase/llm/context.clj+++ b/src/metabase/llm/context.clj@@ -9,7 +9,8 @@[metabase.metabot.metadata-perms :as metabot.perms][metabase.models.interface :as mi][metabase.sql-tools.core :as sql-tools]- [metabase.util.log :as log]))+ [metabase.util.log :as log]+ [metabase.warehouses.db :as warehouses.db]))(set! *warn-on-reflection* true)@@ -26,7 +27,7 @@[database-id sql-string](if (and database-id (seq sql-string))(try- (let [driver (llm.db/database-engine database-id)+ (let [driver (:engine (warehouses.db/database database-id))tables (sql-tools/referenced-tables-raw driver sql-string)](if (seq tables)(let [matched-tables (llm.db/active-tables-matching database-id tables)]diff --git a/src/metabase/llm/db.clj b/src/metabase/llm/db.cljindex 46205b4e840..2460b548d8a 100644--- a/src/metabase/llm/db.clj+++ b/src/metabase/llm/db.clj@@ -9,11 +9,6 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn database-engine- "The engine of the Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one-fn :engine :model/Database :id database-id))-(defn- table-match-clause"Match a Table by name and, when given, schema, both case-insensitively."[{:keys [schema table]}]diff --git a/src/metabase/mcp/db.clj b/src/metabase/mcp/db.cljindex 04b3c6d46d1..c5c9cec63e1 100644--- a/src/metabase/mcp/db.clj+++ b/src/metabase/mcp/db.clj@@ -16,6 +16,11 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))+(mu/defn mcp-session-log :- [:maybe ::mcp.schema/mcp-session-log]+ "The ::mcp.schema/mcp-session-log with `mcp-session-log-id`, or nil."+ [mcp-session-log-id :- :string]+ (t2/select-one :model/McpSessionLog :id [:auto/param mcp-session-log-id]))+(defn select-one-by-id"The `model` row with primary key `id`, or nil. `id` must already be an integer - ids arriving from an agentare resolved to one before they reach here, so a string entity_id is a bug rather than a lookup."@@ -37,17 +42,6 @@[where](t2/select :model/User {:where where}))-(defn table-by-id- "The Table with `table-id`, or nil. Unlike [[select-one-by-id]], a nil `table-id` is answered with nil- rather than refused — callers reach here with a column value, not with an id an agent supplied."- [table-id]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))--(defn field-types- "The `base_type` and `effective_type` of the Field with `field-id`, or nil."- [field-id]- (t2/select-one [:model/Field :base_type :effective_type] :id field-id {:from [(warehouse-schema-overlay/field-query)]}))-(defn nullable-fields-with-fingerprints"The Fields among `field-ids` the warehouse declares nullable, carrying their `:fingerprint`.`field-ids` is expected non-empty — an empty `:in` is a SQL error rather than an empty result,@@ -63,11 +57,6 @@[user-id](t2/exists? :model/User :id user-id :is_active true))-(defn dashboard-parameters- "The `parameters` of the Dashboard with `dashboard-id`, or nil."- [dashboard-id]- (t2/select-one-fn :parameters :model/Dashboard :id dashboard-id))-(defn browsable-database"The Database with `database-id` restricted by the HoneySQL `browsable-where` clause, or nil.@@ -239,11 +228,6 @@[card](t2/hydrate card [:moderation_reviews :moderator_details]))-(defn notification-by-payload-type- "The Notification with `id` whose `payload_type` is `payload-type`, or nil."- [id payload-type]- (t2/select-one :model/Notification :id id :payload_type payload-type))-(defn subscription-pulse-exists?"Whether a Pulse with `pulse-id` exists and is a subscription — a nil `alert_condition` — rather than an alert."[pulse-id]diff --git a/src/metabase/mcp/v2/tools/alert.clj b/src/metabase/mcp/v2/tools/alert.cljindex 9b47755d5db..95ba8f01e95 100644--- a/src/metabase/mcp/v2/tools/alert.clj+++ b/src/metabase/mcp/v2/tools/alert.clj@@ -15,7 +15,6 @@[metabase.api.common :as api][metabase.channel.email.messages :as messages][metabase.channel.settings :as channel.settings]- [metabase.mcp.db :as mcp.db][metabase.mcp.scope :as mcp.scope][metabase.mcp.v2.common :as common][metabase.mcp.v2.message :as message]@@ -28,6 +27,7 @@[metabase.metabot.scope :as metabot.scope][metabase.models.interface :as mi][metabase.notification.api :as notification.api]+ [metabase.notification.db :as notification.db][metabase.util :as u][metabase.util.cron :as u.cron][toucan2.core :as t2]))@@ -323,8 +323,10 @@[id](when-not (int? id)(common/throw-teaching-error (message/msg ["Alerts take a numeric id — they have no entity_id."])))- (let [notification (mcp.db/notification-by-payload-type id :notification/card)]- (when-not (and notification (mi/can-read? notification) (mi/can-write? notification))+ (let [notification (when (pos-int? id) (notification.db/notification id))]+ (when-not (and (= :notification/card (:payload_type notification))+ (mi/can-read? notification)+ (mi/can-write? notification))(common/throw-not-found :alert id))(notification.api/get-notification id)))diff --git a/src/metabase/mcp/v2/tools/content.clj b/src/metabase/mcp/v2/tools/content.cljindex 27d017f1e80..bf441832f29 100644--- a/src/metabase/mcp/v2/tools/content.clj+++ b/src/metabase/mcp/v2/tools/content.clj@@ -36,10 +36,12 @@[metabase.metabot.scope :as metabot.scope][metabase.metrics.core :as metrics][metabase.models.interface :as mi]+ [metabase.notification.db :as notification.db][metabase.pulse.core :as pulse][metabase.queries.core :as queries][metabase.util :as u][metabase.util.log :as log]+ [metabase.warehouse-schema.db :as warehouse-schema.db][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -180,7 +182,7 @@or nil when the stored definition can't be serialized."[kind row](try- (let [table (mcp.db/table-by-id (:table_id row))+ (let [table (warehouse-schema.db/table (:table_id row))mp (lib-be/application-database-metadata-provider (:db_id table))metadata (case kind:measure (lib.metadata/measure mp (:id row))@@ -396,6 +398,14 @@;;; ----------------------------------------------------- alert ----------------------------------------------------+(defn- notification-of-type+ "The Notification with `id` if its payload type is `payload-type`, or nil."+ [id payload-type]+ (when (pos-int? id)+ (let [notification (notification.db/notification id)]+ (when (= payload-type (:payload_type notification))+ notification))))+(defn- fetch-notification"Fetch + read-check one notification row of `payload-type` by numeric id. Notifications haveno entity_id column, so entity_id strings are a teaching error for these types."@@ -403,7 +413,7 @@(when-not (int? id-or-eid)(common/throw-teaching-error(message/msg ["%s take a numeric id — they have no entity_id."] plural)))- (let [notification (mcp.db/notification-by-payload-type id-or-eid payload-type)]+ (let [notification (notification-of-type id-or-eid payload-type)](when-not (and notification (mi/can-read? notification))(common/throw-not-found (keyword tool-type) id-or-eid))(projections/notification-row@@ -435,7 +445,7 @@(projections/subscription-row (redaction/redact-pulse pulse-row))(common/throw-not-found :subscription id-or-eid)))(or (when (int? id-or-eid)- (let [notification (mcp.db/notification-by-payload-type id-or-eid :notification/dashboard)]+ (let [notification (notification-of-type id-or-eid :notification/dashboard)](when (and notification (mi/can-read? notification))(projections/notification-row(redaction/hydrate-and-redact-notification notification)))))diff --git a/src/metabase/mcp/v2/tools/definitions.clj b/src/metabase/mcp/v2/tools/definitions.cljindex 31fbe98e272..23866288f4a 100644--- a/src/metabase/mcp/v2/tools/definitions.clj+++ b/src/metabase/mcp/v2/tools/definitions.clj@@ -12,7 +12,6 @@[medley.core :as m][metabase.lib-be.core :as lib-be][metabase.lib.core :as lib]- [metabase.mcp.db :as mcp.db][metabase.mcp.v2.common :as common][metabase.mcp.v2.message :as message][metabase.mcp.v2.projections :as projections]@@ -20,7 +19,8 @@[metabase.mcp.v2.registry :as registry][metabase.mcp.v2.resolve :as v2.resolve][metabase.mcp.v2.write :as v2.write]- [metabase.metabot.scope :as metabot.scope]))+ [metabase.metabot.scope :as metabot.scope]+ [metabase.warehouse-schema.db :as warehouse-schema.db]))(set! *warn-on-reflection* true)@@ -368,7 +368,7 @@(fn [definition](prepare-definition:segment definition- (mcp.db/table-by-id (:table_id segment)))))]+ (warehouse-schema.db/table (:table_id segment)))))](-> (run-domain-write #(update-segment! (:id segment) body))(write-result :segment)(as-> row (v2.write/readback token-scopes [metabot.scope/agent-content-read] row nil))@@ -437,7 +437,7 @@(fn [definition](prepare-definition:measure definition- (mcp.db/table-by-id (:table_id measure)))))]+ (warehouse-schema.db/table (:table_id measure)))))](-> (run-domain-write #(update-measure! (:id measure) body))(write-result :measure)(as-> row (v2.write/readback token-scopes [metabot.scope/agent-content-read] row nil))diff --git a/src/metabase/mcp/v2/tools/parameters.clj b/src/metabase/mcp/v2/tools/parameters.cljindex b8feb5af050..2fd52d0d2a2 100644--- a/src/metabase/mcp/v2/tools/parameters.clj+++ b/src/metabase/mcp/v2/tools/parameters.clj@@ -28,7 +28,6 @@(:require[clojure.set :as set][clojure.string :as str]- [metabase.mcp.db :as mcp.db][metabase.mcp.v2.common :as common][metabase.mcp.v2.message :as message][metabase.mcp.v2.registry :as registry]@@ -43,6 +42,7 @@[metabase.query-processor.parameters.dates :as params.dates][metabase.util :as u][metabase.util.malli.registry :as mr]+ [metabase.warehouse-schema.db :as warehouse-schema.db][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -87,7 +87,7 @@which `lib-be/instance->metadata` carries over from the Field's `effective_type` (`base_type` whenunset)."[field-id]- (let [{:keys [base_type effective_type]} (mcp.db/field-types field-id)]+ (let [{:keys [base_type effective_type]} (warehouse-schema.db/field field-id)](isa? (or effective_type base_type) :type/Temporal)))(defn- parses-as-date?diff --git a/src/metabase/mcp/v2/tools/subscription.clj b/src/metabase/mcp/v2/tools/subscription.cljindex e79da592654..e72940b6750 100644--- a/src/metabase/mcp/v2/tools/subscription.clj+++ b/src/metabase/mcp/v2/tools/subscription.clj@@ -18,6 +18,7 @@[medley.core :as m][metabase.api.common :as api][metabase.channel.settings :as channel.settings]+ [metabase.dashboards.db :as dashboards.db][metabase.mcp.db :as mcp.db][metabase.mcp.scope :as mcp.scope][metabase.mcp.v2.common :as common]@@ -365,7 +366,7 @@(assoc :parameters(resolve-parametersparameters- (mcp.db/dashboard-parameters (:dashboard_id subscription))))+ (:parameters (dashboards.db/dashboard (:dashboard_id subscription)))))(channel-affecting? args)(assoc :channels (patched-channels (:channels subscription) channeldiff --git a/src/metabase/measures/db.clj b/src/metabase/measures/db.cljindex 8d2516c2907..a1f932c6d31 100644--- a/src/metabase/measures/db.clj+++ b/src/metabase/measures/db.clj@@ -21,10 +21,10 @@:description description:definition definition))-(mu/defn measure- "The Measure with `id`, or nil."+(mu/defn measure :- [:maybe ::measures.schema/measure]+ "The ::measures.schema/measure with `id`, or nil."[id :- ::lib.schema.id/measure]- (t2/select-one :model/Measure :id id))+ (t2/select-one :model/Measure :id [:auto/param id]))(mu/defn unarchived-measures"The unarchived Measures, in case-insensitive name order."@@ -42,16 +42,6 @@changes :- (mut/select-keys ::measures.schema/measure.update [:name :description :archived :definition])](t2/update! :model/Measure id changes))-(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))--(mu/defn table-perms-columns- "The Database id, schema, and id of the Table with `table-id`, or nil."- [table-id :- ::lib.schema.id/table]- (t2/select-one [:model/Table :db_id :schema :id] :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(mu/defn collections"The Collections with `collection-ids`."[collection-ids :- [:sequential ::lib.schema.id/collection]]diff --git a/src/metabase/measures/models/measure.clj b/src/metabase/measures/models/measure.cljindex b9c09786c6e..e0b896a8fde 100644--- a/src/metabase/measures/models/measure.clj+++ b/src/metabase/measures/models/measure.clj@@ -24,6 +24,7 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][methodical.core :as methodical][toucan2.core :as t2][toucan2.tools.hydrate :as t2.hydrate]))@@ -62,7 +63,7 @@(defmethod mi/can-read? :model/Measure([instance](let [table (or (:table instance)- (measures.db/table (:table_id instance)))]+ (warehouse-schema.db/table (:table_id instance)))](mi/can-read? table)))([_model pk](mi/can-read? (measures.db/measure pk))))@@ -72,7 +73,7 @@(defmethod mi/can-write? :model/Measure([instance](let [table (or (:table instance)- (measures.db/table (:table_id instance)))]+ (warehouse-schema.db/table (:table_id instance)))](and (or api/*is-superuser?*(and (api/entitled-data-analyst?)(perms/user-has-permission-for-table?@@ -90,7 +91,7 @@(defmethod mi/can-create? :model/Measure[_model instance](let [table (or (:table instance)- (measures.db/table (:table_id instance)))]+ (warehouse-schema.db/table (:table_id instance)))](and (or api/*is-superuser?*(and (api/entitled-data-analyst?)(perms/user-has-permission-for-table?@@ -175,7 +176,7 @@(defmethod mi/perms-objects-set :model/Measure[measure read-or-write](let [table (or (:table measure)- (measures.db/table-perms-columns (u/the-id (:table_id measure))))]+ (warehouse-schema.db/table (u/the-id (:table_id measure))))](mi/perms-objects-set table read-or-write)))(defn- normalize-definition-from-dbdiff --git a/src/metabase/measures/schema.clj b/src/metabase/measures/schema.cljindex 92ba1df1888..5c5c57c47c1 100644--- a/src/metabase/measures/schema.clj+++ b/src/metabase/measures/schema.clj@@ -23,7 +23,7 @@#(some? (lib/primary-source-table-id %))]]])(mr/def ::measure.definition- "The `:definition` column of a Measure, decoded."+ "The `:definition` a Measure create or update accepts: an MBQL query, possibly legacy, never empty."::lib-be.schema/maybe-legacy-query)(mr/def ::measure.dimension@@ -35,12 +35,13 @@::lib-metric.schema/dimension-mapping)(mr/def ::measure- "A Measure as selected from the app DB: every column of `:measure`, plus `:creator` and `:table` some callers- hydrate onto it."+ "A Measure as selected from the app DB: every column of `:measure`, with an unreadable `:definition` read back as an+ empty query, plus `:creator` and `:table` some callers hydrate onto it."[:merge::measure.update[:map {:closed true}[:id ms/PositiveInt]+ [:definition {:optional true} [:maybe ::lib-be.schema/maybe-legacy-or-empty-query]][:creator {:optional true} [:maybe :metabase.users.schema/user]][:table {:optional true} [:maybe :metabase.warehouse-schema.schema/table]]]])diff --git a/src/metabase/metabot/agent/links.clj b/src/metabase/metabot/agent/links.cljindex 6b0f1260340..7bc6583e5d4 100644--- a/src/metabase/metabot/agent/links.clj+++ b/src/metabase/metabot/agent/links.clj@@ -6,11 +6,13 @@[clojure.string :as str][metabase.lib.core :as lib][metabase.lib.schema]- [metabase.metabot.db :as metabot.db]+ [metabase.measures.db :as measures.db]+ [metabase.segments.db :as segments.db][metabase.system.core :as system][metabase.util.json :as json][metabase.util.log :as log]- [metabase.util.malli.registry :as mr]))+ [metabase.util.malli.registry :as mr]+ [metabase.warehouse-schema.db :as warehouse-schema.db]))(set! *warn-on-reflection* true)@@ -158,7 +160,7 @@unknown."[entity-id](let [measure-id (parse-long entity-id)- table-id (some-> measure-id metabot.db/measure-table-id)]+ table-id (some-> measure-id measures.db/measure :table_id)](if table-id(str "/data-studio/library/tables/" table-id "/measures/" measure-id)(log/warn "Measure not found for link resolution" {:measure-id entity-id}))))@@ -168,8 +170,8 @@segment, or nil when the segment is unknown."[entity-id](let [segment-id (parse-long entity-id)- table-id (some-> segment-id metabot.db/segment-table-id)- db-id (some-> table-id metabot.db/table-database-id)]+ table-id (some-> segment-id segments.db/segment :table_id)+ db-id (some-> table-id warehouse-schema.db/table :db_id)](if db-id(str "/question#?db=" db-id "&table=" table-id "&segment=" segment-id)(log/warn "Segment not found for link resolution" {:segment-id entity-id}))))diff --git a/src/metabase/metabot/api.clj b/src/metabase/metabot/api.cljindex 1340198e25f..29cabbddd0e 100644--- a/src/metabase/metabot/api.clj+++ b/src/metabase/metabot/api.clj@@ -51,7 +51,7 @@can originate one. Permissions are participation-based — a conversation canhave multiple participants (e.g. multiple users in a shared Slack thread)."[conversation-id]- (when-let [conversation (metabot.db/conversation conversation-id)]+ (when-let [conversation (metabot.db/metabot-conversation conversation-id)](api/check-403 (mi/can-read? conversation))))(defn- make-out-of-sync-fndiff --git a/src/metabase/metabot/api/conversations.clj b/src/metabase/metabot/api/conversations.cljindex 31b4ba24158..2cbb02ac32a 100644--- a/src/metabase/metabot/api/conversations.clj+++ b/src/metabase/metabot/api/conversations.clj@@ -188,7 +188,7 @@[{:keys [id]} :- ConversationIdParams_query-params{:keys [message_id]} :- ForkConversationBody]- (let [conversation (api/check-404 (metabot.db/conversation-id-and-user-id id))]+ (let [conversation (api/check-404 (metabot.db/metabot-conversation id))](api/check-403 (= (:user_id conversation) api/*current-user-id*))(let [new-conversation-id (metabot.persistence/fork-conversation! id message_id api/*current-user-id*)](api/check-400 (some? new-conversation-id)diff --git a/src/metabase/metabot/db.clj b/src/metabase/metabot/db.cljindex 57fa7c8640d..d61136e1744 100644--- a/src/metabase/metabot/db.clj+++ b/src/metabase/metabot/db.clj@@ -8,6 +8,7 @@[metabase.api.common :as api][metabase.app-db.core :as mdb][metabase.audit-app.core :as audit-app]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection.model][metabase.lib-be.core :as lib-be][metabase.lib.schema.id :as lib.schema.id]@@ -18,16 +19,17 @@[metabase.util.malli :as mu][metabase.util.malli.schema :as ms][metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay]+ [metabase.warehouse-schema.db :as warehouse-schema.db][toucan2.core :as t2]))-(declare collection metabot-metrics-and-models-query root-collections-of-types)+(declare metabot-metrics-and-models-query root-collections-of-types);;; ------------------------------------------------- Metabot --------------------------------------------------(mu/defn metabot- "The Metabot with `metabot-id`, or nil."+(mu/defn metabot :- [:maybe ::metabot.schema/metabot]+ "The ::metabot.schema/metabot with `metabot-id`, or nil."[metabot-id :- ms/PositiveInt]- (t2/select-one :model/Metabot :id metabot-id))+ (t2/select-one :model/Metabot :id [:auto/param metabot-id]))(mu/defn metabot-by-entity-id"The Metabot with `entity-id`, or nil."@@ -141,20 +143,10 @@;;; ----------------------------------------------- Conversations ------------------------------------------------(mu/defn conversation- "The MetabotConversation with `conversation-id`, or nil."+(mu/defn metabot-conversation :- [:maybe ::metabot.schema/metabot-conversation]+ "The ::metabot.schema/metabot-conversation with `conversation-id`, or nil."[conversation-id :- :string]- (t2/select-one :model/MetabotConversation :id conversation-id))--(mu/defn conversation-id-and-user-id- "The ID and originator of the MetabotConversation with `conversation-id`, or nil."- [conversation-id :- :string]- (t2/select-one [:model/MetabotConversation :id :user_id] :id conversation-id))--(mu/defn conversation-title- "The title of the MetabotConversation with `conversation-id`."- [conversation-id :- :string]- (t2/select-one-fn :title :model/MetabotConversation :id conversation-id))+ (t2/select-one :model/MetabotConversation :id [:auto/param conversation-id]))(mu/defn lock-conversation"The MetabotConversation with `conversation-id`, locked for update."@@ -300,7 +292,7 @@[conversation-id :- :stringuser-id :- ::lib.schema.id/user](boolean- (when-let [{:keys [id user_id slack_thread_ts]} (conversation conversation-id)]+ (when-let [{:keys [id user_id slack_thread_ts]} (metabot-conversation conversation-id)];; Anyone in a Slack thread can join its conversation, so the thread counts before a second person writes.;; A thread older than the `slack_thread_ts` column shows as Slack only through its messages.;; Whoever started a conversation can read it even when none of its messages name them.@@ -416,11 +408,6 @@;;; ------------------------------------------------ Databases -------------------------------------------------(mu/defn database-summary- "The ID, name, description, and engine of the Database with `database-id`."- [database-id :- ::lib.schema.id/database]- (t2/select-one [:model/Database :id :name :description :engine] database-id))-(mu/defn database-with-columns"The `columns` of the Database with `database-id`."[columns :- [:sequential :keyword]@@ -459,22 +446,6 @@;;; ------------------------------------------------- Tables --------------------------------------------------(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))--(mu/defn active-table-with-columns- "The `columns` of the active Table with `table-id`, or nil."- [columns :- [:sequential :keyword]- table-id :- ::lib.schema.id/table]- (t2/select-one columns :id table-id :active true))--(mu/defn table-database-id- "The Database ID of the Table with `table-id`."- [table-id :- ::lib.schema.id/table]- (t2/select-one-fn :db_id :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(defn readable-active-table-database-id"The Database ID of the active Table with `table-id`, or nil when there is no such table *or*the current user cannot read it.@@ -489,8 +460,8 @@and `:collection_id`. Handing it a trimmed row makes it answer a narrower question and deny auser whose access comes through that path."[table-id]- (when-let [table (t2/select-one :model/Table :id table-id :active true {:from [(warehouse-schema-overlay/table-query)]})]- (when (mi/can-read? table)+ (when-let [table (warehouse-schema.db/table table-id)]+ (when (and (:active table) (mi/can-read? table))(:db_id table))))(mu/defn tables-by-id@@ -693,21 +664,11 @@;;; ------------------------------------------------- Fields --------------------------------------------------(mu/defn field- "The Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query)]}))-(mu/defn fields"The Fields with `field-ids`."[field-ids :- [:set ::lib.schema.id/field]](t2/select :model/Field :id [:in field-ids] {:from [(warehouse-schema-overlay/field-query)]}))-(mu/defn field-fingerprint- "The fingerprint of the Field with `field-id`."- [field-id :- ::lib.schema.id/field]- (t2/select-one-fn :fingerprint :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))-(mu/defn field-table-ids"A map of Field ID to Table ID for `field-ids`."[field-ids :- [:set ::lib.schema.id/field]]@@ -715,27 +676,11 @@;;; -------------------------------------------------- Cards ---------------------------------------------------(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(mu/defn card-by-entity-id"The Card with `entity-id`, or nil."[entity-id :- :string](t2/select-one :model/Card :entity_id entity-id))-(mu/defn card-of-type- "The Card with `card-id` if it is of `type`, or nil."- [card-id :- ::lib.schema.id/card- type :- [:enum :model :metric :question]]- (t2/select-one :model/Card :id card-id :type type))--(mu/defn card-type-row- "The ID and type of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one [:model/Card :id :type] :id card-id))-(defn- metabot-metrics-and-models-query"Honey SQL query selecting the metric and model Cards in scope of the Metabot with `metabot-id` that are visible tothe current user, ignoring analytics content. If the Metabot has `:use_verified_content` enabled, restricts to@@ -761,7 +706,7 @@;; Columns are qualified with report_card because the official-collections branch joins;; `collection`, which shares column names (type, archived, id) — unqualified refs would be ambiguous.collection-filter (if metabot-collection-id- (let [metabot-collection (collection metabot-collection-id)+ (let [metabot-collection (collections.db/collection metabot-collection-id)collection-ids (conj (collection.model/descendant-ids metabot-collection) metabot-collection-id)][:in :report_card.collection_id collection-ids])[:and true])@@ -891,16 +836,6 @@;;; ----------------------------------------------- Collections ------------------------------------------------(mu/defn collection- "The Collection with `collection-id`, or nil."- [collection-id :- [:maybe ::lib.schema.id/collection]]- (t2/select-one :model/Collection :id collection-id))--(mu/defn collection-name- "The name of the Collection with `collection-id`."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one-fn :name :model/Collection :id collection-id))-(mu/defn collection-descriptions"A map of Collection ID to description for `collection-ids`."[collection-ids :- [:sequential ::lib.schema.id/collection]]@@ -943,21 +878,6 @@;;; ---------------------------------------------- Other models -----------------------------------------------(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard dashboard-id))--(mu/defn dashboard-summary- "The ID, description, name, Collection ID, and parameters of the Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one [:model/Dashboard :id :description :name :collection_id :parameters] dashboard-id))--(mu/defn dashboard-name- "The name of the Dashboard with `dashboard-id`."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one-fn :name :model/Dashboard :id dashboard-id))-(mu/defn dashboards-in-collection"Return unarchived dashboard summaries in a collection, ordered by name.@@ -1047,12 +967,6 @@{:order-by [[order-column :desc]]:limit limit}))-(mu/defn user-summary- "The ID, email, and names of the User with `user-id`, or nil if `user-id` is nil or matches no User."- [user-id :- [:maybe ::lib.schema.id/user]]- (when user-id- (t2/select-one [:model/User :id :email :first_name :last_name] user-id)))-(mu/defn user-summaries-by-id"A map of ID to the ID, email, and names of the Users with `user-ids`."[user-ids :- [:sequential ::lib.schema.id/user]]@@ -1068,26 +982,6 @@[ids :- [:sequential ms/PositiveInt]](t2/select [:model/Dashboard :id :collection_id] :id [:in ids]))-(mu/defn measure-table-id- "The Table ID of the Measure with `id`, or nil."- [id :- ::lib.schema.id/measure]- (t2/select-one-fn :table_id :model/Measure :id id))--(mu/defn segment-table-id- "The Table ID of the Segment with `id`, or nil."- [id :- ::lib.schema.id/segment]- (t2/select-one-fn :table_id :model/Segment :id id))--(mu/defn measure-entity-id- "The entity ID of the Measure with `id`."- [id :- ::lib.schema.id/measure]- (t2/select-one-fn :entity_id :model/Measure :id id))--(mu/defn segment-entity-id- "The entity ID of the Segment with `id`."- [id :- ::lib.schema.id/segment]- (t2/select-one-fn :entity_id :model/Segment :id id))-(mu/defn measures"The ID, name, description, Table ID, and entity ID of the Measures with `ids`."[ids :- [:sequential ms/PositiveInt]]diff --git a/src/metabase/metabot/feedback.clj b/src/metabase/metabot/feedback.cljindex b85bcf43756..3e1d9e29b35 100644--- a/src/metabase/metabot/feedback.clj+++ b/src/metabase/metabot/feedback.clj@@ -15,7 +15,7 @@[external-id](let [message (metabot.db/message-by-external-id external-id)_ (api/check-404 message)- conversation (metabot.db/conversation-id-and-user-id (:conversation_id message))+ conversation (metabot.db/metabot-conversation (:conversation_id message))_ (api/check-404 conversation)_ (api/check-404 (mi/can-read? conversation))](assoc message :conversation conversation)))diff --git a/src/metabase/metabot/models/metabot_conversation.clj b/src/metabase/metabot/models/metabot_conversation.cljindex 7063a180b2a..26d6869aad8 100644--- a/src/metabase/metabot/models/metabot_conversation.clj+++ b/src/metabase/metabot/models/metabot_conversation.clj@@ -31,7 +31,7 @@(or (= originator-id user-id)(participant? conversation-id user-id))))))([_model pk]- (when-let [instance (metabot.db/conversation-id-and-user-id pk)]+ (when-let [instance (metabot.db/metabot-conversation pk)](mi/can-read? instance))))(methodical/defmethod t2/batched-hydrate [:model/MetabotConversation :user]diff --git a/src/metabase/metabot/persistence.clj b/src/metabase/metabot/persistence.cljindex e11fcf272f5..a47196d5ab2 100644--- a/src/metabase/metabot/persistence.clj+++ b/src/metabase/metabot/persistence.clj@@ -610,7 +610,7 @@"Return the current persisted title for a conversation."[conversation-id](when conversation-id- (metabot.db/conversation-title conversation-id)))+ (:title (metabot.db/metabot-conversation conversation-id))));;; ---------------------------------------- Chat message conversion ----------------------------------------@@ -838,7 +838,7 @@conversation participants may not be able to read; readers resolve names throughthe permission-checked card API."[conversation-id]- (when-let [conv (metabot.db/conversation conversation-id)]+ (when-let [conv (metabot.db/metabot-conversation conversation-id)](let [messages (live-messages conversation-id)]{:conversation_id (:id conv):created_at (:created_at conv)diff --git a/src/metabase/metabot/table_utils.clj b/src/metabase/metabot/table_utils.cljindex a47a52fc49a..3c0b66fb1f6 100644--- a/src/metabase/metabot/table_utils.clj+++ b/src/metabase/metabot/table_utils.clj@@ -5,6 +5,7 @@[metabase.metabot.db :as metabot.db][metabase.metabot.query-analyzer :as query-analyzer][metabase.util :as u]+ [metabase.warehouses.db :as warehouses.db][toucan2.core :as t2][toucan2.realize :as t2.realize])(:import@@ -61,7 +62,8 @@This is the handler for the /get-tables tool endpoint."[{:keys [database-id]}]{:structured-output- {:database (metabot.db/database-summary database-id)+ {:database (some-> (warehouses.db/database database-id)+ (select-keys [:id :name :description :engine])):tables (database-tables database-id)}})(defn similar?diff --git a/src/metabase/metabot/tools/autogen_dashboard.clj b/src/metabase/metabot/tools/autogen_dashboard.cljindex bcaeaa705d9..e10450b8822 100644--- a/src/metabase/metabot/tools/autogen_dashboard.clj+++ b/src/metabase/metabot/tools/autogen_dashboard.clj@@ -7,13 +7,14 @@[metabase.lib-be.core :as lib-be][metabase.lib.core :as lib][metabase.metabot.agent.streaming :as streaming]- [metabase.metabot.db :as metabot.db][metabase.metabot.scope :as scope][metabase.metabot.tools.core :as tools][metabase.metabot.tools.recoverable.common :as recoverable.common][metabase.metabot.tools.shared :as shared]+ [metabase.queries.db :as queries.db][metabase.util.log :as log][metabase.util.malli.registry :as mr]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.xrays.core :as xrays]))(set! *warn-on-reflection* true)@@ -63,8 +64,10 @@[kind id](let [entity (tools/with-entity {:kind kind :id id}(api/read-check (if (= :table kind)- (metabot.db/table id)- (metabot.db/card-of-type id kind))))]+ (warehouse-schema.db/table id)+ (let [card (queries.db/card id)]+ (when (= kind (:type card))+ card)))))](when (or (:archived entity) (false? (:active entity)))(unavailable-source! {:kind kind :id id})){:entity entitydiff --git a/src/metabase/metabot/tools/construct.clj b/src/metabase/metabot/tools/construct.cljindex b88e9a96d9e..b78e3ec4167 100644--- a/src/metabase/metabot/tools/construct.clj+++ b/src/metabase/metabot/tools/construct.clj@@ -33,6 +33,7 @@[metabase.models.interface :as mi][metabase.models.serialization.resolve :as serdes.resolve][metabase.models.serialization.resolve.mp :as resolve.mp]+ [metabase.queries.db :as queries.db][metabase.query-processor.core :as qp][metabase.util :as u][metabase.util.json :as json]@@ -616,7 +617,7 @@numeric-card(let [card-id numeric-card- card (metabot.db/card card-id)+ card (queries.db/card card-id);; Read-check here rather than let the 403 escape: an unreadable card and an absent;; one must be reported identically, or the status code tells a caller whether a;; hidden card exists. Same collapse the read-checked content store applies to everydiff --git a/src/metabase/metabot/tools/create_alert.clj b/src/metabase/metabot/tools/create_alert.cljindex c5a1f1fbb2d..75f10020b33 100644--- a/src/metabase/metabot/tools/create_alert.clj+++ b/src/metabase/metabot/tools/create_alert.clj@@ -5,11 +5,11 @@(:require[metabase.api.common :as api][metabase.channel.settings :as channel.settings]- [metabase.metabot.db :as metabot.db][metabase.metabot.scope :as scope][metabase.metabot.tools.core :as tools][metabase.metabot.tools.util :as metabot.tools.u][metabase.notification.api :as notification.api]+ [metabase.queries.db :as queries.db][metabase.util.cron :as u.cron][metabase.util.i18n :refer [tru]]))@@ -140,7 +140,7 @@(handle [_ {:keys [card_id send_condition schedule send_once]} ctx](let [channel (current-slack-channel ctx)card (tools/with-entity {:kind :card :id card_id}- (api/read-check (metabot.db/card card_id)))+ (api/read-check (queries.db/card card_id)))alert (create-alert! {:card-id card_id:channel channel:schedule schedulediff --git a/src/metabase/metabot/tools/entity_details.clj b/src/metabase/metabot/tools/entity_details.cljindex 86aa8ff3f77..4b81ac5bf5c 100644--- a/src/metabase/metabot/tools/entity_details.clj+++ b/src/metabase/metabot/tools/entity_details.clj@@ -3,17 +3,21 @@[medley.core :as m][metabase.agent-lib.representations.resolve :as repr.resolve][metabase.api.common :as api]+ [metabase.dashboards.db :as dashboards.db][metabase.documents.core :as documents][metabase.lib-be.core :as lib-be][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata][metabase.lib.types.isa :as lib.types.isa]+ [metabase.measures.db :as measures.db][metabase.metabot.db :as metabot.db][metabase.metabot.metadata-perms :as metabot.perms][metabase.metabot.tools.shared.content-store :as shared.content-store][metabase.metabot.tools.util :as metabot.tools.u][metabase.models.interface :as mi][metabase.parameters.field-values :as params.field-values]+ [metabase.segments.db :as segments.db]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.humanization :as u.humanization][metabase.util.i18n :as i18n]@@ -30,8 +34,8 @@[model-key id](when id(case model-key- :model/Measure (metabot.db/measure-entity-id id)- :model/Segment (metabot.db/segment-entity-id id))))+ :model/Measure (:entity_id (measures.db/measure id))+ :model/Segment (:entity_id (segments.db/segment id)))))(defn- convert-measure-or-segment"Convert a measure or segment metadata object to the format expected by the API.@@ -103,7 +107,7 @@[_args](if-let [{:keys [id email first_name last_name]}(or (some-> api/*current-user* deref)- (metabot.db/user-summary api/*current-user-id*))]+ (some-> api/*current-user-id* users.db/user))]{:structured-output (merge {:id id:type :user:name (str first_name " " last_name)@@ -118,11 +122,11 @@(when-not (int? dashboard-id)(throw (ex-info "Invalid dashboard_id format"{:agent-error? true :status-code 400})))- (if-let [dashboard (metabot.db/dashboard-summary dashboard-id)]+ (if-let [dashboard (dashboards.db/dashboard dashboard-id)](do (api/read-check dashboard){:structured-output(-> dashboard- (dissoc :collection_id)+ (select-keys [:id :description :name :parameters])(assoc :type :dashboard:verified (verified-review? dashboard-id "dashboard")))}){:output "dashboard not found"}))@@ -497,7 +501,7 @@{:agent-error? true :status-code 400})))(when-let [base (if metadata-provider(lib.metadata/table metadata-provider id)- (metabot.tools.u/get-table id :db_id :description :name :schema))]+ (metabot.tools.u/get-table id))](let [query-needed? (or with-fields? with-related-tables? with-metrics? with-measures? with-segments?)db-id (if metadata-provider (:db-id base) (:db_id base));; Database metadata including :name so LLM can build portable FK paths@@ -859,8 +863,8 @@id :- :int](let [{:keys [lookup-fn definition-key]} (measure-or-segment-dispatch kind)table-id (case kind- :measure (metabot.db/measure-table-id id)- :segment (metabot.db/segment-table-id id))]+ :measure (:table_id (measures.db/measure id))+ :segment (:table_id (segments.db/segment id)))](when-not table-id(throw (ex-info (format "%s %s not found" (name kind) id){:agent-error? true :status-code 404})))diff --git a/src/metabase/metabot/tools/field_stats.clj b/src/metabase/metabot/tools/field_stats.cljindex 823dddbde36..fec8f687792 100644--- a/src/metabase/metabot/tools/field_stats.clj+++ b/src/metabase/metabot/tools/field_stats.clj@@ -3,7 +3,6 @@[clojure.set :as set][metabase.api.common :as api][metabase.lib.core :as lib]- [metabase.metabot.db :as metabot.db][metabase.metabot.metadata-perms :as metabot.perms][metabase.metabot.tools.core :as tools][metabase.metabot.tools.entity-details :as entity-details]@@ -15,7 +14,8 @@[metabase.request.core :as request][metabase.sync.core :as sync][metabase.sync.util :as sync-util]- [metabase.util.log :as log]))+ [metabase.util.log :as log]+ [metabase.warehouse-schema.db :as warehouse-schema.db]))(defn- build-field-statistics [fvs fp limit](merge@@ -47,7 +47,7 @@;; Sync returns `:sync/no-connection` or a Throwable when it can't sample the database(cond(not (map? result)) ::unavailable- (pos? (:updated-fingerprints result)) (metabot.db/field-fingerprint id)))))+ (pos? (:updated-fingerprints result)) (:fingerprint (warehouse-schema.db/field id))))))(defn- database-unrestricted?[db-id]@@ -83,7 +83,7 @@Unrestricted database users keep fingerprints even when source tables cannot be determined."[query {:keys [id fingerprint]} limit](if id- (let [field (metabot.db/field id)+ (let [field (warehouse-schema.db/field id)table-id (:table_id field)fvs (params.field-values/get-or-create-field-values! field)restricted? (or (not (int? table-id))diff --git a/src/metabase/metabot/tools/resources.clj b/src/metabase/metabot/tools/resources.cljindex 9334204284d..04d3bb1d8ab 100644--- a/src/metabase/metabot/tools/resources.clj+++ b/src/metabase/metabot/tools/resources.clj@@ -71,6 +71,7 @@[metabase.collections.models.collection :as collection][metabase.documents.core :as documents][metabase.documents.prose-mirror :as prose-mirror]+ [metabase.measures.db :as measures.db][metabase.metabot.agent.streaming :as streaming][metabase.metabot.db :as metabot.db][metabase.metabot.query-export :as query-export]@@ -86,6 +87,8 @@[metabase.metabot.tools.shared.llm-shape :as llm-shape][metabase.models.interface :as mi][metabase.permissions.core :as perms]+ [metabase.queries.db :as queries.db]+ [metabase.segments.db :as segments.db][metabase.transforms.core :as transforms][metabase.util :as u][metabase.util.i18n :refer [tru]]@@ -499,7 +502,7 @@(defn- present-source-card"Resolve a source-card id to a typed item map (model / metric / question)."[source-card-id]- (let [src-card (metabot.db/card-type-row source-card-id)+ (let [src-card (queries.db/card source-card-id)src-type (case (:type src-card):model "model":metric "metric"@@ -699,8 +702,8 @@(defn- check-measure-or-segment-resource-database [model id](when-let [table-id (case model- :model/Measure (metabot.db/measure-table-id id)- :model/Segment (metabot.db/segment-table-id id))]+ :model/Measure (:table_id (measures.db/measure id))+ :model/Segment (:table_id (segments.db/segment id)))](check-table-resource-database table-id)))(defn- active-table-resource [id]diff --git a/src/metabase/metabot/tools/run_query.clj b/src/metabase/metabot/tools/run_query.cljindex bdd1586cbbc..db61af1a557 100644--- a/src/metabase/metabot/tools/run_query.clj+++ b/src/metabase/metabot/tools/run_query.clj@@ -21,6 +21,7 @@[metabase.metabot.tools.sql.common :as sql.common][metabase.metabot.tools.util :as tools.u][metabase.models.interface :as mi]+ [metabase.queries.db :as queries.db][metabase.query-processor.compile :as qp.compile][metabase.query-processor.middleware.catch-exceptions :as qp.catch-exceptions][metabase.query-processor.pipeline :as qp.pipeline]@@ -220,7 +221,7 @@can't read the source card or query the base table."[metric](let [{:keys [kind card-id table-id]} (tools.u/metric-required-source metric)- source-card (when (= :card kind) (metabot.db/card card-id))]+ source-card (when (= :card kind) (queries.db/card card-id))](cond(some-> source-card mi/can-read?){:card-type (:type source-card)@@ -248,7 +249,7 @@(when (and (pos-int? parsed) (= query-id (str parsed)))parsed))];; A question the user can't read is treated like one that doesn't exist, so its id tells them nothing.- (let [card (metabot.db/card card-id)]+ (let [card (queries.db/card card-id)](when (some-> card mi/can-read?)(when (= :metric (:type card))(metric-not-runnable! {:query-id query-id, :source (metric-source card)}))@@ -434,7 +435,7 @@through another saved question.Holds a nil for each question that no longer exists."[query]- (map metabot.db/card (:card (lib/all-referenced-entity-ids-recursive query))))+ (map queries.db/card (:card (lib/all-referenced-entity-ids-recursive query))))(defn- metabot-sql-card?"Whether `card` is a SQL question that Metabot saved and nobody has edited since.diff --git a/src/metabase/metabot/tools/save_entity.clj b/src/metabase/metabot/tools/save_entity.cljindex 333a07224c7..bade6a10ab4 100644--- a/src/metabase/metabot/tools/save_entity.clj+++ b/src/metabase/metabot/tools/save_entity.clj@@ -10,7 +10,9 @@(:require[metabase.api.common :as api][metabase.app-db.core :as mdb]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection]+ [metabase.dashboards.db :as dashboards.db][metabase.documents.core :as documents][metabase.events.core :as events][metabase.metabot.agent.links :as links]@@ -211,7 +213,7 @@[collection-id](if (nil? collection-id)(:name (collection/root-collection-with-ui-details nil))- (metabot.db/collection-name collection-id)))+ (:name (collections.db/collection collection-id))))(tools/defrecoverable destination-archived!"The destination is in the trash."@@ -274,7 +276,7 @@:delay-event)]{:card card:destination {:type "dashboard" :id dashboard-id}- :destination-name (metabot.db/dashboard-name dashboard-id)+ :destination-name (:name (dashboards.db/dashboard dashboard-id)):link (str "metabase://dashboard/" dashboard-id)})))(defn- save-to-document!diff --git a/src/metabase/metabot/tools/search.clj b/src/metabase/metabot/tools/search.cljindex 8863d7964ec..6d486832ba5 100644--- a/src/metabase/metabot/tools/search.clj+++ b/src/metabase/metabot/tools/search.clj@@ -22,7 +22,8 @@[metabase.transforms.core :as transforms][metabase.util :as u][metabase.util.log :as log]- [metabase.util.malli :as mu]))+ [metabase.util.malli :as mu]+ [metabase.warehouses.db :as warehouses.db]))(set! *warn-on-reflection* true)@@ -705,7 +706,7 @@(defn- check-search-database- (when-let [database (metabot.db/database-summary database-id)]+ (when-let [database (warehouses.db/database database-id)](mi/can-read? database)))(unavailable-database! {:database-id database-id})))diff --git a/src/metabase/metabot/tools/static_viz.clj b/src/metabase/metabot/tools/static_viz.cljindex e0047b4fbb8..c485558a97d 100644--- a/src/metabase/metabot/tools/static_viz.clj+++ b/src/metabase/metabot/tools/static_viz.clj@@ -3,10 +3,10 @@(:require[metabase.api.common :as api][metabase.metabot.agent.streaming :as streaming]- [metabase.metabot.db :as metabot.db][metabase.metabot.scope :as scope][metabase.metabot.tools.core :as tools]- [metabase.metabot.tools.shared.llm-shape :as llm-shape]))+ [metabase.metabot.tools.shared.llm-shape :as llm-shape]+ [metabase.queries.db :as queries.db]))(set! *warn-on-reflection* true)@@ -33,7 +33,7 @@(handle [_ {:keys [entity_id]} _ctx](let [card (tools/with-entity {:kind :card :id entity_id}- (api/read-check (metabot.db/card entity_id)))]+ (api/read-check (queries.db/card entity_id)))]{:output (queued-output card):data-parts [(streaming/static-viz-part {:entity_id entity_id})]})))diff --git a/src/metabase/metabot/tools/subscriptions.clj b/src/metabase/metabot/tools/subscriptions.cljindex c15ef327877..90f09ece41f 100644--- a/src/metabase/metabot/tools/subscriptions.clj+++ b/src/metabase/metabot/tools/subscriptions.clj@@ -5,7 +5,7 @@(:require[metabase.api.common :as api][metabase.channel.settings :as channel.settings]- [metabase.metabot.db :as metabot.db]+ [metabase.dashboards.db :as dashboards.db][metabase.metabot.scope :as scope][metabase.metabot.tools.core :as tools][metabase.metabot.tools.create-alert :as tools.create-alert]@@ -54,7 +54,7 @@(defn- dashboard-for-subscription [dashboard-id](let [dashboard (tools/with-entity {:kind :dashboard :id dashboard-id}- (-> (metabot.db/dashboard dashboard-id)+ (-> (dashboards.db/dashboard dashboard-id)api/read-check(t2/hydrate [:dashcards :card])))dashcards (filter (comp int? :id :card) (:dashcards dashboard))]diff --git a/src/metabase/metabot/tools/util.clj b/src/metabase/metabot/tools/util.cljindex 93e91ba50f8..807cb5fbea1 100644--- a/src/metabase/metabot/tools/util.clj+++ b/src/metabase/metabot/tools/util.clj@@ -10,7 +10,9 @@[metabase.metabot.db :as metabot.db][metabase.metabot.tools.core :as tools][metabase.models.interface :as mi]- [metabase.util :as u]))+ [metabase.queries.db :as queries.db]+ [metabase.util :as u]+ [metabase.warehouse-schema.db :as warehouse-schema.db]))(defn handle-agent-error"Return an agent output for agent errors, re-throw `e` otherwise.@@ -162,10 +164,10 @@api/read-check))(defn get-table- "Get the `fields` of the table with ID `id`."- [id & fields]- (-> (metabot.db/active-table-with-columns (into [:model/Table :id] fields) id)- api/read-check))+ "Get the active table with ID `id`, if the current user can read it."+ [id]+ (let [table (warehouse-schema.db/table id)]+ (api/read-check (when (:active table) table))))(tools/defrecoverable wrong-source-type!"The card ID identifies a different kind of data source."@@ -181,7 +183,7 @@(defn get-card"Retrieve a readable card by ID, optionally requiring a particular card type."([id]- (-> (metabot.db/card id)+ (-> (queries.db/card id)api/read-check))([id expected-type](let [card (get-card id)]@@ -230,7 +232,7 @@(defn table-query"Return a query based on the table with ID `table-id`."[table-id]- (when-let [table (get-table table-id :db_id)]+ (when-let [table (get-table table-id)](let [mp (lib-be/application-database-metadata-provider (:db_id table))](lib/query mp (lib.metadata/table mp table-id)))))diff --git a/src/metabase/metrics/api.clj b/src/metabase/metrics/api.cljindex 560fe3ece85..f27d9f02a03 100644--- a/src/metabase/metrics/api.clj+++ b/src/metabase/metrics/api.clj@@ -8,10 +8,12 @@[metabase.lib-be.schema :as lib-be.schema][metabase.lib-metric.core :as lib-metric][metabase.lib-metric.schema :as lib-metric.schema]+ [metabase.measures.db :as measures.db][metabase.metrics.core :as metrics][metabase.metrics.db :as metrics.db][metabase.metrics.dimension :as metrics.dimension][metabase.metrics.permissions :as metrics.perms]+ [metabase.queries.db :as queries.db][metabase.query-processor.core :as qp][metabase.query-processor.middleware.permissions :as qp.perms][metabase.query-processor.pipeline :as qp.pipeline]@@ -26,6 +28,13 @@(set! *warn-on-reflection* true)+(defn- metric-card+ "The Card with `id` if it is a metric, or nil."+ [id]+ (let [card (queries.db/card id)]+ (when (= (:type card) :metric)+ card)))+(mr/def ::Metric"Schema for a Metric in list responses (without hydrated dimensions)."[:map@@ -81,9 +90,9 @@(mu/defn- hydrated-metric [id :- ms/PositiveIntinclude-orphaned? :- :boolean]- (api/read-check (metrics.db/metric-card id))+ (api/read-check (metric-card id))(metrics/sync-dimensions! :metadata/metric id)- (cond-> (-> (metrics.db/metric-card id)+ (cond-> (-> (metric-card id)metrics.perms/filter-dimensions-for-user(update :dimensions #(or % []))(update :dimension_mappings #(or % [])))@@ -171,10 +180,10 @@source-id (lib-metric/expression-leaf-id leaf)](case source-type:metric (do- (api/read-check (metrics.db/metric-card source-id))+ (api/read-check (metric-card source-id))[(lib-metric/expression-leaf-uuid leaf) source-id]):measure (do- (api/query-check (metrics.db/measure source-id))+ (api/query-check (measures.db/measure source-id))nil))))(lib-metric/expression-leaves expression))))@@ -342,10 +351,10 @@;;; +----------------------------------------------------------------------------------------------------------------+(defn- read-check-metric! [id]- (api/read-check (metrics.db/metric-card id)))+ (api/read-check (metric-card id)))(defn- write-check-metric! [id]- (api/write-check (metrics.db/metric-card id)))+ (api/write-check (metric-card id)))(defn- notify-dimensions-changed!"Announce a write to metric `id`'s curated dimensions, given the `before` Card that@@ -359,7 +368,7 @@Revisions are unaffected: `metabase.revisions.impl.card` excludes both columns from the snapshot, and`push-revision!` skips a revision whose serialization is unchanged."[id before]- (events/publish-event! :event/card-update {:object (metrics.db/metric-card id)+ (events/publish-event! :event/card-update {:object (metric-card id):previous-object before:user-id api/*current-user-id*}))diff --git a/src/metabase/metrics/db.clj b/src/metabase/metrics/db.cljindex f6b05d6a2fb..ed05795e49e 100644--- a/src/metabase/metrics/db.clj+++ b/src/metabase/metrics/db.clj@@ -37,16 +37,6 @@:limit limit:offset offset}))-(mu/defn metric-card- "The metric Card with `id`, or nil."- [id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id id :type "metric"))--(mu/defn measure- "The Measure with `id`, or nil."- [id :- ::lib.schema.id/measure]- (t2/select-one :model/Measure :id id))-(mu/defn raw-metric-cards-for-database"The id and dimensions of the metric Cards of the Database with `database-id`.@@ -61,8 +51,3 @@[columns :- [:sequential :keyword]field-ids :- [:set ::lib.schema.id/field]](t2/select (into [:model/Field :id] columns) :id [:in field-ids] {:from [(warehouse-schema-overlay/field-query)]}))--(mu/defn field- "The Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query)]}))diff --git a/src/metabase/metrics/dimension.clj b/src/metabase/metrics/dimension.cljindex 21d2dc07e8c..7699d48adbe 100644--- a/src/metabase/metrics/dimension.clj+++ b/src/metabase/metrics/dimension.clj@@ -12,7 +12,8 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]- [metabase.util.malli.schema :as ms]))+ [metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db]));;; ------------------------------------------------- API Shape -------------------------------------------------;;; Convert internal (kebab) dimensions to the snake_case shape the frontend expects, and back.@@ -239,7 +240,7 @@dimension-mappings :- [:maybe [:sequential ::lm.schema/dimension-mapping]]dimension-id :- :string](let [field-id (lib-metric/resolve-dimension-to-field-id dimensions dimension-mappings dimension-id)- field (metrics.db/field field-id)]+ field (warehouse-schema.db/field field-id)](parameters/field->values field)))(mu/defn dimension-search-values :- [:sequential [:vector :string]]@@ -259,11 +260,11 @@dimension-id :- :stringvalue :- :string](let [field-id (lib-metric/resolve-dimension-to-field-id dimensions dimension-mappings dimension-id)- field (metrics.db/field field-id)+ field (warehouse-schema.db/field field-id)parsed-value (parameters/parse-query-param-value-for-field field value)remapped-fid (parameters/remapped-field-id field-id)](if remapped-fid- (let [remapped-field (metrics.db/field remapped-fid)]+ (let [remapped-field (warehouse-schema.db/field remapped-fid)](parameters/remapped-value field remapped-field parsed-value));; No remapping - return the value as-is[parsed-value])))diff --git a/src/metabase/model_persistence/api.clj b/src/metabase/model_persistence/api.cljindex 79cd5139515..7b3520cbc32 100644--- a/src/metabase/model_persistence/api.clj+++ b/src/metabase/model_persistence/api.clj@@ -15,6 +15,7 @@[metabase.permissions.core :as perms][metabase.premium-features.core :as premium-features][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.request.core :as request][metabase.system.core :as system][metabase.util :as u]@@ -22,6 +23,7 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouses.db :as warehouses.db][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -72,7 +74,7 @@[:persisted-info-id ms/PositiveInt]]](api/let-404 [persisted-info (first (fetch-persisted-info {:persisted-info-id persisted-info-id} nil nil))](api/read-check :model/Card (:card_id persisted-info))- (api/write-check (model-persistence.db/database (:database_id persisted-info)))+ (api/write-check (warehouses.db/database (:database_id persisted-info)))persisted-info));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -85,7 +87,7 @@[:card-id ms/PositiveInt]]](api/let-404 [persisted-info (first (fetch-persisted-info {:card-id card-id} nil nil))](api/read-check :model/Card card-id)- (api/read-check (model-persistence.db/database (:database_id persisted-info)))+ (api/read-check (warehouses.db/database (:database_id persisted-info)))persisted-info))(def ^:private CronSchedule@@ -177,9 +179,9 @@[{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]](premium-features/assert-has-feature :cache-granular-controls (tru "Granular cache controls"))- (api/let-404 [{:keys [database_id] :as card} (model-persistence.db/card card-id)]+ (api/let-404 [{:keys [database_id] :as card} (queries.db/card card-id)](api/write-check card)- (let [database (model-persistence.db/database database_id)]+ (let [database (warehouses.db/database database_id)](api/write-check database)(when-not (driver.u/supports? (:engine database) :persist-models database)(throw (ex-info (tru "Database does not support persisting")@@ -203,14 +205,14 @@"Refresh the persisted model caching `card-id`."[{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]]- (api/let-404 [card (model-persistence.db/card card-id)+ (api/let-404 [card (queries.db/card card-id)persisted-info (model-persistence.db/persisted-info-for-card card-id)](when (not (queries/model? card))(throw (ex-info (trs "Cannot refresh a non-model question") {:status-code 400})))(when (:archived card)(throw (ex-info (trs "Cannot refresh an archived model") {:status-code 400})))(api/write-check card)- (api/write-check (model-persistence.db/database (:database_id persisted-info)))+ (api/write-check (warehouses.db/database (:database_id persisted-info)))(task.persist-refresh/schedule-refresh-for-individual! persisted-info)api/generic-204-no-content))@@ -224,10 +226,10 @@[{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]](premium-features/assert-has-feature :cache-granular-controls (tru "Granular cache controls"))- (api/let-404 [card (model-persistence.db/card card-id)]+ (api/let-404 [card (queries.db/card card-id)](api/write-check card)(when-let [persisted-info (model-persistence.db/persisted-info-for-card card-id)]- (api/write-check (model-persistence.db/database (:database_id persisted-info)))+ (api/write-check (warehouses.db/database (:database_id persisted-info)))(persisted-info/mark-for-pruning! {:id (:id persisted-info)} "off"))api/generic-204-no-content))@@ -246,7 +248,7 @@(api/check (model-persistence.settings/persisted-models-enabled)400(tru "Persisting models is not enabled."))- (api/let-404 [database (model-persistence.db/database id)]+ (api/let-404 [database (warehouses.db/database id)](api/write-check database)(if (-> database :settings :persist-models-enabled);; todo: some other response if already persisted?@@ -273,7 +275,7 @@"Attempt to disable model persistence for a database. If already not enabled, just returns a generic 204."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (api/let-404 [database (model-persistence.db/database id)]+ (api/let-404 [database (warehouses.db/database id)](api/write-check database)(if (-> database :settings :persist-models-enabled)(do (model-persistence.db/update-database! id {:settings (dissoc (:settings database) :persist-models-enabled)})diff --git a/src/metabase/model_persistence/db.clj b/src/metabase/model_persistence/db.cljindex 17569a498fa..8fd5310b386 100644--- a/src/metabase/model_persistence/db.clj+++ b/src/metabase/model_persistence/db.clj@@ -92,10 +92,10 @@[ids :- [:sequential ms/PositiveInt]](t2/select :model/PersistedInfo :id [:in ids]))-(mu/defn persisted-info- "The PersistedInfo with `id`, or nil."+(mu/defn persisted-info :- [:maybe ::model-persistence.schema/persisted-info]+ "The ::model-persistence.schema/persisted-info with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/PersistedInfo :id id))+ (t2/select-one :model/PersistedInfo :id [:auto/param id]))(mu/defn persisted-info-for-card"The PersistedInfo of the Card with `card-id`, or nil."@@ -107,11 +107,6 @@[card-id :- ::lib.schema.id/card](t2/select-one-fn :id :model/PersistedInfo :card_id card-id))-(mu/defn persisted-info-state- "The state of the PersistedInfo with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one-fn :state :model/PersistedInfo :id id))-(mu/defn persisted-database-ids"The set of Database ids with PersistedInfos."[]@@ -233,21 +228,6 @@:from [:persisted_info]:where [:= :persisted_info.card_id :report_card.id]}]]]}))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))--(mu/defn card-archived-and-type- "The archived flag and type of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one [:model/Card :archived :type] :id card-id))--(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- [:maybe ::lib.schema.id/database]]- (t2/select-one :model/Database :id database-id))-(mu/defn databases"The Databases with `database-ids`."[database-ids :- [:sequential ::lib.schema.id/database]]diff --git a/src/metabase/model_persistence/events/persisted_info.clj b/src/metabase/model_persistence/events/persisted_info.cljindex 294e63db3df..f967aa2b175 100644--- a/src/metabase/model_persistence/events/persisted_info.clj+++ b/src/metabase/model_persistence/events/persisted_info.clj@@ -5,6 +5,7 @@[metabase.model-persistence.models.persisted-info :as persisted-info][metabase.model-persistence.settings :as model-persistence.settings][metabase.util.log :as log]+ [metabase.warehouses.db :as warehouses.db][methodical.core :as methodical]))(events/derive! ::event :metabase/event)@@ -20,7 +21,7 @@;; is only supposed to be that initial edge when the dataset is being changed.(when (and (= (:type card) :model)(model-persistence.settings/persisted-models-enabled)- (get-in (model-persistence.db/database (:database_id card)) [:settings :persist-models-enabled])+ (get-in (warehouses.db/database (:database_id card)) [:settings :persist-models-enabled])(nil? (model-persistence.db/persisted-info-id-for-card (:id card))))(persisted-info/turn-on-model! user-id card))(catch Throwable ediff --git a/src/metabase/model_persistence/task/persist_refresh.clj b/src/metabase/model_persistence/task/persist_refresh.cljindex b6b9756ee84..7514c5c4f4c 100644--- a/src/metabase/model_persistence/task/persist_refresh.clj+++ b/src/metabase/model_persistence/task/persist_refresh.clj@@ -14,6 +14,7 @@[metabase.model-persistence.db :as model-persistence.db][metabase.model-persistence.models.persisted-info :as persisted-info][metabase.model-persistence.settings :as model-persistence.settings]+ [metabase.queries.db :as queries.db][metabase.query-processor.core :as qp][metabase.query-processor.timezone :as qp.timezone][metabase.task-history.core :as task-history]@@ -23,6 +24,7 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouses.db :as warehouses.db][potemkin.types :as p][toucan2.core :as t2])(:import@@ -56,12 +58,12 @@(defn- refresh-with-stats! [refresher database stats persisted-info];; Since this could be long running, double check state just before refreshing- (when (contains? (persisted-info/refreshable-states) (model-persistence.db/persisted-info-state (:id persisted-info)))+ (when (contains? (persisted-info/refreshable-states) (:state (model-persistence.db/persisted-info (:id persisted-info))))(tracing/with-span :tasks "task.persist.refresh-model" {:db/id (u/the-id database):persist/card-id (:card_id persisted-info):persist/table (:table_name persisted-info)}(log/infof "Attempting to refresh persisted model %s." (:card_id persisted-info))- (let [card (model-persistence.db/card (:card_id persisted-info))+ (let [card (queries.db/card (:card_id persisted-info))definition (persisted-info/metadata->definition (:result_metadata card)(:table_name persisted-info))_ (model-persistence.db/begin-persisted-info-refresh! (u/the-id persisted-info)@@ -138,8 +140,8 @@unpersist-fn (fn [](reduce (fn [stats persisted-info];; Since this could be long running, double check state just before deleting- (let [current-state (model-persistence.db/persisted-info-state (:id persisted-info))- card-info (model-persistence.db/card-archived-and-type (:card_id persisted-info))]+ (let [current-state (:state (model-persistence.db/persisted-info (:id persisted-info)))+ card-info (queries.db/card (:card_id persisted-info))](if (or (contains? (persisted-info/prunable-states) current-state)(:archived card-info)(not= (:type card-info) :model))@@ -200,7 +202,7 @@"Refresh an individual model based on [[PersistedInfo]]."[persisted-info-id refresher trigger](let [persisted-info (model-persistence.db/persisted-info persisted-info-id)- database (when (and persisted-info (model-persistence.db/database (:database_id persisted-info)))+ database (when (and persisted-info (warehouses.db/database (:database_id persisted-info)))(driver.u/lib-database (:database_id persisted-info)))](if (and persisted-info database)(dodiff --git a/src/metabase/native_query_snippets/api.clj b/src/metabase/native_query_snippets/api.cljindex 6f792f3aeb4..aed892ac632 100644--- a/src/metabase/native_query_snippets/api.clj+++ b/src/metabase/native_query_snippets/api.clj@@ -40,7 +40,7 @@(mu/defn get-native-query-snippet :- [:maybe (ms/InstanceOf :model/NativeQuerySnippet)]"Fetch native query snippet with ID and hydrate creator."[id :- ms/PositiveInt]- (-> (api/read-check (native-query-snippets.db/snippet id))+ (-> (api/read-check (native-query-snippets.db/native-query-snippet id))(t2/hydrate :creator :is_remote_synced)));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -87,7 +87,7 @@"Check whether current user has write permissions, then update NativeQuerySnippet with values in `body`. Returnsupdated/hydrated NativeQuerySnippet"[id body]- (let [snippet (native-query-snippets.db/snippet id)+ (let [snippet (native-query-snippets.db/native-query-snippet id)body-fields (u/select-keys-when body:present #{:description :collection_id}:non-nil #{:archived :content :name})diff --git a/src/metabase/native_query_snippets/db.clj b/src/metabase/native_query_snippets/db.cljindex 9314cfe94d8..2f9653b9f08 100644--- a/src/metabase/native_query_snippets/db.clj+++ b/src/metabase/native_query_snippets/db.clj@@ -15,10 +15,10 @@[archived :- :boolean](t2/select :model/NativeQuerySnippet :archived archived {:order-by [[:%lower.name :asc]]}))-(mu/defn snippet- "The NativeQuerySnippet with `id`, or nil."+(mu/defn native-query-snippet :- [:maybe ::native-query-snippets.schema/native-query-snippet]+ "The ::native-query-snippets.schema/native-query-snippet with `id`, or nil."[id :- ::lib.schema.id/native-query-snippet]- (t2/select-one :model/NativeQuerySnippet :id id))+ (t2/select-one :model/NativeQuerySnippet :id [:auto/param id]))(mu/defn snippet-name-exists?"Whether a NativeQuerySnippet named `snippet-name` exists."@@ -47,11 +47,6 @@[snippet-name :- :string](t2/select-one-fn :id :model/NativeQuerySnippet :name snippet-name))-(mu/defn snippet-collection-id- "The Collection id of the NativeQuerySnippet with `id`, or nil."- [id :- ::lib.schema.id/native-query-snippet]- (t2/select-one-fn :collection_id :model/NativeQuerySnippet :id id))-(mu/defn exportable-snippets"A reducible of the NativeQuerySnippets to export via serdes: unarchived when `skip-archived?`, and either in one of`collection-ids`, uncollected when `include-root?`, or — when `filter-column` is given — one of the rows whosediff --git a/src/metabase/native_query_snippets/models/native_query_snippet.clj b/src/metabase/native_query_snippets/models/native_query_snippet.cljindex 3ffc16f90c1..042f926b705 100644--- a/src/metabase/native_query_snippets/models/native_query_snippet.clj+++ b/src/metabase/native_query_snippets/models/native_query_snippet.clj@@ -224,7 +224,7 @@(defmethod serdes/required "NativeQuerySnippet"[_model id]- (when-let [collection_id (native-query-snippets.db/snippet-collection-id id)]+ (when-let [collection_id (:collection_id (native-query-snippets.db/native-query-snippet id))]{["Collection" collection_id] {"NativeQuerySnippet" id}}))(defmethod serdes/deserialization-dependencies "NativeQuerySnippet"@@ -246,7 +246,7 @@(defmethod serdes/descendants "NativeQuerySnippet" [_model-name id _opts](into {}- (for [path (serdes/mbql-deps true (:template_tags (native-query-snippets.db/snippet id)))+ (for [path (serdes/mbql-deps true (:template_tags (native-query-snippets.db/native-query-snippet id))):let [{:keys [model] ref-id :id} (last path)]:when (#{"Card" "NativeQuerySnippet"} model)][[model ref-id] {"NativeQuerySnippet" id}])))diff --git a/src/metabase/notification/api/notification.clj b/src/metabase/notification/api/notification.cljindex 65beabcc972..45faadf2b5c 100644--- a/src/metabase/notification/api/notification.clj+++ b/src/metabase/notification/api/notification.clj@@ -14,6 +14,7 @@[metabase.notification.core :as notification][metabase.notification.db :as notification.db][metabase.notification.models :as models.notification]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]@@ -159,7 +160,7 @@(filter #(#{:notification-recipient/user :notification-recipient/raw-value} ((comp keyword :type) %)))(map (fn [recipient](if (= :notification-recipient/user ((comp keyword :type) recipient))- (or (-> recipient :user :email) (notification.db/user-email (:user_id recipient)))+ (or (-> recipient :user :email) (:email (users.db/user (:user_id recipient))))(-> recipient :details :value))))(remove nil?)set))diff --git a/src/metabase/notification/api/unsubscribe.clj b/src/metabase/notification/api/unsubscribe.cljindex b643006d462..8d9939d9798 100644--- a/src/metabase/notification/api/unsubscribe.clj+++ b/src/metabase/notification/api/unsubscribe.clj@@ -6,8 +6,10 @@[metabase.api.macros :as api.macros][metabase.channel.email.messages :as messages][metabase.config.core :as config]+ [metabase.dashboards.db :as dashboards.db][metabase.events.core :as events][metabase.notification.db :as notification.db]+ [metabase.queries.db :as queries.db][metabase.request.core :as request][metabase.util.i18n :refer [tru]][metabase.util.malli.schema :as ms]@@ -30,9 +32,9 @@(let [notification (t2/hydrate (notification.db/notification-for-handler notification-handler-id) :payload)](case (:payload_type notification);; use the card name- :notification/card (->> notification :payload :card_id notification.db/card-name)+ :notification/card (:name (queries.db/card (-> notification :payload :card_id)));; use the dashboard name- :notification/dashboard (->> notification :payload :dashboard_id notification.db/dashboard-name)+ :notification/dashboard (:name (dashboards.db/dashboard (-> notification :payload :dashboard_id)))(name (:payload_type notification)))));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers todiff --git a/src/metabase/notification/db.clj b/src/metabase/notification/db.cljindex 21b20421063..9b8daa3d24e 100644--- a/src/metabase/notification/db.clj+++ b/src/metabase/notification/db.clj@@ -16,6 +16,11 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))+(mu/defn notification-card :- [:maybe ::notification.schema/notification-card]+ "The ::notification.schema/notification-card with `notification-card-id`, or nil."+ [notification-card-id :- ms/PositiveInt]+ (t2/select-one :model/NotificationCard :id [:auto/param notification-card-id]))+(def ^:private NotificationRow"A whole Notification row for insert."[:map {:closed true}@@ -82,10 +87,10 @@;;; --------------------------------------------- Notification ----------------------------------------------(mu/defn notification- "The Notification with `notification-id`, or nil."+(mu/defn notification :- [:maybe ::notification.schema/notification]+ "The ::notification.schema/notification with `notification-id`, or nil."[notification-id :- ms/PositiveInt]- (t2/select-one :model/Notification notification-id))+ (t2/select-one :model/Notification :id [:auto/param notification-id]))(mu/defn notification-by-internal-id"The seeded Notification with `internal-id`, or nil."@@ -238,11 +243,6 @@[notification-card-id :- ::lib.schema.id/card](t2/exists? :model/NotificationCard notification-card-id))-(mu/defn notification-card-card-id- "The `:card_id` of the NotificationCard with `notification-card-id`."- [notification-card-id :- ::lib.schema.id/card]- (t2/select-one-fn :card_id :model/NotificationCard :id notification-card-id))-(mu/defn insert-notification-card!"Insert `notification-card` and return its ID."[notification-card :- NotificationCardRow]@@ -255,10 +255,10 @@;;; --------------------------------------- NotificationSubscription ----------------------------------------(mu/defn subscription- "The NotificationSubscription with `subscription-id`, or nil."+(mu/defn notification-subscription :- [:maybe ::notification.schema/notification-subscription]+ "The ::notification.schema/notification-subscription with `subscription-id`, or nil."[subscription-id :- ms/PositiveInt]- (t2/select-one :model/NotificationSubscription subscription-id))+ (t2/select-one :model/NotificationSubscription :id [:auto/param subscription-id]))(mu/defn subscriptions-for-notifications"The NotificationSubscriptions of the Notifications with `notification-ids` (nil entries are ignored)."@@ -376,11 +376,6 @@[template-ids :- [:sequential ms/PositiveInt]](t2/select-fn->fn :id identity :model/ChannelTemplate :id [:in template-ids]))-(mu/defn channel-template-channel-type- "The `:channel_type` of the ChannelTemplate with `template-id`."- [template-id :- ms/PositiveInt]- (t2/select-one-fn :channel_type [:model/ChannelTemplate :channel_type] template-id))-(mu/defn insert-channel-template!"Insert `template` and return its ID."[template :- ChannelTemplateRow]@@ -674,31 +669,6 @@id :- [:maybe ms/PositiveInt]](t2/select-one model id))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- [:maybe ::lib.schema.id/card]]- (t2/select-one :model/Card card-id))--(mu/defn unarchived-card- "The Card with `card-id` if it is not archived, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id :archived false))--(mu/defn card-name- "The name of the Card with `card-id`."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :name :model/Card card-id))--(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard dashboard-id))--(mu/defn dashboard-name- "The name of the Dashboard with `dashboard-id`."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one-fn :name :model/Dashboard dashboard-id))-(mu/defn dashboard-tabs"The DashboardTabs of the Dashboard with `dashboard-id`."[dashboard-id :- ::lib.schema.id/dashboard]@@ -714,17 +684,6 @@[dashboard-id :- ::lib.schema.id/dashboard](t2/select :model/DashboardCard :dashboard_id dashboard-id))-(mu/defn user-email- "The email of the User with `user-id`."- [user-id :- ::lib.schema.id/user]- (t2/select-one-fn :email [:model/User :email] user-id))--(mu/defn user-summary- "The ID, names, email, and derived common name of the User with `user-id`, or nil (also for a nil `user-id`, e.g.- a system-created notification without a creator)."- [user-id :- [:maybe ::lib.schema.id/user]]- (t2/select-one [:model/User :id :first_name :last_name :email] user-id))-(mu/defn active-users-by-id"A map of ID to active User for `user-ids`."[user-ids :- [:sequential ::lib.schema.id/user]]diff --git a/src/metabase/notification/models.clj b/src/metabase/notification/models.cljindex 32e684b1df9..64898e334b5 100644--- a/src/metabase/notification/models.clj+++ b/src/metabase/notification/models.clj@@ -7,6 +7,7 @@[malli.core :as mc][malli.util :as mut][medley.core :as m]+ [metabase.channel.db :as channel.db][metabase.channel.models.channel :as models.channel][metabase.lib.schema.common :as lib.schema.common][metabase.models.interface :as mi]@@ -316,7 +317,7 @@[notification-handler](when-let [template-id (:template_id notification-handler)](let [channel-type (keyword (:channel_type notification-handler))- template-type (notification.db/channel-template-channel-type template-id)]+ template-type (:channel_type (channel.db/channel-template template-id))](when (not= channel-type template-type)(throw (ex-info "Channel type and template type mismatch"{:status-code 400diff --git a/src/metabase/notification/payload/core.clj b/src/metabase/notification/payload/core.cljindex 60e90ab9fca..1a7bd61a07b 100644--- a/src/metabase/notification/payload/core.clj+++ b/src/metabase/notification/payload/core.clj@@ -4,13 +4,13 @@[malli.util :as mut][metabase.appearance.core :as appearance][metabase.channel.models.channel :as models.channel]- [metabase.notification.db :as notification.db][metabase.notification.models :as models.notification][metabase.notification.payload.execute :as notification.payload.execute][metabase.notification.payload.temp-storage :as notification.payload.temp-storage][metabase.parameters.schema :as parameters.schema][metabase.premium-features.core :as premium-features][metabase.system.core :as system]+ [metabase.users.db :as users.db][metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]@@ -177,7 +177,7 @@"Realize notification-info with :context and :payload."[notification :- ::Notification](assoc (select-keys notification [:payload_type :creator_id])- :creator (notification.db/user-summary (:creator_id notification))+ :creator (some-> (:creator_id notification) users.db/user (select-keys [:id :first_name :last_name :email :common_name])):payload (w/prewalk (fn [x](if (and (map? x) (:lib/metadata x))(dissoc x :lib/metadata)diff --git a/src/metabase/notification/payload/execute.clj b/src/metabase/notification/payload/execute.cljindex e721b748cc4..9a2797b640e 100644--- a/src/metabase/notification/payload/execute.clj+++ b/src/metabase/notification/payload/execute.clj@@ -4,6 +4,7 @@[medley.core :as m][metabase.api.common :as api][metabase.channel.urls :as urls]+ [metabase.dashboards.db :as dashboards.db][metabase.dashboards.models.dashboard-card :as dashboard-card][metabase.lib.schema.id :as lib.schema.id][metabase.models.interface :as mi]@@ -12,6 +13,7 @@[metabase.notification.payload.temp-storage :as notification.temp-storage][metabase.parameters.schema :as parameters.schema][metabase.parameters.shared :as shared.params]+ [metabase.queries.db :as queries.db][metabase.query-processor.card :as qp.card][metabase.query-processor.core :as qp][metabase.query-processor.dashboard :as qp.dashboard]@@ -200,13 +202,14 @@:or {spill-budget (new-spill-budget)}}](log/with-context {:card_id card_id}(try- (when-let [card (notification.db/unarchived-card card_id)]- (let [dashboard (notification.db/dashboard dashboard_id)+ (when-let [card (let [card (queries.db/card card_id)]+ (when-not (:archived card) card))]+ (let [dashboard (dashboards.db/dashboard dashboard_id)multi-cards (dashboard-card/dashcard->multi-cards dashcard)result-fn (fn [card-id](let [card (if (= card-id (:id card))card- (notification.db/card card-id))+ (queries.db/card card-id))attached-result? (and attached? (= card-id card_id))]{:card card:dashcard dashcard@@ -375,7 +378,7 @@"Returns the result for a card."[creator-id :- pos-int?card-id :- pos-int?]- (let [card (notification.db/card card-id)+ (let [card (queries.db/card card-id)result (request/with-current-user creator-id(-> (qp.card/process-query-for-card card :api;; TODO rename to :notification?diff --git a/src/metabase/notification/payload/impl/card.clj b/src/metabase/notification/payload/impl/card.cljindex 1a66cfc9738..662f9cb788f 100644--- a/src/metabase/notification/payload/impl/card.clj+++ b/src/metabase/notification/payload/impl/card.clj@@ -8,6 +8,7 @@[metabase.notification.payload.execute :as notification.execute][metabase.notification.payload.impl.dashboard :as notification.dashboard][metabase.notification.send :as notification.send]+ [metabase.queries.db :as queries.db][metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.ui-logic :as ui-logic]))@@ -24,7 +25,7 @@:status (:status card-result):error (:error card-result)}))){:card_part part- :card (notification.db/card card-id)+ :card (queries.db/card card-id):style {:color_text_dark channel.render/color-text-dark:color_text_light channel.render/color-text-light:color_text_medium channel.render/color-text-medium}diff --git a/src/metabase/notification/payload/impl/dashboard.clj b/src/metabase/notification/payload/impl/dashboard.cljindex 2de2e9426bf..289d79470f8 100644--- a/src/metabase/notification/payload/impl/dashboard.clj+++ b/src/metabase/notification/payload/impl/dashboard.clj@@ -1,8 +1,8 @@(ns metabase.notification.payload.impl.dashboard(:require[metabase.channel.render.core :as channel.render]+ [metabase.dashboards.db :as dashboards.db][metabase.events.core :as events]- [metabase.notification.db :as notification.db][metabase.notification.payload.core :as notification.payload][metabase.notification.payload.execute :as notification.execute][metabase.notification.send :as notification.send]@@ -44,7 +44,7 @@[{:keys [creator_id dashboard_subscription handlers] :as _notification-info} :- ::notification.payload/Notification](log/with-context {:dashboard_id (:dashboard_id dashboard_subscription)}(let [dashboard-id (:dashboard_id dashboard_subscription)- dashboard (t2/hydrate (notification.db/dashboard dashboard-id) :tabs)+ dashboard (t2/hydrate (dashboards.db/dashboard dashboard-id) :tabs)parameters (parameters (:parameters dashboard_subscription) (:parameters dashboard))attached-ids (attached-card-ids dashboard_subscription)only-card-ids (when (attachment-only? handlers)diff --git a/src/metabase/notification/payload/impl/system_event.clj b/src/metabase/notification/payload/impl/system_event.cljindex 29d437ce8bd..8f505abed5c 100644--- a/src/metabase/notification/payload/impl/system_event.clj+++ b/src/metabase/notification/payload/impl/system_event.clj@@ -5,11 +5,11 @@[metabase.auth-identity.core :as auth-identity][metabase.channel.email.messages :as messages][metabase.channel.urls :as urls]- [metabase.notification.db :as notification.db][metabase.notification.payload.core :as notification.payload][metabase.session.core :as session][metabase.sso.core :as sso][metabase.system.core :as system]+ [metabase.users.db :as users.db][metabase.users.models.user :as user][metabase.util.i18n :refer [trs]][metabase.util.malli :as mu]))@@ -20,7 +20,7 @@(let [reset-token (auth-identity/create-password-reset! user-id)should-link-to-login-page (and (sso/sso-enabled?)(not (session/enable-password-login)))- email (notification.db/user-email user-id)]+ email (:email (users.db/user user-id))](if should-link-to-login-page(cond-> (str (system/site-url) "/auth/login")redirect (str "?redirect=" redirect))diff --git a/src/metabase/notification/send.clj b/src/metabase/notification/send.cljindex 07886167504..672955310a2 100644--- a/src/metabase/notification/send.clj+++ b/src/metabase/notification/send.clj@@ -573,7 +573,7 @@(case payload_type:notification/card (when-let [card-id (or (:card_id payload)(some->> payload_id- notification.db/notification-card-card-id))]+ notification.db/notification-card :card_id))]{:run_type :alert:entity_type :card:entity_id card-iddiff --git a/src/metabase/notification/task/send.clj b/src/metabase/notification/task/send.cljindex c3e7cf8cf78..656f97fd34d 100644--- a/src/metabase/notification/task/send.clj+++ b/src/metabase/notification/task/send.clj@@ -17,7 +17,7 @@(defn- send-notification*[subscription-id]- (let [subscription (notification.db/subscription subscription-id)+ (let [subscription (notification.db/notification-subscription subscription-id)notification-id (:notification_id subscription)notification (notification.db/notification notification-id)](log/with-context {:subscription-id subscription-iddiff --git a/src/metabase/parameters/chain_filter.clj b/src/metabase/parameters/chain_filter.cljindex 0a03948e87c..baf971d4209 100644--- a/src/metabase/parameters/chain_filter.clj+++ b/src/metabase/parameters/chain_filter.clj@@ -91,6 +91,7 @@[metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.metadata-queries :as schema.metadata-queries][metabase.warehouse-schema.models.field :as field][metabase.warehouse-schema.models.field-values :as field-values]))@@ -755,8 +756,8 @@;; TODO: why don't we remap the human readable values here?(let [{:keys [values] has-more-values? :has_more_values}(if (empty? constraints)- (params.field-values/get-or-create-field-values-for-current-user! (parameters.db/field field-id))- (params.field-values/get-or-create-linked-filter-field-values! (parameters.db/field field-id) constraints))]+ (params.field-values/get-or-create-field-values-for-current-user! (warehouse-schema.db/field field-id))+ (params.field-values/get-or-create-linked-filter-field-values! (warehouse-schema.db/field field-id) constraints))]{:values (cond->> valueslimit (take limit)):has_more_values (or (when limit@@ -819,7 +820,7 @@(let [{the-remapped-field-id :id, :keys [mapping-type]} @remapping](if-let [pk-field-id (when (and (= mapping-type :fk->pk->name)relax-fk-requirement?)- (parameters.db/field-fk-target-field-id field-id))]+ (:fk_target_field_id (warehouse-schema.db/field field-id)))](unremapped-chain-filter the-remapped-field-id(map #(cond-> %(= (:field-id %) field-id) (assoc :field-id pk-field-id))@@ -893,12 +894,13 @@(defn- check-valid-search-field"Before running a search query, make sure the Field actually exists and that it's a Text field."[field-id]- (let [base-type (parameters.db/field-base-type field-id)]+ (let [field (warehouse-schema.db/field field-id)+ base-type (:base_type field)](when-not base-type(throw (ex-info (tru "Field {0} does not exist." field-id){:field field-id, :status-code 404})))(when-not (isa? base-type :type/Text)- (let [field-name (parameters.db/field-name field-id)]+ (let [field-name (:name field)](throw (ex-info (tru "Cannot search against non-Text Field {0} {1}" field-id (pr-str field-name)){:status-code 400:field-id field-id@@ -944,7 +946,7 @@:has_more_values false}))(defn- search-cached-field-values? [field-id constraints]- (let [field (parameters.db/field field-id)]+ (let [field (warehouse-schema.db/field field-id)](and (use-cached-field-values? field-id)(isa? (:base_type field) :type/Text);; if we are doing a search, make sure we only use field values when we're certain the fieldvalues we storeddiff --git a/src/metabase/parameters/custom_values.clj b/src/metabase/parameters/custom_values.cljindex f10a570cfe7..5723936256e 100644--- a/src/metabase/parameters/custom_values.clj+++ b/src/metabase/parameters/custom_values.clj@@ -17,6 +17,7 @@[metabase.models.interface :as mi][metabase.parameters.db :as parameters.db][metabase.parameters.schema :as parameters.schema]+ [metabase.queries.db :as queries.db][metabase.query-processor :as qp][metabase.util :as u][metabase.util.i18n :refer [tru]]@@ -234,7 +235,7 @@(case (:values_source_type parameter):static-list (static-list-values parameter query-string):card (let [config (:values_source_config parameter)- card (parameters.db/card (:card_id config))]+ card (queries.db/card (:card_id config))](when-not (mi/can-read? card)(throw (ex-info "You don't have permissions to do that." {:status-code 403})))(or (when-not (:archived card)@@ -285,7 +286,7 @@[{config :values_source_config :as _param} :- ::parameters.schema/parametervalue :- [:or ms/FieldValue [:sequential ms/FieldValue]]](when-let [label-field (:label_field config)]- (when-let [card (parameters.db/card (:card_id config))]+ (when-let [card (queries.db/card (:card_id config))](when (and (not (:archived card)) (mi/can-read? card))(when-let [query (card-query (:id card) (some-> (:dataset_query card) not-empty lib-be/normalize-query))](when (can-get-card-values? query (:value_field config))diff --git a/src/metabase/parameters/db.clj b/src/metabase/parameters/db.cljindex d77b8351c52..0757231d84b 100644--- a/src/metabase/parameters/db.clj+++ b/src/metabase/parameters/db.clj@@ -75,11 +75,6 @@:limit 1})(update :mapping_type mapping-type-code->name)))-(mu/defn field- "The Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query)]}))-(mu/defn fields"The Fields with `field-ids`."[field-ids :- [:set ::lib.schema.id/field]]@@ -90,21 +85,6 @@[field-ids :- [:set ::lib.schema.id/field]](t2/select [:model/Field :id :fk_target_field_id :semantic_type] :id [:in field-ids] {:from [(warehouse-schema-overlay/field-query)]}))-(mu/defn field-fk-target-field-id- "The FK target Field id of the Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one-fn :fk_target_field_id :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query)]}))--(mu/defn field-base-type- "The base type of the Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one-fn :base_type :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))--(mu/defn field-name- "The name of the Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one-fn :name :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))-(mu/defn full-field-values-exist?"Whether complete, non-remapped FieldValues of type `full` exist for the Field with `field-id`."[field-id :- ::lib.schema.id/field]@@ -120,11 +100,6 @@:field_id field-id, :values [:not= nil], :human_readable_values nil, :has_more_values false:type "advanced", :hash_key hash-key))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(mu/defn delete-field-values!"Delete the FieldValues with `id`, returning the number deleted."[id :- ms/PositiveInt]diff --git a/src/metabase/parameters/field.clj b/src/metabase/parameters/field.cljindex b701cebdc4c..0799897c84d 100644--- a/src/metabase/parameters/field.clj+++ b/src/metabase/parameters/field.clj@@ -6,7 +6,6 @@[metabase.lib.core :as lib][metabase.lib.schema.id :as lib.schema.id][metabase.parameters.chain-filter :as chain-filter]- [metabase.parameters.db :as parameters.db][metabase.parameters.field-values :as params.field-values][metabase.parameters.field.search-values-query :as search-values-query][metabase.query-processor.middleware.permissions :as qp.perms]@@ -14,6 +13,7 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.metadata-from-qp :as warehouse-schema.metadata-from-qp][metabase.warehouse-schema.schema :as warehouse-schema.schema])(:import@@ -33,7 +33,7 @@[{semantic-type :semantic_type, fk-target-field-id :fk_target_field_id, :as field}](if (and (isa? semantic-type :type/FK)fk-target-field-id)- (parameters.db/field fk-target-field-id)+ (warehouse-schema.db/field fk-target-field-id)field))(def ^:private default-max-field-search-limit 1000)@@ -89,7 +89,7 @@(if-let [remapped-field-id (when (= has-field-values-type :list)(chain-filter/remapped-field-id field-id))]{:values (search-values (api/check-404 field)- (api/check-404 (parameters.db/field remapped-field-id)))+ (api/check-404 (warehouse-schema.db/field remapped-field-id))):field_id field-id:has_more_values (boolean has_more_values)}(params.field-values/get-or-create-field-values-for-current-user! (api/check-404 field))))@@ -101,10 +101,10 @@Field->Field remapping."[field-id](let [field (if qp.perms/*param-values-query*- (api/check-404 (parameters.db/field field-id))- (api/read-check (parameters.db/field field-id)))+ (api/check-404 (warehouse-schema.db/field field-id))+ (api/read-check (warehouse-schema.db/field field-id)))search-field (or (some->> (chain-filter/remapped-field-id field-id)- parameters.db/field)+ warehouse-schema.db/field)field)][field search-field]))diff --git a/src/metabase/permissions/db.clj b/src/metabase/permissions/db.cljindex cf761ffa325..e238d19d967 100644--- a/src/metabase/permissions/db.clj+++ b/src/metabase/permissions/db.clj@@ -17,6 +17,16 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))+(mu/defn permissions-group-membership :- [:maybe ::permissions.schema/permissions-group-membership]+ "The ::permissions.schema/permissions-group-membership with `permissions-group-membership-id`, or nil."+ [permissions-group-membership-id :- ms/PositiveInt]+ (t2/select-one :model/PermissionsGroupMembership :id [:auto/param permissions-group-membership-id]))++(mu/defn permissions-group :- [:maybe ::permissions.schema/permissions-group]+ "The ::permissions.schema/permissions-group with `permissions-group-id`, or nil."+ [permissions-group-id :- ms/PositiveInt]+ (t2/select-one :model/PermissionsGroup :id [:auto/param permissions-group-id]))+;;; --------------------------------------------- DataPermissions ---------------------------------------------(defn- perm-rows-query-base@@ -332,11 +342,6 @@[](t2/select :model/PermissionsGroup {:where [:= :magic_group_type nil]}))-(mu/defn tenant-group?- "Whether the PermissionsGroup with `group-id` is a tenant group."- [group-id :- ms/PositiveInt]- (t2/select-one-fn :is_tenant_group :model/PermissionsGroup :id group-id))-(mu/defn tenant-group-ids"The IDs of every tenant PermissionsGroup."[]@@ -544,11 +549,6 @@;;; ----------------------------------------------- Collections ------------------------------------------------(mu/defn collection- "The Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one :model/Collection :id collection-id))-(mu/defn personal-or-descendant-collection-ids"The IDs among `collection-ids` that are personal Collections, or descendants of one."[collection-ids :- [:set ::lib.schema.id/collection]]@@ -745,11 +745,6 @@[table-id :- ::lib.schema.id/table](t2/select-one [:model/Table :id :db_id :schema :data_source] :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(mu/defn table-database-id- "The Database ID of the Table with `table-id`."- [table-id :- ::lib.schema.id/table]- (t2/select-one-fn :db_id :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(mu/defn table-database-ids"The ID and Database ID of the Tables with `table-ids`."[table-ids :- [:set ::lib.schema.id/table]]diff --git a/src/metabase/permissions/models/data_permissions.clj b/src/metabase/permissions/models/data_permissions.cljindex 696803f2c55..579766a02e7 100644--- a/src/metabase/permissions/models/data_permissions.clj+++ b/src/metabase/permissions/models/data_permissions.clj@@ -18,6 +18,7 @@[metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.schema][metabase.warehouses.schema][methodical.core :as methodical]@@ -1309,7 +1310,7 @@(let [table-or-id (first (keys table-perms))db-id (if (map? table-or-id)(:db_id table-or-id)- (permissions.db/table-database-id table-or-id))]+ (:db_id (warehouse-schema.db/table table-or-id)))](with-cluster-lock {:perm-type (u/qualified-name perm-type):db-id db-id}(set-table-permissions-internal! group-or-id perm-type table-perms))))diff --git a/src/metabase/permissions/models/permissions.clj b/src/metabase/permissions/models/permissions.cljindex 5a9bf1b80a0..c6f492d345a 100644--- a/src/metabase/permissions/models/permissions.clj+++ b/src/metabase/permissions/models/permissions.clj@@ -162,6 +162,7 @@[clojure.string :as str][metabase.api.common :as api][metabase.audit-app.core :as audit]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection.root :as collection.root][metabase.config.core :as config][metabase.models.interface :as mi]@@ -328,7 +329,7 @@(defmethod mi/can-create? :perms/use-parent-collection-perms[_model m](if-let [collection-id (:collection_id m)]- (mi/can-write? (permissions.db/collection collection-id))+ (mi/can-write? (collections.db/collection collection-id))(mi/can-write? collection.root/root-collection)));;; +----------------------------------------------------------------------------------------------------------------+@@ -559,7 +560,7 @@[collection-or-id](if (map? collection-or-id)collection-or-id- (permissions.db/collection (u/the-id collection-or-id))))+ (collections.db/collection (u/the-id collection-or-id))))(mu/defn- check-is-modifiable-collection"Check whether `collection-or-id` refers to a collection that can have permissions modified. Personal collections, thediff --git a/src/metabase/permissions/models/permissions_group.clj b/src/metabase/permissions/models/permissions_group.cljindex ced4ce28e3b..68cc806d7a5 100644--- a/src/metabase/permissions/models/permissions_group.clj+++ b/src/metabase/permissions/models/permissions_group.clj@@ -174,7 +174,7 @@(defn is-tenant-group?"Returns a boolean representing whether this group is a tenant group."[group-id]- (permissions.db/tenant-group? (u/the-id group-id)))+ (:is_tenant_group (permissions.db/permissions-group (u/the-id group-id))))(defn hidden-tenant-group-ids"Returns the subset of `group-ids` that are tenant groups while the Tenants feature is disableddiff --git a/src/metabase/permissions_rest/api.clj b/src/metabase/permissions_rest/api.cljindex 54bb71b74cf..cbd0d9c5733 100644--- a/src/metabase/permissions_rest/api.clj+++ b/src/metabase/permissions_rest/api.clj@@ -9,6 +9,7 @@[metabase.permissions-rest.db :as permissions-rest.db][metabase.permissions-rest.schema :as permissions-rest.schema][metabase.permissions.core :as perms]+ [metabase.permissions.db :as permissions.db][metabase.premium-features.core :as premium-features :refer [defenterprise]][metabase.request.core :as request][metabase.settings.core :as setting]@@ -181,7 +182,7 @@(perms/check-manager-of-group id)(api/check-404 (empty? (perms/hidden-tenant-group-ids [id])))(api/check-404- (some-> (permissions-rest.db/permissions-group id)+ (some-> (permissions.db/permissions-group id)(t2/hydrate :members)(maybe-fix-name (setting/get :use-tenants)))))@@ -240,11 +241,11 @@[:name ms/NonBlankString]]](perms/check-manager-of-group group-id)(api/check-404 (empty? (perms/hidden-tenant-group-ids [group-id])))- (let [group (permissions-rest.db/permissions-group group-id)]+ (let [group (permissions.db/permissions-group group-id)](api/check-404 group)(permissions-rest.db/rename-permissions-group! group-id name);; return the updated group- (u/prog1 (permissions-rest.db/permissions-group group-id)+ (u/prog1 (permissions.db/permissions-group group-id)(events/publish-event! :event/group-update{:user-id api/*current-user-id*:object <>@@ -260,7 +261,7 @@[:group-id ms/PositiveInt]]](perms/check-manager-of-group group-id)(api/check-404 (empty? (perms/hidden-tenant-group-ids [group-id])))- (let [group (permissions-rest.db/permissions-group group-id)]+ (let [group (permissions.db/permissions-group group-id)](permissions-rest.db/delete-permissions-group! group-id)(events/publish-event! :event/group-delete {:object group:user-id api/*current-user-id*}))@@ -328,7 +329,7 @@(perms/check-advanced-permissions-enabled :group-manager);; Make sure only Super user or Group Managers can call this(perms/check-group-manager)- (let [old (permissions-rest.db/group-membership id)]+ (let [old (permissions.db/permissions-group-membership id)](api/check-404 old)(perms/check-tenant-groups-visible! [(:group_id old)])(perms/check-manager-of-group (:group_id old))@@ -336,7 +337,7 @@(permissions-rest.db/non-admin-user-exists? (:user_id old))[400 (tru "Admin cannot be a group manager.")])(permissions-rest.db/set-group-membership-manager! (:id old) is_group_manager)- (permissions-rest.db/group-membership (:id old))))+ (permissions.db/permissions-group-membership (:id old))));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happen@@ -361,7 +362,7 @@"Remove a User from a PermissionsGroup (delete their membership)."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (let [membership (permissions-rest.db/group-membership id)]+ (let [membership (permissions.db/permissions-group-membership id)](api/check-404 membership)(perms/check-tenant-groups-visible! [(:group_id membership)])(perms/check-manager-of-group (:group_id membership))diff --git a/src/metabase/permissions_rest/db.clj b/src/metabase/permissions_rest/db.cljindex f1ef3c4174c..189cc28ffee 100644--- a/src/metabase/permissions_rest/db.clj+++ b/src/metabase/permissions_rest/db.clj@@ -62,11 +62,6 @@limit (assoc :limit limit)offset (assoc :offset offset)))))-(mu/defn permissions-group- "The PermissionsGroup with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/PermissionsGroup :id id))-(mu/defn permissions-group-exists?"Whether a PermissionsGroup with `id` exists."[id :- ms/PositiveInt]@@ -110,11 +105,6 @@[user-id :- ::lib.schema.id/user](t2/exists? :model/User :id user-id :is_superuser false))-(mu/defn group-membership- "The PermissionsGroupMembership with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/PermissionsGroupMembership :id id))-(mu/defn set-group-membership-manager!"Set the group manager flag of the PermissionsGroupMembership with `id`, returning the number updated."[id :- ms/PositiveIntdiff --git a/src/metabase/public_sharing_rest/api.clj b/src/metabase/public_sharing_rest/api.cljindex 136e73a0afe..fc8e2b0d7cf 100644--- a/src/metabase/public_sharing_rest/api.clj+++ b/src/metabase/public_sharing_rest/api.clj@@ -9,7 +9,9 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.dashboards-rest.api :as api.dashboard]+ [metabase.dashboards.db :as dashboards.db][metabase.dashboards.schema :as dashboards.schema]+ [metabase.documents.db :as documents.db][metabase.documents.prose-mirror :as prose-mirror][metabase.events.core :as events][metabase.lib.core :as lib]@@ -27,6 +29,7 @@[metabase.public-sharing.core :as public-sharing][metabase.public-sharing.validation :as public-sharing.validation][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.queries.schema :as queries.schema][metabase.query-processor.card :as qp.card][metabase.query-processor.dashboard :as qp.dashboard]@@ -114,13 +117,62 @@(seq query) blank-dataset-query)))params/remove-param-fields-non-public-columns))))+(def ^:private public-card-columns+ [:id :dataset_query :description :display :name :parameters :visualization_settings+ :card_schema :type :entity_id :result_metadata :dimensions :dimension_mappings])++(def ^:private public-dashboard-columns+ [:name :description :id :parameters :auto_apply_filters :width])++(defn- active-card+ "The non-archived Card with `card-id`, or nil."+ [card-id]+ (when-let [card (some-> card-id queries.db/card)]+ (when-not (:archived card)+ card)))++(defn- active-card-in-document+ "The non-archived Card with `card-id` that belongs to the Document with `document-id`, or nil."+ [card-id document-id]+ (when-let [card (active-card card-id)]+ (when (= document-id (:document_id card))+ card)))++(defn- public-card-row+ "The non-archived Card with `card-id` with only its public columns, or nil, requiring embedding when `:enable-embedding?`."+ [card-id {:keys [enable-embedding?]}]+ (when-let [card (active-card card-id)]+ (when (or (not enable-embedding?) (:enable_embedding card))+ (mi/instance :model/Card (select-keys card public-card-columns)))))++(defn- public-dashboard-row+ "The non-archived Dashboard with `dashboard-id` with only its public columns, or nil, requiring embedding when `:enable-embedding?`."+ [dashboard-id {:keys [enable-embedding?]}]+ (when-let [dashboard (some-> dashboard-id dashboards.db/dashboard)]+ (when (and (not (:archived dashboard))+ (or (not enable-embedding?) (:enable_embedding dashboard)))+ (mi/instance :model/Dashboard (select-keys dashboard public-dashboard-columns)))))++(defn- public-document-row+ "The non-archived Document with `document-id`, restricted to the columns safe to expose publicly, or nil."+ [document-id]+ (when-let [document (some-> document-id documents.db/document)]+ (when-not (:archived document)+ (mi/instance :model/Document+ (select-keys document [:id :name :document :content_type :created_at :updated_at])))))++(defn- document-content+ "The id, content, and content type of the Document with `document-id`, or nil."+ [document-id]+ (some-> document-id documents.db/document (select-keys [:id :document :content_type])))+(defn public-card"Return the public Card with the given `card-id`, removing all columns that should not be visible to the generalpublic. Throws a 404 if the Card doesn't exist. With `:enable-embedding? true`, additionally requires embeddingto be enabled."[card-id & {:as options}](binding [params/*ignore-current-user-perms-and-return-all-field-values* true]- (-> (api/check-404 (public-sharing-rest.db/public-card card-id options))+ (-> (api/check-404 (public-card-row card-id options))combine-parameters-and-template-tags(t2/hydrate :param_fields)keep-param-fields-for-parameters@@ -195,7 +247,7 @@(mu/defn process-query-for-card-with-id"Run the query for pre-loaded Card `card` with `parameters` and other query options (e.g. `:constraints`).- Callers are responsible for resolving `card` themselves with a fresh `public-sharing-rest.db/active-card` call (each endpoint should+ Callers are responsible for resolving `card` themselves with a fresh `active-card` call (each endpoint shouldselect the Card exactly once and thread the loaded entity here). Returns a `StreamingResponse`."[card :- ::queries.schema/cardexport-format :- [:maybe :keyword]@@ -347,7 +399,7 @@& {:as options} :- [:maybe [:map {:closed true} [:enable-embedding? {:optional true} [:maybe :boolean]]]]](binding [params/*ignore-current-user-perms-and-return-all-field-values* trueparams/*field-id-context* (atom params/empty-field-id-context)]- (-> (api/check-404 (public-sharing-rest.db/public-dashboard dashboard-id options))+ (-> (api/check-404 (public-dashboard-row dashboard-id options))(t2/hydrate [:dashcards :card :series :dashcard/action] :tabs :param_fields)keep-param-fields-for-parametersparams/remove-param-fields-non-public-columns@@ -444,9 +496,9 @@[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](public-sharing.validation/check-public-sharing-enabled)- (let [card (api/check-404 (public-sharing-rest.db/active-card card-id))+ (let [card (api/check-404 (active-card card-id))dashboard (api/check-404 (public-sharing/public-uuid->model :model/Dashboard uuid))- dashcard (api/check-404 (public-sharing-rest.db/dashcard dashcard-id))]+ dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))](process-query-for-dashcard:dashboard dashboard:card card@@ -474,9 +526,9 @@[:pivot_results {:default false} ms/BooleanValue][:csv_include_bom {:optional true} [:maybe ms/BooleanValue]]]](public-sharing.validation/check-public-sharing-enabled)- (let [card (api/check-404 (public-sharing-rest.db/active-card card-id))+ (let [card (api/check-404 (active-card card-id))dashboard (api/check-404 (public-sharing/public-uuid->model :model/Dashboard uuid))- dashcard (api/check-404 (public-sharing-rest.db/dashcard dashcard-id))]+ dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))](u/prog1 (process-query-for-dashcard:dashboard dashboard:card card@@ -729,9 +781,9 @@[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](public-sharing.validation/check-public-sharing-enabled)- (let [card (api/check-404 (public-sharing-rest.db/active-card card-id))+ (let [card (api/check-404 (active-card card-id))dashboard (api/check-404 (public-sharing/public-uuid->model :model/Dashboard uuid))- dashcard (api/check-404 (public-sharing-rest.db/dashcard dashcard-id))]+ dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))](process-query-for-dashcard:dashboard dashboard:card card@@ -839,8 +891,8 @@[:lonField ::api.tiles/legacy-ref]]](public-sharing.validation/check-public-sharing-enabled)(let [dashboard (api/check-404 (public-sharing/public-uuid->model :model/Dashboard uuid))- dashcard (api/check-404 (public-sharing-rest.db/dashcard dashcard-id))- card (api/check-404 (public-sharing-rest.db/active-card card-id))]+ dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))+ card (api/check-404 (active-card card-id))](process-tiles-query-for-dashcard dashboard dashcard cardparameters zoom x y latField lonField)))@@ -863,7 +915,7 @@once before exposing them to unauthenticated users. The document and all cards must not be archived to beaccessible publicly."[document-id]- (let [document (-> (api/check-404 (public-sharing-rest.db/public-document document-id))+ (let [document (-> (api/check-404 (public-document-row document-id));; Hydrate cards via Toucan batched hydration to avoid N+1 queries(t2/hydrate :cards))embedded-ids (set (prose-mirror/card-ids document))]@@ -883,9 +935,9 @@Returns the loaded `:model/Card` entity so the caller can thread it downstream without re-selecting it."[uuid card-id]- (let [document (api/check-404 (public-sharing-rest.db/document-content (public-sharing/public-uuid->id :model/Document uuid)))]+ (let [document (api/check-404 (document-content (public-sharing/public-uuid->id :model/Document uuid)))](api/check-404 (when (contains? (set (prose-mirror/card-ids document)) card-id)- (public-sharing-rest.db/active-card-in-document card-id (:id document))))))+ (active-card-in-document card-id (:id document))))));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happendiff --git a/src/metabase/public_sharing_rest/db.clj b/src/metabase/public_sharing_rest/db.cljindex b9afa1a15d0..3802616bb6f 100644--- a/src/metabase/public_sharing_rest/db.clj+++ b/src/metabase/public_sharing_rest/db.clj@@ -9,47 +9,8 @@;;; ------------------------------------------------------ Cards --------------------------------------------------------(mu/defn public-card- "The non-archived Card with `card-id`, restricted to the columns safe to expose publicly, or nil. With- `:enable-embedding? true`, additionally requires embedding to be enabled."- [card-id :- [:maybe ::lib.schema.id/card]- & {:keys [enable-embedding?]} :- [:maybe [:map {:closed true} [:enable-embedding? {:optional true} [:maybe :boolean]]]]]- (t2/select-one [:model/Card :id :dataset_query :description :display :name :parameters :visualization_settings- :card_schema :type :entity_id :result_metadata :dimensions :dimension_mappings]- {:where [:and- [:= :id card-id]- [:= :archived false]- (when enable-embedding? [:= :enable_embedding true])]}))--(mu/defn active-card- "The non-archived Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id :archived false))--(mu/defn active-card-in-document- "The non-archived Card with `card-id` that belongs to the Document with `document-id`, or nil."- [card-id :- ::lib.schema.id/card- document-id :- ms/PositiveInt]- (t2/select-one :model/Card :id card-id :document_id document-id :archived false))-;;; ---------------------------------------------------- Dashboards -----------------------------------------------------(mu/defn public-dashboard- "The non-archived Dashboard with `dashboard-id`, restricted to the columns safe to expose publicly, or nil. With- `:enable-embedding? true`, additionally requires embedding to be enabled."- [dashboard-id :- [:maybe ::lib.schema.id/dashboard]- & {:keys [enable-embedding?]} :- [:maybe [:map {:closed true} [:enable-embedding? {:optional true} [:maybe :boolean]]]]]- (t2/select-one [:model/Dashboard :name :description :id :parameters :auto_apply_filters :width]- {:where [:and- [:= :id dashboard-id]- [:= :archived false]- (when enable-embedding? [:= :enable_embedding true])]}))--(mu/defn dashcard- "The DashboardCard with `dashcard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard]- (t2/select-one :model/DashboardCard :id dashcard-id))-(mu/defn dashcard-id-in-dashboard"`dashcard-id` if that DashboardCard belongs to the Dashboard with `dashboard-id`, otherwise nil."[dashcard-id :- ::lib.schema.id/dashcard@@ -58,17 +19,6 @@;;; ----------------------------------------------------- Documents -----------------------------------------------------(mu/defn public-document- "The non-archived Document with `document-id`, restricted to the columns safe to expose publicly."- [document-id :- [:maybe ms/PositiveInt]]- (t2/select-one [:model/Document :id :name :document :content_type :created_at :updated_at]- :id document-id, :archived false))--(mu/defn document-content- "The id, content, and content type of the Document with `document-id`, or nil."- [document-id :- [:maybe ms/PositiveInt]]- (t2/select-one [:model/Document :id :document :content_type] :id document-id))-;;; ----------------------------------------------------- Timelines ----------------------------------------------------(mu/defn active-timeline-idsdiff --git a/src/metabase/pulse/api/alert.clj b/src/metabase/pulse/api/alert.cljindex fa7ff68983a..7e89cd2058f 100644--- a/src/metabase/pulse/api/alert.clj+++ b/src/metabase/pulse/api/alert.clj@@ -9,7 +9,7 @@[metabase.classloader.core :as classloader][metabase.config.core :as config][metabase.notification.api :as notification.api]- [metabase.pulse.db :as pulse.db]+ [metabase.queries.db :as queries.db][metabase.util.cron :as u.cron][metabase.util.malli.schema :as ms]))@@ -23,7 +23,7 @@[notification](let [subscription (-> notification :subscriptions first)notification-card (-> notification :payload)- card (->> notification :payload :card_id pulse.db/card)]+ card (->> notification :payload :card_id queries.db/card)](merge(select-keys notification [:id :creator_id :creator :created_at :updated_at]){:name nildiff --git a/src/metabase/pulse/api/pulse.clj b/src/metabase/pulse/api/pulse.cljindex a31c9fda14e..d57bd0ec6e6 100644--- a/src/metabase/pulse/api/pulse.clj+++ b/src/metabase/pulse/api/pulse.clj@@ -25,6 +25,7 @@[metabase.pulse.models.pulse-channel :as pulse-channel][metabase.pulse.schema :as pulse.schema][metabase.pulse.send :as pulse.send]+ [metabase.queries.db :as queries.db][metabase.util :as u][metabase.util.i18n :refer [tru]][metabase.util.malli.registry :as mr]@@ -84,7 +85,7 @@(update pulse :cards(fn [cards](mapv (fn [card] (assoc card :download_perms (case (perms/download-perms-level- (or (:dataset_query card) (pulse.db/card-query (:id card)))+ (or (:dataset_query card) (:dataset_query (queries.db/card (:id card))))api/*current-user-id*):no :none:ten-thousand-rows :limiteddiff --git a/src/metabase/pulse/broken_subscriptions.clj b/src/metabase/pulse/broken_subscriptions.cljindex 11b53b941a0..de4526b558c 100644--- a/src/metabase/pulse/broken_subscriptions.clj+++ b/src/metabase/pulse/broken_subscriptions.clj@@ -3,8 +3,10 @@the dashboard they belong to."(:require[metabase.channel.email.messages :as messages]+ [metabase.dashboards.db :as dashboards.db][metabase.pulse.db :as pulse.db][metabase.pulse.models.pulse :as pulse]+ [metabase.users.db :as users.db][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -16,7 +18,7 @@- The user info for the creator of the pulse- The users affected by the pulse"[{bad-pulse-id :id pulse-name :name :keys [parameters creator_id]}]- (let [creator (pulse.db/user-name-and-email creator_id)+ (let [creator (select-keys (users.db/user creator_id) [:first_name :last_name :email])bad-pulse-channels (pulse.db/pulse-channel-kinds-for-pulse bad-pulse-id)]{:pulse-id bad-pulse-id:pulse-name pulse-name@@ -46,7 +48,7 @@[dashboard-id original-dashboard-params](when (seq original-dashboard-params)(let [{:keys [resolved-params]} (t2/hydrate- (pulse.db/dashboard-parameters dashboard-id)+ (dashboards.db/dashboard dashboard-id):resolved-params)dashboard-params (set (keys resolved-params))];; ordered so the notifications go out in a stable order rather than whatever order the rows come back in@@ -71,7 +73,7 @@(let [{dashboard-name :namedashboard-description :descriptiondashboard-creator :creator} (t2/hydrate- (pulse.db/dashboard-name-description-creator dashboard-id)+ (dashboards.db/dashboard dashboard-id):creator)](for [broken-pulse broken-pulses](assocdiff --git a/src/metabase/pulse/db.clj b/src/metabase/pulse/db.cljindex 2a3b4d5cd1a..d36236505c9 100644--- a/src/metabase/pulse/db.clj+++ b/src/metabase/pulse/db.clj@@ -9,38 +9,16 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card card-id))--(mu/defn card-query- "The query of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- ;; Written out by hand rather than using `metabase.queries.core/card-query-info`: `queries` already uses- ;; `pulse`, so requiring it back would add a module cycle for one query. Keep in sync with- ;; `metabase.queries.card-schema/schema-upgrade-triggers`.- (t2/select-one-fn :dataset_query- [:model/Card :id :dataset_query :card_schema :type :entity_id- :result_metadata :dimensions :dimension_mappings]- card-id))--(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil. `dashboard-id` may be nil (e.g. a legacy Pulse with no Dashboard), in- which case the result is nil."- [dashboard-id :- [:maybe ::lib.schema.id/dashboard]]- (t2/select-one :model/Dashboard :id dashboard-id))+(mu/defn pulse-channel :- [:maybe ::pulse.schema/pulse-channel]+ "The ::pulse.schema/pulse-channel with `pulse-channel-id`, or nil."+ [pulse-channel-id :- ms/PositiveInt]+ (t2/select-one :model/PulseChannel :id [:auto/param pulse-channel-id]))(mu/defn dashboard-archived? :- :boolean"Whether the Dashboard with `dashboard-id` exists and is archived."[dashboard-id :- [:maybe ::lib.schema.id/dashboard]](t2/exists? :model/Dashboard :id dashboard-id :archived true))-(mu/defn dashboard-collection-id- "The Collection id of the Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one-fn :collection_id :model/Dashboard, :id dashboard-id))-(mu/defn dashcard-ids-by-card"A map of Card id to DashboardCard id for the DashboardCards of the Dashboard with `dashboard-id` showing one of`card-ids`."@@ -66,11 +44,6 @@[:= :dc.dashboard_id dashboard-id][:not= :dc.card_id nil]]})))-(mu/defn channel- "The Channel with `channel-id`, or nil."- [channel-id :- ms/PositiveInt]- (t2/select-one :model/Channel :id channel-id))-(mu/defn active-http-channel-exists?"Whether an active HTTP Channel exists."[]@@ -86,26 +59,16 @@[user-ids :- [:set ::lib.schema.id/user]](t2/select-pk->fn :email :model/User, :id [:in user-ids]))-(mu/defn pulse- "The Pulse with `pulse-id`, or nil."+(mu/defn pulse :- [:maybe ::pulse.schema/pulse]+ "The ::pulse.schema/pulse with `pulse-id`, or nil."[pulse-id :- ::lib.schema.id/pulse]- (t2/select-one :model/Pulse :id pulse-id))+ (t2/select-one :model/Pulse :id [:auto/param pulse-id]))(mu/defn pulse-id"The id of the Pulse with `pulse-id` if it exists, or nil."[pulse-id :- ::lib.schema.id/pulse](t2/select-one-pk :model/Pulse :id pulse-id))-(mu/defn unarchived-pulse- "The unarchived Pulse with `pulse-id`, or nil."- [pulse-id :- ::lib.schema.id/pulse]- (t2/select-one :model/Pulse :id pulse-id :archived false))--(mu/defn unarchived-non-alert-pulse- "The unarchived, non-alert Pulse with `pulse-id`, or nil."- [pulse-id :- ::lib.schema.id/pulse]- (t2/select-one :model/Pulse :id pulse-id :archived false :alert_condition nil))-(mu/defn alert"The Pulse with `pulse-id` if it is an alert, or nil."[pulse-id :- ::lib.schema.id/pulse]@@ -280,11 +243,6 @@[pulse-id :- ::lib.schema.id/pulse](t2/select-one-pk :model/PulseChannel :pulse_id pulse-id :channel_type "email"))-(mu/defn pulse-channel-details- "The details of the PulseChannel with `channel-id`, or nil."- [channel-id :- ms/PositiveInt]- (t2/select-one-fn :details :model/PulseChannel :id channel-id))-(mu/defn pulse-channels-without-recipients"The id, details, Channel, and type of the PulseChannels of the Pulse with `pulse-id` that have no recipients."[pulse-id :- ::lib.schema.id/pulse]@@ -410,11 +368,6 @@[user-ids :- [:set ::lib.schema.id/user]](t2/select-pk->fn :tenant_id :model/User :id [:in user-ids]))-(defn user-name-and-email- "The first name, last name, and email of the User with `user-id`, or nil."- [user-id]- (t2/select-one [:model/User :first_name :last_name :email] user-id))-(defn users-names-and-emails"The first names, last names, and emails of the Users with `user-ids`."[user-ids]@@ -430,16 +383,6 @@[channel-id](t2/select [:model/PulseChannelRecipient :user_id] :pulse_channel_id channel-id))-(defn dashboard-parameters- "The id and parameters of the Dashboard with `dashboard-id`, or nil."- [dashboard-id]- (t2/select-one [:model/Dashboard :id :parameters] dashboard-id))--(defn dashboard-name-description-creator- "The name, description, and creator id of the Dashboard with `dashboard-id`, or nil."- [dashboard-id]- (t2/select-one [:model/Dashboard :name :description :creator_id] dashboard-id))-(defn unarchived-pulses-for-dashboard"The unarchived Pulses of the Dashboard with `dashboard-id`, in id order."[dashboard-id]diff --git a/src/metabase/pulse/models/pulse.clj b/src/metabase/pulse/models/pulse.cljindex 7490e3eaf8c..8a75cad4e18 100644--- a/src/metabase/pulse/models/pulse.clj+++ b/src/metabase/pulse/models/pulse.clj@@ -22,6 +22,7 @@[medley.core :as m][metabase.api.common :as api][metabase.collections.models.collection :as collection]+ [metabase.dashboards.db :as dashboards.db][metabase.events.core :as events][metabase.lib.core :as lib][metabase.lib.schema.id :as lib.schema.id]@@ -31,6 +32,7 @@[metabase.pulse.db :as pulse.db][metabase.pulse.models.pulse-channel :as pulse-channel][metabase.pulse.schema :as pulse.schema]+ [metabase.queries.db :as queries.db][metabase.util :as u][metabase.util.i18n :refer [deferred-tru tru]][metabase.util.malli :as mu]@@ -74,7 +76,7 @@(let [defaults {:parameters []}dashboard-id (:dashboard_id notification)collection-id (if dashboard-id- (pulse.db/dashboard-collection-id dashboard-id)+ (:collection_id (dashboards.db/dashboard dashboard-id))(:collection_id notification))notification (->> (for [[k v] notification:when (some? v)]@@ -184,7 +186,7 @@"Return true if the card has attachments and those can be read. If it has no attachments, return true"[card](if (or (:include_csv card) (:include_xls card))- (let [level (perms/download-perms-level (or (:dataset_query card) (pulse.db/card-query (:id card))) api/*current-user-id*)]+ (let [level (perms/download-perms-level (or (:dataset_query card) (:dataset_query (queries.db/card (:id card)))) api/*current-user-id*)](and level (not= level :no)))true))@@ -365,11 +367,12 @@{:pre [(even? (count additional-conditions))]}(let [id (u/the-id notification-or-id)opts (apply hash-map additional-conditions)]- (some-> (cond- (contains? opts :alert_condition) (pulse.db/unarchived-non-alert-pulse id)- (contains? opts :archived) (pulse.db/unarchived-pulse id)- :else (pulse.db/pulse id))- hydrate-notification)))+ (when-let [pulse (pulse.db/pulse id)]+ (when (cond+ (contains? opts :alert_condition) (and (not (:archived pulse)) (nil? (:alert_condition pulse)))+ (contains? opts :archived) (not (:archived pulse))+ :else true)+ (hydrate-notification pulse)))))(mu/defn- notification->alert :- (ms/InstanceOf :model/Pulse)"Take a generic `Notification` and put it in the standard `Alert` format the frontend expects. This really justdiff --git a/src/metabase/pulse/models/pulse_channel_recipient.clj b/src/metabase/pulse/models/pulse_channel_recipient.cljindex 17575bcfd32..62ee8aba65a 100644--- a/src/metabase/pulse/models/pulse_channel_recipient.clj+++ b/src/metabase/pulse/models/pulse_channel_recipient.clj@@ -17,7 +17,7 @@last-recipient? (zero? other-recipients-count)](when last-recipient?;; make sure this channel doesn't have any email-address (non-User) recipients.- (let [details (pulse.db/pulse-channel-details channel-id)+ (let [details (:details (pulse.db/pulse-channel channel-id))has-email-addresses? (seq (:emails details))](when-not has-email-addresses?(pulse.db/delete-pulse-channel! channel-id))))))diff --git a/src/metabase/pulse/schema.clj b/src/metabase/pulse/schema.cljindex bc114f2d263..db3d990025a 100644--- a/src/metabase/pulse/schema.clj+++ b/src/metabase/pulse/schema.clj@@ -85,11 +85,13 @@[:emails {:optional true} [:maybe [:sequential :string]]]])(mr/def ::pulse-channel- "A PulseChannel as selected from the app DB: every column of `:pulse_channel`."+ "A PulseChannel as selected from the app DB: every column of `:pulse_channel`, with `:details` as stored rather+ than as written."[:merge::pulse-channel.update[:map {:closed true}- [:id ms/PositiveInt]]])+ [:id ms/PositiveInt]+ [:details {:optional true} [:maybe [:map {::mr/deliberately-open true, :description "the column as stored"}]]]]])(mr/def ::pulse-channel.update"What an update (or insert) of a PulseChannel accepts: every column of `:pulse_channel` except `id`, all optional."diff --git a/src/metabase/pulse/send.clj b/src/metabase/pulse/send.cljindex 33bfedb3a76..2adddefda61 100644--- a/src/metabase/pulse/send.clj+++ b/src/metabase/pulse/send.clj@@ -3,9 +3,10 @@(:require[clojure.string :as str][medley.core :as m]+ [metabase.channel.db :as channel.db]+ [metabase.dashboards.db :as dashboards.db][metabase.models.interface :as mi][metabase.notification.core :as notification]- [metabase.pulse.db :as pulse.db][metabase.pulse.models.pulse :as models.pulse][metabase.task-history.core :as task-history][metabase.util :as u]@@ -52,7 +53,7 @@"The Channel row of an HTTP pulse channel, or nil for email and Slack pulse channels, which have none."[{channel-type :channel_type :as pulse-channel}](when (= :http (keyword channel-type))- (pulse.db/channel (:channel_id pulse-channel))))+ (channel.db/channel (:channel_id pulse-channel))))(defn- get-notification-handler[pulse-channel]@@ -188,7 +189,7 @@;; with-task-run is a no-op if already nested (e.g., from scheduler)(task-history/with-task-run (some-> (pulse->task-run-info pulse)(assoc :auto-complete (not async?)))- (let [dashboard (pulse.db/dashboard dashboard_id)+ (let [dashboard (some-> dashboard_id dashboards.db/dashboard)pulse (-> (mi/instance :model/Pulse pulse);; This is usually already done by this step, in the `send-pulses` task which uses `retrieve-pulse`;; to fetch the Pulse.diff --git a/src/metabase/queries/cached_result.clj b/src/metabase/queries/cached_result.cljindex dc2bfefa63d..167ede39992 100644--- a/src/metabase/queries/cached_result.clj+++ b/src/metabase/queries/cached_result.clj@@ -14,6 +14,7 @@(:require[metabase.api.common :as api][metabase.permissions.core :as perms]+ [metabase.queries.db :as queries.db][metabase.query-permissions.core :as query-perms][metabase.query-processor.result-serialization :as qp.result-serialization][metabase.util :as u]@@ -189,7 +190,7 @@FE already expects) from a stored_result row and an optional `sort` keyword. Returns nilwhen the blob is missing/unreadable so the caller can 404."[stored-result sort]- (when-let [qp-result (deserialize-cached-result (:result_data stored-result))]+ (when-let [qp-result (deserialize-cached-result (queries.db/stored-result-data (:id stored-result)))](let [sorted (apply-sort qp-result sort)data (:data sorted)]{:status "completed"diff --git a/src/metabase/queries/card_write_checks.clj b/src/metabase/queries/card_write_checks.cljindex 980f264e63c..dc37665ce90 100644--- a/src/metabase/queries/card_write_checks.clj+++ b/src/metabase/queries/card_write_checks.clj@@ -5,6 +5,7 @@(:require[metabase.api.common :as api][metabase.collections.models.collection :as collection]+ [metabase.dashboards.db :as dashboards.db][metabase.embedding.validation :as embedding.validation][metabase.lib-be.schema :as lib-be.schema][metabase.lib.core :as lib]@@ -47,7 +48,7 @@(cond;; you specified both - they must match(and specified-collection-id? dashboard-id)- (let [dashboard-collection-id (queries.db/dashboard-collection-id dashboard-id)]+ (let [dashboard-collection-id (:collection_id (dashboards.db/dashboard dashboard-id))](api/check-400 (= collection-id dashboard-collection-id)(tru "Mismatch detected between Dashboard''s `collection_id` ({0}) and `collection_id` ({1})"dashboard-collection-id@@ -56,7 +57,7 @@specified-collection-id? collection-id- dashboard-id (queries.db/dashboard-collection-id dashboard-id)+ dashboard-id (:collection_id (dashboards.db/dashboard dashboard-id)):else nil)))@@ -88,7 +89,7 @@(when (api/column-will-change? (:dashboard_id card-before-update) (get card-updates :dashboard_id ::api/not-provided))(check-allowed-to-remove-from-existing-dashboards card-before-update)(when-let [dashboard-id (:dashboard_id card-updates)]- (card/check-shared-dashboard-timeline-permissions! (queries.db/dashboard dashboard-id)+ (card/check-shared-dashboard-timeline-permissions! (dashboards.db/dashboard dashboard-id)[(merge card-before-update card-updates)])))(collection/check-allowed-to-change-collection card-before-update card-updates))diff --git a/src/metabase/queries/db.clj b/src/metabase/queries/db.cljindex 369e5ee0126..ebce04fc147 100644--- a/src/metabase/queries/db.clj+++ b/src/metabase/queries/db.clj@@ -17,6 +17,16 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))+(mu/defn stored-result :- [:maybe ::queries.schema/stored-result]+ "The ::queries.schema/stored-result with `stored-result-id`, or nil."+ [stored-result-id :- ms/PositiveInt]+ (t2/select-one :model/StoredResult :id [:auto/param stored-result-id]))++(mu/defn stored-result-data+ "The serialized result bytes of the StoredResult with `stored-result-id`, or nil."+ [stored-result-id :- ms/PositiveInt]+ (t2/select-one-fn :result_data [:model/StoredResult :result_data] :id [:auto/param stored-result-id]))+;;; ------------------------------------------------ Cards ------------------------------------------------(def ^:private not-in-exploration-document@@ -54,10 +64,10 @@not-in-exploration-document]}(seq order-columns) (assoc :order-by (mapv (fn [column] [column :asc]) order-columns)))))-(mu/defn card- "The Card with `card-id`, or nil."+(mu/defn card :- [:maybe ::queries.schema/card]+ "The ::queries.schema/card with `card-id`, or nil."[card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))+ (t2/select-one :model/Card :id [:auto/param card-id]))(mu/defn cards"The Cards with `card-ids` (nil entries, e.g. from virtual dashcards, are ignored)."@@ -84,16 +94,6 @@[card-id :- ::lib.schema.id/card](:dataset_query (card-query-info card-id)))-(mu/defn card-document-id- "The `:document_id` of the Card with `card-id`."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :document_id :model/Card :id card-id))--(mu/defn card-parameters- "The `:parameters` of the Card with `card-id`."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :parameters [:model/Card :parameters] :id card-id))-(mu/defn raw-card-dimensions"The raw `:dimensions` row of the Card with `card-id`."[card-id :- ::lib.schema.id/card]@@ -101,11 +101,6 @@:from [:report_card]:where [:= :id card-id]}))-(mu/defn card-database-and-table-ids- "The database and primary table IDs of the Card with `card-id`, as `:database-id` and `:table-id`."- [card-id :- ::lib.schema.id/card]- (t2/select-one [:model/Card [:database_id :database-id] [:table_id :table-id]] :id card-id))-(mu/defn cards-queries-info"The IDs and query-related fields of the Cards with `card-ids`.@@ -242,11 +237,6 @@[database-ids :- [:set ::lib.schema.id/database]](t2/select :model/Database :id [:in database-ids]))-(mu/defn database-name- "The name of the Database with `database-id`."- [database-id :- [:maybe ::lib.schema.id/database]]- (t2/select-one-fn :name :model/Database :id database-id))-(mu/defn field-database-info-for-ids"The id, name, table name, and Database id of the Fields with `field-ids`."[field-ids :- [:set ::lib.schema.id/field]]@@ -269,26 +259,11 @@[snippet-ids :- [:set ::lib.schema.id/native-query-snippet]](t2/select :model/NativeQuerySnippet :id [:in snippet-ids]))-(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id dashboard-id))-(mu/defn dashboards"The Dashboards with `dashboard-ids`."[dashboard-ids :- [:set ::lib.schema.id/dashboard]](t2/select :model/Dashboard :id [:in dashboard-ids]))-(mu/defn dashboard-collection-id- "The `:collection_id` of the Dashboard with `dashboard-id`."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one-fn :collection_id [:model/Dashboard :collection_id] :id dashboard-id))--(mu/defn dashboard-parameters- "The `:parameters` of the Dashboard with `dashboard-id`."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one-fn :parameters [:model/Dashboard :parameters] :id dashboard-id))-(mu/defn update-dashboard!"Apply `changes` to the Dashboard with `dashboard-id`, returning the number updated."[dashboard-id :- ::lib.schema.id/dashboarddiff --git a/src/metabase/queries/models/card.clj b/src/metabase/queries/models/card.cljindex 64ff60280c8..e4770220ac3 100644--- a/src/metabase/queries/models/card.clj+++ b/src/metabase/queries/models/card.clj@@ -16,6 +16,7 @@[metabase.config.core :as config][metabase.content-verification.core :as moderation][metabase.dashboards.autoplace :as autoplace]+ [metabase.dashboards.db :as dashboards.db][metabase.embedding.settings :as embed.settings][metabase.events.core :as events][metabase.graph.core :as graph]@@ -53,6 +54,7 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.fn :as mu.fn]+ [metabase.warehouses.db :as warehouses.db][methodical.core :as methodical][toucan2.core :as t2][toucan2.pipeline :as t2.pipeline]@@ -154,7 +156,7 @@[card](cond(contains? card :document_id) (:document_id card)- (:id card) (queries.db/card-document-id (:id card))+ (:id card) (:document_id (queries.db/card (:id card))):else ::not-adjudicable))(defn- parent-document-permits?@@ -356,7 +358,7 @@(doseq [{:keys [field-id field-name table-name field-db-id]} (queries.db/field-database-info-for-ids (set field-ids))](when-not (= field-db-id query-db-id)(throw (ex-info (letfn [(describe-database [db-id]- (format "%d %s" db-id (pr-str (queries.db/database-name db-id))))]+ (format "%d %s" db-id (pr-str (:name (warehouses.db/database db-id)))))](tru "Invalid Field Filter: Field {0} belongs to Database {1}, but the query is against Database {2}"(format "%d %s.%s" field-id (pr-str table-name) (pr-str field-name))(describe-database field-db-id)@@ -440,7 +442,7 @@changes)(defn- check-dashboard-internal-card-insert [card]- (let [correct-collection-id (queries.db/dashboard-collection-id (:dashboard_id card))+ (let [correct-collection-id (:collection_id (dashboards.db/dashboard (:dashboard_id card)))invalid? (or (and (contains? card :collection_id)(not= correct-collection-id (:collection_id card)))(not (contains? #{:question "question" nil} (:type card)))@@ -507,8 +509,8 @@(doseq [[[po-type po-id] param-cards](group-by (juxt :parameterized_object_type :parameterized_object_id) parameter-cards)](let [parameters (case po-type- :card (queries.db/card-parameters po-id)- :dashboard (queries.db/dashboard-parameters po-id))+ :card (:parameters (queries.db/card po-id))+ :dashboard (:parameters (dashboards.db/dashboard po-id)))affected-param-ids-set (cond;; update all parameters that use this card as source(:archived changes)@@ -1121,7 +1123,7 @@(defn- apply-dashboard-question-updates [card changes](if-let [dashboard-id (:dashboard_id changes)]- (assoc card :collection_id (queries.db/dashboard-collection-id dashboard-id))+ (assoc card :collection_id (:collection_id (dashboards.db/dashboard dashboard-id)))card))(defn- check-allowed-content@@ -1218,7 +1220,7 @@;;; ----------------------------------------------- Creating Cards ----------------------------------------------------(defn- autoplace-dashcard-for-card! [dashboard-id maybe-dashboard-tab-id card size]- (let [dashboard (t2/hydrate (queries.db/dashboard dashboard-id) :dashcards [:tabs :tab-cards])+ (let [dashboard (t2/hydrate (dashboards.db/dashboard dashboard-id) :dashcards [:tabs :tab-cards]){:keys [dashcards tabs]} dashboardtabs (remove #(when maybe-dashboard-tab-id (not= maybe-dashboard-tab-id (:id %))) tabs)already-on-dashboard? (seq (filter #(= (:id card) (:card_id %)) dashcards))]@@ -1247,7 +1249,7 @@(queries.db/delete-dashcards-for-card-on-dashboard! card-id dashboard-id)(when-let [dashcard-ids (seq (map :id (queries.db/dashcard-series-for-card-on-dashboard card-id dashboard-id)))](queries.db/delete-dashcard-series! (set dashcard-ids)))- (events/publish-event! :event/dashboard-update {:object (queries.db/dashboard dashboard-id)+ (events/publish-event! :event/dashboard-update {:object (dashboards.db/dashboard dashboard-id):user-id api/*current-user-id*}))(defn- autoplace-or-remove-dashcards-for-card!@@ -1321,7 +1323,7 @@(not (:dashboard_id input-card-data)))));; Gated here, not in `check-allowed-to-create-card!`: the copy endpoints skip that stack but still autoplace.(when-let [dashboard-id (and autoplace-dashboard-questions? (:dashboard_id input-card-data))]- (check-shared-dashboard-timeline-permissions! (queries.db/dashboard dashboard-id) [input-card-data]))+ (check-shared-dashboard-timeline-permissions! (dashboards.db/dashboard dashboard-id) [input-card-data]))(let [data-keys [:dataset_query :description :display :name :visualization_settings:parameters :parameter_mappings :collection_id :collection_position:cache_ttl :type :dashboard_id :document_id]diff --git a/src/metabase/queries/models/query.clj b/src/metabase/queries/models/query.cljindex e9ead8a55b6..befcb82be22 100644--- a/src/metabase/queries/models/query.clj+++ b/src/metabase/queries/models/query.clj@@ -1,6 +1,7 @@(ns metabase.queries.models.query"Functions related to the 'Query' model, which records stuff such as average query execution time."(:require+ [clojure.set :as set][metabase.lib-be.schema :as lib-be.schema][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata]@@ -165,7 +166,8 @@(if-let [source-card-id (lib/primary-source-card-id query)](let [card (or (lib.metadata/card query source-card-id);; Card may belong to a different Database; fetch from the app DB- (queries.db/card-database-and-table-ids source-card-id))]+ (some-> (queries.db/card source-card-id)+ (set/rename-keys {:database_id :database-id, :table_id :table-id})))](merge {:table-id nil, :database-id (:database query)} (select-keys card [:database-id :table-id])))(let [table-id (lib/primary-source-table-id query)]{:database-id database-iddiff --git a/src/metabase/queries/models/stored_result.clj b/src/metabase/queries/models/stored_result.cljindex 5945cd095d2..f1a990d98de 100644--- a/src/metabase/queries/models/stored_result.clj+++ b/src/metabase/queries/models/stored_result.clj@@ -10,7 +10,8 @@[metabase.models.interface :as mi][metabase.permissions.core :as perms][methodical.core :as methodical]- [toucan2.core :as t2]))+ [toucan2.core :as t2]+ [toucan2.tools.default-fields :as t2.default-fields]))(methodical/defmethod t2/table-name :model/StoredResult [_model] :stored_result)@@ -22,3 +23,6 @@(doto :model/StoredResult(derive :metabase/model)(derive :hook/timestamped?))++(t2.default-fields/define-default-fields :model/StoredResult+ [:id :creator_id :database_id :dataset_query :data_access_token :row_count :created_at :updated_at])diff --git a/src/metabase/queries_rest/api/card.clj b/src/metabase/queries_rest/api/card.cljindex 5644fe2fac4..452a9a8e33e 100644--- a/src/metabase/queries_rest/api/card.clj+++ b/src/metabase/queries_rest/api/card.clj@@ -23,6 +23,7 @@[metabase.public-sharing.validation :as public-sharing.validation][metabase.queries-rest.db :as queries-rest.db][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.queries.schema :as queries.schema][metabase.query-permissions.core :as query-perms][metabase.query-processor.api :as api.dataset]@@ -210,7 +211,7 @@"Get `Card` with ID."[id](let [with-last-edit-info #(first (revisions/with-last-edit-info [%] :card))- raw-card (queries-rest.db/card id)]+ raw-card (queries.db/card id)](-> raw-cardapi/read-checkhydrate-card-details@@ -427,7 +428,7 @@(fn [ids](every? pos-int? (api/parse-multi-values-param ids parse-long)))]]]]](let [exclude_ids (when exclude_ids (api/parse-multi-values-param exclude_ids parse-long))- card (-> (queries-rest.db/card id) api/check-404 api/read-check)+ card (-> (queries.db/card id) api/check-404 api/read-check)card-display (:display card)](when-not (supported-series-display-type card-display)(throw (ex-info (tru "Card with type {0} is not compatible to have series" (name card-display))@@ -573,7 +574,7 @@(let [query (:dataset_query card-updates)](queries/check-card-can-be-saved! query card-type)(check-parameter-permissions (:parameters card-updates)- (or query (queries-rest.db/card-query id)))+ (or query (:dataset_query (queries.db/card id))))(when-some [query (:dataset_query card-updates)](queries/check-no-save-cycle! id query))(let [card-before-update (t2/hydrate (api/write-check :model/Card id)@@ -751,7 +752,7 @@(collection/check-for-remote-sync-update card)));; what a single card's update publishes too: remote sync listens to learn what entered or left its scope(doseq [card cards]- (events/publish-event! :event/card-update {:object (queries-rest.db/card (u/the-id card))+ (events/publish-event! :event/card-update {:object (queries.db/card (u/the-id card)):previous-object (get before (u/the-id card)):user-id api/*current-user-id*}))))@@ -801,7 +802,7 @@ids. 404s (rather than 403s) on an unpaired id so it doesn't confirm the snapshot exists."[card-id stored-result-id sort](api/check-exists? :model/StoredResultUse :card_id card-id :stored_result_id stored-result-id)- (let [sr (api/check-404 (queries-rest.db/stored-result stored-result-id))]+ (let [sr (api/check-404 (queries.db/stored-result stored-result-id))](queries/assert-can-view-card-snapshots! card-id)(api/check-404 (queries/cached-dataset sr sort))))@@ -825,7 +826,7 @@request](let [resolved-card-id (eid-translation/->id-or-404 :card card-id)_ (some-> (data-apps/request-data-app request) (data-apps/check-card resolved-card-id))- card (api/check-404 (queries-rest.db/card resolved-card-id))]+ card (api/check-404 (queries.db/card resolved-card-id))](if stored_result_id(do(api/read-check card)@@ -879,7 +880,7 @@request](some-> (data-apps/request-data-app request) (data-apps/check-card card-id))(qp.card/process-query-for-card- (api/check-404 (queries-rest.db/card card-id)) export-format+ (api/check-404 (queries.db/card card-id)) export-format:parameters parameters:constraints nil:context (api.dataset/export-format->context export-format)@@ -909,7 +910,7 @@(api/check-superuser)(public-sharing.validation/check-public-sharing-enabled)(api/check-not-archived (api/read-check :model/Card card-id))- (let [{existing-public-uuid :public_uuid} (queries-rest.db/card-public-uuid-columns card-id)+ (let [{existing-public-uuid :public_uuid} (queries.db/card card-id)uuid (or existing-public-uuid(u/prog1 (str (random-uuid));; one transaction, so a failing handler cannot leave a saved link that a retry never reports@@ -918,7 +919,7 @@{:public_uuid <>:made_public_by_id api/*current-user-id*})(events/publish-event! :event/card-public-link-created- {:object (queries-rest.db/card card-id)+ {:object (queries.db/card card-id):object-id card-id:user-id api/*current-user-id*}))))]{:uuid uuid}))@@ -942,7 +943,7 @@{:public_uuid nil:made_public_by_id nil})(events/publish-event! :event/card-public-link-deleted- {:object (queries-rest.db/card card-id)+ {:object (queries.db/card card-id):object-id card-id:user-id api/*current-user-id*})){:status 204, :body nil})@@ -964,7 +965,7 @@[:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter-with-value]]]]request](some-> (data-apps/request-data-app request) (data-apps/check-card card-id))- (let [card (api/check-404 (queries-rest.db/card card-id))]+ (let [card (api/check-404 (queries.db/card card-id))](when dashboard_id(api/read-check :model/Dashboard dashboard_id))(qp.card/process-query-for-card card :apidiff --git a/src/metabase/queries_rest/db.clj b/src/metabase/queries_rest/db.cljindex 61981cf8aeb..89b7b35a36a 100644--- a/src/metabase/queries_rest/db.clj+++ b/src/metabase/queries_rest/db.clj@@ -85,26 +85,11 @@[table-id :- ::lib.schema.id/table](t2/select-one-fn :db_id :model/Table, :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))-(mu/defn cards-by-id"A map of Card id to Card for the Cards with `card-ids`."[card-ids :- [:sequential ::lib.schema.id/card]](t2/select-fn->fn :id identity :model/Card :id [:in card-ids]))-(mu/defn card-query- "The query of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :dataset_query :model/Card :id card-id))--(mu/defn card-public-uuid-columns- "The public uuid of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one [:model/Card :public_uuid] :id card-id))-(mu/defn compatible-series-cards"The unarchived Cards other than `excluded-card-id` displayed as one of `display-types`, newest first, whose id isless than `last-cursor` (when given), excluding `exclude-ids`, and whose lower-cased name matches the SQL LIKE@@ -132,11 +117,6 @@limit(assoc :limit limit))))-(mu/defn dashboard-collection-id- "The Collection id of the Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one-fn :collection_id [:model/Dashboard :collection_id] dashboard-id))-(mu/defn update-card!"Apply `changes` to the Card with `card-id`."[card-id :- ::lib.schema.id/card@@ -169,8 +149,3 @@[:or [:not= :collection_id new-collection-id-or-nil](when new-collection-id-or-nil[:= :collection_id nil])]]}))--(mu/defn stored-result- "The StoredResult with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one :model/StoredResult :id id))diff --git a/src/metabase/query_permissions/db.clj b/src/metabase/query_permissions/db.cljindex 49066ffd23d..63982a4e774 100644--- a/src/metabase/query_permissions/db.clj+++ b/src/metabase/query_permissions/db.clj@@ -7,17 +7,6 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn card-collection-id- "The `:collection_id` of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one [:model/Card :collection_id] :id card-id))--(mu/defn card-not-in-database- "The Card with `card-id` if it does not belong to the Database with `database-id`, or nil."- [card-id :- ::lib.schema.id/card- database-id :- ::lib.schema.id/database]- (t2/select-one :model/Card :id card-id :database_id [:!= database-id]))-(mu/defn field-table-ids"The set of Table ids of the Fields with `field-ids`."[field-ids :- [:or [:set ::lib.schema.id/field] [:sequential ::lib.schema.id/field]]]diff --git a/src/metabase/query_permissions/impl.clj b/src/metabase/query_permissions/impl.cljindex 14ce505289c..e3d7ec98a58 100644--- a/src/metabase/query_permissions/impl.clj+++ b/src/metabase/query_permissions/impl.clj@@ -16,6 +16,7 @@[metabase.lib.schema.id :as lib.schema.id][metabase.models.interface :as mi][metabase.permissions.core :as perms]+ [metabase.queries.db :as queries.db][metabase.query-permissions.db :as query-permissions.db][metabase.query-processor.error-type :as qp.error-type][metabase.query-processor.interface :as qp.i]@@ -182,7 +183,7 @@(if (qp.store/initialized?)(when-let [{:keys [collection-id]} (lib.metadata/card (qp.store/metadata-provider) card-id)](t2/instance :model/Card {:collection_id collection-id}))- (query-permissions.db/card-collection-id card-id))+ (queries.db/card card-id))(throw (Exception. (tru "Card {0} does not exist." card-id)))))(mu/defn- source-card-read-perms :- [:set perms/PathSchema]@@ -350,6 +351,13 @@table-id))table-id->required-perm))+(defn- card-not-in-database+ "The Card with `card-id` if it does not belong to the Database with `database-id`, or nil."+ [card-id database-id]+ (let [card (queries.db/card card-id)]+ (when (and card (not= database-id (:database_id card)))+ card)))+(defn- card[database-id card-id](or (some-> (lib.metadata.protocols/card (qp.store/metadata-provider) card-id)@@ -359,7 +367,7 @@;; used by the model upon which the action is defined. In this case, the underlying model whose;; permissions we need to check will not be exposed by the metadata provider, so we need a fallback.;; -- Noah- (query-permissions.db/card-not-in-database card-id database-id)+ (card-not-in-database card-id database-id)(throw (ex-info (tru "Card {0} does not exist." card-id){:type qp.error-type/invalid-query:card-id card-id}))))diff --git a/src/metabase/query_processor/api.clj b/src/metabase/query_processor/api.cljindex f5379ed021c..489a80556e0 100644--- a/src/metabase/query_processor/api.clj+++ b/src/metabase/query_processor/api.clj@@ -27,7 +27,6 @@[metabase.queries.core :as queries][metabase.query-processor :as qp][metabase.query-processor.compile :as qp.compile]- [metabase.query-processor.db :as query-processor.db][metabase.query-processor.middleware.constraints :as qp.constraints][metabase.query-processor.middleware.permissions :as qp.perms][metabase.query-processor.pivot :as qp.pivot]@@ -44,6 +43,7 @@;; defendpoint param schemas (ms/PositiveInt etc.); lib.schema has no API-param coercion schemas^{:clj-kondo/ignore [:discouraged-namespace]} [metabase.util.malli.schema :as ms][metabase.util.performance :refer [get-in select-keys]]+ [metabase.warehouse-schema.db :as warehouse-schema.db][steffan-westcott.clj-otel.api.trace.span :as span]));;; -------------------------------------------- Running a Query Normally --------------------------------------------@@ -74,7 +74,7 @@(let [table-id (when (= (lib/normalized-query-type query) :mbql/query)(lib/primary-source-table-id query))](when (int? table-id)- (events/publish-event! :event/table-read {:object (query-processor.db/table table-id)+ (events/publish-event! :event/table-read {:object (warehouse-schema.db/table table-id):user-id api/*current-user-id*})));; add sensible constraints for results limits on our query(let [source-card-id (when (= (lib/normalized-query-type query) :mbql/query)diff --git a/src/metabase/query_processor/db.clj b/src/metabase/query_processor/db.cljindex 352f28b7c92..5003d985431 100644--- a/src/metabase/query_processor/db.clj+++ b/src/metabase/query_processor/db.clj@@ -8,7 +8,6 @@[metabase.lib.schema.metadata :as lib.schema.metadata][metabase.queries.schema :as queries.schema][metabase.util.malli :as mu]- [metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay]^{:clj-kondo/ignore [:discouraged-namespace]}[toucan2.core :as t2]))@@ -16,11 +15,6 @@"A `java.time` instant, date, or date-time."[:fn #(instance? java.time.temporal.Temporal %)])-(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn dashcard-series-exists?"Whether the Card with `card-id` is a series of the DashboardCard with `dashcard-id`."[card-id :- [:maybe ::lib.schema.id/card]diff --git a/src/metabase/revisions/api.clj b/src/metabase/revisions/api.cljindex d8cab028523..f75985354c1 100644--- a/src/metabase/revisions/api.clj+++ b/src/metabase/revisions/api.clj@@ -120,7 +120,10 @@[:revision_id ms/PositiveInt]]](let [[model instance] (model-and-instance entity id)_ (api/write-check instance)- revision (api/check-404 (revisions.db/revision (name model) id revision-id))]+ revision (api/check-404 (let [revision (revisions.db/revision revision-id)]+ (when (and (= (name model) (:model revision))+ (= id (:model_id revision)))+ revision)))];; if reverting a Card, make sure we have *data* permissions to run the query we're reverting to(when (= model :model/Card);; TODO -- we should be using something like `api/read-check` for this, but unfortunately the impl for Cardsdiff --git a/src/metabase/revisions/db.clj b/src/metabase/revisions/db.cljindex 925ede6fd42..67fb507369f 100644--- a/src/metabase/revisions/db.clj+++ b/src/metabase/revisions/db.clj@@ -4,6 +4,7 @@(:require[malli.core :as mc][metabase.lib.schema.id :as lib.schema.id]+ [metabase.revisions.schema :as revisions.schema][metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]@@ -82,17 +83,10 @@[card-ids :- [:set ::lib.schema.id/card]](t2/select-pk->fn :dataset_query :model/Card :id [:in card-ids]))-(mu/defn revision- "The Revision with `revision-id` of the `model-name` row with `model-id`, or nil."- [model-name :- :string- model-id :- ms/PositiveInt- revision-id :- ms/PositiveInt]- (t2/select-one :model/Revision :model model-name, :model_id model-id, :id revision-id))--(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))+(mu/defn revision :- [:maybe ::revisions.schema/revision]+ "The ::revisions.schema/revision with `revision-id`, or nil."+ [revision-id :- ms/PositiveInt]+ (t2/select-one :model/Revision :id [:auto/param revision-id]))(mu/defn dashcards"The DashboardCards of the Dashboard with `dashboard-id`."@@ -176,13 +170,6 @@model-id :- ms/PositiveInt](t2/select-one-fn :object :model/Revision :model model-name :model_id model-id {:order-by [[:id :desc]]}))-(mu/defn revision-object- "The serialized object of the Revision with `revision-id` of the `model-name` row with `model-id`, or nil."- [model-name :- :string- model-id :- ms/PositiveInt- revision-id :- ms/PositiveInt]- (t2/select-one-fn :object :model/Revision :model model-name :model_id model-id :id revision-id))-(def ^:private revision-object-extra-keys"Extra keys [[metabase.revisions.impl.dashboard/serialize-instance]] and friends add to some models' revision`:object` beyond their own row schema."diff --git a/src/metabase/revisions/impl/card.clj b/src/metabase/revisions/impl/card.cljindex 3a020e49c95..6888c2b9145 100644--- a/src/metabase/revisions/impl/card.clj+++ b/src/metabase/revisions/impl/card.clj@@ -1,7 +1,7 @@(ns metabase.revisions.impl.card(:require[metabase.queries.core :as queries]- [metabase.revisions.db :as revisions.db]+ [metabase.queries.db :as queries.db][metabase.revisions.models.revision :as revision][toucan2.core :as t2]))@@ -42,7 +42,7 @@(not (:card_schema serialized-card)) (assoc :card_schema queries/starting-card-schema-version))restored (apply dissoc serialized-card excluded-columns-for-card-revision)](queries/check-new-parameter-source-card-permissions "card" id (:parameters restored))- (queries/maybe-unverify! (t2/hydrate (revisions.db/card id) [:moderation_reviews :moderator_details])+ (queries/maybe-unverify! (t2/hydrate (queries.db/card id) [:moderation_reviews :moderator_details])restored{:id user-id})((get-method revision/revert-to-revision! :default) model id user-id restored)))diff --git a/src/metabase/revisions/models/revision.clj b/src/metabase/revisions/models/revision.cljindex f064447b2c4..6f18c0c7908 100644--- a/src/metabase/revisions/models/revision.clj+++ b/src/metabase/revisions/models/revision.clj@@ -257,7 +257,10 @@[:entity [:fn toucan-model?]]]](let [{:keys [id user-id revision-id entity]} infomodel-name (name entity)- serialized-instance (revisions.db/revision-object model-name id revision-id)]+ serialized-instance (let [revision (revisions.db/revision revision-id)]+ (when (and (= model-name (:model revision))+ (= id (:model_id revision)))+ (:object revision)))](t2/with-transaction [_conn](let [already-in-target-state? (= serialized-instance(revisions.db/latest-revision-object model-name id))]diff --git a/src/metabase/sample_data/db.clj b/src/metabase/sample_data/db.cljindex 38e0bf5181d..2f00f0ade78 100644--- a/src/metabase/sample_data/db.clj+++ b/src/metabase/sample_data/db.clj@@ -23,11 +23,6 @@[](t2/select-one-pk :model/Database :is_sample true))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database database-id))-(mu/defn set-sample-database-details!"Set the `details` of the sample Database, returning the ids of the updated rows."[details :- ::warehouses.schema/database.details]diff --git a/src/metabase/sample_data/impl.clj b/src/metabase/sample_data/impl.cljindex 05355115997..80f6ffe4b64 100644--- a/src/metabase/sample_data/impl.clj+++ b/src/metabase/sample_data/impl.clj@@ -12,6 +12,7 @@[metabase.util.files :as u.files][metabase.util.i18n :refer [trs]][metabase.util.log :as log]+ [metabase.warehouses.db :as warehouses.db][ring.util.codec :as codec][toucan2.core :as t2])(:import@@ -105,7 +106,7 @@(let [engine (sample-database-engine)details (try-to-extract-sample-database! engine)db (if (sample-data.db/sample-database-exists?)- (sample-data.db/database (first (sample-data.db/set-sample-database-details! details)))+ (warehouses.db/database (first (sample-data.db/set-sample-database-details! details)))(sample-data.db/insert-sample-database! sample-database-name details engine))](log/debug "Syncing Sample Database...")(sync/sync-database! (u/the-id db)))diff --git a/src/metabase/segments/db.clj b/src/metabase/segments/db.cljindex 2df37e708a8..255a28c7570 100644--- a/src/metabase/segments/db.clj+++ b/src/metabase/segments/db.clj@@ -23,10 +23,10 @@:description description:definition definition))-(mu/defn segment- "The Segment with `id`, or nil."+(mu/defn segment :- [:maybe ::segments.schema/segment]+ "The ::segments.schema/segment with `id`, or nil."[id :- ::lib.schema.id/segment]- (t2/select-one :model/Segment :id id))+ (t2/select-one :model/Segment :id [:auto/param id]))(mu/defn unarchived-segments"The unarchived Segments, in case-insensitive name order."@@ -44,21 +44,6 @@changes :- (mut/select-keys ::segments.schema/segment.update [:description :caveats :points_of_interest :archived :definition :name :show_in_getting_started])](t2/update! :model/Segment id changes))-(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))--(mu/defn table-database-id- "The Database id of the Table with `table-id`, or nil."- [table-id :- ::lib.schema.id/table]- (t2/select-one-fn :db_id :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))--(mu/defn table-perms-columns- "The Database id, schema, and id of the Table with `table-id`, or nil."- [table-id :- ::lib.schema.id/table]- (t2/select-one [:model/Table :db_id :schema :id] :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(mu/defn collections"The Collections with `collection-ids`."[collection-ids :- [:sequential ::lib.schema.id/collection]]diff --git a/src/metabase/segments/models/segment.clj b/src/metabase/segments/models/segment.cljindex 29d2b86338d..41843225c15 100644--- a/src/metabase/segments/models/segment.clj+++ b/src/metabase/segments/models/segment.clj@@ -22,6 +22,7 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][methodical.core :as methodical][toucan2.core :as t2][toucan2.tools.hydrate :as t2.hydrate]))@@ -95,7 +96,7 @@(defmethod mi/can-write? :model/Segment([instance](let [table (or (:table instance)- (segments.db/table (:table_id instance)))]+ (warehouse-schema.db/table (:table_id instance)))](and (or (mi/superuser?)(and (api/entitled-data-analyst?)(perms/user-has-permission-for-table?@@ -115,7 +116,7 @@(defmethod mi/can-create? :model/Segment[_model instance](let [table (or (:table instance)- (segments.db/table (:table_id instance)))]+ (warehouse-schema.db/table (:table_id instance)))](and (or (mi/superuser?)(and (api/entitled-data-analyst?)(perms/user-has-permission-for-table?@@ -161,7 +162,7 @@[{:keys [definition], table-id :table_id}](when (some? definition)(let [database-id (when table-id- (segments.db/table-database-id table-id))]+ (:db_id (warehouse-schema.db/table table-id)))](normalize-segment-definition definition table-id database-id))))(t2/define-before-insert :model/Segment@@ -206,7 +207,7 @@(defmethod mi/perms-objects-set :model/Segment[segment read-or-write](let [table (or (:table segment)- (segments.db/table-perms-columns (u/the-id (:table_id segment))))]+ (warehouse-schema.db/table (u/the-id (:table_id segment))))](mi/perms-objects-set table read-or-write)))(defn- maybe-migrated-segment-definitiondiff --git a/src/metabase/segments/schema.clj b/src/metabase/segments/schema.cljindex 1973f128132..a5ae9b9b40f 100644--- a/src/metabase/segments/schema.clj+++ b/src/metabase/segments/schema.clj@@ -29,16 +29,17 @@(nil? (lib/current-limit query))))]]])(mr/def ::segment.definition- "The `:definition` column of a Segment, decoded."+ "The `:definition` a Segment create or update accepts: an MBQL query, possibly legacy, never empty."::lib-be.schema/maybe-legacy-query)(mr/def ::segment- "A Segment as selected from the app DB: every column of `:segment`, plus `:creator` and `:table` some callers- hydrate onto it."+ "A Segment as selected from the app DB: every column of `:segment`, with an unreadable `:definition` read back as an+ empty query, plus `:creator` and `:table` some callers hydrate onto it."[:merge::segment.update[:map {:closed true}[:id ms/PositiveInt]+ [:definition {:optional true} [:maybe ::lib-be.schema/maybe-legacy-or-empty-query]][:creator {:optional true} [:maybe :metabase.users.schema/user]][:table {:optional true} [:maybe :metabase.warehouse-schema.schema/table]]]])diff --git a/src/metabase/session/api.clj b/src/metabase/session/api.cljindex b26b5531289..fc9e7c9e1f4 100644--- a/src/metabase/session/api.clj+++ b/src/metabase/session/api.clj@@ -22,6 +22,7 @@[metabase.settings.core :as setting][metabase.sso.core :as sso][metabase.system.core :as system]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.i18n :refer [deferred-tru tru]][metabase.util.log :as log]@@ -590,7 +591,7 @@(verify-second-factor! user-id code jti)(do(events/publish-event! :event/mfa-verification-failed- {:object (session.db/user user-id)})+ {:object (users.db/user user-id)})(throw (ex-info (tru "Invalid authentication code.") {:status-code 401}))))))user (session.db/user-login-status user-id)];; the account can be deactivated (or deleted) between the password step and here; a@@ -660,7 +661,7 @@(or(confirm-enrollment! user-id code jti)(do (events/publish-event! :event/mfa-required-enrollment-failed- {:object (session.db/user user-id)})+ {:object (users.db/user user-id)})(throw (ex-info (tru "Invalid authentication code.") {:status-code 401}))))))user (session.db/user-login-status user-id)];; the account can be deactivated (or deleted) between the password step and here; andiff --git a/src/metabase/session/db.clj b/src/metabase/session/db.cljindex cb843c04571..ce3f549abb2 100644--- a/src/metabase/session/db.clj+++ b/src/metabase/session/db.clj@@ -127,11 +127,11 @@(t2/query-one hsql))))(mu/defn auth-identity-for-provider- "The AuthIdentity of the User with `user-id` at `provider`, or nil. See `metabase.auth-identity.db/auth-identity`,+ "The AuthIdentity of the User with `user-id` at `provider`, or nil. See `metabase.auth-identity.db/auth-identity-for-user-and-provider`,which owns the AuthIdentity table."[user-id :- ::lib.schema.id/userprovider :- :string]- (auth-identity.db/auth-identity user-id provider))+ (auth-identity.db/auth-identity-for-user-and-provider user-id provider))(mu/defn auth-identity-exists?"Whether the User with `user-id` has an AuthIdentity at `provider`."@@ -145,21 +145,11 @@credentials :- [:maybe ::auth-identity.schema/auth-identity.credentials]](t2/update! :model/AuthIdentity auth-identity-id {:credentials credentials}))-(mu/defn auth-identity-provider- "The `:provider` of the AuthIdentity with `auth-identity-id`, or nil."- [auth-identity-id :- ms/PositiveInt]- (t2/select-one [:model/AuthIdentity :provider] :id auth-identity-id))-(mu/defn user-by-email"The id, SSO source, and active flag of the User whose email matches `email` case-insensitively, or nil."[email :- :string](t2/select-one [:model/User :id :sso_source :is_active] :%lower.email (u/lower-case-en email)))-(mu/defn user- "The User with `user-id`, or nil."- [user-id :- ::lib.schema.id/user]- (t2/select-one :model/User :id user-id))-(mu/defn user-login-status"The id, active flag, last login, and tenant id of the User with `user-id`, or nil."[user-id :- ::lib.schema.id/user]diff --git a/src/metabase/session/models/session.clj b/src/metabase/session/models/session.cljindex b06345ec8d4..994c0883dbb 100644--- a/src/metabase/session/models/session.clj+++ b/src/metabase/session/models/session.clj@@ -6,10 +6,11 @@[buddy.core.nonce :as nonce][clojure.core.memoize :as memo][environ.core :as env]+ [metabase.auth-identity.db :as auth-identity.db][metabase.events.core :as events][metabase.request.core :as request]- [metabase.session.db :as session.db][metabase.session.settings :as session.settings]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.encryption :as encryption][metabase.util.i18n :refer [tru]]@@ -96,7 +97,7 @@(throw (ex-info "Session key should not be stored plaintext in the session table." {})));; Check auth identity provider if provided(when-let [auth-identity-id (:auth_identity_id session)]- (when-let [auth-identity (session.db/auth-identity-provider auth-identity-id)]+ (when-let [auth-identity (auth-identity.db/auth-identity auth-identity-id)](when (and (= "password" (:provider auth-identity))(not (session.settings/enable-password-login)))(throw (ex-info (str (tru "Password login is disabled for this instance."))@@ -112,7 +113,7 @@(t2/define-after-insert :model/Session[session]- (when-let [user (session.db/user (:user_id session))]+ (when-let [user (users.db/user (:user_id session))](let [event {:user-id (u/the-id user)}](events/publish-event! :event/user-login event)(when (nil? (:last_login user))diff --git a/src/metabase/setup_rest/api.clj b/src/metabase/setup_rest/api.cljindex 9977dda34f1..a6d14a05fc9 100644--- a/src/metabase/setup_rest/api.clj+++ b/src/metabase/setup_rest/api.clj@@ -11,6 +11,7 @@[metabase.setup-rest.db :as setup-rest.db][metabase.setup.core :as setup][metabase.system.core :as system]+ [metabase.users.db :as users.db][metabase.util :as u][metabase.util.i18n :as i18n :refer [tru]][metabase.util.malli :as mu]@@ -101,7 +102,7 @@(setting/restore-cache!)(throw e))))](let [{:keys [user-id session-key session]} (create!)- superuser (setup-rest.db/user user-id)]+ superuser (users.db/user user-id)](events/publish-event! :event/user-login {:user-id user-id})(when-not (:last_login superuser)(events/publish-event! :event/user-joined {:user-id user-id}))diff --git a/src/metabase/setup_rest/db.clj b/src/metabase/setup_rest/db.cljindex e249bf3c324..b0937538a20 100644--- a/src/metabase/setup_rest/db.clj+++ b/src/metabase/setup_rest/db.clj@@ -2,7 +2,6 @@"Application database queries for the setup REST module. Every function here is a direct Toucan 2 call with noadditional logic, so the rest of the module never talks to `toucan2.core` itself."(:require- [metabase.lib.schema.id :as lib.schema.id][metabase.util.malli :as mu][toucan2.core :as t2]))@@ -16,8 +15,3 @@:first_name first-name:last_name last-name:is_superuser true))--(mu/defn user- "The User with `user-id`, or nil."- [user-id :- ::lib.schema.id/user]- (t2/select-one :model/User :id user-id))diff --git a/src/metabase/slackbot/db.clj b/src/metabase/slackbot/db.cljindex db584d337b1..85cd66ddfaa 100644--- a/src/metabase/slackbot/db.clj+++ b/src/metabase/slackbot/db.clj@@ -2,7 +2,6 @@"Application database queries for the Slack bot module. Every function here is a direct Toucan 2 call with noadditional logic, so the rest of the module never talks to `toucan2.core` itself."(:require- [metabase.lib.schema.id :as lib.schema.id][metabase.util.malli :as mu][toucan2.core :as t2]))@@ -59,11 +58,6 @@slack-msg-id :- :string](t2/select-one-fn :user_id:model/MetabotMessage- :channel_id channel-id- :slack_msg_id slack-msg-id+ :channel_id [:auto/param channel-id]+ :slack_msg_id [:auto/param slack-msg-id]:role "assistant"))--(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))diff --git a/src/metabase/slackbot/query.clj b/src/metabase/slackbot/query.cljindex d3236ec34fd..f03e6c6eebb 100644--- a/src/metabase/slackbot/query.clj+++ b/src/metabase/slackbot/query.clj@@ -5,10 +5,10 @@[metabase.channel.render.core :as channel.render][metabase.formatter.core :as formatter][metabase.lib.core :as lib]+ [metabase.queries.db :as queries.db][metabase.query-processor.core :as qp][metabase.query-processor.middleware.permissions :as qp.perms][metabase.query-processor.schema :as qp.schema]- [metabase.slackbot.db :as slackbot.db][metabase.util :as u]))(set! *warn-on-reflection* true)@@ -265,7 +265,7 @@- `table` and display types not supported by static viz render as native Slack table blocks- static viz chart types render as PNG"[card-id]- (let [card (slackbot.db/card card-id)+ (let [card (queries.db/card card-id)_ (when-not card(throw (ex-info "Card not found" {:card-id card-id :type :card-not-found})))card-name (:name card)diff --git a/src/metabase/sync/analyze/classify.clj b/src/metabase/sync/analyze/classify.cljindex f0f1415f593..d7e723d88e6 100644--- a/src/metabase/sync/analyze/classify.clj+++ b/src/metabase/sync/analyze/classify.clj@@ -31,7 +31,8 @@[metabase.tracing.core :as tracing][metabase.util :as u][metabase.util.log :as log]- [metabase.util.malli :as mu]))+ [metabase.util.malli :as mu]+ [metabase.warehouse-schema.db :as warehouse-schema.db]));;; +----------------------------------------------------------------------------------------------------------------+;;; | CLASSIFYING INDIVIDUAL FIELDS |@@ -84,7 +85,7 @@(or (:fingerprint field)(when (qp.store/initialized?)(:fingerprint (lib.metadata/field (qp.store/metadata-provider) (u/the-id field))))- (sync.db/field-fingerprint (u/the-id field)))))+ (:fingerprint (warehouse-schema.db/field (u/the-id field))))))([field :- i/FieldInstance{:keys [exists-name]} :- ClassifyOptsdiff --git a/src/metabase/sync/db.clj b/src/metabase/sync/db.cljindex 9225daf11a1..2266de63617 100644--- a/src/metabase/sync/db.clj+++ b/src/metabase/sync/db.clj@@ -30,36 +30,16 @@;;; ------------------------------------------------ Database -------------------------------------------------(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))-(mu/defn database-exists?"Whether a Database with `database-id` exists."[database-id :- ::lib.schema.id/database](t2/exists? :model/Database :id database-id))-(mu/defn database-initial-sync-status- "The `initial_sync_status` of the Database with `database-id`."- [database-id :- ::lib.schema.id/database]- (t2/select-one-fn :initial_sync_status :model/Database :id database-id))--(mu/defn database-sample?- "Whether the Database with `database-id` is the Sample Database."- [database-id :- ::lib.schema.id/database]- (boolean (t2/select-one-fn :is_sample :model/Database :id database-id)))-(mu/defn attached-dwh-database-id"The ID of the attached data warehouse Database, or nil."[](t2/select-one-pk :model/Database :is_attached_dwh true))-(mu/defn database-stub?- "Whether the Database with `database-id` is a stub."- [database-id :- ::lib.schema.id/database]- (t2/select-one-fn :is_stub :model/Database :id database-id))-(mu/defn database-on-demand-flags"A map of Database ID to its `:is_on_demand` flag for `database-ids`."[database-ids :- [:set ::lib.schema.id/database]]@@ -340,11 +320,6 @@:order-by [[:id :asc]]:limit limit}))-(mu/defn field-fingerprint- "The fingerprint of the Field with `field-id`."- [field-id :- ::lib.schema.id/field]- (t2/select-one-fn :fingerprint :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))-(mu/defn active-fields-metadata-for-table"The sync metadata columns of the active Fields of the Table with `table-id`, as sync wrote them, in field order."[table-id :- ::lib.schema.id/table]diff --git a/src/metabase/sync/sync.clj b/src/metabase/sync/sync.cljindex 89368e1b4c5..8fcb8db79f4 100644--- a/src/metabase/sync/sync.clj+++ b/src/metabase/sync/sync.clj@@ -15,7 +15,6 @@[metabase.lib.schema.id :as lib.schema.id][metabase.sync.analyze :as analyze][metabase.sync.analyze.fingerprint :as sync.fingerprint]- [metabase.sync.db :as sync.db][metabase.sync.field-values :as sync.field-values][metabase.sync.interface :as i][metabase.sync.sync-metadata :as sync-metadata]@@ -23,7 +22,8 @@[metabase.tracing.core :as tracing][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]- [metabase.warehouse-schema.models.field :as field])+ [metabase.warehouse-schema.models.field :as field]+ [metabase.warehouses.db :as warehouses.db])(:import(java.time.temporal Temporal)))@@ -84,7 +84,7 @@(let [database (driver.u/lib-database database-id)](tracing/with-span :sync "sync.database" {:db/id database-id}(sync-util/sync-operation :sync database (format "Sync %s" (sync-util/name-for-logging database))- (->> (scan-phases scan (= "complete" (sync.db/database-initial-sync-status database-id)))+ (->> (scan-phases scan (= "complete" (:initial_sync_status (warehouses.db/database database-id))))(keep (partial do-phase! database-id))(doall)))))))diff --git a/src/metabase/sync/sync_metadata/tables.clj b/src/metabase/sync/sync_metadata/tables.cljindex 4506a353809..06e9df2af71 100644--- a/src/metabase/sync/sync_metadata/tables.clj+++ b/src/metabase/sync/sync_metadata/tables.clj@@ -21,7 +21,8 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]- [metabase.warehouse-schema.humanization :as warehouse-schema.humanization])+ [metabase.warehouse-schema.humanization :as warehouse-schema.humanization]+ [metabase.warehouses.db :as warehouses.db])(:import(clojure.lang ITransientSet)))@@ -183,7 +184,7 @@Throws an exception if there is already a table with the same name, schema and database ID."[database :- i/DatabaseInstancetable :- TableMetadata]- (insert-table! database table {:sample? (sync.db/database-sample? (:id database))}))+ (insert-table! database table {:sample? (boolean (:is_sample (warehouses.db/database (:id database))))}))(mu/defn- reactivate-table!"Mark an existing inactive Table active again, refreshing its cruft-dependent columns. `existing`@@ -205,7 +206,7 @@[database :- i/DatabaseInstance{schema :schema table-name :name :as table} :- TableMetadata](if-let [existing (sync.db/inactive-table-by-schema-and-name (u/the-id database) schema table-name)]- (reactivate-table! database existing {:sample? (sync.db/database-sample? (u/the-id database))})+ (reactivate-table! database existing {:sample? (boolean (:is_sample (warehouses.db/database (u/the-id database))))})(create-table! database table)));; TODO - should we make this logic case-insensitive like it is for fields?@@ -535,7 +536,7 @@context (transduce (partition-all table-sync-batch-size)(completing reconcile-batch){:created 0, :updated 0, :complete? true- :sample? (sync.db/database-sample? (:id database))+ :sample? (boolean (:is_sample (warehouses.db/database (:id database)))):seen (transient #{}), :metabase-metadata []}(:tables db-metadata)){:keys [created updated complete?]} context]diff --git a/src/metabase/sync/task/sync_databases.clj b/src/metabase/sync/task/sync_databases.cljindex 1336964db62..043c20a274e 100644--- a/src/metabase/sync/task/sync_databases.clj+++ b/src/metabase/sync/task/sync_databases.clj@@ -27,7 +27,8 @@[metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]- [metabase.warehouses.core :as warehouses])+ [metabase.warehouses.core :as warehouses]+ [metabase.warehouses.db :as warehouses.db])(:import(org.quartzJobDetail)))@@ -71,7 +72,7 @@(defn- sync-and-analyze-database*- (when-let [database (or (sync.db/database database-id)+ (when-let [database (or (warehouses.db/database database-id)(do(sync-databases-trigger/unschedule-tasks-for-db! (mi/instance :model/Database {:id database-id}))(log/warnf "Cannot sync Database %d: Database does not exist." database-id)))]@@ -117,7 +118,7 @@:raw-job-context job-context:job-context (pr-str job-context)}))))- (sync.db/database-stub? database-id)+ (:is_stub (warehouses.db/database database-id))(log/warnf "Skipping scheduled sync for Database %d: it is a stub." database-id):else@@ -138,7 +139,7 @@(log/debugf "Skipping scheduled field-values update for Database %d: disable-auto-sync is on." database-id)(do(log/infof "Update Field values task triggered for Database %d." database-id)- (when-let [database (or (sync.db/database database-id)+ (when-let [database (or (warehouses.db/database database-id)(do(sync-databases-trigger/unschedule-tasks-for-db! (mi/instance :model/Database {:id database-id}))(log/warnf "Cannot update Field values for Database %d: Database does not exist." database-id)))]diff --git a/src/metabase/sync/util.clj b/src/metabase/sync/util.cljindex a61144aeab1..0ac706c9010 100644--- a/src/metabase/sync/util.clj+++ b/src/metabase/sync/util.clj@@ -25,6 +25,7 @@[metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms][metabase.util.memory :as u.mem]+ [metabase.warehouses.db :as warehouses.db][metabase.warehouses.models.database :as database][toucan2.realize :as t2.realize])(:import@@ -471,7 +472,7 @@(defn set-initial-database-sync-complete!"Marks initial sync as complete for this database so that this is reflected in the UI, if not already set"[database]- (when (not= (sync.db/database-initial-sync-status (u/the-id database)) "complete")+ (when (not= (:initial_sync_status (warehouses.db/database (u/the-id database))) "complete")(sync.db/update-database! (u/the-id database) {:initial_sync_status "complete":initial_sync_error nil})))@@ -479,7 +480,7 @@"Marks initial sync as aborted for this database, recording the message of `error` (the Throwable that aborted it)so that the cause can be displayed on the UI"[database error]- (when (not= (sync.db/database-initial-sync-status (u/the-id database)) "complete")+ (when (not= (:initial_sync_status (warehouses.db/database (u/the-id database))) "complete")(sync.db/update-database! (u/the-id database) {:initial_sync_status "aborted":initial_sync_error (ex-message error)})))diff --git a/src/metabase/task_history/db.clj b/src/metabase/task_history/db.cljindex 8f0ce3f8883..5e0854c9304 100644--- a/src/metabase/task_history/db.clj+++ b/src/metabase/task_history/db.clj@@ -104,10 +104,10 @@[filters :- RunFilters](t2/count :model/TaskRun (or (run-where filters) {})))-(mu/defn task-run- "The TaskRun with `id`, or nil."+(mu/defn task-run :- [:maybe ::task-history.schema/task-run]+ "The ::task-history.schema/task-run with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/TaskRun :id id))+ (t2/select-one :model/TaskRun :id [:auto/param id]))(mu/defn tasks-for-run"The TaskHistory rows of the TaskRun with `run-id`, oldest first."diff --git a/src/metabase/tiles/api.clj b/src/metabase/tiles/api.cljindex 5fd5a79f447..5bbdc4fb115 100644--- a/src/metabase/tiles/api.clj+++ b/src/metabase/tiles/api.clj@@ -3,6 +3,7 @@(:require[metabase.api.common :as api][metabase.api.macros :as api.macros]+ [metabase.dashboards.db :as dashboards.db];; TODO (Cam 10/10/25) -- update the tile API to use MBQL 5^{:clj-kondo/ignore [:discouraged-namespace]} [metabase.legacy-mbql.normalize :as mbql.normalize];; tile API field refs are still legacy MBQL; keep the legacy schema until the MBQL 5 port above@@ -13,10 +14,10 @@[metabase.lib.schema.id :as lib.schema.id][metabase.lib.schema.metadata :as lib.schema.metadata][metabase.parameters.schema :as parameters.schema]+ [metabase.queries.db :as queries.db][metabase.query-processor.card :as qp.card][metabase.query-processor.core :as qp][metabase.query-processor.dashboard :as qp.dashboard]- [metabase.tiles.db :as tiles.db][metabase.util :as u][metabase.util.i18n :refer [tru]][metabase.util.json :as json]@@ -305,7 +306,7 @@[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::legacy-ref][:lonField ::legacy-ref]]]- (process-tiles-query-for-card (api/check-404 (tiles.db/card card-id))+ (process-tiles-query-for-card (api/check-404 (queries.db/card card-id))parameters zoom x y lat-field lon-field));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -327,7 +328,7 @@[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::legacy-ref][:lonField ::legacy-ref]]]- (process-tiles-query-for-dashcard (api/check-404 (tiles.db/dashboard dashboard-id))- (api/check-404 (tiles.db/dashcard dashcard-id))- (api/check-404 (tiles.db/card card-id))+ (process-tiles-query-for-dashcard (api/check-404 (dashboards.db/dashboard dashboard-id))+ (api/check-404 (dashboards.db/dashboard-card dashcard-id))+ (api/check-404 (queries.db/card card-id))parameters zoom x y lat-field lon-field))diff --git a/src/metabase/tiles/db.clj b/src/metabase/tiles/db.cljdeleted file mode 100644index 7edb716fab7..00000000000--- a/src/metabase/tiles/db.clj+++ /dev/null@@ -1,22 +0,0 @@-(ns metabase.tiles.db- "Application database queries for the tiles module. Every function here is a direct Toucan 2 call with no- additional logic, so the rest of the module never talks to `toucan2.core` itself."- (:require- [metabase.lib.schema.id :as lib.schema.id]- [metabase.util.malli :as mu]- [toucan2.core :as t2]))--(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card card-id))--(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil."- [dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard dashboard-id))--(mu/defn dashcard- "The DashboardCard with `dashcard-id`, or nil."- [dashcard-id :- ::lib.schema.id/dashcard]- (t2/select-one :model/DashboardCard dashcard-id))diff --git a/src/metabase/timeline/api/timeline.clj b/src/metabase/timeline/api/timeline.cljindex 26b4e594ba6..22544847cf9 100644--- a/src/metabase/timeline/api/timeline.clj+++ b/src/metabase/timeline/api/timeline.clj@@ -4,6 +4,7 @@[metabase.api-scope.data-app :as api-scope][metabase.api.common :as api][metabase.api.macros :as api.macros]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.collections.models.collection.root :as collection.root][metabase.events.core :as events]@@ -161,6 +162,6 @@{:keys [include archived]} :- [:map {:closed true}[:include {:optional true} [:maybe [:= "events"]]][:archived {:default false} [:maybe :boolean]]]]- (api/read-check (timeline.db/collection id))+ (api/read-check (collections.db/collection id))(timeline/timelines-for-collection id {:timeline/events? (= include "events"):timeline/archived? archived}))diff --git a/src/metabase/timeline/api/timeline_event.clj b/src/metabase/timeline/api/timeline_event.cljindex 784222cffa4..e6d6846a4d6 100644--- a/src/metabase/timeline/api/timeline_event.clj+++ b/src/metabase/timeline/api/timeline_event.clj@@ -47,7 +47,7 @@{:creator_id api/*current-user-id*:timestamp parsed}(when-not icon- {:icon (timeline.db/timeline-icon timeline_id)}))]+ {:icon (:icon (timeline.db/timeline timeline_id))}))](analytics/track-event! :snowplow/timeline(cond-> {:event :new-event-created:time_matters time_mattersdiff --git a/src/metabase/timeline/db.clj b/src/metabase/timeline/db.cljindex d82b30514c9..1ade02d6d6a 100644--- a/src/metabase/timeline/db.clj+++ b/src/metabase/timeline/db.clj@@ -26,15 +26,10 @@(collection/visible-collection-filter-clause)]:order-by [[:%lower.name :asc]]}))-(mu/defn timeline- "The Timeline with `id`, or nil."+(mu/defn timeline :- [:maybe ::timeline.schema/timeline]+ "The ::timeline.schema/timeline with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Timeline :id id))--(mu/defn timeline-icon- "The icon of the Timeline with `id`, or nil."- [id :- ms/PositiveInt]- (t2/select-one-fn :icon :model/Timeline :id id))+ (t2/select-one :model/Timeline :id [:auto/param id]))(mu/defn timelines-by-id"A map of id to Timeline for the Timelines with `ids`."@@ -64,20 +59,15 @@[id :- ms/PositiveInt](t2/delete! :model/Timeline :id id))-(mu/defn collection- "The Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one :model/Collection :id collection-id))-(mu/defn insert-timeline-event!"Insert the TimelineEvent `row` and return the inserted instance."[row :- (mut/select-keys ::timeline.schema/timeline-event.update [:name :timestamp :timezone :timeline_id :creator_id :description :time_matters :icon :archived])](t2/insert-returning-instance! :model/TimelineEvent row))-(mu/defn timeline-event- "The TimelineEvent with `id`, or nil."+(mu/defn timeline-event :- [:maybe ::timeline.schema/timeline-event]+ "The ::timeline.schema/timeline-event with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/TimelineEvent :id id))+ (t2/select-one :model/TimelineEvent :id [:auto/param id]))(mu/defn timeline-events-for-timelines"The TimelineEvents of the Timelines with `timeline-ids`, unarchived only unless `all?`, and (when `start` and/ordiff --git a/src/metabase/transforms/canceling.clj b/src/metabase/transforms/canceling.cljindex 356e7a8a29b..05267a7c3e7 100644--- a/src/metabase/transforms/canceling.clj+++ b/src/metabase/transforms/canceling.clj@@ -202,7 +202,7 @@(try;; Skip silently if the run was deleted between cancelation insert and now;; — `chan-signal-cancel!` would be a no-op anyway in that case.- (when-let [run (transforms.db/run id)]+ (when-let [run (transforms.db/transform-run id)](cancel-run! run request-time))(catch Throwable t(log/error (str "Error canceling " id ": " (ex-message t)))))))diff --git a/src/metabase/transforms/crud.clj b/src/metabase/transforms/crud.cljindex b0602578aab..53eea743f79 100644--- a/src/metabase/transforms/crud.clj+++ b/src/metabase/transforms/crud.clj@@ -21,6 +21,8 @@[metabase.util :as u][metabase.util.i18n :refer [deferred-tru]][metabase.util.log :as log]+ [metabase.warehouse-schema.db :as warehouse-schema.db]+ [metabase.warehouses.db :as warehouses.db][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -28,7 +30,7 @@(defn check-database-feature"Check that the target database supports the required features for this transform."[transform]- (let [database (api/check-400 (transforms.db/database (transforms-base.i/target-db-id transform))+ (let [database (api/check-400 (warehouses.db/database (transforms-base.i/target-db-id transform))(deferred-tru "The target database cannot be found."))features (transforms-base.u/required-database-features transform)](api/check-400 (not (:is_sample database))@@ -61,7 +63,7 @@and leaves the Metabase table with zero fields."[transform](let [db-id (transforms-base.i/target-db-id transform)- db (transforms.db/database db-id)]+ db (warehouses.db/database db-id)](when (and db (driver.u/supports? (:engine db) :schemas db))(api/check-400 (not (str/blank? (get-in transform [:target :schema])))(deferred-tru "A target schema is required for this database.")))))@@ -79,7 +81,7 @@[{:keys [source] :as transform}](when (transforms-base.u/checkpoint-source? transform)(let [checkpoint-filter-field-id (get-in source [:source-incremental-strategy :checkpoint-filter-field-id])- field (transforms.db/field checkpoint-filter-field-id)]+ field (warehouse-schema.db/field checkpoint-filter-field-id)](api/check-400 field (deferred-tru "Checkpoint field not found."))(let [column (field->column field)](api/check-400 (transforms-base.u/supported-checkpoint-column? column)@@ -93,7 +95,7 @@[{:keys [source] :as transform}](let [{:keys [lookback checkpoint-filter-field-id]} (:source-incremental-strategy source)](when-let [{:keys [unit]} (and (transforms-base.u/checkpoint-source? transform) lookback)]- (when-let [field (transforms.db/field checkpoint-filter-field-id)]+ (when-let [field (warehouse-schema.db/field checkpoint-filter-field-id)](let [column (field->column field)](api/check-400 (lib.types.isa/date-or-datetime? column)(deferred-tru "A lookback window is only supported for date or datetime checkpoint columns."))diff --git a/src/metabase/transforms/db.clj b/src/metabase/transforms/db.cljindex 7f8192856f0..b0d27edbf0a 100644--- a/src/metabase/transforms/db.clj+++ b/src/metabase/transforms/db.clj@@ -14,6 +14,16 @@[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))+(mu/defn transform-job-run :- [:maybe ::transforms.schema/transform-job-run]+ "The ::transforms.schema/transform-job-run with `transform-job-run-id`, or nil."+ [transform-job-run-id :- ms/PositiveInt]+ (t2/select-one :model/TransformJobRun :id [:auto/param transform-job-run-id]))++(mu/defn transform-dag-run :- [:maybe ::transforms.schema/transform-dag-run]+ "The ::transforms.schema/transform-dag-run with `transform-dag-run-id`, or nil."+ [transform-dag-run-id :- ms/PositiveInt]+ (t2/select-one :model/TransformDagRun :id [:auto/param transform-dag-run-id]))+(def ^:private no-active-run-clause"Honey SQL clause matching TransformRunCancelation rows whose run is no longer active."[:not [:exists ^:allow-subquery@@ -25,10 +35,10 @@;;; ------------------------------------------------ Transform -------------------------------------------------(mu/defn transform- "The Transform with `transform-id`, or nil."+(mu/defn transform :- [:maybe ::transforms.schema/transform]+ "The ::transforms.schema/transform with `transform-id`, or nil."[transform-id :- ::lib.schema.id/transform]- (t2/select-one :model/Transform :id transform-id))+ (t2/select-one :model/Transform :id [:auto/param transform-id]))(mu/defn transforms"The Transforms with `transform-ids`."@@ -49,11 +59,6 @@[](t2/select [:model/Transform :id :target :target_table_id :created_at :table_dependencies]))-(mu/defn transform-snapshot- "The name, entity ID, and source type of the Transform with `transform-id`."- [transform-id :- ::lib.schema.id/transform]- (t2/select-one [:model/Transform :name :entity_id :source_type] :id transform-id))-(mu/defn transform-summaries-by-id"A map of ID to the ID, name, and Collection ID of the Transforms with `transform-ids`."[transform-ids :- [:set ::lib.schema.id/transform]]@@ -64,16 +69,6 @@[transform-ids :- [:sequential ::lib.schema.id/transform]](t2/select-pk->fn :name :model/Transform :id [:in transform-ids]))-(mu/defn transform-last-checkpoint-value- "The last checkpoint value of the Transform with `transform-id`."- [transform-id :- ::lib.schema.id/transform]- (t2/select-one-fn :last_checkpoint_value [:model/Transform :last_checkpoint_value] transform-id))--(mu/defn transform-collection-id- "The Collection ID of the Transform with `transform-id`."- [transform-id :- ::lib.schema.id/transform]- (t2/select-one-fn :collection_id :model/Transform :id transform-id))-(mu/defn insert-transform!"Insert `transform` and return the new instance."[transform :- ::transforms.schema/transform.update]@@ -92,10 +87,10 @@;;; ---------------------------------------------- Transform tags -----------------------------------------------(mu/defn tag- "The TransformTag with `tag-id`, or nil."+(mu/defn transform-tag :- [:maybe ::transforms.schema/transform-tag]+ "The ::transforms.schema/transform-tag with `tag-id`, or nil."[tag-id :- ms/PositiveInt]- (t2/select-one :model/TransformTag :id tag-id))+ (t2/select-one :model/TransformTag :id [:auto/param tag-id]))(mu/defn existing-tag-ids"The subset of `tag-ids` that exist."@@ -174,10 +169,10 @@;;; ---------------------------------------------- Transform jobs -----------------------------------------------(mu/defn job- "The TransformJob with `job-id`, or nil."+(mu/defn transform-job :- [:maybe ::transforms.schema/transform-job]+ "The ::transforms.schema/transform-job with `job-id`, or nil."[job-id :- ms/PositiveInt]- (t2/select-one :model/TransformJob :id job-id))+ (t2/select-one :model/TransformJob :id [:auto/param job-id]))(mu/defn active-jobs"The active TransformJobs."@@ -189,11 +184,6 @@[](t2/select-pks-set :model/TransformJob :active false))-(mu/defn job-snapshot- "The name, entity ID, and built-in type of the TransformJob with `job-id`."- [job-id :- ms/PositiveInt]- (t2/select-one [:model/TransformJob :name :entity_id :built_in_type] :id job-id))-(mu/defn job-names-by-id"A map of ID to name for the TransformJobs with `job-ids`."[job-ids :- [:sequential ms/PositiveInt]]@@ -240,10 +230,10 @@;;; ---------------------------------------------- Transform runs -----------------------------------------------(mu/defn run- "The TransformRun with `run-id`, or nil."+(mu/defn transform-run :- [:maybe ::transforms.schema/transform-run]+ "The ::transforms.schema/transform-run with `run-id`, or nil."[run-id :- ms/PositiveInt]- (t2/select-one :model/TransformRun :id run-id))+ (t2/select-one :model/TransformRun :id [:auto/param run-id]))(mu/defn runs"The TransformRuns with `run-ids`."@@ -822,16 +812,6 @@;;; ----------------------------------------------- Other models ------------------------------------------------(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database database-id))--(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn databases"The Databases with `database-ids`."[database-ids :- [:set ::lib.schema.id/database]]@@ -852,11 +832,6 @@[transform-ids :- [:set ::lib.schema.id/transform]](t2/select :model/TableIndex :transform_id [:in transform-ids] {:order-by [[:index_name :asc]]}))-(mu/defn field- "The Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query)]}))-(mu/defn field-exists?"Whether a Field with `field-id` exists."[field-id :- ::lib.schema.id/field]diff --git a/src/metabase/transforms/jobs.clj b/src/metabase/transforms/jobs.cljindex fc8362ed3cb..da016df4e8c 100644--- a/src/metabase/transforms/jobs.clj+++ b/src/metabase/transforms/jobs.clj@@ -528,7 +528,7 @@;; We hope that this will be the most recent user.;; Only root-cause failures are reported individually; dependents that never ran because an;; upstream transform failed are summarized as a count to avoid a cascade of redundant errors.- (let [job (transforms.db/job job-id)+ (let [job (transforms.db/transform-job job-id)[roots cascades] (split-cascade-failures failures)roots (map (fn [failure](let [transform (::transform failure)]diff --git a/src/metabase/transforms/models/dag_run.clj b/src/metabase/transforms/models/dag_run.cljindex f63ef82c60b..49902464ac9 100644--- a/src/metabase/transforms/models/dag_run.clj+++ b/src/metabase/transforms/models/dag_run.clj@@ -38,7 +38,7 @@Snapshots the seed transform's name and entity_id so the run stays displayable after thetransform is deleted (its FK is SET NULL, as for `transform_run.transform_id`)."[source-transform-id direction user-id transform-count]- (let [transform (transforms.db/transform-snapshot source-transform-id)]+ (let [transform (transforms.db/transform source-transform-id)](transforms.db/insert-dag-run! {:source_transform_id source-transform-id:source_transform_name (:name transform):source_transform_entity_id (:entity_id transform)diff --git a/src/metabase/transforms/models/job_run.clj b/src/metabase/transforms/models/job_run.cljindex 4883596de59..d3b14698a10 100644--- a/src/metabase/transforms/models/job_run.clj+++ b/src/metabase/transforms/models/job_run.clj@@ -40,9 +40,7 @@"Start a run. Snapshots the job's name and entity_id so the run stays displayable after the jobis deleted (`transform_job_run.job_id` has no FK; job runs outlive their job)."([job-id run-method]- ;; :built_in_type so the after-select hook localizes built-in job names; str realizes the- ;; LocalizedString into the snapshot- (let [job (transforms.db/job-snapshot job-id)]+ (let [job (transforms.db/transform-job job-id)](transforms.db/insert-job-run! {:job_id job-id:job_name (some-> (:name job) str):job_entity_id (:entity_id job)diff --git a/src/metabase/transforms/models/transform.clj b/src/metabase/transforms/models/transform.cljindex 68db91dd0f1..6330d6389c7 100644--- a/src/metabase/transforms/models/transform.clj+++ b/src/metabase/transforms/models/transform.clj@@ -294,7 +294,7 @@(assoc transform :last_checkpoint_value checkpoint_hi_value);; latest transform value wins, could be reset(assoc transform :last_checkpoint_value- (transforms.db/transform-last-checkpoint-value transform-id)))+ (:last_checkpoint_value (transforms.db/transform transform-id))))transform))))))(methodical/defmethod t2/batched-hydrate [:model/Transform :transform_tag_ids]@@ -541,7 +541,7 @@(defmethod serdes/required "Transform"[_model id]- (when-let [collection-id (transforms.db/transform-collection-id id)]+ (when-let [collection-id (:collection_id (transforms.db/transform id))]{["Collection" collection-id] {"Transform" id}}))(defn- maybe-extract-transform-query-textdiff --git a/src/metabase/transforms/models/transform_job.clj b/src/metabase/transforms/models/transform_job.cljindex 50ec32f59b6..55f2f7d78aa 100644--- a/src/metabase/transforms/models/transform_job.clj+++ b/src/metabase/transforms/models/transform_job.clj@@ -43,7 +43,7 @@(every? mi/can-write? transforms)true)))))([_model pk]- (when-let [job (transforms.db/job pk)]+ (when-let [job (transforms.db/transform-job pk)](mi/can-write? job))))(defmethod mi/can-create? :model/TransformJob@@ -98,7 +98,7 @@[job-id](cluster-lock/with-cluster-lock (active-flip-lock-name job-id)(when (pos? (transforms.db/activate-job! job-id))- (transforms.schedule/initialize-job! (transforms.db/job job-id)))))+ (transforms.schedule/initialize-job! (transforms.db/transform-job job-id)))))(defn deactivate-job!"Deactivate a transform job: set `:active` to false and remove its Quartz trigger so crondiff --git a/src/metabase/transforms/models/transform_run.clj b/src/metabase/transforms/models/transform_run.cljindex 5ae42270ed4..f2526217f7f 100644--- a/src/metabase/transforms/models/transform_run.clj+++ b/src/metabase/transforms/models/transform_run.clj@@ -46,7 +46,7 @@(boolean (when-let [transform-id (:transform_id instance)](mi/can-read? :model/Transform transform-id)))))([_model pk]- (when-let [run (transforms.db/run pk)]+ (when-let [run (transforms.db/transform-run pk)](mi/can-read? run))))(mi/define-simple-hydration-method add-transform-runs@@ -69,7 +69,7 @@([transform-id](start-run! transform-id {}))([transform-id properties]- (let [transform (transforms.db/transform-snapshot transform-id)+ (let [transform (transforms.db/transform transform-id)metered-as (premium-features/transform-metered-as (:source_type transform))run (transforms.db/insert-run! (assoc properties:transform_id transform-id@@ -139,7 +139,7 @@(cancel/delete-cancelation! run-id)(when (pos? <>)(analytics/inc! :metabase-transforms/timeouts-total {:type "transform"})- (when-let [run (transforms.db/run run-id)]+ (when-let [run (transforms.db/transform-run run-id)](publish-timeout-event! run))))))(defn- reap-transform-runs!diff --git a/src/metabase/transforms/models/transform_tag.clj b/src/metabase/transforms/models/transform_tag.cljindex b69da3737f4..506d73086fa 100644--- a/src/metabase/transforms/models/transform_tag.clj+++ b/src/metabase/transforms/models/transform_tag.clj@@ -31,7 +31,7 @@(let [transforms (transform/transforms-with-tags [(:id instance)])](every? mi/can-write? transforms)))))([_model pk]- (when-let [tag (transforms.db/tag pk)]+ (when-let [tag (transforms.db/transform-tag pk)](mi/can-write? tag))))(defmethod mi/can-create? :model/TransformTagdiff --git a/src/metabase/transforms/schema.clj b/src/metabase/transforms/schema.cljindex da22d706c1c..dffb6a88afc 100644--- a/src/metabase/transforms/schema.clj+++ b/src/metabase/transforms/schema.clj@@ -81,7 +81,8 @@[:database {:optional true} [:maybe :int]][:type [:= "table"]][:schema {:optional true} [:maybe ms/NonBlankString]]- [:name :string]])+ [:name :string]+ [:target-incremental-strategy {:optional true} [:maybe ::target-incremental-strategy]]])(mr/def ::table-incremental-target[:map {:closed true}diff --git a/src/metabase/transforms/util.clj b/src/metabase/transforms/util.cljindex e6436e95be3..14d9aeb87c9 100644--- a/src/metabase/transforms/util.clj+++ b/src/metabase/transforms/util.clj@@ -27,7 +27,9 @@[metabase.transforms.models.transform-run :as transform-run][metabase.transforms.settings :as transforms.settings][metabase.util :as u]- [metabase.util.log :as log])+ [metabase.util.log :as log]+ [metabase.warehouse-schema.db :as warehouse-schema.db]+ [metabase.warehouses.db :as warehouses.db])(:import(java.sql SQLException)))@@ -74,8 +76,8 @@(if models-cache(get-in models-cache [model id])(case model- :model/Database (transforms.db/database id)- :model/Table (transforms.db/table id))))+ :model/Database (warehouses.db/database id)+ :model/Table (warehouse-schema.db/table id))))source (:source transform)](case (keyword (:type source)):querydiff --git a/src/metabase/transforms_base/db.clj b/src/metabase/transforms_base/db.cljindex 3497b1dc174..a349bf85a0f 100644--- a/src/metabase/transforms_base/db.clj+++ b/src/metabase/transforms_base/db.clj@@ -23,7 +23,7 @@(mu/defn transform"The Transform with `transform-id`, or nil."[transform-id :- ::lib.schema.id/transform]- (t2/select-one :model/Transform transform-id))+ (t2/select-one :model/Transform :id [:auto/param transform-id]))(mu/defn update-transform!"Apply `changes` to the Transform with `transform-id`."@@ -47,11 +47,6 @@[database-id :- ::lib.schema.id/database](t2/exists? :model/Database :id database-id))-(mu/defn field-table-id- "The Table id of the Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one-fn :table_id :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))-(mu/defn target-table"The Table named `table-name` in `schema` of the Database with `database-id` also matching the key-value`conditions`, or nil."@@ -61,11 +56,6 @@& conditions :- [:* [:or :keyword :string :int :boolean]]](apply t2/select-one :model/Table :db_id database-id :schema schema :name table-name conditions))-(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn table-for-transform"The Table owned by the Transform with `transform-id`, or nil. `transform-id` is nil for a transformthat hasn't been saved yet, in which case there is no owned Table either."diff --git a/src/metabase/transforms_base/util.clj b/src/metabase/transforms_base/util.cljindex f1d447563fc..7bd1e439f11 100644--- a/src/metabase/transforms_base/util.clj+++ b/src/metabase/transforms_base/util.clj@@ -38,6 +38,7 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]+ [metabase.warehouse-schema.db :as warehouse-schema.db][toucan2.core :as t2])(:import(java.time Instant LocalDate LocalDateTime LocalTime OffsetDateTime OffsetTime ZonedDateTime)@@ -160,7 +161,7 @@after the transform was made incremental."[{:keys [source]}](let [field-id (get-in source [:source-incremental-strategy :checkpoint-filter-field-id])- table-id (when field-id (transforms-base.db/field-table-id field-id))]+ table-id (when field-id (:table_id (warehouse-schema.db/field field-id)))](table-template-tag-name (:query source) table-id)));;; ------------------------------------------------- Transform Normalization -------------------------------------------------@@ -537,7 +538,7 @@(let [table (if (nil? (:schema table))(if-let [actual-schema (resolve-nil-schema (:engine database) database table)](do (transforms-base.db/update-table! (:id table) {:schema actual-schema})- (-> (transforms-base.db/table (:id table))+ (-> (warehouse-schema.db/table (:id table))(t2/hydrate :db)))table)table)]diff --git a/src/metabase/transforms_rest/api/transform_dag_run.clj b/src/metabase/transforms_rest/api/transform_dag_run.cljindex 70c03bc8b4f..14c9869ee2f 100644--- a/src/metabase/transforms_rest/api/transform_dag_run.clj+++ b/src/metabase/transforms_rest/api/transform_dag_run.clj@@ -8,8 +8,8 @@[metabase.api.routes.common :refer [+auth]][metabase.transforms-base.util :as transforms-base.u][metabase.transforms-rest.api.util :as transforms-rest.api.u]- [metabase.transforms-rest.db :as transforms-rest.db][metabase.transforms.core :as transforms.core]+ [metabase.transforms.db :as transforms.db][metabase.util.malli.schema :as ms][toucan2.core :as t2]))@@ -31,7 +31,7 @@(api.macros/defendpoint :get "/:run-id/transform-runs" :- [:sequential transforms-rest.api.u/MemberTransformRunResponse]"Get the transform runs that made up a specific DAG run."[{:keys [run-id]} :- [:map {:closed true} [:run-id ms/PositiveInt]]]- (let [dag-run (api/check-404 (transforms-rest.db/dag-run run-id))]+ (let [dag-run (api/check-404 (transforms.db/transform-dag-run run-id))](check-seed-transform api/read-check dag-run)(->> (t2/hydrate (transforms.core/transform-runs-for-dag-run run-id)[:transform :collection :transform_tag_ids])@@ -40,7 +40,7 @@(api.macros/defendpoint :post "/:run-id/cancel" :- :nil"Cancel an in-progress manual DAG run and request cancellation of its still-running transforms."[{:keys [run-id]} :- [:map {:closed true} [:run-id ms/PositiveInt]]]- (let [dag-run (api/check-404 (transforms-rest.db/dag-run run-id))]+ (let [dag-run (api/check-404 (transforms.db/transform-dag-run run-id))](check-seed-transform api/write-check dag-run)(api/check-400 (transforms.core/cancel-dag-run! run-id))nil))diff --git a/src/metabase/transforms_rest/api/transform_job.clj b/src/metabase/transforms_rest/api/transform_job.cljindex a547d96d3e5..c6290ede316 100644--- a/src/metabase/transforms_rest/api/transform_job.clj+++ b/src/metabase/transforms_rest/api/transform_job.clj@@ -10,6 +10,7 @@[metabase.transforms-rest.api.util :as transforms-rest.api.u][metabase.transforms-rest.db :as transforms-rest.db][metabase.transforms.core :as transforms.core]+ [metabase.transforms.db :as transforms.db][metabase.transforms.util :as transforms.u][metabase.util.i18n :refer [deferred-tru LocalizedString]][metabase.util.log :as log]@@ -170,7 +171,7 @@[:active {:optional true} :boolean][:tag_ids {:optional true} [:sequential ms/PositiveInt]]]](log/info "Updating transform job" job-id)- (let [existing-job (t2/hydrate (transforms-rest.db/job job-id) :tag_ids)]+ (let [existing-job (t2/hydrate (transforms.db/transform-job job-id) :tag_ids)];; Check write permission on both current state and final state (with new tags if provided)(api/write-check existing-job)(when (some? tag-ids)@@ -205,7 +206,7 @@;; activate-job! only runs when :active toggled false→true.(when (and schedule was-active will-be-active)(transforms.core/update-job! job-id schedule))- (-> (transforms-rest.db/job job-id)+ (-> (transforms.db/transform-job job-id)(t2/hydrate :tag_ids :last_run)(update :last_run transforms-base.u/present-run)))))@@ -213,7 +214,7 @@"Delete a transform job."[{:keys [job-id]} :- [:map {:closed true} [:job-id ms/PositiveInt]]](log/info "Deleting transform job" job-id)- (api/write-check (t2/hydrate (transforms-rest.db/job job-id) :tag_ids))+ (api/write-check (t2/hydrate (transforms.db/transform-job job-id) :tag_ids))(transforms-rest.db/delete-job! job-id)(transforms.core/delete-job! job-id)api/generic-204-no-content)@@ -231,7 +232,7 @@{:keys [run_all]} :- [:map {:closed true}[:run_all {:default false} :boolean]]](log/info "Manual run of transform job" job-id)- (api/write-check (transforms-rest.db/job job-id))+ (api/write-check (transforms.db/transform-job job-id))(transforms-rest.api.u/async-run-response(deferred-tru "Job run started"):job_run_id@@ -246,7 +247,7 @@[{:keys [job-id]} :- [:map {:closed true}[:job-id ms/PositiveInt]]](log/info "Getting transform job" job-id)- (-> (api/read-check (transforms-rest.db/job job-id))+ (-> (api/read-check (transforms.db/transform-job job-id))(t2/hydrate :tag_ids :last_run)(update :last_run transforms-base.u/present-run)))@@ -324,6 +325,13 @@:limit (request/limit)))(update :data #(map transforms-base.u/present-run %))))+(defn- job-run+ "The TransformJobRun with `run-id` belonging to the TransformJob with `job-id`, or nil."+ [run-id job-id]+ (let [run (transforms.db/transform-job-run run-id)]+ (when (= (:job_id run) job-id)+ run)))+(api.macros/defendpoint :get "/:job-id/runs/:run-id/transform-runs" :- [:sequential transforms-rest.api.u/MemberTransformRunResponse]"Get the transform runs that made up a specific job run."[{:keys [job-id run-id]} :- [:map {:closed true}@@ -331,7 +339,7 @@[:run-id ms/PositiveInt]]_query-params](api/read-check :model/TransformJob job-id)- (api/check-404 (transforms-rest.db/job-run run-id job-id))+ (api/check-404 (job-run run-id job-id))(let [runs (transforms.core/transform-runs-for-job-run run-id)](->> (t2/hydrate runs [:transform :collection :transform_tag_ids])(map transforms-base.u/present-run))))@@ -342,7 +350,7 @@[:job-id ms/PositiveInt][:run-id ms/PositiveInt]]](api/write-check :model/TransformJob job-id)- (api/check-404 (transforms-rest.db/job-run run-id job-id))+ (api/check-404 (job-run run-id job-id))(api/check-400 (transforms.core/cancel-job-run! run-id))nil)diff --git a/src/metabase/transforms_rest/api/transform_tag.clj b/src/metabase/transforms_rest/api/transform_tag.cljindex defeaf68f9d..c29bd69f5b4 100644--- a/src/metabase/transforms_rest/api/transform_tag.clj+++ b/src/metabase/transforms_rest/api/transform_tag.clj@@ -6,6 +6,7 @@[metabase.models.interface :as mi][metabase.transforms-rest.db :as transforms-rest.db][metabase.transforms.core :as transforms.core]+ [metabase.transforms.db :as transforms.db][metabase.util.i18n :refer [deferred-tru LocalizedString]][metabase.util.log :as log][metabase.util.malli.schema :as ms]@@ -43,18 +44,18 @@{:keys [name]} :- [:map {:closed true}[:name ms/NonBlankString]]](log/info "Updating transform tag" tag-id)- (api/write-check (transforms-rest.db/tag tag-id))+ (api/write-check (transforms.db/transform-tag tag-id))(api/check-400 (not (transforms.core/tag-name-exists-excluding? name tag-id))(deferred-tru "A tag with the name ''{0}'' already exists." name))(transforms-rest.db/update-tag! tag-id name)- (transforms-rest.db/tag tag-id))+ (transforms.db/transform-tag tag-id))(api.macros/defendpoint :delete "/:tag-id" :- :nil"Delete a transform tag. Removes it from all transforms and jobs."[{:keys [tag-id]} :- [:map {:closed true}[:tag-id ms/PositiveInt]]](log/info "Deleting transform tag" tag-id)- (api/write-check (transforms-rest.db/tag tag-id))+ (api/write-check (transforms.db/transform-tag tag-id))(transforms-rest.db/delete-tag! tag-id)nil)diff --git a/src/metabase/transforms_rest/db.clj b/src/metabase/transforms_rest/db.cljindex be51fbb47f1..b3ee99afa5d 100644--- a/src/metabase/transforms_rest/db.clj+++ b/src/metabase/transforms_rest/db.clj@@ -28,11 +28,6 @@[tag-ids :- [:sequential ms/PositiveInt]](set (t2/select-pks-vec :model/TransformTag :id [:in tag-ids])))-(mu/defn tag- "The TransformTag with `tag-id`, or nil."- [tag-id :- ms/PositiveInt]- (t2/select-one :model/TransformTag :id tag-id))-(mu/defn insert-tag!"Insert a TransformTag named `name` and return the inserted instance."[name :- :string]@@ -72,11 +67,6 @@[active :- :boolean](t2/select :model/TransformJob :active active))-(mu/defn job- "The TransformJob with `job-id`, or nil."- [job-id :- ms/PositiveInt]- (t2/select-one :model/TransformJob :id job-id))-(mu/defn job-pk"The primary key of the TransformJob with `job-id`, or nil."[job-id :- ms/PositiveInt]@@ -97,16 +87,3 @@"Every TransformJob, newest first."[](t2/select :model/TransformJob {:order-by [[:created_at :desc]]}))--(mu/defn job-run- "The TransformJobRun with `run-id` belonging to the TransformJob with `job-id`, or nil."- [run-id :- ms/PositiveInt- job-id :- ms/PositiveInt]- (t2/select-one :model/TransformJobRun :id run-id :job_id job-id))--;;; -------------------------------------------------- DAG runs -------------------------------------------------------(mu/defn dag-run- "The TransformDagRun with `run-id`, or nil."- [run-id :- ms/PositiveInt]- (t2/select-one :model/TransformDagRun :id run-id))diff --git a/src/metabase/upload/db.clj b/src/metabase/upload/db.cljindex 87070d268b9..7402fe1be40 100644--- a/src/metabase/upload/db.clj+++ b/src/metabase/upload/db.clj@@ -17,16 +17,6 @@[](t2/select-one :model/Database :uploads_enabled true))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))--(mu/defn database-is-attached-dwh?- "Whether the Database with `database-id` is an attached data warehouse."- [database-id :- ::lib.schema.id/database]- (t2/select-one-fn :is_attached_dwh :model/Database database-id))-(mu/defn disable-uploads-for-all-databases!"Disable uploads on every Database that has them enabled."[]@@ -120,11 +110,6 @@[table-id :- ::lib.schema.id/table](t2/update-returning-pks! :model/Card {:table_id table-id :archived false} {:archived true}))-(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn tables"The Tables with `table-ids`."[table-ids :- [:set ::lib.schema.id/table]]diff --git a/src/metabase/upload/impl.clj b/src/metabase/upload/impl.cljindex 445985a4344..549b2ae0f06 100644--- a/src/metabase/upload/impl.clj+++ b/src/metabase/upload/impl.clj@@ -33,8 +33,10 @@[metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.humanization :as warehouse-schema.humanization][metabase.warehouse-schema.models.table :as table]+ [metabase.warehouses.db :as warehouses.db][toucan2.core :as t2])(:import(com.ibm.icu.text Transliterator)@@ -632,7 +634,7 @@[:db-id ms/PositiveInt][:schema-name {:optional true} [:maybe :string]][:table-prefix {:optional true} [:maybe :string]]]]- (let [database (or (upload.db/database db-id)+ (let [database (or (warehouses.db/database db-id)(throw (ex-info (tru "The uploads database does not exist."){:status-code 422})))](check-can-create-upload database schema-name)@@ -988,7 +990,7 @@[:filename :string][:file (ms/InstanceOfClass File)][:action update-action-schema]]]- (let [table (api/check-404 (upload.db/table table-id))+ (let [table (api/check-404 (warehouse-schema.db/table table-id))database (table/database table)replace? (= :metabase.upload/replace action)](check-can-update database table)diff --git a/src/metabase/upload/settings.clj b/src/metabase/upload/settings.cljindex fb6c84e04d1..07e3d9d09df 100644--- a/src/metabase/upload/settings.clj+++ b/src/metabase/upload/settings.clj@@ -5,7 +5,8 @@[metabase.settings.core :refer [defsetting]][metabase.upload.db :as upload.db][metabase.util.i18n :refer [deferred-tru]]- [metabase.util.log :as log]))+ [metabase.util.log :as log]+ [metabase.warehouses.db :as warehouses.db]))(defn- not-handling-api-request?[]@@ -16,7 +17,7 @@[db-id](or (not-handling-api-request?)(mi/can-write? :model/Database db-id)- (upload.db/database-is-attached-dwh? db-id)+ (:is_attached_dwh (warehouses.db/database db-id))(api/throw-403)))(defsetting uploads-settingsdiff --git a/src/metabase/users/db.clj b/src/metabase/users/db.cljindex a3afa960b0c..b6ae753fb85 100644--- a/src/metabase/users/db.clj+++ b/src/metabase/users/db.clj@@ -14,6 +14,11 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))+(mu/defn user :- [:maybe ::users.schema/user]+ "The ::users.schema/user with `user-id`, or nil."+ [user-id :- ::lib.schema.id/user]+ (t2/select-one :model/User :id [:auto/param user-id]))+(defn- status-clause"Figure out what `where` clause to add to the user query when we get a fiddly status and include_deactivatedquery.diff --git a/src/metabase/users_rest/api.clj b/src/metabase/users_rest/api.cljindex 25241dae0c1..c7100bc0941 100644--- a/src/metabase/users_rest/api.clj+++ b/src/metabase/users_rest/api.clj@@ -10,6 +10,7 @@[metabase.auth-identity.core :as auth-identity][metabase.collections.models.collection :as collection][metabase.config.core :as config]+ [metabase.dashboards.db :as dashboards.db][metabase.events.core :as events][metabase.models.interface :as mi][metabase.permissions.core :as perms]@@ -21,6 +22,7 @@[metabase.tenants.core :as tenants][metabase.users-rest.db :as users-rest.db][metabase.users.core :as users]+ [metabase.users.db :as users.db][metabase.users.models.user :as user][metabase.users.schema :as users.schema][metabase.users.settings :as users.settings]@@ -331,7 +333,7 @@[user](let [enabled? (appearance/custom-homepage)id (appearance/custom-homepage-dashboard)- dash (users-rest.db/dashboard id)+ dash (when (pos-int? id) (dashboards.db/dashboard id))valid? (and enabled? id (some? dash) (not (:archived dash)) (mi/can-read? dash))](assoc user:custom_homepage (when valid? {:dashboard_id id}))))@@ -568,7 +570,7 @@(api/check-400 (not (and (:tenant_id changes) (:is_superuser changes)))"Superusers cannot be tenant users")(reset-magic-group-membership! id (:tenant_id changes)))- (events/publish-event! :event/user-update {:object (users-rest.db/user id)+ (events/publish-event! :event/user-update {:object (users.db/user id):previous-object user-before-update:user-id api/*current-user-id*}))(maybe-update-user-personal-collection-name! user-before-update body)@@ -714,7 +716,7 @@(check-not-internal-user id)(api/check-404 (users-rest.db/user-exists? id))(users-rest.db/update-personal-user! id {:is_active false})- (events/publish-event! :event/user-deactivated {:object (users-rest.db/user id) :user-id api/*current-user-id*})+ (events/publish-event! :event/user-deactivated {:object (users.db/user id) :user-id api/*current-user-id*}){:success true});;; +----------------------------------------------------------------------------------------------------------------+diff --git a/src/metabase/users_rest/db.clj b/src/metabase/users_rest/db.cljindex a5970d10132..1862503e9b5 100644--- a/src/metabase/users_rest/db.clj+++ b/src/metabase/users_rest/db.clj@@ -75,13 +75,6 @@[user-id :- ::lib.schema.id/user](t2/select-one [:model/LoginHistory :timestamp] :user_id user-id {:order-by [[:timestamp :asc]]}))-(mu/defn dashboard- "The Dashboard with `dashboard-id`, or nil. `dashboard-id` may be nil (e.g. when no custom homepage dashboard is- configured) or a stale/invalid id (e.g. a deleted custom homepage Dashboard) that matches no Dashboard, in which- case the result is nil."- [dashboard-id :- [:maybe :int]]- (t2/select-one :model/Dashboard :id dashboard-id))-(mu/defn writable-collection-exists?"Whether the current user can write to at least one Collection (excluding the Trash and archived items)."[]@@ -104,11 +97,6 @@changes :- ::users.schema/user.update](t2/update! :model/User user-id changes))-(mu/defn user- "The User with `user-id`, or nil."- [user-id :- ::lib.schema.id/user]- (t2/select-one :model/User :id user-id))-(mu/defn personal-user-columns"The id, email, name, active flag, SSO source, and tenant id of the personal User with `user-id`, or nil."[user-id :- ::lib.schema.id/user]diff --git a/src/metabase/view_log/db.clj b/src/metabase/view_log/db.cljindex c29d00138be..dde6e997eac 100644--- a/src/metabase/view_log/db.clj+++ b/src/metabase/view_log/db.clj@@ -3,7 +3,6 @@additional logic, so the rest of the module never talks to `toucan2.core` itself."(:require[java-time.api :as t]- [metabase.lib.schema.id :as lib.schema.id][metabase.util.malli :as mu][metabase.util.malli.schema :as ms][metabase.view-log.schema :as view-log.schema]@@ -49,11 +48,6 @@(t2/with-transaction [_conn](t2/insert! :model/ViewLog views)))-(mu/defn card-type- "The `:type` of the Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one-fn :type :model/Card :id card-id))-(mu/defn update-dashboards-last-viewed-at!"Move `last_viewed_at` of each Dashboard in `dashboard-id->timestamp` forward to its timestamp, without touching`updated_at`, via a raw update that bypasses Toucan 2 model hooks (specifically the :hook/search-indexdiff --git a/src/metabase/view_log/events/view_log.clj b/src/metabase/view_log/events/view_log.cljindex b7f27431789..002eb5a2e70 100644--- a/src/metabase/view_log/events/view_log.clj+++ b/src/metabase/view_log/events/view_log.clj@@ -10,6 +10,7 @@[metabase.batch-processing.core :as grouper][metabase.events.core :as events][metabase.premium-features.core :as premium-features]+ [metabase.queries.db :as queries.db][metabase.query-permissions.core :as query-perms][metabase.util :as u][metabase.util.log :as log]@@ -169,7 +170,7 @@(try(when (and (= context :ad-hoc)(or (analytics/data-app-client?)- (= :model (view-log.db/card-type card-id))))+ (= :model (:type (queries.db/card card-id)))))(increment-view-counts! :model/Card card-id)(record-views! (generate-view :model :model/Card:object-id card-iddiff --git a/src/metabase/warehouse_schema/db.clj b/src/metabase/warehouse_schema/db.cljindex 9d4d3936933..c11762ce0dc 100644--- a/src/metabase/warehouse_schema/db.clj+++ b/src/metabase/warehouse_schema/db.clj@@ -18,10 +18,10 @@"How should we order fields."[[:position :asc] [:%lower.name :asc]])-(mu/defn field+(mu/defn field :- [:maybe ::warehouse-schema.schema/field]"The ::warehouse-schema.schema/field with `field-id`, or nil."[field-id :- ::lib.schema.id/field]- (t2/select-one :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query)]}))+ (t2/select-one :model/Field :id [:auto/param field-id] {:from [(warehouse-schema-overlay/field-query)]}))(mu/defn field-in-path"The ::warehouse-schema.schema/field named by the last of `field-names` (each nested inside the previous, bottom-most first) under@@ -45,11 +45,6 @@[field-ids :- [:sequential ::lib.schema.id/field]](t2/select [:model/Field :id :table_id] :id [:in field-ids] {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))-(mu/defn field-table-id- "The ::warehouse-schema.schema/table ID of the ::warehouse-schema.schema/field with `field-id`."- [field-id :- ::lib.schema.id/field]- (t2/select-one-fn :table_id :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))-(mu/defn field-id-by-name"The ID of the ::warehouse-schema.schema/field named `field-name` under `parent-id` in the ::warehouse-schema.schema/table with `table-id`, or nil."[table-id :- ::lib.schema.id/table@@ -57,12 +52,6 @@field-name :- :string](t2/select-one-pk :model/Field :name field-name :parent_id parent-id :table_id table-id {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))-(mu/defn field-values-eligibility- "The columns deciding whether the ::warehouse-schema.schema/field with `field-id` should have FieldValues, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one [:model/Field :base_type :visibility_type :has_field_values :preview_display] :id field-id- {:from [(warehouse-schema-overlay/field-query)]}))-(mu/defn field-ids-for-table"The IDs of the Fields of the ::warehouse-schema.schema/table with `table-id`."[table-id :- ::lib.schema.id/table]@@ -421,10 +410,10 @@;;; ------------------------------------------------- ::warehouse-schema.schema/table --------------------------------------------------(mu/defn table+(mu/defn table :- [:maybe ::warehouse-schema.schema/table]"The ::warehouse-schema.schema/table with `table-id`, or nil."[table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))+ (t2/select-one :model/Table :id [:auto/param table-id] {:from [(warehouse-schema-overlay/table-query)]}))(mu/defn tables"The Tables with `table-ids`."@@ -438,16 +427,6 @@table-name :- :string](t2/select-one :model/Table :name table-name :db_id database-id :schema schema {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn table-name-and-schema- "The name and schema of the ::warehouse-schema.schema/table with `table-id`."- [table-id :- ::lib.schema.id/table]- (t2/select-one [:model/Table :name :schema] :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))--(mu/defn table-database-id- "The ::warehouses.schema/database ID of the ::warehouse-schema.schema/table with `table-id`."- [table-id :- ::lib.schema.id/table]- (t2/select-one-fn :db_id :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query {:user-settings? false})]}))-(defn active-tables-for-database"The active Tables of the Database with `database-id`."[database-id]@@ -537,26 +516,11 @@;;; ------------------------------------------------ ::warehouses.schema/database -------------------------------------------------(mu/defn database- "The ::warehouses.schema/database with `database-id`, or nil."- [database-id :- [:maybe ::lib.schema.id/database]]- (t2/select-one :model/Database :id database-id))-(mu/defn databases-by-id"A map of ID to ::warehouses.schema/database for `database-ids`."[database-ids :- [:set ::lib.schema.id/database]](t2/select-pk->fn identity :model/Database :id [:in database-ids]))-(mu/defn database-engine- "The engine of the ::warehouses.schema/database with `database-id`."- [database-id :- ::lib.schema.id/database]- (t2/select-one-fn :engine :model/Database :id database-id))--(mu/defn database-name- "The name of the ::warehouses.schema/database with `database-id`."- [database-id :- [:maybe ::lib.schema.id/database]]- (t2/select-one-fn :name :model/Database :id database-id))-(mu/defn database-id-by-name"The ID of the ::warehouses.schema/database named `database-name`, or nil."[database-name :- :string]diff --git a/src/metabase/warehouse_schema/field_values/distinct_batch.clj b/src/metabase/warehouse_schema/field_values/distinct_batch.cljindex dbefc373772..1d11bee0dd1 100644--- a/src/metabase/warehouse_schema/field_values/distinct_batch.clj+++ b/src/metabase/warehouse_schema/field_values/distinct_batch.clj@@ -37,8 +37,8 @@[metabase.query-processor :as qp][metabase.util :as u][metabase.util.honey-sql-2 :as h2x]- [metabase.warehouse-schema.db :as warehouse-schema.db]- [metabase.warehouse-schema.models.field-values :as field-values]))+ [metabase.warehouse-schema.models.field-values :as field-values]+ [metabase.warehouses.db :as warehouses.db]))(set! *warn-on-reflection* true)@@ -138,7 +138,7 @@(or equivalent) to decide log-and-continue vs abort semantics."[table fields](let [db-id (:db_id table)- driver (:engine (warehouse-schema.db/database db-id))+ driver (:engine (warehouses.db/database db-id))fields (vec fields)hsql (build-union driver table fields)[sql & params] (sql.qp/format-honeysql driver hsql)diff --git a/src/metabase/warehouse_schema/metadata_from_qp.clj b/src/metabase/warehouse_schema/metadata_from_qp.cljindex b6d5ec5328c..74c31fcf54e 100644--- a/src/metabase/warehouse_schema/metadata_from_qp.clj+++ b/src/metabase/warehouse_schema/metadata_from_qp.clj@@ -35,7 +35,7 @@query-xform :- [:=> [:cat ::lib.schema/query] ::lib.schema/query]rff :- [:maybe ::qp.schema/rff]]{:pre [(pos-int? table-id)]}- (let [database-id (warehouse-schema.db/table-database-id table-id)+ (let [database-id (:db_id (warehouse-schema.db/table table-id))mp (lib-be/application-database-metadata-provider database-id)query (-> (lib/query mp (lib.metadata/table mp table-id))query-xformdiff --git a/src/metabase/warehouse_schema/models/field.clj b/src/metabase/warehouse_schema/models/field.cljindex fe88f7c2fdd..b7261d2c0de 100644--- a/src/metabase/warehouse_schema/models/field.clj+++ b/src/metabase/warehouse_schema/models/field.clj@@ -391,7 +391,7 @@[{field-name :name, table-id :table_id, parent-id :parent_id}](conj (vec (if-let [parent (warehouse-schema.db/field parent-id)](qualified-name-components parent)- (let [{table-name :name, schema :schema} (warehouse-schema.db/table-name-and-schema table-id)]+ (let [{table-name :name, schema :schema} (warehouse-schema.db/table table-id)](conj (when schema[schema])table-name))))@@ -407,7 +407,7 @@(mdb/memoize-for-application-db(fn [field-id]{:pre [(integer? field-id)]}- (warehouse-schema.db/field-table-id field-id))))+ (:table_id (warehouse-schema.db/field field-id)))))(defn field-id->database-id"Return the ID of the Database this Field belongs to."diff --git a/src/metabase/warehouse_schema/models/field_values.clj b/src/metabase/warehouse_schema/models/field_values.cljindex 34fd175bcfb..2d3e1381441 100644--- a/src/metabase/warehouse_schema/models/field_values.clj+++ b/src/metabase/warehouse_schema/models/field_values.clj@@ -250,7 +250,7 @@[field-or-field-id](if-not (map? field-or-field-id)(let [field-id (u/the-id field-or-field-id)]- (recur (or (warehouse-schema.db/field-values-eligibility field-id)+ (recur (or (warehouse-schema.db/field field-id)(throw (ex-info (tru "Field {0} does not exist." field-id){:field-id field-id, :status-code 404})))))(let [{base-type :base_typediff --git a/src/metabase/warehouse_schema/models/table.clj b/src/metabase/warehouse_schema/models/table.cljindex b1052c008c9..f87591e5e05 100644--- a/src/metabase/warehouse_schema/models/table.clj+++ b/src/metabase/warehouse_schema/models/table.clj@@ -19,6 +19,7 @@[metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.humanization :as humanization][metabase.warehouse-schema.schema]+ [metabase.warehouses.db :as warehouses.db][methodical.core :as methodical][toucan2.core :as t2]))@@ -232,7 +233,7 @@;; reasserts matching DB-level defaults for non-model insert paths.(let [defaults {:display_name (humanization/name->human-readable-name (:name table)):field_order (or (:field_order table)- (driver/default-field-order (warehouse-schema.db/database-engine (:db_id table))))+ (driver/default-field-order (:engine (warehouses.db/database (:db_id table))))):data_layer :internal:data_authority :unconfigured}](collection/check-allowed-content :table (:collection_id table))@@ -567,7 +568,7 @@(defn database"Return the `Database` associated with this `Table`."[table]- (warehouse-schema.db/database (:db_id table)))+ (warehouses.db/database (:db_id table)));;; ------------------------------------------------- Serialization -------------------------------------------------(defmethod serdes/deserialization-dependencies "Table" [{:keys [collection_id transform_id]}]@@ -591,7 +592,7 @@(merge fields settings field-settings dimensions segments measures)))(defmethod serdes/generate-path "Table" [_ table]- (let [db-name (warehouse-schema.db/database-name (:db_id table))]+ (let [db-name (:name (warehouses.db/database (:db_id table)))](filterv some? [{:model "Database" :id db-name}(when (:schema table){:model "Schema" :id (:schema table)})diff --git a/src/metabase/warehouse_schema/table.clj b/src/metabase/warehouse_schema/table.cljindex 28a7748941a..21a1de170d8 100644--- a/src/metabase/warehouse_schema/table.clj+++ b/src/metabase/warehouse_schema/table.clj@@ -9,6 +9,7 @@[metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.models.field-values :as field-values][metabase.warehouses.core :as warehouses]+ [metabase.warehouses.db :as warehouses.db][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -330,7 +331,7 @@include-database?(assoc :db (when-let [database (when (int? database_id)(or (get databases database_id)- (warehouse-schema.db/database database_id)))]+ (warehouses.db/database database_id)))](when (mi/can-read? database) database)))include-fields?diff --git a/src/metabase/warehouse_schema_rest/api/field.clj b/src/metabase/warehouse_schema_rest/api/field.cljindex f490555e386..691a371c0b3 100644--- a/src/metabase/warehouse_schema_rest/api/field.clj+++ b/src/metabase/warehouse_schema_rest/api/field.clj@@ -17,6 +17,7 @@[metabase.util.malli.schema :as ms][metabase.util.quick-task :as quick-task][metabase.warehouse-schema-rest.db :as warehouse-schema-rest.db]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.field :as schema.field][metabase.warehouse-schema.metadata-from-qp :as metadata-from-qp][metabase.warehouse-schema.models.field :as field]@@ -90,9 +91,9 @@(when target-field-id(check-field-in-same-database! source-field-id target-field-id param-name)(when (not= target-field-id current-target-field-id)- (-> (warehouse-schema-rest.db/field target-field-id)+ (-> (warehouse-schema.db/field target-field-id):table_id- warehouse-schema-rest.db/table+ warehouse-schema.db/tableschema.table/check-data-model-perms))))(defn- clear-dimension-on-fk-change! [{:keys [dimensions], :as _field}]@@ -170,7 +171,7 @@[:settings {:optional true} [:maybe ms/VisualizationSettings]][:nfc_path {:optional true} [:maybe [:sequential ms/NonBlankString]]][:json_unfolding {:optional true} [:maybe :boolean]]]]- (let [field (-> (warehouse-schema-rest.db/field id)+ (let [field (-> (warehouse-schema.db/field id)api/write-check(t2/hydrate :dimensions))new-semantic-type (keyword (get body :semantic_type (:semantic_type field)))@@ -216,7 +217,7 @@(update-nested-fields-on-json-unfolding-change! field json-unfolding));; return updated field. note the fingerprint on this might be out of date if the task below would replace them;; but that shouldn't matter for the datamodel page- (let [updated (warehouse-schema-rest.db/field id)]+ (let [updated (warehouse-schema.db/field id)](u/prog1 (-> updated(t2/hydrate :dimensions :has_field_values)(schema.field/hydrate-target-with-data-model-perms))@@ -280,7 +281,7 @@:type dimension-type:name dimension-name:human_readable_field_id human-readable-field-id})))- (events/publish-event! :event/field-update {:object (warehouse-schema-rest.db/field id)+ (events/publish-event! :event/field-update {:object (warehouse-schema.db/field id):user-id api/*current-user-id*})(warehouse-schema-rest.db/dimension-for-field id))@@ -294,7 +295,7 @@[:id ms/PositiveInt]]](api/write-check :model/Field id)(warehouse-schema-rest.db/delete-dimensions-for-field! id)- (events/publish-event! :event/field-update {:object (warehouse-schema-rest.db/field id)+ (events/publish-event! :event/field-update {:object (warehouse-schema.db/field id):user-id api/*current-user-id*})api/generic-204-no-content)@@ -313,7 +314,7 @@_bodyrequest](some-> (data-apps/request-data-app request) (data-apps/check-field id))- (let [field (api/query-check (warehouse-schema-rest.db/field id))]+ (let [field (api/query-check (warehouse-schema.db/field id))](parameters.field/field->values field)))(defn- validate-human-readable-pairs@@ -339,7 +340,7 @@_query-params{value-pairs :values} :- [:map {:closed true}[:values ms/FieldValuesList]]]- (let [field (api/write-check (warehouse-schema-rest.db/field id))]+ (let [field (api/write-check (warehouse-schema.db/field id))](api/check (field-values/field-should-have-field-values? field)[400 (str "You can only update the human readable values of a mapped values of a Field whose value of ""`has_field_values` is `list` or whose 'base_type' is 'type/Boolean'.")])@@ -365,7 +366,7 @@[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](analytics/track-event! :snowplow/simple_event {:event "field_manual_scan" :target_id id})- (let [field (api/write-check (warehouse-schema-rest.db/field id))+ (let [field (api/write-check (warehouse-schema.db/field id));; Grant full permissions so that permission checks pass during sync. If a user has DB detail perms;; but no data perms, they should stll be able to trigger a sync of field values. This is fine because we don't;; return any actual field values from this API. (#21764)@@ -389,7 +390,7 @@Database is set up to automatically sync FieldValues, they will be recreated during the next cycle."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (field-values/clear-field-values-for-field! (api/write-check (warehouse-schema-rest.db/field id)))+ (field-values/clear-field-values-for-field! (api/write-check (warehouse-schema.db/field id))){:status :success});;; --------------------------------------------------- Searching ----------------------------------------------------@@ -414,8 +415,8 @@(data-apps/check-field data-app search-id))(when-not value(api/check-400 (request/limit) "Limit required if value is omitted"))- (let [field (api/check-404 (warehouse-schema-rest.db/field id))- search-field (api/check-404 (warehouse-schema-rest.db/field search-id))]+ (let [field (api/check-404 (warehouse-schema.db/field id))+ search-field (api/check-404 (warehouse-schema.db/field search-id))](api/check-403 (mi/can-read? field))(api/check-403 (mi/can-read? search-field))(parameters.field/search-values field search-field value (request/limit))))@@ -437,8 +438,8 @@(when-let [data-app (data-apps/request-data-app request)](data-apps/check-field data-app id)(data-apps/check-field data-app remapped-id))- (let [field (-> (warehouse-schema-rest.db/field id) api/check-404 api/read-check)- remapped-field (-> (warehouse-schema-rest.db/field remapped-id) api/check-404 api/read-check)+ (let [field (-> (warehouse-schema.db/field id) api/check-404 api/read-check)+ remapped-field (-> (warehouse-schema.db/field remapped-id) api/check-404 api/read-check)value (parameters.field/parse-query-param-value-for-field field value)](parameters.field/remapped-value field remapped-field value)))@@ -455,4 +456,4 @@_bodyrequest](some-> (data-apps/request-data-app request) (data-apps/check-field id))- (-> (warehouse-schema-rest.db/field id) api/read-check xrays/related))+ (-> (warehouse-schema.db/field id) api/read-check xrays/related))diff --git a/src/metabase/warehouse_schema_rest/api/table.clj b/src/metabase/warehouse_schema_rest/api/table.cljindex 6e9b73949b9..457bad4a40b 100644--- a/src/metabase/warehouse_schema_rest/api/table.clj+++ b/src/metabase/warehouse_schema_rest/api/table.clj@@ -6,6 +6,7 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.collections.core :as collections]+ [metabase.collections.db :as collections.db][metabase.data-apps.core :as data-apps][metabase.database-routing.core :as database-routing][metabase.driver.settings :as driver.settings]@@ -33,9 +34,11 @@[metabase.util.malli.schema :as ms][metabase.util.quick-task :as quick-task][metabase.warehouse-schema-rest.db :as warehouse-schema-rest.db]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.models.table :as table][metabase.warehouse-schema.models.table-user-settings :as schema.table-user-settings][metabase.warehouse-schema.table :as schema.table]+ [metabase.warehouses.db :as warehouses.db][metabase.xrays.core :as xrays][steffan-westcott.clj-otel.api.trace.span :as span][toucan2.core :as t2]))@@ -147,7 +150,7 @@(let [api-perm-check-fn (if include_editable_data_modelschema.table/check-data-model-permsapi/read-check)]- (-> (api/check-404 (warehouse-schema-rest.db/table id))+ (-> (api/check-404 (warehouse-schema.db/table id))api-perm-check-fn(t2/hydrate :db :pk_field :collection)schema.table/present-table)))@@ -159,7 +162,7 @@(api.macros/defendpoint :get "/:table-id/data""Get the data for the given table"[{:keys [table-id]} :- [:map {:closed true} [:table-id ms/PositiveInt]]]- (let [table (warehouse-schema-rest.db/table table-id)+ (let [table (warehouse-schema.db/table table-id)db-id (:db_id table)](api/query-check table)(qp.store/with-metadata-provider db-id@@ -225,7 +228,7 @@(u/update-some :data_source keyword)not-empty)](schema.table-user-settings/upsert-user-settings existing-table changes))- (let [updated-table (warehouse-schema-rest.db/table id)+ (let [updated-table (warehouse-schema.db/table id)changed-field-order? (not= (:field_order updated-table) (:field_order existing-table))](if changed-field-order?(do@@ -242,7 +245,7 @@(quick-task/submit-task!(fn [](doseq [[db-id tables] (group-by :db_id newly-unhidden)]- (let [database (warehouse-schema-rest.db/database db-id)]+ (let [database (warehouses.db/database db-id)];; it's okay to allow testing H2 connections during sync. We only want to disallow you from testing them for the;; purposes of creating a new H2 database.(if (binding [driver.settings/*allow-testing-h2-connections* true@@ -257,7 +260,7 @@(defn- check-can-publish-tables-to-collection- (let [collection (api/check-404 (warehouse-schema-rest.db/collection collection-id))]+ (let [collection (api/check-404 (collections.db/collection collection-id))](api/check-400 (= (:type collection) collections/library-data-collection-type)(tru "Tables can only be published to Semantic layer/Data collections."))(api/check-403 (every? mi/can-query? tables))))@@ -398,7 +401,7 @@:origin_id (:id origin-field):origin origin-field:destination_id (:fk_target_field_id origin-field)- :destination (t2/hydrate (warehouse-schema-rest.db/field (:fk_target_field_id origin-field)) :table)})))+ :destination (t2/hydrate (warehouse-schema.db/field (:fk_target_field_id origin-field)) :table)})));; TODO (Cam 10/28/25) -- fix this endpoint route to use kebab-case for consistency with the rest of our REST API;;@@ -412,7 +415,7 @@are eligible for FieldValues."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (let [table (api/write-check (warehouse-schema-rest.db/table id))]+ (let [table (api/write-check (warehouse-schema.db/table id))](events/publish-event! :event/table-manual-scan {:object table :user-id api/*current-user-id*});; Grant full permissions so that permission checks pass during sync. If a user has DB detail perms;; but no data perms, they should stll be able to trigger a sync of field values. This is fine because we don't@@ -436,7 +439,7 @@this Table's Database is set up to automatically sync FieldValues, they will be recreated during the next cycle."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (api/write-check (warehouse-schema-rest.db/table id))+ (api/write-check (warehouse-schema.db/table id))(when-let [field-ids (warehouse-schema-rest.db/field-ids-for-table id)](warehouse-schema-rest.db/delete-field-values-for-fields! field-ids)){:status :success})@@ -449,7 +452,7 @@"Return related entities."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (-> (warehouse-schema-rest.db/table id) api/read-check xrays/related))+ (-> (warehouse-schema.db/table id) api/read-check xrays/related))(api.macros/defendpoint :put "/:id/fields/order" :- [:map[:success [:= true]]]@@ -462,8 +465,8 @@[:sequential ms/PositiveInt][:map {:closed true} [:field_order [:sequential ms/PositiveInt]]]]](let [field-order (if (map? body) (:field_order body) body)]- (-> (warehouse-schema-rest.db/table id) api/write-check (schema.table-user-settings/custom-order-fields! field-order))- (events/publish-event! :event/table-update {:object (warehouse-schema-rest.db/table id)+ (-> (warehouse-schema.db/table id) api/write-check (schema.table-user-settings/custom-order-fields! field-order))+ (events/publish-event! :event/table-update {:object (warehouse-schema.db/table id):user-id api/*current-user-id*})){:success true})@@ -554,8 +557,10 @@"Trigger a manual update of the schema metadata for this `Table`."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (let [table (api/check-404 (warehouse-schema-rest.db/table id))- database (api/check-404 (warehouse-schema-rest.db/non-destination-database (:db_id table)))]+ (let [table (api/check-404 (warehouse-schema.db/table id))+ database (api/check-404 (let [database (warehouses.db/database (:db_id table))]+ (when (nil? (:router_database_id database))+ database)))](api/check-403(perms/user-has-permission-for-table?api/*current-user-id*diff --git a/src/metabase/warehouse_schema_rest/db.clj b/src/metabase/warehouse_schema_rest/db.cljindex c01ce648929..dd0c9dee7f6 100644--- a/src/metabase/warehouse_schema_rest/db.clj+++ b/src/metabase/warehouse_schema_rest/db.clj@@ -25,11 +25,6 @@(warehouse-schema-overlay/table-query {:alias :target_t}) [:= :tf.table_id :target_t.id]]:where [:= :sf.id source-field-id]}))-(mu/defn field- "The Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query)]}))-(mu/defn set-nested-fields-active!"Set the active flag of the Fields of the Table with `table-id` whose NFC path matches the SQL LIKE`nfc-path-pattern`, returning the number updated."@@ -130,26 +125,6 @@[table-ids :- [:sequential ::lib.schema.id/table]](t2/select :model/Table :id [:in table-ids] {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn table- "The Table with `table-id`, or nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))--(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database database-id))--(mu/defn non-destination-database- "The Database with `database-id` if it is not a routing destination, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id :router_database_id nil))--(mu/defn collection- "The Collection with `collection-id`, or nil."- [collection-id :- [:maybe ::lib.schema.id/collection]]- (t2/select-one :model/Collection :id collection-id))-(mu/defn active-unretired-field-ids-for-table"The ids of the active, unretired Fields of the Table with `table-id`, or nil."[table-id :- ::lib.schema.id/table]diff --git a/src/metabase/warehouses/db.clj b/src/metabase/warehouses/db.cljindex 3f07a45a7c7..60a593ffbc3 100644--- a/src/metabase/warehouses/db.clj+++ b/src/metabase/warehouses/db.clj@@ -9,20 +9,10 @@[metabase.warehouses.schema :as warehouses.schema][toucan2.core :as t2]))-(mu/defn router-database-id- "The router Database id of the Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one-fn :router_database_id :model/Database :id database-id))--(mu/defn database- "The Database with `database-id`, or nil."+(mu/defn database :- [:maybe ::warehouses.schema/database]+ "The ::warehouses.schema/database with `database-id`, or nil."[database-id :- [:maybe ::lib.schema.id/database]]- (t2/select-one :model/Database :id database-id))--(mu/defn non-destination-database- "The Database with `database-id` if it is not a routing destination, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id :router_database_id nil))+ (t2/select-one :model/Database :id [:auto/param database-id]))(mu/defn databases"The Databases with `database-ids`."diff --git a/src/metabase/warehouses/models/database.clj b/src/metabase/warehouses/models/database.cljindex f301374dc6a..7813f56fddb 100644--- a/src/metabase/warehouses/models/database.clj+++ b/src/metabase/warehouses/models/database.clj@@ -102,7 +102,7 @@:private true} db-id->router-db-id(mdb/memoize-for-application-db(fn [db-id]- (warehouses.db/router-database-id db-id))))+ (:router_database_id (warehouses.db/database db-id)))))(defmethod mi/can-read? :model/Database;; Check if user can see this database's metadata.@@ -216,7 +216,7 @@regardless of the `disable-auto-sync` setting. For automatically-triggered syncs use[[should-auto-sync?]]."[database-id]- (nil? (warehouses.db/router-database-id database-id)))+ (nil? (:router_database_id (warehouses.db/database database-id))))(defn should-auto-sync?"Should this database be synced *automatically* — scheduled sync/analyze, the post-add initialdiff --git a/src/metabase/warehouses/util.clj b/src/metabase/warehouses/util.cljindex fad77d6b595..d5f74edca25 100644--- a/src/metabase/warehouses/util.clj+++ b/src/metabase/warehouses/util.clj@@ -22,9 +22,10 @@[:exclude-uneditable-details? {:optional true :default false} ms/MaybeBooleanValue][:include-destination-databases? {:optional true :default false} ms/MaybeBooleanValue]]](let [filter-by-data-access? (not (or include-editable-data-model? exclude-uneditable-details?))- database (api/check-404 (if include-destination-databases?- (warehouses.db/database id)- (warehouses.db/non-destination-database id)))+ database (api/check-404 (let [database (warehouses.db/database id)]+ (when (or include-destination-databases?+ (nil? (:router_database_id database)))+ database)))router-db-id (:router_database_id database)](cond-> databasefilter-by-data-access? api/read-checkdiff --git a/src/metabase/warehouses_rest/api.clj b/src/metabase/warehouses_rest/api.cljindex cdb6ddc978d..68d7c69a69a 100644--- a/src/metabase/warehouses_rest/api.clj+++ b/src/metabase/warehouses_rest/api.clj@@ -45,6 +45,7 @@[metabase.warehouse-schema.table :as schema.table][metabase.warehouses-rest.db :as warehouses-rest.db][metabase.warehouses.core :as warehouses]+ [metabase.warehouses.db :as warehouses.db][metabase.warehouses.models.database :as database][metabase.warehouses.schema :as warehouses.schema][toucan2.core :as t2]))@@ -914,7 +915,7 @@[:details ms/DatabaseDetails][:id {:optional true} [:maybe ms/PositiveInt]]]]]](api/check-superuser)- (let [database (when id (api/write-check (warehouses-rest.db/database id)))+ (let [database (when id (api/write-check (warehouses.db/database id)))details-or-error (if database(test-existing-database-details database engine details)(warehouses/test-connection-details engine details))]@@ -1017,7 +1018,7 @@(when (:write-data-connection details)(throw (ex-info (tru "write-data-connection must not be set in details"){:status-code 400})))- (let [existing-database (api/write-check (warehouses-rest.db/database id))+ (let [existing-database (api/write-check (warehouses.db/database id));; e2e tests run against the H2 sample database and need to toggle its settings (actions,;; table editing), so the guard is lifted when test endpoints are enabled_ (when (and (:is_sample existing-database)@@ -1111,7 +1112,7 @@;; with the advanced-config feature enabled.(when (premium-features/enable-cache-granular-controls?)(warehouses-rest.db/update-database! id {:cache_ttl cache_ttl}))- (let [db (warehouses-rest.db/database id)]+ (let [db (warehouses.db/database id)];; the details in db and existing-database have been normalized so they are the same here;; we need to pass through details-changed? which is calculated before detail normalization;; to ensure the pool is invalidated and [[driver-api/secret-value-as-file!]] memoization is cleared@@ -1138,7 +1139,7 @@[:id ms/PositiveInt]]](api/check-superuser)(t2/with-transaction [_conn]- (api/let-404 [db (warehouses-rest.db/database id)]+ (api/let-404 [db (warehouses.db/database id)](api/check-403 (mi/can-write? db))(warehouses-rest.db/delete-destination-databases! id)(database-routing/delete-associated-database-router! id)@@ -1450,7 +1451,7 @@[{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]{:keys [connection-type]} :- [:map {:closed true} [:connection-type {:optional true} ::driver.conn/connection-type]]](api/check-superuser)- (let [{:as database :keys [engine]} (api/check-404 (warehouses-rest.db/database id))+ (let [{:as database :keys [engine]} (api/check-404 (warehouses.db/database id))connection-type (or connection-type :default)connection-details (driver.conn/details-for-exact-type database connection-type)](api/check-400 connection-details (tru "No {0} connection configured for this database" (name connection-type)))diff --git a/src/metabase/warehouses_rest/db.clj b/src/metabase/warehouses_rest/db.cljindex 113cbfe02b4..ecacff44602 100644--- a/src/metabase/warehouses_rest/db.clj+++ b/src/metabase/warehouses_rest/db.clj@@ -249,11 +249,6 @@[](t2/select-one :model/Database :is_sample true))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))-(mu/defn update-database!"Apply `changes` to the Database with `database-id`, returning the number updated."[database-id :- ::lib.schema.id/databasediff --git a/src/metabase/xrays/api/automagic_dashboards.clj b/src/metabase/xrays/api/automagic_dashboards.cljindex 085196a1d2e..95bf2c342c1 100644--- a/src/metabase/xrays/api/automagic_dashboards.clj+++ b/src/metabase/xrays/api/automagic_dashboards.clj@@ -5,7 +5,9 @@[medley.core :as m][metabase.api.common :as api][metabase.api.macros :as api.macros]+ [metabase.collections.db :as collections.db][metabase.indexed-entities.core :as indexed-entities]+ [metabase.indexed-entities.db :as indexed-entities.db][metabase.lib-be.core :as lib-be][metabase.lib-be.schema :as lib-be.schema][metabase.lib.core :as lib]@@ -13,7 +15,9 @@[metabase.models.interface :as mi][metabase.permissions.core :as perms][metabase.queries.core :as queries]+ [metabase.queries.db :as queries.db][metabase.query-permissions.core :as query-perms]+ [metabase.segments.db :as segments.db][metabase.util :as u][metabase.util.i18n :as i18n :refer [deferred-tru]][metabase.util.json :as json]@@ -21,6 +25,8 @@[metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms][metabase.util.regex :as u.regex]+ [metabase.warehouse-schema.db :as warehouse-schema.db]+ [metabase.warehouses.db :as warehouses.db][metabase.xrays.automagic-dashboards.comparison :as automagic-dashboards.comparison][metabase.xrays.automagic-dashboards.core :as automagic-dashboards.core][metabase.xrays.automagic-dashboards.dashboard-templates :as automagic-dashboards.dashboard-templates]@@ -96,7 +102,7 @@"Return a list of candidates for automagic dashboards ordered by interestingness."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (-> (xrays.db/database id)+ (-> (warehouses.db/database id)api/read-checkautomagic-dashboards.core/candidate-tables))@@ -129,19 +135,20 @@(if-let [[_ card-id-str] (when (string? table-id-str)(re-matches #"^card__(\d+$)" table-id-str))](->entity :question card-id-str)- (api/read-check (xrays.db/table (ensure-int table-id-str)))))+ (api/read-check (warehouse-schema.db/table (ensure-int table-id-str)))))(defmethod ->entity :segment[_entity-type segment-id-str]- (api/read-check (xrays.db/segment (ensure-int segment-id-str))))+ (api/read-check (segments.db/segment (ensure-int segment-id-str))))(defmethod ->entity :model[_entity-type card-id-str]- (api/read-check (xrays.db/model-card (ensure-int card-id-str))))+ (let [card (queries.db/card (ensure-int card-id-str))]+ (api/read-check (when (= :model (:type card)) card))))(defmethod ->entity :question[_entity-type card-id-str]- (api/read-check (xrays.db/card (ensure-int card-id-str))))+ (api/read-check (queries.db/card (ensure-int card-id-str))))(mu/defn adhoc-query-instance :- [:and(ms/InstanceOf :model/Query)@@ -161,11 +168,11 @@(defmethod ->entity :field[_entity-type field-id-str]- (api/read-check (xrays.db/field (ensure-int field-id-str))))+ (api/read-check (warehouse-schema.db/field (ensure-int field-id-str))))(defmethod ->entity :transform[_entity-type transform-name]- (api/read-check (xrays.db/collection (transforms.materialize/get-collection transform-name)))+ (api/read-check (collections.db/collection (transforms.materialize/get-collection transform-name)))transform-name)(def ^:private entities@@ -307,7 +314,7 @@:keys [linked-tables model-pk indexed-value]}](if (seq linked-tables)(let [child-dashboards (map (fn [{:keys [linked-table-id linked-field-id]}]- (let [table (xrays.db/table linked-table-id)+ (let [table (warehouse-schema.db/table linked-table-id)mp (lib-be/application-database-metadata-provider (:db_id table))](automagic-dashboards.core/automagic-analysistable@@ -372,8 +379,8 @@[{:keys [model-index-id pk-id]} :- [:map {:closed true}[:model-index-id :int][:pk-id :int]]]- (api/let-404 [model-index (xrays.db/model-index model-index-id)- model (xrays.db/card (:model_id model-index))]+ (api/let-404 [model-index (indexed-entities.db/model-index model-index-id)+ model (queries.db/card (:model_id model-index))];; `->entity` does a read check on the model but this is here as well to be extra sure.(api/read-check :model/Card (:model_id model-index))(let [linked (linked-entities {:model modeldiff --git a/src/metabase/xrays/automagic_dashboards/core.clj b/src/metabase/xrays/automagic_dashboards/core.cljindex 7a1544a16f5..d05333a4924 100644--- a/src/metabase/xrays/automagic_dashboards/core.clj+++ b/src/metabase/xrays/automagic_dashboards/core.clj@@ -154,6 +154,7 @@[metabase.lib.schema.id :as lib.schema.id][metabase.models.interface :as mi][metabase.permissions.core :as perms]+ [metabase.queries.db :as queries.db][metabase.query-processor.util :as qp.util][metabase.segments.schema :as segments.schema][metabase.types.core :as types]@@ -163,7 +164,9 @@[metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.models.field :as field]+ [metabase.warehouses.db :as warehouses.db][metabase.xrays.automagic-dashboards.combination :as combination][metabase.xrays.automagic-dashboards.dashboard-templates :as dashboard-templates][metabase.xrays.automagic-dashboards.filters :as filters]@@ -200,7 +203,7 @@(mu/defmethod ->root :model/Segment :- ::ads/root[segment :- [:map [:definition [:maybe ::segments.schema/definition]]]]- (let [table (->> segment :table_id xrays.db/table)]+ (let [table (->> segment :table_id warehouse-schema.db/table)]{:entity segment:full-name (tru "{0} in the {1} segment" (:display_name table) (:name segment)):short-name (:display_name table)@@ -213,7 +216,7 @@(mu/defmethod ->root :xrays/Metric :- ::ads/root[{:keys [table-id], :as metric} :- ::ads/metric]- (let [table (some->> table-id xrays.db/table)]+ (let [table (some->> table-id warehouse-schema.db/table)]{:entity metric:full-name (if (:id metric)(trun "{0} metric" "{0} metrics" (:name metric))@@ -256,7 +259,7 @@(mu/defn- source-question :- [:maybe (ms/InstanceOf :model/Card)][card-or-question :- ::ads/card-or-question](when-let [source-card-id (source-card-id card-or-question)]- (xrays.db/card source-card-id)))+ (queries.db/card source-card-id)))(mu/defn- table-like?[{query :dataset_query, :as _card-or-question} :- ::ads/card-or-question]@@ -284,7 +287,7 @@source-question(assoc :entity_type :entity/GenericTable))(native-query? card) (-> card (assoc :entity_type :entity/GenericTable))- :else (->> card table-id xrays.db/table)))+ :else (->> card table-id warehouse-schema.db/table)))(mu/defmethod ->root :model/Card :- ::ads/root[card :- ::ads/card-or-question]@@ -412,7 +415,7 @@(let [db-id (or ((some-fn :db_id :database_id) source)(throw (ex-info "Source is missing Database ID"{:source source})))]- (xrays.db/database db-id)))+ (warehouses.db/database db-id)))(defn- relevant-fields"Source fields from tables that are applicable to the entity being x-rayed."diff --git a/src/metabase/xrays/automagic_dashboards/interesting.clj b/src/metabase/xrays/automagic_dashboards/interesting.cljindex f44fb03a19a..66054603c33 100644--- a/src/metabase/xrays/automagic_dashboards/interesting.clj+++ b/src/metabase/xrays/automagic_dashboards/interesting.clj@@ -53,7 +53,9 @@[metabase.util.date-2 :as u.date][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.models.field :as field]+ [metabase.warehouses.db :as warehouses.db][metabase.xrays.automagic-dashboards.dashboard-templates :as dashboard-templates][metabase.xrays.automagic-dashboards.schema :as ads][metabase.xrays.automagic-dashboards.util :as magic.util]@@ -124,7 +126,7 @@(condfull-name full-namelink (format "%s → %s"- (-> (xrays.db/field link) :display_name (str/replace #"(?i)\sid$" ""))+ (-> (warehouse-schema.db/field link) :display_name (str/replace #"(?i)\sid$" ""))display_name):else display_name))@@ -372,7 +374,7 @@;; TODO - Deduplicate from core(mu/defn- source->db :- (ms/InstanceOf :model/Database)[source :- (ms/InstanceOf #{:model/Table :model/Card})]- (xrays.db/database ((some-fn :db_id :database_id) source)))+ (warehouses.db/database ((some-fn :db_id :database_id) source)))(defn- enriched-field-with-sources [{:keys [tables source]} field](assoc fielddiff --git a/src/metabase/xrays/automagic_dashboards/util.clj b/src/metabase/xrays/automagic_dashboards/util.cljindex ed6f877f84d..1be054be46c 100644--- a/src/metabase/xrays/automagic_dashboards/util.clj+++ b/src/metabase/xrays/automagic_dashboards/util.clj@@ -15,8 +15,8 @@[metabase.util.malli :as mu][metabase.util.malli.schema :as ms][metabase.util.match :as match]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.xrays.automagic-dashboards.schema :as ads]- [metabase.xrays.db :as xrays.db][ring.util.codec :as codec]))(mu/defn field-isa?@@ -97,7 +97,7 @@(or;; Handle integer Field IDs.(when (integer? id-or-name)- (xrays.db/field id-or-name))+ (warehouse-schema.db/field id-or-name));; handle field string names. Only if we have result metadata. (Not sure why)(when (string? id-or-name)(when-not result-metadatadiff --git a/src/metabase/xrays/db.clj b/src/metabase/xrays/db.cljindex cb37a87f8bc..95beb0b5caf 100644--- a/src/metabase/xrays/db.clj+++ b/src/metabase/xrays/db.clj@@ -6,21 +6,9 @@[metabase.lib.schema.id :as lib.schema.id][metabase.queries.schema :as queries.schema][metabase.util.malli :as mu]- [metabase.util.malli.schema :as ms][metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay][toucan2.core :as t2]))-(mu/defn database- "The Database with `database-id`, or nil."- [database-id :- ::lib.schema.id/database]- (t2/select-one :model/Database :id database-id))--(mu/defn table- "The Table with `table-id`, or nil. `table-id` may be nil (some callers pass a Card's or Metric's possibly-absent- table id), in which case this returns nil."- [table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))-(mu/defn tables"The Tables with `table-ids`."[table-ids :- [:set ::lib.schema.id/table]]@@ -78,16 +66,6 @@[:= :active true]]schema (conj [:= :schema schema]))}))-(mu/defn field- "The Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query)]}))--(mu/defn field-name- "The name of the Field with `field-id`, or nil."- [field-id :- ::lib.schema.id/field]- (t2/select-one-fn :name :model/Field :id field-id {:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))-(mu/defn metadata-column"The `:metadata/column` with `field-id`, or nil."[field-id :- ::lib.schema.id/field]@@ -148,16 +126,6 @@:active true{:from [(warehouse-schema-overlay/field-query)]}))-(mu/defn card- "The Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id))--(mu/defn model-card- "The model Card with `card-id`, or nil."- [card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id card-id :type :model))-(mu/defn cards-in-collection"The Cards in the Collection with `collection-id`."[collection-id :- ::lib.schema.id/collection]@@ -186,27 +154,12 @@[collection-id :- ::lib.schema.id/collection](t2/delete! :model/Card :collection_id collection-id))-(mu/defn segment- "The Segment with `segment-id`, or nil."- [segment-id :- ::lib.schema.id/segment]- (t2/select-one :model/Segment :id segment-id))-(mu/defn unarchived-segments-for-table"The unarchived Segments of the Table with `table-id`. `table-id` may be nil (the caller's Table isitself sometimes absent)."[table-id :- [:maybe ::lib.schema.id/table]](t2/select :model/Segment :table_id table-id :archived false))-(mu/defn collection- "The Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one :model/Collection :id collection-id))--(mu/defn collection-location-columns- "The location and id of the Collection with `collection-id`, or nil."- [collection-id :- ::lib.schema.id/collection]- (t2/select-one [:model/Collection :location :id] :id collection-id))-(mu/defn collection-id-by-name-and-location"The id of the Collection named `collection-name` at `location`, or nil."[collection-name :- :string@@ -269,8 +222,3 @@(apply t2/select [:model/DashboardCard :card_id :dashboard_id](concat (when (seq card-ids) [:card_id [:in card-ids]])(when (seq excluded-dashboard-ids) [:dashboard_id [:not-in excluded-dashboard-ids]]))))--(mu/defn model-index- "The ModelIndex with `model-index-id`, or nil."- [model-index-id :- ms/PositiveInt]- (t2/select-one :model/ModelIndex model-index-id))diff --git a/src/metabase/xrays/related.clj b/src/metabase/xrays/related.cljindex d189fa48cbf..25cdb758405 100644--- a/src/metabase/xrays/related.clj+++ b/src/metabase/xrays/related.clj@@ -4,14 +4,17 @@[clojure.set :as set][medley.core :as m][metabase.api.common :as api]+ [metabase.collections.db :as collections.db][metabase.lib.core :as lib][metabase.lib.schema.util :as lib.schema.util][metabase.models.interface :as mi]+ [metabase.queries.db :as queries.db][metabase.query-processor.util :as qp.util][metabase.segments.schema :as segments.schema][metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.xrays.automagic-dashboards.schema :as ads][metabase.xrays.db :as xrays.db]))@@ -120,9 +123,9 @@(defn- linking-to[table](->> (xrays.db/fk-target-field-ids-for-table (:id table))- (map (comp xrays.db/table+ (map (comp warehouse-schema.db/table:table_id- xrays.db/field))+ warehouse-schema.db/field))distinctfilter-visible(take max-matches)))@@ -131,7 +134,7 @@[table](if-let [fields (not-empty (xrays.db/active-field-ids-for-table (:id table)))](->> (xrays.db/table-ids-of-fields-targeting fields)- (map xrays.db/table)+ (map warehouse-schema.db/table)filter-visible(take max-matches))[]))@@ -140,7 +143,7 @@[card](if-let [dashboards (some-> (:id card) xrays.db/dashboard-ids-for-card not-empty)](->> (xrays.db/other-card-ids-on-dashboards dashboards (:id card))- (map xrays.db/card)+ (map queries.db/card)filter-visible(take max-matches))[]))@@ -188,7 +191,7 @@(->> cards(m/distinct-by :collection_id)interesting-mix- (keep (comp xrays.db/collection :collection_id))+ (keep (comp collections.db/collection :collection_id))filter-visible))(defmulti related@@ -198,7 +201,7 @@(defmethod related :model/Card[card]- (let [table (xrays.db/table (:table_id card))+ (let [table (warehouse-schema.db/table (:table_id card))similar-questions (similar-questions card)similar-metrics (similar-metrics card)]{:table table@@ -217,7 +220,7 @@(defmethod related :xrays/Metric[metric]- (let [table (xrays.db/table (:table_id metric))]+ (let [table (warehouse-schema.db/table (:table_id metric))]{:table table:segments (->> tablesegments-for-table@@ -226,7 +229,7 @@(defmethod related :model/Segment[segment]- (let [table (xrays.db/table (:table_id segment))]+ (let [table (warehouse-schema.db/table (:table_id segment))]{:table table:metrics (metrics-for-table table):segments (->> table@@ -250,7 +253,7 @@(defmethod related :model/Field[field]- (let [table (xrays.db/table (:table_id field))]+ (let [table (warehouse-schema.db/table (:table_id field))]{:table table:segments (->> tablesegments-for-table@@ -267,7 +270,7 @@(defmethod related :model/Dashboard[dashboard]- (let [cards (map xrays.db/card (xrays.db/card-ids-for-dashboard (:id dashboard)))]+ (let [cards (map queries.db/card (xrays.db/card-ids-for-dashboard (:id dashboard)))]{:cards (->> cards(mapcat similar-questions)(remove (set cards))diff --git a/src/metabase/xrays/transforms/core.clj b/src/metabase/xrays/transforms/core.cljindex 71544658ad9..c5fd76c777f 100644--- a/src/metabase/xrays/transforms/core.clj+++ b/src/metabase/xrays/transforms/core.clj@@ -10,6 +10,7 @@[metabase.util.malli :as mu][metabase.util.malli.schema :as ms][metabase.util.match :as match]+ [metabase.warehouse-schema.db :as warehouse-schema.db][metabase.warehouse-schema.models.table :as table][metabase.xrays.db :as xrays.db][metabase.xrays.domain-entities.core :as de :refer [Bindings DimensionBindings SourceEntity SourceName]]@@ -36,7 +37,7 @@field-name[:field (id :guard integer?) _]- (xrays.db/field-name id)))+ (:name (warehouse-schema.db/field id))))(mu/defn- infer-resulting-dimensions :- DimensionBindings[bindings :- Bindingsdiff --git a/src/metabase/xrays/transforms/materialize.clj b/src/metabase/xrays/transforms/materialize.cljindex 59e6b396d71..df064d06d6e 100644--- a/src/metabase/xrays/transforms/materialize.clj+++ b/src/metabase/xrays/transforms/materialize.clj@@ -1,6 +1,7 @@(ns metabase.xrays.transforms.materialize(:require[metabase.api.common :as api]+ [metabase.collections.db :as collections.db][metabase.collections.models.collection :as collection][metabase.lib-be.core :as lib-be][metabase.lib.schema.id :as lib.schema.id]@@ -16,7 +17,7 @@(defn- root-container-location[](collection/children-location- (xrays.db/collection-location-columns (get-or-create-root-container-collection!))))+ (collections.db/collection (get-or-create-root-container-collection!))))(mu/defn get-collection :- [:maybe ::lib.schema.id/collection]"Get collection named `collection-name`. If no location is given root collection for automaticallydiff --git a/test/metabase/auth_identity/db_test.clj b/test/metabase/auth_identity/db_test.cljindex 5bcba450bcc..5d61eb22bad 100644--- a/test/metabase/auth_identity/db_test.clj+++ b/test/metabase/auth_identity/db_test.clj@@ -15,7 +15,7 @@(mt/with-temp [:model/User {user-id :id} {}:model/AuthIdentity _ {:user_id user-id :provider "google"}](mu/disable-enforcement- (doseq [[fn-name f] {"auth-identity" auth-identity.db/auth-identity+ (doseq [[fn-name f] {"auth-identity" auth-identity.db/auth-identity-for-user-and-provider"auth-identity-id" auth-identity.db/auth-identity-id"auth-identity-expiry" auth-identity.db/auth-identity-expiry"auth-identity-exists?" auth-identity.db/auth-identity-exists?@@ -68,12 +68,12 @@:model/AuthIdentity {ai-id :id} {:user_id user-id :provider "google"}:model/AuthIdentity _ {:user_id other-id :provider "google"}](testing "a matching user and provider finds the identity"- (is (= ai-id (:id (auth-identity.db/auth-identity user-id "google"))))+ (is (= ai-id (:id (auth-identity.db/auth-identity-for-user-and-provider user-id "google"))))(is (= ai-id (auth-identity.db/auth-identity-id user-id "google")))(is (= ai-id (:id (auth-identity.db/auth-identity-expiry user-id "google"))))(is (true? (auth-identity.db/auth-identity-exists? user-id "google"))))(testing "another provider matches nothing"- (is (nil? (auth-identity.db/auth-identity user-id "password")))+ (is (nil? (auth-identity.db/auth-identity-for-user-and-provider user-id "password")))(is (nil? (auth-identity.db/auth-identity-id user-id "password")))(is (nil? (auth-identity.db/auth-identity-expiry user-id "password")))(is (false? (auth-identity.db/auth-identity-exists? user-id "password"))))diff --git a/test/metabase/auth_identity/session_test.clj b/test/metabase/auth_identity/session_test.cljindex b23c2583fb9..f016ec0bd6c 100644--- a/test/metabase/auth_identity/session_test.clj+++ b/test/metabase/auth_identity/session_test.clj@@ -34,8 +34,7 @@(testing "Creating a session with Google SSO authentication tracks the auth_identity_id"(mt/with-temp [:model/User user {}:model/AuthIdentity google-auth {:user_id (:id user)- :provider "google"- :metadata {:sso_source "google"}}]+ :provider "google"}](let [device-info {:device_id "test-device-456":embedded false:token_exchange false@@ -51,8 +50,7 @@(testing "Creating a session with LDAP authentication tracks the auth_identity_id"(mt/with-temp [:model/User user {}:model/AuthIdentity ldap-auth {:user_id (:id user)- :provider "ldap"- :metadata {:login_attributes {:uid "testuser"}}}]+ :provider "ldap"}](let [device-info {:device_id "test-device-789":embedded false:token_exchange falsediff --git a/test/metabase/channel/rest/api/channel_test.clj b/test/metabase/channel/rest/api/channel_test.cljindex 50b4dadef50..cc665d11c48 100644--- a/test/metabase/channel/rest/api/channel_test.clj+++ b/test/metabase/channel/rest/api/channel_test.clj@@ -80,7 +80,7 @@(mt/user-http-request :crowberto :get 200 "channel" {:include_inactive true}))))))(deftest list-channels-permissions-test- (mt/with-temp [:model/Channel {chn-1 :id} (assoc default-test-channel :type :channel/http)]+ (mt/with-temp [:model/Channel {chn-1 :id} (assoc default-test-channel :type :channel/http :details {:url "https://metabase.com" :auth-method "none"})](let [get-channel (fn [user status](mt/user-http-request user :get status (format "channel/%s" chn-1)))get-channels (fn [user]diff --git a/test/metabase/explorations/api_test.clj b/test/metabase/explorations/api_test.cljindex 2492d68fc1f..2561982e2a1 100644--- a/test/metabase/explorations/api_test.clj+++ b/test/metabase/explorations/api_test.clj@@ -2947,8 +2947,8 @@{:display "bar" :visualization-settings {}}))(is (= 2 (count @checked))"both source queries are permission-checked")- (is (= (set (map #(t2/select-one-fn :dataset_query :model/ExplorationQuery :id %) query-ids))- (set @checked))+ (is (= (set (map #(lib/primary-source-table-id (t2/select-one-fn :dataset_query :model/ExplorationQuery :id %)) query-ids))+ (set (map lib/primary-source-table-id @checked)))"and they are the two sources' own queries, not the first one twice"))))))(deftest composite-collapses-duplicate-exploration-query-ids-testdiff --git a/test/metabase/explorations/derived_perms_test.clj b/test/metabase/explorations/derived_perms_test.cljindex f36aa1b67b5..a63c3eb64e2 100644--- a/test/metabase/explorations/derived_perms_test.clj+++ b/test/metabase/explorations/derived_perms_test.clj@@ -287,8 +287,9 @@(testing "grouping cannot be free: [[visibility-key]] resolves each chart's query, because thelens half of the verdict compares *resolved* tables and two charts can share a rawfootprint while reading different ones. That resolution is per chart and mostly metadata- reads, so cost grows — but it must stay far below re-running the verdict itself, which- would be ~13 queries a chart (~325 for 25)."+ reads (each chart's stored query is read back with its metadata provider attached), so cost+ grows — but it must stay far below re-running the verdict itself, which would be ~13+ queries a chart (~325 for 25)."(let [specs (fn [n] (repeat n {:creator-id (mt/user->id :lucky) :table :venues :token {}}))measure (fn [n](let [thread (thread-with-snapshots! (specs n))]@@ -298,8 +299,8 @@(call-count)))))small (measure 2)large (measure 25)]- (is (< large (* 2 small))- (format "resolution must stay cheap (2 charts: %d queries, 25 charts: %d)" small large)))))+ (is (< (- large small) (* 2 (- 25 2)))+ (format "resolution must stay under 2 queries a chart (2 charts: %d queries, 25 charts: %d)" small large)))));;; --------------------------------- Summary-document content gate ---------------------------------diff --git a/test/metabase/explorations/models/exploration_test.clj b/test/metabase/explorations/models/exploration_test.cljindex 287b54b77b7..3c734087ed5 100644--- a/test/metabase/explorations/models/exploration_test.clj+++ b/test/metabase/explorations/models/exploration_test.clj@@ -158,11 +158,13 @@:card_id (:id metric):dimension_id "d1":page_id (:id p)- :dataset_query {:database 1 :type :query}}]+ :dataset_query (let [mp (mt/metadata-provider)]+ (lib/query mp (lib.metadata/table mp (mt/id :venues))))}](testing "ExplorationQuery transforms"(let [reread (t2/select-one :model/ExplorationQuery :id (:id q))](is (= "d1" (:dimension_id reread)))- (is (= 1 (-> reread :dataset_query :database)))))))+ (is (= (mt/id) (-> reread :dataset_query :database)))+ (is (= (mt/id :venues) (lib/primary-source-table-id (:dataset_query reread))))))))(deftest exploration-is-searchable-test;; The wiring assertions run unconditionally so this test can never silently passdiff --git a/test/metabase/explorations/queues_test.clj b/test/metabase/explorations/queues_test.cljindex 7e1f37e9f4b..59c285d66c3 100644--- a/test/metabase/explorations/queues_test.clj+++ b/test/metabase/explorations/queues_test.clj@@ -120,11 +120,9 @@(mt/with-temporary-setting-values [queue-max-retries 2](do-with-fixtures!(fn [{:keys [card thread]}]- ;; a database that doesn't exist: the QP throws on every attempt+ ;; a table that doesn't exist: the QP throws on every attempt(let [qid (insert-query! (:id thread) (:id card)- {:database 999999- :type :query- :query {:source-table 1 :aggregation [[:count]]}})]+ {:database (mt/id) :type :query :query {:source-table Integer/MAX_VALUE :aggregation [[:count]]}})](mq.tu/with-test-mq [ctx](#'explorations.queues/publish-pending-queries! (:id thread))(mq.tu/eventually! ctx #(= "error" (status qid)) 60000))@@ -144,11 +142,9 @@(mt/with-temporary-setting-values [queue-max-retries 5](do-with-fixtures!(fn [{:keys [card thread]}]- ;; a database that doesn't exist: the QP throws on every attempt → the error path+ ;; a table that doesn't exist: the QP throws on every attempt → the error path(let [qid (insert-query! (:id thread) (:id card)- {:database 999999- :type :query- :query {:source-table 1 :aggregation [[:count]]}})+ {:database (mt/id) :type :query :query {:source-table Integer/MAX_VALUE :aggregation [[:count]]}})calls (atom 0)orig runner/maybe-complete-thread!](mq.tu/with-worker-redefs [runner/maybe-complete-thread!@@ -234,11 +230,9 @@(mt/with-temporary-setting-values [queue-max-retries 2](do-with-fixtures!(fn [{:keys [card thread]}]- ;; a database that doesn't exist: the QP throws on every attempt+ ;; a table that doesn't exist: the QP throws on every attempt(let [poison (insert-query! (:id thread) (:id card)- {:database 999999- :type :query- :query {:source-table 1 :aggregation [[:count]]}})+ {:database (mt/id) :type :query :query {:source-table Integer/MAX_VALUE :aggregation [[:count]]}})good (insert-query! (:id thread) (:id card) (venues-query))](mq.tu/with-test-mq [ctx];; Published in one `with-queue` so the outbox chunks them into a single batch, poisondiff --git a/test/metabase/explorations/runner_test.clj b/test/metabase/explorations/runner_test.cljindex 5a3e34cc3b9..4f1799b29ee 100644--- a/test/metabase/explorations/runner_test.clj+++ b/test/metabase/explorations/runner_test.clj@@ -15,6 +15,7 @@[metabase.metabot.self.claude][metabase.metabot.usage][metabase.permissions.core :as perms]+ [metabase.queries.db :as queries.db][metabase.query-processor.core :as qp][metabase.test :as mt][metabase.test.util.dynamic-redefs :as dynamic-redefs]@@ -96,7 +97,7 @@(is (some? result))(is (some? (:stored_result_id result)))(is (some? sr))- (is (pos? (count (:result_data sr))))+ (is (pos? (count (queries.db/stored-result-data (:id sr)))))(is (= 1 (:row_count sr))"the QP's top-level :row_count (1 row for an unbucketed count) is persisted on the snapshot")))))@@ -153,7 +154,7 @@(is (= "done" (:status final)))(is (some? result))(is (some? sr))- (is (pos? (count (:result_data sr))))+ (is (pos? (count (queries.db/stored-result-data (:id sr)))))(is (nil? (:interestingness_score result)))))))))(deftest run-one-iteration-writes-contextual-score-test@@ -228,7 +229,7 @@(is (= "done" (:status final)))(is (some? result))(is (some? sr))- (is (pos? (count (:result_data sr))))+ (is (pos? (count (queries.db/stored-result-data (:id sr)))))(is (nil? (:contextual_interestingness_score result)))(is (double? (:interestingness_score result))"heuristic score still computed when contextual fails")))))))@@ -314,8 +315,7 @@:dataset_query (lib/->legacy-MBQL (let [mp (mt/metadata-provider)] (-> (lib/query mp (lib.metadata/table mp (mt/id :venues))) (lib/aggregate (lib/count)))))}](let [thread (temp-thread! (:id u))row (pending-query! (:id thread) (:id card)- {:database 999999 :type :query- :query {:source-table 1 :aggregation [[:count]]}})+ {:database (mt/id) :type :query :query {:source-table Integer/MAX_VALUE :aggregation [[:count]]}})final (drain-until-terminal! (:id row))](is (= "error" (:status final)))(is (some? (:error_message final)))diff --git a/test/metabase/metabot/tools/autogen_dashboard_test.clj b/test/metabase/metabot/tools/autogen_dashboard_test.cljindex 85c6bd98290..c41929fb471 100644--- a/test/metabase/metabot/tools/autogen_dashboard_test.clj+++ b/test/metabase/metabot/tools/autogen_dashboard_test.clj@@ -8,13 +8,13 @@[metabase.lib.metadata :as lib.metadata][metabase.metabot.agent.core :as agent][metabase.metabot.context :as metabot.context]- [metabase.metabot.db :as metabot.db][metabase.metabot.scope :as scope][metabase.metabot.tools :as metabot.tools][metabase.metabot.tools.autogen-dashboard :as autogen-dashboard][metabase.metabot.tools.recoverable.common :as recoverable.common][metabase.test :as mt]- [metabase.util.log.capture :as log.capture]))+ [metabase.util.log.capture :as log.capture]+ [metabase.warehouse-schema.db :as warehouse-schema.db]))(defn- invoke"Call `create_autogenerated_dashboard` with `source` the way the agent loop does, in a conversation that holds@@ -310,6 +310,6 @@(deftest unexpected-error-test(testing "an error that no one declared ends the turn"- (mt/with-dynamic-fn-redefs [metabot.db/table (fn [_] (throw (ex-info "boom" {})))]+ (mt/with-dynamic-fn-redefs [warehouse-schema.db/table (fn [_] (throw (ex-info "boom" {})))](is (= {:class :unrecoverable :code :internal}(:error (invoke {:table_id 1})))))))diff --git a/test/metabase/metabot/tools/construct_representations_test.clj b/test/metabase/metabot/tools/construct_representations_test.cljindex a967923042d..b77546b8652 100644--- a/test/metabase/metabot/tools/construct_representations_test.clj+++ b/test/metabase/metabot/tools/construct_representations_test.clj@@ -41,6 +41,7 @@[metabase.models.serialization.resolve.mp :as resolve.mp][metabase.permissions.core :as perms][metabase.permissions.models.permissions-group :as perms-group]+ [metabase.queries.db :as queries.db][metabase.query-processor.core :as qp][metabase.query-processor.middleware.add-implicit-clauses :as qp.add-implicit-clauses][metabase.test :as mt]@@ -1532,12 +1533,12 @@"stages" [{"lib/type" "mbql.stage/mbql" "source-card" card-id}]})(defn- with-stubbed-card!- "Run `f` with `metabot.db/card` serving only card 500, and `api/read-check` bound to+ "Run `f` with `queries.db/card` serving only card 500, and `api/read-check` bound to`read-check`. Stubs the model lookup rather than the content store: the numeric`source-card` branch resolves the database id straight off the card row, before anymetadata provider or resolver exists."[read-check f]- (mt/with-dynamic-fn-redefs [metabot.db/card (fn [id] (when (= id 500) {:id 500 :database_id 1}))+ (mt/with-dynamic-fn-redefs [queries.db/card (fn [id] (when (= id 500) {:id 500 :database_id 1}))api/read-check read-check](f)))diff --git a/test/metabase/metabot/tools/util_test.clj b/test/metabase/metabot/tools/util_test.cljindex eb64c4eea61..b427ebb4b42 100644--- a/test/metabase/metabot/tools/util_test.clj+++ b/test/metabase/metabot/tools/util_test.clj@@ -283,9 +283,9 @@:model/Table {active-table-id :id} {:db_id db-id, :name "active_table", :active true, :visibility_type nil}:model/Table {inactive-table-id :id} {:db_id db-id, :name "inactive_table", :active false, :visibility_type nil}](mt/with-current-user (mt/user->id :crowberto)- (is (= active-table-id (:id (metabot.tools.util/get-table active-table-id :db_id))))+ (is (= active-table-id (:id (metabot.tools.util/get-table active-table-id))))(is (thrown? clojure.lang.ExceptionInfo- (metabot.tools.util/get-table inactive-table-id :db_id)))))))+ (metabot.tools.util/get-table inactive-table-id)))))))(deftest ^:parallel find-column-by-field-id-test(let [columns [{:id 301 :name "ID"}diff --git a/test/metabase/session/api_test.clj b/test/metabase/session/api_test.cljindex 0e3a7280251..fe6041345fd 100644--- a/test/metabase/session/api_test.clj+++ b/test/metabase/session/api_test.clj@@ -581,7 +581,7 @@(mt/with-temp [:model/User user {};; the pre-existing session hangs off a different identity, so last_used_at on the;; password identity below is nil until the reset itself touches it- :model/AuthIdentity _ {:user_id (:id user) :provider "google" :metadata {:sso_source "google"}}]+ :model/AuthIdentity _ {:user_id (:id user) :provider "google"}](auth-identity/set-password! (:id user) "password")(let [stale-session (auth-identity/create-session-with-auth-tracking!user