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
Revert "Select models by id through their module's db fn" (#85839)
Alexander Polyankin9c0007c06594
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 65491ec1bd9..9235255485d 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -118,8 +118,7 @@usersutilwarehouse-schema-overlay- warehouses- warehouses.schema}+ warehouses}:model-exports #{:model/Action :model/ImplicitAction :model/QueryAction}:model-imports #{:model/Card:model/Collection@@ -148,7 +147,7 @@permissionspublic-sharingutil}- :model-imports #{:model/Action :model/Card}}+ :model-imports #{:model/Action :model/Card :model/Database}}activity-feed{:team "UX West"@@ -158,17 +157,13 @@:uses #{apibatch-processingcollections- dashboards- documentseventslib.schemamodelspermissions- queriesutilutil.config- warehouse-schema-overlay- warehouses.schema}+ warehouse-schema-overlay}:model-imports #{:model/Card:model/Collection:model/Dashboard@@ -402,7 +397,7 @@task.historytracingutil- warehouses.schema}+ warehouse-schema-overlay}:model-exports #{:model/AuditLog}:model-imports #{:model/ApiKey:model/Card@@ -440,7 +435,6 @@lib.schemamodelspremium-features- queriesquery-permissionsutil}:model-exports #{:model/ViewLog}@@ -529,7 +523,6 @@channel{:team "Gadget":api #{metabase.channel.core- metabase.channel.dbmetabase.channel.emailmetabase.channel.email.messagesmetabase.channel.init@@ -570,11 +563,12 @@tilestimelineutil- util.config- warehouses}+ util.config}:model-exports #{:model/Channel :model/ChannelTemplate}- :model-imports #{:model/DashboardCard+ :model-imports #{:model/Dashboard+ :model/DashboardCard:model/DashboardTab+ :model/Database:model/PulseChannel:model/User}}@@ -622,7 +616,6 @@:api #{metabase.collections.childrenmetabase.collections.coremetabase.collections.curation- metabase.collections.dbmetabase.collections.initmetabase.collections.models.collectionmetabase.collections.models.collection.root@@ -695,9 +688,7 @@:uses #{analyticsapichannel- documentsevents- explorationsliblib.schemamodels@@ -778,7 +769,6 @@{:team "UX West":api #{metabase.dashboards.autoplacemetabase.dashboards.constants- metabase.dashboards.dbmetabase.dashboards.initmetabase.dashboards.models.dashboardmetabase.dashboards.models.dashboard-card@@ -859,7 +849,6 @@query-processorrequestrevisions- usersutilxrays}:model-imports #{:model/Action@@ -902,7 +891,6 @@syncutilwarehouse-schema-overlay- warehouseswarehouses.schema}:model-imports #{:model/Database:model/Dimension@@ -924,7 +912,6 @@{:team "UX West":api #{metabase.documents.apimetabase.documents.core- metabase.documents.dbmetabase.documents.initmetabase.documents.prose-mirrormetabase.documents.schema}@@ -934,7 +921,6 @@audit-app.view-logbatch-processingcollections- dashboardseventsliblib.be@@ -950,7 +936,7 @@settingsstalenessutil- warehouses.schema}+ warehouse-schema-overlay}:model-exports #{:model/Document}:model-imports #{:model/Card:model/Collection@@ -1075,6 +1061,7 @@util}:model-imports #{:model/Card:model/Dashboard+ :model/DashboardCard:model/EmbeddingSdkReact18Host:model/EmbeddingTheme}}@@ -1098,11 +1085,7 @@explorations{:team "UX West"- :api #{metabase.explorations.api- metabase.explorations.core- metabase.explorations.db- metabase.explorations.init- metabase.explorations.schema}+ :api #{metabase.explorations.api metabase.explorations.core metabase.explorations.init metabase.explorations.schema}:uses #{analyticsanalytics.interfaceapi@@ -1128,7 +1111,6 @@query-processorrequestsearch- segmentssettingstasktask.history@@ -1215,7 +1197,6 @@{:team "UX West":api #{metabase.indexed-entities.apimetabase.indexed-entities.core- metabase.indexed-entities.dbmetabase.indexed-entities.init}:uses #{analyticsapi@@ -1224,13 +1205,12 @@lib.schemamodelspermissions- queriesquery-processorsearchsynctaskutil}- :model-exports #{:model/ModelIndexValue}+ :model-exports #{:model/ModelIndex :model/ModelIndexValue}:model-imports #{:model/Card :model/Collection}}interestingness@@ -1340,12 +1320,10 @@lib.metadatalib.schemalib.types- queriessettingsutil- warehouse-schema-overlay- warehouses.schema}- :model-imports #{:model/Field}}+ warehouse-schema-overlay}+ :model-imports #{:model/Card :model/Field :model/Table}}lib.schema{:team "Querying Platform"@@ -1475,6 +1453,7 @@:model/Field:model/Measure:model/NativeQuerySnippet+ :model/Notification:model/Pulse:model/Segment:model/Table@@ -1508,7 +1487,7 @@measures{:team "Graphy"- :api #{metabase.measures.api metabase.measures.db metabase.measures.schema}+ :api #{metabase.measures.api metabase.measures.schema}:uses #{apicollectionsevents@@ -1563,7 +1542,6 @@audit-appchannelcollections- dashboardsdata-appsdocumentsdriver@@ -1576,7 +1554,6 @@lib.belib.metadatalib.schema- measuresmetabot.llmmetabot.slackbotmetrics@@ -1594,7 +1571,6 @@requestsearchsearch.entity-retrieval- segmentsserversettingssql-tools@@ -1603,12 +1579,10 @@tasktimelinetransforms- usersutilutil.configwarehouse-schema-overlaywarehouses- warehouses.schemaxrays}:model-exports #{:model/AiUsageLog:model/Metabot@@ -1663,6 +1637,7 @@sso.auth-identityutil}:model-imports #{:model/Card+ :model/Collection:model/Dashboard:model/DashboardCard:model/DashboardTab@@ -1703,9 +1678,11 @@startuputilutil.config- warehouse-schema-overlay- warehouses}- :model-imports #{:model/Card :model/Field :model/Table}}+ warehouse-schema-overlay}+ :model-imports #{:model/Card+ :model/Database+ :model/Field+ :model/Table}}metabot.slackbot{:team "Metabot"@@ -1723,7 +1700,6 @@metabotmetabot.llmpermissions- queriesquery-processorrequestserver@@ -1732,7 +1708,7 @@systemuploadutil}- :model-imports #{:model/AuthIdentity :model/MetabotMessage}}+ :model-imports #{:model/AuthIdentity :model/Card :model/MetabotMessage}}metrics{:team "UX West"@@ -1747,18 +1723,15 @@lib.metadatalib.metriclib.schema- measuresmodelsparameterspermissions- queriesquery-processorrequestserverutil- warehouse-schema-overlay- warehouses.schema}- :model-imports #{:model/Card :model/Field}}+ warehouse-schema-overlay}+ :model-imports #{:model/Card :model/Field :model/Measure}}mfa{:team "Security Engineering"@@ -1894,7 +1867,6 @@:api #{metabase.notification.apimetabase.notification.cardmetabase.notification.core- metabase.notification.dbmetabase.notification.initmetabase.notification.modelsmetabase.notification.payload.core}@@ -1936,6 +1908,7 @@:model-imports #{:model/Card:model/Channel:model/ChannelTemplate+ :model/Dashboard:model/DashboardCard:model/DashboardTab:model/TaskHistory@@ -1979,7 +1952,6 @@lib.schemamodelsparameters.schema- queriesquery-processorutilutil.classloader@@ -2162,7 +2134,6 @@app-dbchannelcollections- dashboardsdriverembeddingevents@@ -2173,13 +2144,11 @@parameters.schemapermissionspremium-features- queriesquery-processorrequesttasktask.historytracing- usersutilutil.classloaderutil.config@@ -2201,9 +2170,8 @@{:team "Graphy":api #{metabase.queries.card-schemametabase.queries.core- metabase.queries.dbmetabase.queries.init- metabase.queries.models.query+ metabase.queries.models.query ; TODO FIXMEmetabase.queries.schema}:uses #{analyticsanalytics.interface@@ -2244,7 +2212,6 @@util.configutil.graphwarehouse-schema-overlay- warehouseswarehouses.schema}:model-exports #{:model/Card:model/ParameterCard@@ -2302,6 +2269,7 @@:model/Collection:model/Dashboard:model/Database+ :model/StoredResult:model/StoredResultUse:model/Table}}@@ -2316,7 +2284,6 @@lib.schemamodelspermissions- queriesquery-processorrequestutil@@ -2402,12 +2369,13 @@usersutilutil.config- warehouses.schema}+ warehouse-schema-overlay}:model-imports #{:model/Card:model/DashboardCardSeries:model/Database:model/QueryCache- :model/QueryExecution}}+ :model/QueryExecution+ :model/Table}}query-processor.cache-backend{:team "Querying Platform"@@ -2627,7 +2595,7 @@segments{:team "Graphy":module-exports #{segments.rest}- :api #{metabase.segments.db metabase.segments.schema}+ :api #{metabase.segments.schema}:uses #{apicollectionslib@@ -2721,7 +2689,6 @@systemtasktracing- usersutilutil.config}:model-exports #{:model/Session}@@ -2784,12 +2751,12 @@apiappearanceevents+ lib.schemarequestsettingssetupsso.auth-identitysystem- usersutil}:model-imports #{:model/User}}@@ -3017,18 +2984,17 @@metabase.tiles.initmetabase.tiles.settings}:uses #{api- dashboardsliblib.belib.legacy-mbqllib.schemaparameters.schemapremium-features- queriesquery-processorsettingsstartup- util}}+ util}+ :model-imports #{:model/Card :model/Dashboard :model/DashboardCard}}timeline{:team "UX West"@@ -3062,7 +3028,6 @@transforms.indexestransforms.inspector}:api #{metabase.transforms.core- metabase.transforms.dbmetabase.transforms.initmetabase.transforms.instrumentationmetabase.transforms.interface@@ -3097,11 +3062,11 @@transforms.feature-gatingtransforms.indexesutil- warehouse-schema-overlay- warehouses- warehouses.schema}+ warehouse-schema-overlay}:model-exports #{:model/Transform+ :model/TransformDagRun:model/TransformJob+ :model/TransformJobRun:model/TransformJobTransformTag:model/TransformRun:model/TransformTag@@ -3144,8 +3109,7 @@synctransforms.indexesutil- warehouse-schema-overlay- warehouses.schema}}+ warehouse-schema-overlay}}transforms.feature-gating{:team "Graphy"@@ -3195,7 +3159,9 @@transforms.baseutil}:model-imports #{:model/Transform+ :model/TransformDagRun:model/TransformJob+ :model/TransformJobRun:model/TransformJobTransformTag:model/TransformRun:model/TransformTag}}@@ -3223,7 +3189,6 @@syncutilwarehouse-schema-overlay- warehouseswarehouses.schema}:model-imports #{:model/Card:model/Database@@ -3264,7 +3229,6 @@{:team "UX West":module-exports #{users.tenants}:api #{metabase.users.core- metabase.users.dbmetabase.users.initmetabase.users.models.usermetabase.users.models.user-parameter-value@@ -3302,7 +3266,6 @@api-scopeappearancecollections- dashboardseventslib.schemamodels@@ -3371,7 +3334,6 @@:module-exports #{warehouses.schemawarehouses.secrets}:api #{metabase.warehouses.core- metabase.warehouses.dbmetabase.warehouses.initmetabase.warehouses.models.databasemetabase.warehouses.schema}@@ -3441,7 +3403,6 @@{: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@@ -3521,10 +3482,11 @@uploadutilwarehouse-schema-overlay- warehouseswarehouses.schemaxrays}- :model-imports #{:model/Dimension+ :model-imports #{:model/Collection+ :model/Database+ :model/Dimension:model/Field:model/FieldValues:model/Table}}@@ -3568,7 +3530,6 @@sync.analyzeutilwarehouse-schema-overlay- warehouseswarehouses.schema}:model-imports #{:model/Card:model/Collection@@ -3576,6 +3537,7 @@:model/DashboardCard:model/Database:model/Field+ :model/ModelIndex:model/Query:model/Revision:model/Segment@@ -3597,10 +3559,11 @@query-processorsyncutil- warehouse-schema-overlay- warehouses- warehouses.schema}- :model-imports #{:model/Field :model/FieldValues}}+ warehouse-schema-overlay}+ :model-imports #{:model/Database+ :model/Field+ :model/FieldValues+ :model/Table}}enterprise/advanced-config{:team "UX West"@@ -3725,9 +3688,9 @@{:team "UX West":api #{metabase-enterprise.billing.api.routes}:uses #{api+ lib.schemapremium-featuresstore-api- usersutil}:model-imports #{:model/User}}@@ -3735,7 +3698,6 @@{:team "UX West":api #{metabase-enterprise.cache.init}:uses #{cache- dashboardslib.schemapremium-featuresquery-processor@@ -3744,6 +3706,7 @@util}:model-imports #{:model/CacheConfig:model/Card+ :model/Dashboard:model/DatabaseRouter:model/Query:model/QueryCache@@ -3775,11 +3738,12 @@:api #{metabase-enterprise.database-replication.api metabase-enterprise.database-replication.init}:uses #{apidriver+ lib.schemapremium-featuressettingsutil- warehouses- enterprise/cloud}}+ enterprise/cloud}+ :model-imports #{:model/Database}}enterprise/cloud.gsheets{:team "Cloud"@@ -3931,14 +3895,14 @@modelspermissionspremium-features- usersutilwarehouse-schema-overlaywarehouses.schema}:model-imports #{:model/AuditLog:model/Collection:model/Dimension- :model/Table}}+ :model/Table+ :model/User}}enterprise/database-routing{:team "UX West"@@ -3968,7 +3932,6 @@app-dbbatch-processingcollections- dashboardsdata-appsdatabase-routingdocuments@@ -3997,7 +3960,6 @@utilutil.graphwarehouse-schema-overlay- warehouses.schemaenterprise/permissions.sandbox}:model-imports #{:model/Action:model/Card@@ -4220,7 +4182,6 @@settingsssosso.auth-identity- usersutilutil.config}:model-imports #{:model/AuthIdentity :model/User}}@@ -4228,7 +4189,8 @@enterprise/native-query-snippets{:team "Graphy":ns-prefix "metabase-enterprise.snippet-collections"- :uses #{models+ :uses #{lib.schema+ modelsnative-query-snippetspermissionspremium-features@@ -4255,14 +4217,14 @@utilwarehouse-schema-overlaywarehouses- warehouses.schemaenterprise/permissions.impersonation}:model-imports #{:model/ApplicationPermissionsRevision:model/ConnectionImpersonation:model/DataPermissions:model/Permissions:model/PermissionsGroupMembership- :model/Sandbox}}+ :model/Sandbox+ :model/Table}}enterprise/permissions.debug{:team "Security Engineering"@@ -4273,12 +4235,10 @@lib.schemamodelspermissions- queriesquery-processor- usersutilwarehouse-schema-overlay}- :model-imports #{:model/Card}}+ :model-imports #{:model/Card :model/User}}enterprise/permissions.impersonation{:team "Security Engineering"@@ -4421,11 +4381,9 @@collectionshealth-inspectorlib.schema- measurespremium-featuressearchsearch.entity-retrieval- segmentstaskutilwarehouse-schema-overlay@@ -4631,7 +4589,6 @@requestsettingssso.auth-identity- usersutil}:model-exports #{:model/Tenant}:model-imports #{:model/Collection :model/User}}@@ -4654,7 +4611,6 @@sql-toolssql-tools.parsingtask- transformstransforms.baseutil}:model-exports #{:model/TransformTest}@@ -4693,9 +4649,11 @@transformstransforms.baseutil- warehouse-schema-overlay- warehouses}- :model-imports #{:model/Field :model/Table :model/Transform}}+ warehouse-schema-overlay}+ :model-imports #{:model/Database+ :model/Field+ :model/Table+ :model/Transform}}enterprise/transforms.python{:team "Graphy"@@ -4721,11 +4679,12 @@transforms.baseutilutil.config- warehouse-schema-overlay- warehouses- warehouses.schema}+ warehouse-schema-overlay}:model-exports #{:model/PythonLibrary}- :model-imports #{:model/Field :model/Table :model/TransformRun}}+ :model-imports #{:model/Database+ :model/Field+ :model/Table+ :model/TransformRun}}enterprise/upload{:team "UX West"@@ -4738,8 +4697,7 @@premium-featuresuploadutil- warehouse-schema-overlay- warehouses.schema}+ warehouse-schema-overlay}: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 9ad58b07633..eb30653cbda 100644--- a/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.clj+++ b/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.clj@@ -13,8 +13,7 @@[metabase.query-processor.core :as qp][metabase.sync.field-values :as sync.field-values][metabase.util :as u]- [metabase.util.queue :as queue]- [metabase.warehouse-schema.db :as warehouse-schema.db])+ [metabase.util.queue :as queue])(:import(java.util.concurrent ArrayBlockingQueue)))@@ -89,7 +88,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 (warehouse-schema.db/table table-id))+ (let [{:keys [db_id]} (api/check-404 (action-v2.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 db1d75f3b4b..0e0ad9ab67d 100644--- a/enterprise/backend/src/metabase_enterprise/action_v2/db.clj+++ b/enterprise/backend/src/metabase_enterprise/action_v2/db.clj@@ -10,6 +10,21 @@[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 eaaf1939a90..85f6074ac20 100644--- a/enterprise/backend/src/metabase_enterprise/action_v2/execute_form.clj+++ b/enterprise/backend/src/metabase_enterprise/action_v2/execute_form.clj@@ -10,8 +10,6 @@[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))@@ -105,10 +103,8 @@row-data]}](when-not table-id(throw (ex-info "Must provide table-id" {:status-code 400})))- (let [table (api/read-check (let [table (warehouse-schema.db/table table-id)]- (when (:active table)- table)))- database (warehouses.db/database (:db_id table))+ (let [table (api/read-check (action-v2.db/active-table table-id))+ database (action-v2.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 317d08b9670..9e9ba0d51c3 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj@@ -73,6 +73,11 @@[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 5b4c852fc1b..7bdfafab2d5 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_config/file/databases.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_config/file/databases.clj@@ -11,8 +11,7 @@[metabase.sync.core :as sync][metabase.util :as u][metabase.util.log :as log]- [metabase.util.quick-task :as quick-task]- [metabase.warehouses.db :as warehouses.db]))+ [metabase.util.quick-task :as quick-task]))(s/def :metabase-enterprise.advanced-config.file.databases.config-file-spec/namestring?)@@ -142,7 +141,7 @@(:is_stub existing) (assoc :is_stub false:initial_sync_status "incomplete")))(when (:is_stub existing)- (sync-if-configured! (warehouses.db/database (:id existing)))))+ (sync-if-configured! (advanced-config.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 6d3f9646c14..a9ccf826173 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_permissions/common.clj@@ -7,7 +7,6 @@[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?@@ -17,7 +16,7 @@:feature :advanced-permissions[instance](let [table (or (:table instance)- (warehouse-schema.db/table (:table_id instance)))]+ (advanced-permissions.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 50d13aa50a0..410e640a766 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_permissions/db.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_permissions/db.clj@@ -9,6 +9,11 @@[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 890d6b6a2f2..3a04a7b1865 100644--- a/enterprise/backend/src/metabase_enterprise/billing/api.clj+++ b/enterprise/backend/src/metabase_enterprise/billing/api.clj@@ -10,7 +10,6 @@[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]@@ -67,7 +66,7 @@using the embedding token and signed in user's email to fetch the billing information."[](let [token (premium-features/premium-embedding-token)- email (:email (users.db/user api/*current-user-id*))+ email (billing.db/user-email 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 e68d9acd16c..51ee5ea0fbc 100644--- a/enterprise/backend/src/metabase_enterprise/billing/db.clj+++ b/enterprise/backend/src/metabase_enterprise/billing/db.clj@@ -2,6 +2,7 @@"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]))@@ -9,3 +10,8 @@"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 3bb28a1f327..2bb3785343d 100644--- a/enterprise/backend/src/metabase_enterprise/cache/db.clj+++ b/enterprise/backend/src/metabase_enterprise/cache/db.clj@@ -147,6 +147,11 @@[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 e710baecc9e..929acce1cde 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,7 +6,6 @@[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]@@ -187,7 +186,7 @@[{:keys [model_id model]}](case model"question" [model_id]- "dashboard" (let [dashboard (-> (dashboards.db/dashboard model_id)+ "dashboard" (let [dashboard (-> (cache.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 1b734ca488b..58b06a10777 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/custom-viz-plugin id))]+ (let [plugin (api/write-check (custom-viz-plugin.db/non-blob-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/custom-viz-plugin id))+ (let [existing (api/write-check (custom-viz-plugin.db/non-blob-plugin id))updates (select-keys body [:enabled])](when (seq updates)(custom-viz-plugin.db/update-plugin! id updates))- (let [result (custom-viz-plugin.db/custom-viz-plugin id)]+ (let [result (custom-viz-plugin.db/non-blob-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/custom-viz-plugin id))+ (let [existing (api/write-check (custom-viz-plugin.db/non-blob-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/custom-viz-plugin id))+ (let [plugin (api/read-check (custom-viz-plugin.db/non-blob-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/custom-viz-plugin id))+ (let [plugin (api/read-check (custom-viz-plugin.db/non-blob-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/custom-viz-plugin id))+ (api/write-check (custom-viz-plugin.db/non-blob-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/custom-viz-plugin id))]+ (let [plugin (api/write-check (custom-viz-plugin.db/non-blob-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/custom-viz-plugin id)]+ (let [result (custom-viz-plugin.db/non-blob-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 ba72bb1a5e7..7967de46de9 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/custom-viz-plugin id))+ (custom-viz-plugin.db/non-blob-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 (:dev_bundle_url (custom-viz-plugin.db/custom-viz-plugin id)))))+ (not-empty (custom-viz-plugin.db/plugin-dev-bundle-url 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 86f6e1c15ac..2c149b59f8c 100644--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.clj+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.clj@@ -7,44 +7,26 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(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])+(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 ^: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`."+(mu/defn non-blob-plugin+ "The CustomVizPlugin with `plugin-id` without its bundle, or nil."[plugin-id :- ms/PositiveInt]- (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)))))+ (t2/select-one non-blob-columns :id plugin-id))(mu/defn non-blob-plugins"Every CustomVizPlugin without its bundle, ordered by display name."[]- (t2/select non-blob-model {:order-by [[:display_name :asc]]}))+ (t2/select non-blob-columns {: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-model :status :active :enabled true {:order-by [[:display_name :asc]]}))+ (t2/select non-blob-columns :status :active :enabled true {:order-by [[:display_name :asc]]}))(mu/defn plugin-by-identifier"The CustomVizPlugin with `identifier`, or nil."@@ -56,6 +38,16 @@[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 c6c2eb5b6cf..ff2993f661c 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,8 +8,7 @@[metabase.models.interface :as mi][metabase.models.serialization :as serdes][methodical.core :as methodical]- [toucan2.core :as t2]- [toucan2.tools.default-fields :as t2.default-fields])+ [toucan2.core :as t2])(:import(java.sql Blob)))@@ -37,8 +36,11 @@(derive :metabase/model)(derive :hook/timestamped?))-(t2.default-fields/define-default-fields :model/CustomVizPlugin- custom-viz-plugin.db/non-blob-columns)+(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])(defmethod mi/can-read? :model/CustomVizPlugin([_instance] (some? api/*current-user-id*))@@ -89,11 +91,6 @@{: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))))@@ -102,7 +99,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/custom-viz-plugin id))+ (custom-viz-plugin.db/non-blob-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 f55f7f9fa55..4a66546d67d 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 :- [:maybe ::data-apps.schema/data-app]- "The ::data-apps.schema/data-app with `data-app-id`, or nil."+(mu/defn data-app+ "The DataApp with `data-app-id` without its bundle, or nil."[data-app-id :- ms/PositiveInt]- (t2/select-one :model/DataApp :id [:auto/param data-app-id]))+ (t2/select-one non-blob-model :id data-app-id))(mu/defn data-app-by-slug"The DataApp named `slug` without its bundle, or nil."@@ -87,6 +87,11 @@[](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]@@ -97,6 +102,11 @@[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 73b49a83691..c891d0d9490 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/group_access.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/group_access.clj@@ -3,7 +3,6 @@[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]@@ -36,7 +35,7 @@(defn- app-collection"The resource collection of `app`, or a 404."[app]- (api/check-404 (some-> (:resource_collection_id app) collections.db/collection)))+ (api/check-404 (some-> (:resource_collection_id app) data-apps.db/resource-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 85f767ad666..d51e0723eec 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,7 +3,6 @@[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]@@ -78,7 +77,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 (some-> collection-id collections.db/collection)]+ (let [collection (data-apps.db/resource-collection collection-id)](when-not (and collection(= "data-apps" (some-> (:namespace collection) name))(= "/" (:location collection))@@ -214,7 +213,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 (:resource_collection_id (data-apps.db/data-app id))]+ (when-let [collection-id (data-apps.db/resource-collection-id 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 be59d8e845e..a707de73f0c 100644--- a/enterprise/backend/src/metabase_enterprise/data_complexity_score/complexity.clj+++ b/enterprise/backend/src/metabase_enterprise/data_complexity_score/complexity.clj@@ -12,7 +12,6 @@[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]))@@ -174,7 +173,7 @@[collection-id](when collection-id(into #{collection-id}- (when-let [root (collections.db/collection collection-id)]+ (when-let [root (data-complexity-score.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 c84470429f2..c5eae3c0024 100644--- a/enterprise/backend/src/metabase_enterprise/data_complexity_score/db.clj+++ b/enterprise/backend/src/metabase_enterprise/data_complexity_score/db.clj@@ -28,6 +28,11 @@[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."[]@@ -73,10 +78,10 @@source :- :string](t2/select-one :model/DataComplexityScore :fingerprint fingerprint :source source {:order-by [[:id :desc]]}))-(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."+(mu/defn score-entry+ "The DataComplexityScore with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/DataComplexityScore :id [:auto/param id]))+ (t2/select-one :model/DataComplexityScore :id 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 e389d79e527..620bc5da350 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/data-complexity-score id))+ (score-with-calculated-at (data-complexity-score.db/score-entry 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 4aaf8cfae28..ebef4c0ec07 100644--- a/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj+++ b/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj@@ -7,11 +7,9 @@[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]))@@ -139,7 +137,7 @@(when (= topic :table-publish){:published_at timestamp:published_by (when user-id- (some-> (users.db/user user-id)+ (some-> (data-studio.db/user-name-and-email user-id)(select-keys [:id :common_name])))})))(api.macros/defendpoint :get "/:id/publishing-info" :- [:maybe PublishingInfo]@@ -172,7 +170,7 @@_query-paramsbody :- ::publish-table-selectors](api/check-data-studio-access)- (let [target-collection (api/check-404 (collections.db/collection (:collection_id body)))+ (let [target-collection (api/check-404 (data-studio.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)@@ -203,7 +201,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 collections.db/collection)+ (run! (comp api/write-check data-studio.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 4f2426664cd..93d7f9829ab 100644--- a/enterprise/backend/src/metabase_enterprise/data_studio/db.clj+++ b/enterprise/backend/src/metabase_enterprise/data_studio/db.clj@@ -86,6 +86,11 @@[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]@@ -95,6 +100,11 @@: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 3aee9cebb13..e6c8c78968a 100644--- a/enterprise/backend/src/metabase_enterprise/database_replication/api.clj+++ b/enterprise/backend/src/metabase_enterprise/database_replication/api.clj@@ -3,6 +3,7 @@[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]@@ -12,8 +13,7 @@[metabase.premium-features.core :as premium-features][metabase.util :as u][metabase.util.log :as log]- [metabase.util.malli.schema :as ms]- [metabase.warehouses.db :as warehouses.db])+ [metabase.util.malli.schema :as ms])(: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 (warehouses.db/database database-id)+ (let [database (database-replication.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 (warehouses.db/database database-id)+ (let [database (database-replication.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.cljnew file mode 100644index 00000000000..c01168868d7--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/database_replication/db.clj@@ -0,0 +1,12 @@+(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 4bb3b575d80..1ed6d05b2a3 100644--- a/enterprise/backend/src/metabase_enterprise/database_routing/api.clj+++ b/enterprise/backend/src/metabase_enterprise/database_routing/api.clj@@ -10,8 +10,7 @@[metabase.settings.core :as setting][metabase.util :as u][metabase.util.malli.schema :as ms]- [metabase.warehouses.core :as warehouses]- [metabase.warehouses.db :as warehouses.db]))+ [metabase.warehouses.core :as warehouses]));; 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@@ -40,7 +39,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} (warehouses.db/database router_database_id)]+ (let [{:keys [engine auto_run_queries is_on_demand] :as router-db} (database-routing.db/database router_database_id)](if-let [invalid-destinations (->> destinations(keep (fn [{details :details n :name}](try@@ -75,7 +74,7 @@(defn- delete-router![db-id]- (let [db (warehouses.db/database db-id)]+ (let [db (database-routing.db/database db-id)](events/publish-event! :event/database-update {:object db:previous-object db:user-id api/*current-user-id*@@ -84,7 +83,7 @@(defn- create-or-update-router![db-id user-attribute]- (let [db (warehouses.db/database db-id)]+ (let [db (database-routing.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@@ -109,7 +108,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 (warehouses.db/database id)]+ (let [db (database-routing.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 c65811aab82..c984737f513 100644--- a/enterprise/backend/src/metabase_enterprise/database_routing/db.clj+++ b/enterprise/backend/src/metabase_enterprise/database_routing/db.clj@@ -7,6 +7,11 @@[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 23b0eecc53d..767f0c2597b 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/db.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/db.clj@@ -679,6 +679,11 @@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]]@@ -689,6 +694,16 @@[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 fc3a2f697a9..db82d3d3229 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/hooks.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/hooks.clj@@ -11,12 +11,10 @@[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)@@ -120,11 +118,10 @@(case model(:model/DashboardCard :model/DashboardTab) [:dashboard (:dashboard_id row)]:model/DashboardCardSeries [:dashboard (some-> (:dashboardcard_id row)- dashboards.db/dashboard-card- :dashboard_id)]+ dependencies.db/dashcard-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) warehouse-schema.db/field :table_id)]+ :model/FieldUserSettings [:table (some-> (:field_id row) dependencies.db/field-table-id)]nil))(def ^:private part-columns@@ -172,7 +169,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) warehouse-schema.db/field :table_id)]+ (when-let [table-id (some-> (:field_id row) dependencies.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 45087146191..d6a2c2690ad 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/result_metadata.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/result_metadata.clj@@ -14,7 +14,6 @@[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]@@ -129,7 +128,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 (queries.db/card card-id)+ card (dependencies.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 c7c81483779..ab5b3e493f9 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/connection-impersonation id))+ (api/check-404 (impersonation.db/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 a409dcd0422..4dbd0765ddb 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 connection-impersonation :- [:maybe ::impersonation.schema/connection-impersonation]- "The ::impersonation.schema/connection-impersonation with `impersonation-id`, or nil."+(mu/defn impersonation+ "The ConnectionImpersonation with `impersonation-id`, or nil."[impersonation-id :- ms/PositiveInt]- (t2/select-one :model/ConnectionImpersonation :id [:auto/param impersonation-id]))+ (t2/select-one :model/ConnectionImpersonation :id 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 b03791f2951..9697de137e4 100644--- a/enterprise/backend/src/metabase_enterprise/library/db.clj+++ b/enterprise/backend/src/metabase_enterprise/library/db.clj@@ -37,6 +37,11 @@: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 886108dbd55..18d0b1e3a76 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.collections.db :as collections.db]+ [metabase-enterprise.library.db :as library.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 (:type (collections.db/collection collection-id))]+ (let [collection-type (library.db/collection-type 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) (:type (collections.db/collection parent-id)))))+ (not= (:type collection) (library.db/collection-type 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 96dd8785c6c..42bddcbe804 100644--- a/enterprise/backend/src/metabase_enterprise/mcp/db.clj+++ b/enterprise/backend/src/metabase_enterprise/mcp/db.clj@@ -19,6 +19,11 @@[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 f37e4523c99..d466cf565b5 100644--- a/enterprise/backend/src/metabase_enterprise/mcp/usage.clj+++ b/enterprise/backend/src/metabase_enterprise/mcp/usage.clj@@ -8,10 +8,9 @@best-effort: a failure is logged and swallowed so logging never fails the MCP request andadds negligible latency."(:require- [metabase-enterprise.mcp.db :as ee.mcp.db]+ [metabase-enterprise.mcp.db :as 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]))@@ -53,7 +52,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 (ee.mcp.db/session-log-exists? session-id)))+ (not (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@@ -62,7 +61,7 @@pii (select-keys (analytics/pii-fields-from {:user-agent user-agent:ip-address ip-address})[:user_agent :ip_address])]- (ee.mcp.db/insert-session-log!+ (mcp.db/insert-session-log!(merge {:id session-id:user_id user-id:tenant_id tenant-id@@ -79,7 +78,7 @@[session-id](try(when session-id- (ee.mcp.db/end-session-log! session-id))+ (mcp.db/end-session-log! session-id))(catch Throwable e(log/warnf "Failed to record MCP session end: %s" (ex-message e)))))@@ -97,8 +96,7 @@:client_version (truncate (:version client-info) client-version-max-length)}session-id- (some-> (mcp.db/mcp-session-log session-id)- (select-keys [:client_name :client_version]))+ (mcp.db/session-client-identity session-id):else nil))@@ -120,7 +118,7 @@pii (select-keys (analytics/pii-fields-from {:user-agent user-agent:ip-address ip-address})[:user_agent :ip_address :sanitized_user_agent])]- (ee.mcp.db/insert-tool-call-log!+ (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 4cdf4e03b42..db12962ae89 100644--- a/enterprise/backend/src/metabase_enterprise/metabot_analytics/conversations.clj+++ b/enterprise/backend/src/metabase_enterprise/metabot_analytics/conversations.clj@@ -9,7 +9,6 @@[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]@@ -121,7 +120,7 @@(defn fetch-conversation-detail"Fetch a conversation detail or throw a 404."[conversation-id]- (let [conversation (metabot.db/metabot-conversation conversation-id)]+ (let [conversation (metabot-analytics.db/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 1df92d3b741..8f126d255da 100644--- a/enterprise/backend/src/metabase_enterprise/metabot_analytics/db.clj+++ b/enterprise/backend/src/metabase_enterprise/metabot_analytics/db.clj@@ -11,6 +11,11 @@[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 a11bcefb830..a6d82efc4e6 100644--- a/enterprise/backend/src/metabase_enterprise/mfa/core.clj+++ b/enterprise/backend/src/metabase_enterprise/mfa/core.clj@@ -4,6 +4,7 @@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]@@ -11,7 +12,6 @@[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 (:email (users.db/user user-id))]+ user-email (mfa.db/user-email 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 6662c86bfed..8e9981cb6d7 100644--- a/enterprise/backend/src/metabase_enterprise/mfa/db.clj+++ b/enterprise/backend/src/metabase_enterprise/mfa/db.clj@@ -58,6 +58,16 @@[: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 a20323a2b97..2b31b4cc7bb 100644--- a/enterprise/backend/src/metabase_enterprise/mfa/management.clj+++ b/enterprise/backend/src/metabase_enterprise/mfa/management.clj@@ -23,7 +23,6 @@[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]@@ -72,7 +71,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 (:email (users.db/user user-id))]+ (when-let [user-email (mfa.db/user-email user-id)](when-let [user-info (sso/find-user user-email)](sso/verify-password user-info password)))(catch Exception e@@ -127,7 +126,7 @@(fn [](or (enrollment/confirm-enrollment! api/*current-user-id* code)(throw (invalid-code-ex)))))- user (users.db/user api/*current-user-id*)]+ user (mfa.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}))@@ -145,7 +144,7 @@(when-not (verification/verify-attempt! api/*current-user-id* code nil)(throw (invalid-code-ex)))(enrollment/disable! api/*current-user-id*))))- (let [user (users.db/user api/*current-user-id*)]+ (let [user (mfa.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)@@ -187,7 +186,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 (users.db/user user-id)]+ (let [user (mfa.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 917530c3220..dc793fbb982 100644--- a/enterprise/backend/src/metabase_enterprise/permission_debug/db.clj+++ b/enterprise/backend/src/metabase_enterprise/permission_debug/db.clj@@ -8,6 +8,16 @@[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 d081450b0be..9b09b8b6f2a 100644--- a/enterprise/backend/src/metabase_enterprise/permission_debug/impl.clj+++ b/enterprise/backend/src/metabase_enterprise/permission_debug/impl.clj@@ -17,9 +17,7 @@[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]))@@ -67,7 +65,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? (:is_superuser (users.db/user user-id))]+ (let [user-is-superuser? (permission-debug.db/user-superuser? user-id)](if user-is-superuser?::is-superuseraction-type))))@@ -200,7 +198,7 @@[{:keys [user-id model-id] :as debug-info} :- DebuggerArguments](merge-permission-check(debug-permissions (assoc debug-info :action-type :card/read))- (let [card (queries.db/card model-id)+ (let [card (permission-debug.db/card model-id)blocked-by-group (check-table-permissions user-id card{:perms/view-data :blocked}{:perms/view-data :legacy-no-self-service})]@@ -219,7 +217,7 @@[{:keys [user-id model-id] :as debug-info} :- DebuggerArguments](merge-permission-check(debug-permissions (assoc debug-info :action-type :card/query))- (let [card (queries.db/card model-id)+ (let [card (permission-debug.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 6a5b284dbaf..565faf77ece 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj@@ -10,7 +10,6 @@[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]@@ -39,7 +38,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) collections.db/collection :namespace))}))))))+ (some-> (u/id collection) remote-sync.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 64506d751e8..a1b4b2d624b 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj@@ -400,6 +400,11 @@[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]@@ -446,6 +451,12 @@[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."[]@@ -745,16 +756,21 @@[](t2/delete! :model/RemoteSyncObject))-(mu/defn remote-sync-task :- [:maybe ::remote-sync.schema/remote-sync-task]- "The ::remote-sync.schema/remote-sync-task with `task-id`, or nil."+(mu/defn task+ "The RemoteSyncTask with `task-id`, or nil."[task-id :- ms/PositiveInt]- (t2/select-one :model/RemoteSyncTask :id [:auto/param task-id]))+ (t2/select-one :model/RemoteSyncTask 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 ed48a26285a..df3550bcc76 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj@@ -24,7 +24,6 @@[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]@@ -474,8 +473,7 @@(defn- hydrate-collection-details"Hydrates details for a Collection."[id]- (when-let [collection (collections.db/collection id)]- {:name (:name collection) :collection_id (:id collection)}))+ (remote-sync.db/collection-name-and-id id))(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 83eab1fa7b2..e557c74a344 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/remote-sync-task task-id)]+ (let [task (remote-sync.db/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/remote-sync-task task-id) remote-sync.task/running?)+ (when (some-> (remote-sync.db/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 153c997d1d8..76fd6574c65 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? (:cancelled (remote-sync.db/remote-sync-task task-id)))+ (when (true? (remote-sync.db/task-cancelled? 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 e3134b31936..d7cdb5be96e 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj@@ -17,7 +17,6 @@[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]@@ -879,7 +878,7 @@(and (library-synced-object? spec object)(or (nil? collection-id)(= collections/data-actions-ns- (some-> (collections.db/collection collection-id) :namespace keyword))))))+ (some-> (remote-sync.db/collection-namespace collection-id) keyword))))))(defmethod check-eligibility-by-type :collection[{:keys [eligibility] :as spec} object]@@ -888,7 +887,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 (:namespace (collections.db/collection collection-id))}))]+ (data-apps-namespace-collection? {:namespace (remote-sync.db/collection-namespace 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 a6b612e22f0..5194525bd8b 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/api.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/api.clj@@ -11,7 +11,6 @@[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]))@@ -104,7 +103,7 @@[:transform_tag_ids {:optional true} [:maybe [:sequential pos-int?]]]]](api/check-superuser)(let [user-id api/*current-user-id*- card (api/check-404 (queries.db/card card_id))+ card (api/check-404 (replacement.db/card card_id))transform (transforms/create-transform!{:name transform_name:source {:type :query@@ -147,14 +146,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/replacement-run id)+ (or (replacement.db/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/replacement-run id)]+ (let [run (replacement.db/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 2072fe768c2..a657fc412e2 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 replacement-run :- [:maybe ::replacement.schema/replacement-run]- "The ::replacement.schema/replacement-run with `run-id`, or nil."+(mu/defn run+ "The ReplacementRun with `run-id`, or nil."[run-id :- ms/PositiveInt]- (t2/select-one :model/ReplacementRun :id [:auto/param run-id]))+ (t2/select-one :model/ReplacementRun :id run-id))(mu/defn runs"The ReplacementRuns, newest first, restricted to the `is-active` flag when given."@@ -33,6 +33,11 @@[](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]@@ -92,11 +97,21 @@[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]@@ -109,24 +124,44 @@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@@ -144,6 +179,11 @@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 1a37bff8966..ab183a99c9e 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/field_refs.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/field_refs.clj@@ -3,15 +3,10 @@[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.queries.db :as queries.db]- [metabase.segments.db :as segments.db]- [metabase.source-swap.core :as source-swap]- [metabase.transforms.db :as transforms.db]))+ [metabase.source-swap.core :as source-swap]))(set! *warn-on-reflection* true)@@ -165,11 +160,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 (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)+ :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)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 541de50a04a..1d270b899e1 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/replacement-run run-id))))+ (not (:is_active (replacement.db/run-active-flag 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 fdcade76250..6fae87f12bf 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/runner.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/runner.clj@@ -12,13 +12,10 @@[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)@@ -113,8 +110,8 @@(count all-transitive-dependents))) ;; phase 2: swap(let [db-id (case (first old-source)- :card (:database_id (queries.db/card (second old-source)))- :table (:db_id (warehouse-schema.db/table (second old-source))))+ :card (replacement.db/card-database-id (second old-source))+ :table (replacement.db/table-database-id (second old-source)))batch-size 500];; phase 1: Upgrade field refs for ALL transitive dependents(doseq [batch (partition-all batch-size all-transitive-dependents)]@@ -175,7 +172,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 (queries.db/card card-id)+ (let [card (replacement.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)]@@ -195,7 +192,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 (transforms.db/transform transform-id)+ (let [transform (or (replacement.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 f15d80cbb49..b56ece1d476 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/source_check.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/source_check.clj@@ -6,12 +6,10 @@[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.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util.malli :as mu]))(set! *warn-on-reflection* true)@@ -46,8 +44,8 @@[entity-type :- ::replacement.schema/source-entity-typeentity-id :- ::replacement.schema/source-entity-id](case entity-type- :card (:database_id (queries.db/card entity-id))- :table (:db_id (warehouse-schema.db/table entity-id))))+ :card (replacement.db/card-database-id entity-id)+ :table (replacement.db/table-database-id 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 792dd5e9396..90906469119 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/source_swap.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/source_swap.clj@@ -16,16 +16,11 @@[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.segments.db :as segments.db]- [metabase.source-swap.core :as source-swap]- [metabase.transforms.db :as transforms.db]))+ [metabase.source-swap.core :as source-swap]))(set! *warn-on-reflection* true)@@ -180,7 +175,7 @@(replacement.db/update-dashboard! (:id dashboard) {:parameters parameters'}))(when (or any-dashcard-changed? params-changed?)(events/publish-event!- :event/dashboard-update {:object (dashboards.db/dashboard (:id dashboard))+ :event/dashboard-update {:object (replacement.db/dashboard (:id dashboard)):user-id api/*current-user-id*}))))(defn swap-source!@@ -191,11 +186,11 @@([[entity-type entity-id :as entity-ref] old-source new-source](swap-source! entity-ref(case entity-type- :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)+ :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)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 9a3bcfa4aa8..382d0fbe032 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj@@ -2,6 +2,7 @@(: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]@@ -11,7 +12,6 @@[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 (warehouse-schema.db/table id))+ (let [table (api/check-404 (sandbox.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 4ee93d117bf..5e5318edc56 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 :- [:maybe ::sandbox.schema/sandbox]- "The ::sandbox.schema/sandbox with `sandbox-id`, or nil."+(mu/defn sandbox+ "The Sandbox with `sandbox-id`, or nil."[sandbox-id :- ::lib.schema.id/sandbox]- (t2/select-one :model/Sandbox :id [:auto/param sandbox-id]))+ (t2/select-one :model/Sandbox :id sandbox-id))(mu/defn sandboxes"Every Sandbox, in ID order."@@ -150,6 +150,11 @@[: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?`."@@ -187,6 +192,11 @@[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 84da0bab360..9cee0d59b82 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/models/sandbox.clj@@ -19,7 +19,6 @@[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]@@ -136,7 +135,7 @@;; not all sandboxes have Cards(when card-id;; not all Cards have saved result metadata- (when-let [result-metadata (not-empty (:result_metadata (queries.db/card card-id)))]+ (when-let [result-metadata (not-empty (sandbox.db/card-result-metadata card-id))](check-columns-match-table table-id result-metadata))))([table-id :- ::lib.schema.id/table@@ -195,7 +194,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 (:result_metadata (queries.db/card card-id))]+ (let [original-result-metadata (sandbox.db/card-result-metadata 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 9d186849a23..229092cf05c 100644--- a/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/db.clj+++ b/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/db.clj@@ -55,6 +55,16 @@[:= :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 ddf0fa28c99..2da0be24d66 100644--- a/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/reconcile.clj+++ b/enterprise/backend/src/metabase_enterprise/search/entity_retrieval/reconcile.clj@@ -29,9 +29,7 @@[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]@@ -206,8 +204,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")- (:table_id (measures.db/measure entity-local-id))- (:table_id (segments.db/segment entity-local-id)))]+ (entity-retrieval.db/measure-table-id entity-local-id)+ (entity-retrieval.db/segment-table-id 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 29697fb052a..a4bf059c3c1 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 security-advisory :- [:maybe ::security-center.schema/security-advisory]- "The ::security-center.schema/security-advisory with `id`, or nil."+(mu/defn advisory+ "The SecurityAdvisory with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/SecurityAdvisory :id [:auto/param id]))+ (t2/select-one :model/SecurityAdvisory :id 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 b5672e68650..0768d9430b4 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/security-advisory (:id advisory))+ (-> (security-center.db/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.cljnew file mode 100644index 00000000000..2957a93b0ea--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/snippet_collections/db.clj@@ -0,0 +1,14 @@+(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 cb2810dc067..6b5a55c38eb 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? (native-query-snippets.db/native-query-snippet id))))+ (can-read? (snippet-collections.db/snippet-with-collection-id 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? (native-query-snippets.db/native-query-snippet id))))+ (can-write? (snippet-collections.db/snippet-with-collection-id 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 980836d947d..ae3d303e0ef 100644--- a/enterprise/backend/src/metabase_enterprise/sso/db.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/db.clj@@ -2,16 +2,10 @@"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.@@ -40,6 +34,12 @@[: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 54faad2346e..b12547ba1d9 100644--- a/enterprise/backend/src/metabase_enterprise/sso/models/relay_state.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/models/relay_state.clj@@ -75,9 +75,7 @@retried callback doesn't burn the key."[key](when (relay-state-key? key)- (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))))+ (sso.db/unexpired-relay-state (hash-key key) (t/offset-date-time))))(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 9b12ecd5ccd..8529d70061b 100644--- a/enterprise/backend/src/metabase_enterprise/stale/api.clj+++ b/enterprise/backend/src/metabase_enterprise/stale/api.clj@@ -10,7 +10,6 @@[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]@@ -115,7 +114,7 @@(t/minus (t/local-date) (t/months 6)))collection (if (= id :root)collection/root-collection- (collections.db/collection id))+ (stale.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 e5ad79f7fc3..416f03a9020 100644--- a/enterprise/backend/src/metabase_enterprise/stale/db.clj+++ b/enterprise/backend/src/metabase_enterprise/stale/db.clj@@ -7,6 +7,11 @@[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 a21c1dfc3d8..6c3553d433a 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/support-access-grant-log grant-id)]+ (let [grant (support-access-grants.db/grant 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/support-access-grant-log grant-id)+ (-> (support-access-grants.db/grant 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 817e7e945f5..e52cf47bde5 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 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."+(mu/defn grant+ "The SupportAccessGrantLog with `grant-id`, or nil."[grant-id :- ms/PositiveInt]- (t2/select-one :model/SupportAccessGrantLog :id [:auto/param grant-id]))+ (t2/select-one :model/SupportAccessGrantLog :id grant-id))(mu/defn current-grant"The newest unrevoked SupportAccessGrantLog that has not ended, or nil."@@ -75,6 +75,11 @@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 13d78b776d5..08c480077f2 100644--- a/enterprise/backend/src/metabase_enterprise/support_access_grants/provider.clj+++ b/enterprise/backend/src/metabase_enterprise/support_access_grants/provider.clj@@ -9,7 +9,6 @@[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]@@ -73,7 +72,7 @@{:status-code 400})))(u/prog1 (auth-identity/generate-reset-token user-id)(t2/with-transaction [_]- (let [user (users.db/user user-id)+ (let [user (support-access-grants.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 0bc414fffb6..ee8a77234e3 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/api.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/api.clj@@ -6,7 +6,6 @@[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]@@ -83,13 +82,6 @@[: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@@ -101,11 +93,11 @@tenant-after-update (tenants.db/tenant tenant-id)](when (false? is_active)(tenants.db/deactivate-tenant-users! tenant-id)- (some-> (collection-with-archived-state (:tenant_collection_id tenant-before-update) false)+ (some-> (tenants.db/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-> (collection-with-archived-state (:tenant_collection_id tenant-before-update) true)+ (some-> (tenants.db/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 ddf006af2db..00aaacada06 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 (:slug (tenants.db/tenant tenant_id))+ :user/tenant-slug (tenants.db/tenant-slug 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 (:slug (tenants.db/tenant tenant_id))+ :user/tenant-slug (tenants.db/tenant-slug 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 b06eb3c9b8d..a313550118b 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/db.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/db.clj@@ -10,16 +10,26 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(mu/defn tenant :- [:maybe ::tenants.schema/tenant]- "The ::tenants.schema/tenant with `tenant-id`, or nil."+(mu/defn tenant+ "The Tenant with `tenant-id`, or nil."[tenant-id :- ms/PositiveInt]- (t2/select-one :model/Tenant :id [:auto/param tenant-id]))+ (t2/select-one :model/Tenant :id 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`."@@ -99,6 +109,17 @@(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 b0330bd1dc7..51b5762f6ef 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/models.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/models.clj@@ -7,7 +7,6 @@[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]@@ -89,8 +88,8 @@:feature :tenants[user-or-id](into []- (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))]+ (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)](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 8fd47881d67..d99a8ef622f 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 ::transform-testing.schema/transform-test with `id`, or nil."+ "The TransformTest with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/TransformTest :id [:auto/param id]))+ (t2/select-one :model/TransformTest :id id))(mu/defn insert-transform-test! :- ::transform-testing.schema/transform-test"Insert the TransformTest `transform-test` and return the inserted instance."@@ -112,6 +112,11 @@[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 a187dc4ed24..64da975f4d9 100644--- a/enterprise/backend/src/metabase_enterprise/transform_testing/runner.clj+++ b/enterprise/backend/src/metabase_enterprise/transform_testing/runner.clj@@ -37,7 +37,6 @@[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]))@@ -120,7 +119,7 @@(defn- testable-transform"The transform `transform-id` names, if it is one a test can run."[transform-id]- (let [transform (api/check-404 (transforms.db/transform transform-id))]+ (let [transform (api/check-404 (transform-testing.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 6dc08d4e9b9..cb1706ce1c5 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_inspector/context.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_inspector/context.clj@@ -19,8 +19,7 @@[metabase.util.honey-sql-2 :as h2x][metabase.util.log :as log][metabase.util.malli :as mu]- [metabase.util.malli.registry :as mr]- [metabase.warehouses.db :as warehouses.db]))+ [metabase.util.malli.registry :as mr]))(set! *warn-on-reflection* true)@@ -57,7 +56,7 @@transforms-base.u/massage-sql-queryqp.preprocess/preprocess)db-id (transforms-base.u/transform-source-database transform)- driver (keyword (:engine (warehouses.db/database db-id)))+ driver (keyword (transforms-inspector.db/database-engine db-id))deps (driver/native-query-deps driver query)table-ids (keep :table deps)](table-ids->source-info table-ids))@@ -322,7 +321,7 @@:target target-info:db-id db-id:driver (or (:driver query-info)- (keyword (:engine (warehouses.db/database db-id))))+ (keyword (transforms-inspector.db/database-engine 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 64b24037406..1c0c94f98c5 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_inspector/db.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_inspector/db.clj@@ -12,6 +12,11 @@[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 49bd4278a30..56d46f840fc 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_inspector/query_analysis.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_inspector/query_analysis.clj@@ -12,6 +12,7 @@;; 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]@@ -20,8 +21,7 @@[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.warehouses.db :as warehouses.db]))+ [metabase.util.log :as log]))(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 (:engine (warehouses.db/database db-id)))+ driver (keyword (transforms-inspector.db/database-engine 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 d90f70ec78f..7b3220bf549 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_python/db.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/db.clj@@ -2,7 +2,6 @@"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]@@ -15,16 +14,26 @@[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 :- [:maybe ::transforms-python.schema/python-library]- "The ::transforms-python.schema/python-library with `library-id`, or nil."+(mu/defn python-library+ "The PythonLibrary with `library-id`, or nil."[library-id :- ms/PositiveInt]- (t2/select-one :model/PythonLibrary :id [:auto/param library-id]))+ (t2/select-one :model/PythonLibrary 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 26a1896708e..de46a2e34e7 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_python/python_runner.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/python_runner.clj@@ -21,9 +21,7 @@[metabase.util.i18n :as i18n][metabase.util.json :as json][metabase.util.log :as log]- [metabase.util.malli :as mu]- [metabase.warehouse-schema.db :as warehouse-schema.db]- [metabase.warehouses.db :as warehouses.db])+ [metabase.util.malli :as mu])(:import(clojure.lang PersistentQueue)(java.io BufferedWriter File InputStream OutputStream OutputStreamWriter)@@ -292,7 +290,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 (:db_id (warehouse-schema.db/table table-id))+ (let [db-id (transforms-python.db/table-database-id 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)@@ -320,8 +318,8 @@(let [tmp-data-file (File/createTempFile data-path "")tmp-meta-file (File/createTempFile manifest-path "")](try- (let [db-id (:db_id (warehouse-schema.db/table table_id))- driver (:engine (warehouses.db/database db-id))+ (let [db-id (transforms-python.db/table-database-id table_id)+ driver (transforms-python.db/database-engine 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 d0282bd3763..aa9ace26508 100644--- a/enterprise/backend/src/metabase_enterprise/upload_management/api.clj+++ b/enterprise/backend/src/metabase_enterprise/upload_management/api.clj@@ -9,8 +9,7 @@[metabase.premium-features.core :as premium-features][metabase.upload.core :as upload][metabase.util.i18n :refer [tru]]- [metabase.util.malli.schema :as ms]- [metabase.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util.malli.schema :as ms]))(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@@ -50,7 +49,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 (warehouse-schema.db/table id))+ (let [table (api/check-404 (upload-management.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 7a208f1f053..6666afe3347 100644--- a/enterprise/backend/src/metabase_enterprise/upload_management/db.clj+++ b/enterprise/backend/src/metabase_enterprise/upload_management/db.clj@@ -22,3 +22,8 @@[](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 216b1ec7219..512a18bfa9c 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.clj@@ -12,7 +12,6 @@[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]@@ -645,8 +644,8 @@(mt/with-temp [:model/Card {card-id :id} {:dataset_query (table-query :venues)}](run-jobs!)(reprocess! card-id)- (let [card (mt/original-fn #'queries.db/card)]- (mt/with-dynamic-fn-redefs [queries.db/card (fn [id] (assoc (card id) :result_metadata nil))]+ (let [card (mt/original-fn #'dependencies.db/card)]+ (mt/with-dynamic-fn-redefs [dependencies.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 68630098046..fd1751a22b1 100644--- a/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.clj+++ b/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.clj@@ -6,7 +6,6 @@[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)@@ -320,7 +319,7 @@(t2/query-one {:update :transform:set {:source "{\"type\":\"query\",\"query\":{}}"}:where [:= :id transform-id]})- (is (nil? (mu/disable-enforcement (replacement.field-refs/upgrade-field-refs! [:transform transform-id]))))))))+ (is (nil? (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 bd5bae7ecfe..ad757017ed0 100644--- a/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.clj+++ b/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.clj@@ -11,7 +11,6 @@[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)@@ -180,10 +179,9 @@(t2/query-one {:update :transform:set {:source "{\"type\":\"query\",\"query\":{}}"}:where [:= :id transform-id]})- (is (nil? (mu/disable-enforcement- (replacement.source-swap/swap-source! [:transform transform-id]- [:table (mt/id :orders)]- [:table (mt/id :reviews)]))))))))))+ (is (nil? (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 75c83860447..b3f262e6a2d 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 525540bf3a7..dd28cf1ac08 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-tables [] :body "def transform():\n pass"}}+ {:source {:type "python" :source-database (mt/id)}}: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 cfe4865f289..13a059e68f4 100644--- a/enterprise/backend/test/metabase_enterprise/transforms/core_test.clj+++ b/enterprise/backend/test/metabase_enterprise/transforms/core_test.clj@@ -50,9 +50,7 @@:database (mt/id)}}:model/Transform {python-id :id}{:source {:type "python"- :source-database (mt/id)- :source-tables []- :body "def transform():\n pass"}+ :source-database (mt/id)}: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 8144b83821d..793446c4b1a 100644--- a/src/metabase/actions/actions.clj+++ b/src/metabase/actions/actions.clj@@ -29,7 +29,6 @@[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)))@@ -257,7 +256,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] #(:db_id (warehouse-schema.db/table table-id)))))+ (cached-database (cached-value [:table-by-db-ids table-id] #(actions.db/table-database-id table-id))))(mu/defn- check-permissions[policy :- :keyworddiff --git a/src/metabase/actions/args.clj b/src/metabase/actions/args.cljindex 93a396bb1fa..65832617001 100644--- a/src/metabase/actions/args.clj+++ b/src/metabase/actions/args.clj@@ -1,5 +1,6 @@(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]@@ -7,8 +8,7 @@[metabase.lib.schema.parameter :as lib.schema.parameter][metabase.util :as u][metabase.util.log :as log]- [metabase.util.malli.registry :as mr]- [metabase.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util.malli.registry :as mr]))(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 (:db_id (warehouse-schema.db/table table-id))))+ {:database (or database (when table-id (actions.db/table-database-id 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 09de96c712c..0067cffe317 100644--- a/src/metabase/actions/db.clj+++ b/src/metabase/actions/db.clj@@ -10,11 +10,6 @@[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."[]@@ -33,6 +28,21 @@: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]]@@ -43,6 +53,16 @@[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]@@ -56,6 +76,11 @@[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]@@ -66,11 +91,47 @@[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]@@ -139,6 +200,12 @@[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]]@@ -190,6 +257,11 @@;; 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]@@ -204,24 +276,3 @@"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 24dfb36efa3..e59065797a1 100644--- a/src/metabase/actions/execution.clj+++ b/src/metabase/actions/execution.clj@@ -18,7 +18,6 @@[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]@@ -95,7 +94,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 (:dataset_query (queries.db/card model-id))))+ (:table-id (query/query->database-and-table-ids (actions.db/card-query model-id)))table-id)](first (when table-id (actions.db/tables-with-fields [table-id])))))@@ -302,7 +301,7 @@(qp/process-query(qp/userland-query(if-let [model-id (:model_id action)]- (qp.card/query-for-card (queries.db/card model-id) prefetch-parameters nil nil)+ (qp.card/query-for-card (actions.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 af8fbe57f92..d66dbcf5bba 100644--- a/src/metabase/actions/models.clj+++ b/src/metabase/actions/models.clj@@ -6,7 +6,6 @@[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]@@ -16,7 +15,6 @@[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]@@ -24,8 +22,6 @@[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]))@@ -102,7 +98,7 @@(defn- check-implicit-action-model"Throws a 400 unless the Card with `model-id` is a model."[model-id]- (when-not (= (:type (queries.db/card model-id)) :model)+ (when-not (= (actions.db/card-type model-id) :model)(throw (ex-info (tru "Actions must be made with models, not cards."){:status-code 400}))))@@ -111,7 +107,7 @@[{model-id :model_id, :as action}](when (and (implicit? action)model-id- (not (query/supports-implicit-actions? (:dataset_query (queries.db/card model-id)))))+ (not (query/supports-implicit-actions? (actions.db/card-query model-id))))(throw (ex-info (tru "Implicit actions are not supported for models with clauses."){:status-code 400}))))@@ -128,7 +124,7 @@(defn- collection-namespace"The namespace of the Collection with `collection-id` as a keyword, or nil."[collection-id]- (some-> collection-id collections.db/collection :namespace keyword))+ (some-> collection-id actions.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."@@ -155,7 +151,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 (:collection_id (queries.db/card model-id))]+ (let [model-collection-id (actions.db/card-collection-id model-id)](when (and (some? collection-id) (not= collection-id model-collection-id))(throw (model-collection-error)))(assoc action :collection_id model-collection-id)))@@ -210,7 +206,7 @@(some? table-id)(not mi/*deserializing?*)(perms/data-app-collection? collection-id)- (not (:is_published (warehouse-schema.db/table table-id))))+ (not (actions.db/table-published? 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@@ -229,7 +225,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) (:collection_id (queries.db/card model-id))))+ (not= (:collection_id action) (actions.db/card-collection-id 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))@@ -255,19 +251,19 @@(t2/define-before-insert :model/QueryAction[query-action](u/prog1 (set-query-database query-action)- (check-data-app-action-query (:collection_id (actions.db/action (:action_id <>))) (:dataset_query <>))))+ (check-data-app-action-query (actions.db/action-collection-id (: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 (:collection_id (actions.db/action (:action_id <>))) (:dataset_query <>)))))+ (check-data-app-action-query (actions.db/action-collection-id (: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 (:model_id (actions.db/action action-id))+ (if (actions.db/action-model-id 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})))@@ -294,7 +290,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 (:collection_id (actions.db/action action-id)) table-id)))+ (check-data-app-action-table (actions.db/action-collection-id action-id) table-id)))(t2/define-before-update :model/ImplicitAction[implicit-action]@@ -316,8 +312,7 @@: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))- warehouse-schema.db/table- :db_id))]+ actions.db/table-database-id))]:query [(:database query)][]))@@ -326,7 +321,7 @@[action](doseq [database-id (action-database-ids action):when database-id]- (actions/check-actions-enabled-for-database (warehouses.db/database database-id))))+ (actions/check-actions-enabled-for-database (actions.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."@@ -783,7 +778,7 @@(serdes/mbql-deps true dataset_query)))))))(defmethod serdes/descendants "Action" [_model-name id _opts]- (when-let [model-id (:model_id (actions.db/action id))]+ (when-let [model-id (actions.db/action-model-id id)]{["Card" model-id] {"Action" id}}));;;; ------------------------------------------------- Search ----------------------------------------------------------diff --git a/src/metabase/actions/scope.clj b/src/metabase/actions/scope.cljindex 31ae5244456..243c158ecd7 100644--- a/src/metabase/actions/scope.clj+++ b/src/metabase/actions/scope.clj@@ -3,8 +3,7 @@[metabase.actions.db :as actions.db][metabase.actions.types :as types][metabase.lib.core :as lib]- [metabase.util.malli :as mu]- [metabase.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util.malli :as mu]));; TODO Perhaps we will prefer the FE just sending this explicitly instead?;; For now, it is not doing this, so we infer it.@@ -46,7 +45,7 @@(:model-id scope) (hydrate-from-card (:model-id scope))(:table-id scope)- (update :database-id #(or % (:db_id (warehouse-schema.db/table (:table-id scope))) missing-id))))+ (update :database-id #(or % (actions.db/table-database-id (: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 5a3a6eb7c43..44f484c1f1b 100644--- a/src/metabase/actions_rest/db.clj+++ b/src/metabase/actions_rest/db.clj@@ -45,6 +45,11 @@[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 fbb4ea135e5..1e1204f7a58 100644--- a/src/metabase/activity_feed/api.clj+++ b/src/metabase/activity_feed/api.clj@@ -5,14 +5,9 @@[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@@ -116,11 +111,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 (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)))]+ :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)))](when-not exists?(throw (ex-info "Model not found" {:model model :model_id model-id})))(api/read-check (entity))@@ -138,7 +133,7 @@in the last 24 hours."[](if-let [dashboard-id (recent-views/most-recently-viewed-dashboard-id *current-user-id*)]- (let [dashboard (-> (dashboards.db/dashboard dashboard-id)+ (let [dashboard (-> (activity-feed.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 df7999dc0b3..f8b6429e11c 100644--- a/src/metabase/activity_feed/db.clj+++ b/src/metabase/activity_feed/db.clj@@ -113,6 +113,36 @@[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 b77d55d91e7..e2379eeb81a 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 (:document_id (queries.db/card card-id))))+ (not (activity-feed.db/card-document-id 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? (:document_id (queries.db/card object-id))))+ (nil? (activity-feed.db/card-document-id 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 e3f300cfc36..66fca434770 100644--- a/src/metabase/agent_api/api.clj+++ b/src/metabase/agent_api/api.clj@@ -17,10 +17,8 @@[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]@@ -37,7 +35,6 @@[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]@@ -84,7 +81,7 @@[collection-id](if-not collection-id(:name (collection/root-collection-with-ui-details nil))- (let [coll (collections.db/collection collection-id)+ (let [coll (agent-api.db/collection-breadcrumb-columns 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.@@ -918,7 +915,7 @@:card-updates card-updates:actor @api/*current-user*:delete-old-dashcards? false})- (update-card-response (queries.db/card id))))+ (update-card-response (agent-api.db/card id))))(mr/def ::create-question-request[:map {:closed true}@@ -1376,13 +1373,6 @@(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 [...]}.@@ -1396,7 +1386,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 (dashboards.db/dashboard dashboard-id)+ dashboard (agent-api.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@@ -1459,7 +1449,7 @@"update_text"(let [existing (api/check-404- (dashcard-in-dashboard dashcard_id dashboard-id))+ (agent-api.db/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)@@ -1474,7 +1464,7 @@"remove"(let [existing (api/check-404- (dashcard-in-dashboard dashcard_id dashboard-id))]+ (agent-api.db/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 #(-> %@@ -1483,7 +1473,7 @@"move"(let [existing (api/check-404- (dashcard-in-dashboard dashcard_id dashboard-id))+ (agent-api.db/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.@@ -1621,7 +1611,7 @@{:object current-dash:user-id api/*current-user-id*:dashcards (:removed result)}))- (let [updated (dashboards.db/dashboard id)]+ (let [updated (agent-api.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 0e8de431e08..da7bc14d7ab 100644--- a/src/metabase/agent_api/db.clj+++ b/src/metabase/agent_api/db.clj@@ -9,6 +9,22 @@[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]@@ -39,6 +55,12 @@[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 bd5e5c96fb0..402a50c1716 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 :- [:maybe ::api-keys.schema/api-key]- "The ::api-keys.schema/api-key with `id`, or nil."+(mu/defn api-key+ "The ApiKey with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/ApiKey :id [:auto/param id]))+ (t2/select-one :model/ApiKey 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 650c8cd88b7..40ed57777ac 100644--- a/src/metabase/audit_app/db.clj+++ b/src/metabase/audit_app/db.clj@@ -6,6 +6,7 @@[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@@ -33,6 +34,11 @@[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 7133ee28e6f..53c07b04faf 100644--- a/src/metabase/audit_app/models/audit_log.clj+++ b/src/metabase/audit_app/models/audit_log.clj@@ -14,7 +14,6 @@[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]))@@ -118,7 +117,7 @@[metric _event-type](let [table-id (:table_id metric)db-id (when table-id- (:db_id (warehouse-schema.db/table table-id)))]+ (audit-app.db/table-database-id 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 28390a606a8..c7ae56d517e 100644--- a/src/metabase/auth_identity/db.clj+++ b/src/metabase/auth_identity/db.clj@@ -22,16 +22,11 @@[:expires_at {:optional true} [:maybe ms/TemporalInstant]][:confirmed_at {:optional true} [:maybe ms/TemporalInstant]]])-(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+(mu/defn auth-identity"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 [:auto/param (long user-id)] :provider [:auto/param provider]))+ (t2/select-one :model/AuthIdentity :user_id (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."@@ -87,6 +82,11 @@: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 bc25cb97085..35ac3aff61b 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-for-user-and-provider user-id "password")]+ (if-let [pw-auth-identity (auth-identity.db/auth-identity 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-for-user-and-provider user-id "emailed-secret-password-reset")+ (get-in (auth-identity.db/auth-identity 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 e171d63ea92..b9db2e78226 100644--- a/src/metabase/auth_identity/provider.clj+++ b/src/metabase/auth_identity/provider.clj@@ -64,7 +64,6 @@[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]]@@ -430,7 +429,7 @@[{user-id :id}](when (setting/get :send-new-sso-user-admin-email?)(try- (messages/send-user-joined-admin-notification-email! (users.db/user user-id) :sso-auth? true)+ (messages/send-user-joined-admin-notification-email! (auth-identity.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)))))@@ -511,7 +510,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 (users.db/user (:id <>))+ (events/publish-event! :event/user-invited {:object (assoc (auth-identity.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 60e283b726d..1a592a819c3 100644--- a/src/metabase/auth_identity/providers/emailed_secret.clj+++ b/src/metabase/auth_identity/providers/emailed_secret.clj@@ -9,7 +9,6 @@[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]@@ -109,7 +108,7 @@[user-id :- ms/PositiveInt](u/prog1 (generate-reset-token user-id)(t2/with-transaction [_]- (let [user (users.db/user user-id)+ (let [user (auth-identity.db/user user-id)auth-identity {:user_id user-id:provider "emailed-secret-password-reset":provider_id (:email user)@@ -147,7 +146,7 @@:else(try(if-let [user-id (parse-token-user-id token)]- (if-let [auth-identity (auth-identity.db/auth-identity-for-user-and-provider user-id (name provider))]+ (if-let [auth-identity (auth-identity.db/auth-identity user-id (name provider))](let [verification-result (verify-reset-token token (:credentials auth-identity))](case verification-result:valid@@ -194,7 +193,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! (users.db/user (:id user))))+ (messages/send-user-joined-admin-notification-email! (auth-identity.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 077ab30c078..d61e1c26db3 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-for-user-and-provider (:id user) "password")))+ (auth-identity.db/auth-identity (: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 4bab6229841..64c6df86256 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 :- [:maybe ::cache.schema/cache-config]- "The ::cache.schema/cache-config with `pk`, or nil."+(mu/defn cache-config+ "The CacheConfig with primary key `pk`, or nil."[pk :- ms/PositiveInt]- (t2/select-one :model/CacheConfig :id [:auto/param pk]))+ (t2/select-one :model/CacheConfig 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 34ba5c124e2..456e10073db 100644--- a/src/metabase/channel/db.clj+++ b/src/metabase/channel/db.clj@@ -9,11 +9,6 @@[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)@@ -38,10 +33,10 @@[row :- ChannelRow](t2/insert-returning-instance! :model/Channel row))-(mu/defn channel :- [:maybe ::channel.schema/channel]- "The ::channel.schema/channel with `id`, or nil."+(mu/defn channel+ "The Channel with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Channel :id [:auto/param id]))+ (t2/select-one :model/Channel id))(mu/defn update-channel!"Apply `changes` to the Channel with `id`, returning the number updated."@@ -95,6 +90,16 @@[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 4710d63731a..d9ec7f0b5bd 100644--- a/src/metabase/channel/render/card.clj+++ b/src/metabase/channel/render/card.clj@@ -1,6 +1,7 @@(ns metabase.channel.render.card(:require[hiccup.util :as hiccup.util]+ [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]@@ -15,8 +16,7 @@[metabase.util.i18n :refer [tru]][metabase.util.log :as log][metabase.util.malli :as mu]- [metabase.util.malli.registry :as mr]- [metabase.warehouses.db :as warehouses.db]))+ [metabase.util.malli.registry :as mr]))(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 warehouses.db/database qp.timezone/results-timezone-id)+ (or (some->> card :database_id channel.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 4412f7995bd..3594251ea32 100644--- a/src/metabase/channel/render/pdf.clj+++ b/src/metabase/channel/render/pdf.clj@@ -51,7 +51,6 @@[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]@@ -1508,7 +1507,7 @@(map (juxt #(-> % :dashcard :id) identity)))parts)dims (paper-dims paper-key)- dash (dashboards.db/dashboard dashboard-id)+ dash (channel.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 c9ddf8412bb..b8910184a3f 100644--- a/src/metabase/channel/render/preview.clj+++ b/src/metabase/channel/render/preview.clj@@ -16,7 +16,6 @@[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]))@@ -84,7 +83,7 @@"Given a dashboard ID, renders all of the dashcards to hiccup datastructure."[dashboard-id](let [user (channel.db/any-user)- dashboard (dashboards.db/dashboard dashboard-id)+ dashboard (channel.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 902b9d65413..a55625783d4 100644--- a/src/metabase/collections/db.clj+++ b/src/metabase/collections/db.clj@@ -24,15 +24,15 @@;;; ---------------------------------------------- Single Collections -----------------------------------------------(mu/defn collection :- [:maybe ::collections.schema/collection]+(mu/defn collection"The ::collections.schema/collection with `collection-id`, or nil."[collection-id :- ::lib.schema.id/collection]- (t2/select-one :model/Collection :id [:auto/param collection-id]))+ (t2/select-one :model/Collection :id collection-id))-(mu/defn collection-location-columns- "The location, id, and type of the Collection with `collection-id`, or nil."+(mu/defn collection-id-and-namespace+ "The ID and namespace of the ::collections.schema/collection with `collection-id`, or nil."[collection-id :- ::lib.schema.id/collection]- (t2/select-one [:model/Collection :location :id :type] :id [:auto/param collection-id]))+ (t2/select-one [:model/Collection :id :namespace] :id collection-id))(mu/defn collection-of-type"The ::collections.schema/collection of `type`, or nil."@@ -75,6 +75,32 @@[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 f515f56ea56..bb2314ca001 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 (:is_remote_synced (collections.db/collection (u/the-id collection-or-id)))))+ :else (collections.db/collection-remote-synced? (u/the-id collection-or-id))))(defn- is-library?"Is this the Library collection?"@@ -215,9 +215,7 @@^{::memoize/args-fn (fn [[id]] [(mdb/unique-identifier) id])}(fn [id](when id- (let [collection (collections.db/collection id)]- (when (= "/" (:location collection))- (:type collection)))))+ (collections.db/root-collection-type-by-id id))):ttl/threshold (* 60 60 1000)))(defn root-collection-type@@ -586,7 +584,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 (:namespace (collections.db/collection parent-id))]+ (let [parent-namespace (collections.db/collection-namespace 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}})))))))@@ -601,7 +599,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? (:is_remote_synced (collections.db/collection parent-id))]+ (let [parent-is-remote-synced? (collections.db/collection-remote-synced? 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@@ -1875,7 +1873,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? (some-> (parent-id* {:location new-location}) collections.db/collection :is_remote_synced)]+ will-be-in-remote-synced? (collections.db/collection-remote-synced? (parent-id* {:location new-location}))](when will-be-in-trash?(throw (ex-info "Cannot `move-collection!` into the Trash. Call `archive-collection!` instead."{:collection collection@@ -2192,7 +2190,7 @@(defmethod mi/perms-objects-set :model/Collection[collection-or-id read-or-write](let [collection (if (integer? collection-or-id)- (collections.db/collection collection-or-id)+ (collections.db/collection-id-and-namespace collection-or-id)collection-or-id)](if (and (= (u/qualified-name (:namespace collection)) "snippets")(not (premium-features/enable-snippet-collections?)))@@ -2246,7 +2244,7 @@{["Collection" (u/last path)] {"Collection" id}}))))(defmethod serdes/descendants "Collection" [_model-name id {:keys [skip-archived]}]- (let [location (when id (:location (collections.db/collection id)))+ (let [location (when id (collections.db/collection-location 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@@ -2364,7 +2362,7 @@(check-collection-namespace Card new-collection-id)"[model collection-id](when collection-id- (let [collection (or (collections.db/collection collection-id)+ (let [collection (or (collections.db/collection-id-and-namespace 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 1e911051612..47a5f978b44 100644--- a/src/metabase/collections_rest/api.clj+++ b/src/metabase/collections_rest/api.clj@@ -12,7 +12,6 @@[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]@@ -638,7 +637,7 @@[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-403 api/*is-superuser?*)- (let [collection (collections.db/collection id)+ (let [collection (collections-rest.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 578a7ef5231..c8bca4c826d 100644--- a/src/metabase/collections_rest/db.clj+++ b/src/metabase/collections_rest/db.clj@@ -7,6 +7,11 @@[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 51faf59a403..857d7541fbd 100644--- a/src/metabase/comments/api.clj+++ b/src/metabase/comments/api.clj@@ -12,9 +12,7 @@[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]@@ -155,10 +153,10 @@& [{:keys [entity parent];; if you don't pass them we'll try to fetch them:or {entity (case target_type- "document" (documents.db/document target_id)- "exploration" (explorations.db/exploration target_id))+ "document" (comments.db/document target_id)+ "exploration" (comments.db/exploration target_id))parent (when parent_comment_id- (comments.db/comment parent_comment_id))}}]]+ (comments.db/comment-by-id 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`@@ -182,7 +180,7 @@(defn notify-comment-id!"Send a notification using only comment id"[comment-id]- (notify-comment! (-> (comments.db/comment comment-id)+ (notify-comment! (-> (comments.db/comment-by-id 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@@ -199,7 +197,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 parent_comment_id))+ (-> (api/check-404 (comments.db/comment-by-id parent_comment_id))(u/prog1 (api/check-400 (and (= (:target_type <>) target_type)(= (:target_id <>) target_id)(= (:child_target_id <>) child_target_id))@@ -230,7 +228,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 comment-id))+ (let [comment (api/check-404 (comments.db/comment-by-id 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")))]@@ -248,7 +246,7 @@u/remove-nilsnot-empty)](comments.db/update-comment! comment-id updates))- (let [updated-comment (-> (comments.db/comment comment-id)+ (let [updated-comment (-> (comments.db/comment-by-id comment-id)(t2/hydrate :creator :reactions))](events/publish-event! :event/comment-update{:object updated-comment@@ -263,7 +261,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 comment-id))]+ (let [comment (api/check-404 (comments.db/comment-by-id 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")))@@ -288,7 +286,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 comment-id))]+ (let [comment (api/check-404 (comments.db/comment-by-id 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 7df1b978b0b..55aef5f3cd9 100644--- a/src/metabase/comments/db.clj+++ b/src/metabase/comments/db.clj@@ -1,7 +1,6 @@(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]@@ -51,10 +50,20 @@[user-ids :- [:sequential ::lib.schema.id/user]](t2/select-pks-set :model/User :id [:in user-ids] :is_active true))-(mu/defn comment :- [:maybe ::comments.schema/comment]- "The ::comments.schema/comment with `id`, or nil."+(mu/defn document+ "The Document with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Comment :id [:auto/param id]))+ (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))(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 667ebdd313b..6725388f55a 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.db :as queries.db]+ [metabase.queries.core :as queries][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 :- [:maybe ::dashboards.schema/dashboard]- "The ::dashboards.schema/dashboard with `dashboard-id`, or nil."+(mu/defn dashboard+ "The Dashboard with `dashboard-id`, or nil."[dashboard-id :- ::lib.schema.id/dashboard]- (t2/select-one :model/Dashboard :id [:auto/param dashboard-id]))+ (t2/select-one :model/Dashboard :id dashboard-id))(mu/defn insert-dashboard!"Insert the Dashboard `row` and return the inserted instance."@@ -113,10 +113,15 @@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.db/card-query-info card-id))+ (queries/card-query-info card-id))(mu/defn card-queries"A map of Card id to query for the Cards with `card-ids`."@@ -174,10 +179,10 @@:where [:in :series.dashboardcard_id dashcard-ids]:order-by [[:series.position :asc]]}))-(mu/defn dashboard-card :- [:maybe ::dashboards.schema/dashboard-card]- "The ::dashboards.schema/dashboard-card with `dashcard-id`, or nil."+(mu/defn dashcard+ "The DashboardCard with `dashcard-id`, or nil."[dashcard-id :- ::lib.schema.id/dashcard]- (t2/select-one :model/DashboardCard :id [:auto/param dashcard-id]))+ (t2/select-one :model/DashboardCard :id dashcard-id))(mu/defn multi-cards-for-dashcard"The unarchived Cards added to the DashboardCard with `dashcard-id` as series (the 'add series' feature)."@@ -371,10 +376,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 :- [:maybe ::dashboards.schema/dashboard-tab]- "The ::dashboards.schema/dashboard-tab with `tab-id`, or nil."+(mu/defn dashboard-tab+ "The DashboardTab with `tab-id`, or nil."[tab-id :- ms/PositiveInt]- (t2/select-one :model/DashboardTab :id [:auto/param tab-id]))+ (t2/select-one :model/DashboardTab :id 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 4fa53f052cf..f1ac4df8d8d 100644--- a/src/metabase/dashboards/models/dashboard.clj+++ b/src/metabase/dashboards/models/dashboard.clj@@ -22,7 +22,6 @@[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]@@ -294,7 +293,7 @@[card](cond;; If this is a pre-existing card, just return it- (and (integer? (:id card)) (queries.db/card (:id card)))+ (and (integer? (:id card)) (dashboards.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 f108270e7f2..46eaf032df4 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/dashboard-card id)+ (-> (dashboards.db/dashcard id)(t2/hydrate :series)))(defn dashcard->multi-cardsdiff --git a/src/metabase/dashboards/write.clj b/src/metabase/dashboards/write.cljindex e7bf057cfeb..d1f345ca8e4 100644--- a/src/metabase/dashboards/write.clj+++ b/src/metabase/dashboards/write.clj@@ -25,7 +25,6 @@[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]]@@ -188,7 +187,7 @@(defn- create-dashcards (filter pos-int?)) dashcards)]- (api/check-not-archived (queries.db/card card-id)))+ (api/check-not-archived (dashboards.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 10f4cffa1bf..dd95d92f5ee 100644--- a/src/metabase/dashboards_rest/api.clj+++ b/src/metabase/dashboards_rest/api.clj@@ -15,11 +15,9 @@[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]@@ -42,7 +40,6 @@[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]@@ -54,7 +51,6 @@[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]@@ -367,7 +363,7 @@(fn [card](when card(let [dataset-query (or (:dataset_query card)- (some-> (:id card) queries.db/card :dataset_query))+ (dashboards-rest.db/card-query (:id card)))download-level (when (seq dataset-query)(perms/download-perms-level dataset-query api/*current-user-id*))](assoc card :download_perms (case download-level@@ -393,7 +389,7 @@(span/with-span!{:name "get-dashboard":attributes {:dashboard/id id}}- (-> (dashboards.db/dashboard id)+ (-> (dashboards-rest.db/dashboard id)api/read-checkhydrate-dashboard-detailscollection.root/hydrate-root-collection@@ -754,7 +750,7 @@cards (dashboards-rest.db/dashboard-item-cards id (request/paged?) (request/limit) (request/offset))]{:total (count cards):data (collections.children/post-process-rows {}- (some-> (:collection_id dashboard) collections.db/collection)+ (dashboards-rest.db/collection (:collection_id dashboard))cards):limit (request/limit):offset (request/offset)@@ -850,7 +846,7 @@(defn- create-dashcards (filter pos-int?)) dashcards)]- (api/check-not-archived (queries.db/card card-id)))+ (api/check-not-archived (dashboards-rest.db/card card-id)))(check-parameter-mapping-permissions (for [{:keys [card_id parameter_mappings]} dashcardsmapping parameter_mappings](assoc mapping :card-id card_id)))@@ -959,7 +955,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 (select-keys (users.db/user creator_id) [:first_name :last_name :email])]+ (let [creator (dashboards-rest.db/user-name-and-email creator_id)]{:pulse-id bad-pulse-id:pulse-name pulse-name:bad-parameters parameters@@ -986,7 +982,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.db/dashboard dashboard-id) :resolved-params)+ (let [{:keys [resolved-params]} (t2/hydrate (dashboards-rest.db/dashboard-parameters 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)@@ -1009,7 +1005,7 @@(when-some [broken-pulses (broken-pulses dashboard-id original-dashboard-params)](let [{dashboard-name :namedashboard-description :description- dashboard-creator :creator} (t2/hydrate (dashboards.db/dashboard dashboard-id) :creator)]+ dashboard-creator :creator} (t2/hydrate (dashboards-rest.db/dashboard-name-columns dashboard-id) :creator)](for [broken-pulse broken-pulses](assoc(bad-pulse-notification-data broken-pulse)@@ -1043,7 +1039,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.db/dashboard id) [:dashcards :card] :resolved-params))+ (t2/hydrate (dashboards-rest.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@@ -1109,7 +1105,7 @@(select-keys dashcards-changes-stats [:created-dashcards :deleted-dashcards])))))(collections/check-for-remote-sync-update current-dash))true))- (let [dashboard (dashboards.db/dashboard id)]+ (let [dashboard (dashboards-rest.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)))@@ -1229,7 +1225,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 (:public_uuid (dashboards.db/dashboard dashboard-id))+ (let [existing-public-uuid (dashboards-rest.db/dashboard-public-uuid 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@@ -1238,7 +1234,7 @@{:public_uuid <>:made_public_by_id api/*current-user-id*})(events/publish-event! :event/dashboard-public-link-created- {:object (dashboards.db/dashboard dashboard-id)+ {:object (dashboards-rest.db/dashboard dashboard-id):object-id dashboard-id:user-id api/*current-user-id*}))))]{:uuid uuid}))@@ -1262,7 +1258,7 @@{:public_uuid nil:made_public_by_id nil})(events/publish-event! :event/dashboard-public-link-deleted- {:object (dashboards.db/dashboard dashboard-id)+ {:object (dashboards-rest.db/dashboard dashboard-id):object-id dashboard-id:user-id api/*current-user-id*})){:status 204, :body nil})@@ -1275,7 +1271,7 @@"Return related entities."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (-> (dashboards.db/dashboard id) api/read-check xrays/related))+ (-> (dashboards-rest.db/dashboard id) api/read-check xrays/related));;; ---------------------------------------------- Transient dashboards ----------------------------------------------@@ -1475,8 +1471,7 @@request](some-> (data-apps/request-data-app request) (data-apps/check-dashboard dashboard-id))(api/read-check :model/Dashboard dashboard-id)- (let [dashcard (dashboards.db/dashboard-card dashcard-id)]- (api/check-404 (= (:dashboard_id dashcard) dashboard-id))+ (let [dashcard (api/check-404 (dashboards-rest.db/dashcard-in-dashboard dashcard-id dashboard-id))](actions/fetch-values(api/check-404 (actions/dashcard->action dashcard))parameters)))@@ -1526,9 +1521,9 @@(m/mapply qp.dashboard/process-query-for-dashcard(merge(dissoc body :dashboard_load_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))}))))+ {: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))}))));; 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@@ -1557,9 +1552,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.db/dashboard dashboard-id))- :card (api/check-404 (queries.db/card card-id))- :dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-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)):export-format export-format:parameters parameters:context (api.dataset/export-format->context export-format)@@ -1593,7 +1588,7 @@(m/mapply qp.dashboard/process-query-for-dashcard(mergebody- {: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))+ {: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)):qp qp.pivot/run-pivot-query})))diff --git a/src/metabase/dashboards_rest/db.clj b/src/metabase/dashboards_rest/db.cljindex a9f6e5f10ea..95cb07bafa1 100644--- a/src/metabase/dashboards_rest/db.clj+++ b/src/metabase/dashboards_rest/db.clj@@ -21,6 +21,26 @@[:= :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."[]@@ -113,6 +133,16 @@[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]]@@ -138,11 +168,27 @@[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]]@@ -160,6 +206,11 @@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 854f6192575..396ee4a3c8d 100644--- a/src/metabase/data_studio/api/table.clj+++ b/src/metabase/data_studio/api/table.clj@@ -19,8 +19,7 @@[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.warehouses.db :as warehouses.db]))+ [metabase.warehouse-schema.models.table-user-settings :as schema.table-user-settings]))(set! *warn-on-reflection* true)@@ -135,7 +134,7 @@(u.jvm/in-virtual-thread*(fn [](doseq [[db-id tables] (group-by :db_id newly-unhidden)]- (let [database (warehouses.db/database db-id)]+ (let [database (data-studio.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 ac189a870f3..ce2fb0773bb 100644--- a/src/metabase/data_studio/db.clj+++ b/src/metabase/data_studio/db.clj@@ -70,6 +70,11 @@: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 2ab861cf8ae..49a2a436cd9 100644--- a/src/metabase/documents/api/document.clj+++ b/src/metabase/documents/api/document.clj@@ -13,7 +13,6 @@[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]@@ -39,13 +38,6 @@: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]@@ -205,7 +197,7 @@(api/create-check :model/Document {:collection_id collection_id})(let [existing-document (api/check-404(api/read-check- (unarchived-document from-document-id)))+ (documents.db/unarchived-document from-document-id)))document-data {:name (or name (:name existing-document)):document (:document existing-document):content_type (:content_type existing-document)@@ -264,14 +256,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 (:public_uuid (documents.db/document document-id))]+ (if-let [existing-uuid (documents.db/document-public-uuid 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 (:public_uuid (documents.db/document document-id))}))))+ {:uuid (documents.db/document-public-uuid 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@@ -323,7 +315,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 (unarchived-document document-id))]+ (let [document (api/check-404 (documents.db/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)))))@@ -362,7 +354,7 @@[:pivot_results {:default false} ms/BooleanValue]]](validate-card-in-document document-id card-id)(qp.card/process-query-for-card- (api/check-404 (queries.db/card card-id)) export-format+ (api/check-404 (documents.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 c4bdd219dd4..c27e61f1bd2 100644--- a/src/metabase/documents/db.clj+++ b/src/metabase/documents/db.clj@@ -10,12 +10,18 @@[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 :- [:maybe ::documents.schema/document]- "The ::documents.schema/document with `id`, or nil."+(mu/defn document+ "The Document with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Document :id [:auto/param id]))+ (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))(mu/defn visible-unarchived-documents"The unarchived Documents not attached to an Exploration, in a Collection visible to the current user."@@ -67,11 +73,26 @@[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]@@ -118,6 +139,16 @@[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 24ba054cdd9..b54e98662d8 100644--- a/src/metabase/documents/models/document.clj+++ b/src/metabase/documents/models/document.clj@@ -4,7 +4,6 @@[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]@@ -16,7 +15,6 @@[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]@@ -30,7 +28,6 @@[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]))@@ -592,9 +589,9 @@\"dashboard\") and `id`, or nil."[model id](case model- ("card" "dataset") (queries.db/card id)- "table" (warehouse-schema.db/table id)- "dashboard" (dashboards.db/dashboard id)))+ ("card" "dataset") (documents.db/card id)+ "table" (documents.db/table id)+ "dashboard" (documents.db/dashboard id)))(def ^:private model->serdes-model{"card" "Card"diff --git a/src/metabase/documents/schema.clj b/src/metabase/documents/schema.cljindex 9d22af3c584..e7185b0b917 100644--- a/src/metabase/documents/schema.clj+++ b/src/metabase/documents/schema.clj@@ -15,13 +15,12 @@::prose-mirror/ast)(mr/def ::document- "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."+ "A Document as selected from the app DB: every column of `:document`, 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 2d21a7df0ce..07feac2f3e1 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? (:exploration_id (documents.db/document object-id)))+ (when (nil? (documents.db/document-exploration-id 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 69f49406038..815907e83a6 100644--- a/src/metabase/embedding/db.clj+++ b/src/metabase/embedding/db.clj@@ -3,16 +3,10 @@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 114fc07f216..1df2eada4ce 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,7 +18,6 @@[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]@@ -351,19 +350,13 @@(->> (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_params (queries.db/card card-id)))]+ (embedding-rest.db/card-embedding-params card-id))](-> (api.public/public-card card-id :enable-embedding? enable-embedding?)api.public/combine-parameters-and-template-tags(remove-token-parameters token-params)@@ -476,7 +469,7 @@[:enable-embedding? {:optional true} [:maybe :boolean]]]]](let [dashboard-id (unsigned-token->dashboard-id unsigned-token)embedding-params (or embedding-params- (:embedding_params (dashboards.db/dashboard dashboard-id)))+ (embedding-rest.db/dashboard-embedding-params 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)@@ -630,7 +623,7 @@& {:keys [preview] :or {preview false}}](let [unsigned-token (embed/unsign token)dashboard-id (unsigned-token->dashboard-id unsigned-token)- dashboard (dashboards.db/dashboard dashboard-id)+ dashboard (embedding-rest.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@@ -685,7 +678,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 (dashboards.db/dashboard dashboard-id)+ dashboard (embedding-rest.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 110b7af8b9e..13c2cb2c341 100644--- a/src/metabase/embedding_rest/api/embed.clj+++ b/src/metabase/embedding_rest/api/embed.clj@@ -18,13 +18,12 @@[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]@@ -86,7 +85,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 (queries.db/card card-id)))+ (api.embed.common/check-embedding-enabled-for-card (api/check-404 (embedding-rest.db/card-embedding-flags card-id)))(api.embed.common/card-for-unsigned-token unsigned :enable-embedding? true)))(defn ^:private run-query-for-unsigned-token-async@@ -97,7 +96,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 (queries.db/card card-id))]+ card (api/check-404 (embedding-rest.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@@ -170,7 +169,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 (dashboards.db/dashboard dashboard-id)))+ (api.embed.common/check-embedding-enabled-for-dashboard (api/check-404 (embedding-rest.db/dashboard-embedding-flags 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*}))))@@ -192,9 +191,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 (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))]+ 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))](api.embed.common/check-embedding-enabled-for-dashboard dashboard)(api.embed.common/process-query-for-dashcard:export-format export-format@@ -318,7 +317,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 (queries.db/card card-id))]+ card (api/check-404 (embedding-rest.db/card card-id))](api.embed.common/check-embedding-enabled-for-card card)(api.embed.common/card-param-values {:unsigned-token unsigned:card card@@ -333,7 +332,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 (queries.db/card card-id))]+ card (api/check-404 (embedding-rest.db/card card-id))](api.embed.common/check-embedding-enabled-for-card card)(api.embed.common/card-param-values {:unsigned-token unsigned:card card@@ -353,7 +352,7 @@[:value :string]]](let [unsigned (unsign-and-translate-ids token)card-id (api.embed.common/unsigned-token->card-id unsigned)- card (api/check-404 (queries.db/card card-id))]+ card (api/check-404 (embedding-rest.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@@ -413,7 +412,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 (queries.db/card card-id))]+ card (api/check-404 (embedding-rest.db/card card-id))](api.embed.common/check-embedding-enabled-for-card card)(request/as-admin(api.embed.common/process-tiles-query-for-card@@ -443,9 +442,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 (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))]+ 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))](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 4ef039d0d94..db2ff6af66f 100644--- a/src/metabase/embedding_rest/api/preview_embed.clj+++ b/src/metabase/embedding_rest/api/preview_embed.clj@@ -11,12 +11,11 @@(: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]@@ -60,7 +59,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 (queries.db/card card-id))]+ card (api/check-404 (embedding-rest.db/card card-id))](api.embed.common/process-query-for-card-with-params:export-format :api:card card@@ -76,7 +75,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 (queries.db/card card-id))+ (-> (api/check-404 (embedding-rest.db/card card-id))(assoc :embedding_params (token-embedding-params unsigned-token)))))(api.macros/defendpoint :get "/card/:token/params/:param-key/values" :- ms/FieldValuesResult@@ -177,9 +176,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 (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))+ 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))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@@ -202,7 +201,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 (queries.db/card card-id))]+ card (api/check-404 (embedding-rest.db/card card-id))](api.embed.common/process-query-for-card-with-params:export-format :api:card card@@ -224,9 +223,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 (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))+ 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))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@@ -258,7 +257,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 (queries.db/card card-id))]+ card (api/check-404 (embedding-rest.db/card card-id))](request/as-admin(api.embed.common/process-tiles-query-for-cardcard@@ -287,9 +286,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 (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))]+ 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))](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 0ce97d08af2..38e1aa8e66a 100644--- a/src/metabase/embedding_rest/api/theme.clj+++ b/src/metabase/embedding_rest/api/theme.clj@@ -4,7 +4,6 @@[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]@@ -36,7 +35,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.db/embedding-theme id))+ (embedding-rest.db/embedding-theme id))(api.macros/defendpoint :post "/" :- ::EmbeddingTheme"Create a new embedding theme."@@ -60,7 +59,7 @@(cond-> {}name (assoc :name name)settings (assoc :settings settings)))- (embedding.db/embedding-theme id))+ (embedding-rest.db/embedding-theme id))(api.macros/defendpoint :delete "/:id" :- :nil"Delete an embedding theme."@@ -73,7 +72,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.db/embedding-theme id)]+ (let [source-theme (embedding-rest.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 22916b6913e..73ed769e641 100644--- a/src/metabase/embedding_rest/db.clj+++ b/src/metabase/embedding_rest/db.clj@@ -4,10 +4,52 @@(: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."[]@@ -19,6 +61,11 @@[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 e69ffa924e9..242bce23832 100644--- a/src/metabase/explorations/api.clj+++ b/src/metabase/explorations/api.clj@@ -8,7 +8,6 @@[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]@@ -20,12 +19,10 @@[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]@@ -276,6 +273,17 @@(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."@@ -348,8 +356,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 ::lib.schema.common/base-type]]- [:semantic-type {:optional true} [:maybe ::lib.schema.common/semantic-or-relation-type]]])+ [:effective-type {:optional true} [:maybe :string]]+ [:semantic-type {:optional true} [:maybe :string]]])(def ^:private BlockSelection"One Research-plan area on the FE — a metric plus its chosen dimensions. Persisted verbatim as@@ -677,10 +685,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/exploration-page page_id))- block (api/check-404 (explorations.db/exploration-block (:exploration_block_id page)))+ (let [page (api/check-404 (explorations.db/page page_id))+ block (api/check-404 (explorations.db/block (:exploration_block_id page)))src-thread-id (:exploration_thread_id block)- src-thread (explorations.db/exploration-thread src-thread-id)+ src-thread (explorations.db/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@@ -694,7 +702,7 @@metric-selection (first metric-selections)cards (mapv (fn [{:keys [card_id]}](api/read-check- (api/check-404 (when card_id (queries.db/card card_id)))))+ (api/check-404 (when card_id (explorations.db/card card_id)))))metric-selections)card (api/check-404 (first cards))card-name (:name card)@@ -721,7 +729,7 @@tid (:id thread)](explorations.db/insert-blocks! {:exploration_thread_id tid:metrics metrics'- :dimensions (:dimensions block)+ :dimensions (stringify-dim-types (:dimensions block)):position 0})(insert-thread-timelines! tid timeline-ids);; Stamp `started_at` last — it's the signal the planning worker claims on.@@ -813,12 +821,12 @@(defn- get-exploration-page-or-404[page-id]- (api/check-404 (explorations.db/exploration-page page-id)))+ (api/check-404 (explorations.db/page page-id)))(defn- get-thread-or-404"Fetch the thread, or 404."[thread-id]- (api/check-404 (explorations.db/exploration-thread thread-id)))+ (api/check-404 (explorations.db/thread thread-id)))(defn- write-check-thread [thread-id](let [thread (get-thread-or-404 thread-id)]@@ -878,13 +886,13 @@(let [pending-ids (explorations.db/lock-pending-query-ids-for-thread thread-id)](when (seq pending-ids)(explorations.db/cancel-queries! pending-ids)))))- (select-keys (explorations.db/exploration-thread thread-id) [:id :canceled_at :completed_at]))+ (explorations.db/thread-terminal-state thread-id))(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/exploration-query query-id))))+ (api/read-check (api/check-404 (explorations.db/query query-id))))(defn- stream-stored-result"Replay a worker-serialized QP result (gzipped+nippy bytes from `:model/StoredResult.result_data`)@@ -919,7 +927,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 (queries.db/stored-result-data (:id sr))))+ (stream-stored-result format (:result_data 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@@ -969,16 +977,14 @@(defn- document-summary"Project a Document onto the `::ExplorationDocument` wire shape."[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])))+ (explorations.db/summary-document-columns doc-id))(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 (:exploration_block_id (explorations.db/exploration-page page-id))]- (-> (:metrics (explorations.db/exploration-block block-id))+ (when-let [block-id (explorations.db/page-block-id page-id)]+ (-> (explorations.db/block-metrics block-id)first:explore_filtersnot-empty)))diff --git a/src/metabase/explorations/db.clj b/src/metabase/explorations/db.cljindex 0a2cd92d73b..9f4a4604e6b 100644--- a/src/metabase/explorations/db.clj+++ b/src/metabase/explorations/db.clj@@ -19,10 +19,10 @@;;; ----------------------------------------------- Exploration ------------------------------------------------(mu/defn exploration :- [:maybe ::explorations.schema/exploration]- "The ::explorations.schema/exploration with `exploration-id`, or nil."+(mu/defn exploration+ "The Exploration with `exploration-id`, or nil."[exploration-id :- ms/PositiveInt]- (t2/select-one :model/Exploration :id [:auto/param exploration-id]))+ (t2/select-one :model/Exploration :id exploration-id))(defn- my-explorations-query"The query for the Explorations `user-id` created or edited, ordered by that user's most-recent@@ -110,10 +110,40 @@;;; ------------------------------------------------- Threads --------------------------------------------------(mu/defn exploration-thread :- [:maybe ::explorations.schema/exploration-thread]- "The ::explorations.schema/exploration-thread with `thread-id`, or nil."+(mu/defn thread+ "The ExplorationThread with `thread-id`, or nil."[thread-id :- ms/PositiveInt]- (t2/select-one :model/ExplorationThread :id [:auto/param thread-id]))+ (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))(mu/defn thread-in-exploration?"Whether the ExplorationThread with `thread-id` belongs to the Exploration with `exploration-id`."@@ -223,10 +253,20 @@;;; ------------------------------------------------- Blocks --------------------------------------------------(mu/defn exploration-block :- [:maybe ::explorations.schema/exploration-block]- "The ::explorations.schema/exploration-block with `block-id`, or nil."+(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`."[block-id :- ms/PositiveInt]- (t2/select-one :model/ExplorationBlock :id [:auto/param block-id]))+ (t2/select-one-fn :metrics :model/ExplorationBlock :id block-id))(mu/defn block-for-page"The ExplorationBlock owning the ExplorationPage with `page-id`, or nil."@@ -276,10 +316,20 @@;;; -------------------------------------------------- Pages ---------------------------------------------------(mu/defn exploration-page :- [:maybe ::explorations.schema/exploration-page]- "The ::explorations.schema/exploration-page with `page-id`, or nil."+(mu/defn page+ "The ExplorationPage with `page-id`, or nil."[page-id :- ms/PositiveInt]- (t2/select-one :model/ExplorationPage :id [:auto/param page-id]))+ (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))(mu/defn page-id-for-key"The ID of the ExplorationPage of the given block, Card, dimension, and query type, or nil."@@ -340,10 +390,26 @@;;; ------------------------------------------------- Queries --------------------------------------------------(mu/defn exploration-query :- [:maybe ::explorations.schema/exploration-query]- "The ::explorations.schema/exploration-query with `query-id`, or nil."+(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."[query-id :- ms/PositiveInt]- (t2/select-one :model/ExplorationQuery :id [:auto/param query-id]))+ (t2/select-one-fn :exploration_thread_id :model/ExplorationQuery+ :id query-id :status [:in ["done" "error" "canceled"]]))(mu/defn runnable-query"The pending ExplorationQuery with `query-id` on an uncanceled thread, or nil."@@ -516,6 +582,11 @@;;; ---------------------------------------------- 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."@@ -622,6 +693,14 @@;;; ------------------------------------------------ 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]]@@ -636,6 +715,11 @@[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]@@ -666,11 +750,26 @@;;; ------------------------------------------------ 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]]@@ -721,6 +820,11 @@[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 98a079c4fdc..04827c11b17 100644--- a/src/metabase/explorations/derived_perms.clj+++ b/src/metabase/explorations/derived_perms.clj@@ -20,7 +20,6 @@(: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]@@ -194,7 +193,7 @@(:id document)(exploration-content-visible?- (:exploration_id (documents.db/document (:id document))))+ (explorations.db/document-exploration-id (:id document))):elsefalse))diff --git a/src/metabase/explorations/models/exploration_block.clj b/src/metabase/explorations/models/exploration_block.cljindex 47366b94431..79da67b0a2b 100644--- a/src/metabase/explorations/models/exploration_block.clj+++ b/src/metabase/explorations/models/exploration_block.clj@@ -14,7 +14,6 @@[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]))@@ -37,19 +36,8 @@(: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 (comp (:in mi/transform-json) stringify-dim-types)+ {:in (:in mi/transform-json):out (comp keywordize-dim-types (:out mi/transform-json))})(defn- normalize-explore-filters@@ -100,14 +88,14 @@([instance](mi/can-read? :model/ExplorationThread (:exploration_thread_id instance)))([_model pk]- (when-let [g (explorations.db/exploration-block pk)]+ (when-let [g (explorations.db/block-thread-id-row 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/exploration-block pk)]+ (when-let [g (explorations.db/block-thread-id-row 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 8f3422789e3..286f1032efd 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/exploration-page pk)]+ (when-let [p (explorations.db/page-block-id-row 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/exploration-page pk)]+ (when-let [p (explorations.db/page-block-id-row 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 de4644ee77c..3007ccbcf5c 100644--- a/src/metabase/explorations/models/exploration_query.clj+++ b/src/metabase/explorations/models/exploration_query.clj@@ -1,7 +1,6 @@(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]@@ -17,7 +16,7 @@(t2/deftransforms :model/ExplorationQuery{:visualization_settings mi/transform-json- :dataset_query lib-be/transform-query+ :dataset_query mi/transform-json:params mi/transform-json:data_access_token perms/data-access-token-transform})@@ -25,14 +24,14 @@([instance](mi/can-read? :model/ExplorationThread (:exploration_thread_id instance)))([_model pk]- (when-let [q (explorations.db/exploration-query pk)]+ (when-let [q (explorations.db/query-thread-id-row 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/exploration-query pk)]+ (when-let [q (explorations.db/query-thread-id-row 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 2910d963b7f..42c3787d9f8 100644--- a/src/metabase/explorations/models/exploration_query_result.clj+++ b/src/metabase/explorations/models/exploration_query_result.clj@@ -6,7 +6,6 @@[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]]@@ -40,7 +39,7 @@still pending/errored)."[eq-id](when-let [sr-id (explorations.db/query-result-stored-result-id eq-id)]- (queries.db/stored-result sr-id)))+ (explorations.db/stored-result sr-id)))(defn- deserialize-stored-result"Inverse of [[qp/do-with-serialization]] for a stored_result's@@ -70,10 +69,10 @@[eq-ids](mapv(fn [eq-id]- (let [eq (api/check-404 (t2/hydrate (explorations.db/exploration-query eq-id) :segment_name))+ (let [eq (api/check-404 (t2/hydrate (explorations.db/query eq-id) :segment_name))eqr (api/check-404 (explorations.db/query-result eq-id))- 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))))]+ sr (api/check-404 (explorations.db/stored-result (:stored_result_id eqr)))+ qp-result (api/check-404 (deserialize-stored-result (:result_data sr)))]{:eq eq :eqr eqr :sr sr :qp-result qp-result}))eq-ids))@@ -132,7 +131,7 @@first-eq (:eq (first eq-results))first-sr (:sr (first eq-results))src-card (when-let [card-id (:card_id first-eq)]- (queries.db/card card-id))+ (explorations.db/card-presentation 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 289313e4849..4f9134ef25e 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/exploration-thread pk)]+ (when-let [thread (explorations.db/thread-exploration-id-row 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/exploration-thread pk)]+ (when-let [thread (explorations.db/thread-exploration-id-row 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 364c970e260..281e88a648f 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]- (:prompt (explorations.db/exploration-thread thread-id)))+ (explorations.db/thread-prompt 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]- (:query_plan_transcript (explorations.db/exploration-thread thread-id)))+ (explorations.db/thread-transcript thread-id))diff --git a/src/metabase/explorations/query_plan/context.clj b/src/metabase/explorations/query_plan/context.cljindex 9599a1dcc05..85c28ebabfc 100644--- a/src/metabase/explorations/query_plan/context.clj+++ b/src/metabase/explorations/query_plan/context.clj@@ -20,7 +20,6 @@[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)@@ -349,7 +348,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 (queries.db/card card_id)+ (let [card (explorations.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 5cc9ea3656b..d860257179d 100644--- a/src/metabase/explorations/runner.clj+++ b/src/metabase/explorations/runner.clj@@ -20,11 +20,9 @@[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@@ -191,7 +189,7 @@(defn- exploration-id"Walk EQ → ExplorationThread → Exploration.id for recording the stored_result_use reference."[exploration-query]- (:exploration_id (explorations.db/exploration-thread (:exploration_thread_id exploration-query))))+ (explorations.db/thread-exploration-id (:exploration_thread_id exploration-query)))(defn- variant-note"Human phrase for a chart's breakdown variant + params, or nil for the plain `default`@@ -217,7 +215,7 @@Returns nil for a plain unsegmented default breakdown (nothing to call out)."[row](let [segment-name (when-let [sid (:segment_id row)]- (:name (segments.db/segment sid)))+ (explorations.db/segment-name sid))variant (variant-note (:query_type row) (:params row))parts (cond-> []variant (conj variant)@@ -233,7 +231,7 @@charts that won't be scored."[exploration-query]{:card-description (when-let [card-id (:card_id exploration-query)]- (some-> (:description (queries.db/card card-id))+ (some-> (explorations.db/card-description card-id)str/trimnot-empty)):sql (contextual-interestingness/dataset-query->sql (:dataset_query exploration-query))})@@ -259,7 +257,7 @@(if (nil? creator-id)(log/warnf "Skipping contextual interestingness for ExplorationQuery %d: no creator-id on exploration"(:id exploration-query))- (let [prompt (:prompt (explorations.db/exploration-thread thread-id))]+ (let [prompt (explorations.db/thread-prompt thread-id)](when-not (str/blank? prompt)(let [{:keys [card-description sql]} (build-score-context exploration-query)](request/with-current-user creator-id@@ -374,9 +372,7 @@(when (persist-query-result! row started computed)(record-query-outcome! "done"))(:exploration_thread_id row))))- (let [query (explorations.db/exploration-query query-id)]- (when (contains? #{"done" "error" "canceled"} (:status query))- (:exploration_thread_id query)))))+ (explorations.db/finished-query-thread-id query-id)))(defn fail-query!"Terminally mark `query-id` as `error` with `message`, the user-visible failure state the UI@@ -384,7 +380,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 (:exploration_thread_id (explorations.db/exploration-query query-id))]+ (let [thread-id (explorations.db/query-thread-id query-id)](when (pos? (explorations.db/fail-pending-query! query-id message (OffsetDateTime/now)))(record-query-outcome! "error"))thread-id))@@ -401,7 +397,7 @@(defn plan-thread!"Run the LLM planner for `thread-id`, materializing its `ExplorationQuery` rows. Idempotent for MQ."[thread-id]- (let [thread (explorations.db/exploration-thread thread-id)+ (let [thread (explorations.db/thread-planning-state 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 9efc4f50cda..cd87bc3a792 100644--- a/src/metabase/explorations/schema.clj+++ b/src/metabase/explorations/schema.clj@@ -2,8 +2,7 @@"Malli schemas for the explorations module."(:require[metabase.interestingness.chart.types :as chart.types]- [metabase.lib-be.schema :as lib-be.schema]- [metabase.lib.schema.common :as lib.schema.common]+ [metabase.lib.schema :as lib.schema][metabase.lib.schema.id :as lib.schema.id][metabase.metrics.core :as metrics][metabase.util.malli.registry :as mr]@@ -59,8 +58,8 @@[:map {:closed true}[:dimension-id ms/UUIDString][:display-name {: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]]])+ [:effective-type {:optional true} [:maybe :string]]+ [:semantic-type {:optional true} [:maybe :string]]])(mr/def ::exploration-block"A ExplorationBlock as selected from the app DB: every column of `:exploration_block`."@@ -105,8 +104,8 @@ms/VisualizationSettings)(mr/def ::exploration-query.dataset-query- "The `:dataset_query` a ExplorationQuery create or update accepts: an MBQL query, possibly legacy, never empty."- ::lib-be.schema/maybe-legacy-query)+ "The `:dataset_query` column of a ExplorationQuery, decoded."+ ::lib.schema/query)(mr/def ::exploration-query.params"The `:params` column of a ExplorationQuery, decoded."@@ -120,13 +119,11 @@::exploration-thread.data-access-token)(mr/def ::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."+ "A ExplorationQuery as selected from the app DB: every column of `:exploration_query`."[:merge::exploration-query.update[:map {:closed true}- [:id ms/PositiveInt]- [:dataset_query {:optional true} [:maybe ::lib-be.schema/maybe-legacy-or-empty-query]]]])+ [:id ms/PositiveInt]]])(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 29beeaac619..4db1c677597 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 id)]+ (when-let [previous (glossary.db/glossary-entry id)](glossary.db/update-glossary-entry! id term definition)- (let [entry (glossary.db/glossary id)]+ (let [entry (glossary.db/glossary-entry 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 id)]+ (when-let [entry (glossary.db/glossary-entry 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 3af4d1e6173..6f8295e8762 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 :- [:maybe ::glossary.schema/glossary]- "The ::glossary.schema/glossary with `id`, or nil."+(mu/defn glossary-entry+ "The Glossary entry with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Glossary :id [:auto/param id]))+ (t2/select-one :model/Glossary :id 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 5978a0533cf..149a33412bc 100644--- a/src/metabase/indexed_entities/db.clj+++ b/src/metabase/indexed_entities/db.clj@@ -4,14 +4,15 @@(: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 :- [:maybe ::indexed-entities.schema/model-index]- "The ::indexed-entities.schema/model-index with `id`, or nil."+(mu/defn model-index+ "The ModelIndex with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/ModelIndex :id [:auto/param id]))+ (t2/select-one :model/ModelIndex :id id))(mu/defn model-indexes-for-model"The ModelIndexes of the model Card with `model-id`."@@ -33,6 +34,11 @@[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 1b7e346c019..10698d86fbc 100644--- a/src/metabase/indexed_entities/models/model_index.clj+++ b/src/metabase/indexed_entities/models/model_index.clj@@ -12,7 +12,6 @@[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]@@ -92,7 +91,7 @@the record with that primary key."[model-index :- ::indexed-entities.schema/model-indexpk :- [:maybe :int]]- (let [model (queries.db/card (:model_id model-index))+ (let [model (indexed-entities.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 86c66ec58ed..142f70931fc 100644--- a/src/metabase/indexed_entities/task/index_values.clj+++ b/src/metabase/indexed_entities/task/index_values.clj@@ -7,7 +7,6 @@[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]@@ -35,7 +34,7 @@[model-index-id](let [model-index (indexed-entities.db/model-index model-index-id)model (when model-index- (queries.db/card (:model_id model-index)))]+ (indexed-entities.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 ad6dd9f9e7a..6e65ae2dc9a 100644--- a/src/metabase/indexes/db.clj+++ b/src/metabase/indexes/db.clj@@ -2,17 +2,11 @@"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."@@ -49,6 +43,11 @@: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 48d67d89fe6..6c42eddd982 100644--- a/src/metabase/indexes/models/table_index.clj+++ b/src/metabase/indexes/models/table_index.clj@@ -102,9 +102,7 @@(defn select-applicable-by-id"Fetch a single applicable index request by id."[id]- (let [table-index (indexes.db/table-index id)]- (when-not (= :delete-pending (:status table-index))- table-index)))+ (indexes.db/applicable-table-index id))(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 158d391bb22..c93810a0881 100644--- a/src/metabase/indexes_rest/api.clj+++ b/src/metabase/indexes_rest/api.clj@@ -9,7 +9,6 @@[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]@@ -91,7 +90,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.db/table-index id))+ (doto (api/check-404 (indexes-rest.db/table-index id))(read-check-owner!)))(api.macros/defendpoint :post "/request" :- RequestIndex@@ -139,7 +138,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.db/table-index id))))+ (indexes-rest.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 c917281e2c4..83484c14f21 100644--- a/src/metabase/indexes_rest/db.clj+++ b/src/metabase/indexes_rest/db.clj@@ -13,6 +13,11 @@[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 d66a6f3ab36..9ed565f6e38 100644--- a/src/metabase/lib_metric/db.clj+++ b/src/metabase/lib_metric/db.clj@@ -14,6 +14,16 @@[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 ea9ccb785c4..3bdfce1c7b8 100644--- a/src/metabase/lib_metric/dimension/jvm.clj+++ b/src/metabase/lib_metric/dimension/jvm.clj@@ -9,7 +9,6 @@[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)))@@ -130,7 +129,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]}- (queries.db/card card-id)]+ (lib-metric.db/card-table-and-database-id 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 bde558c1fb7..667f6e4f158 100644--- a/src/metabase/lib_metric/metadata/jvm.clj+++ b/src/metabase/lib_metric/metadata/jvm.clj@@ -14,8 +14,7 @@[metabase.lib.metadata.protocols :as lib.metadata.protocols][metabase.settings.core :as setting][metabase.util.malli :as mu]- [metabase.util.memoize :as memoize]- [metabase.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util.memoize :as memoize]))(set! *warn-on-reflection* true)@@ -24,7 +23,7 @@[](memoize/lru(fn [table-id]- (:db_id (warehouse-schema.db/table table-id)))+ (lib-metric.db/table-database-id table-id)):lru/threshold 1000))(defn- fetch-metricsdiff --git a/src/metabase/llm/context.clj b/src/metabase/llm/context.cljindex b9142b94d3e..b430bf236ef 100644--- a/src/metabase/llm/context.clj+++ b/src/metabase/llm/context.clj@@ -9,8 +9,7 @@[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.warehouses.db :as warehouses.db]))+ [metabase.util.log :as log]))(set! *warn-on-reflection* true)@@ -27,7 +26,7 @@[database-id sql-string](if (and database-id (seq sql-string))(try- (let [driver (:engine (warehouses.db/database database-id))+ (let [driver (llm.db/database-engine 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 2460b548d8a..46205b4e840 100644--- a/src/metabase/llm/db.clj+++ b/src/metabase/llm/db.clj@@ -9,6 +9,11 @@[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 c5c9cec63e1..04b3c6d46d1 100644--- a/src/metabase/mcp/db.clj+++ b/src/metabase/mcp/db.clj@@ -16,11 +16,6 @@[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."@@ -42,6 +37,17 @@[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,@@ -57,6 +63,11 @@[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.@@ -228,6 +239,11 @@[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 95ba8f01e95..9b47755d5db 100644--- a/src/metabase/mcp/v2/tools/alert.clj+++ b/src/metabase/mcp/v2/tools/alert.clj@@ -15,6 +15,7 @@[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]@@ -27,7 +28,6 @@[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,10 +323,8 @@[id](when-not (int? id)(common/throw-teaching-error (message/msg ["Alerts take a numeric id — they have no entity_id."])))- (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))+ (let [notification (mcp.db/notification-by-payload-type id :notification/card)]+ (when-not (and 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 bf441832f29..27d017f1e80 100644--- a/src/metabase/mcp/v2/tools/content.clj+++ b/src/metabase/mcp/v2/tools/content.clj@@ -36,12 +36,10 @@[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)@@ -182,7 +180,7 @@or nil when the stored definition can't be serialized."[kind row](try- (let [table (warehouse-schema.db/table (:table_id row))+ (let [table (mcp.db/table-by-id (:table_id row))mp (lib-be/application-database-metadata-provider (:db_id table))metadata (case kind:measure (lib.metadata/measure mp (:id row))@@ -398,14 +396,6 @@;;; ----------------------------------------------------- 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."@@ -413,7 +403,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 (notification-of-type id-or-eid payload-type)]+ (let [notification (mcp.db/notification-by-payload-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@@ -445,7 +435,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 (notification-of-type id-or-eid :notification/dashboard)]+ (let [notification (mcp.db/notification-by-payload-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 23866288f4a..31fbe98e272 100644--- a/src/metabase/mcp/v2/tools/definitions.clj+++ b/src/metabase/mcp/v2/tools/definitions.clj@@ -12,6 +12,7 @@[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]@@ -19,8 +20,7 @@[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.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.metabot.scope :as metabot.scope]))(set! *warn-on-reflection* true)@@ -368,7 +368,7 @@(fn [definition](prepare-definition:segment definition- (warehouse-schema.db/table (:table_id segment)))))]+ (mcp.db/table-by-id (: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- (warehouse-schema.db/table (:table_id measure)))))]+ (mcp.db/table-by-id (: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 2fd52d0d2a2..b8feb5af050 100644--- a/src/metabase/mcp/v2/tools/parameters.clj+++ b/src/metabase/mcp/v2/tools/parameters.clj@@ -28,6 +28,7 @@(: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]@@ -42,7 +43,6 @@[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]} (warehouse-schema.db/field field-id)]+ (let [{:keys [base_type effective_type]} (mcp.db/field-types 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 e72940b6750..e79da592654 100644--- a/src/metabase/mcp/v2/tools/subscription.clj+++ b/src/metabase/mcp/v2/tools/subscription.clj@@ -18,7 +18,6 @@[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]@@ -366,7 +365,7 @@(assoc :parameters(resolve-parametersparameters- (:parameters (dashboards.db/dashboard (:dashboard_id subscription)))))+ (mcp.db/dashboard-parameters (: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 a1f932c6d31..8d2516c2907 100644--- a/src/metabase/measures/db.clj+++ b/src/metabase/measures/db.clj@@ -21,10 +21,10 @@:description description:definition definition))-(mu/defn measure :- [:maybe ::measures.schema/measure]- "The ::measures.schema/measure with `id`, or nil."+(mu/defn measure+ "The Measure with `id`, or nil."[id :- ::lib.schema.id/measure]- (t2/select-one :model/Measure :id [:auto/param id]))+ (t2/select-one :model/Measure :id id))(mu/defn unarchived-measures"The unarchived Measures, in case-insensitive name order."@@ -42,6 +42,16 @@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 e0b896a8fde..b9c09786c6e 100644--- a/src/metabase/measures/models/measure.clj+++ b/src/metabase/measures/models/measure.clj@@ -24,7 +24,6 @@[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]))@@ -63,7 +62,7 @@(defmethod mi/can-read? :model/Measure([instance](let [table (or (:table instance)- (warehouse-schema.db/table (:table_id instance)))]+ (measures.db/table (:table_id instance)))](mi/can-read? table)))([_model pk](mi/can-read? (measures.db/measure pk))))@@ -73,7 +72,7 @@(defmethod mi/can-write? :model/Measure([instance](let [table (or (:table instance)- (warehouse-schema.db/table (:table_id instance)))]+ (measures.db/table (:table_id instance)))](and (or api/*is-superuser?*(and (api/entitled-data-analyst?)(perms/user-has-permission-for-table?@@ -91,7 +90,7 @@(defmethod mi/can-create? :model/Measure[_model instance](let [table (or (:table instance)- (warehouse-schema.db/table (:table_id instance)))]+ (measures.db/table (:table_id instance)))](and (or api/*is-superuser?*(and (api/entitled-data-analyst?)(perms/user-has-permission-for-table?@@ -176,7 +175,7 @@(defmethod mi/perms-objects-set :model/Measure[measure read-or-write](let [table (or (:table measure)- (warehouse-schema.db/table (u/the-id (:table_id measure))))]+ (measures.db/table-perms-columns (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 5c5c57c47c1..92ba1df1888 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` a Measure create or update accepts: an MBQL query, possibly legacy, never empty."+ "The `:definition` column of a Measure, decoded."::lib-be.schema/maybe-legacy-query)(mr/def ::measure.dimension@@ -35,13 +35,12 @@::lib-metric.schema/dimension-mapping)(mr/def ::measure- "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."+ "A Measure as selected from the app DB: every column of `:measure`, 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 4094afaff89..be11a3c85bf 100644--- a/src/metabase/metabot/agent/links.clj+++ b/src/metabase/metabot/agent/links.clj@@ -6,14 +6,12 @@[clojure.string :as str][metabase.lib.core :as lib][metabase.lib.schema]- [metabase.measures.db :as measures.db]+ [metabase.metabot.db :as metabot.db][metabase.metabot.query-repair :as query-repair]- [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.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util.malli.registry :as mr]))(set! *warn-on-reflection* true)@@ -159,7 +157,7 @@unknown."[entity-id](let [measure-id (parse-long entity-id)- table-id (some-> measure-id measures.db/measure :table_id)]+ table-id (some-> measure-id metabot.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}))))@@ -169,8 +167,8 @@segment, or nil when the segment is unknown."[entity-id](let [segment-id (parse-long entity-id)- table-id (some-> segment-id segments.db/segment :table_id)- db-id (some-> table-id warehouse-schema.db/table :db_id)]+ table-id (some-> segment-id metabot.db/segment-table-id)+ db-id (some-> table-id metabot.db/table-database-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 29cabbddd0e..1340198e25f 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/metabot-conversation conversation-id)]+ (when-let [conversation (metabot.db/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 2cbb02ac32a..31b4ba24158 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/metabot-conversation id))]+ (let [conversation (api/check-404 (metabot.db/conversation-id-and-user-id 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 d61136e1744..57fa7c8640d 100644--- a/src/metabase/metabot/db.clj+++ b/src/metabase/metabot/db.clj@@ -8,7 +8,6 @@[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]@@ -19,17 +18,16 @@[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 metabot-metrics-and-models-query root-collections-of-types)+(declare collection metabot-metrics-and-models-query root-collections-of-types);;; ------------------------------------------------- Metabot --------------------------------------------------(mu/defn metabot :- [:maybe ::metabot.schema/metabot]- "The ::metabot.schema/metabot with `metabot-id`, or nil."+(mu/defn metabot+ "The Metabot with `metabot-id`, or nil."[metabot-id :- ms/PositiveInt]- (t2/select-one :model/Metabot :id [:auto/param metabot-id]))+ (t2/select-one :model/Metabot :id metabot-id))(mu/defn metabot-by-entity-id"The Metabot with `entity-id`, or nil."@@ -143,10 +141,20 @@;;; ----------------------------------------------- Conversations ------------------------------------------------(mu/defn metabot-conversation :- [:maybe ::metabot.schema/metabot-conversation]- "The ::metabot.schema/metabot-conversation with `conversation-id`, or nil."+(mu/defn conversation+ "The MetabotConversation with `conversation-id`, or nil."[conversation-id :- :string]- (t2/select-one :model/MetabotConversation :id [:auto/param conversation-id]))+ (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))(mu/defn lock-conversation"The MetabotConversation with `conversation-id`, locked for update."@@ -292,7 +300,7 @@[conversation-id :- :stringuser-id :- ::lib.schema.id/user](boolean- (when-let [{:keys [id user_id slack_thread_ts]} (metabot-conversation conversation-id)]+ (when-let [{:keys [id user_id slack_thread_ts]} (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.@@ -408,6 +416,11 @@;;; ------------------------------------------------ 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]@@ -446,6 +459,22 @@;;; ------------------------------------------------- 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.@@ -460,8 +489,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 (warehouse-schema.db/table table-id)]- (when (and (:active table) (mi/can-read? table))+ (when-let [table (t2/select-one :model/Table :id table-id :active true {:from [(warehouse-schema-overlay/table-query)]})]+ (when (mi/can-read? table)(:db_id table))))(mu/defn tables-by-id@@ -664,11 +693,21 @@;;; ------------------------------------------------- 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]]@@ -676,11 +715,27 @@;;; -------------------------------------------------- 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@@ -706,7 +761,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 (collections.db/collection metabot-collection-id)+ (let [metabot-collection (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])@@ -836,6 +891,16 @@;;; ----------------------------------------------- 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]]@@ -878,6 +943,21 @@;;; ---------------------------------------------- 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.@@ -967,6 +1047,12 @@{: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]]@@ -982,6 +1068,26 @@[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 3e1d9e29b35..b85bcf43756 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/metabot-conversation (:conversation_id message))+ conversation (metabot.db/conversation-id-and-user-id (: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 26d6869aad8..7063a180b2a 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/metabot-conversation pk)]+ (when-let [instance (metabot.db/conversation-id-and-user-id 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 a47196d5ab2..e11fcf272f5 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- (:title (metabot.db/metabot-conversation conversation-id))))+ (metabot.db/conversation-title 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/metabot-conversation conversation-id)]+ (when-let [conv (metabot.db/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 3c0b66fb1f6..a47a52fc49a 100644--- a/src/metabase/metabot/table_utils.clj+++ b/src/metabase/metabot/table_utils.clj@@ -5,7 +5,6 @@[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@@ -62,8 +61,7 @@This is the handler for the /get-tables tool endpoint."[{:keys [database-id]}]{:structured-output- {:database (some-> (warehouses.db/database database-id)- (select-keys [:id :name :description :engine]))+ {:database (metabot.db/database-summary database-id):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 e10450b8822..bcaeaa705d9 100644--- a/src/metabase/metabot/tools/autogen_dashboard.clj+++ b/src/metabase/metabot/tools/autogen_dashboard.clj@@ -7,14 +7,13 @@[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)@@ -64,10 +63,8 @@[kind id](let [entity (tools/with-entity {:kind kind :id id}(api/read-check (if (= :table kind)- (warehouse-schema.db/table id)- (let [card (queries.db/card id)]- (when (= kind (:type card))- card)))))]+ (metabot.db/table id)+ (metabot.db/card-of-type id kind))))](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 b78e3ec4167..b88e9a96d9e 100644--- a/src/metabase/metabot/tools/construct.clj+++ b/src/metabase/metabot/tools/construct.clj@@ -33,7 +33,6 @@[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]@@ -617,7 +616,7 @@numeric-card(let [card-id numeric-card- card (queries.db/card card-id)+ card (metabot.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 75f10020b33..c5a1f1fbb2d 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 (queries.db/card card_id)))+ (api/read-check (metabot.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 4b81ac5bf5c..86aa8ff3f77 100644--- a/src/metabase/metabot/tools/entity_details.clj+++ b/src/metabase/metabot/tools/entity_details.clj@@ -3,21 +3,17 @@[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]@@ -34,8 +30,8 @@[model-key id](when id(case model-key- :model/Measure (:entity_id (measures.db/measure id))- :model/Segment (:entity_id (segments.db/segment id)))))+ :model/Measure (metabot.db/measure-entity-id id)+ :model/Segment (metabot.db/segment-entity-id id))))(defn- convert-measure-or-segment"Convert a measure or segment metadata object to the format expected by the API.@@ -107,7 +103,7 @@[_args](if-let [{:keys [id email first_name last_name]}(or (some-> api/*current-user* deref)- (some-> api/*current-user-id* users.db/user))]+ (metabot.db/user-summary api/*current-user-id*))]{:structured-output (merge {:id id:type :user:name (str first_name " " last_name)@@ -122,11 +118,11 @@(when-not (int? dashboard-id)(throw (ex-info "Invalid dashboard_id format"{:agent-error? true :status-code 400})))- (if-let [dashboard (dashboards.db/dashboard dashboard-id)]+ (if-let [dashboard (metabot.db/dashboard-summary dashboard-id)](do (api/read-check dashboard){:structured-output(-> dashboard- (select-keys [:id :description :name :parameters])+ (dissoc :collection_id)(assoc :type :dashboard:verified (verified-review? dashboard-id "dashboard")))}){:output "dashboard not found"}))@@ -501,7 +497,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))]+ (metabot.tools.u/get-table id :db_id :description :name :schema))](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@@ -863,8 +859,8 @@id :- :int](let [{:keys [lookup-fn definition-key]} (measure-or-segment-dispatch kind)table-id (case kind- :measure (:table_id (measures.db/measure id))- :segment (:table_id (segments.db/segment id)))]+ :measure (metabot.db/measure-table-id id)+ :segment (metabot.db/segment-table-id 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 fec8f687792..823dddbde36 100644--- a/src/metabase/metabot/tools/field_stats.clj+++ b/src/metabase/metabot/tools/field_stats.clj@@ -3,6 +3,7 @@[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]@@ -14,8 +15,7 @@[metabase.request.core :as request][metabase.sync.core :as sync][metabase.sync.util :as sync-util]- [metabase.util.log :as log]- [metabase.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util.log :as log]))(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)) (:fingerprint (warehouse-schema.db/field id))))))+ (pos? (:updated-fingerprints result)) (metabot.db/field-fingerprint 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 (warehouse-schema.db/field id)+ (let [field (metabot.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 04d3bb1d8ab..9334204284d 100644--- a/src/metabase/metabot/tools/resources.clj+++ b/src/metabase/metabot/tools/resources.clj@@ -71,7 +71,6 @@[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]@@ -87,8 +86,6 @@[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]]@@ -502,7 +499,7 @@(defn- present-source-card"Resolve a source-card id to a typed item map (model / metric / question)."[source-card-id]- (let [src-card (queries.db/card source-card-id)+ (let [src-card (metabot.db/card-type-row source-card-id)src-type (case (:type src-card):model "model":metric "metric"@@ -702,8 +699,8 @@(defn- check-measure-or-segment-resource-database [model id](when-let [table-id (case model- :model/Measure (:table_id (measures.db/measure id))- :model/Segment (:table_id (segments.db/segment id)))]+ :model/Measure (metabot.db/measure-table-id id)+ :model/Segment (metabot.db/segment-table-id 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 2b14cc5599f..faf30a8a62b 100644--- a/src/metabase/metabot/tools/run_query.clj+++ b/src/metabase/metabot/tools/run_query.clj@@ -21,7 +21,6 @@[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]@@ -221,7 +220,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) (queries.db/card card-id))]+ source-card (when (= :card kind) (metabot.db/card card-id))](cond(some-> source-card mi/can-read?){:card-type (:type source-card)@@ -249,7 +248,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 (queries.db/card card-id)]+ (let [card (metabot.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)}))@@ -437,7 +436,7 @@through another saved question.Holds a nil for each question that no longer exists."[query]- (map queries.db/card (:card (lib/all-referenced-entity-ids-recursive query))))+ (map metabot.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 bade6a10ab4..333a07224c7 100644--- a/src/metabase/metabot/tools/save_entity.clj+++ b/src/metabase/metabot/tools/save_entity.clj@@ -10,9 +10,7 @@(: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]@@ -213,7 +211,7 @@[collection-id](if (nil? collection-id)(:name (collection/root-collection-with-ui-details nil))- (:name (collections.db/collection collection-id))))+ (metabot.db/collection-name collection-id)))(tools/defrecoverable destination-archived!"The destination is in the trash."@@ -276,7 +274,7 @@:delay-event)]{:card card:destination {:type "dashboard" :id dashboard-id}- :destination-name (:name (dashboards.db/dashboard dashboard-id))+ :destination-name (metabot.db/dashboard-name 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 6d486832ba5..8863d7964ec 100644--- a/src/metabase/metabot/tools/search.clj+++ b/src/metabase/metabot/tools/search.clj@@ -22,8 +22,7 @@[metabase.transforms.core :as transforms][metabase.util :as u][metabase.util.log :as log]- [metabase.util.malli :as mu]- [metabase.warehouses.db :as warehouses.db]))+ [metabase.util.malli :as mu]))(set! *warn-on-reflection* true)@@ -706,7 +705,7 @@(defn- check-search-database- (when-let [database (warehouses.db/database database-id)]+ (when-let [database (metabot.db/database-summary 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 c485558a97d..e0047b4fbb8 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.queries.db :as queries.db]))+ [metabase.metabot.tools.shared.llm-shape :as llm-shape]))(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 (queries.db/card entity_id)))]+ (api/read-check (metabot.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 90f09ece41f..c15ef327877 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.dashboards.db :as dashboards.db]+ [metabase.metabot.db :as metabot.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}- (-> (dashboards.db/dashboard dashboard-id)+ (-> (metabot.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 807cb5fbea1..93e91ba50f8 100644--- a/src/metabase/metabot/tools/util.clj+++ b/src/metabase/metabot/tools/util.clj@@ -10,9 +10,7 @@[metabase.metabot.db :as metabot.db][metabase.metabot.tools.core :as tools][metabase.models.interface :as mi]- [metabase.queries.db :as queries.db]- [metabase.util :as u]- [metabase.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util :as u]))(defn handle-agent-error"Return an agent output for agent errors, re-throw `e` otherwise.@@ -164,10 +162,10 @@api/read-check))(defn get-table- "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))))+ "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))(tools/defrecoverable wrong-source-type!"The card ID identifies a different kind of data source."@@ -183,7 +181,7 @@(defn get-card"Retrieve a readable card by ID, optionally requiring a particular card type."([id]- (-> (queries.db/card id)+ (-> (metabot.db/card id)api/read-check))([id expected-type](let [card (get-card id)]@@ -232,7 +230,7 @@(defn table-query"Return a query based on the table with ID `table-id`."[table-id]- (when-let [table (get-table table-id)]+ (when-let [table (get-table table-id :db_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 f27d9f02a03..560fe3ece85 100644--- a/src/metabase/metrics/api.clj+++ b/src/metabase/metrics/api.clj@@ -8,12 +8,10 @@[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]@@ -28,13 +26,6 @@(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@@ -90,9 +81,9 @@(mu/defn- hydrated-metric [id :- ms/PositiveIntinclude-orphaned? :- :boolean]- (api/read-check (metric-card id))+ (api/read-check (metrics.db/metric-card id))(metrics/sync-dimensions! :metadata/metric id)- (cond-> (-> (metric-card id)+ (cond-> (-> (metrics.db/metric-card id)metrics.perms/filter-dimensions-for-user(update :dimensions #(or % []))(update :dimension_mappings #(or % [])))@@ -180,10 +171,10 @@source-id (lib-metric/expression-leaf-id leaf)](case source-type:metric (do- (api/read-check (metric-card source-id))+ (api/read-check (metrics.db/metric-card source-id))[(lib-metric/expression-leaf-uuid leaf) source-id]):measure (do- (api/query-check (measures.db/measure source-id))+ (api/query-check (metrics.db/measure source-id))nil))))(lib-metric/expression-leaves expression))))@@ -351,10 +342,10 @@;;; +----------------------------------------------------------------------------------------------------------------+(defn- read-check-metric! [id]- (api/read-check (metric-card id)))+ (api/read-check (metrics.db/metric-card id)))(defn- write-check-metric! [id]- (api/write-check (metric-card id)))+ (api/write-check (metrics.db/metric-card id)))(defn- notify-dimensions-changed!"Announce a write to metric `id`'s curated dimensions, given the `before` Card that@@ -368,7 +359,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 (metric-card id)+ (events/publish-event! :event/card-update {:object (metrics.db/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 ed05795e49e..f6b05d6a2fb 100644--- a/src/metabase/metrics/db.clj+++ b/src/metabase/metrics/db.clj@@ -37,6 +37,16 @@: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`.@@ -51,3 +61,8 @@[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 7699d48adbe..21d2dc07e8c 100644--- a/src/metabase/metrics/dimension.clj+++ b/src/metabase/metrics/dimension.clj@@ -12,8 +12,7 @@[metabase.util.log :as log][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.util.malli.schema :as ms]));;; ------------------------------------------------- API Shape -------------------------------------------------;;; Convert internal (kebab) dimensions to the snake_case shape the frontend expects, and back.@@ -240,7 +239,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 (warehouse-schema.db/field field-id)]+ field (metrics.db/field field-id)](parameters/field->values field)))(mu/defn dimension-search-values :- [:sequential [:vector :string]]@@ -260,11 +259,11 @@dimension-id :- :stringvalue :- :string](let [field-id (lib-metric/resolve-dimension-to-field-id dimensions dimension-mappings dimension-id)- field (warehouse-schema.db/field field-id)+ field (metrics.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 (warehouse-schema.db/field remapped-fid)]+ (let [remapped-field (metrics.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 7b3520cbc32..79cd5139515 100644--- a/src/metabase/model_persistence/api.clj+++ b/src/metabase/model_persistence/api.clj@@ -15,7 +15,6 @@[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]@@ -23,7 +22,6 @@[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)@@ -74,7 +72,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 (warehouses.db/database (:database_id persisted-info)))+ (api/write-check (model-persistence.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@@ -87,7 +85,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 (warehouses.db/database (:database_id persisted-info)))+ (api/read-check (model-persistence.db/database (:database_id persisted-info)))persisted-info))(def ^:private CronSchedule@@ -179,9 +177,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} (queries.db/card card-id)]+ (api/let-404 [{:keys [database_id] :as card} (model-persistence.db/card card-id)](api/write-check card)- (let [database (warehouses.db/database database_id)]+ (let [database (model-persistence.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")@@ -205,14 +203,14 @@"Refresh the persisted model caching `card-id`."[{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]]- (api/let-404 [card (queries.db/card card-id)+ (api/let-404 [card (model-persistence.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 (warehouses.db/database (:database_id persisted-info)))+ (api/write-check (model-persistence.db/database (:database_id persisted-info)))(task.persist-refresh/schedule-refresh-for-individual! persisted-info)api/generic-204-no-content))@@ -226,10 +224,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 (queries.db/card card-id)]+ (api/let-404 [card (model-persistence.db/card card-id)](api/write-check card)(when-let [persisted-info (model-persistence.db/persisted-info-for-card card-id)]- (api/write-check (warehouses.db/database (:database_id persisted-info)))+ (api/write-check (model-persistence.db/database (:database_id persisted-info)))(persisted-info/mark-for-pruning! {:id (:id persisted-info)} "off"))api/generic-204-no-content))@@ -248,7 +246,7 @@(api/check (model-persistence.settings/persisted-models-enabled)400(tru "Persisting models is not enabled."))- (api/let-404 [database (warehouses.db/database id)]+ (api/let-404 [database (model-persistence.db/database id)](api/write-check database)(if (-> database :settings :persist-models-enabled);; todo: some other response if already persisted?@@ -275,7 +273,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 (warehouses.db/database id)]+ (api/let-404 [database (model-persistence.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 8fd5310b386..17569a498fa 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 :- [:maybe ::model-persistence.schema/persisted-info]- "The ::model-persistence.schema/persisted-info with `id`, or nil."+(mu/defn persisted-info+ "The PersistedInfo with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/PersistedInfo :id [:auto/param id]))+ (t2/select-one :model/PersistedInfo :id id))(mu/defn persisted-info-for-card"The PersistedInfo of the Card with `card-id`, or nil."@@ -107,6 +107,11 @@[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."[]@@ -228,6 +233,21 @@: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 f967aa2b175..294e63db3df 100644--- a/src/metabase/model_persistence/events/persisted_info.clj+++ b/src/metabase/model_persistence/events/persisted_info.clj@@ -5,7 +5,6 @@[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)@@ -21,7 +20,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 (warehouses.db/database (:database_id card)) [:settings :persist-models-enabled])+ (get-in (model-persistence.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 7514c5c4f4c..b6b9756ee84 100644--- a/src/metabase/model_persistence/task/persist_refresh.clj+++ b/src/metabase/model_persistence/task/persist_refresh.clj@@ -14,7 +14,6 @@[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]@@ -24,7 +23,6 @@[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@@ -58,12 +56,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) (:state (model-persistence.db/persisted-info (:id persisted-info))))+ (when (contains? (persisted-info/refreshable-states) (model-persistence.db/persisted-info-state (: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 (queries.db/card (:card_id persisted-info))+ (let [card (model-persistence.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)@@ -140,8 +138,8 @@unpersist-fn (fn [](reduce (fn [stats persisted-info];; Since this could be long running, double check state just before deleting- (let [current-state (:state (model-persistence.db/persisted-info (:id persisted-info)))- card-info (queries.db/card (:card_id persisted-info))]+ (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))](if (or (contains? (persisted-info/prunable-states) current-state)(:archived card-info)(not= (:type card-info) :model))@@ -202,7 +200,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 (warehouses.db/database (:database_id persisted-info)))+ database (when (and persisted-info (model-persistence.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 aed892ac632..6f792f3aeb4 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/native-query-snippet id))+ (-> (api/read-check (native-query-snippets.db/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/native-query-snippet id)+ (let [snippet (native-query-snippets.db/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 2f9653b9f08..9314cfe94d8 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 native-query-snippet :- [:maybe ::native-query-snippets.schema/native-query-snippet]- "The ::native-query-snippets.schema/native-query-snippet with `id`, or nil."+(mu/defn snippet+ "The NativeQuerySnippet with `id`, or nil."[id :- ::lib.schema.id/native-query-snippet]- (t2/select-one :model/NativeQuerySnippet :id [:auto/param id]))+ (t2/select-one :model/NativeQuerySnippet :id id))(mu/defn snippet-name-exists?"Whether a NativeQuerySnippet named `snippet-name` exists."@@ -47,6 +47,11 @@[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 042f926b705..3ffc16f90c1 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 (:collection_id (native-query-snippets.db/native-query-snippet id))]+ (when-let [collection_id (native-query-snippets.db/snippet-collection-id 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/native-query-snippet id)))+ (for [path (serdes/mbql-deps true (:template_tags (native-query-snippets.db/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 45faadf2b5c..65beabcc972 100644--- a/src/metabase/notification/api/notification.clj+++ b/src/metabase/notification/api/notification.clj@@ -14,7 +14,6 @@[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]@@ -160,7 +159,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) (:email (users.db/user (:user_id recipient))))+ (or (-> recipient :user :email) (notification.db/user-email (: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 8d9939d9798..b643006d462 100644--- a/src/metabase/notification/api/unsubscribe.clj+++ b/src/metabase/notification/api/unsubscribe.clj@@ -6,10 +6,8 @@[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]@@ -32,9 +30,9 @@(let [notification (t2/hydrate (notification.db/notification-for-handler notification-handler-id) :payload)](case (:payload_type notification);; use the card name- :notification/card (:name (queries.db/card (-> notification :payload :card_id)))+ :notification/card (->> notification :payload :card_id notification.db/card-name);; use the dashboard name- :notification/dashboard (:name (dashboards.db/dashboard (-> notification :payload :dashboard_id)))+ :notification/dashboard (->> notification :payload :dashboard_id notification.db/dashboard-name)(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 9b8daa3d24e..21b20421063 100644--- a/src/metabase/notification/db.clj+++ b/src/metabase/notification/db.clj@@ -16,11 +16,6 @@[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}@@ -87,10 +82,10 @@;;; --------------------------------------------- Notification ----------------------------------------------(mu/defn notification :- [:maybe ::notification.schema/notification]- "The ::notification.schema/notification with `notification-id`, or nil."+(mu/defn notification+ "The Notification with `notification-id`, or nil."[notification-id :- ms/PositiveInt]- (t2/select-one :model/Notification :id [:auto/param notification-id]))+ (t2/select-one :model/Notification notification-id))(mu/defn notification-by-internal-id"The seeded Notification with `internal-id`, or nil."@@ -243,6 +238,11 @@[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 notification-subscription :- [:maybe ::notification.schema/notification-subscription]- "The ::notification.schema/notification-subscription with `subscription-id`, or nil."+(mu/defn subscription+ "The NotificationSubscription with `subscription-id`, or nil."[subscription-id :- ms/PositiveInt]- (t2/select-one :model/NotificationSubscription :id [:auto/param subscription-id]))+ (t2/select-one :model/NotificationSubscription subscription-id))(mu/defn subscriptions-for-notifications"The NotificationSubscriptions of the Notifications with `notification-ids` (nil entries are ignored)."@@ -376,6 +376,11 @@[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]@@ -669,6 +674,31 @@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]@@ -684,6 +714,17 @@[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 64898e334b5..32e684b1df9 100644--- a/src/metabase/notification/models.clj+++ b/src/metabase/notification/models.clj@@ -7,7 +7,6 @@[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]@@ -317,7 +316,7 @@[notification-handler](when-let [template-id (:template_id notification-handler)](let [channel-type (keyword (:channel_type notification-handler))- template-type (:channel_type (channel.db/channel-template template-id))]+ template-type (notification.db/channel-template-channel-type 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 1a7bd61a07b..60e90ab9fca 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 (some-> (:creator_id notification) users.db/user (select-keys [:id :first_name :last_name :email :common_name]))+ :creator (notification.db/user-summary (:creator_id notification)):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 9a2797b640e..e721b748cc4 100644--- a/src/metabase/notification/payload/execute.clj+++ b/src/metabase/notification/payload/execute.clj@@ -4,7 +4,6 @@[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]@@ -13,7 +12,6 @@[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]@@ -202,14 +200,13 @@:or {spill-budget (new-spill-budget)}}](log/with-context {:card_id card_id}(try- (when-let [card (let [card (queries.db/card card_id)]- (when-not (:archived card) card))]- (let [dashboard (dashboards.db/dashboard dashboard_id)+ (when-let [card (notification.db/unarchived-card card_id)]+ (let [dashboard (notification.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- (queries.db/card card-id))+ (notification.db/card card-id))attached-result? (and attached? (= card-id card_id))]{:card card:dashcard dashcard@@ -378,7 +375,7 @@"Returns the result for a card."[creator-id :- pos-int?card-id :- pos-int?]- (let [card (queries.db/card card-id)+ (let [card (notification.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 662f9cb788f..1a66cfc9738 100644--- a/src/metabase/notification/payload/impl/card.clj+++ b/src/metabase/notification/payload/impl/card.clj@@ -8,7 +8,6 @@[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]))@@ -25,7 +24,7 @@:status (:status card-result):error (:error card-result)}))){:card_part part- :card (queries.db/card card-id)+ :card (notification.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 289d79470f8..2de2e9426bf 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 (dashboards.db/dashboard dashboard-id) :tabs)+ dashboard (t2/hydrate (notification.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 8f505abed5c..29d437ce8bd 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 (:email (users.db/user user-id))]+ email (notification.db/user-email 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 9e7433eeec7..170f731b3e4 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 656f97fd34d..c3e7cf8cf78 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/notification-subscription subscription-id)+ (let [subscription (notification.db/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 baf971d4209..0a03948e87c 100644--- a/src/metabase/parameters/chain_filter.clj+++ b/src/metabase/parameters/chain_filter.clj@@ -91,7 +91,6 @@[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]))@@ -756,8 +755,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! (warehouse-schema.db/field field-id))- (params.field-values/get-or-create-linked-filter-field-values! (warehouse-schema.db/field field-id) 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))]{:values (cond->> valueslimit (take limit)):has_more_values (or (when limit@@ -820,7 +819,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?)- (:fk_target_field_id (warehouse-schema.db/field field-id)))]+ (parameters.db/field-fk-target-field-id field-id))](unremapped-chain-filter the-remapped-field-id(map #(cond-> %(= (:field-id %) field-id) (assoc :field-id pk-field-id))@@ -894,13 +893,12 @@(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 [field (warehouse-schema.db/field field-id)- base-type (:base_type field)]+ (let [base-type (parameters.db/field-base-type field-id)](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 (:name field)]+ (let [field-name (parameters.db/field-name field-id)](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@@ -946,7 +944,7 @@:has_more_values false}))(defn- search-cached-field-values? [field-id constraints]- (let [field (warehouse-schema.db/field field-id)]+ (let [field (parameters.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 5723936256e..f10a570cfe7 100644--- a/src/metabase/parameters/custom_values.clj+++ b/src/metabase/parameters/custom_values.clj@@ -17,7 +17,6 @@[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]]@@ -235,7 +234,7 @@(case (:values_source_type parameter):static-list (static-list-values parameter query-string):card (let [config (:values_source_config parameter)- card (queries.db/card (:card_id config))]+ card (parameters.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)@@ -286,7 +285,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 (queries.db/card (:card_id config))]+ (when-let [card (parameters.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 0757231d84b..d77b8351c52 100644--- a/src/metabase/parameters/db.clj+++ b/src/metabase/parameters/db.clj@@ -75,6 +75,11 @@: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]]@@ -85,6 +90,21 @@[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]@@ -100,6 +120,11 @@: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 0799897c84d..b701cebdc4c 100644--- a/src/metabase/parameters/field.clj+++ b/src/metabase/parameters/field.clj@@ -6,6 +6,7 @@[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]@@ -13,7 +14,6 @@[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)- (warehouse-schema.db/field fk-target-field-id)+ (parameters.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 (warehouse-schema.db/field remapped-field-id)))+ (api/check-404 (parameters.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 (warehouse-schema.db/field field-id))- (api/read-check (warehouse-schema.db/field field-id)))+ (api/check-404 (parameters.db/field field-id))+ (api/read-check (parameters.db/field field-id)))search-field (or (some->> (chain-filter/remapped-field-id field-id)- warehouse-schema.db/field)+ parameters.db/field)field)][field search-field]))diff --git a/src/metabase/permissions/db.clj b/src/metabase/permissions/db.cljindex e238d19d967..cf761ffa325 100644--- a/src/metabase/permissions/db.clj+++ b/src/metabase/permissions/db.clj@@ -17,16 +17,6 @@[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@@ -342,6 +332,11 @@[](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."[]@@ -549,6 +544,11 @@;;; ----------------------------------------------- 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,6 +745,11 @@[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 579766a02e7..696803f2c55 100644--- a/src/metabase/permissions/models/data_permissions.clj+++ b/src/metabase/permissions/models/data_permissions.clj@@ -18,7 +18,6 @@[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]@@ -1310,7 +1309,7 @@(let [table-or-id (first (keys table-perms))db-id (if (map? table-or-id)(:db_id table-or-id)- (:db_id (warehouse-schema.db/table table-or-id)))]+ (permissions.db/table-database-id 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 c6f492d345a..5a9bf1b80a0 100644--- a/src/metabase/permissions/models/permissions.clj+++ b/src/metabase/permissions/models/permissions.clj@@ -162,7 +162,6 @@[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]@@ -329,7 +328,7 @@(defmethod mi/can-create? :perms/use-parent-collection-perms[_model m](if-let [collection-id (:collection_id m)]- (mi/can-write? (collections.db/collection collection-id))+ (mi/can-write? (permissions.db/collection collection-id))(mi/can-write? collection.root/root-collection)));;; +----------------------------------------------------------------------------------------------------------------+@@ -560,7 +559,7 @@[collection-or-id](if (map? collection-or-id)collection-or-id- (collections.db/collection (u/the-id collection-or-id))))+ (permissions.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 68cc806d7a5..ced4ce28e3b 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]- (:is_tenant_group (permissions.db/permissions-group (u/the-id group-id))))+ (permissions.db/tenant-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 cbd0d9c5733..54bb71b74cf 100644--- a/src/metabase/permissions_rest/api.clj+++ b/src/metabase/permissions_rest/api.clj@@ -9,7 +9,6 @@[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]@@ -182,7 +181,7 @@(perms/check-manager-of-group id)(api/check-404 (empty? (perms/hidden-tenant-group-ids [id])))(api/check-404- (some-> (permissions.db/permissions-group id)+ (some-> (permissions-rest.db/permissions-group id)(t2/hydrate :members)(maybe-fix-name (setting/get :use-tenants)))))@@ -241,11 +240,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.db/permissions-group group-id)]+ (let [group (permissions-rest.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.db/permissions-group group-id)+ (u/prog1 (permissions-rest.db/permissions-group group-id)(events/publish-event! :event/group-update{:user-id api/*current-user-id*:object <>@@ -261,7 +260,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.db/permissions-group group-id)]+ (let [group (permissions-rest.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*}))@@ -329,7 +328,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.db/permissions-group-membership id)]+ (let [old (permissions-rest.db/group-membership id)](api/check-404 old)(perms/check-tenant-groups-visible! [(:group_id old)])(perms/check-manager-of-group (:group_id old))@@ -337,7 +336,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.db/permissions-group-membership (:id old))))+ (permissions-rest.db/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@@ -362,7 +361,7 @@"Remove a User from a PermissionsGroup (delete their membership)."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (let [membership (permissions.db/permissions-group-membership id)]+ (let [membership (permissions-rest.db/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 189cc28ffee..f1ef3c4174c 100644--- a/src/metabase/permissions_rest/db.clj+++ b/src/metabase/permissions_rest/db.clj@@ -62,6 +62,11 @@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]@@ -105,6 +110,11 @@[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 fc8e2b0d7cf..136e73a0afe 100644--- a/src/metabase/public_sharing_rest/api.clj+++ b/src/metabase/public_sharing_rest/api.clj@@ -9,9 +9,7 @@[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]@@ -29,7 +27,6 @@[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]@@ -117,62 +114,13 @@(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-card-row card-id options))+ (-> (api/check-404 (public-sharing-rest.db/public-card card-id options))combine-parameters-and-template-tags(t2/hydrate :param_fields)keep-param-fields-for-parameters@@ -247,7 +195,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 `active-card` call (each endpoint should+ Callers are responsible for resolving `card` themselves with a fresh `public-sharing-rest.db/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]@@ -399,7 +347,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-dashboard-row dashboard-id options))+ (-> (api/check-404 (public-sharing-rest.db/public-dashboard dashboard-id options))(t2/hydrate [:dashcards :card :series :dashcard/action] :tabs :param_fields)keep-param-fields-for-parametersparams/remove-param-fields-non-public-columns@@ -496,9 +444,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 (active-card card-id))+ (let [card (api/check-404 (public-sharing-rest.db/active-card card-id))dashboard (api/check-404 (public-sharing/public-uuid->model :model/Dashboard uuid))- dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))]+ dashcard (api/check-404 (public-sharing-rest.db/dashcard dashcard-id))](process-query-for-dashcard:dashboard dashboard:card card@@ -526,9 +474,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 (active-card card-id))+ (let [card (api/check-404 (public-sharing-rest.db/active-card card-id))dashboard (api/check-404 (public-sharing/public-uuid->model :model/Dashboard uuid))- dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))]+ dashcard (api/check-404 (public-sharing-rest.db/dashcard dashcard-id))](u/prog1 (process-query-for-dashcard:dashboard dashboard:card card@@ -781,9 +729,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 (active-card card-id))+ (let [card (api/check-404 (public-sharing-rest.db/active-card card-id))dashboard (api/check-404 (public-sharing/public-uuid->model :model/Dashboard uuid))- dashcard (api/check-404 (dashboards.db/dashboard-card dashcard-id))]+ dashcard (api/check-404 (public-sharing-rest.db/dashcard dashcard-id))](process-query-for-dashcard:dashboard dashboard:card card@@ -891,8 +839,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 (dashboards.db/dashboard-card dashcard-id))- card (api/check-404 (active-card card-id))]+ dashcard (api/check-404 (public-sharing-rest.db/dashcard dashcard-id))+ card (api/check-404 (public-sharing-rest.db/active-card card-id))](process-tiles-query-for-dashcard dashboard dashcard cardparameters zoom x y latField lonField)))@@ -915,7 +863,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-document-row document-id))+ (let [document (-> (api/check-404 (public-sharing-rest.db/public-document document-id));; Hydrate cards via Toucan batched hydration to avoid N+1 queries(t2/hydrate :cards))embedded-ids (set (prose-mirror/card-ids document))]@@ -935,9 +883,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 (document-content (public-sharing/public-uuid->id :model/Document uuid)))]+ (let [document (api/check-404 (public-sharing-rest.db/document-content (public-sharing/public-uuid->id :model/Document uuid)))](api/check-404 (when (contains? (set (prose-mirror/card-ids document)) card-id)- (active-card-in-document card-id (:id document))))))+ (public-sharing-rest.db/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 3802616bb6f..b9afa1a15d0 100644--- a/src/metabase/public_sharing_rest/db.clj+++ b/src/metabase/public_sharing_rest/db.clj@@ -9,8 +9,47 @@;;; ------------------------------------------------------ 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@@ -19,6 +58,17 @@;;; ----------------------------------------------------- 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 7e89cd2058f..fa7ff68983a 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.queries.db :as queries.db]+ [metabase.pulse.db :as pulse.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 queries.db/card)]+ card (->> notification :payload :card_id pulse.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 d57bd0ec6e6..a31c9fda14e 100644--- a/src/metabase/pulse/api/pulse.clj+++ b/src/metabase/pulse/api/pulse.clj@@ -25,7 +25,6 @@[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]@@ -85,7 +84,7 @@(update pulse :cards(fn [cards](mapv (fn [card] (assoc card :download_perms (case (perms/download-perms-level- (or (:dataset_query card) (:dataset_query (queries.db/card (:id card))))+ (or (:dataset_query card) (pulse.db/card-query (: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 de4526b558c..11b53b941a0 100644--- a/src/metabase/pulse/broken_subscriptions.clj+++ b/src/metabase/pulse/broken_subscriptions.clj@@ -3,10 +3,8 @@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)@@ -18,7 +16,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 (select-keys (users.db/user creator_id) [:first_name :last_name :email])+ (let [creator (pulse.db/user-name-and-email creator_id)bad-pulse-channels (pulse.db/pulse-channel-kinds-for-pulse bad-pulse-id)]{:pulse-id bad-pulse-id:pulse-name pulse-name@@ -48,7 +46,7 @@[dashboard-id original-dashboard-params](when (seq original-dashboard-params)(let [{:keys [resolved-params]} (t2/hydrate- (dashboards.db/dashboard dashboard-id)+ (pulse.db/dashboard-parameters 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@@ -73,7 +71,7 @@(let [{dashboard-name :namedashboard-description :descriptiondashboard-creator :creator} (t2/hydrate- (dashboards.db/dashboard dashboard-id)+ (pulse.db/dashboard-name-description-creator dashboard-id):creator)](for [broken-pulse broken-pulses](assocdiff --git a/src/metabase/pulse/db.clj b/src/metabase/pulse/db.cljindex d36236505c9..2a3b4d5cd1a 100644--- a/src/metabase/pulse/db.clj+++ b/src/metabase/pulse/db.clj@@ -9,16 +9,38 @@[metabase.util.malli.schema :as ms][toucan2.core :as t2]))-(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 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 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`."@@ -44,6 +66,11 @@[:= :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."[]@@ -59,16 +86,26 @@[user-ids :- [:set ::lib.schema.id/user]](t2/select-pk->fn :email :model/User, :id [:in user-ids]))-(mu/defn pulse :- [:maybe ::pulse.schema/pulse]- "The ::pulse.schema/pulse with `pulse-id`, or nil."+(mu/defn pulse+ "The Pulse with `pulse-id`, or nil."[pulse-id :- ::lib.schema.id/pulse]- (t2/select-one :model/Pulse :id [:auto/param pulse-id]))+ (t2/select-one :model/Pulse :id 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]@@ -243,6 +280,11 @@[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]@@ -368,6 +410,11 @@[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]@@ -383,6 +430,16 @@[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 8a75cad4e18..7490e3eaf8c 100644--- a/src/metabase/pulse/models/pulse.clj+++ b/src/metabase/pulse/models/pulse.clj@@ -22,7 +22,6 @@[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]@@ -32,7 +31,6 @@[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]@@ -76,7 +74,7 @@(let [defaults {:parameters []}dashboard-id (:dashboard_id notification)collection-id (if dashboard-id- (:collection_id (dashboards.db/dashboard dashboard-id))+ (pulse.db/dashboard-collection-id dashboard-id)(:collection_id notification))notification (->> (for [[k v] notification:when (some? v)]@@ -186,7 +184,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) (:dataset_query (queries.db/card (:id card)))) api/*current-user-id*)]+ (let [level (perms/download-perms-level (or (:dataset_query card) (pulse.db/card-query (:id card))) api/*current-user-id*)](and level (not= level :no)))true))@@ -367,12 +365,11 @@{:pre [(even? (count additional-conditions))]}(let [id (u/the-id notification-or-id)opts (apply hash-map additional-conditions)]- (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)))))+ (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)))(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 62ee8aba65a..17575bcfd32 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 (:details (pulse.db/pulse-channel channel-id))+ (let [details (pulse.db/pulse-channel-details 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 db3d990025a..bc114f2d263 100644--- a/src/metabase/pulse/schema.clj+++ b/src/metabase/pulse/schema.clj@@ -85,13 +85,11 @@[:emails {:optional true} [:maybe [:sequential :string]]]])(mr/def ::pulse-channel- "A PulseChannel as selected from the app DB: every column of `:pulse_channel`, with `:details` as stored rather- than as written."+ "A PulseChannel as selected from the app DB: every column of `:pulse_channel`."[:merge::pulse-channel.update[:map {:closed true}- [:id ms/PositiveInt]- [:details {:optional true} [:maybe [:map {::mr/deliberately-open true, :description "the column as stored"}]]]]])+ [:id ms/PositiveInt]]])(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 2adddefda61..33bfedb3a76 100644--- a/src/metabase/pulse/send.clj+++ b/src/metabase/pulse/send.clj@@ -3,10 +3,9 @@(: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]@@ -53,7 +52,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))- (channel.db/channel (:channel_id pulse-channel))))+ (pulse.db/channel (:channel_id pulse-channel))))(defn- get-notification-handler[pulse-channel]@@ -189,7 +188,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 (some-> dashboard_id dashboards.db/dashboard)+ (let [dashboard (pulse.db/dashboard dashboard_id)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 167ede39992..dc2bfefa63d 100644--- a/src/metabase/queries/cached_result.clj+++ b/src/metabase/queries/cached_result.clj@@ -14,7 +14,6 @@(: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]@@ -190,7 +189,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 (queries.db/stored-result-data (:id stored-result)))]+ (when-let [qp-result (deserialize-cached-result (:result_data 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 dc37665ce90..980f264e63c 100644--- a/src/metabase/queries/card_write_checks.clj+++ b/src/metabase/queries/card_write_checks.clj@@ -5,7 +5,6 @@(: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]@@ -48,7 +47,7 @@(cond;; you specified both - they must match(and specified-collection-id? dashboard-id)- (let [dashboard-collection-id (:collection_id (dashboards.db/dashboard dashboard-id))]+ (let [dashboard-collection-id (queries.db/dashboard-collection-id 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@@ -57,7 +56,7 @@specified-collection-id? collection-id- dashboard-id (:collection_id (dashboards.db/dashboard dashboard-id))+ dashboard-id (queries.db/dashboard-collection-id dashboard-id):else nil)))@@ -89,7 +88,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! (dashboards.db/dashboard dashboard-id)+ (card/check-shared-dashboard-timeline-permissions! (queries.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 ebce04fc147..369e5ee0126 100644--- a/src/metabase/queries/db.clj+++ b/src/metabase/queries/db.clj@@ -17,16 +17,6 @@[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@@ -64,10 +54,10 @@not-in-exploration-document]}(seq order-columns) (assoc :order-by (mapv (fn [column] [column :asc]) order-columns)))))-(mu/defn card :- [:maybe ::queries.schema/card]- "The ::queries.schema/card with `card-id`, or nil."+(mu/defn card+ "The Card with `card-id`, or nil."[card-id :- ::lib.schema.id/card]- (t2/select-one :model/Card :id [:auto/param card-id]))+ (t2/select-one :model/Card :id card-id))(mu/defn cards"The Cards with `card-ids` (nil entries, e.g. from virtual dashcards, are ignored)."@@ -94,6 +84,16 @@[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,6 +101,11 @@: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`.@@ -237,6 +242,11 @@[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]]@@ -259,11 +269,26 @@[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 e4770220ac3..64ff60280c8 100644--- a/src/metabase/queries/models/card.clj+++ b/src/metabase/queries/models/card.clj@@ -16,7 +16,6 @@[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]@@ -54,7 +53,6 @@[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]@@ -156,7 +154,7 @@[card](cond(contains? card :document_id) (:document_id card)- (:id card) (:document_id (queries.db/card (:id card)))+ (:id card) (queries.db/card-document-id (:id card)):else ::not-adjudicable))(defn- parent-document-permits?@@ -358,7 +356,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 (:name (warehouses.db/database db-id)))))]+ (format "%d %s" db-id (pr-str (queries.db/database-name 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)@@ -442,7 +440,7 @@changes)(defn- check-dashboard-internal-card-insert [card]- (let [correct-collection-id (:collection_id (dashboards.db/dashboard (:dashboard_id card)))+ (let [correct-collection-id (queries.db/dashboard-collection-id (:dashboard_id card))invalid? (or (and (contains? card :collection_id)(not= correct-collection-id (:collection_id card)))(not (contains? #{:question "question" nil} (:type card)))@@ -509,8 +507,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 (:parameters (queries.db/card po-id))- :dashboard (:parameters (dashboards.db/dashboard po-id)))+ :card (queries.db/card-parameters po-id)+ :dashboard (queries.db/dashboard-parameters po-id))affected-param-ids-set (cond;; update all parameters that use this card as source(:archived changes)@@ -1123,7 +1121,7 @@(defn- apply-dashboard-question-updates [card changes](if-let [dashboard-id (:dashboard_id changes)]- (assoc card :collection_id (:collection_id (dashboards.db/dashboard dashboard-id)))+ (assoc card :collection_id (queries.db/dashboard-collection-id dashboard-id))card))(defn- check-allowed-content@@ -1220,7 +1218,7 @@;;; ----------------------------------------------- Creating Cards ----------------------------------------------------(defn- autoplace-dashcard-for-card! [dashboard-id maybe-dashboard-tab-id card size]- (let [dashboard (t2/hydrate (dashboards.db/dashboard dashboard-id) :dashcards [:tabs :tab-cards])+ (let [dashboard (t2/hydrate (queries.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))]@@ -1249,7 +1247,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 (dashboards.db/dashboard dashboard-id)+ (events/publish-event! :event/dashboard-update {:object (queries.db/dashboard dashboard-id):user-id api/*current-user-id*}))(defn- autoplace-or-remove-dashcards-for-card!@@ -1323,7 +1321,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! (dashboards.db/dashboard dashboard-id) [input-card-data]))+ (check-shared-dashboard-timeline-permissions! (queries.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 befcb82be22..e9ead8a55b6 100644--- a/src/metabase/queries/models/query.clj+++ b/src/metabase/queries/models/query.clj@@ -1,7 +1,6 @@(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]@@ -166,8 +165,7 @@(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- (some-> (queries.db/card source-card-id)- (set/rename-keys {:database_id :database-id, :table_id :table-id})))]+ (queries.db/card-database-and-table-ids source-card-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 f1a990d98de..5945cd095d2 100644--- a/src/metabase/queries/models/stored_result.clj+++ b/src/metabase/queries/models/stored_result.clj@@ -10,8 +10,7 @@[metabase.models.interface :as mi][metabase.permissions.core :as perms][methodical.core :as methodical]- [toucan2.core :as t2]- [toucan2.tools.default-fields :as t2.default-fields]))+ [toucan2.core :as t2]))(methodical/defmethod t2/table-name :model/StoredResult [_model] :stored_result)@@ -23,6 +22,3 @@(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 452a9a8e33e..5644fe2fac4 100644--- a/src/metabase/queries_rest/api/card.clj+++ b/src/metabase/queries_rest/api/card.clj@@ -23,7 +23,6 @@[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]@@ -211,7 +210,7 @@"Get `Card` with ID."[id](let [with-last-edit-info #(first (revisions/with-last-edit-info [%] :card))- raw-card (queries.db/card id)]+ raw-card (queries-rest.db/card id)](-> raw-cardapi/read-checkhydrate-card-details@@ -428,7 +427,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.db/card id) api/check-404 api/read-check)+ card (-> (queries-rest.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))@@ -574,7 +573,7 @@(let [query (:dataset_query card-updates)](queries/check-card-can-be-saved! query card-type)(check-parameter-permissions (:parameters card-updates)- (or query (:dataset_query (queries.db/card id))))+ (or query (queries-rest.db/card-query 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)@@ -752,7 +751,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.db/card (u/the-id card))+ (events/publish-event! :event/card-update {:object (queries-rest.db/card (u/the-id card)):previous-object (get before (u/the-id card)):user-id api/*current-user-id*}))))@@ -802,7 +801,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.db/stored-result stored-result-id))]+ (let [sr (api/check-404 (queries-rest.db/stored-result stored-result-id))](queries/assert-can-view-card-snapshots! card-id)(api/check-404 (queries/cached-dataset sr sort))))@@ -826,7 +825,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.db/card resolved-card-id))]+ card (api/check-404 (queries-rest.db/card resolved-card-id))](if stored_result_id(do(api/read-check card)@@ -880,7 +879,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.db/card card-id)) export-format+ (api/check-404 (queries-rest.db/card card-id)) export-format:parameters parameters:constraints nil:context (api.dataset/export-format->context export-format)@@ -910,7 +909,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.db/card card-id)+ (let [{existing-public-uuid :public_uuid} (queries-rest.db/card-public-uuid-columns 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@@ -919,7 +918,7 @@{:public_uuid <>:made_public_by_id api/*current-user-id*})(events/publish-event! :event/card-public-link-created- {:object (queries.db/card card-id)+ {:object (queries-rest.db/card card-id):object-id card-id:user-id api/*current-user-id*}))))]{:uuid uuid}))@@ -943,7 +942,7 @@{:public_uuid nil:made_public_by_id nil})(events/publish-event! :event/card-public-link-deleted- {:object (queries.db/card card-id)+ {:object (queries-rest.db/card card-id):object-id card-id:user-id api/*current-user-id*})){:status 204, :body nil})@@ -965,7 +964,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.db/card card-id))]+ (let [card (api/check-404 (queries-rest.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 89b7b35a36a..61981cf8aeb 100644--- a/src/metabase/queries_rest/db.clj+++ b/src/metabase/queries_rest/db.clj@@ -85,11 +85,26 @@[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@@ -117,6 +132,11 @@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@@ -149,3 +169,8 @@[: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 63982a4e774..49066ffd23d 100644--- a/src/metabase/query_permissions/db.clj+++ b/src/metabase/query_permissions/db.clj@@ -7,6 +7,17 @@[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 e3d7ec98a58..14ce505289c 100644--- a/src/metabase/query_permissions/impl.clj+++ b/src/metabase/query_permissions/impl.clj@@ -16,7 +16,6 @@[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]@@ -183,7 +182,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}))- (queries.db/card card-id))+ (query-permissions.db/card-collection-id card-id))(throw (Exception. (tru "Card {0} does not exist." card-id)))))(mu/defn- source-card-read-perms :- [:set perms/PathSchema]@@ -351,13 +350,6 @@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)@@ -367,7 +359,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- (card-not-in-database card-id database-id)+ (query-permissions.db/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 489a80556e0..f5379ed021c 100644--- a/src/metabase/query_processor/api.clj+++ b/src/metabase/query_processor/api.clj@@ -27,6 +27,7 @@[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]@@ -43,7 +44,6 @@;; 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 (warehouse-schema.db/table table-id)+ (events/publish-event! :event/table-read {:object (query-processor.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 5003d985431..352f28b7c92 100644--- a/src/metabase/query_processor/db.clj+++ b/src/metabase/query_processor/db.clj@@ -8,6 +8,7 @@[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]))@@ -15,6 +16,11 @@"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 f75985354c1..d8cab028523 100644--- a/src/metabase/revisions/api.clj+++ b/src/metabase/revisions/api.clj@@ -120,10 +120,7 @@[:revision_id ms/PositiveInt]]](let [[model instance] (model-and-instance entity id)_ (api/write-check instance)- revision (api/check-404 (let [revision (revisions.db/revision revision-id)]- (when (and (= (name model) (:model revision))- (= id (:model_id revision)))- revision)))]+ revision (api/check-404 (revisions.db/revision (name model) id revision-id))];; 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 67fb507369f..925ede6fd42 100644--- a/src/metabase/revisions/db.clj+++ b/src/metabase/revisions/db.clj@@ -4,7 +4,6 @@(: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]@@ -83,10 +82,17 @@[card-ids :- [:set ::lib.schema.id/card]](t2/select-pk->fn :dataset_query :model/Card :id [:in card-ids]))-(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 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 dashcards"The DashboardCards of the Dashboard with `dashboard-id`."@@ -170,6 +176,13 @@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 6888c2b9145..3a020e49c95 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.queries.db :as queries.db]+ [metabase.revisions.db :as revisions.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 (queries.db/card id) [:moderation_reviews :moderator_details])+ (queries/maybe-unverify! (t2/hydrate (revisions.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 6f18c0c7908..f064447b2c4 100644--- a/src/metabase/revisions/models/revision.clj+++ b/src/metabase/revisions/models/revision.clj@@ -257,10 +257,7 @@[:entity [:fn toucan-model?]]]](let [{:keys [id user-id revision-id entity]} infomodel-name (name entity)- serialized-instance (let [revision (revisions.db/revision revision-id)]- (when (and (= model-name (:model revision))- (= id (:model_id revision)))- (:object revision)))]+ serialized-instance (revisions.db/revision-object model-name id revision-id)](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 2f00f0ade78..38e0bf5181d 100644--- a/src/metabase/sample_data/db.clj+++ b/src/metabase/sample_data/db.clj@@ -23,6 +23,11 @@[](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 80f6ffe4b64..05355115997 100644--- a/src/metabase/sample_data/impl.clj+++ b/src/metabase/sample_data/impl.clj@@ -12,7 +12,6 @@[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@@ -106,7 +105,7 @@(let [engine (sample-database-engine)details (try-to-extract-sample-database! engine)db (if (sample-data.db/sample-database-exists?)- (warehouses.db/database (first (sample-data.db/set-sample-database-details! details)))+ (sample-data.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 255a28c7570..2df37e708a8 100644--- a/src/metabase/segments/db.clj+++ b/src/metabase/segments/db.clj@@ -23,10 +23,10 @@:description description:definition definition))-(mu/defn segment :- [:maybe ::segments.schema/segment]- "The ::segments.schema/segment with `id`, or nil."+(mu/defn segment+ "The Segment with `id`, or nil."[id :- ::lib.schema.id/segment]- (t2/select-one :model/Segment :id [:auto/param id]))+ (t2/select-one :model/Segment :id id))(mu/defn unarchived-segments"The unarchived Segments, in case-insensitive name order."@@ -44,6 +44,21 @@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 41843225c15..29d2b86338d 100644--- a/src/metabase/segments/models/segment.clj+++ b/src/metabase/segments/models/segment.clj@@ -22,7 +22,6 @@[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]))@@ -96,7 +95,7 @@(defmethod mi/can-write? :model/Segment([instance](let [table (or (:table instance)- (warehouse-schema.db/table (:table_id instance)))]+ (segments.db/table (:table_id instance)))](and (or (mi/superuser?)(and (api/entitled-data-analyst?)(perms/user-has-permission-for-table?@@ -116,7 +115,7 @@(defmethod mi/can-create? :model/Segment[_model instance](let [table (or (:table instance)- (warehouse-schema.db/table (:table_id instance)))]+ (segments.db/table (:table_id instance)))](and (or (mi/superuser?)(and (api/entitled-data-analyst?)(perms/user-has-permission-for-table?@@ -162,7 +161,7 @@[{:keys [definition], table-id :table_id}](when (some? definition)(let [database-id (when table-id- (:db_id (warehouse-schema.db/table table-id)))]+ (segments.db/table-database-id table-id))](normalize-segment-definition definition table-id database-id))))(t2/define-before-insert :model/Segment@@ -207,7 +206,7 @@(defmethod mi/perms-objects-set :model/Segment[segment read-or-write](let [table (or (:table segment)- (warehouse-schema.db/table (u/the-id (:table_id segment))))]+ (segments.db/table-perms-columns (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 a5ae9b9b40f..1973f128132 100644--- a/src/metabase/segments/schema.clj+++ b/src/metabase/segments/schema.clj@@ -29,17 +29,16 @@(nil? (lib/current-limit query))))]]])(mr/def ::segment.definition- "The `:definition` a Segment create or update accepts: an MBQL query, possibly legacy, never empty."+ "The `:definition` column of a Segment, decoded."::lib-be.schema/maybe-legacy-query)(mr/def ::segment- "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."+ "A Segment as selected from the app DB: every column of `:segment`, 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 fc9e7c9e1f4..b26b5531289 100644--- a/src/metabase/session/api.clj+++ b/src/metabase/session/api.clj@@ -22,7 +22,6 @@[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]@@ -591,7 +590,7 @@(verify-second-factor! user-id code jti)(do(events/publish-event! :event/mfa-verification-failed- {:object (users.db/user user-id)})+ {:object (session.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@@ -661,7 +660,7 @@(or(confirm-enrollment! user-id code jti)(do (events/publish-event! :event/mfa-required-enrollment-failed- {:object (users.db/user user-id)})+ {:object (session.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 ce3f549abb2..cb843c04571 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-for-user-and-provider`,+ "The AuthIdentity of the User with `user-id` at `provider`, or nil. See `metabase.auth-identity.db/auth-identity`,which owns the AuthIdentity table."[user-id :- ::lib.schema.id/userprovider :- :string]- (auth-identity.db/auth-identity-for-user-and-provider user-id provider))+ (auth-identity.db/auth-identity user-id provider))(mu/defn auth-identity-exists?"Whether the User with `user-id` has an AuthIdentity at `provider`."@@ -145,11 +145,21 @@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 994c0883dbb..b06345ec8d4 100644--- a/src/metabase/session/models/session.clj+++ b/src/metabase/session/models/session.clj@@ -6,11 +6,10 @@[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]]@@ -97,7 +96,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 (auth-identity.db/auth-identity auth-identity-id)]+ (when-let [auth-identity (session.db/auth-identity-provider 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."))@@ -113,7 +112,7 @@(t2/define-after-insert :model/Session[session]- (when-let [user (users.db/user (:user_id session))]+ (when-let [user (session.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 a6d14a05fc9..9977dda34f1 100644--- a/src/metabase/setup_rest/api.clj+++ b/src/metabase/setup_rest/api.clj@@ -11,7 +11,6 @@[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]@@ -102,7 +101,7 @@(setting/restore-cache!)(throw e))))](let [{:keys [user-id session-key session]} (create!)- superuser (users.db/user user-id)]+ superuser (setup-rest.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 b0937538a20..e249bf3c324 100644--- a/src/metabase/setup_rest/db.clj+++ b/src/metabase/setup_rest/db.clj@@ -2,6 +2,7 @@"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]))@@ -15,3 +16,8 @@: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 85cd66ddfaa..db584d337b1 100644--- a/src/metabase/slackbot/db.clj+++ b/src/metabase/slackbot/db.clj@@ -2,6 +2,7 @@"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]))@@ -58,6 +59,11 @@slack-msg-id :- :string](t2/select-one-fn :user_id:model/MetabotMessage- :channel_id [:auto/param channel-id]- :slack_msg_id [:auto/param slack-msg-id]+ :channel_id channel-id+ :slack_msg_id 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 f03e6c6eebb..d3236ec34fd 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 (queries.db/card card-id)+ (let [card (slackbot.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 d7e723d88e6..f0f1415f593 100644--- a/src/metabase/sync/analyze/classify.clj+++ b/src/metabase/sync/analyze/classify.clj@@ -31,8 +31,7 @@[metabase.tracing.core :as tracing][metabase.util :as u][metabase.util.log :as log]- [metabase.util.malli :as mu]- [metabase.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util.malli :as mu]));;; +----------------------------------------------------------------------------------------------------------------+;;; | CLASSIFYING INDIVIDUAL FIELDS |@@ -85,7 +84,7 @@(or (:fingerprint field)(when (qp.store/initialized?)(:fingerprint (lib.metadata/field (qp.store/metadata-provider) (u/the-id field))))- (:fingerprint (warehouse-schema.db/field (u/the-id field))))))+ (sync.db/field-fingerprint (u/the-id field)))))([field :- i/FieldInstance{:keys [exists-name]} :- ClassifyOptsdiff --git a/src/metabase/sync/db.clj b/src/metabase/sync/db.cljindex 2266de63617..9225daf11a1 100644--- a/src/metabase/sync/db.clj+++ b/src/metabase/sync/db.clj@@ -30,16 +30,36 @@;;; ------------------------------------------------ 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]]@@ -320,6 +340,11 @@: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 8fcb8db79f4..89368e1b4c5 100644--- a/src/metabase/sync/sync.clj+++ b/src/metabase/sync/sync.clj@@ -15,6 +15,7 @@[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]@@ -22,8 +23,7 @@[metabase.tracing.core :as tracing][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]- [metabase.warehouse-schema.models.field :as field]- [metabase.warehouses.db :as warehouses.db])+ [metabase.warehouse-schema.models.field :as field])(: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" (:initial_sync_status (warehouses.db/database database-id))))+ (->> (scan-phases scan (= "complete" (sync.db/database-initial-sync-status 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 06e9df2af71..4506a353809 100644--- a/src/metabase/sync/sync_metadata/tables.clj+++ b/src/metabase/sync/sync_metadata/tables.clj@@ -21,8 +21,7 @@[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.warehouses.db :as warehouses.db])+ [metabase.warehouse-schema.humanization :as warehouse-schema.humanization])(:import(clojure.lang ITransientSet)))@@ -184,7 +183,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? (boolean (:is_sample (warehouses.db/database (:id database))))}))+ (insert-table! database table {:sample? (sync.db/database-sample? (:id database))}))(mu/defn- reactivate-table!"Mark an existing inactive Table active again, refreshing its cruft-dependent columns. `existing`@@ -206,7 +205,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? (boolean (:is_sample (warehouses.db/database (u/the-id database))))})+ (reactivate-table! database existing {:sample? (sync.db/database-sample? (u/the-id database))})(create-table! database table)));; TODO - should we make this logic case-insensitive like it is for fields?@@ -536,7 +535,7 @@context (transduce (partition-all table-sync-batch-size)(completing reconcile-batch){:created 0, :updated 0, :complete? true- :sample? (boolean (:is_sample (warehouses.db/database (:id database))))+ :sample? (sync.db/database-sample? (: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 043c20a274e..1336964db62 100644--- a/src/metabase/sync/task/sync_databases.clj+++ b/src/metabase/sync/task/sync_databases.clj@@ -27,8 +27,7 @@[metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]- [metabase.warehouses.core :as warehouses]- [metabase.warehouses.db :as warehouses.db])+ [metabase.warehouses.core :as warehouses])(:import(org.quartzJobDetail)))@@ -72,7 +71,7 @@(defn- sync-and-analyze-database*- (when-let [database (or (warehouses.db/database database-id)+ (when-let [database (or (sync.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)))]@@ -118,7 +117,7 @@:raw-job-context job-context:job-context (pr-str job-context)}))))- (:is_stub (warehouses.db/database database-id))+ (sync.db/database-stub? database-id)(log/warnf "Skipping scheduled sync for Database %d: it is a stub." database-id):else@@ -139,7 +138,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 (warehouses.db/database database-id)+ (when-let [database (or (sync.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 0ac706c9010..a61144aeab1 100644--- a/src/metabase/sync/util.clj+++ b/src/metabase/sync/util.clj@@ -25,7 +25,6 @@[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@@ -472,7 +471,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= (:initial_sync_status (warehouses.db/database (u/the-id database))) "complete")+ (when (not= (sync.db/database-initial-sync-status (u/the-id database)) "complete")(sync.db/update-database! (u/the-id database) {:initial_sync_status "complete":initial_sync_error nil})))@@ -480,7 +479,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= (:initial_sync_status (warehouses.db/database (u/the-id database))) "complete")+ (when (not= (sync.db/database-initial-sync-status (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 5e0854c9304..8f0ce3f8883 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 :- [:maybe ::task-history.schema/task-run]- "The ::task-history.schema/task-run with `id`, or nil."+(mu/defn task-run+ "The TaskRun with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/TaskRun :id [:auto/param id]))+ (t2/select-one :model/TaskRun :id 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 5bbdc4fb115..5fd5a79f447 100644--- a/src/metabase/tiles/api.clj+++ b/src/metabase/tiles/api.clj@@ -3,7 +3,6 @@(: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@@ -14,10 +13,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]@@ -306,7 +305,7 @@[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::legacy-ref][:lonField ::legacy-ref]]]- (process-tiles-query-for-card (api/check-404 (queries.db/card card-id))+ (process-tiles-query-for-card (api/check-404 (tiles.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@@ -328,7 +327,7 @@[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::legacy-ref][:lonField ::legacy-ref]]]- (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))+ (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))parameters zoom x y lat-field lon-field))diff --git a/src/metabase/tiles/db.clj b/src/metabase/tiles/db.cljnew file mode 100644index 00000000000..7edb716fab7--- /dev/null+++ b/src/metabase/tiles/db.clj@@ -0,0 +1,22 @@+(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 22544847cf9..26b4e594ba6 100644--- a/src/metabase/timeline/api/timeline.clj+++ b/src/metabase/timeline/api/timeline.clj@@ -4,7 +4,6 @@[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]@@ -162,6 +161,6 @@{:keys [include archived]} :- [:map {:closed true}[:include {:optional true} [:maybe [:= "events"]]][:archived {:default false} [:maybe :boolean]]]]- (api/read-check (collections.db/collection id))+ (api/read-check (timeline.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 e6d6846a4d6..784222cffa4 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 (:icon (timeline.db/timeline timeline_id))}))]+ {:icon (timeline.db/timeline-icon 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 1ade02d6d6a..d82b30514c9 100644--- a/src/metabase/timeline/db.clj+++ b/src/metabase/timeline/db.clj@@ -26,10 +26,15 @@(collection/visible-collection-filter-clause)]:order-by [[:%lower.name :asc]]}))-(mu/defn timeline :- [:maybe ::timeline.schema/timeline]- "The ::timeline.schema/timeline with `id`, or nil."+(mu/defn timeline+ "The Timeline with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/Timeline :id [:auto/param id]))+ (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))(mu/defn timelines-by-id"A map of id to Timeline for the Timelines with `ids`."@@ -59,15 +64,20 @@[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 :- [:maybe ::timeline.schema/timeline-event]- "The ::timeline.schema/timeline-event with `id`, or nil."+(mu/defn timeline-event+ "The TimelineEvent with `id`, or nil."[id :- ms/PositiveInt]- (t2/select-one :model/TimelineEvent :id [:auto/param id]))+ (t2/select-one :model/TimelineEvent :id 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 05267a7c3e7..356e7a8a29b 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/transform-run id)]+ (when-let [run (transforms.db/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 53eea743f79..b0602578aab 100644--- a/src/metabase/transforms/crud.clj+++ b/src/metabase/transforms/crud.clj@@ -21,8 +21,6 @@[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)@@ -30,7 +28,7 @@(defn check-database-feature"Check that the target database supports the required features for this transform."[transform]- (let [database (api/check-400 (warehouses.db/database (transforms-base.i/target-db-id transform))+ (let [database (api/check-400 (transforms.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))@@ -63,7 +61,7 @@and leaves the Metabase table with zero fields."[transform](let [db-id (transforms-base.i/target-db-id transform)- db (warehouses.db/database db-id)]+ db (transforms.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.")))))@@ -81,7 +79,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 (warehouse-schema.db/field checkpoint-filter-field-id)]+ field (transforms.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)@@ -95,7 +93,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 (warehouse-schema.db/field checkpoint-filter-field-id)]+ (when-let [field (transforms.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 b0d27edbf0a..7f8192856f0 100644--- a/src/metabase/transforms/db.clj+++ b/src/metabase/transforms/db.clj@@ -14,16 +14,6 @@[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@@ -35,10 +25,10 @@;;; ------------------------------------------------ Transform -------------------------------------------------(mu/defn transform :- [:maybe ::transforms.schema/transform]- "The ::transforms.schema/transform with `transform-id`, or nil."+(mu/defn transform+ "The Transform with `transform-id`, or nil."[transform-id :- ::lib.schema.id/transform]- (t2/select-one :model/Transform :id [:auto/param transform-id]))+ (t2/select-one :model/Transform :id transform-id))(mu/defn transforms"The Transforms with `transform-ids`."@@ -59,6 +49,11 @@[](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]]@@ -69,6 +64,16 @@[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]@@ -87,10 +92,10 @@;;; ---------------------------------------------- Transform tags -----------------------------------------------(mu/defn transform-tag :- [:maybe ::transforms.schema/transform-tag]- "The ::transforms.schema/transform-tag with `tag-id`, or nil."+(mu/defn tag+ "The TransformTag with `tag-id`, or nil."[tag-id :- ms/PositiveInt]- (t2/select-one :model/TransformTag :id [:auto/param tag-id]))+ (t2/select-one :model/TransformTag :id tag-id))(mu/defn existing-tag-ids"The subset of `tag-ids` that exist."@@ -169,10 +174,10 @@;;; ---------------------------------------------- Transform jobs -----------------------------------------------(mu/defn transform-job :- [:maybe ::transforms.schema/transform-job]- "The ::transforms.schema/transform-job with `job-id`, or nil."+(mu/defn job+ "The TransformJob with `job-id`, or nil."[job-id :- ms/PositiveInt]- (t2/select-one :model/TransformJob :id [:auto/param job-id]))+ (t2/select-one :model/TransformJob :id job-id))(mu/defn active-jobs"The active TransformJobs."@@ -184,6 +189,11 @@[](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]]@@ -230,10 +240,10 @@;;; ---------------------------------------------- Transform runs -----------------------------------------------(mu/defn transform-run :- [:maybe ::transforms.schema/transform-run]- "The ::transforms.schema/transform-run with `run-id`, or nil."+(mu/defn run+ "The TransformRun with `run-id`, or nil."[run-id :- ms/PositiveInt]- (t2/select-one :model/TransformRun :id [:auto/param run-id]))+ (t2/select-one :model/TransformRun :id run-id))(mu/defn runs"The TransformRuns with `run-ids`."@@ -812,6 +822,16 @@;;; ----------------------------------------------- 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]]@@ -832,6 +852,11 @@[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 da016df4e8c..fc8362ed3cb 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/transform-job job-id)+ (let [job (transforms.db/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 49902464ac9..f63ef82c60b 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 source-transform-id)]+ (let [transform (transforms.db/transform-snapshot 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 d3b14698a10..4883596de59 100644--- a/src/metabase/transforms/models/job_run.clj+++ b/src/metabase/transforms/models/job_run.clj@@ -40,7 +40,9 @@"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]- (let [job (transforms.db/transform-job job-id)]+ ;; :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)](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 6330d6389c7..68db91dd0f1 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- (:last_checkpoint_value (transforms.db/transform transform-id))))+ (transforms.db/transform-last-checkpoint-value 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 (:collection_id (transforms.db/transform id))]+ (when-let [collection-id (transforms.db/transform-collection-id 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 55f2f7d78aa..50ec32f59b6 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/transform-job pk)]+ (when-let [job (transforms.db/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/transform-job job-id)))))+ (transforms.schedule/initialize-job! (transforms.db/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 f2526217f7f..5ae42270ed4 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/transform-run pk)]+ (when-let [run (transforms.db/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 transform-id)+ (let [transform (transforms.db/transform-snapshot 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/transform-run run-id)]+ (when-let [run (transforms.db/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 506d73086fa..b69da3737f4 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/transform-tag pk)]+ (when-let [tag (transforms.db/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 dffb6a88afc..da22d706c1c 100644--- a/src/metabase/transforms/schema.clj+++ b/src/metabase/transforms/schema.clj@@ -81,8 +81,7 @@[:database {:optional true} [:maybe :int]][:type [:= "table"]][:schema {:optional true} [:maybe ms/NonBlankString]]- [:name :string]- [:target-incremental-strategy {:optional true} [:maybe ::target-incremental-strategy]]])+ [:name :string]])(mr/def ::table-incremental-target[:map {:closed true}diff --git a/src/metabase/transforms/util.clj b/src/metabase/transforms/util.cljindex 14d9aeb87c9..e6436e95be3 100644--- a/src/metabase/transforms/util.clj+++ b/src/metabase/transforms/util.clj@@ -27,9 +27,7 @@[metabase.transforms.models.transform-run :as transform-run][metabase.transforms.settings :as transforms.settings][metabase.util :as u]- [metabase.util.log :as log]- [metabase.warehouse-schema.db :as warehouse-schema.db]- [metabase.warehouses.db :as warehouses.db])+ [metabase.util.log :as log])(:import(java.sql SQLException)))@@ -76,8 +74,8 @@(if models-cache(get-in models-cache [model id])(case model- :model/Database (warehouses.db/database id)- :model/Table (warehouse-schema.db/table id))))+ :model/Database (transforms.db/database id)+ :model/Table (transforms.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 a349bf85a0f..3497b1dc174 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 :id [:auto/param transform-id]))+ (t2/select-one :model/Transform transform-id))(mu/defn update-transform!"Apply `changes` to the Transform with `transform-id`."@@ -47,6 +47,11 @@[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."@@ -56,6 +61,11 @@& 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 7bd1e439f11..f1d447563fc 100644--- a/src/metabase/transforms_base/util.clj+++ b/src/metabase/transforms_base/util.clj@@ -38,7 +38,6 @@[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)@@ -161,7 +160,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 (:table_id (warehouse-schema.db/field field-id)))]+ table-id (when field-id (transforms-base.db/field-table-id field-id))](table-template-tag-name (:query source) table-id)));;; ------------------------------------------------- Transform Normalization -------------------------------------------------@@ -538,7 +537,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})- (-> (warehouse-schema.db/table (:id table))+ (-> (transforms-base.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 14c9869ee2f..70c03bc8b4f 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.db/transform-dag-run run-id))]+ (let [dag-run (api/check-404 (transforms-rest.db/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.db/transform-dag-run run-id))]+ (let [dag-run (api/check-404 (transforms-rest.db/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 c6290ede316..a547d96d3e5 100644--- a/src/metabase/transforms_rest/api/transform_job.clj+++ b/src/metabase/transforms_rest/api/transform_job.clj@@ -10,7 +10,6 @@[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]@@ -171,7 +170,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.db/transform-job job-id) :tag_ids)]+ (let [existing-job (t2/hydrate (transforms-rest.db/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)@@ -206,7 +205,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.db/transform-job job-id)+ (-> (transforms-rest.db/job job-id)(t2/hydrate :tag_ids :last_run)(update :last_run transforms-base.u/present-run)))))@@ -214,7 +213,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.db/transform-job job-id) :tag_ids))+ (api/write-check (t2/hydrate (transforms-rest.db/job job-id) :tag_ids))(transforms-rest.db/delete-job! job-id)(transforms.core/delete-job! job-id)api/generic-204-no-content)@@ -232,7 +231,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.db/transform-job job-id))+ (api/write-check (transforms-rest.db/job job-id))(transforms-rest.api.u/async-run-response(deferred-tru "Job run started"):job_run_id@@ -247,7 +246,7 @@[{:keys [job-id]} :- [:map {:closed true}[:job-id ms/PositiveInt]]](log/info "Getting transform job" job-id)- (-> (api/read-check (transforms.db/transform-job job-id))+ (-> (api/read-check (transforms-rest.db/job job-id))(t2/hydrate :tag_ids :last_run)(update :last_run transforms-base.u/present-run)))@@ -325,13 +324,6 @@: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}@@ -339,7 +331,7 @@[:run-id ms/PositiveInt]]_query-params](api/read-check :model/TransformJob job-id)- (api/check-404 (job-run run-id job-id))+ (api/check-404 (transforms-rest.db/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))))@@ -350,7 +342,7 @@[:job-id ms/PositiveInt][:run-id ms/PositiveInt]]](api/write-check :model/TransformJob job-id)- (api/check-404 (job-run run-id job-id))+ (api/check-404 (transforms-rest.db/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 c29bd69f5b4..defeaf68f9d 100644--- a/src/metabase/transforms_rest/api/transform_tag.clj+++ b/src/metabase/transforms_rest/api/transform_tag.clj@@ -6,7 +6,6 @@[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]@@ -44,18 +43,18 @@{:keys [name]} :- [:map {:closed true}[:name ms/NonBlankString]]](log/info "Updating transform tag" tag-id)- (api/write-check (transforms.db/transform-tag tag-id))+ (api/write-check (transforms-rest.db/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.db/transform-tag tag-id))+ (transforms-rest.db/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.db/transform-tag tag-id))+ (api/write-check (transforms-rest.db/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 b3ee99afa5d..be51fbb47f1 100644--- a/src/metabase/transforms_rest/db.clj+++ b/src/metabase/transforms_rest/db.clj@@ -28,6 +28,11 @@[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]@@ -67,6 +72,11 @@[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]@@ -87,3 +97,16 @@"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 7402fe1be40..87070d268b9 100644--- a/src/metabase/upload/db.clj+++ b/src/metabase/upload/db.clj@@ -17,6 +17,16 @@[](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."[]@@ -110,6 +120,11 @@[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 549b2ae0f06..445985a4344 100644--- a/src/metabase/upload/impl.clj+++ b/src/metabase/upload/impl.clj@@ -33,10 +33,8 @@[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)@@ -634,7 +632,7 @@[:db-id ms/PositiveInt][:schema-name {:optional true} [:maybe :string]][:table-prefix {:optional true} [:maybe :string]]]]- (let [database (or (warehouses.db/database db-id)+ (let [database (or (upload.db/database db-id)(throw (ex-info (tru "The uploads database does not exist."){:status-code 422})))](check-can-create-upload database schema-name)@@ -990,7 +988,7 @@[:filename :string][:file (ms/InstanceOfClass File)][:action update-action-schema]]]- (let [table (api/check-404 (warehouse-schema.db/table table-id))+ (let [table (api/check-404 (upload.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 07e3d9d09df..fb6c84e04d1 100644--- a/src/metabase/upload/settings.clj+++ b/src/metabase/upload/settings.clj@@ -5,8 +5,7 @@[metabase.settings.core :refer [defsetting]][metabase.upload.db :as upload.db][metabase.util.i18n :refer [deferred-tru]]- [metabase.util.log :as log]- [metabase.warehouses.db :as warehouses.db]))+ [metabase.util.log :as log]))(defn- not-handling-api-request?[]@@ -17,7 +16,7 @@[db-id](or (not-handling-api-request?)(mi/can-write? :model/Database db-id)- (:is_attached_dwh (warehouses.db/database db-id))+ (upload.db/database-is-attached-dwh? db-id)(api/throw-403)))(defsetting uploads-settingsdiff --git a/src/metabase/users/db.clj b/src/metabase/users/db.cljindex b6ae753fb85..a3afa960b0c 100644--- a/src/metabase/users/db.clj+++ b/src/metabase/users/db.clj@@ -14,11 +14,6 @@[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 c7100bc0941..25241dae0c1 100644--- a/src/metabase/users_rest/api.clj+++ b/src/metabase/users_rest/api.clj@@ -10,7 +10,6 @@[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]@@ -22,7 +21,6 @@[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]@@ -333,7 +331,7 @@[user](let [enabled? (appearance/custom-homepage)id (appearance/custom-homepage-dashboard)- dash (when (pos-int? id) (dashboards.db/dashboard id))+ dash (users-rest.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}))))@@ -570,7 +568,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.db/user id)+ (events/publish-event! :event/user-update {:object (users-rest.db/user id):previous-object user-before-update:user-id api/*current-user-id*}))(maybe-update-user-personal-collection-name! user-before-update body)@@ -716,7 +714,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.db/user id) :user-id api/*current-user-id*})+ (events/publish-event! :event/user-deactivated {:object (users-rest.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 1862503e9b5..a5970d10132 100644--- a/src/metabase/users_rest/db.clj+++ b/src/metabase/users_rest/db.clj@@ -75,6 +75,13 @@[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)."[]@@ -97,6 +104,11 @@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 dde6e997eac..c29d00138be 100644--- a/src/metabase/view_log/db.clj+++ b/src/metabase/view_log/db.clj@@ -3,6 +3,7 @@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]@@ -48,6 +49,11 @@(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 002eb5a2e70..b7f27431789 100644--- a/src/metabase/view_log/events/view_log.clj+++ b/src/metabase/view_log/events/view_log.clj@@ -10,7 +10,6 @@[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]@@ -170,7 +169,7 @@(try(when (and (= context :ad-hoc)(or (analytics/data-app-client?)- (= :model (:type (queries.db/card card-id)))))+ (= :model (view-log.db/card-type 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 c11762ce0dc..9d4d3936933 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 :- [:maybe ::warehouse-schema.schema/field]+(mu/defn field"The ::warehouse-schema.schema/field with `field-id`, or nil."[field-id :- ::lib.schema.id/field]- (t2/select-one :model/Field :id [:auto/param field-id] {:from [(warehouse-schema-overlay/field-query)]}))+ (t2/select-one :model/Field :id 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,6 +45,11 @@[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@@ -52,6 +57,12 @@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]@@ -410,10 +421,10 @@;;; ------------------------------------------------- ::warehouse-schema.schema/table --------------------------------------------------(mu/defn table :- [:maybe ::warehouse-schema.schema/table]+(mu/defn table"The ::warehouse-schema.schema/table with `table-id`, or nil."[table-id :- [:maybe ::lib.schema.id/table]]- (t2/select-one :model/Table :id [:auto/param table-id] {:from [(warehouse-schema-overlay/table-query)]}))+ (t2/select-one :model/Table :id table-id {:from [(warehouse-schema-overlay/table-query)]}))(mu/defn tables"The Tables with `table-ids`."@@ -427,6 +438,16 @@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]@@ -516,11 +537,26 @@;;; ------------------------------------------------ ::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 1d11bee0dd1..dbefc373772 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.models.field-values :as field-values]- [metabase.warehouses.db :as warehouses.db]))+ [metabase.warehouse-schema.db :as warehouse-schema.db]+ [metabase.warehouse-schema.models.field-values :as field-values]))(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 (warehouses.db/database db-id))+ driver (:engine (warehouse-schema.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 74c31fcf54e..b6d5ec5328c 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 (:db_id (warehouse-schema.db/table table-id))+ (let [database-id (warehouse-schema.db/table-database-id 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 b7261d2c0de..fe88f7c2fdd 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 table-id)]+ (let [{table-name :name, schema :schema} (warehouse-schema.db/table-name-and-schema table-id)](conj (when schema[schema])table-name))))@@ -407,7 +407,7 @@(mdb/memoize-for-application-db(fn [field-id]{:pre [(integer? field-id)]}- (:table_id (warehouse-schema.db/field field-id)))))+ (warehouse-schema.db/field-table-id 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 2d3e1381441..34fd175bcfb 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 field-id)+ (recur (or (warehouse-schema.db/field-values-eligibility 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 f87591e5e05..b1052c008c9 100644--- a/src/metabase/warehouse_schema/models/table.clj+++ b/src/metabase/warehouse_schema/models/table.clj@@ -19,7 +19,6 @@[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]))@@ -233,7 +232,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 (:engine (warehouses.db/database (:db_id table)))))+ (driver/default-field-order (warehouse-schema.db/database-engine (:db_id table)))):data_layer :internal:data_authority :unconfigured}](collection/check-allowed-content :table (:collection_id table))@@ -568,7 +567,7 @@(defn database"Return the `Database` associated with this `Table`."[table]- (warehouses.db/database (:db_id table)))+ (warehouse-schema.db/database (:db_id table)));;; ------------------------------------------------- Serialization -------------------------------------------------(defmethod serdes/deserialization-dependencies "Table" [{:keys [collection_id transform_id]}]@@ -592,7 +591,7 @@(merge fields settings field-settings dimensions segments measures)))(defmethod serdes/generate-path "Table" [_ table]- (let [db-name (:name (warehouses.db/database (:db_id table)))]+ (let [db-name (warehouse-schema.db/database-name (: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 21a1de170d8..28a7748941a 100644--- a/src/metabase/warehouse_schema/table.clj+++ b/src/metabase/warehouse_schema/table.clj@@ -9,7 +9,6 @@[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)@@ -331,7 +330,7 @@include-database?(assoc :db (when-let [database (when (int? database_id)(or (get databases database_id)- (warehouses.db/database database_id)))]+ (warehouse-schema.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 691a371c0b3..f490555e386 100644--- a/src/metabase/warehouse_schema_rest/api/field.clj+++ b/src/metabase/warehouse_schema_rest/api/field.clj@@ -17,7 +17,6 @@[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]@@ -91,9 +90,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.db/field target-field-id)+ (-> (warehouse-schema-rest.db/field target-field-id):table_id- warehouse-schema.db/table+ warehouse-schema-rest.db/tableschema.table/check-data-model-perms))))(defn- clear-dimension-on-fk-change! [{:keys [dimensions], :as _field}]@@ -171,7 +170,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.db/field id)+ (let [field (-> (warehouse-schema-rest.db/field id)api/write-check(t2/hydrate :dimensions))new-semantic-type (keyword (get body :semantic_type (:semantic_type field)))@@ -217,7 +216,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.db/field id)]+ (let [updated (warehouse-schema-rest.db/field id)](u/prog1 (-> updated(t2/hydrate :dimensions :has_field_values)(schema.field/hydrate-target-with-data-model-perms))@@ -281,7 +280,7 @@:type dimension-type:name dimension-name:human_readable_field_id human-readable-field-id})))- (events/publish-event! :event/field-update {:object (warehouse-schema.db/field id)+ (events/publish-event! :event/field-update {:object (warehouse-schema-rest.db/field id):user-id api/*current-user-id*})(warehouse-schema-rest.db/dimension-for-field id))@@ -295,7 +294,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.db/field id)+ (events/publish-event! :event/field-update {:object (warehouse-schema-rest.db/field id):user-id api/*current-user-id*})api/generic-204-no-content)@@ -314,7 +313,7 @@_bodyrequest](some-> (data-apps/request-data-app request) (data-apps/check-field id))- (let [field (api/query-check (warehouse-schema.db/field id))]+ (let [field (api/query-check (warehouse-schema-rest.db/field id))](parameters.field/field->values field)))(defn- validate-human-readable-pairs@@ -340,7 +339,7 @@_query-params{value-pairs :values} :- [:map {:closed true}[:values ms/FieldValuesList]]]- (let [field (api/write-check (warehouse-schema.db/field id))]+ (let [field (api/write-check (warehouse-schema-rest.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'.")])@@ -366,7 +365,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.db/field id))+ (let [field (api/write-check (warehouse-schema-rest.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)@@ -390,7 +389,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.db/field id)))+ (field-values/clear-field-values-for-field! (api/write-check (warehouse-schema-rest.db/field id))){:status :success});;; --------------------------------------------------- Searching ----------------------------------------------------@@ -415,8 +414,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.db/field id))- search-field (api/check-404 (warehouse-schema.db/field search-id))]+ (let [field (api/check-404 (warehouse-schema-rest.db/field id))+ search-field (api/check-404 (warehouse-schema-rest.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))))@@ -438,8 +437,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.db/field id) api/check-404 api/read-check)- remapped-field (-> (warehouse-schema.db/field remapped-id) api/check-404 api/read-check)+ (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)value (parameters.field/parse-query-param-value-for-field field value)](parameters.field/remapped-value field remapped-field value)))@@ -456,4 +455,4 @@_bodyrequest](some-> (data-apps/request-data-app request) (data-apps/check-field id))- (-> (warehouse-schema.db/field id) api/read-check xrays/related))+ (-> (warehouse-schema-rest.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 0116113fb9b..0e84980d16a 100644--- a/src/metabase/warehouse_schema_rest/api/table.clj+++ b/src/metabase/warehouse_schema_rest/api/table.clj@@ -6,7 +6,6 @@[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]@@ -34,11 +33,9 @@[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]))@@ -145,7 +142,7 @@(let [api-perm-check-fn (if include_editable_data_modelschema.table/check-data-model-permsapi/read-check)]- (-> (api/check-404 (warehouse-schema.db/table id))+ (-> (api/check-404 (warehouse-schema-rest.db/table id))api-perm-check-fn(t2/hydrate :db :pk_field :collection)schema.table/present-table)))@@ -157,7 +154,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.db/table table-id)+ (let [table (warehouse-schema-rest.db/table table-id)db-id (:db_id table)](api/query-check table)(qp.store/with-metadata-provider db-id@@ -223,7 +220,7 @@(u/update-some :data_source keyword)not-empty)](schema.table-user-settings/upsert-user-settings existing-table changes))- (let [updated-table (warehouse-schema.db/table id)+ (let [updated-table (warehouse-schema-rest.db/table id)changed-field-order? (not= (:field_order updated-table) (:field_order existing-table))](if changed-field-order?(do@@ -240,7 +237,7 @@(quick-task/submit-task!(fn [](doseq [[db-id tables] (group-by :db_id newly-unhidden)]- (let [database (warehouses.db/database db-id)]+ (let [database (warehouse-schema-rest.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@@ -255,7 +252,7 @@(defn- check-can-publish-tables-to-collection- (let [collection (api/check-404 (collections.db/collection collection-id))]+ (let [collection (api/check-404 (warehouse-schema-rest.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))))@@ -396,7 +393,7 @@:origin_id (:id origin-field):origin origin-field:destination_id (:fk_target_field_id origin-field)- :destination (t2/hydrate (warehouse-schema.db/field (:fk_target_field_id origin-field)) :table)})))+ :destination (t2/hydrate (warehouse-schema-rest.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;;@@ -410,7 +407,7 @@are eligible for FieldValues."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (let [table (api/write-check (warehouse-schema.db/table id))]+ (let [table (api/write-check (warehouse-schema-rest.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@@ -434,7 +431,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.db/table id))+ (api/write-check (warehouse-schema-rest.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})@@ -447,7 +444,7 @@"Return related entities."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (-> (warehouse-schema.db/table id) api/read-check xrays/related))+ (-> (warehouse-schema-rest.db/table id) api/read-check xrays/related))(api.macros/defendpoint :put "/:id/fields/order" :- [:map[:success [:= true]]]@@ -460,8 +457,8 @@[:sequential ms/PositiveInt][:map {:closed true} [:field_order [:sequential ms/PositiveInt]]]]](let [field-order (if (map? body) (:field_order body) body)]- (-> (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)+ (-> (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):user-id api/*current-user-id*})){:success true})@@ -552,10 +549,8 @@"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.db/table id))- database (api/check-404 (let [database (warehouses.db/database (:db_id table))]- (when (nil? (:router_database_id database))- database)))]+ (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)))](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 dd0c9dee7f6..c01ce648929 100644--- a/src/metabase/warehouse_schema_rest/db.clj+++ b/src/metabase/warehouse_schema_rest/db.clj@@ -25,6 +25,11 @@(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."@@ -125,6 +130,26 @@[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 60a593ffbc3..3f07a45a7c7 100644--- a/src/metabase/warehouses/db.clj+++ b/src/metabase/warehouses/db.clj@@ -9,10 +9,20 @@[metabase.warehouses.schema :as warehouses.schema][toucan2.core :as t2]))-(mu/defn database :- [:maybe ::warehouses.schema/database]- "The ::warehouses.schema/database with `database-id`, or nil."+(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."[database-id :- [:maybe ::lib.schema.id/database]]- (t2/select-one :model/Database :id [:auto/param database-id]))+ (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))(mu/defn databases"The Databases with `database-ids`."diff --git a/src/metabase/warehouses/models/database.clj b/src/metabase/warehouses/models/database.cljindex 7813f56fddb..f301374dc6a 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]- (:router_database_id (warehouses.db/database db-id)))))+ (warehouses.db/router-database-id 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? (:router_database_id (warehouses.db/database database-id))))+ (nil? (warehouses.db/router-database-id 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 d5f74edca25..fad77d6b595 100644--- a/src/metabase/warehouses/util.clj+++ b/src/metabase/warehouses/util.clj@@ -22,10 +22,9 @@[: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 (let [database (warehouses.db/database id)]- (when (or include-destination-databases?- (nil? (:router_database_id database)))- database)))+ database (api/check-404 (if include-destination-databases?+ (warehouses.db/database id)+ (warehouses.db/non-destination-database id)))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 68d7c69a69a..cdb6ddc978d 100644--- a/src/metabase/warehouses_rest/api.clj+++ b/src/metabase/warehouses_rest/api.clj@@ -45,7 +45,6 @@[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]))@@ -915,7 +914,7 @@[:details ms/DatabaseDetails][:id {:optional true} [:maybe ms/PositiveInt]]]]]](api/check-superuser)- (let [database (when id (api/write-check (warehouses.db/database id)))+ (let [database (when id (api/write-check (warehouses-rest.db/database id)))details-or-error (if database(test-existing-database-details database engine details)(warehouses/test-connection-details engine details))]@@ -1018,7 +1017,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.db/database id))+ (let [existing-database (api/write-check (warehouses-rest.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)@@ -1112,7 +1111,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.db/database id)]+ (let [db (warehouses-rest.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@@ -1139,7 +1138,7 @@[:id ms/PositiveInt]]](api/check-superuser)(t2/with-transaction [_conn]- (api/let-404 [db (warehouses.db/database id)]+ (api/let-404 [db (warehouses-rest.db/database id)](api/check-403 (mi/can-write? db))(warehouses-rest.db/delete-destination-databases! id)(database-routing/delete-associated-database-router! id)@@ -1451,7 +1450,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.db/database id))+ (let [{:as database :keys [engine]} (api/check-404 (warehouses-rest.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 ecacff44602..113cbfe02b4 100644--- a/src/metabase/warehouses_rest/db.clj+++ b/src/metabase/warehouses_rest/db.clj@@ -249,6 +249,11 @@[](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 95bf2c342c1..085196a1d2e 100644--- a/src/metabase/xrays/api/automagic_dashboards.clj+++ b/src/metabase/xrays/api/automagic_dashboards.clj@@ -5,9 +5,7 @@[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]@@ -15,9 +13,7 @@[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]@@ -25,8 +21,6 @@[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]@@ -102,7 +96,7 @@"Return a list of candidates for automagic dashboards ordered by interestingness."[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]- (-> (warehouses.db/database id)+ (-> (xrays.db/database id)api/read-checkautomagic-dashboards.core/candidate-tables))@@ -135,20 +129,19 @@(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 (warehouse-schema.db/table (ensure-int table-id-str)))))+ (api/read-check (xrays.db/table (ensure-int table-id-str)))))(defmethod ->entity :segment[_entity-type segment-id-str]- (api/read-check (segments.db/segment (ensure-int segment-id-str))))+ (api/read-check (xrays.db/segment (ensure-int segment-id-str))))(defmethod ->entity :model[_entity-type card-id-str]- (let [card (queries.db/card (ensure-int card-id-str))]- (api/read-check (when (= :model (:type card)) card))))+ (api/read-check (xrays.db/model-card (ensure-int card-id-str))))(defmethod ->entity :question[_entity-type card-id-str]- (api/read-check (queries.db/card (ensure-int card-id-str))))+ (api/read-check (xrays.db/card (ensure-int card-id-str))))(mu/defn adhoc-query-instance :- [:and(ms/InstanceOf :model/Query)@@ -168,11 +161,11 @@(defmethod ->entity :field[_entity-type field-id-str]- (api/read-check (warehouse-schema.db/field (ensure-int field-id-str))))+ (api/read-check (xrays.db/field (ensure-int field-id-str))))(defmethod ->entity :transform[_entity-type transform-name]- (api/read-check (collections.db/collection (transforms.materialize/get-collection transform-name)))+ (api/read-check (xrays.db/collection (transforms.materialize/get-collection transform-name)))transform-name)(def ^:private entities@@ -314,7 +307,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 (warehouse-schema.db/table linked-table-id)+ (let [table (xrays.db/table linked-table-id)mp (lib-be/application-database-metadata-provider (:db_id table))](automagic-dashboards.core/automagic-analysistable@@ -379,8 +372,8 @@[{:keys [model-index-id pk-id]} :- [:map {:closed true}[:model-index-id :int][:pk-id :int]]]- (api/let-404 [model-index (indexed-entities.db/model-index model-index-id)- model (queries.db/card (:model_id model-index))]+ (api/let-404 [model-index (xrays.db/model-index model-index-id)+ model (xrays.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 d05333a4924..7a1544a16f5 100644--- a/src/metabase/xrays/automagic_dashboards/core.clj+++ b/src/metabase/xrays/automagic_dashboards/core.clj@@ -154,7 +154,6 @@[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]@@ -164,9 +163,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.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]@@ -203,7 +200,7 @@(mu/defmethod ->root :model/Segment :- ::ads/root[segment :- [:map [:definition [:maybe ::segments.schema/definition]]]]- (let [table (->> segment :table_id warehouse-schema.db/table)]+ (let [table (->> segment :table_id xrays.db/table)]{:entity segment:full-name (tru "{0} in the {1} segment" (:display_name table) (:name segment)):short-name (:display_name table)@@ -216,7 +213,7 @@(mu/defmethod ->root :xrays/Metric :- ::ads/root[{:keys [table-id], :as metric} :- ::ads/metric]- (let [table (some->> table-id warehouse-schema.db/table)]+ (let [table (some->> table-id xrays.db/table)]{:entity metric:full-name (if (:id metric)(trun "{0} metric" "{0} metrics" (:name metric))@@ -259,7 +256,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)]- (queries.db/card source-card-id)))+ (xrays.db/card source-card-id)))(mu/defn- table-like?[{query :dataset_query, :as _card-or-question} :- ::ads/card-or-question]@@ -287,7 +284,7 @@source-question(assoc :entity_type :entity/GenericTable))(native-query? card) (-> card (assoc :entity_type :entity/GenericTable))- :else (->> card table-id warehouse-schema.db/table)))+ :else (->> card table-id xrays.db/table)))(mu/defmethod ->root :model/Card :- ::ads/root[card :- ::ads/card-or-question]@@ -415,7 +412,7 @@(let [db-id (or ((some-fn :db_id :database_id) source)(throw (ex-info "Source is missing Database ID"{:source source})))]- (warehouses.db/database db-id)))+ (xrays.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 66054603c33..f44fb03a19a 100644--- a/src/metabase/xrays/automagic_dashboards/interesting.clj+++ b/src/metabase/xrays/automagic_dashboards/interesting.clj@@ -53,9 +53,7 @@[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]@@ -126,7 +124,7 @@(condfull-name full-namelink (format "%s → %s"- (-> (warehouse-schema.db/field link) :display_name (str/replace #"(?i)\sid$" ""))+ (-> (xrays.db/field link) :display_name (str/replace #"(?i)\sid$" ""))display_name):else display_name))@@ -374,7 +372,7 @@;; TODO - Deduplicate from core(mu/defn- source->db :- (ms/InstanceOf :model/Database)[source :- (ms/InstanceOf #{:model/Table :model/Card})]- (warehouses.db/database ((some-fn :db_id :database_id) source)))+ (xrays.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 1be054be46c..ed6f877f84d 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)- (warehouse-schema.db/field id-or-name))+ (xrays.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 95beb0b5caf..cb37a87f8bc 100644--- a/src/metabase/xrays/db.clj+++ b/src/metabase/xrays/db.clj@@ -6,9 +6,21 @@[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]]@@ -66,6 +78,16 @@[:= :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]@@ -126,6 +148,16 @@: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]@@ -154,12 +186,27 @@[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@@ -222,3 +269,8 @@(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 25cdb758405..d189fa48cbf 100644--- a/src/metabase/xrays/related.clj+++ b/src/metabase/xrays/related.clj@@ -4,17 +4,14 @@[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]))@@ -123,9 +120,9 @@(defn- linking-to[table](->> (xrays.db/fk-target-field-ids-for-table (:id table))- (map (comp warehouse-schema.db/table+ (map (comp xrays.db/table:table_id- warehouse-schema.db/field))+ xrays.db/field))distinctfilter-visible(take max-matches)))@@ -134,7 +131,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 warehouse-schema.db/table)+ (map xrays.db/table)filter-visible(take max-matches))[]))@@ -143,7 +140,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 queries.db/card)+ (map xrays.db/card)filter-visible(take max-matches))[]))@@ -191,7 +188,7 @@(->> cards(m/distinct-by :collection_id)interesting-mix- (keep (comp collections.db/collection :collection_id))+ (keep (comp xrays.db/collection :collection_id))filter-visible))(defmulti related@@ -201,7 +198,7 @@(defmethod related :model/Card[card]- (let [table (warehouse-schema.db/table (:table_id card))+ (let [table (xrays.db/table (:table_id card))similar-questions (similar-questions card)similar-metrics (similar-metrics card)]{:table table@@ -220,7 +217,7 @@(defmethod related :xrays/Metric[metric]- (let [table (warehouse-schema.db/table (:table_id metric))]+ (let [table (xrays.db/table (:table_id metric))]{:table table:segments (->> tablesegments-for-table@@ -229,7 +226,7 @@(defmethod related :model/Segment[segment]- (let [table (warehouse-schema.db/table (:table_id segment))]+ (let [table (xrays.db/table (:table_id segment))]{:table table:metrics (metrics-for-table table):segments (->> table@@ -253,7 +250,7 @@(defmethod related :model/Field[field]- (let [table (warehouse-schema.db/table (:table_id field))]+ (let [table (xrays.db/table (:table_id field))]{:table table:segments (->> tablesegments-for-table@@ -270,7 +267,7 @@(defmethod related :model/Dashboard[dashboard]- (let [cards (map queries.db/card (xrays.db/card-ids-for-dashboard (:id dashboard)))]+ (let [cards (map xrays.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 c5fd76c777f..71544658ad9 100644--- a/src/metabase/xrays/transforms/core.clj+++ b/src/metabase/xrays/transforms/core.clj@@ -10,7 +10,6 @@[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]]@@ -37,7 +36,7 @@field-name[:field (id :guard integer?) _]- (:name (warehouse-schema.db/field id))))+ (xrays.db/field-name id)))(mu/defn- infer-resulting-dimensions :- DimensionBindings[bindings :- Bindingsdiff --git a/src/metabase/xrays/transforms/materialize.clj b/src/metabase/xrays/transforms/materialize.cljindex df064d06d6e..59e6b396d71 100644--- a/src/metabase/xrays/transforms/materialize.clj+++ b/src/metabase/xrays/transforms/materialize.clj@@ -1,7 +1,6 @@(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]@@ -17,7 +16,7 @@(defn- root-container-location[](collection/children-location- (collections.db/collection (get-or-create-root-container-collection!))))+ (xrays.db/collection-location-columns (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 5d61eb22bad..5bcba450bcc 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-for-user-and-provider+ (doseq [[fn-name f] {"auth-identity" auth-identity.db/auth-identity"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-for-user-and-provider user-id "google"))))+ (is (= ai-id (:id (auth-identity.db/auth-identity 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-for-user-and-provider user-id "password")))+ (is (nil? (auth-identity.db/auth-identity 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 f016ec0bd6c..b23c2583fb9 100644--- a/test/metabase/auth_identity/session_test.clj+++ b/test/metabase/auth_identity/session_test.clj@@ -34,7 +34,8 @@(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"}]+ :provider "google"+ :metadata {:sso_source "google"}}](let [device-info {:device_id "test-device-456":embedded false:token_exchange false@@ -50,7 +51,8 @@(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"}]+ :provider "ldap"+ :metadata {:login_attributes {:uid "testuser"}}}](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 cc665d11c48..50b4dadef50 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 :details {:url "https://metabase.com" :auth-method "none"})]+ (mt/with-temp [:model/Channel {chn-1 :id} (assoc default-test-channel :type :channel/http)](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 2561982e2a1..2492d68fc1f 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 #(lib/primary-source-table-id (t2/select-one-fn :dataset_query :model/ExplorationQuery :id %)) query-ids))- (set (map lib/primary-source-table-id @checked)))+ (is (= (set (map #(t2/select-one-fn :dataset_query :model/ExplorationQuery :id %) query-ids))+ (set @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 a63c3eb64e2..f36aa1b67b5 100644--- a/test/metabase/explorations/derived_perms_test.clj+++ b/test/metabase/explorations/derived_perms_test.clj@@ -287,9 +287,8 @@(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 (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)."+ 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)."(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))]@@ -299,8 +298,8 @@(call-count)))))small (measure 2)large (measure 25)]- (is (< (- large small) (* 2 (- 25 2)))- (format "resolution must stay under 2 queries a chart (2 charts: %d queries, 25 charts: %d)" small large)))))+ (is (< large (* 2 small))+ (format "resolution must stay cheap (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 3c734087ed5..287b54b77b7 100644--- a/test/metabase/explorations/models/exploration_test.clj+++ b/test/metabase/explorations/models/exploration_test.clj@@ -158,13 +158,11 @@:card_id (:id metric):dimension_id "d1":page_id (:id p)- :dataset_query (let [mp (mt/metadata-provider)]- (lib/query mp (lib.metadata/table mp (mt/id :venues))))}]+ :dataset_query {:database 1 :type :query}}](testing "ExplorationQuery transforms"(let [reread (t2/select-one :model/ExplorationQuery :id (:id q))](is (= "d1" (:dimension_id reread)))- (is (= (mt/id) (-> reread :dataset_query :database)))- (is (= (mt/id :venues) (lib/primary-source-table-id (:dataset_query reread))))))))+ (is (= 1 (-> reread :dataset_query :database)))))))(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 59c285d66c3..7e1f37e9f4b 100644--- a/test/metabase/explorations/queues_test.clj+++ b/test/metabase/explorations/queues_test.clj@@ -120,9 +120,11 @@(mt/with-temporary-setting-values [queue-max-retries 2](do-with-fixtures!(fn [{:keys [card thread]}]- ;; a table that doesn't exist: the QP throws on every attempt+ ;; a database that doesn't exist: the QP throws on every attempt(let [qid (insert-query! (:id thread) (:id card)- {:database (mt/id) :type :query :query {:source-table Integer/MAX_VALUE :aggregation [[:count]]}})]+ {:database 999999+ :type :query+ :query {:source-table 1 :aggregation [[:count]]}})](mq.tu/with-test-mq [ctx](#'explorations.queues/publish-pending-queries! (:id thread))(mq.tu/eventually! ctx #(= "error" (status qid)) 60000))@@ -142,9 +144,11 @@(mt/with-temporary-setting-values [queue-max-retries 5](do-with-fixtures!(fn [{:keys [card thread]}]- ;; a table that doesn't exist: the QP throws on every attempt → the error path+ ;; a database that doesn't exist: the QP throws on every attempt → the error path(let [qid (insert-query! (:id thread) (:id card)- {:database (mt/id) :type :query :query {:source-table Integer/MAX_VALUE :aggregation [[:count]]}})+ {:database 999999+ :type :query+ :query {:source-table 1 :aggregation [[:count]]}})calls (atom 0)orig runner/maybe-complete-thread!](mq.tu/with-worker-redefs [runner/maybe-complete-thread!@@ -230,9 +234,11 @@(mt/with-temporary-setting-values [queue-max-retries 2](do-with-fixtures!(fn [{:keys [card thread]}]- ;; a table that doesn't exist: the QP throws on every attempt+ ;; a database that doesn't exist: the QP throws on every attempt(let [poison (insert-query! (:id thread) (:id card)- {:database (mt/id) :type :query :query {:source-table Integer/MAX_VALUE :aggregation [[:count]]}})+ {:database 999999+ :type :query+ :query {:source-table 1 :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 60995f5d8f3..b17372f8ec0 100644--- a/test/metabase/explorations/runner_test.clj+++ b/test/metabase/explorations/runner_test.clj@@ -15,7 +15,6 @@[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]@@ -97,7 +96,7 @@(is (some? result))(is (some? (:stored_result_id result)))(is (some? sr))- (is (pos? (count (queries.db/stored-result-data (:id sr)))))+ (is (pos? (count (:result_data sr))))(is (= 1 (:row_count sr))"the QP's top-level :row_count (1 row for an unbucketed count) is persisted on the snapshot")))))@@ -154,7 +153,7 @@(is (= "done" (:status final)))(is (some? result))(is (some? sr))- (is (pos? (count (queries.db/stored-result-data (:id sr)))))+ (is (pos? (count (:result_data sr))))(is (nil? (:interestingness_score result)))))))))(deftest run-one-iteration-writes-contextual-score-test@@ -229,7 +228,7 @@(is (= "done" (:status final)))(is (some? result))(is (some? sr))- (is (pos? (count (queries.db/stored-result-data (:id sr)))))+ (is (pos? (count (:result_data sr))))(is (nil? (:contextual_interestingness_score result)))(is (double? (:interestingness_score result))"heuristic score still computed when contextual fails")))))))@@ -315,7 +314,8 @@: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 (mt/id) :type :query :query {:source-table Integer/MAX_VALUE :aggregation [[:count]]}})+ {:database 999999 :type :query+ :query {:source-table 1 :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 c41929fb471..85c6bd98290 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.warehouse-schema.db :as warehouse-schema.db]))+ [metabase.util.log.capture :as log.capture]))(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 [warehouse-schema.db/table (fn [_] (throw (ex-info "boom" {})))]+ (mt/with-dynamic-fn-redefs [metabot.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 b77546b8652..a967923042d 100644--- a/test/metabase/metabot/tools/construct_representations_test.clj+++ b/test/metabase/metabot/tools/construct_representations_test.clj@@ -41,7 +41,6 @@[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]@@ -1533,12 +1532,12 @@"stages" [{"lib/type" "mbql.stage/mbql" "source-card" card-id}]})(defn- with-stubbed-card!- "Run `f` with `queries.db/card` serving only card 500, and `api/read-check` bound to+ "Run `f` with `metabot.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 [queries.db/card (fn [id] (when (= id 500) {:id 500 :database_id 1}))+ (mt/with-dynamic-fn-redefs [metabot.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 b427ebb4b42..eb64c4eea61 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))))+ (is (= active-table-id (:id (metabot.tools.util/get-table active-table-id :db_id))))(is (thrown? clojure.lang.ExceptionInfo- (metabot.tools.util/get-table inactive-table-id)))))))+ (metabot.tools.util/get-table inactive-table-id :db_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 0001b96f058..b73e39a62b1 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"}]+ :model/AuthIdentity _ {:user_id (:id user) :provider "google" :metadata {:sso_source "google"}}](auth-identity/set-password! (:id user) "password")(let [stale-session (auth-identity/create-session-with-auth-tracking!user