From b1298421ac2d7b157bb3578ac1679a0da6ba8f9f Mon Sep 17 00:00:00 2001
From: Cam Saul <1455846+camsaul@users.noreply.github.com>
Date: Wed, 18 Jan 2023 21:25:59 -0800
Subject: [PATCH] Switch to Honey SQL 2 and Toucan 2, part 2 (#27743)

* Switch to Toucan 2 part 1

* Fix Kondo errors

* Switch to Toucan 2, part 2

* Fix Kondo errors
---
 .clj-kondo/config.edn                         |  16 +-
 .clj-kondo/macros/toucan/models.clj           |   5 -
 .../audit_app/pages/common.clj                |   6 +-
 .../enhancements/integrations/ldap.clj        |   3 +-
 .../metabase_enterprise/sandbox/api/gtap.clj  |  14 +-
 .../models/group_table_access_policy.clj      |   2 +-
 .../serialization/dump.clj                    |   8 +-
 .../serialization/load.clj                    |  10 +-
 .../sandbox/api/dashboard_test.clj            |   7 +-
 .../sandbox/api/field_test.clj                |  15 +-
 .../sandbox/api/gtap_test.clj                 |  18 +-
 .../sandbox/api/permissions_test.clj          |  40 +-
 .../sandbox/api/pulse_test.clj                |   3 +-
 .../sandbox/api/table_test.clj                |  15 +-
 .../sandbox/api/user_test.clj                 |   8 +-
 .../sandbox/api/util_test.clj                 |   4 +-
 .../models/params/chain_filter_test.clj       |   3 +-
 .../models/params/field_values_test.clj       |  72 +--
 .../sandbox/pulse_test.clj                    |  31 +-
 .../row_level_restrictions_test.clj           | 437 +++++++++---------
 .../metabase_enterprise/sandbox/test_util.clj |  10 +-
 .../serialization/load_test.clj               |   2 -
 .../serialization/test_util.clj               |   9 +-
 .../serialization/upsert_test.clj             |  68 +--
 .../backend/test/metabase_enterprise/test.clj |  13 +
 src/metabase/analytics/snowplow.clj           |   6 +-
 src/metabase/analytics/stats.clj              |   7 +-
 src/metabase/api/action.clj                   |   6 +-
 src/metabase/api/activity.clj                 |  33 +-
 src/metabase/api/card.clj                     |   1 -
 src/metabase/api/common.clj                   |   4 +-
 src/metabase/api/dashboard.clj                |  13 +-
 src/metabase/api/database.clj                 |  58 ++-
 src/metabase/api/embed.clj                    |  18 +-
 src/metabase/api/permissions.clj              |   3 +-
 src/metabase/api/public.clj                   |   1 +
 src/metabase/api/revision.clj                 |   2 +-
 src/metabase/api/setup.clj                    |  10 +-
 src/metabase/api/table.clj                    |  26 +-
 src/metabase/api/user.clj                     |  13 +-
 src/metabase/automagic_dashboards/core.clj    |   8 +-
 src/metabase/cmd/rotate_encryption_key.clj    |   6 +-
 src/metabase/db/query.clj                     |   4 +
 src/metabase/db/setup.clj                     |   6 +-
 src/metabase/driver/sql/query_processor.clj   |  11 +-
 src/metabase/integrations/common.clj          |   6 +-
 src/metabase/integrations/google.clj          |   3 +-
 .../ldap/default_implementation.clj           |   3 +-
 src/metabase/models/card.clj                  |  21 +-
 src/metabase/models/collection.clj            |  15 +-
 src/metabase/models/database.clj              |   2 +-
 src/metabase/models/login_history.clj         |  13 +-
 src/metabase/models/permissions.clj           |   2 +-
 src/metabase/models/pulse.clj                 |   3 +-
 src/metabase/models/query.clj                 |   4 +-
 src/metabase/models/revision.clj              |  14 +-
 src/metabase/models/serialization/base.clj    |  16 +-
 src/metabase/models/setting/cache.clj         |   2 +-
 src/metabase/models/user.clj                  |   6 +-
 .../middleware/add_dimension_projections.clj  |   7 +-
 src/metabase/related.clj                      |  17 +-
 src/metabase/server/middleware/session.clj    |  30 +-
 .../sync/analyze/classifiers/name.clj         |   2 +-
 src/metabase/task.clj                         |   7 +-
 src/metabase/transforms/dashboard.clj         |   1 +
 src/metabase/troubleshooting.clj              |   2 +
 test/metabase/api/action_test.clj             |   3 +-
 test/metabase/api/dashboard_test.clj          |   6 +-
 test/metabase/api/database_test.clj           |  25 +-
 test/metabase/api/embed_test.clj              |  16 +-
 test/metabase/api/permissions_test.clj        |   1 -
 test/metabase/api/pulse_test.clj              |   4 +-
 test/metabase/api/revision_test.clj           |  71 +--
 test/metabase/api/search_test.clj             |  10 +-
 test/metabase/api/session_test.clj            |  11 +-
 test/metabase/api/table_test.clj              |  53 ++-
 .../cmd/rotate_encryption_key_test.clj        |  13 +-
 test/metabase/db/schema_migrations_test.clj   |  33 +-
 test/metabase/integrations/google_test.clj    |  13 +-
 test/metabase/models/card_test.clj            |  13 +-
 test/metabase/models/collection_test.clj      |  15 +-
 test/metabase/models/field_test.clj           |   2 +-
 test/metabase/models/field_values_test.clj    |  10 +-
 test/metabase/models/login_history_test.clj   |   6 +-
 test/metabase/models/metric_test.clj          |   4 +-
 .../models/native_query_snippet_test.clj      |   2 +-
 test/metabase/models/segment_test.clj         |  10 +-
 test/metabase/models/session_test.clj         |  22 +-
 .../models/setting/multi_setting_test.clj     |   4 +-
 test/metabase/models/user_test.clj            |   8 +-
 .../add_dimension_projections_test.clj        |  34 +-
 .../middleware/fetch_source_query_test.clj    |  10 +-
 .../server/middleware/session_test.clj        |   2 +-
 test/metabase/test.clj                        |  10 -
 test/metabase/test/data/users.clj             |   4 +-
 test/metabase/util/encryption_test.clj        |   6 +-
 96 files changed, 858 insertions(+), 794 deletions(-)
 delete mode 100644 .clj-kondo/macros/toucan/models.clj
 create mode 100644 enterprise/backend/test/metabase_enterprise/test.clj

diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn
index 03705ef4f78..9bc9fb6452e 100644
--- a/.clj-kondo/config.edn
+++ b/.clj-kondo/config.edn
@@ -79,7 +79,6 @@
     metabase.public-settings.premium-features/enable-enhancements?               {:namespaces ["metabase\\.models.*"]}
     metabase.query-processor.middleware.resolve-joins/maybe-resolve-source-table {:namespaces ["metabase.*"]}
     metabase.query-processor.util/normalize-token                                {:namespaces ["metabase.*"]}
-    metabase.util/key-by                                                         {:namespaces ["metabase(?:-enterprise)?.*"]}
     schema.core/both                                                             {:namespaces ["metabase.*"]}
     schema.core/either                                                           {:namespaces ["metabase.*"]}}}
 
@@ -89,10 +88,7 @@
 
   :unresolved-var
   {:exclude
-   [colorize.core
-    metabase.test/with-gtaps
-    metabase.test/with-gtaps-for-user
-    metabase.test/with-user-attributes]}
+   [colorize.core]}
 
   :unsorted-required-namespaces {:level :warning}
 
@@ -138,6 +134,7 @@
     medley.core                                                     m
     metabase-enterprise.audit-app.pages.common                      common
     metabase-enterprise.sandbox.api.table                           table
+    metabase-enterprise.test                                        met
     metabase.analytics.stats                                        stats
     metabase.api.activity                                           api.activity
     metabase.api.alert                                              api.alert
@@ -326,6 +323,7 @@
     metabase.sync.util                                              sync-util
     metabase.sync.util-test                                         sync.util-test
     metabase.task.sync-databases                                    task.sync-databases
+    metabase.test                                                   mt
     metabase.test-runner.assert-exprs                               test-runner.assert-exprs
     metabase.test-runner.init                                       test-runner.init
     metabase.test-runner.junit                                      test-runner.junit
@@ -440,6 +438,7 @@
    clojure.core/type                                                                                                         hooks.metabase.models.disallow-type-or-class/hook
    metabase-enterprise.advanced-permissions.models.permissions.application-permissions-test/with-new-group-and-current-graph hooks.common/with-two-top-level-bindings
    metabase-enterprise.audit-app.pages-test/with-temp-objects                                                                hooks.common/with-one-binding
+   metabase-enterprise.sandbox.models.group-table-access-policy/GroupTableAccessPolicy                                       hooks.metabase.models.disallow-invoking-model/hook
    metabase-enterprise.serialization.test-util/with-temp-dpc                                                                 hooks.toucan.util.test/with-temp*
    metabase.analytics.prometheus-test/with-prometheus-system                                                                 hooks.common/with-two-bindings
    metabase.api.alert-test/with-alert-in-collection                                                                          hooks.common/with-four-bindings
@@ -447,10 +446,10 @@
    metabase.api.card-test/with-temp-native-card                                                                              hooks.common/with-two-bindings
    metabase.api.card-test/with-temp-native-card-with-params                                                                  hooks.common/with-two-bindings
    metabase.api.collection-test/with-french-user-and-personal-collection                                                     hooks.common/with-two-top-level-bindings
-   metabase.api.common/defendpoint-schema                                                                                    hooks.metabase.api.common/defendpoint
    metabase.api.common/defendpoint                                                                                           hooks.metabase.api.common/defendpoint
    metabase.api.common/defendpoint-async                                                                                     hooks.metabase.api.common/defendpoint
    metabase.api.common/defendpoint-async-schema                                                                              hooks.metabase.api.common/defendpoint
+   metabase.api.common/defendpoint-schema                                                                                    hooks.metabase.api.common/defendpoint
    metabase.api.dashboard-test/with-chain-filter-fixtures                                                                    hooks.common/let-one-with-optional-value
    metabase.api.embed-test/do-response-formats                                                                               hooks.common/with-two-bindings
    metabase.api.embed-test/with-chain-filter-fixtures                                                                        hooks.common/let-one-with-optional-value
@@ -621,6 +620,7 @@
    clojurewerkz.quartzite.triggers/build                                        macros.quartz/build-trigger
    metabase-enterprise.sandbox.test-util/with-gtaps                             macros.metabase-enterprise.sandbox.test-util/with-gtaps
    metabase-enterprise.serialization.test-util/with-world                       macros.metabase-enterprise.serialization.test-util/with-world
+   metabase-enterprise.test/with-gtaps                                          macros.metabase-enterprise.sandbox.test-util/with-gtaps
    metabase.api.card-test/with-ordered-items                                    macros.metabase.api.card-test/with-ordered-items
    metabase.api.collection-test/with-collection-hierarchy                       macros.metabase.api.collection-test/with-collection-hierarchy
    metabase.api.collection-test/with-some-children-of-collection                macros.metabase.api.collection-test/with-some-children-of-collection
@@ -639,11 +639,9 @@
    metabase.test.util/with-temp-env-var-value                                   macros.metabase.test.util/with-temp-env-var-value
    metabase.test.util/with-temporary-raw-setting-values                         macros.metabase.test.util/with-temporary-raw-setting-values
    metabase.test/with-group-for-user                                            macros.metabase.test.data.users/with-group-for-user
-   metabase.test/with-gtaps                                                     macros.metabase-enterprise.sandbox.test-util/with-gtaps
    metabase.test/with-persistence-enabled                                       macros.metabase.test.persistence/with-persistence-enabled
    metabase.test/with-temp-env-var-value                                        macros.metabase.test.util/with-temp-env-var-value
-   metabase.test/with-temporary-raw-setting-values                              macros.metabase.test.util/with-temporary-raw-setting-values
-   toucan.models/defmodel                                                       macros.toucan.models/defmodel}}
+   metabase.test/with-temporary-raw-setting-values                              macros.metabase.test.util/with-temporary-raw-setting-values}}
 
  :config-in-call
  {metabase.util.honey-sql-2-extensions/with-database-type-info {:linters {:type-mismatch {:level :off}}}}
diff --git a/.clj-kondo/macros/toucan/models.clj b/.clj-kondo/macros/toucan/models.clj
deleted file mode 100644
index ca20dc2e260..00000000000
--- a/.clj-kondo/macros/toucan/models.clj
+++ /dev/null
@@ -1,5 +0,0 @@
-(ns macros.toucan.models)
-
-(defmacro defmodel [model-name & _args]
-  `(do
-     (def ~model-name "Docstring." nil)))
diff --git a/enterprise/backend/src/metabase_enterprise/audit_app/pages/common.clj b/enterprise/backend/src/metabase_enterprise/audit_app/pages/common.clj
index ca3b3af9b85..d0a11be7dc7 100644
--- a/enterprise/backend/src/metabase_enterprise/audit_app/pages/common.clj
+++ b/enterprise/backend/src/metabase_enterprise/audit_app/pages/common.clj
@@ -3,7 +3,6 @@
   (:require
    [clojure.core.async :as a]
    [clojure.core.memoize :as memoize]
-   [clojure.java.jdbc :as jdbc]
    [clojure.string :as str]
    [clojure.walk :as walk]
    [honeysql.core :as hsql]
@@ -13,6 +12,7 @@
    [medley.core :as m]
    [metabase-enterprise.audit-app.query-processor.middleware.handle-audit-queries :as qp.middleware.audit]
    [metabase.db :as mdb]
+   [metabase.db.connection :as mdb.connection]
    [metabase.driver.sql-jdbc.execute :as sql-jdbc.execute]
    [metabase.driver.sql-jdbc.sync :as sql-jdbc.sync]
    [metabase.driver.sql.query-processor :as sql.qp]
@@ -93,7 +93,7 @@
   ;; another
   (let [timezone (memoize/ttl sql-jdbc.sync/db-default-timezone :ttl/threshold (u/hours->ms 1))]
     (fn []
-      (timezone (mdb/db-type) (db/connection)))))
+      (timezone (mdb/db-type) {:datasource mdb.connection/*application-db*}))))
 
 (defn- compile-honeysql [driver honeysql-query]
   (try
@@ -114,7 +114,7 @@
     ;; instead of mocking up a chunk of regular QP pipeline.
     (binding [qp.timezone/*results-timezone-id-override* (application-db-default-timezone)]
       (try
-        (with-open [conn (jdbc/get-connection (db/connection))
+        (with-open [conn (.getConnection mdb.connection/*application-db*)
                     stmt (sql-jdbc.execute/prepared-statement driver conn sql params)
                     rs   (sql-jdbc.execute/execute-prepared-statement! driver stmt)]
           (let [rsmeta   (.getMetaData rs)
diff --git a/enterprise/backend/src/metabase_enterprise/enhancements/integrations/ldap.clj b/enterprise/backend/src/metabase_enterprise/enhancements/integrations/ldap.clj
index 8890f8eed20..568dd6e939c 100644
--- a/enterprise/backend/src/metabase_enterprise/enhancements/integrations/ldap.clj
+++ b/enterprise/backend/src/metabase_enterprise/enhancements/integrations/ldap.clj
@@ -4,6 +4,7 @@
    [metabase.integrations.common :as integrations.common]
    [metabase.integrations.ldap.default-implementation :as default-impl]
    [metabase.integrations.ldap.interface :as i]
+   [metabase.models.interface :as mi]
    [metabase.models.setting :as setting :refer [defsetting]]
    [metabase.models.user :as user :refer [User]]
    [metabase.public-settings.premium-features
@@ -73,7 +74,7 @@
                           (ldap-group-membership-filter))]
       (assoc user-info :attributes (syncable-user-attributes result)))))
 
-(defenterprise-schema fetch-or-create-user! :- (class User)
+(defenterprise-schema fetch-or-create-user! :- (mi/InstanceOf User)
   "Using the `user-info` (from `find-user`) get the corresponding Metabase user, creating it if necessary."
   :feature :any
   [{:keys [first-name last-name email groups attributes], :as user-info} :- EEUserInfo
diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/api/gtap.clj b/enterprise/backend/src/metabase_enterprise/sandbox/api/gtap.clj
index 963fec60086..f623aa3b884 100644
--- a/enterprise/backend/src/metabase_enterprise/sandbox/api/gtap.clj
+++ b/enterprise/backend/src/metabase_enterprise/sandbox/api/gtap.clj
@@ -20,11 +20,10 @@
     (db/select-one GroupTableAccessPolicy :group_id group_id :table_id table_id)
     (db/select GroupTableAccessPolicy {:order-by [[:id :asc]]})))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/:id"
+(api/defendpoint GET "/:id"
   "Fetch GTAP by `id`"
   [id]
-  (api/check-404 (GroupTableAccessPolicy id)))
+  (api/check-404 (db/select-one GroupTableAccessPolicy :id id)))
 
 ;; TODO - not sure what other endpoints we might need, e.g. for fetching the list above but for a given group or Table
 
@@ -54,20 +53,19 @@
   [id :as {{:keys [card_id #_attribute_remappings], :as body} :body}]
   {card_id              (s/maybe su/IntGreaterThanZero)
    #_attribute_remappings #_AttributeRemappings} ; TODO -  fix me
-  (api/check-404 (GroupTableAccessPolicy id))
+  (api/check-404 (db/select-one GroupTableAccessPolicy :id id))
   ;; Only update `card_id` and/or `attribute_remappings` if the values are present in the body of the request.
   ;; This allows existing values to be "cleared" by being set to nil
   (when (some #(contains? body %) [:card_id :attribute_remappings])
     (db/update! GroupTableAccessPolicy id
       (u/select-keys-when body
         :present #{:card_id :attribute_remappings})))
-  (GroupTableAccessPolicy id))
+  (db/select-one GroupTableAccessPolicy :id id))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema DELETE "/:id"
+(api/defendpoint DELETE "/:id"
   "Delete a GTAP entry."
   [id]
-  (api/check-404 (GroupTableAccessPolicy id))
+  (api/check-404 (db/select-one GroupTableAccessPolicy :id id))
   (db/delete! GroupTableAccessPolicy :id id)
   api/generic-204-no-content)
 
diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/models/group_table_access_policy.clj b/enterprise/backend/src/metabase_enterprise/sandbox/models/group_table_access_policy.clj
index b10b0a19cc2..27321a81ce6 100644
--- a/enterprise/backend/src/metabase_enterprise/sandbox/models/group_table_access_policy.clj
+++ b/enterprise/backend/src/metabase_enterprise/sandbox/models/group_table_access_policy.clj
@@ -146,7 +146,7 @@
 
 (defn- pre-update [{:keys [id], :as updates}]
   (u/prog1 updates
-    (let [original (GroupTableAccessPolicy id)
+    (let [original (db/select-one GroupTableAccessPolicy :id id)
           updated  (merge original updates)]
       (when-not (= (:table_id original) (:table_id updated))
         (throw (ex-info (tru "You cannot change the Table ID of a GTAP once it has been created.")
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/dump.clj b/enterprise/backend/src/metabase_enterprise/serialization/dump.clj
index a9c976f0e55..548ee882390 100644
--- a/enterprise/backend/src/metabase_enterprise/serialization/dump.clj
+++ b/enterprise/backend/src/metabase_enterprise/serialization/dump.clj
@@ -11,6 +11,7 @@
    [metabase.models.database :refer [Database]]
    [metabase.models.dimension :refer [Dimension]]
    [metabase.models.field :refer [Field]]
+   [metabase.models.interface :as mi]
    [metabase.models.metric :refer [Metric]]
    [metabase.models.pulse :refer [Pulse]]
    [metabase.models.segment :refer [Segment]]
@@ -34,8 +35,11 @@
   (io/make-parents filename)
   (spit filename (yaml/generate-string obj :dumper-options {:flow-style :block})))
 
-(def ^:private as-file?
-  (comp (set (map type [Pulse Dashboard Metric Segment Field User])) type))
+(defn- as-file?
+  [instance]
+  (some (fn [model]
+          (mi/instance-of? model instance))
+        [Pulse Dashboard Metric Segment Field User]))
 
 (defn- spit-entity
   [path entity]
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/load.clj b/enterprise/backend/src/metabase_enterprise/serialization/load.clj
index 1747961ba97..1543304e6fc 100644
--- a/enterprise/backend/src/metabase_enterprise/serialization/load.clj
+++ b/enterprise/backend/src/metabase_enterprise/serialization/load.clj
@@ -195,11 +195,11 @@
   (.getName (io/file path)))
 
 (defn- unresolved-names->string
-  ([entity]
-   (unresolved-names->string entity nil))
-  ([entity insert-id]
+  ([model]
+   (unresolved-names->string model nil))
+  ([model insert-id]
    (str
-    (when-let [nm (:name entity)] (str "\"" nm "\""))
+    (when-let [nm (:name model)] (str "\"" nm "\""))
     (when insert-id (format " (inserted as ID %d) " insert-id))
     "missing:\n  "
     (str/join
@@ -207,7 +207,7 @@
      (map
       (fn [[k v]]
         (format "at %s -> %s" (str/join "/" v) k))
-      (::unresolved-names entity))))))
+      (::unresolved-names model))))))
 
 (defmulti load
   "Load an entity of type `model` stored at `path` in the context `context`.
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/dashboard_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/dashboard_test.clj
index 7eeddf55296..62256d9844b 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/dashboard_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/dashboard_test.clj
@@ -2,6 +2,7 @@
   "Tests for special behavior of `/api/metabase/dashboard` endpoints in the Metabase Enterprise Edition."
   (:require
    [clojure.test :refer :all]
+   [metabase-enterprise.test :as met]
    [metabase.api.dashboard-test :as api.dashboard-test]
    [metabase.models :refer [DashboardCard FieldValues]]
    [metabase.models.params.chain-filter-test :as chain-filter-test]
@@ -14,7 +15,7 @@
 
 (deftest chain-filter-sandboxed-field-values-test
   (testing "When chain filter endpoints would normally return cached FieldValues (#13832), make sure sandboxing is respected"
-    (mt/with-gtaps {:gtaps {:categories {:query (mt/mbql-query categories {:filter [:< $id 3]})}}}
+    (met/with-gtaps {:gtaps {:categories {:query (mt/mbql-query categories {:filter [:< $id 3]})}}}
       (mt/with-temp-vals-in-db FieldValues (u/the-id (db/select-one-id FieldValues :field_id (mt/id :categories :name))) {:values ["Good" "Bad"]}
         (api.dashboard-test/with-chain-filter-fixtures [{:keys [dashboard]}]
           (testing "GET /api/dashboard/:id/params/:param-key/values"
@@ -31,7 +32,7 @@
 (deftest add-card-parameter-mapping-permissions-test
   (testing "POST /api/dashboard/:id/cards"
     (testing "Should check current user's data permissions for the `parameter_mapping`"
-      (mt/with-gtaps {:gtaps {:venues {}}}
+      (met/with-gtaps {:gtaps {:venues {}}}
         (api.dashboard-test/do-with-add-card-parameter-mapping-permissions-fixtures
          (fn [{:keys [card-id mappings add-card! dashcards]}]
            (testing "Should be able to add a card with `parameter_mapping` with only sandboxed perms"
@@ -53,7 +54,7 @@
 (deftest update-cards-parameter-mapping-permissions-test
   (testing "PUT /api/dashboard/:id/cards"
     (testing "Should check current user's data permissions for the `parameter_mapping`"
-      (mt/with-gtaps {:gtaps {:venues {}}}
+      (met/with-gtaps {:gtaps {:venues {}}}
         (api.dashboard-test/do-with-update-cards-parameter-mapping-permissions-fixtures
          (fn [{:keys [dashboard-id card-id update-mappings! new-mappings]}]
            (testing "Should be able to update `:parameter_mappings` *with* only sandboxed perms"
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/field_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/field_test.clj
index 609df4ee1bf..7d9b51dd147 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/field_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/field_test.clj
@@ -3,6 +3,7 @@
   (:require
    [clojure.test :refer :all]
    [metabase-enterprise.sandbox.test-util :as mt.tu]
+   [metabase-enterprise.test :as met]
    [metabase.models :refer [Field FieldValues User]]
    [metabase.models.field-values :as field-values]
    [metabase.test :as mt]
@@ -10,7 +11,7 @@
 
 (deftest fetch-field-test
   (testing "GET /api/field/:id"
-    (mt/with-gtaps {:gtaps      {:venues {:query      (mt.tu/restricted-column-query (mt/id))
+    (met/with-gtaps {:gtaps      {:venues {:query      (mt.tu/restricted-column-query (mt/id))
                                           :remappings {:cat [:variable [:field (mt/id :venues :category_id) nil]]}}}
                     :attributes {:cat 50}}
       (testing "Can I fetch a Field that I don't have read access for if I have segmented table access for it?"
@@ -40,7 +41,7 @@
                                        :remappings {:cat [:variable [:template-tag "cat"]]}}}
                  :attributes {:cat 50}}]]]
         (testing (format "GTAP rule is a %s query" query-type)
-          (mt/with-gtaps gtap-rule
+          (met/with-gtaps gtap-rule
             (testing (str "When I call the FieldValues API endpoint for a Field that I have segmented table access only "
                           "for, will I get ad-hoc values?\n")
               (letfn [(fetch-values [user field]
@@ -85,7 +86,7 @@
                   (testing "A User with a *different* sandbox should see their own values"
                     (let [password (mt/random-name)]
                       (mt/with-temp User [another-user {:password password}]
-                        (mt/with-gtaps-for-user another-user {:gtaps      {:venues
+                        (met/with-gtaps-for-user another-user {:gtaps      {:venues
                                                                            {:remappings
                                                                             {:cat
                                                                              [:dimension (mt/id :venues :category_id)]}}}
@@ -110,7 +111,7 @@
         ;; sanity test without gtap
         (is (= [[1 "$"] [2 "$$"] [3 "$$$"] [4 "$$$$"]]
                (:values (mt/user-http-request :rasta :get 200 (format "field/%d/values" field-id)))))
-        (mt/with-gtaps {:gtaps      {:venues
+        (met/with-gtaps {:gtaps      {:venues
                                      {:remappings {:cat [:variable [:field (mt/id :venues :category_id) nil]]}}}
                         :attributes {:cat 4}}
           (is (= [[1 "$"] [3 "$$$"]]
@@ -118,7 +119,7 @@
 
 (deftest search-test
   (testing "GET /api/field/:id/search/:search-id"
-    (mt/with-gtaps {:gtaps      {:venues
+    (met/with-gtaps {:gtaps      {:venues
                                  {:remappings {:cat [:variable [:field (mt/id :venues :category_id) nil]]}
                                   :query      (mt.tu/restricted-column-query (mt/id))}}
                     :attributes {:cat 50}}
@@ -136,7 +137,7 @@
                  (mt/user-http-request :rasta :get 200 url :value "Ta"))))))))
 
 (deftest caching-test
-  (mt/with-gtaps {:gtaps
+  (met/with-gtaps {:gtaps
                   {:venues
                    {:remappings {:cat [:variable [:field (mt/id :venues :category_id) nil]]}
                     :query      (mt.tu/restricted-column-query (mt/id))}}
@@ -156,7 +157,7 @@
       (testing "Do different users has different sandbox FieldValues"
         (let [password (mt/random-name)]
           (mt/with-temp User [another-user {:password password}]
-            (mt/with-gtaps-for-user another-user {:gtaps      {:venues
+            (met/with-gtaps-for-user another-user {:gtaps      {:venues
                                                                {:remappings {:cat [:variable [:field (mt/id :venues :category_id) nil]]}
                                                                 :query      (mt.tu/restricted-column-query (mt/id))}}
                                                   :attributes {:cat 5}}
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/gtap_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/gtap_test.clj
index 6bdd563c864..2f869a1328d 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/gtap_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/gtap_test.clj
@@ -147,9 +147,9 @@
 
 (deftest update-gtap-test
   (testing "PUT /api/mt/gtap"
-    (mt/with-temp* [Table                  [{table-id :id}]
-                    PermissionsGroup       [{group-id :id}]
-                    Card                   [{card-id :id}]]
+    (mt/with-temp* [Table            [{table-id :id}]
+                    PermissionsGroup [{group-id :id}]
+                    Card             [{card-id :id}]]
       (premium-features-test/with-premium-features #{:sandboxes}
         (testing "Test that we can update only the attribute remappings for a GTAP"
           (mt/with-temp GroupTableAccessPolicy [{gtap-id :id} {:table_id             table-id
@@ -216,8 +216,9 @@
                               :card_id  card-id-1))))
 
           (testing "Test that we can update a sandbox using the permission graph API"
-            (let [sandbox-id (db/select-one-field :id GroupTableAccessPolicy {:table_id table-id-1
-                                                                              :group_id group-id})
+            (let [sandbox-id (db/select-one-field :id GroupTableAccessPolicy
+                                                  :table_id table-id-1
+                                                  :group_id group-id)
                   graph      (assoc (perms/data-perms-graph)
                                     :sandboxes [{:id                   sandbox-id
                                                  :card_id              card-id-2
@@ -231,9 +232,10 @@
                                            :table_id table-id-1
                                            :group_id group-id)))))
 
-         (testing "Test that we can create and update multiple sandboxes at once using the permission graph API"
-            (let [sandbox-id (db/select-one-field :id GroupTableAccessPolicy {:table_id table-id-1
-                                                                              :group_id group-id})
+          (testing "Test that we can create and update multiple sandboxes at once using the permission graph API"
+            (let [sandbox-id (db/select-one-field :id GroupTableAccessPolicy
+                                                  :table_id table-id-1
+                                                  :group_id group-id)
                   graph      (assoc (perms/data-perms-graph)
                                     :sandboxes [{:id                   sandbox-id
                                                  :card_id              card-id-1
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj
index 1cab256e11a..b15acf1f4c8 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj
@@ -3,9 +3,11 @@
    [cheshire.core :as json]
    [clojure.string :as str]
    [clojure.test :refer :all]
-   [metabase-enterprise.sandbox.models.group-table-access-policy :refer [GroupTableAccessPolicy]]
-   [metabase.models :refer [Card Database PermissionsGroup
-                            PersistedInfo Table]]
+   [metabase-enterprise.sandbox.models.group-table-access-policy
+    :refer [GroupTableAccessPolicy]]
+   [metabase-enterprise.test :as met]
+   [metabase.models
+    :refer [Card Database PermissionsGroup PersistedInfo Table]]
    [metabase.models.permissions-group :as perms-group]
    [metabase.models.persisted-info :as persisted-info]
    [metabase.query-processor :as qp]
@@ -61,7 +63,7 @@
                                     {:native :none, :schemas {:PUBLIC {(mt/id :venues) {:query :all}}}})
                 :expected-perms   (fn []
                                     {:schemas {:PUBLIC {(mt/id :venues) {:query "all"}}}})}}]
-        (mt/with-gtaps {:gtaps {:venues {}}}
+        (met/with-gtaps {:gtaps {:venues {}}}
           (testing message
             (testing "sanity check"
               (testing "perms graph endpoint should return segmented perms for Venues table"
@@ -98,8 +100,8 @@
                 (testing "GTAP should be deleted from application DB"
                   (is (= []
                          (db/select GroupTableAccessPolicy
-                           :group_id (u/the-id &group)
-                           :table_id (mt/id :venues)))))
+                                    :group_id (u/the-id &group)
+                                    :table_id (mt/id :venues)))))
                 (testing "GTAP for same group, other database should not be affected"
                   (is (schema= [(s/one {:id                   su/IntGreaterThanZero
                                         :group_id             (s/eq (u/the-id &group))
@@ -108,8 +110,8 @@
                                         :attribute_remappings (s/eq nil)}
                                        "GTAP")]
                                (db/select GroupTableAccessPolicy
-                                 :group_id (u/the-id &group)
-                                 :table_id (u/the-id db-2-table)))))
+                                          :group_id (u/the-id &group)
+                                          :table_id (u/the-id db-2-table)))))
                 (testing "GTAP for same table, other group should not be affected"
                   (is (schema= [(s/one {:id                   su/IntGreaterThanZero
                                         :group_id             (s/eq (u/the-id other-group))
@@ -157,14 +159,14 @@
                        :database_id (mt/id)}]]
           (fake-persist-card! card)
           (is (str/includes?
-                (:query (qp/compile
+               (:query (qp/compile
 
-                          {:database (mt/id)
-                           :query {:source-table (str "card__" (u/the-id card))}
-                           :type :query}))
-                "metabase_cache")))))
+                        {:database (mt/id)
+                         :query {:source-table (str "card__" (u/the-id card))}
+                         :type :query}))
+               "metabase_cache")))))
     (testing "Queries from source if sandboxed"
-      (mt/with-gtaps
+      (met/with-gtaps
         {:gtaps {:venues {:query (mt/mbql-query venues)
                           :remappings {:cat ["variable" [:field (mt/id :venues :category_id) nil]]}}}
          :attributes {"cat" 50}}
@@ -174,8 +176,8 @@
                        :database_id (mt/id)}]]
           (fake-persist-card! card)
           (is (not (str/includes?
-                     (:query (qp/compile
-                               {:database (mt/id)
-                                :query {:source-table (str "card__" (u/the-id card))}
-                                :type :query}))
-                     "metabase_cache"))))))))
+                    (:query (qp/compile
+                             {:database (mt/id)
+                              :query {:source-table (str "card__" (u/the-id card))}
+                              :type :query}))
+                    "metabase_cache"))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/pulse_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/pulse_test.clj
index 2561ccab4fe..a36dc4d3ae9 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/pulse_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/pulse_test.clj
@@ -2,6 +2,7 @@
   "Tests that would logically be included in `metabase.api.pulse-test` but are separate as they are enterprise only."
   (:require
    [clojure.test :refer :all]
+   [metabase-enterprise.test :as met]
    [metabase.integrations.slack]
    [metabase.test :as mt]))
 
@@ -12,7 +13,7 @@
     (testing (str "Non-segmented users are able to send pulses to any slack channel that the configured instance can "
                   "see. A segmented user should not be able to send messages to those channels. This tests that a "
                   "segmented user doesn't see any slack channels.")
-      (mt/with-gtaps {:gtaps {:venues {}}}
+      (met/with-gtaps {:gtaps {:venues {}}}
         (mt/with-temporary-setting-values [slack-token nil]
           (is (= nil
                  (-> (mt/user-http-request :rasta :get 200 "pulse/form_input")
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/table_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/table_test.clj
index ebcb7cf95ca..11663b0a0e0 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/table_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/table_test.clj
@@ -3,6 +3,7 @@
    [clojure.string :as str]
    [clojure.test :refer :all]
    [metabase-enterprise.sandbox.test-util :as mt.tu]
+   [metabase-enterprise.test :as met]
    [metabase.test :as mt]))
 
 (def ^:private all-columns
@@ -17,10 +18,10 @@
                 (if (seq fields)
                   (set (map (comp str/upper-case :name) fields))
                   response)))]
-      (mt/with-gtaps {:gtaps      {:venues
-                                   {:remappings {:cat [:variable [:field (mt/id :venues :category_id) nil]]}
-                                    :query      (mt.tu/restricted-column-query (mt/id))}}
-                      :attributes {:cat 50}}
+      (met/with-gtaps {:gtaps      {:venues
+                                    {:remappings {:cat [:variable [:field (mt/id :venues :category_id) nil]]}
+                                     :query      (mt.tu/restricted-column-query (mt/id))}}
+                       :attributes {:cat 50}}
         (testing "Users with restricted access to the columns of a table should only see columns included in the GTAP question"
           (is (= #{"CATEGORY_ID" "ID" "NAME"}
                  (field-names :rasta))))
@@ -31,8 +32,8 @@
 
       (testing (str "If a GTAP has a question, but that question doesn't include a clause to restrict the columns that "
                     "are returned, all fields should be returned")
-        (mt/with-gtaps {:gtaps      {:venues {:query      (mt/mbql-query venues)
-                                              :remappings {:cat [:variable [:field (mt/id :venues :category_id) nil]]}}}
-                        :attributes {:cat 50}}
+        (met/with-gtaps {:gtaps      {:venues {:query      (mt/mbql-query venues)
+                                               :remappings {:cat [:variable [:field (mt/id :venues :category_id) nil]]}}}
+                         :attributes {:cat 50}}
           (is (= all-columns
                  (field-names :rasta))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/user_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/user_test.clj
index 47c538321e5..89c55cd7bb3 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/user_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/user_test.clj
@@ -2,7 +2,9 @@
   "Tests that would logically be included in `metabase.api.user-test` but are separate as they are enterprise only."
   (:require
    [clojure.test :refer :all]
-   [metabase.models.permissions-group-membership :refer [PermissionsGroupMembership]]
+   [metabase-enterprise.test :as met]
+   [metabase.models.permissions-group-membership
+    :refer [PermissionsGroupMembership]]
    [metabase.test :as mt]
    [metabase.test.fixtures :as fixtures]
    [metabase.test.util :as tu]
@@ -16,7 +18,7 @@
 ;; themselves. This test checks that GET /api/user for a segmented user only returns themselves
 (deftest segmented-user-list-test
   (testing "GET /api/user for a segmented user should return themselves"
-    (mt/with-gtaps {:gtaps {:venues {}}}
+    (met/with-gtaps {:gtaps {:venues {}}}
       ;; Now do the request
       (is (= [{:common_name "Rasta Toucan"
                :last_name   "Toucan"
@@ -30,7 +32,7 @@
                                           :group_id (u/the-id group)
                                           :user_id (mt/user->id :rasta))]
             (db/update! PermissionsGroupMembership (:id membership)
-              :is_group_manager true))
+                        :is_group_manager true))
           (is (= [{:common_name "Rasta Toucan"
                    :last_name   "Toucan"
                    :first_name  "Rasta"
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/util_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/util_test.clj
index 860c587dde4..ab902c72dfd 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/util_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/util_test.clj
@@ -2,10 +2,10 @@
   (:require
    [clojure.test :refer :all]
    [metabase-enterprise.sandbox.api.util :as mt.api.u]
-   [metabase.test :as mt]))
+   [metabase-enterprise.test :as met]))
 
 (defn- has-segmented-perms-when-segmented-db-exists? [user-kw]
-  (mt/with-gtaps-for-user user-kw {:gtaps {:venues {}}}
+  (met/with-gtaps-for-user user-kw {:gtaps {:venues {}}}
     (mt.api.u/segmented-user?)))
 
 (deftest never-segment-admins-test
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/models/params/chain_filter_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/models/params/chain_filter_test.clj
index b53e9ae075e..66e9c501be2 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/models/params/chain_filter_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/models/params/chain_filter_test.clj
@@ -1,6 +1,7 @@
 (ns metabase-enterprise.sandbox.models.params.chain-filter-test
   (:require
    [clojure.test :refer :all]
+   [metabase-enterprise.test :as met]
    [metabase.api.common :as api]
    [metabase.models :refer [FieldValues]]
    [metabase.models.field-values :as field-values]
@@ -11,7 +12,7 @@
 (deftest chain-filter-sandboxed-field-values-test
   (testing "When chain-filter would normally return cached FieldValues (#13832), make sure sandboxing is respected"
     (mt/with-model-cleanup [FieldValues]
-      (mt/with-gtaps {:gtaps {:categories {:query (mt/mbql-query categories {:filter [:< $id 3]})}}}
+      (met/with-gtaps {:gtaps {:categories {:query (mt/mbql-query categories {:filter [:< $id 3]})}}}
         (field-values/clear-advanced-field-values-for-field! (mt/id :categories :name))
         (testing "values"
           (is (= {:values          ["African" "American"]
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/models/params/field_values_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/models/params/field_values_test.clj
index 6762e7270d4..d8008b8c2e2 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/models/params/field_values_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/models/params/field_values_test.clj
@@ -1,12 +1,22 @@
 (ns metabase-enterprise.sandbox.models.params.field-values-test
   (:require
    [clojure.test :refer :all]
-   [metabase-enterprise.sandbox.models.group-table-access-policy :refer [GroupTableAccessPolicy]]
-   [metabase-enterprise.sandbox.models.params.field-values :as ee-params.field-values]
-   [metabase.models :refer [Card Field FieldValues PermissionsGroup PermissionsGroupMembership User]]
+   [metabase-enterprise.sandbox.models.group-table-access-policy
+    :refer [GroupTableAccessPolicy]]
+   [metabase-enterprise.sandbox.models.params.field-values
+    :as ee-params.field-values]
+   [metabase-enterprise.test :as met]
+   [metabase.models
+    :refer [Card
+            Field
+            FieldValues
+            PermissionsGroup
+            PermissionsGroupMembership
+            User]]
    [metabase.models.field-values :as field-values]
    [metabase.models.params.field-values :as params.field-values]
-   [metabase.public-settings.premium-features-test :as premium-features-test]
+   [metabase.public-settings.premium-features-test
+    :as premium-features-test]
    [metabase.server.middleware.session :as mw.session]
    [metabase.test :as mt]
    [toucan.db :as db]))
@@ -14,9 +24,9 @@
 (deftest get-or-create-advanced-field-values!
   (doseq [fv-type [:sandbox :linked-filter]]
     (testing "create a new field values and fix up the human readable values"
-      (mt/with-gtaps {:gtaps {:categories {:query (mt/mbql-query categories {:filter [:and
-                                                                                      [:> $id 3]
-                                                                                      [:< $id 6]]})}}}
+      (met/with-gtaps {:gtaps {:categories {:query (mt/mbql-query categories {:filter [:and
+                                                                                       [:> $id 3]
+                                                                                       [:< $id 6]]})}}}
         ;; the categories-id doesn't have a field values, we fake it with a full fieldvalues to make it easier to test
         (db/insert! FieldValues {:type                  :full
                                  :field_id              (mt/id :categories :id)
@@ -24,8 +34,8 @@
                                  :human_readable_values (map #(str "id_" %) (range 10))})
         (let [categories-id (mt/id :categories :id)
               fv            (params.field-values/get-or-create-advanced-field-values!
-                              fv-type
-                              (db/select-one Field :id (mt/id :categories :id)))]
+                             fv-type
+                             (db/select-one Field :id (mt/id :categories :id)))]
           (is (= 1 (db/count FieldValues :field_id categories-id :type fv-type)))
           (is (= [4 5] (:values fv)))
           (is (= ["id_4" "id_5"] (:human_readable_values fv)))
@@ -33,19 +43,19 @@
 
           (testing "call second time shouldn't create a new FieldValues"
             (params.field-values/get-or-create-advanced-field-values!
-              :sandbox
-              (db/select-one Field :id (mt/id :categories :id)))
+             :sandbox
+             (db/select-one Field :id (mt/id :categories :id)))
             (is (= 1 (db/count FieldValues :field_id categories-id :type fv-type)))))))
 
     (testing "make sure the Fieldvalues respect [field-values/*total-max-length*]"
-      (mt/with-gtaps {:gtaps {:categories {:query (mt/mbql-query categories {:filter [:and
-                                                                                      [:> $id 3]
-                                                                                      [:< $id 6]]})}}}
+      (met/with-gtaps {:gtaps {:categories {:query (mt/mbql-query categories {:filter [:and
+                                                                                       [:> $id 3]
+                                                                                       [:< $id 6]]})}}}
         (binding [field-values/*total-max-length* 5]
           (is (= ["Asian"]
                  (:values (params.field-values/get-or-create-advanced-field-values!
-                            fv-type
-                            (db/select-one Field :id (mt/id :categories :name)))))))))))
+                           fv-type
+                           (db/select-one Field :id (mt/id :categories :name)))))))))))
 
 (deftest advanced-field-values-hash-test
   (premium-features-test/with-premium-features #{:sandboxes}
@@ -53,7 +63,7 @@
     (mt/with-temp-copy-of-db
       (testing "gtap with remappings"
         (letfn [(hash-for-user-id [user-id login-attributes field-id]
-                  (mt/with-gtaps-for-user user-id
+                  (met/with-gtaps-for-user user-id
                     {:gtaps      {:categories {:remappings {"State" [:dimension [:field (mt/id :categories :name) nil]]}}}
                      :attributes login-attributes}
                     (ee-params.field-values/hash-key-for-sandbox field-id)))]
@@ -76,15 +86,15 @@
               (is (= (hash-for-user-id user-id-1 {"State" "CA"} (mt/id :categories :name))
                      (hash-for-user-id user-id-2 {"State" "CA"} (mt/id :categories :name)))))
 
-           (testing "same users but the login_attributes change should have different hash"
-             (is (not= (hash-for-user-id user-id-1 {"State" "CA"} (mt/id :categories :name))
-                       (hash-for-user-id user-id-1 {"State" "NY"} (mt/id :categories :name)))))
+            (testing "same users but the login_attributes change should have different hash"
+              (is (not= (hash-for-user-id user-id-1 {"State" "CA"} (mt/id :categories :name))
+                        (hash-for-user-id user-id-1 {"State" "NY"} (mt/id :categories :name)))))
 
-           (testing "2 users with different login_attributes should have different hash"
-             (is (not= (hash-for-user-id user-id-1 {"State" "CA"} (mt/id :categories :name))
-                       (hash-for-user-id user-id-2 {"State" "NY"} (mt/id :categories :name))))
-             (is (not= (hash-for-user-id user-id-1 {} (mt/id :categories :name))
-                       (hash-for-user-id user-id-2 {"State" "NY"} (mt/id :categories :name)))))))))
+            (testing "2 users with different login_attributes should have different hash"
+              (is (not= (hash-for-user-id user-id-1 {"State" "CA"} (mt/id :categories :name))
+                        (hash-for-user-id user-id-2 {"State" "NY"} (mt/id :categories :name))))
+              (is (not= (hash-for-user-id user-id-1 {} (mt/id :categories :name))
+                        (hash-for-user-id user-id-2 {"State" "NY"} (mt/id :categories :name)))))))))
 
     (testing "gtap with card and remappings"
       ;; hack so that we don't have to setup all the sandbox permissions the table
@@ -116,9 +126,9 @@
                 (is (not= (hash-for-user-id-with-attributes user-id-1 {"State" "CA"} (mt/id :categories :name))
                           (hash-for-user-id-with-attributes user-id-2 {"State" "CA"} (mt/id :categories :id)))))
 
-             (testing "with different attributes, the hash should be the different"
-               (is (not= (hash-for-user-id-with-attributes user-id-1 {"State" "CA"} (mt/id :categories :name))
-                         (hash-for-user-id-with-attributes user-id-2 {"State" "NY"} (mt/id :categories :name)))))))
+              (testing "with different attributes, the hash should be the different"
+                (is (not= (hash-for-user-id-with-attributes user-id-1 {"State" "CA"} (mt/id :categories :name))
+                          (hash-for-user-id-with-attributes user-id-2 {"State" "NY"} (mt/id :categories :name)))))))
 
           (testing "gtap with native question"
             (mt/with-temp*
@@ -176,9 +186,9 @@
                 (is (not= (hash-for-user-id-with-attributes user-id-1 {"State" "CA"} (mt/id :categories :name))
                           (hash-for-user-id-with-attributes user-id-2 {"State" "CA"} (mt/id :categories :id)))))
 
-             (testing "with different attributes, the hash should be the different"
-               (is (not= (hash-for-user-id-with-attributes user-id-1 {"State" "CA"} (mt/id :categories :name))
-                         (hash-for-user-id-with-attributes user-id-2 {"State" "NY"} (mt/id :categories :name)))))))
+              (testing "with different attributes, the hash should be the different"
+                (is (not= (hash-for-user-id-with-attributes user-id-1 {"State" "CA"} (mt/id :categories :name))
+                          (hash-for-user-id-with-attributes user-id-2 {"State" "NY"} (mt/id :categories :name)))))))
 
           (testing "2 users in different groups and gtaps use 2 different cards"
             (mt/with-temp*
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/pulse_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/pulse_test.clj
index 9e920ef0d68..d252c8296b0 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/pulse_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/pulse_test.clj
@@ -4,6 +4,7 @@
    [clojure.java.io :as io]
    [clojure.test :refer :all]
    [medley.core :as m]
+   [metabase-enterprise.test :as met]
    [metabase.email.messages :as messages]
    [metabase.models
     :refer [Card Pulse PulseCard PulseChannel PulseChannelRecipient]]
@@ -17,9 +18,9 @@
 (deftest sandboxed-pulse-test
   (testing "Pulses should get sent with the row-level restrictions of the User that created them."
     (letfn [(send-pulse-created-by-user! [user-kw]
-              (mt/with-gtaps {:gtaps      {:venues {:query      (mt/mbql-query venues)
-                                                    :remappings {:cat ["variable" [:field (mt/id :venues :category_id) nil]]}}}
-                              :attributes {"cat" 50}}
+              (met/with-gtaps {:gtaps      {:venues {:query      (mt/mbql-query venues)
+                                                     :remappings {:cat ["variable" [:field (mt/id :venues :category_id) nil]]}}}
+                               :attributes {"cat" 50}}
                 (mt/with-temp Card [card {:dataset_query (mt/mbql-query venues {:aggregation [[:count]]})}]
                   ;; `with-gtaps` binds the current test user; we don't want that falsely affecting results
                   (mt/with-test-user nil
@@ -55,15 +56,15 @@
 
 (deftest e2e-sandboxed-pulse-test
   (testing "Sending Pulses w/ sandboxing, end-to-end"
-    (mt/with-gtaps {:gtaps {:venues {:query (mt/mbql-query venues
-                                                           {:filter [:= $price 3]})}}}
+    (met/with-gtaps {:gtaps {:venues {:query (mt/mbql-query venues
+                                               {:filter [:= $price 3]})}}}
       (let [query (mt/mbql-query venues
-                                 {:aggregation [[:count]]
-                                  :breakout    [$price]})]
+                    {:aggregation [[:count]]
+                     :breakout    [$price]})]
         (is (= [[3 13]]
                (mt/formatted-rows [int int]
-                                  (mt/with-test-user :rasta
-                                    (qp/process-query query))))
+                 (mt/with-test-user :rasta
+                   (qp/process-query query))))
             "Basic sanity check: make sure the query is properly set up to apply GTAPs")
         (testing "GTAPs should apply to Pulses — they should get the same results as if running that query normally"
           (is (= [[3 13]]
@@ -81,8 +82,8 @@
 
 (deftest user-attributes-test
   (testing "Pulses should be sandboxed correctly by User login_attributes"
-    (mt/with-gtaps {:gtaps      {:venues {:remappings {:price [:dimension [:field (mt/id :venues :price) nil]]}}}
-                    :attributes {"price" "1"}}
+    (met/with-gtaps {:gtaps      {:venues {:remappings {:price [:dimension [:field (mt/id :venues :price) nil]]}}}
+                     :attributes {"price" "1"}}
       (let [query (mt/mbql-query venues)]
         (mt/with-test-user :rasta
           (mt/with-temp Card [card {:dataset_query query}]
@@ -101,8 +102,8 @@
 
 (deftest pulse-preview-test
   (testing "Pulse preview endpoints should be sandboxed"
-    (mt/with-gtaps {:gtaps      {:venues {:remappings {:price [:dimension [:field (mt/id :venues :price) nil]]}}}
-                    :attributes {"price" "1"}}
+    (met/with-gtaps {:gtaps      {:venues {:remappings {:price [:dimension [:field (mt/id :venues :price) nil]]}}}
+                     :attributes {"price" "1"}}
       (let [query (mt/mbql-query venues)]
         (mt/with-test-user :rasta
           (mt/with-temp Card [card {:dataset_query query}]
@@ -130,8 +131,8 @@
 
 (deftest csv-downloads-test
   (testing "CSV/XLSX downloads should be sandboxed"
-    (mt/with-gtaps {:gtaps      {:venues {:remappings {:price [:dimension [:field (mt/id :venues :price) nil]]}}}
-                    :attributes {"price" "1"}}
+    (met/with-gtaps {:gtaps      {:venues {:remappings {:price [:dimension [:field (mt/id :venues :price) nil]]}}}
+                     :attributes {"price" "1"}}
       (let [query (mt/mbql-query venues)]
         (mt/with-test-user :rasta
           (mt/with-temp* [Card                 [{card-id :id}  {:dataset_query query}]
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj
index aafd6d23f89..ee4635db2b6 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj
@@ -5,8 +5,11 @@
    [clojure.test :refer :all]
    [honeysql.core :as hsql]
    [medley.core :as m]
-   [metabase-enterprise.sandbox.models.group-table-access-policy :refer [GroupTableAccessPolicy]]
-   [metabase-enterprise.sandbox.query-processor.middleware.row-level-restrictions :as row-level-restrictions]
+   [metabase-enterprise.sandbox.models.group-table-access-policy
+    :refer [GroupTableAccessPolicy]]
+   [metabase-enterprise.sandbox.query-processor.middleware.row-level-restrictions
+    :as row-level-restrictions]
+   [metabase-enterprise.test :as met]
    [metabase.api.common :as api]
    [metabase.driver :as driver]
    [metabase.driver.sql.query-processor :as sql.qp]
@@ -161,9 +164,9 @@
 
 (deftest middleware-test
   (testing "Make sure the middleware does the correct transformation given the GTAPs we have"
-    (mt/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
-                                 :venues   (dissoc (venues-price-mbql-gtap-def) :query)}
-                    :attributes {"user" 5, "price" 1}}
+    (met/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
+                                  :venues   (dissoc (venues-price-mbql-gtap-def) :query)}
+                     :attributes {"user" 5, "price" 1}}
       (testing "Should add a filter for attributes-only GTAP"
         (is (= (mt/query checkins
                  {:type  :query
@@ -215,8 +218,8 @@
                                   :condition    [:= $venue_id &v.venues.id]}]}))))))
 
     (testing "Should substitute appropriate value in native query"
-      (mt/with-gtaps {:gtaps      {:venues (venues-category-native-gtap-def)}
-                      :attributes {"cat" 50}}
+      (met/with-gtaps {:gtaps      {:venues (venues-category-native-gtap-def)}
+                       :attributes {"cat" 50}}
         (is (= (mt/query nil
                  {:database (mt/id)
                   :type     :query
@@ -248,23 +251,23 @@
                          (filter #(isa? driver/hierarchy % :sql))
                          (mt/normal-drivers-with-feature :nested-queries))
     (testing "When querying with full permissions, no changes should be made"
-      (mt/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
-                      :attributes {"cat" 50}}
+      (met/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
+                       :attributes {"cat" 50}}
         (perms/grant-permissions! &group (perms/table-query-path (db/select-one Table :id (mt/id :venues))))
         (is (= [[100]]
                (run-venues-count-query)))))
 
     (testing (str "Basic test around querying a table by a user with segmented only permissions and a GTAP question that "
                   "is a native query")
-      (mt/with-gtaps {:gtaps      {:venues (venues-category-native-gtap-def)}
-                      :attributes {"cat" 50}}
+      (met/with-gtaps {:gtaps      {:venues (venues-category-native-gtap-def)}
+                       :attributes {"cat" 50}}
         (is (= [[10]]
                (run-venues-count-query)))))
 
     (testing (str "Basic test around querying a table by a user with segmented only permissions and a GTAP question that "
                   "is MBQL")
-      (mt/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
-                      :attributes {"cat" 50}}
+      (met/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
+                       :attributes {"cat" 50}}
         (is (= [[10]]
                (run-venues-count-query)))))
 
@@ -273,8 +276,8 @@
       (is (thrown-with-msg?
            clojure.lang.ExceptionInfo
            #"Query requires user attribute `cat`"
-           (mt/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
-                           :attributes {"something_random" 50}}
+           (met/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
+                            :attributes {"something_random" 50}}
              (mt/run-mbql-query venues {:aggregation [[:count]]})))))
 
     (testing (str "When processing a query that requires a user attribute and that user attribute is nil, throw an "
@@ -282,27 +285,27 @@
       (is (thrown-with-msg?
            clojure.lang.ExceptionInfo
            #"Query requires user attribute `cat`"
-           (mt/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
-                           :attributes {"cat" nil}}
+           (met/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
+                            :attributes {"cat" nil}}
              (mt/run-mbql-query venues {:aggregation [[:count]]})))))
 
     (testing "Another basic test, same as above, but with a numeric string that needs to be coerced"
-      (mt/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
-                      :attributes {"cat" "50"}}
+      (met/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
+                       :attributes {"cat" "50"}}
         (is (= [[10]]
                (run-venues-count-query)))))
 
     (testing "Another basic test, this one uses a stringified float for the login attribute"
-      (mt/with-gtaps {:gtaps      {:venues {:query      (mt/mbql-query venues)
-                                            :remappings {:cat ["variable" [:field (mt/id :venues :latitude) nil]]}}}
-                      :attributes {"cat" "34.1018"}}
+      (met/with-gtaps {:gtaps      {:venues {:query      (mt/mbql-query venues)
+                                             :remappings {:cat ["variable" [:field (mt/id :venues :latitude) nil]]}}}
+                       :attributes {"cat" "34.1018"}}
         (is (= [[3]]
                (run-venues-count-query)))))
 
     (testing "Tests that users can have a different parameter name in their query than they have in their user attributes"
-      (mt/with-gtaps {:gtaps      {:venues {:query      (:query (venues-category-native-gtap-def))
-                                            :remappings {:something.different ["variable" ["template-tag" "cat"]]}}}
-                      :attributes {"something.different" 50}}
+      (met/with-gtaps {:gtaps      {:venues {:query      (:query (venues-category-native-gtap-def))
+                                             :remappings {:something.different ["variable" ["template-tag" "cat"]]}}}
+                       :attributes {"something.different" 50}}
         (is (= [[10]]
                (run-venues-count-query)))))
 
@@ -310,19 +313,19 @@
       (is (= [[1 "Red Medicine"]
               [2 "Stout Burgers & Beers"]]
              (mt/formatted-rows [int str]
-               (mt/with-gtaps {:gtaps {:venues (venue-names-native-gtap-def)}}
+               (met/with-gtaps {:gtaps {:venues (venue-names-native-gtap-def)}}
                  (mt/run-mbql-query venues {:limit 2, :order-by [[:asc [:field (mt/id :venues :id)]]]}))))))
 
     (testing (str "When no card_id is included in the GTAP, should default to a query against the table, with the GTAP "
                   "criteria applied")
-      (mt/with-gtaps {:gtaps      {:venues (dissoc (venues-category-mbql-gtap-def) :query)}
-                      :attributes {"cat" 50}}
+      (met/with-gtaps {:gtaps      {:venues (dissoc (venues-category-mbql-gtap-def) :query)}
+                       :attributes {"cat" 50}}
         (is (= [[10]]
                (run-venues-count-query)))))
 
     (testing "Same test as above but make sure we coerce a numeric string correctly"
-      (mt/with-gtaps {:gtaps      {:venues (dissoc (venues-category-mbql-gtap-def) :query)}
-                      :attributes {"cat" "50"}}
+      (met/with-gtaps {:gtaps      {:venues (dissoc (venues-category-mbql-gtap-def) :query)}
+                       :attributes {"cat" "50"}}
         (is (= [[10]]
                (run-venues-count-query)))))
 
@@ -374,42 +377,42 @@
 (deftest e2e-fks-test
   (mt/test-drivers (row-level-restrictions-fk-drivers)
     (mt/with-bigquery-fks #{:bigquery :bigquery-cloud-sdk}
-     (testing (str "1 - Creates a GTAP filtering question, looking for any checkins happening on or after 2014\n"
-                   "2 - Apply the `user` attribute, looking for only our user (i.e. `user_id` =  5)\n"
-                   "3 - Checkins are related to Venues, query for checkins, grouping by the Venue's price\n"
-                   "4 - Order by the Venue's price to ensure a predictably ordered response")
-       (mt/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
-                                    :venues   nil}
-                       :attributes {"user" 5}}
-         (is (= [[1 10] [2 36] [3 4] [4 5]]
-                (run-checkins-count-broken-out-by-price-query)))))
-
-     (testing (str "Test that we're able to use a GTAP for an FK related table. For this test, the user has segmented "
-                   "permissions on checkins and venues, so we need to apply a GTAP to the original table (checkins) in "
-                   "addition to the related table (venues). This test uses a GTAP question for both tables")
-       (mt/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
-                                    :venues   (venues-price-mbql-gtap-def)}
-                       :attributes {"user" 5, "price" 1}}
-         (is (= #{[nil 45] [1 10]}
-                (set (run-checkins-count-broken-out-by-price-query))))))
-
-     (testing "Test that the FK related table can be a \"default\" GTAP, i.e. a GTAP where the `card_id` is nil"
-       (mt/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
-                                    :venues   (dissoc (venues-price-mbql-gtap-def) :query)}
-                       :attributes {"user" 5, "price" 1}}
-         (is (= #{[nil 45] [1 10]}
-                (set (run-checkins-count-broken-out-by-price-query))))))
-
-     (testing (str "Test that we have multiple FK related, segmented tables. This test has checkins with a GTAP "
-                   "question with venues and users having the default GTAP and segmented permissions")
-       (mt/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
-                                    :venues   (dissoc (venues-price-mbql-gtap-def) :query)
-                                    :users    {:remappings {:user ["variable" [:field (mt/id :users :id) nil]]}}}
-                       :attributes {"user" 5, "price" 1}}
-         (is (= #{[nil "Quentin Sören" 45] [1 "Quentin Sören" 10]}
-                (set
-                 (mt/format-rows-by [#(when % (int %)) str int]
-                   (mt/rows
+      (testing (str "1 - Creates a GTAP filtering question, looking for any checkins happening on or after 2014\n"
+                    "2 - Apply the `user` attribute, looking for only our user (i.e. `user_id` =  5)\n"
+                    "3 - Checkins are related to Venues, query for checkins, grouping by the Venue's price\n"
+                    "4 - Order by the Venue's price to ensure a predictably ordered response")
+        (met/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
+                                      :venues   nil}
+                         :attributes {"user" 5}}
+          (is (= [[1 10] [2 36] [3 4] [4 5]]
+                 (run-checkins-count-broken-out-by-price-query)))))
+
+      (testing (str "Test that we're able to use a GTAP for an FK related table. For this test, the user has segmented "
+                    "permissions on checkins and venues, so we need to apply a GTAP to the original table (checkins) in "
+                    "addition to the related table (venues). This test uses a GTAP question for both tables")
+        (met/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
+                                      :venues   (venues-price-mbql-gtap-def)}
+                         :attributes {"user" 5, "price" 1}}
+          (is (= #{[nil 45] [1 10]}
+                 (set (run-checkins-count-broken-out-by-price-query))))))
+
+      (testing "Test that the FK related table can be a \"default\" GTAP, i.e. a GTAP where the `card_id` is nil"
+        (met/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
+                                      :venues   (dissoc (venues-price-mbql-gtap-def) :query)}
+                         :attributes {"user" 5, "price" 1}}
+          (is (= #{[nil 45] [1 10]}
+                 (set (run-checkins-count-broken-out-by-price-query))))))
+
+      (testing (str "Test that we have multiple FK related, segmented tables. This test has checkins with a GTAP "
+                    "question with venues and users having the default GTAP and segmented permissions")
+        (met/with-gtaps {:gtaps      {:checkins (checkins-user-mbql-gtap-def)
+                                      :venues   (dissoc (venues-price-mbql-gtap-def) :query)
+                                      :users    {:remappings {:user ["variable" [:field (mt/id :users :id) nil]]}}}
+                         :attributes {"user" 5, "price" 1}}
+          (is (= #{[nil "Quentin Sören" 45] [1 "Quentin Sören" 10]}
+                 (set
+                  (mt/format-rows-by [#(when % (int %)) str int]
+                    (mt/rows
                      (mt/run-mbql-query checkins
                        {:aggregation [[:count]]
                         :order-by    [[:asc $venue_id->venues.price]]
@@ -428,8 +431,8 @@
 
 (deftest remark-test
   (testing "make sure GTAP queries still include ID of user who ran them in the remark"
-    (mt/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
-                    :attributes {"cat" 50}}
+    (met/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
+                     :attributes {"cat" 50}}
       (is (= (format "Metabase:: userID: %d queryType: MBQL queryHash: <hash>" (mt/user->id :rasta))
              (run-query-returning-remark
               (fn []
@@ -438,14 +441,14 @@
 (deftest breakouts-test
   (mt/test-drivers (row-level-restrictions-fk-drivers)
     (testing "Make sure that if a GTAP is in effect we can still do stuff like breakouts (#229)"
-      (mt/with-gtaps {:gtaps      {:venues (venues-category-native-gtap-def)}
-                      :attributes {"cat" 50}}
+      (met/with-gtaps {:gtaps      {:venues (venues-category-native-gtap-def)}
+                       :attributes {"cat" 50}}
         (is (= [[1 6] [2 4]]
                (mt/format-rows-by [int int]
                  (mt/rows
-                   (mt/run-mbql-query venues
-                     {:aggregation [[:count]]
-                      :breakout    [$price]})))))))))
+                  (mt/run-mbql-query venues
+                    {:aggregation [[:count]]
+                     :breakout    [$price]})))))))))
 
 (deftest sql-with-join-test
   (mt/test-drivers (row-level-restrictions-fk-drivers)
@@ -456,30 +459,30 @@
               [72 1]]
              (mt/format-rows-by [int int identity int]
                (mt/rows
-                 (mt/with-gtaps {:gtaps      {:checkins (parameterized-sql-with-join-gtap-def)}
+                (met/with-gtaps {:gtaps      {:checkins (parameterized-sql-with-join-gtap-def)}
                                  :attributes {"user" 1}}
-                   (mt/run-mbql-query checkins
-                     {:limit 2})))))))
+                  (mt/run-mbql-query checkins
+                    {:limit 2})))))))
 
     (testing (str "EE #230: If we modify the query in a way that would cause the original to get nested as a source query, "
                   "do things work?")
       (is (= [[5 69]]
              (mt/format-rows-by [int int]
                (mt/rows
-                 (mt/with-gtaps {:gtaps      {:checkins (parameterized-sql-with-join-gtap-def)}
+                (met/with-gtaps {:gtaps      {:checkins (parameterized-sql-with-join-gtap-def)}
                                  :attributes {"user" 5}}
-                   (mt/run-mbql-query checkins
-                     {:aggregation [[:count]]
-                      :breakout    [$user_id]})))))))))
+                  (mt/run-mbql-query checkins
+                    {:aggregation [[:count]]
+                     :breakout    [$user_id]})))))))))
 
 (deftest correct-metadata-test
   (testing (str "We should return the same metadata as the original Table when running a query against a sandboxed "
                 "Table (EE #390)\n")
     (let [cols          (fn []
                           (mt/cols
-                            (mt/run-mbql-query venues
-                              {:order-by [[:asc $id]]
-                               :limit    2})))
+                           (mt/run-mbql-query venues
+                             {:order-by [[:asc $id]]
+                              :limit    2})))
           original-cols (cols)
           ;; `with-gtaps` copies the test DB so this function will update the IDs in `original-cols` so they'll match
           ;; up with the current copy
@@ -491,93 +494,93 @@
                                    :table_id (mt/id :venues)
                                    :field_ref [:field id nil])))]
       (testing "A query with a simple attributes-based sandbox should have the same metadata"
-        (mt/with-gtaps {:gtaps      {:venues (dissoc (venues-category-mbql-gtap-def) :query)}
-                        :attributes {"cat" 50}}
-            (is (= (expected-cols)
-                   (cols)))))
+        (met/with-gtaps {:gtaps      {:venues (dissoc (venues-category-mbql-gtap-def) :query)}
+                         :attributes {"cat" 50}}
+          (is (= (expected-cols)
+                 (cols)))))
 
       (testing "A query with an equivalent MBQL query sandbox should have the same metadata"
-        (mt/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
-                        :attributes {"cat" 50}}
-            (is (= (expected-cols)
-                   (cols)))))
+        (met/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
+                         :attributes {"cat" 50}}
+          (is (= (expected-cols)
+                 (cols)))))
 
       (testing "A query with an equivalent native query sandbox should have the same metadata"
-        (mt/with-gtaps {:gtaps {:venues {:query (mt/native-query
-                                                  {:query
-                                                   (str "SELECT ID, NAME, CATEGORY_ID, LATITUDE, LONGITUDE, PRICE "
-                                                        "FROM VENUES "
-                                                        "WHERE CATEGORY_ID = {{cat}}")
-
-                                                   :template_tags
-                                                   {:cat {:name "cat" :display_name "cat" :type "number" :required true}}})
-                                         :remappings {:cat ["variable" ["template-tag" "cat"]]}}}
-                        :attributes {"cat" 50}}
+        (met/with-gtaps {:gtaps {:venues {:query (mt/native-query
+                                                   {:query
+                                                    (str "SELECT ID, NAME, CATEGORY_ID, LATITUDE, LONGITUDE, PRICE "
+                                                         "FROM VENUES "
+                                                         "WHERE CATEGORY_ID = {{cat}}")
+
+                                                    :template_tags
+                                                    {:cat {:name "cat" :display_name "cat" :type "number" :required true}}})
+                                          :remappings {:cat ["variable" ["template-tag" "cat"]]}}}
+                         :attributes {"cat" 50}}
           (is (= (expected-cols)
                  (cols)))))
 
       (testing (str "If columns are added/removed/reordered we should still merge in metadata for the columns we're "
                     "able to match from the original Table")
-        (mt/with-gtaps {:gtaps {:venues {:query (mt/native-query
-                                                  {:query
-                                                   (str "SELECT NAME, ID, LONGITUDE, PRICE, 1 AS ONE "
-                                                        "FROM VENUES "
-                                                        "WHERE CATEGORY_ID = {{cat}}")
-
-                                                   :template_tags
-                                                   {:cat {:name "cat" :display_name "cat" :type "number" :required true}}})
-                                         :remappings {:cat ["variable" ["template-tag" "cat"]]}}}
-                        :attributes {"cat" 50}}
+        (met/with-gtaps {:gtaps {:venues {:query (mt/native-query
+                                                   {:query
+                                                    (str "SELECT NAME, ID, LONGITUDE, PRICE, 1 AS ONE "
+                                                         "FROM VENUES "
+                                                         "WHERE CATEGORY_ID = {{cat}}")
+
+                                                    :template_tags
+                                                    {:cat {:name "cat" :display_name "cat" :type "number" :required true}}})
+                                          :remappings {:cat ["variable" ["template-tag" "cat"]]}}}
+                         :attributes {"cat" 50}}
           (let [[id-col name-col _ _ longitude-col price-col] (expected-cols)]
-              (is (= [name-col id-col longitude-col price-col]
-                     (cols)))))))))
+            (is (= [name-col id-col longitude-col price-col]
+                   (cols)))))))))
 
 (deftest sql-with-joins-test
   (testing "Should be able to use a Saved Question with no source Metadata as a GTAP (EE #525)"
-    (mt/with-gtaps (mt/$ids
-                     {:gtaps      {:venues   {:query      (mt/native-query
-                                                            {:query         (str "SELECT DISTINCT VENUES.* "
-                                                                                 "FROM VENUES "
-                                                                                 "LEFT JOIN CHECKINS"
-                                                                                 "       ON CHECKINS.VENUE_ID = VENUES.ID "
-                                                                                 "WHERE CHECKINS.USER_ID IN ({{sandbox}})")
-                                                             :template-tags {"sandbox"
-                                                                             {:name         "sandbox"
-                                                                              :display-name "Sandbox"
-                                                                              :type         :text}}})
-                                              :remappings {"user_id" [:variable [:template-tag "sandbox"]]}}
-                                   :checkins {:remappings {"user_id" [:dimension $checkins.user_id]}}}
-                      :attributes {"user_id" 1}})
+    (met/with-gtaps (mt/$ids
+                      {:gtaps      {:venues   {:query      (mt/native-query
+                                                             {:query         (str "SELECT DISTINCT VENUES.* "
+                                                                                  "FROM VENUES "
+                                                                                  "LEFT JOIN CHECKINS"
+                                                                                  "       ON CHECKINS.VENUE_ID = VENUES.ID "
+                                                                                  "WHERE CHECKINS.USER_ID IN ({{sandbox}})")
+                                                              :template-tags {"sandbox"
+                                                                              {:name         "sandbox"
+                                                                               :display-name "Sandbox"
+                                                                               :type         :text}}})
+                                               :remappings {"user_id" [:variable [:template-tag "sandbox"]]}}
+                                    :checkins {:remappings {"user_id" [:dimension $checkins.user_id]}}}
+                       :attributes {"user_id" 1}})
       (is (= [[2 "2014-09-18T00:00:00Z"  1 31 31 "Bludso's BBQ"         5 33.8894 -118.207 2]
               [72 "2015-04-18T00:00:00Z" 1  1  1 "Red Medicine"         4 10.0646 -165.374 3]
               [80 "2013-12-27T00:00:00Z" 1 99 99 "Golden Road Brewing" 10 34.1505 -118.274 2]]
              (mt/rows
-               (mt/run-mbql-query checkins
-                 {:joins    [{:fields       :all
-                              :source-table $$venues
-                              :condition    [:= $venue_id &Venue.venues.id]
-                              :alias        "Venue"}]
-                  :order-by [[:asc $id]]
-                  :limit    3})))))))
+              (mt/run-mbql-query checkins
+                {:joins    [{:fields       :all
+                             :source-table $$venues
+                             :condition    [:= $venue_id &Venue.venues.id]
+                             :alias        "Venue"}]
+                 :order-by [[:asc $id]]
+                 :limit    3})))))))
 
 (deftest run-sql-queries-to-infer-columns-test
   (testing "Run SQL queries to infer the columns when used as GTAPS (#13716)\n"
     (testing "Should work with SQL queries that return less columns than there were in the original Table\n"
-      (mt/with-gtaps (mt/$ids
-                       {:gtaps      {:venues   {:query      (mt/native-query
-                                                              {:query         (str "SELECT DISTINCT VENUES.ID, VENUES.NAME "
-                                                                                   "FROM VENUES "
-                                                                                   "WHERE VENUES.ID IN ({{sandbox}})")
-                                                               :template-tags {"sandbox"
-                                                                               {:name         "sandbox"
-                                                                                :display-name "Sandbox"
-                                                                                :type         :text}}})
-                                                :remappings {"venue_id" [:variable [:template-tag "sandbox"]]}}
-                                     :checkins {}}
-                        :attributes {"venue_id" 1}})
+      (met/with-gtaps (mt/$ids
+                        {:gtaps      {:venues   {:query      (mt/native-query
+                                                               {:query         (str "SELECT DISTINCT VENUES.ID, VENUES.NAME "
+                                                                                    "FROM VENUES "
+                                                                                    "WHERE VENUES.ID IN ({{sandbox}})")
+                                                                :template-tags {"sandbox"
+                                                                                {:name         "sandbox"
+                                                                                 :display-name "Sandbox"
+                                                                                 :type         :text}}})
+                                                 :remappings {"venue_id" [:variable [:template-tag "sandbox"]]}}
+                                      :checkins {}}
+                         :attributes {"venue_id" 1}})
         (let [venues-gtap-card-id (db/select-one-field :card_id GroupTableAccessPolicy
-                                    :group_id (:id &group)
-                                    :table_id (mt/id :venues))]
+                                                       :group_id (:id &group)
+                                                       :table_id (mt/id :venues))]
           (is (integer? venues-gtap-card-id))
           (testing "GTAP Card should not yet current have result_metadata"
             (is (= nil
@@ -585,14 +588,14 @@
           (testing "Should be able to run the query"
             (is (= [[1 "Red Medicine" 1 "Red Medicine"]]
                    (mt/rows
-                     (mt/run-mbql-query venues
-                       {:fields   [$id $name] ; joined fields get appended automatically because we specify :all :below
-                        :joins    [{:fields       :all
-                                    :source-table $$venues
-                                    :condition    [:= $id &Venue.id]
-                                    :alias        "Venue"}]
-                        :order-by [[:asc $id]]
-                        :limit    3})))))
+                    (mt/run-mbql-query venues
+                      {:fields   [$id $name] ; joined fields get appended automatically because we specify :all :below
+                       :joins    [{:fields       :all
+                                   :source-table $$venues
+                                   :condition    [:= $id &Venue.id]
+                                   :alias        "Venue"}]
+                       :order-by [[:asc $id]]
+                       :limit    3})))))
           (testing "After running the query the first time, result_metadata should have been saved for the GTAP Card"
             (is (schema= [(s/one {:name         (s/eq "ID")
                                   :base_type    (s/eq :type/BigInteger)
@@ -609,19 +612,19 @@
 (deftest run-queries-to-infer-columns-error-on-column-type-changes-test
   (testing "If we have to run a query to infer columns (see above) we should validate column constraints (#14099)\n"
     (letfn [(do-with-sql-gtap [sql f]
-              (mt/with-gtaps (mt/$ids
-                               {:gtaps      {:venues   {:query      (mt/native-query
-                                                                      {:query         sql
-                                                                       :template-tags {"sandbox"
-                                                                                       {:name         "sandbox"
-                                                                                        :display-name "Sandbox"
-                                                                                        :type         :text}}})
-                                                        :remappings {"venue_id" [:variable [:template-tag "sandbox"]]}}
-                                             :checkins {}}
-                                :attributes {"venue_id" 1}})
+              (met/with-gtaps (mt/$ids
+                                {:gtaps      {:venues   {:query      (mt/native-query
+                                                                       {:query         sql
+                                                                        :template-tags {"sandbox"
+                                                                                        {:name         "sandbox"
+                                                                                         :display-name "Sandbox"
+                                                                                         :type         :text}}})
+                                                         :remappings {"venue_id" [:variable [:template-tag "sandbox"]]}}
+                                              :checkins {}}
+                                 :attributes {"venue_id" 1}})
                 (let [venues-gtap-card-id (db/select-one-field :card_id GroupTableAccessPolicy
-                                            :group_id (:id &group)
-                                            :table_id (mt/id :venues))]
+                                                               :group_id (:id &group)
+                                                               :table_id (mt/id :venues))]
                   (is (integer? venues-gtap-card-id))
                   (testing "GTAP Card should not yet current have result_metadata"
                     (is (= nil
@@ -669,8 +672,8 @@
 
 (deftest dont-cache-sandboxes-test
   (cache-test/with-mock-cache [save-chan]
-    (mt/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
-                    :attributes {"cat" 50}}
+    (met/with-gtaps {:gtaps      {:venues (venues-category-mbql-gtap-def)}
+                     :attributes {"cat" 50}}
       (letfn [(run-query []
                 (qp/process-query (assoc (mt/mbql-query venues {:aggregation [[:count]]})
                                          :cache-ttl 100)))]
@@ -692,7 +695,7 @@
             (is (= [[10]]
                    (mt/rows result)))))
         (testing "Run the query with different User attributes, should not get the cached result"
-          (mt/with-user-attributes :rasta {"cat" 40}
+          (met/with-user-attributes :rasta {"cat" 40}
             ;; re-bind current user so updated attributes come in to effect
             (mt/with-test-user :rasta
               (is (= {"cat" 40}
@@ -709,9 +712,9 @@
   (testing "Sandboxing should work with remapped FK columns (#14629)"
     (mt/dataset sample-dataset
       ;; set up GTAP against reviews
-      (mt/with-gtaps (mt/$ids reviews
-                       {:gtaps      {:reviews {:remappings {"user_id" [:dimension $product_id]}}}
-                        :attributes {"user_id" 1}})
+      (met/with-gtaps (mt/$ids reviews
+                        {:gtaps      {:reviews {:remappings {"user_id" [:dimension $product_id]}}}
+                         :attributes {"user_id" 1}})
         ;; grant full data perms for products
         (perms/grant-permissions! (perms-group/all-users) (perms/data-perms-path
                                                            (mt/id)
@@ -757,11 +760,11 @@
   (testing "should work on questions with joins, with sandboxed target table, where target fields cannot be filtered (#13642)"
     ;; Sandbox ORDERS and PRODUCTS
     (mt/dataset sample-dataset
-      (mt/with-gtaps (mt/$ids nil
-                       {:gtaps      {:orders   {:remappings {:user_id [:dimension $orders.user_id]}}
-                                     :products {:remappings {:user_cat [:dimension $products.category]}}}
-                        :attributes {:user_id  "1"
-                                     :user_cat "Widget"}})
+      (met/with-gtaps (mt/$ids nil
+                        {:gtaps      {:orders   {:remappings {:user_id [:dimension $orders.user_id]}}
+                                      :products {:remappings {:user_cat [:dimension $products.category]}}}
+                         :attributes {:user_id  "1"
+                                      :user_cat "Widget"}})
         ;; create query with joins
         (let [query (mt/mbql-query orders
                       {:aggregation [[:count]]
@@ -808,7 +811,7 @@
                                                           :effective_type :type/Text
                                                           :coercion_strategy nil
                                                           :semantic_type  (db/select-one-field :semantic_type Field
-                                                                           :id (mt/id :products :category))
+                                                                                               :id (mt/id :products :category))
                                                           :database_type "CHARACTER VARYING"
                                                           :name          "CATEGORY"}]]
                                        (get-in (qp/preprocess drill-thru-query) [:query :filter])))))]
@@ -833,9 +836,9 @@
   (testing "drill-through should work on implicit joined tables with sandboxes should have correct metadata (#13641)"
     (mt/dataset sample-dataset
       ;; create Sandbox on ORDERS
-      (mt/with-gtaps (mt/$ids nil
-                       {:gtaps      {:orders {:remappings {:user_id [:dimension $orders.user_id]}}}
-                        :attributes {:user_id "1"}})
+      (met/with-gtaps (mt/$ids nil
+                        {:gtaps      {:orders {:remappings {:user_id [:dimension $orders.user_id]}}}
+                         :attributes {:user_id "1"}})
         ;; make sure the sandboxed group can still access the Products table, which is referenced below.
         (perms/grant-permissions! &group (perms/data-perms-path (mt/id) "PUBLIC" (mt/id :products)))
         (letfn [(do-tests []
@@ -901,10 +904,10 @@
 (deftest native-fk-remapping-test
   (testing "FK remapping should still work for questions with native sandboxes (EE #520)"
     (mt/dataset sample-dataset
-      (let [mbql-sandbox-results (mt/with-gtaps {:gtaps      (mt/$ids
-                                                               {:orders   {:remappings {"user_id" [:dimension $orders.user_id]}}
-                                                                :products {:remappings {"user_cat" [:dimension $products.category]}}})
-                                                 :attributes {"user_id" 1, "user_cat" "Widget"}}
+      (let [mbql-sandbox-results (met/with-gtaps {:gtaps      (mt/$ids
+                                                                {:orders   {:remappings {"user_id" [:dimension $orders.user_id]}}
+                                                                 :products {:remappings {"user_cat" [:dimension $products.category]}}})
+                                                  :attributes {"user_id" 1, "user_cat" "Widget"}}
                                    (mt/with-column-remappings [orders.product_id products.title]
                                      (mt/run-mbql-query orders)))]
         (doseq [orders-gtap-card-has-metadata?   [true false]
@@ -912,21 +915,21 @@
           (testing (format "\nwith GTAP metadata for Orders? %s Products? %s"
                            (pr-str orders-gtap-card-has-metadata?)
                            (pr-str products-gtap-card-has-metadata?))
-            (mt/with-gtaps {:gtaps      {:orders   {:query      (mt/native-query
-                                                                  {:query         "SELECT * FROM ORDERS WHERE USER_ID={{uid}} AND TOTAL > 10"
-                                                                   :template-tags {"uid" {:display-name "User ID"
-                                                                                          :id           "1"
-                                                                                          :name         "uid"
-                                                                                          :type         :number}}})
-                                                    :remappings {"user_id" [:variable [:template-tag "uid"]]}}
-                                         :products {:query      (mt/native-query
-                                                                  {:query         "SELECT * FROM PRODUCTS WHERE CATEGORY={{cat}} AND PRICE > 10"
-                                                                   :template-tags {"cat" {:display-name "Category"
-                                                                                          :id           "2"
-                                                                                          :name         "cat"
-                                                                                          :type         :text}}})
-                                                    :remappings {"user_cat" [:variable [:template-tag "cat"]]}}}
-                            :attributes {"user_id" "1", "user_cat" "Widget"}}
+            (met/with-gtaps {:gtaps      {:orders   {:query      (mt/native-query
+                                                                   {:query         "SELECT * FROM ORDERS WHERE USER_ID={{uid}} AND TOTAL > 10"
+                                                                    :template-tags {"uid" {:display-name "User ID"
+                                                                                           :id           "1"
+                                                                                           :name         "uid"
+                                                                                           :type         :number}}})
+                                                     :remappings {"user_id" [:variable [:template-tag "uid"]]}}
+                                          :products {:query      (mt/native-query
+                                                                   {:query         "SELECT * FROM PRODUCTS WHERE CATEGORY={{cat}} AND PRICE > 10"
+                                                                    :template-tags {"cat" {:display-name "Category"
+                                                                                           :id           "2"
+                                                                                           :name         "cat"
+                                                                                           :type         :text}}})
+                                                     :remappings {"user_cat" [:variable [:template-tag "cat"]]}}}
+                             :attributes {"user_id" "1", "user_cat" "Widget"}}
               (when orders-gtap-card-has-metadata?
                 (set-query-metadata-for-gtap-card! &group :orders "uid" 1))
               (when products-gtap-card-has-metadata?
@@ -956,10 +959,10 @@
                     :presto-jdbc)
     (testing "Pivot table queries should work with sandboxed users (#14969)"
       (mt/dataset sample-dataset
-        (mt/with-gtaps {:gtaps      (mt/$ids
-                                      {:orders   {:remappings {:user_id [:dimension $orders.user_id]}}
-                                       :products {:remappings {:user_cat [:dimension $products.category]}}})
-                        :attributes {:user_id 1, :user_cat "Widget"}}
+        (met/with-gtaps {:gtaps      (mt/$ids
+                                       {:orders   {:remappings {:user_id [:dimension $orders.user_id]}}
+                                        :products {:remappings {:user_cat [:dimension $products.category]}}})
+                         :attributes {:user_id 1, :user_cat "Widget"}}
           (perms/grant-permissions! &group (perms/table-query-path (db/select-one Table :id (mt/id :people))))
           (is (= (->> [["Twitter" nil      0 401.51]
                        ["Twitter" "Widget" 0 498.59]
@@ -989,7 +992,7 @@
 
 (deftest caching-test
   (testing "Make sure Sandboxing works in combination with caching (#18579)"
-    (mt/with-gtaps {:gtaps {:venues {:query (mt/mbql-query venues {:order-by [[:asc $id]], :limit 5})}}}
+    (met/with-gtaps {:gtaps {:venues {:query (mt/mbql-query venues {:order-by [[:asc $id]], :limit 5})}}}
       (let [card-id   (db/select-one-field :card_id GroupTableAccessPolicy :group_id (u/the-id &group))
             _         (is (integer? card-id))
             query     (db/select-one-field :dataset_query Card :id card-id)
@@ -1020,18 +1023,18 @@
     (mt/dataset sample-dataset
       ;; with-gtaps creates a new copy of the database. So make sure to do that before anything else. Gets really
       ;; confusing when `(mt/id)` and friends change value halfway through the test
-      (mt/with-gtaps {:gtaps {:products
-                              {:remappings {:category
-                                            ["dimension"
-                                             [:field (mt/id :products :category)
-                                              nil]]}}}}
+      (met/with-gtaps {:gtaps {:products
+                               {:remappings {:category
+                                             ["dimension"
+                                              [:field (mt/id :products :category)
+                                               nil]]}}}}
         (mt/with-persistence-enabled [persist-models!]
           (mt/with-temp* [Card [model {:dataset       true
                                        :dataset_query (mt/mbql-query
-                                                       products
-                                                       ;; note does not include the field we have to filter on. No way
-                                                       ;; to use the sandbox filter on the cached table
-                                                       {:fields [$id $price]})}]]
+                                                          products
+                                                        ;; note does not include the field we have to filter on. No way
+                                                        ;; to use the sandbox filter on the cached table
+                                                          {:fields [$id $price]})}]]
             ;; persist model (as admin, so sandboxing is not applied to the persisted query)
             (mt/with-test-user :crowberto
               (persist-models!))
@@ -1048,7 +1051,7 @@
                                    :database (mt/id)}
                     regular-result (mt/with-test-user :crowberto
                                      (qp/process-query query))
-                    sandboxed-result (mt/with-user-attributes :rasta {"category" "Gizmo"}
+                    sandboxed-result (met/with-user-attributes :rasta {"category" "Gizmo"}
                                        (mt/with-test-user :rasta
                                          (qp/process-query query)))]
                 (testing "Unsandboxed"
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/test_util.clj b/enterprise/backend/test/metabase_enterprise/sandbox/test_util.clj
index 644c0cb7d41..dde792d6b6d 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/test_util.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/test_util.clj
@@ -90,7 +90,7 @@
 (defmacro with-gtaps-for-user
   "Like `with-gtaps`, but for an arbitrary User. `test-user-name-or-user-id` can be a predefined test user e.g. `:rasta`
   or an arbitrary User ID."
-  {:style/indent 2}
+  {:style/indent :defn}
   [test-user-name-or-user-id gtaps-and-attributes-map & body]
   `(do-with-gtaps-for-user (fn [] ~gtaps-and-attributes-map) ~test-user-name-or-user-id (fn [~'&group] ~@body)))
 
@@ -108,13 +108,13 @@
 
   *  `:remappings`, if specified, is saved as the `:attribute_remappings` property of the GTAP.
 
-    (mt/with-gtaps {:gtaps      {:checkins {:query      {:database (data/id), ...}
-                                            :remappings {:user_category [\"variable\" ...]}}}
-                    :attributes {\"user_category\" 1}}
+    (met/with-gtaps {:gtaps      {:checkins {:query      {:database (data/id), ...}
+                                             :remappings {:user_category [\"variable\" ...]}}}
+                     :attributes {\"user_category\" 1}}
       (mt/run-mbql-query checkins {:limit 2}))
 
   Introduces `&group` anaphor, bound to the PermissionsGroup associated with this GTAP."
-  {:style/indent 1}
+  {:style/indent :defn}
   [gtaps-and-attributes-map & body]
   `(do-with-gtaps-for-user (fn [] ~gtaps-and-attributes-map) :rasta (fn [~'&group] ~@body)))
 
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/load_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/load_test.clj
index b625f43bf61..c47def7e28f 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/load_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/load_test.clj
@@ -310,8 +310,6 @@
                                :sparksql  ; foreign-keys is not supported by this driver
                                ;; foreign-keys is not supported by the below driver even though it has joins
                                :bigquery-cloud-sdk))
-
-
       (let [fingerprint (ts/with-world
                           (qp.store/fetch-and-store-database! db-id)
                           (qp.store/fetch-and-store-tables! [table-id
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/test_util.clj b/enterprise/backend/test/metabase_enterprise/serialization/test_util.clj
index 6aa5dfb7e39..936db098311 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/test_util.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/test_util.clj
@@ -126,14 +126,14 @@
           (when (.exists (io/file dump-dir))
             (.delete (io/file dump-dir))))))))
 
-(defmacro with-random-dump-dir {:style/indent 2} [[dump-dir-binding prefix] & body]
+(defmacro with-random-dump-dir {:style/indent 1} [[dump-dir-binding prefix] & body]
   `(do-with-random-dump-dir ~prefix (fn [~dump-dir-binding] ~@body)))
 
 (defmacro with-world
   "Run test in the context of a minimal Metabase instance connected to our test database."
+  {:style/indent 0}
   [& body]
-  `(with-temp-dpc [Database   [{~'db-id :id} (into {:name temp-db-name} (-> (data/id)
-                                                                            Database
+  `(with-temp-dpc [Database   [{~'db-id :id} (into {:name temp-db-name} (-> (data/db)
                                                                             (dissoc :id :features :name)))]
                    Table      [{~'table-id :id :as ~'table} (temp-table (data/id :venues) ~'db-id)]
                    Table      [{~'table-id-categories :id}  (temp-table (data/id :categories) ~'db-id)]
@@ -330,8 +330,7 @@
                    PulseCard           [{~'pulsecard-root-id :id} {:pulse_id ~'pulse-id
                                                                    :card_id  ~'card-id-root}]
                    PulseCard           [{~'pulsecard-collection-id :id} {:pulse_id ~'pulse-id
-                                                                         :card_id  ~'card-id}
-                                                         :query {:source-table (str "card__" ~'card-id-root)}]
+                                                                         :card_id  ~'card-id}]
                    Card                [{~'card-id-template-tags :id}
                                         {:query_type    :native
                                          :name          "My Native Card With Template Tags"
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/upsert_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/upsert_test.clj
index 658ff249d20..e9f61712516 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/upsert_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/upsert_test.clj
@@ -84,40 +84,42 @@
     :else
     entity))
 
+(defn- test-select-identical [model]
+  (testing (name model)
+    (let [id-cond (#'upsert/identity-condition model)
+          [e1 e2] (if (contains? (set id-cond) :name)
+                    [{:name "a"} {:name "b"}]
+                    [{} {}])]
+      (mt/with-temp* [Dashboard [dashboard {:name "Dummy Dashboard"}]
+                      ;; create an additional entity so we're sure whe get the right one
+                      model     [_ (dummy-entity dashboard model e1 1)]
+                      model     [{id :id} (dummy-entity dashboard model e2 2)]]
+        (let [e (db/select-one model (models/primary-key model) id)]
+          ;; make sure that all columns in identity-condition actually exist in the model
+          (is (= (set id-cond) (-> e
+                                   (select-keys id-cond)
+                                   keys
+                                   set)))
+          (is (= (#'upsert/select-identical model (cond-> e
+                                                    ;; engine is a keyword but has to be a string for
+                                                    ;; HoneySQL to not interpret it as a col name
+                                                    (mi/instance-of? Database e) (update :engine name)))
+                 e)))))))
+
 (deftest identical-test
-  (letfn [(test-select-identical [model]
-            (testing (name model)
-              (let [id-cond (#'upsert/identity-condition model)
-                    [e1 e2] (if (contains? (set id-cond) :name)
-                              [{:name "a"} {:name "b"}]
-                              [{} {}])]
-                (mt/with-temp* [Dashboard [dashboard {:name "Dummy Dashboard"}]
-                                ;; create an additional entity so we're sure whe get the right one
-                                model     [_ (dummy-entity dashboard model e1 1)]
-                                model     [{id :id} (dummy-entity dashboard model e2 2)]]
-                  (let [e (db/select-one model (models/primary-key model) id)]
-                    ;; make sure that all columns in identity-condition actually exist in the model
-                    (is (= (set id-cond) (-> e
-                                             (select-keys id-cond)
-                                             keys
-                                             set)))
-                    (is (= (#'upsert/select-identical model (cond-> e
-                                                              ;; engine is a keyword but has to be a string for
-                                                              ;; HoneySQL to not interpret it as a col name
-                                                              (mi/instance-of? Database e) (update :engine name)))
-                           e)))))))]
-    (doseq [model [Collection
-                   Card
-                   Table
-                   Field
-                   Metric
-                   NativeQuerySnippet
-                   Segment
-                   Dashboard
-                   DashboardCard
-                   Database
-                   Pulse
-                   User]]
+  (doseq [model [Collection
+                 Card
+                 Table
+                 Field
+                 Metric
+                 NativeQuerySnippet
+                 Segment
+                 Dashboard
+                 DashboardCard
+                 Database
+                 Pulse
+                 User]]
+    (testing model
       (test-select-identical model))))
 
 (deftest has-post-insert?-test
diff --git a/enterprise/backend/test/metabase_enterprise/test.clj b/enterprise/backend/test/metabase_enterprise/test.clj
new file mode 100644
index 00000000000..bb1e0597339
--- /dev/null
+++ b/enterprise/backend/test/metabase_enterprise/test.clj
@@ -0,0 +1,13 @@
+(ns metabase-enterprise.test
+  "Catch-all test util namespace. Similar to [[metabase.test]], but for EE stuff."
+  (:require
+   [metabase-enterprise.sandbox.test-util :as sandbox.tu]
+   [potemkin :as p]))
+
+(comment sandbox.tu/keep-me)
+
+(p/import-vars
+ [sandbox.tu
+  with-gtaps
+  with-gtaps-for-user
+  with-user-attributes])
diff --git a/src/metabase/analytics/snowplow.clj b/src/metabase/analytics/snowplow.clj
index 9200a7febaf..ac2dfc5bb59 100644
--- a/src/metabase/analytics/snowplow.clj
+++ b/src/metabase/analytics/snowplow.clj
@@ -23,10 +23,12 @@
    (org.apache.http.impl.client HttpClients)
    (org.apache.http.impl.conn PoolingHttpClientConnectionManager)))
 
+(set! *warn-on-reflection* true)
+
 (defsetting analytics-uuid
   (deferred-tru
-   (str "Unique identifier to be used in Snowplow analytics, to identify this instance of Metabase. "
-        "This is a public setting since some analytics events are sent prior to initial setup."))
+    (str "Unique identifier to be used in Snowplow analytics, to identify this instance of Metabase. "
+         "This is a public setting since some analytics events are sent prior to initial setup."))
   :visibility :public
   :setter     :none
   :type       ::public-settings/uuid-nonce
diff --git a/src/metabase/analytics/stats.clj b/src/metabase/analytics/stats.clj
index 2ad9235bc5e..b2d74b13100 100644
--- a/src/metabase/analytics/stats.clj
+++ b/src/metabase/analytics/stats.clj
@@ -258,7 +258,7 @@
   "Get metrics based on pulses
   TODO: characterize by non-user account emails, # emails"
   []
-  (let [pulse-conditions {:left-join [Pulse [:= :pulse.id :pulse_id]], :where [:= :pulse.alert_condition nil]}]
+  (let [pulse-conditions {:left-join [:pulse [:= :pulse.id :pulse_id]], :where [:= :pulse.alert_condition nil]}]
     {:pulses               (db/count Pulse :alert_condition nil)
      ;; "Table Cards" are Cards that include a Table you can download
      :with_table_cards     (num-notifications-with-xls-or-csv-cards [:= :alert_condition nil])
@@ -269,7 +269,7 @@
      :num_cards_per_pulses (medium-histogram (vals (db-frequencies PulseCard :pulse_id   pulse-conditions)))}))
 
 (defn- alert-metrics []
-  (let [alert-conditions {:left-join [Pulse [:= :pulse.id :pulse_id]], :where [:not= (db/qualify Pulse :alert_condition) nil]}]
+  (let [alert-conditions {:left-join [:pulse [:= :pulse.id :pulse_id]], :where [:not= (db/qualify Pulse :alert_condition) nil]}]
     {:alerts               (db/count Pulse :alert_condition [:not= nil])
      :with_table_cards     (num-notifications-with-xls-or-csv-cards [:not= :alert_condition nil])
      :first_time_only      (db/count Pulse :alert_condition [:not= nil], :alert_first_only true)
@@ -279,7 +279,6 @@
      :num_alerts_per_card  (medium-histogram (vals (db-frequencies PulseCard :card_id    alert-conditions)))
      :num_cards_per_alerts (medium-histogram (vals (db-frequencies PulseCard :pulse_id   alert-conditions)))}))
 
-
 (defn- collection-metrics
   "Get metrics on Collection usage."
   []
@@ -305,7 +304,6 @@
                                             json/generate-string))
                                       databases))}))
 
-
 (defn- table-metrics
   "Get metrics based on Tables."
   []
@@ -314,7 +312,6 @@
      :num_per_database (medium-histogram tables :db_id)
      :num_per_schema   (medium-histogram tables :schema)}))
 
-
 (defn- field-metrics
   "Get metrics based on Fields."
   []
diff --git a/src/metabase/api/action.clj b/src/metabase/api/action.clj
index 746fab38a56..a1c18b7ac52 100644
--- a/src/metabase/api/action.clj
+++ b/src/metabase/api/action.clj
@@ -54,9 +54,9 @@
 
 (defn- type->model [existing-action-type]
   (case existing-action-type
-                          :http HTTPAction
-                          :implicit ImplicitAction
-                          :query QueryAction))
+    :http     HTTPAction
+    :implicit ImplicitAction
+    :query    QueryAction))
 
 #_{:clj-kondo/ignore [:deprecated-var]}
 (api/defendpoint-schema DELETE "/:action-id"
diff --git a/src/metabase/api/activity.clj b/src/metabase/api/activity.clj
index dd02088ca52..ec4c6cc6b5d 100644
--- a/src/metabase/api/activity.clj
+++ b/src/metabase/api/activity.clj
@@ -4,13 +4,9 @@
    [clojure.string :as str]
    [compojure.core :refer [GET]]
    [medley.core :as m]
-   #_{:clj-kondo/ignore [:deprecated-var]}
-   [metabase.api.common
-    :refer [*current-user-id* defendpoint-schema define-routes]]
+   [metabase.api.common :as api :refer [*current-user-id* define-routes]]
    [metabase.models.activity :refer [Activity]]
-   [metabase.models.bookmark :refer [CardBookmark DashboardBookmark]]
    [metabase.models.card :refer [Card]]
-   [metabase.models.collection :refer [Collection]]
    [metabase.models.dashboard :refer [Dashboard]]
    [metabase.models.interface :as mi]
    [metabase.models.query-execution :refer [QueryExecution]]
@@ -88,7 +84,7 @@
                                     (existing-card? (:card_id dashcard))))))))))))
 
 #_{:clj-kondo/ignore [:deprecated-var]}
-(defendpoint-schema GET "/"
+(api/defendpoint-schema GET "/"
   "Get recent activity."
   []
   (filter mi/can-read? (-> (db/select Activity, {:order-by [[:timestamp :desc]], :limit 40})
@@ -102,11 +98,11 @@
         "card"      [Card
                      :id :name :collection_id :description :display
                      :dataset_query :dataset :archived
-                     (db/qualify Collection :authority_level)]
+                     :collection.authority_level]
         "dashboard" [Dashboard
                      :id :name :collection_id :description
                      :archived
-                     (db/qualify Collection :authority_level)]
+                     :collection.authority_level]
         "table"     [Table
                      :id :name :db_id
                      :display_name :initial_sync_status
@@ -115,7 +111,7 @@
             self-qualify #(db/qualify model-symb %)]
         (cond-> {:where [:in (self-qualify :id) ids]}
           (not= model "table")
-          (merge {:left-join [Collection [:= (db/qualify Collection :id) (self-qualify :collection_id)]]})))))
+          (merge {:left-join [:collection [:= :collection.id (self-qualify :collection_id)]]})))))
 
 (defn- select-items! [model ids]
   (when (seq ids)
@@ -158,24 +154,27 @@
                                                  [:= :bm.id nil]]
                                      :order-by  [[:max_ts :desc] [:model :desc]]
                                      :limit     views-limit
-                                     :left-join [[DashboardBookmark :bm]
+                                     :left-join [[:dashboard_bookmark :bm]
                                                  [:and
                                                   [:= :model "dashboard"]
                                                   [:= :bm.user_id *current-user-id*]
                                                   [:= :model_id :bm.dashboard_id]]]})
-        card-runs                 (->> (db/select [QueryExecution [:%min.executor_id :user_id] [(db/qualify QueryExecution :card_id) :model_id]
-                                                   [:%count.* :cnt] [:%max.started_at :max_ts]]
-                                         {:group-by [(db/qualify QueryExecution :card_id) :context]
+        card-runs                 (->> (db/select [QueryExecution
+                                                   [:%min.executor_id :user_id]
+                                                   [:query_execution.card_id :model_id]
+                                                   [:%count.* :cnt]
+                                                   [:%max.started_at :max_ts]]
+                                         {:group-by [:query_execution.card_id :context]
                                           :where    [:and
                                                      (when-not all-users? [:= :executor_id *current-user-id*])
                                                      [:= :context (hx/literal :question)]
                                                      [:= :bm.id nil]]
                                           :order-by [[:max_ts :desc]]
                                           :limit    card-runs-limit
-                                          :left-join [[CardBookmark :bm]
+                                          :left-join [[:card_bookmark :bm]
                                                       [:and
                                                        [:= :bm.user_id *current-user-id*]
-                                                       [:= (db/qualify QueryExecution :card_id) :bm.card_id]]]})
+                                                       [:= :query_execution.card_id :bm.card_id]]]})
                                        (map #(dissoc % :row_count))
                                        (map #(assoc % :model "card")))]
     (->> (concat card-runs dashboard-and-table-views)
@@ -186,7 +185,7 @@
 (def ^:private card-runs-limit 8)
 
 #_{:clj-kondo/ignore [:deprecated-var]}
-(defendpoint-schema GET "/recent_views"
+(api/defendpoint-schema GET "/recent_views"
   "Get the list of 5 things the current user has been viewing most recently."
   []
   (let [views (views-and-runs views-limit card-runs-limit false)
@@ -249,7 +248,7 @@
         (mapcat #(get groups %) model-precedence))))
 
 #_{:clj-kondo/ignore [:deprecated-var]}
-(defendpoint-schema GET "/popular_items"
+(api/defendpoint-schema GET "/popular_items"
   "Get the list of 5 popular things for the current user. Query takes 8 and limits to 5 so that if it
   finds anything archived, deleted, etc it can hopefully still get 5."
   []
diff --git a/src/metabase/api/card.clj b/src/metabase/api/card.clj
index f50b25dae79..cd6612560cd 100644
--- a/src/metabase/api/card.clj
+++ b/src/metabase/api/card.clj
@@ -181,7 +181,6 @@
   (let [raw-card (db/select-one Card :id id)
         card (-> raw-card
                  (hydrate :creator
-                          :bookmarked
                           :dashboard_count
                           :parameter_usage_count
                           :can_write
diff --git a/src/metabase/api/common.clj b/src/metabase/api/common.clj
index 5f16e2032fd..b34a8aaed65 100644
--- a/src/metabase/api/common.clj
+++ b/src/metabase/api/common.clj
@@ -420,7 +420,7 @@
    obj)
 
   ([entity id]
-   (read-check (entity id)))
+   (read-check (db/select-one entity :id id)))
 
   ([entity id & other-conditions]
    (read-check (apply db/select-one entity :id id other-conditions))))
@@ -435,7 +435,7 @@
    (check-403 (mi/can-write? obj))
    obj)
   ([entity id]
-   (write-check (entity id)))
+   (write-check (db/select-one entity :id id)))
   ([entity id & other-conditions]
    (write-check (apply db/select-one entity :id id other-conditions))))
 
diff --git a/src/metabase/api/dashboard.clj b/src/metabase/api/dashboard.clj
index 2be2c8c337d..258622a0e73 100644
--- a/src/metabase/api/dashboard.clj
+++ b/src/metabase/api/dashboard.clj
@@ -227,24 +227,23 @@
   card. The `:discard` key is a vector of cards which were not copied due to permissions."
   [ordered-cards]
   (letfn [(split-cards [{:keys [card series] :as db-card}]
-
             (cond
-              (nil? (:card_id db-card)) ;; text card
-              []
+              (nil? (:card_id db-card)) ; text card
+              {}
 
               ;; cards without permissions are just a map with an :id from [[hide-unreadable-card]]
               (not (mi/model card))
-              [nil (into [card] series)]
+              {:retain nil, :discard (into [card] series)}
 
               (mi/can-read? card)
               (let [{writable true unwritable false} (group-by (comp boolean mi/can-read?)
                                                                series)]
-                [(into [card] writable) unwritable])
+                {:retain (into [card] writable), :discard unwritable})
               ;; if you can't write the base, we don't have anywhere to put the series
               :else
-              [[] (into [card] series)]))]
+              {:discard (into [card] series)}))]
     (reduce (fn [acc db-card]
-              (let [[retain discard] (split-cards db-card)]
+              (let [{:keys [retain discard]} (split-cards db-card)]
                 (-> acc
                     (update :copy merge (m/index-by :id retain))
                     (update :discard concat discard))))
diff --git a/src/metabase/api/database.clj b/src/metabase/api/database.clj
index fffc3d97483..5a490504867 100644
--- a/src/metabase/api/database.clj
+++ b/src/metabase/api/database.clj
@@ -23,7 +23,6 @@
     :as database
     :refer [Database protected-password]]
    [metabase.models.field :refer [Field readable-fields-only]]
-   [metabase.models.field-values :refer [FieldValues]]
    [metabase.models.interface :as mi]
    [metabase.models.permissions :as perms]
    [metabase.models.persisted-info :as persisted-info]
@@ -87,10 +86,10 @@
                                     :write
                                     :none))))
 
-(defn- card-database-supports-nested-queries? [{{database-id :database} :dataset_query, :as _card}]
+(defn- card-database-supports-nested-queries? [{{database-id :database, :as database} :dataset_query, :as _card}]
   (when database-id
     (when-let [driver (driver.u/database->driver database-id)]
-      (driver/supports? driver :nested-queries))))
+      (driver/database-supports? driver :nested-queries database))))
 
 (defn- card-has-ambiguous-columns?
   "We know a card has ambiguous columns if any of the columns that come back end in `_2` (etc.) because that's what
@@ -596,15 +595,15 @@
    substring (s/maybe su/NonBlankString)}
   (api/read-check Database id)
   (when (and (str/blank? prefix) (str/blank? substring))
-    (throw (ex-info "Must include prefix or search" {:status-code 400})))
+    (throw (ex-info (tru "Must include prefix or search") {:status-code 400})))
   (try
     (cond
       substring
       (autocomplete-suggestions id (str "%" substring "%"))
       prefix
       (autocomplete-suggestions id (str prefix "%")))
-    (catch Throwable t
-      (log/warn "Error with autocomplete: " (.getMessage t)))))
+    (catch Throwable e
+      (log/warn e (trs "Error with autocomplete: {0}" (ex-message e))))))
 
 #_{:clj-kondo/ignore [:deprecated-var]}
 (api/defendpoint-schema GET "/:id/card_autocomplete_suggestions"
@@ -619,8 +618,8 @@
     (->> (autocomplete-cards id query)
          (filter mi/can-read?)
          (map #(select-keys % [:id :name :dataset :collection_name])))
-    (catch Throwable t
-      (log/warn "Error with autocomplete: " (.getMessage t)))))
+    (catch Throwable e
+      (log/warn e (trs "Error with autocomplete: {0}" (ex-message e))))))
 
 
 ;;; ------------------------------------------ GET /api/database/:id/fields ------------------------------------------
@@ -1022,7 +1021,7 @@
 
 (defn- delete-all-field-values-for-database! [database-or-id]
   (when-let [field-values-ids (seq (database->field-values-ids database-or-id))]
-    (db/execute! {:delete-from FieldValues
+    (db/execute! {:delete-from :metabase_fieldvalues
                   :where       [:in :id field-values-ids]})))
 
 
@@ -1099,56 +1098,51 @@
                          :visibility_type nil
                          {:order-by [[:display_name :asc]]})))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/:id/schema/:schema"
+(api/defendpoint GET "/:id/schema/:schema"
   "Returns a list of Tables for the given Database `id` and `schema`"
   [id schema]
   (api/check-404 (seq (schema-tables-list id schema))))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/:id/schema/"
+(api/defendpoint GET "/:id/schema/"
   "Return a list of Tables for a Database whose `schema` is `nil` or an empty string."
   [id]
   (api/check-404 (seq (concat (schema-tables-list id nil)
                               (schema-tables-list id "")))))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET ["/:virtual-db/schema/:schema"
-                             :virtual-db (re-pattern (str mbql.s/saved-questions-virtual-database-id))]
+(api/defendpoint GET ["/:virtual-db/schema/:schema"
+                      :virtual-db (re-pattern (str mbql.s/saved-questions-virtual-database-id))]
   "Returns a list of Tables for the saved questions virtual database."
   [schema]
   (when (public-settings/enable-nested-queries)
     (->> (source-query-cards
           :card
           :additional-constraints [(if (= schema (api.table/root-collection-schema-name))
-                                      [:= :collection_id nil]
-                                      [:in :collection_id (api/check-404 (seq (db/select-ids Collection :name schema)))])])
+                                     [:= :collection_id nil]
+                                     [:in :collection_id (api/check-404 (not-empty (db/select-ids Collection :name schema)))])])
          (map api.table/card->virtual-table))))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET ["/:virtual-db/datasets/:schema"
-                             :virtual-db (re-pattern (str mbql.s/saved-questions-virtual-database-id))]
+(api/defendpoint GET ["/:virtual-db/datasets/:schema"
+                      :virtual-db (re-pattern (str mbql.s/saved-questions-virtual-database-id))]
   "Returns a list of Tables for the datasets virtual database."
   [schema]
   (when (public-settings/enable-nested-queries)
     (->> (source-query-cards
           :dataset
           :additional-constraints [(if (= schema (api.table/root-collection-schema-name))
-                                      [:= :collection_id nil]
-                                      [:in :collection_id (api/check-404 (seq (db/select-ids Collection :name schema)))])])
+                                     [:= :collection_id nil]
+                                     [:in :collection_id (api/check-404 (not-empty (db/select-ids Collection :name schema)))])])
          (map api.table/card->virtual-table))))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/db-ids-with-deprecated-drivers"
+(api/defendpoint GET "/db-ids-with-deprecated-drivers"
   "Return a list of database IDs using currently deprecated drivers."
   []
   (map
-    u/the-id
-    (filter
-      (fn [database]
-        (let [info (driver.u/available-drivers-info)
-              d    (driver.u/database->driver database)]
-          (some? (:superseded-by (d info)))))
-      (db/select-ids Database))))
+   u/the-id
+   (filter
+    (fn [database]
+      (let [info (driver.u/available-drivers-info)
+            d    (driver.u/database->driver database)]
+        (some? (:superseded-by (d info)))))
+    (db/select-ids Database))))
 
 (api/define-routes)
diff --git a/src/metabase/api/embed.clj b/src/metabase/api/embed.clj
index eefa2750a0b..a0df238431c 100644
--- a/src/metabase/api/embed.clj
+++ b/src/metabase/api/embed.clj
@@ -237,10 +237,10 @@
 (defn card-for-unsigned-token
   "Return the info needed for embedding about Card specified in `token`. Additional `constraints` can be passed to the
   `public-card` function that fetches the Card."
-  {:style/indent 1}
   [unsigned-token & {:keys [embedding-params constraints]}]
-  (let [card-id        (embed/get-in-unsigned-token-or-throw unsigned-token [:resource :question])
-        token-params   (embed/get-in-unsigned-token-or-throw unsigned-token [:params])]
+  {:pre [((some-fn empty? sequential?) constraints) (even? (count constraints))]}
+  (let [card-id      (embed/get-in-unsigned-token-or-throw unsigned-token [:resource :question])
+        token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])]
     (-> (apply api.public/public-card :id card-id, constraints)
         add-implicit-card-parameters
         (remove-token-parameters token-params)
@@ -270,8 +270,8 @@
 (defn dashboard-for-unsigned-token
   "Return the info needed for embedding about Dashboard specified in `token`. Additional `constraints` can be passed to
   the `public-dashboard` function that fetches the Dashboard."
-  {:style/indent 1}
   [unsigned-token & {:keys [embedding-params constraints]}]
+  {:pre [((some-fn empty? sequential?) constraints) (even? (count constraints))]}
   (let [dashboard-id (embed/get-in-unsigned-token-or-throw unsigned-token [:resource :dashboard])
         token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])]
     (-> (apply api.public/public-dashboard :id dashboard-id, constraints)
@@ -327,8 +327,7 @@
 
 ;;; ------------------------------------------- /api/embed/card endpoints --------------------------------------------
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/card/:token"
+(api/defendpoint GET "/card/:token"
   "Fetch a Card via a JSON Web Token signed with the `embedding-secret-key`.
 
    Token should have the following format:
@@ -337,7 +336,7 @@
   [token]
   (let [unsigned (embed/unsign token)]
     (check-embedding-enabled-for-card (embed/get-in-unsigned-token-or-throw unsigned [:resource :question]))
-    (card-for-unsigned-token unsigned, :constraints {:enable_embedding true})))
+    (card-for-unsigned-token unsigned, :constraints [:enable_embedding true])))
 
 (defn ^:private run-query-for-unsigned-token-async
   "Run the query belonging to Card identified by `unsigned-token`. Checks that embedding is enabled both globally and
@@ -386,8 +385,7 @@
 
 ;;; ----------------------------------------- /api/embed/dashboard endpoints -----------------------------------------
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/dashboard/:token"
+(api/defendpoint GET "/dashboard/:token"
   "Fetch a Dashboard via a JSON Web Token signed with the `embedding-secret-key`.
 
    Token should have the following format:
@@ -396,7 +394,7 @@
   [token]
   (let [unsigned (embed/unsign token)]
     (check-embedding-enabled-for-dashboard (embed/get-in-unsigned-token-or-throw unsigned [:resource :dashboard]))
-    (dashboard-for-unsigned-token unsigned, :constraints {:enable_embedding true})))
+    (dashboard-for-unsigned-token unsigned, :constraints [:enable_embedding true])))
 
 (defn- dashcard-results-for-signed-token-async
   "Fetch the results of running a Card belonging to a Dashboard using a JSON Web Token signed with the
diff --git a/src/metabase/api/permissions.clj b/src/metabase/api/permissions.clj
index 8ca90e85702..ea2e0b40ed9 100644
--- a/src/metabase/api/permissions.clj
+++ b/src/metabase/api/permissions.clj
@@ -184,8 +184,7 @@
                  :is_group_manager boolean}]}"
   []
   (validation/check-group-manager)
-  (group-by :user_id (db/select [PermissionsGroupMembership [:id :membership_id :is_group_manager]
-                                 :group_id :user_id :is_group_manager]
+  (group-by :user_id (db/select [PermissionsGroupMembership [:id :membership_id] :group_id :user_id :is_group_manager]
                                 (cond-> {}
                                   (and (not api/*is-superuser?*)
                                        api/*is-group-manager?*)
diff --git a/src/metabase/api/public.clj b/src/metabase/api/public.clj
index ef1b4aa4763..34b02aa71c9 100644
--- a/src/metabase/api/public.clj
+++ b/src/metabase/api/public.clj
@@ -174,6 +174,7 @@
   "Return a public Dashboard matching key-value `conditions`, removing all columns that should not be visible to the
    general public. Throws a 404 if the Dashboard doesn't exist."
   [& conditions]
+  {:pre [(even? (count conditions))]}
   (-> (api/check-404 (apply db/select-one [Dashboard :name :description :id :parameters], :archived false, conditions))
       (hydrate [:ordered_cards :card :series :dashcard/action] :param_fields)
       api.dashboard/add-query-average-durations
diff --git a/src/metabase/api/revision.clj b/src/metabase/api/revision.clj
index 84d9f051412..cc1e15f9cac 100644
--- a/src/metabase/api/revision.clj
+++ b/src/metabase/api/revision.clj
@@ -37,7 +37,7 @@
   {entity Entity, id s/Int, revision_id s/Int}
   (let [[model instance] (model-and-instance entity id)
         _                (api/write-check instance)
-        revision         (api/check-404 (db/select-one Revision :model (:name model), :model_id id, :id revision_id))]
+        revision         (api/check-404 (db/select-one Revision :model (name model), :model_id id, :id revision_id))]
     ;; if reverting a Card, make sure we have *data* permissions to run the query we're reverting to
     (when (= model Card)
       (api.card/check-data-permissions-for-query (get-in revision [:object :dataset_query])))
diff --git a/src/metabase/api/setup.clj b/src/metabase/api/setup.clj
index 550803bd835..d8c702311eb 100644
--- a/src/metabase/api/setup.clj
+++ b/src/metabase/api/setup.clj
@@ -57,11 +57,11 @@
             {:status-code 403})))
   (let [session-id (str (UUID/randomUUID))
         new-user   (db/insert! User
-                     :email        email
-                     :first_name   first-name
-                     :last_name    last-name
-                     :password     (str (UUID/randomUUID))
-                     :is_superuser true)
+                               :email        email
+                               :first_name   first-name
+                               :last_name    last-name
+                               :password     (str (UUID/randomUUID))
+                               :is_superuser true)
         user-id    (u/the-id new-user)]
     ;; this results in a second db call, but it avoids redundant password code so figure it's worth it
     (user/set-password! user-id password)
diff --git a/src/metabase/api/table.clj b/src/metabase/api/table.clj
index 64622d3430a..0cef5223f1e 100644
--- a/src/metabase/api/table.clj
+++ b/src/metabase/api/table.clj
@@ -34,16 +34,14 @@
   "Schema for a valid table field ordering."
   (apply s/enum (map name table/field-orderings)))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/"
+(api/defendpoint GET "/"
   "Get all `Tables`."
   []
   (as-> (db/select Table, :active true, {:order-by [[:name :asc]]}) tables
     (hydrate tables :db)
     (filterv mi/can-read? tables)))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/:id"
+(api/defendpoint GET "/:id"
   "Get `Table` with ID."
   [id include_editable_data_model]
   (let [api-perm-check-fn (if (Boolean/parseBoolean include_editable_data_model)
@@ -65,8 +63,8 @@
         changed-field-order? (not= (:field_order updated-table) (:field_order existing-table))]
     (if changed-field-order?
       (do
-       (table/update-field-positions! updated-table)
-       (hydrate updated-table [:fields [:target :has_field_values] :dimensions :has_field_values]))
+        (table/update-field-positions! updated-table)
+        (hydrate updated-table [:fields [:target :has_field_values] :dimensions :has_field_values]))
       updated-table)))
 
 (defn- sync-unhidden-tables
@@ -399,15 +397,13 @@
         (assoc-dimension-options (driver.u/database->driver database_id))
         remove-nested-pk-fk-semantic-types)))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/card__:id/fks"
+(api/defendpoint GET "/card__:id/fks"
   "Return FK info for the 'virtual' table for a Card. This is always empty, so this endpoint
    serves mainly as a placeholder to avoid having to change anything on the frontend."
   []
   []) ; return empty array
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/:id/fks"
+(api/defendpoint GET "/:id/fks"
   "Get all foreign keys whose destination is a `Field` that belongs to this `Table`."
   [id]
   (api/read-check Table id)
@@ -420,9 +416,7 @@
        :destination_id (:fk_target_field_id origin-field)
        :destination    (hydrate (db/select-one Field :id (:fk_target_field_id origin-field)) :table)})))
 
-
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema POST "/:id/rescan_values"
+(api/defendpoint POST "/:id/rescan_values"
   "Manually trigger an update for the FieldValues for the Fields belonging to this Table. Only applies to Fields that
    are eligible for FieldValues."
   [id]
@@ -437,8 +431,7 @@
          (sync.field-values/update-field-values-for-table! table))))
     {:status :success}))
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema POST "/:id/discard_values"
+(api/defendpoint POST "/:id/discard_values"
   "Discard the FieldValues belonging to the Fields in this Table. Only applies to fields that have FieldValues. If
    this Table's Database is set up to automatically sync FieldValues, they will be recreated during the next cycle."
   [id]
@@ -447,8 +440,7 @@
     (db/simple-delete! FieldValues :field_id [:in field-ids]))
   {:status :success})
 
-#_{:clj-kondo/ignore [:deprecated-var]}
-(api/defendpoint-schema GET "/:id/related"
+(api/defendpoint GET "/:id/related"
   "Return related entities."
   [id]
   (-> (db/select-one Table :id id) api/read-check related/related))
diff --git a/src/metabase/api/user.clj b/src/metabase/api/user.clj
index e219455153b..25cdb9f9536 100644
--- a/src/metabase/api/user.clj
+++ b/src/metabase/api/user.clj
@@ -333,12 +333,13 @@
       ;; implicitly prevent group manager from updating users' info
       (when (or (= id api/*current-user-id*)
                 api/*is-superuser?*)
-        (api/check-500
-         (db/update! User id (u/select-keys-when body
-                               :present (cond-> #{:first_name :last_name :locale}
-                                          api/*is-superuser?* (conj :login_attributes))
-                               :non-nil (cond-> #{:email}
-                                          api/*is-superuser?* (conj :is_superuser)))))
+        (when-let [changes (not-empty
+                            (u/select-keys-when body
+                              :present (cond-> #{:first_name :last_name :locale}
+                                         api/*is-superuser?* (conj :login_attributes))
+                              :non-nil (cond-> #{:email}
+                                         api/*is-superuser?* (conj :is_superuser))))]
+          (db/update! User id changes))
         (maybe-update-user-personal-collection-name! user-before-update body))
       (maybe-set-user-group-memberships! id user_group_memberships is_superuser)))
   (-> (fetch-user :id id)
diff --git a/src/metabase/automagic_dashboards/core.clj b/src/metabase/automagic_dashboards/core.clj
index d3866e92086..80d0b72a82a 100644
--- a/src/metabase/automagic_dashboards/core.clj
+++ b/src/metabase/automagic_dashboards/core.clj
@@ -221,8 +221,10 @@
 (def ^:private ^{:arglists '([card-or-question])} native-query?
   (comp #{:native} qp.util/normalize-token #(get-in % [:dataset_query :type])))
 
-(def ^:private ^{:arglists '([card-or-question])} source-question
-  (comp Card qp.util/query->source-card-id :dataset_query))
+(defn- source-question
+  [card-or-question]
+  (when-let [source-card-id (qp.util/query->source-card-id (:dataset_query card-or-question))]
+    (db/select-one Card :id source-card-id)))
 
 (defn- table-like?
   [card-or-question]
@@ -701,7 +703,7 @@
     (-> target field/table (assoc :link id))))
 
 (def ^:private ^{:arglists '([source])} source->engine
-  (comp :engine Database (some-fn :db_id :database_id)))
+  (comp :engine (partial db/select-one Database :id) (some-fn :db_id :database_id)))
 
 (defmulti
   ^{:private  true
diff --git a/src/metabase/cmd/rotate_encryption_key.clj b/src/metabase/cmd/rotate_encryption_key.clj
index 0106e80d161..d12419806fc 100644
--- a/src/metabase/cmd/rotate_encryption_key.clj
+++ b/src/metabase/cmd/rotate_encryption_key.clj
@@ -13,7 +13,7 @@
    [toucan.db :as db]))
 
 (defn rotate-encryption-key!
-  "Rotate the current configured db using the current MB_ENCRYPTION_SECRET_KEY env var and `to-key` argument."
+  "Rotate the current configured db using the current `MB_ENCRYPTION_SECRET_KEY` env var and `to-key` argument."
   [to-key]
   (when-not (mdb/db-is-set-up?)
     (log/warnf "Database not found. Metabase will create a new database at %s and proceeed encrypting." "2")
@@ -35,7 +35,7 @@
     (jdbc/with-db-transaction [t-conn {:datasource (mdb.connection/data-source)}]
       (doseq [[id details] (db/select-id->field :details Database)]
         (when (encryption/possibly-encrypted-string? details)
-          (throw (ex-info (trs "Can't decrypt app db with MB_ENCRYPTION_SECRET_KEY") {:database-id id})))
+          (throw (ex-info (trs "Can''t decrypt app db with MB_ENCRYPTION_SECRET_KEY") {:database-id id})))
         (jdbc/update! t-conn
                       :metabase_database
                       {:details (encrypt-str-fn (json/encode details))}
@@ -53,7 +53,7 @@
       ;; of whether they are the "current version" or not), should be updated with the new key
       (doseq [[id value] (db/select-id->field :value Secret)]
         (when (encryption/possibly-encrypted-string? value)
-          (throw (ex-info (trs "Can't decrypt secret value with MB_ENCRYPTION_SECRET_KEY") {:secret-id id})))
+          (throw (ex-info (trs "Can''t decrypt secret value with MB_ENCRYPTION_SECRET_KEY") {:secret-id id})))
         (jdbc/update! t-conn
                       :secret
                       {value-column (encrypt-bytes-fn value)}
diff --git a/src/metabase/db/query.clj b/src/metabase/db/query.clj
index 001da0657fa..b2cf385e942 100644
--- a/src/metabase/db/query.clj
+++ b/src/metabase/db/query.clj
@@ -103,6 +103,8 @@
   See namespace documentation for [[metabase.db.query]] for pro debugging tips."
   [sql-args-or-honey-sql-map & {:as jdbc-options}]
   (increment-call-count!)
+  ;; make sure [[metabase.db.setup]] gets loaded so default Honey SQL options and the like are loaded.
+  (classloader/require 'metabase.db.setup)
   (let [sql-args (compile sql-args-or-honey-sql-map)]
     ;; catch errors running the query and rethrow with the failing generated SQL and the failing Honey SQL form -- this
     ;; will help with debugging stuff. This should mostly be dev-facing because we should hopefully not be committing
@@ -129,6 +131,8 @@
   See namespace documentation for [[metabase.db.query]] for pro debugging tips."
   [sql-args-or-honey-sql-map & {:as jdbc-options}]
   (increment-call-count!)
+  ;; make sure [[metabase.db.setup]] gets loaded so default Honey SQL options and the like are loaded.
+  (classloader/require 'metabase.db.setup)
   (let [sql-args (compile sql-args-or-honey-sql-map)]
     ;; It doesn't really make sense to put a try-catch around this since it will return immediately and not execute
     ;; until we actually reduce it
diff --git a/src/metabase/db/setup.clj b/src/metabase/db/setup.clj
index cb83f327dff..69a0b17b58d 100644
--- a/src/metabase/db/setup.clj
+++ b/src/metabase/db/setup.clj
@@ -158,8 +158,10 @@
 ;;; [[*application-db*]]; register this as the default quoting style for Toucan. Then
 (defn quote-for-application-db
   "Quote SQL identifier string `s` appropriately for the currently bound application database."
-  [s]
-  ((get @#'hformat/quote-fns (mdb.connection/quoting-style (mdb.connection/db-type))) s))
+  ([s]
+   (quote-for-application-db (mdb.connection/quoting-style (mdb.connection/db-type)) s))
+  ([db-type s]
+   ((get @#'hformat/quote-fns db-type) s)))
 
 ;;; register with Honey SQL 1
 (alter-var-root #'hformat/quote-fns assoc ::application-db quote-for-application-db)
diff --git a/src/metabase/driver/sql/query_processor.clj b/src/metabase/driver/sql/query_processor.clj
index 00789d7439e..62ad26f3cae 100644
--- a/src/metabase/driver/sql/query_processor.clj
+++ b/src/metabase/driver/sql/query_processor.clj
@@ -27,7 +27,6 @@
    [pretty.core :refer [PrettyPrintable]]
    [schema.core :as s])
   (:import
-   (metabase.models.field FieldInstance)
    (metabase.util.honey_sql_1_extensions Identifier TypedHoneySQLForm)))
 
 (comment metabase.models.field/keep-me) ; for FieldInstance
@@ -863,15 +862,15 @@
   [:= (->honeysql driver field) (->honeysql driver value)])
 
 (defn- correct-null-behaviour
-  [driver [op & args]]
-  (let [field-arg (mbql.u/match-one args
-                    FieldInstance &match
-                    :field        &match)]
+  [driver [op & args :as clause]]
+  (if-let [field-arg (mbql.u/match-one args
+                       :field          &match)]
     ;; We must not transform the head again else we'll have an infinite loop
     ;; (and we can't do it at the call-site as then it will be harder to fish out field references)
     [:or
      (into [op] (map (partial ->honeysql driver)) args)
-     [:= (->honeysql driver field-arg) nil]]))
+     [:= (->honeysql driver field-arg) nil]]
+    clause))
 
 (defmethod ->honeysql [:sql :!=]
   [driver [_ field value]]
diff --git a/src/metabase/integrations/common.clj b/src/metabase/integrations/common.clj
index dc34491ea9d..b0b95b145ce 100644
--- a/src/metabase/integrations/common.clj
+++ b/src/metabase/integrations/common.clj
@@ -48,6 +48,6 @@
       ;; if adding membership fails for one reason or another (i.e. if the group doesn't exist) log the error add the
       ;; user to the other groups rather than failing entirely
       (try
-       (db/insert! PermissionsGroupMembership :group_id id, :user_id user-id)
-       (catch Throwable e
-         (log/error e (trs "Error adding User {0} to Group {1}" user-id id)))))))
+        (db/insert! PermissionsGroupMembership :group_id id, :user_id user-id)
+        (catch Throwable e
+          (log/error e (trs "Error adding User {0} to Group {1}" user-id id)))))))
diff --git a/src/metabase/integrations/google.clj b/src/metabase/integrations/google.clj
index d7bec1624cc..6226557636c 100644
--- a/src/metabase/integrations/google.clj
+++ b/src/metabase/integrations/google.clj
@@ -6,6 +6,7 @@
    [clojure.tools.logging :as log]
    [metabase.api.common :as api]
    [metabase.integrations.google.interface :as google.i]
+   [metabase.models.interface :as mi]
    [metabase.models.setting :as setting :refer [defsetting]]
    [metabase.models.setting.multi-setting
     :refer [define-multi-setting-impl]]
@@ -110,7 +111,7 @@
   ;; things hairy and only enforce those for non-Google Auth users
   (user/create-new-google-auth-user! new-user))
 
-(s/defn ^:private google-auth-fetch-or-create-user! :- metabase.models.user.UserInstance
+(s/defn ^:private google-auth-fetch-or-create-user! :- (mi/InstanceOf User)
   [first-name last-name email]
   (or (db/select-one [User :id :email :last_login] :%lower.email (u/lower-case-en email))
       (google-auth-create-new-user! {:first_name first-name
diff --git a/src/metabase/integrations/ldap/default_implementation.clj b/src/metabase/integrations/ldap/default_implementation.clj
index 2f23da5fdfb..4e97b73bd5b 100644
--- a/src/metabase/integrations/ldap/default_implementation.clj
+++ b/src/metabase/integrations/ldap/default_implementation.clj
@@ -5,6 +5,7 @@
    [clojure.string :as str]
    [metabase.integrations.common :as integrations.common]
    [metabase.integrations.ldap.interface :as i]
+   [metabase.models.interface :as mi]
    [metabase.models.user :as user :refer [User]]
    [metabase.public-settings.premium-features
     :refer [defenterprise-schema]]
@@ -116,7 +117,7 @@
       flatten
       set))
 
-(defenterprise-schema fetch-or-create-user! :- (class User)
+(defenterprise-schema fetch-or-create-user! :- (mi/InstanceOf User)
   "Using the `user-info` (from `find-user`) get the corresponding Metabase user, creating it if necessary."
   metabase-enterprise.enhancements.integrations.ldap
   [{:keys [first-name last-name email groups]} :- i/UserInfo
diff --git a/src/metabase/models/card.clj b/src/metabase/models/card.clj
index 1d464be9d5d..301d77c2959 100644
--- a/src/metabase/models/card.clj
+++ b/src/metabase/models/card.clj
@@ -3,6 +3,7 @@
   is a historical name, but is the same thing; both terms are used interchangeably in the backend codebase."
   (:require
    [clojure.set :as set]
+   [clojure.string :as str]
    [clojure.tools.logging :as log]
    [medley.core :as m]
    [metabase.db.query :as mdb.query]
@@ -93,12 +94,17 @@
 (defn populate-query-fields
   "Lift `database_id`, `table_id`, and `query_type` from query definition when inserting/updating a Card."
   [{{query-type :type, :as outer-query} :dataset_query, :as card}]
-  (merge (when-let [{:keys [database-id table-id]} (and query-type
-                                                        (query/query->database-and-table-ids outer-query))]
-           {:database_id database-id
-            :table_id    table-id
-            :query_type  (keyword query-type)})
-         card))
+  (cond->> card
+    ;; mega HACK FIXME -- don't update this stuff when doing deserialization because it might differ from what's in the
+    ;; YAML file and break tests like [[metabase-enterprise.serialization.v2.e2e.yaml-test/e2e-storage-ingestion-test]].
+    ;; The root cause of this issue is that we're generating Cards that have a different Database ID or Table ID from
+    ;; what's actually in their query -- we need to fix [[metabase.test.generate]], but I'm not sure how to do that
+    (not mi/*deserializing?*)
+    (merge (when-let [{:keys [database-id table-id]} (and query-type
+                                                          (query/query->database-and-table-ids outer-query))]
+             {:database_id database-id
+              :table_id    table-id
+              :query_type  (keyword query-type)}))))
 
 (defn- populate-result-metadata
   "When inserting/updating a Card, populate the result metadata column if not already populated by inferring the
@@ -330,6 +336,7 @@
   [:name (serdes.hash/hydrated-hash :collection "<none>") :created_at])
 
 ;;; ------------------------------------------------- Serialization --------------------------------------------------
+
 (defmethod serdes.base/extract-query "Card" [_ opts]
   (serdes.base/extract-query-collections Card opts))
 
@@ -410,7 +417,7 @@
         snippets      (some->> card :dataset_query :native :template-tags vals (keep :snippet-id))]
     (set/union
       (when (and (string? source-table)
-                 (.startsWith ^String source-table "card__"))
+                 (str/starts-with? source-table "card__"))
         #{["Card" (Integer/parseInt (.substring ^String source-table 6))]})
       (when (seq template-tags)
         (set (for [card-id template-tags]
diff --git a/src/metabase/models/collection.clj b/src/metabase/models/collection.clj
index c5058714190..29458254254 100644
--- a/src/metabase/models/collection.clj
+++ b/src/metabase/models/collection.clj
@@ -611,7 +611,7 @@
       (db/update! Collection (u/the-id collection) :location new-location)
       ;; we need to update all the descendant collections as well...
       (db/execute!
-       {:update Collection
+       {:update :collection
         :set    {:location (hsql/call :replace :location orig-children-location new-children-location)}
         :where  [:like :location (str orig-children-location "%")]}))))
 
@@ -798,7 +798,7 @@
 
   This needs to be done recursively for all descendants as well."
   [collection :- (mi/InstanceOf Collection)]
-  (db/execute! {:delete-from Permissions
+  (db/execute! {:delete-from :permissions
                 :where       [:in :object (for [collection (cons collection (descendants collection))
                                                 path-fn    [perms/collection-read-path
                                                             perms/collection-readwrite-path]]
@@ -887,7 +887,7 @@
     (when (:personal_owner_id collection)
       (throw (Exception. (tru "You cannot delete a Personal Collection!")))))
   ;; Delete permissions records for this Collection
-  (db/execute! {:delete-from Permissions
+  (db/execute! {:delete-from :permissions
                 :where       [:or
                               [:= :object (perms/collection-readwrite-path collection)]
                               [:= :object (perms/collection-read-path collection)]]}))
@@ -917,9 +917,9 @@
   (let [parent-id (-> coll
                       (hydrate :parent_id)
                       :parent_id)]
-   (if parent-id
-     (serdes.hash/identity-hash (db/select-one Collection :id parent-id))
-     "ROOT")))
+    (if parent-id
+      (serdes.hash/identity-hash (db/select-one Collection :id parent-id))
+      "ROOT")))
 
 (defmethod serdes.hash/identity-hash-fields Collection
   [_collection]
@@ -936,7 +936,7 @@
   :pre-update     pre-update
   :pre-delete     pre-delete})
 
-(defmethod serdes.base/extract-query "Collection" [_ {:keys [collection-set]}]
+(defmethod serdes.base/extract-query "Collection" [_model {:keys [collection-set]}]
   (if (seq collection-set)
     (db/select-reducible Collection :id [:in collection-set])
     (db/select-reducible Collection :personal_owner_id nil)))
@@ -1149,6 +1149,7 @@
     ;; efficiently create a map of user ID -> personal collection ID
     (let [user-id->collection-id (db/select-field->id :personal_owner_id Collection
                                    :personal_owner_id [:in (set (map u/the-id users))])]
+      (assert (map? user-id->collection-id))
       ;; now for each User, try to find the corresponding ID out of that map. If it's not present (the personal
       ;; Collection hasn't been created yet), then instead call `user->personal-collection-id`, which will create it
       ;; as a side-effect. This will ensure this property never comes back as `nil`
diff --git a/src/metabase/models/database.clj b/src/metabase/models/database.clj
index ecf28178c67..5c56a6ae79c 100644
--- a/src/metabase/models/database.clj
+++ b/src/metabase/models/database.clj
@@ -92,7 +92,7 @@
 
 (defn- pre-delete [{id :id, driver :engine, :as database}]
   (unschedule-tasks! database)
-  (db/execute! {:delete-from (db/resolve-model 'Permissions)
+  (db/execute! {:delete-from :permissions
                 :where       [:like :object (str "%" (perms/data-perms-path id) "%")]})
   (delete-orphaned-secrets! database)
   (try
diff --git a/src/metabase/models/login_history.clj b/src/metabase/models/login_history.clj
index fcb1df7376b..866e9654e10 100644
--- a/src/metabase/models/login_history.clj
+++ b/src/metabase/models/login_history.clj
@@ -3,6 +3,7 @@
    [clojure.tools.logging :as log]
    [java-time :as t]
    [metabase.email.messages :as messages]
+   [metabase.models.interface :as mi]
    [metabase.models.setting :refer [defsetting]]
    [metabase.server.request.util :as request.u]
    [metabase.util.date-2 :as u.date]
@@ -86,10 +87,8 @@
 (defn- pre-update [_login-history]
   (throw (RuntimeException. (tru "You can''t update a LoginHistory after it has been created."))))
 
-(extend #_{:clj-kondo/ignore [:metabase/disallow-class-or-type-on-model]} (class LoginHistory)
-  models/IModel
-  (merge
-   models/IModelDefaults
-   {:post-select post-select
-    :post-insert post-insert
-    :pre-update  pre-update}))
+(mi/define-methods
+ LoginHistory
+ {:post-select post-select
+  :post-insert post-insert
+  :pre-update  pre-update})
diff --git a/src/metabase/models/permissions.clj b/src/metabase/models/permissions.clj
index 30d9ab3e26b..66930915f77 100644
--- a/src/metabase/models/permissions.clj
+++ b/src/metabase/models/permissions.clj
@@ -573,7 +573,7 @@
   (set-has-full-permissions? permissions-set (application-perms-path perm-type)))
 
 (s/defn perms-objects-set-for-parent-collection :- #{Path}
-  "Implementation of `IModel` `perms-objects-set` for models with a `collection_id`, such as Card, Dashboard, or Pulse.
+  "Implementation of `perms-objects-set` for models with a `collection_id`, such as Card, Dashboard, or Pulse.
   This simply returns the `perms-objects-set` of the parent Collection (based on `collection_id`) or for the Root
   Collection if `collection_id` is `nil`."
   ([this read-or-write]
diff --git a/src/metabase/models/pulse.clj b/src/metabase/models/pulse.clj
index 10a00ba0352..9ccede966c1 100644
--- a/src/metabase/models/pulse.clj
+++ b/src/metabase/models/pulse.clj
@@ -229,7 +229,7 @@
   "Hydrate Pulse or Alert with the Fields needed for sending it."
   [notification :- (mi/InstanceOf Pulse)]
   (-> notification
-      (hydrate :creator :cards :dashboard [:channels :recipients])
+      (hydrate :creator :cards [:channels :recipients])
       (m/dissoc-in [:details :emails])))
 
 (s/defn ^:private hydrate-notifications :- [(mi/InstanceOf Pulse)]
@@ -259,6 +259,7 @@
   "Fetch an Alert or Pulse, and do the 'standard' hydrations, adding `:channels` with `:recipients`, `:creator`, and
   `:cards`."
   [notification-or-id & additional-conditions]
+  {:pre [(even? (count additional-conditions))]}
   (some-> (apply db/select-one Pulse :id (u/the-id notification-or-id), additional-conditions)
           hydrate-notification))
 
diff --git a/src/metabase/models/query.clj b/src/metabase/models/query.clj
index 1ded80fff59..c70709d104b 100644
--- a/src/metabase/models/query.clj
+++ b/src/metabase/models/query.clj
@@ -36,7 +36,7 @@
     :integer))
 
 (defn- update-rolling-average-execution-time!
-  "Update the rolling average execution time for query with QUERY-HASH. Returns `true` if a record was updated,
+  "Update the rolling average execution time for query with `query-hash`. Returns `true` if a record was updated,
    or `false` if no matching records were found."
   ^Boolean [query, ^bytes query-hash, ^Integer execution-time-ms]
   (let [avg-execution-time (hx/cast (int-casting-type) (hx/round (hx/+ (hx/* 0.9 :average_execution_time)
@@ -57,7 +57,7 @@
 (defn- record-new-query-entry!
   "Record a query and its execution time for a `query` with `query-hash` that's not already present in the DB.
   `execution-time-ms` is used as a starting point."
-  [query, ^bytes query-hash, ^Integer execution-time-ms]
+  [query ^bytes query-hash ^Integer execution-time-ms]
   (db/insert! Query
     :query                  query
     :query_hash             query-hash
diff --git a/src/metabase/models/revision.clj b/src/metabase/models/revision.clj
index 507a0d25d2c..426d4a66261 100644
--- a/src/metabase/models/revision.clj
+++ b/src/metabase/models/revision.clj
@@ -51,7 +51,7 @@
 (defmethod diff-str :default
   [model o1 o2]
   (when-let [[before after] (data/diff o1 o2)]
-    (diff-string (:name model) before after)))
+    (diff-string (name model) before after)))
 
 ;;; # Revision Entity
 
@@ -97,7 +97,7 @@
   "Get the revisions for `model` with `id` in reverse chronological order."
   [model id]
   {:pre [(models/model? model) (integer? id)]}
-  (db/select Revision, :model (:name model), :model_id id, {:order-by [[:id :desc]]}))
+  (db/select Revision, :model (name model), :model_id id, {:order-by [[:id :desc]]}))
 
 (defn revisions+details
   "Fetch `revisions` for `model` with `id` and add details."
@@ -114,7 +114,7 @@
   [model id]
   {:pre [(models/model? model) (integer? id)]}
   (when-let [old-revisions (seq (drop max-revisions (map :id (db/select [Revision :id]
-                                                               :model    (:name model)
+                                                               :model    (name model)
                                                                :model_id id
                                                                {:order-by [[:timestamp :desc]]}))))]
     (db/delete! Revision :id [:in old-revisions])))
@@ -136,7 +136,7 @@
     ;; make sure we still have a map after calling out serialization function
     (assert (map? object))
     (db/insert! Revision
-      :model        (:name entity)
+      :model        (name entity)
       :model_id     id
       :user_id      user-id
       :object       object
@@ -155,14 +155,14 @@
          (integer? user-id)
          (db/exists? User :id user-id)
          (integer? revision-id)]}
-  (let [serialized-instance (db/select-one-field :object Revision, :model (:name entity), :model_id id, :id revision-id)]
+  (let [serialized-instance (db/select-one-field :object Revision, :model (name entity), :model_id id, :id revision-id)]
     (db/transaction
       ;; Do the reversion of the object
       (revert-to-revision! entity id user-id serialized-instance)
       ;; Push a new revision to record this change
-      (let [last-revision (db/select-one Revision :model (:name entity), :model_id id, {:order-by [[:id :desc]]})
+      (let [last-revision (db/select-one Revision :model (name entity), :model_id id, {:order-by [[:id :desc]]})
             new-revision  (db/insert! Revision
-                            :model        (:name entity)
+                            :model        (name entity)
                             :model_id     id
                             :user_id      user-id
                             :object       serialized-instance
diff --git a/src/metabase/models/serialization/base.clj b/src/metabase/models/serialization/base.clj
index 3d3d62e95a0..61a7032c960 100644
--- a/src/metabase/models/serialization/base.clj
+++ b/src/metabase/models/serialization/base.clj
@@ -45,7 +45,8 @@
   By default this is a column, `:entity_id`.
 
   Models that have a different portable ID should override this."
-  (fn [model-name _] model-name))
+  {:arglists '([model-name instance])}
+  (fn [model-name _instance] model-name))
 
 (defmethod serdes-entity-id :default [_ {:keys [entity_id]}]
   entity_id)
@@ -81,7 +82,8 @@
   - The primary key might still be attached, during extraction.
   - `:label` is optional
   - The logic to guess the leaf part of the path is in [[infer-self-path]], for use in overriding."
-  (fn [model _] model))
+  {:arglists '([model-name instance])}
+  (fn [model-name _instance] model-name))
 
 (defn infer-self-path
   "Implements the default logic from [[serdes-generate-path]] that guesses the `:id` of this entity. Factored out
@@ -185,7 +187,8 @@
 
   You probably don't want to implement this directly. The default implementation delegates to [[extract-query]] and
   [[extract-one]], which are usually more convenient to override."
-  (fn [model _] model))
+  {:arglists '([model-name opts])}
+  (fn [model-name _opts] model-name))
 
 (defmulti extract-query
   "Performs the select query, possibly filtered, for all the entities of this model that should be serialized. Called
@@ -200,7 +203,8 @@
   Defaults to using `(toucan.db/select model)` for the entire table.
 
   You may want to override this to eg. skip archived entities, or otherwise filter what gets serialized."
-  (fn [model _] model))
+  {:arglists '([model-name opts])}
+  (fn [model-name _opts] model-name))
 
 (defmulti extract-one
   "Extracts a single entity retrieved from the database into a portable map with `:serdes/meta` attached.
@@ -219,7 +223,8 @@
   When overriding this, [[extract-one-basics]] is probably a useful starting point.
 
   Keyed by the model name of the entity, the first argument."
-  (fn [model _opts _entity] model))
+  {:arglists '([model-name opts instance])}
+  (fn [model-name _opts _instance] model-name))
 
 (defmethod extract-all :default [model opts]
   (eduction (map (partial extract-one model opts))
@@ -327,6 +332,7 @@
   the incoming key. For the identity hash, this scans the entire table and builds a cache of
   [[serdes.hash/identity-hash]] to primary keys, since the identity hash cannot be queried directly.
   This cache is cleared at the beginning and end of the deserialization process."
+  {:arglists '([path])}
   (fn [path]
     (-> path last :model)))
 
diff --git a/src/metabase/models/setting/cache.clj b/src/metabase/models/setting/cache.clj
index 08404364d0c..9ae67bafdbb 100644
--- a/src/metabase/models/setting/cache.clj
+++ b/src/metabase/models/setting/cache.clj
@@ -85,7 +85,7 @@
           (db/simple-insert! 'Setting :key settings-last-updated-key, :value current-timestamp-as-string-honeysql)
           (catch java.sql.SQLException e
             ;; go ahead and log the Exception anyway on the off chance that it *wasn't* just a race condition issue
-            (log/error (trs "Error inserting a new Setting: {0}"
+            (log/error (trs "Error updating Settings last updated value: {0}"
                             (with-out-str (jdbc/print-sql-exception-chain e))))))))
   ;; Now that we updated the value in the DB, go ahead and update our cached value as well, because we know about the
   ;; changes
diff --git a/src/metabase/models/user.clj b/src/metabase/models/user.clj
index 74f32c5289b..2e5c50a21f1 100644
--- a/src/metabase/models/user.clj
+++ b/src/metabase/models/user.clj
@@ -17,7 +17,7 @@
    [metabase.public-settings :as public-settings]
    [metabase.public-settings.premium-features :as premium-features]
    [metabase.util :as u]
-   [metabase.util.i18n :as i18n :refer [deferred-tru trs]]
+   [metabase.util.i18n :as i18n :refer [deferred-tru trs tru]]
    [metabase.util.password :as u.password]
    [metabase.util.schema :as su]
    [schema.core :as schema]
@@ -52,7 +52,7 @@
   (assert (u/email? email))
   (assert ((every-pred string? (complement str/blank?)) password))
   (when locale
-    (assert (i18n/available-locale? locale)))
+    (assert (i18n/available-locale? locale) (tru "Invalid locale: {0}" (pr-str locale))))
   (merge
    insert-default-values
    user
@@ -108,7 +108,7 @@
   (when email
     (assert (u/email? email)))
   (when locale
-    (assert (i18n/available-locale? locale)))
+    (assert (i18n/available-locale? locale) (tru "Invalid locale: {0}" (pr-str locale))))
   ;; delete all subscriptions to pulses/alerts/etc. if the User is getting archived (`:is_active` status changes)
   (when (false? active?)
     (db/delete! 'PulseChannelRecipient :user_id id))
diff --git a/src/metabase/query_processor/middleware/add_dimension_projections.clj b/src/metabase/query_processor/middleware/add_dimension_projections.clj
index 07c652e5819..e3fde856846 100644
--- a/src/metabase/query_processor/middleware/add_dimension_projections.clj
+++ b/src/metabase/query_processor/middleware/add_dimension_projections.clj
@@ -31,7 +31,6 @@
    [metabase.mbql.schema :as mbql.s]
    [metabase.mbql.util :as mbql.u]
    [metabase.models.dimension :refer [Dimension]]
-   [metabase.models.field :refer [Field]]
    [metabase.query-processor.store :as qp.store]
    [metabase.util :as u]
    [metabase.util.schema :as su]
@@ -85,7 +84,11 @@
     ;;
     ;; Not sure this isn't broken. Probably better to have [[metabase.query-processor.util.add-alias-info]] do the name
     ;; deduplication instead.
-    (let [unique-name (comp (mbql.u/unique-name-generator) :name Field)]
+    (let [name-generator (mbql.u/unique-name-generator)
+          unique-name    (fn [field-id]
+                           (qp.store/fetch-and-store-fields! #{field-id})
+                           (let [field (qp.store/field field-id)]
+                             (name-generator (:name field))))]
       (vec
        (mbql.u/match fields
          ;; don't match Fields that have been joined from another Table
diff --git a/src/metabase/related.clj b/src/metabase/related.clj
index 73f83b290dd..65899de9f14 100644
--- a/src/metabase/related.clj
+++ b/src/metabase/related.clj
@@ -120,7 +120,9 @@
          :table_id           (:id table)
          :fk_target_field_id [:not= nil]
          :active             true)
-       (map (comp Table :table_id Field))
+       (map (comp (partial db/select-one Table :id)
+                  :table_id
+                  (partial db/select-one Field :id)))
        distinct
        filter-visible
        (take max-matches)))
@@ -183,16 +185,17 @@
   [cards]
   (let [recent           (recently-modified-dashboards)
         card->dashboards (->> (apply db/select [DashboardCard :card_id :dashboard_id]
-                                     (cond-> {}
-                                       (not-empty cards)
-                                       (assoc :card_id [:in (map :id cards)])
+                                     (cond-> []
+                                       (seq cards)
+                                       (concat [:card_id [:in (map :id cards)]])
 
-                                       (not-empty recent)
-                                       (assoc :dashboard_id [:not-in recent])))
+                                       (seq recent)
+                                       (concat [:dashboard_id [:not-in recent]])))
                               (group-by :card_id))
         best             (->> cards
                               (mapcat (comp card->dashboards :id))
                               distinct
+                              ;; TODO -- extremely naughty to be doing a separate select for every single Dashboard ID
                               (map (partial db/select-one Dashboard :id))
                               filter-visible
                               (take max-best-matches))]
@@ -203,7 +206,7 @@
   (->> cards
        (m/distinct-by :collection_id)
        interesting-mix
-       (keep (comp Collection :collection_id))
+       (keep (comp (partial db/select-one Collection :id) :collection_id))
        filter-visible))
 
 (defmulti related
diff --git a/src/metabase/server/middleware/session.clj b/src/metabase/server/middleware/session.clj
index 8784a6c9f69..a2a59bc2fa2 100644
--- a/src/metabase/server/middleware/session.clj
+++ b/src/metabase/server/middleware/session.clj
@@ -19,7 +19,6 @@
    [metabase.driver.sql.query-processor :as sql.qp]
    [metabase.models.permissions-group-membership
     :refer [PermissionsGroupMembership]]
-   [metabase.models.session :refer [Session]]
    [metabase.models.setting
     :as setting
     :refer [*user-local-values* defsetting]]
@@ -232,21 +231,20 @@
    (fn [db-type max-age-minutes session-type enable-advanced-permissions?]
      (first
       (db/honeysql->sql
-       (cond->
-         {:select    [[:session.user_id :metabase-user-id]
-                      [:user.is_superuser :is-superuser?]
-                      [:user.locale :user-locale]]
-          :from      [[Session :session]]
-          :left-join [[User :user] [:= :session.user_id :user.id]]
-          :where     [:and
-                      [:= :user.is_active true]
-                      [:= :session.id (hsql/raw "?")]
-                      (let [oldest-allowed (sql.qp/add-interval-honeysql-form db-type :%now (- max-age-minutes) :minute)]
-                        [:> :session.created_at oldest-allowed])
-                      [:= :session.anti_csrf_token (case session-type
-                                                     :normal         nil
-                                                     :full-app-embed "?")]]
-          :limit     1}
+       (cond-> {:select    [[:session.user_id :metabase-user-id]
+                            [:user.is_superuser :is-superuser?]
+                            [:user.locale :user-locale]]
+                :from      [[:core_session :session]]
+                :left-join [[:core_user :user] [:= :session.user_id :user.id]]
+                :where     [:and
+                            [:= :user.is_active true]
+                            [:= :session.id (hsql/raw "?")]
+                            (let [oldest-allowed (sql.qp/add-interval-honeysql-form db-type :%now (- max-age-minutes) :minute)]
+                              [:> :session.created_at oldest-allowed])
+                            [:= :session.anti_csrf_token (case session-type
+                                                           :normal         nil
+                                                           :full-app-embed "?")]]
+                :limit     1}
 
          enable-advanced-permissions?
          (->
diff --git a/src/metabase/sync/analyze/classifiers/name.clj b/src/metabase/sync/analyze/classifiers/name.clj
index bd2d785e253..a4e87683c99 100644
--- a/src/metabase/sync/analyze/classifiers/name.clj
+++ b/src/metabase/sync/analyze/classifiers/name.clj
@@ -178,7 +178,7 @@
    [(prefix-or-postfix "vendor")       :entity/CompanyTable]])
 
 (s/defn infer-entity-type :- i/TableInstance
-  "Classifer that infers the semantic type of a TABLE based on its name."
+  "Classifer that infers the semantic type of a `table` based on its name."
   [table :- i/TableInstance]
   (let [table-name (-> table :name str/lower-case)]
     (assoc table :entity_type (or (some (fn [[pattern type]]
diff --git a/src/metabase/task.clj b/src/metabase/task.clj
index 19e5fd37f08..a2ad31cce31 100644
--- a/src/metabase/task.clj
+++ b/src/metabase/task.clj
@@ -12,17 +12,16 @@
 
   Find the JavaDoc for Quartz here: http://www.quartz-scheduler.org/api/2.3.0/index.html"
   (:require
-   [clojure.java.jdbc :as jdbc]
    [clojure.string :as str]
    [clojure.tools.logging :as log]
    [clojurewerkz.quartzite.scheduler :as qs]
    [environ.core :as env]
    [metabase.db :as mdb]
+   [metabase.db.connection :as mdb.connection]
    [metabase.plugins.classloader :as classloader]
    [metabase.util :as u]
    [metabase.util.i18n :refer [trs]]
-   [schema.core :as s]
-   [toucan.db :as db])
+   [schema.core :as s])
   (:import
    (org.quartz CronTrigger JobDetail JobKey Scheduler Trigger TriggerKey)))
 
@@ -102,7 +101,7 @@
     ;; in a perfect world we could just check whether we're creating a new Connection or not, and if using an existing
     ;; Connection, wrap it in a delegating proxy wrapper that makes `.close()` a no-op but forwards all other methods.
     ;; Now that would be a useful macro!
-    (some-> @@#'db/default-db-connection jdbc/get-connection))
+    (.getConnection mdb.connection/*application-db*))
   (shutdown [_]))
 
 (when-not *compile-files*
diff --git a/src/metabase/transforms/dashboard.clj b/src/metabase/transforms/dashboard.clj
index ed92212c815..70fdab3bd76 100644
--- a/src/metabase/transforms/dashboard.clj
+++ b/src/metabase/transforms/dashboard.clj
@@ -35,6 +35,7 @@
 
 (defn- card-for-source-table
   [table]
+  {:pre [(map? table)]}
   {:creator_id             api/*current-user-id*
    :dataset_query          {:type     :query
                             :query    {:source-table (u/the-id table)}
diff --git a/src/metabase/troubleshooting.clj b/src/metabase/troubleshooting.clj
index bfb25326b1c..9a2a67fed3d 100644
--- a/src/metabase/troubleshooting.clj
+++ b/src/metabase/troubleshooting.clj
@@ -10,6 +10,8 @@
   (:import
    (javax.management ObjectName)))
 
+(set! *warn-on-reflection* true)
+
 (defn system-info
   "System info we ask for for bug reports"
   []
diff --git a/test/metabase/api/action_test.clj b/test/metabase/api/action_test.clj
index 4e167c84770..3f82d4abc83 100644
--- a/test/metabase/api/action_test.clj
+++ b/test/metabase/api/action_test.clj
@@ -6,6 +6,7 @@
    [metabase.models :refer [Card]]
    [metabase.models.action :refer [Action]]
    [metabase.test :as mt]
+   [metabase.util :as u]
    [metabase.util.schema :as su]
    [schema.core :as s]))
 
@@ -175,7 +176,7 @@
                               :response_handle ".body"
                               :error_handle ".status >= 400"}
               created-action (mt/user-http-request :crowberto :post 200 "action" initial-action)
-              action-path (str "action/" (:id created-action))]
+              action-path (str "action/" (u/the-id created-action))]
           (testing "Validate POST"
             (testing "Required fields"
               (is (partial= {:errors {:name "string"},
diff --git a/test/metabase/api/dashboard_test.clj b/test/metabase/api/dashboard_test.clj
index e96d763da97..0e855a0cc1d 100644
--- a/test/metabase/api/dashboard_test.clj
+++ b/test/metabase/api/dashboard_test.clj
@@ -198,9 +198,9 @@
               (mt/user-http-request :rasta :post 200 "dashboard" {:name                dashboard-name
                                                                   :collection_id       (u/the-id collection)
                                                                   :collection_position 1000})
-              (is (= #metabase.models.dashboard.DashboardInstance{:collection_id true, :collection_position 1000}
-                     (some-> (db/select-one [Dashboard :collection_id :collection_position] :name dashboard-name)
-                             (update :collection_id (partial = (u/the-id collection))))))
+              (is (=? {:collection_id true, :collection_position 1000}
+                      (some-> (db/select-one [Dashboard :collection_id :collection_position] :name dashboard-name)
+                              (update :collection_id (partial = (u/the-id collection))))))
               (finally
                 (db/delete! Dashboard :name dashboard-name)))))
 
diff --git a/test/metabase/api/database_test.clj b/test/metabase/api/database_test.clj
index 5047d9a64b2..b5952732799 100644
--- a/test/metabase/api/database_test.clj
+++ b/test/metabase/api/database_test.clj
@@ -772,16 +772,18 @@
     (testing "Can we UPDATE the schedules for an existing database?"
       (testing "We cannot if we don't mark `:let-user-control-scheduling`"
         (mt/with-temp Database [db {:engine "h2", :details (:details (mt/db))}]
-          (mt/user-http-request :crowberto :put 200 (format "database/%d" (u/the-id db))
-                                (assoc db :schedules attempted))
+          (is (=? (select-keys (mt/db) [:cache_field_values_schedule :metadata_sync_schedule])
+                  (mt/user-http-request :crowberto :put 200 (format "database/%d" (u/the-id db))
+                                        (assoc db :schedules attempted))))
           (is (not= expected
                     (into {} (db/select-one [Database :cache_field_values_schedule :metadata_sync_schedule] :id (u/the-id db)))))))
       (testing "We can if we mark `:let-user-control-scheduling`"
         (mt/with-temp Database [db {:engine "h2", :details (:details (mt/db))}]
-          (mt/user-http-request :crowberto :put 200 (format "database/%d" (u/the-id db))
-                                (-> db
-                                    (assoc :schedules attempted)
-                                    (assoc-in [:details :let-user-control-scheduling] true)))
+          (is (=? expected
+                  (mt/user-http-request :crowberto :put 200 (format "database/%d" (u/the-id db))
+                                        (-> (into {} db)
+                                            (assoc :schedules attempted)
+                                            (assoc-in [:details :let-user-control-scheduling] true)))))
           (is (= expected
                  (into {} (db/select-one [Database :cache_field_values_schedule :metadata_sync_schedule] :id (u/the-id db)))))))
       (testing "if we update back to metabase managed schedules it randomizes for us"
@@ -789,8 +791,9 @@
           (mt/with-temp Database [db (merge {:engine "h2" :details (assoc (:details (mt/db))
                                                                           :let-user-control-scheduling true)}
                                             original-custom-schedules)]
-            (mt/user-http-request :crowberto :put 200 (format "database/%d" (u/the-id db))
-                                  (assoc-in db [:details :let-user-control-scheduling] false))
+            (is (=? {:id (u/the-id db)}
+                    (mt/user-http-request :crowberto :put 200 (format "database/%d" (u/the-id db))
+                                          (assoc-in db [:details :let-user-control-scheduling] false))))
             (let [schedules (into {} (db/select-one [Database :cache_field_values_schedule :metadata_sync_schedule] :id (u/the-id db)))]
               (is (not= original-custom-schedules schedules))
               (is (= "hourly" (-> schedules :metadata_sync_schedule u.cron/cron-string->schedule-map :schedule_type)))
@@ -874,7 +877,8 @@
                     Field       [field-2  {:table_id (u/the-id table-2)}]
                     FieldValues [values-1 {:field_id (u/the-id field-1), :values [1 2 3 4]}]
                     FieldValues [values-2 {:field_id (u/the-id field-2), :values [1 2 3 4]}]]
-      (mt/user-http-request :crowberto :post 200 (format "database/%d/discard_values" (u/the-id db)))
+      (is (= {:status "ok"}
+             (mt/user-http-request :crowberto :post 200 (format "database/%d/discard_values" (u/the-id db)))))
       (testing "values-1 still exists?"
         (is (= false
                (db/exists? FieldValues :id (u/the-id values-1)))))
@@ -1163,7 +1167,8 @@
                                                  :dataset false)]]
         ;; run the cards to populate their result_metadata columns
         (doseq [card [card-1 card-2]]
-          (mt/user-http-request :crowberto :post 202 (format "card/%d/query" (u/the-id card))))
+          (is (=? {:status "completed"}
+                  (mt/user-http-request :crowberto :post 202 (format "card/%d/query" (u/the-id card))))))
         (testing "Should be able to get datasets in a specific collection"
           (is (= [{:id               (format "card__%d" (:id card-1))
                    :db_id            (mt/id)
diff --git a/test/metabase/api/embed_test.clj b/test/metabase/api/embed_test.clj
index cc996646346..1cdf1078008 100644
--- a/test/metabase/api/embed_test.clj
+++ b/test/metabase/api/embed_test.clj
@@ -131,8 +131,9 @@
        (is (= [{:col "Count"} {:col 100.0}]
               actual))))))
 
-(defn dissoc-id-and-name {:style/indent 0} [obj]
-  (dissoc obj :id :name))
+(defn dissoc-id-and-name [obj]
+  (cond-> obj
+    (map? obj) (dissoc :id :name)))
 
 (def successful-card-info
   "Data that should be returned if `GET /api/embed/card/:token` completes successfully (minus `:id` and `:name`).
@@ -199,8 +200,13 @@
                                                                            :c {:type "date", :name "c", :display_name "c"}
                                                                            :d {:type "date", :name "d", :display_name "d"}}}}
                              :embedding_params {:a "locked", :b "disabled", :c "enabled", :d "enabled"}}]
-        (is (= [{:id nil, :type "date/single", :target ["variable" ["template-tag" "d"]], :name "d", :slug "d", :default nil}]
-               (:parameters (client/client :get 200 (card-url card {:params {:c 100}})))))))))
+        (is (=? {:parameters [{:id      nil
+                               :type    "date/single"
+                               :target  ["variable" ["template-tag" "d"]]
+                               :name    "d"
+                               :slug    "d"
+                               :default nil}]}
+                (client/client :get 200 (card-url card {:params {:c 100}}))))))))
 
 
 ;;; ------------------------- GET /api/embed/card/:token/query (and JSON/CSV/XLSX variants) --------------------------
@@ -387,7 +393,7 @@
     (mt/with-temp Dashboard [dash {:enable_embedding true}]
       (is (= successful-dashboard-info
              (dissoc-id-and-name
-               (client/client :get 200 (dashboard-url dash))))))))
+              (client/client :get 200 (dashboard-url dash))))))))
 
 (deftest we-should-fail-when-attempting-to-use-an-expired-token-2
   (with-embedding-enabled-and-new-secret-key
diff --git a/test/metabase/api/permissions_test.clj b/test/metabase/api/permissions_test.clj
index e050d58ea84..2bb4337e0a9 100644
--- a/test/metabase/api/permissions_test.clj
+++ b/test/metabase/api/permissions_test.clj
@@ -259,7 +259,6 @@
                      result))
         (is (= (db/select-field :id 'User) (set (keys result))))))))
 
-
 (deftest add-group-membership-test
   (testing "POST /api/permissions/membership"
     (mt/with-temp* [User             [user]
diff --git a/test/metabase/api/pulse_test.clj b/test/metabase/api/pulse_test.clj
index 6d864e6148a..57fed1c8d3a 100644
--- a/test/metabase/api/pulse_test.clj
+++ b/test/metabase/api/pulse_test.clj
@@ -76,8 +76,8 @@
       (grant-collection-perms-fn! (perms-group/all-users) collection)
       ;; use db/execute! instead of db/update! so the updated_at field doesn't get automatically updated!
       (when (seq pulses-or-ids)
-        (db/execute! {:update Pulse
-                      :set    [[:collection_id (u/the-id collection)]]
+        (db/execute! {:update :pulse
+                      :set    {:collection_id (u/the-id collection)}
                       :where  [:in :id (set (map u/the-id pulses-or-ids))]}))
       (f))))
 
diff --git a/test/metabase/api/revision_test.clj b/test/metabase/api/revision_test.clj
index c535f45eb09..1a086d6e81a 100644
--- a/test/metabase/api/revision_test.clj
+++ b/test/metabase/api/revision_test.clj
@@ -5,9 +5,7 @@
    [metabase.models.collection :refer [Collection]]
    [metabase.models.dashboard :refer [Dashboard]]
    [metabase.models.dashboard-card :refer [DashboardCard]]
-   [metabase.models.revision
-    :as revision
-    :refer [push-revision! Revision revisions]]
+   [metabase.models.revision :as revision :refer [Revision]]
    [metabase.test :as mt]
    [metabase.test.data.users :as test.users]
    [metabase.test.fixtures :as fixtures]
@@ -26,20 +24,23 @@
     (dissoc revision :timestamp :id)))
 
 (defn- create-card-revision [card is-creation? user]
-  (push-revision!
+  (revision/push-revision!
     :object       card
     :entity       Card
     :id           (:id card)
     :user-id      (test.users/user->id user)
     :is-creation? is-creation?))
 
-(defn- create-dashboard-revision! [dash is-creation? user]
-  (push-revision!
-    :object       (db/select-one Dashboard :id (:id dash))
-    :entity       Dashboard
-    :id           (:id dash)
-    :user-id      (test.users/user->id user)
-    :is-creation? is-creation?))
+;;; TODO -- seems weird that this fetches the Dashboard while the Card version above does not ?
+(defn- create-dashboard-revision!
+  "Fetch the latest version of a Dashboard and save a revision entry for it. Returns the fetched Dashboard."
+  [dash is-creation? user]
+  (revision/push-revision!
+   :object       (db/select-one Dashboard :id (:id dash))
+   :entity       Dashboard
+   :id           (:id dash)
+   :user-id      (test.users/user->id user)
+   :is-creation? is-creation?))
 
 ;;; # GET /revision
 
@@ -96,7 +97,7 @@
                (create-card-revision card true :rasta)
                (create-card-revision (assoc card :name "something else") false :rasta)
                (db/insert! Revision
-                 :model        (:name Card)
+                 :model        "Card"
                  :model_id     id
                  :user_id      (test.users/user->id :rasta)
                  :object       (revision/serialize-instance Card (:id card) card)
@@ -115,6 +116,21 @@
   (testing "Reverting through API works"
     (tt/with-temp* [Dashboard [{:keys [id] :as dash}]
                     Card      [{card-id :id, :as card}]]
+      (is (=? {:id id}
+              (create-dashboard-revision! dash true :rasta)))
+      (let [dashcard (db/insert! DashboardCard :dashboard_id id :card_id (:id card))]
+        (is (=? {:id id}
+                (create-dashboard-revision! dash false :rasta)))
+        (is (true? (db/simple-delete! DashboardCard, :id (:id dashcard)))))
+      (is (=? {:id id}
+              (create-dashboard-revision! dash false :rasta)))
+      (testing "Revert to the previous revision, allowed because rasta has permissions on parent collection"
+        (let [[_ {previous-revision-id :id}] (revision/revisions Dashboard id)]
+          (is (=? {:id          int?
+                   :description "added a card."}
+                  (mt/user-http-request :rasta :post 200 "revision/revert" {:entity      :dashboard
+                                                                            :id          id
+                                                                            :revision_id previous-revision-id})))))
       (is (= [{:is_reversion true
                :is_creation  false
                :message      nil
@@ -128,38 +144,27 @@
                :user         @rasta-revision-info
                :diff         {:before {:cards [{:size_x 4, :size_y 4, :row 0, :col 0, :card_id card-id, :series []}]}
                               :after  {:cards nil}}
-               :description "removed a card."}
+               :description  "removed a card."}
               {:is_reversion false
                :is_creation  false
                :message      nil
                :user         @rasta-revision-info
                :diff         {:before {:cards nil}
                               :after  {:cards [{:size_x 4, :size_y 4, :row 0, :col 0, :card_id card-id, :series []}]}}
-               :description "added a card."}
+               :description  "added a card."}
               {:is_reversion false
                :is_creation  true
                :message      nil
                :user         @rasta-revision-info
                :diff         nil
                :description  "rearranged the cards."}]
-             (do
-               (create-dashboard-revision! dash true :rasta)
-               (let [dashcard (db/insert! DashboardCard :dashboard_id id :card_id (:id card))]
-                 (create-dashboard-revision! dash false :rasta)
-                 (db/simple-delete! DashboardCard, :id (:id dashcard)))
-               (create-dashboard-revision! dash false :rasta)
-               (let [[_ {previous-revision-id :id}] (revisions Dashboard id)]
-                 ;; Revert to the previous revision, allowed because rasta has permissions on parent collection
-                 (mt/user-http-request :rasta :post "revision/revert" {:entity      :dashboard
-                                                                       :id          id
-                                                                       :revision_id previous-revision-id}))
-               (->> (get-revisions :dashboard id)
-                    (mapv (fn [rev]
-                            (if-not (:diff rev)
-                              rev
-                              (if (get-in rev [:diff :before :cards])
-                                (update-in rev [:diff :before :cards] strip-ids)
-                                (update-in rev [:diff :after :cards] strip-ids))))))))))))
+             (->> (get-revisions :dashboard id)
+                  (mapv (fn [rev]
+                          (if-not (:diff rev)
+                            rev
+                            (if (get-in rev [:diff :before :cards])
+                              (update-in rev [:diff :before :cards] strip-ids)
+                              (update-in rev [:diff :after :cards] strip-ids)))))))))))
 
 (deftest permission-check-on-revert-test
   (testing "Are permissions enforced by the revert action in the revision api?"
@@ -169,7 +174,7 @@
         (create-dashboard-revision! dashboard true :crowberto)
         (create-dashboard-revision! dashboard false :crowberto)
         (let [dashboard-id          (u/the-id dashboard)
-              [_ {prev-rev-id :id}] (revisions Dashboard dashboard-id)
+              [_ {prev-rev-id :id}] (revision/revisions Dashboard dashboard-id)
               update-req            {:entity :dashboard, :id dashboard-id, :revision_id prev-rev-id}]
           ;; rasta should not have permissions to update the dashboard (i.e. revert), because they are not admin and do
           ;; not have any particular permission on the collection where it lives (because of the
diff --git a/test/metabase/api/search_test.clj b/test/metabase/api/search_test.clj
index 6264f450e06..4bd070a7739 100644
--- a/test/metabase/api/search_test.clj
+++ b/test/metabase/api/search_test.clj
@@ -572,11 +572,11 @@
   (testing "Search should only return Collections in the 'default' namespace"
     (mt/with-temp* [Collection [_c1 {:name "Normal Collection"}]
                     Collection [_c2 {:name "Coin Collection", :namespace "currency"}]]
-      (is (= ["Normal Collection"]
-             (->> (search-request-data :crowberto :q "Collection")
-                  (filter #(and (= (:model %) "collection")
-                                (#{"Normal Collection" "Coin Collection"} (:name %))))
-                  (map :name)))))))
+      (assert (not (db/exists? Collection :name "Coin Collection", :namespace nil)))
+      (is (=? [{:name "Normal Collection"}]
+              (->> (search-request-data :crowberto :q "Collection")
+                   (filter #(and (= (:model %) "collection")
+                                 (#{"Normal Collection" "Coin Collection"} (:name %))))))))))
 
 (deftest no-dashboard-subscription-pulses-test
   (testing "Pulses used for Dashboard subscriptions should not be returned by search results (#14190)"
diff --git a/test/metabase/api/session_test.clj b/test/metabase/api/session_test.clj
index dd222888c0f..03eb3bddb2c 100644
--- a/test/metabase/api/session_test.clj
+++ b/test/metabase/api/session_test.clj
@@ -440,9 +440,9 @@
       (mt/with-temporary-setting-values [ldap-user-base "cn=wrong,cn=com"]
         (mt/with-temp User [_ {:email    "ngoc@metabase.com"
                                :password "securedpassword"}]
-            (is (schema= SessionResponse
-                         (mt/client :post 200 "session" {:username "ngoc@metabase.com"
-                                                         :password "securedpassword"}))))))
+          (is (schema= SessionResponse
+                       (mt/client :post 200 "session" {:username "ngoc@metabase.com"
+                                                       :password "securedpassword"}))))))
 
     (testing "Test that we can login with LDAP with new user"
       (try
@@ -469,8 +469,9 @@
           [ldap-group-mappings (json/generate-string {"cn=Accounting,ou=Groups,dc=metabase,dc=com" [(:id group)]})]
           (is (schema= SessionResponse
                        (mt/client :post 200 "session" {:username "fred.taylor@metabase.com", :password "pa$$word"})))
-          (let [user-id (db/select-one-id User :email "fred.taylor@metabase.com")]
-            (is (= true (db/exists? PermissionsGroupMembership :group_id (:id group) (:user_id user-id))))))))))
+          (testing "PermissionsGroupMembership should exist"
+            (let [user-id (db/select-one-id User :email "fred.taylor@metabase.com")]
+              (is (db/exists? PermissionsGroupMembership :group_id (u/the-id group) :user_id (u/the-id user-id))))))))))
 
 (deftest no-password-no-login-test
   (testing "A user with no password should not be able to do password-based login"
diff --git a/test/metabase/api/table_test.clj b/test/metabase/api/table_test.clj
index 04a49fd51bc..7de0314b2b9 100644
--- a/test/metabase/api/table_test.clj
+++ b/test/metabase/api/table_test.clj
@@ -327,31 +327,33 @@
                             (let [fut (original unhidden)]
                               (when (future? fut)
                                 (deref fut)))))]
-            (let [set-visibility (fn [state]
-                                   (mt/user-http-request :crowberto :put 200 (format "table/%d" (:id table))
-                                                         {:display_name    "Userz"
-                                                          :visibility_type state
-                                                          :description     "What a nice table!"}))
-                  set-name      (fn []
-                                  (mt/user-http-request :crowberto :put 200 (format "table/%d" (:id table))
-                                                         {:display_name (mt/random-name)
-                                                          :description  "What a nice table!"}))]
-
-              (set-visibility "hidden")
-              (set-visibility nil)        ; <- should get synced
+            (letfn [(set-visibility! [state]
+                      (testing (format "Set state => %s" (pr-str state))
+                        (mt/user-http-request :crowberto :put 200 (format "table/%d" (:id table))
+                                              {:display_name    "Userz"
+                                               :visibility_type state
+                                               :description     "What a nice table!"})))
+                    (set-name! []
+                      (testing "set display name"
+                        (mt/user-http-request :crowberto :put 200 (format "table/%d" (:id table))
+                                              {:display_name (mt/random-name)
+                                               :description  "What a nice table!"})))]
+
+              (set-visibility! "hidden")
+              (set-visibility! nil)     ; <- should get synced
               (is (= 1
                      @called))
-              (set-visibility "hidden")
-              (set-visibility "cruft")
-              (set-visibility "technical")
-              (set-visibility nil)        ; <- should get synced again
+              (set-visibility! "hidden")
+              (set-visibility! "cruft")
+              (set-visibility! "technical")
+              (set-visibility! nil)     ; <- should get synced again
               (is (= 2
                      @called))
-              (set-visibility "technical")
+              (set-visibility! "technical")
               (is (= 2
                      @called))
               (testing "Update table's properties shouldn't trigger sync"
-                (set-name)
+                (set-name!)
                 (is (= 2
                        @called)))))))))
 
@@ -360,17 +362,18 @@
       (mt/with-temp* [Table [{id-1 :id} {}]
                       Table [{id-2 :id} {:visibility_type "hidden"}]]
         (with-redefs [api.table/sync-unhidden-tables (fn [unhidden] (reset! unhidden-ids (set (map :id unhidden))))]
-          (let [set-many-vis (fn [ids state]
-                               (reset! unhidden-ids #{})
-                               (mt/user-http-request :crowberto :put 200 "table/"
-                                                     {:ids ids :visibility_type state}))]
-            (set-many-vis [id-1 id-2] nil) ;; unhides only 2
+          (letfn [(set-many-vis! [ids state]
+                    (reset! unhidden-ids #{})
+                    (testing (format "Set visibility type => %s" (pr-str state))
+                      (mt/user-http-request :crowberto :put 200 "table/"
+                                            {:ids ids :visibility_type state})))]
+            (set-many-vis! [id-1 id-2] nil) ;; unhides only 2
             (is (= @unhidden-ids #{id-2}))
 
-            (set-many-vis [id-1 id-2] "hidden")
+            (set-many-vis! [id-1 id-2] "hidden")
             (is (= @unhidden-ids #{})) ;; no syncing when they are hidden
 
-            (set-many-vis [id-1 id-2] nil) ;; both are made unhidden so both synced
+            (set-many-vis! [id-1 id-2] nil) ;; both are made unhidden so both synced
             (is (= @unhidden-ids #{id-1 id-2}))))))))
 
 (deftest get-fks-test
diff --git a/test/metabase/cmd/rotate_encryption_key_test.clj b/test/metabase/cmd/rotate_encryption_key_test.clj
index 7baa7450bf9..bd2573424b4 100644
--- a/test/metabase/cmd/rotate_encryption_key_test.clj
+++ b/test/metabase/cmd/rotate_encryption_key_test.clj
@@ -145,10 +145,17 @@
 
               (testing "full rollback when a database details looks encrypted with a different key than the current one"
                 (encryption-test/with-secret-key k3
-                  (db/insert! Database {:name "k3", :engine :mysql, :details "{\"db\":\"/tmp/k3.db\"}"}))
+                  (let [db (db/insert! Database {:name "k3", :engine :mysql, :details "{\"db\":\"/tmp/k3.db\"}"})]
+                    (is (=? {:name "k3"}
+                            db))))
                 (encryption-test/with-secret-key k2
-                  (db/insert! Database {:name "k2", :engine :mysql, :details "{\"db\":\"/tmp/k2.db\"}"})
-                  (is (thrown? clojure.lang.ExceptionInfo (rotate-encryption-key! k3))))
+                  (let [db (db/insert! Database {:name "k2", :engine :mysql, :details "{\"db\":\"/tmp/k2.db\"}"})]
+                    (is (=? {:name "k2"}
+                            db)))
+                  (is (thrown-with-msg?
+                       clojure.lang.ExceptionInfo
+                       #"Can't decrypt app db with MB_ENCRYPTION_SECRET_KEY"
+                       (rotate-encryption-key! k3))))
                 (encryption-test/with-secret-key k3
                   (is (not= {:db "/tmp/k2.db"} (db/select-one-field :details Database :name "k2")))
                   (is (= {:db "/tmp/k3.db"} (db/select-one-field :details Database :name "k3")))))
diff --git a/test/metabase/db/schema_migrations_test.clj b/test/metabase/db/schema_migrations_test.clj
index 576a25c6f0d..eac0f4f3f50 100644
--- a/test/metabase/db/schema_migrations_test.clj
+++ b/test/metabase/db/schema_migrations_test.clj
@@ -26,7 +26,6 @@
             Database
             Dimension
             Field
-            Permissions
             Pulse
             Setting
             Table
@@ -42,13 +41,15 @@
    (java.sql Connection)
    (java.util UUID)))
 
+(set! *warn-on-reflection* true)
+
 (use-fixtures :once (fixtures/initialize :db))
 
 (deftest rollback-test
   (testing "Migrating to latest version, rolling back to v44, and then migrating up again"
     ;; using test-migrations to excercise all drivers
     (impl/test-migrations [1] [_]
-      (let [{:keys [db-type data-source]} mdb.connection/*application-db*
+      (let [{:keys [db-type ^javax.sql.DataSource data-source]} mdb.connection/*application-db*
             migrate!    (partial db.setup/migrate! db-type data-source)
             get-last-id (fn []
                           (-> {:connection (.getConnection data-source)}
@@ -364,7 +365,7 @@
                                                          :where  [:= :name perms-group/admin-group-name]})]
             (is (integer? admin-group-id))
             (when existing-entry?
-              (db/execute! {:insert-into Permissions
+              (db/execute! {:insert-into :permissions
                             :values      [{:object   "/"
                                            :group_id admin-group-id}]}))
             (migrate!)
@@ -378,7 +379,7 @@
     (doseq [with-existing-data-migration? [true false]]
       (testing (format "With existing data migration? %s" (pr-str with-existing-data-migration?))
         (impl/test-migrations "v43.00-007" [migrate!]
-          (db/execute! {:insert-into Database
+          (db/execute! {:insert-into :metabase_database
                         :values      [{:name       "My DB"
                                        :engine     "h2"
                                        :created_at :%now
@@ -400,7 +401,7 @@
 (deftest migrate-legacy-site-url-setting-test
   (testing "Migration v43.00-008: migrate legacy `-site-url` Setting to `site-url`; remove trailing slashes (#4123, #4188, #20402)"
     (impl/test-migrations ["v43.00-008"] [migrate!]
-      (db/execute! {:insert-into Setting
+      (db/execute! {:insert-into :setting
                     :values      [{:key   "-site-url"
                                    :value "http://localhost:3000/"}]})
       (migrate!)
@@ -410,7 +411,7 @@
 (deftest site-url-ensure-protocol-test
   (testing "Migration v43.00-009: ensure `site-url` Setting starts with a protocol (#20403)"
     (impl/test-migrations ["v43.00-009"] [migrate!]
-      (db/execute! {:insert-into Setting
+      (db/execute! {:insert-into :setting
                     :values      [{:key   "site-url"
                                    :value "localhost:3000"}]})
       (migrate!)
@@ -428,7 +429,7 @@
 (deftest add-migrated-collections-test
   (testing "Migrations v43.00-014 - v43.00-019"
     (letfn [(create-user! []
-              (db/execute! {:insert-into User
+              (db/execute! {:insert-into :core_user
                             :values      [{:first_name  "Cam"
                                            :last_name   "Era"
                                            :email       "cam@era.com"
@@ -439,7 +440,7 @@
                 :collection-name  "Migrated Dashboards"
                 :create-instance! (fn []
                                     (create-user!)
-                                    (db/execute! {:insert-into Dashboard
+                                    (db/execute! {:insert-into :report_dashboard
                                                   :values      [{:name          "My Dashboard"
                                                                  :created_at    :%now
                                                                  :updated_at    :%now
@@ -450,7 +451,7 @@
                 :collection-name  "Migrated Pulses"
                 :create-instance! (fn []
                                     (create-user!)
-                                    (db/execute! {:insert-into Pulse
+                                    (db/execute! {:insert-into :pulse
                                                   :values      [{:name          "My Pulse"
                                                                  :created_at    :%now
                                                                  :updated_at    :%now
@@ -461,13 +462,13 @@
                 :collection-name  "Migrated Questions"
                 :create-instance! (fn []
                                     (create-user!)
-                                    (db/execute! {:insert-into Database
+                                    (db/execute! {:insert-into :metabase_database
                                                   :values      [{:name       "My DB"
                                                                  :engine     "h2"
                                                                  :details    "{}"
                                                                  :created_at :%now
                                                                  :updated_at :%now}]})
-                                    (db/execute! {:insert-into Card
+                                    (db/execute! {:insert-into :report_card
                                                   :values      [{:name                   "My Saved Question"
                                                                  :created_at             :%now
                                                                  :updated_at             :%now
@@ -518,7 +519,7 @@
               (testing "Migrated Collection already exists\n"
                 (impl/test-migrations ["v43.00-014" "v43.00-019"] [migrate!]
                   (create-instance!)
-                  (db/execute! {:insert-into Collection
+                  (db/execute! {:insert-into :collection
                                 :values      [{:name collection-name, :slug "existing_collection", :color "#abc123"}]})
                   (migrate!)
                   (is (= [{:name collection-name, :slug "existing_collection"}]
@@ -555,7 +556,7 @@
 
       (testing "entry already exists: don't create an entry"
         (impl/test-migrations ["v43.00-020" "v43.00-021"] [migrate!]
-          (db/execute! {:insert-into Permissions
+          (db/execute! {:insert-into :permissions
                         :values      [{:object   "/collection/root/"
                                        :group_id (all-users-group-id)}]})
           (migrate!)
@@ -565,7 +566,7 @@
 (deftest clear-ldap-user-passwords-test
   (testing "Migration v43.00-029: clear password and password_salt for LDAP users"
     (impl/test-migrations ["v43.00-029"] [migrate!]
-      (db/execute! {:insert-into User
+      (db/execute! {:insert-into :core_user
                     :values      [{:first_name    "Cam"
                                    :last_name     "Era"
                                    :email         "cam@era.com"
@@ -590,7 +591,7 @@
 (deftest grant-download-perms-test
   (testing "Migration v43.00-042: grant download permissions to All Users permissions group"
     (impl/test-migrations ["v43.00-042" "v43.00-043"] [migrate!]
-      (db/execute! {:insert-into Database
+      (db/execute! {:insert-into :metabase_database
                     :values      [{:name       "My DB"
                                    :engine     "h2"
                                    :created_at :%now
@@ -713,7 +714,7 @@
 
       (testing "Should not fail if permissions already exist"
         (impl/test-migrations ["v44.00-033" "v44.00-034"] [migrate!]
-          (db/execute! {:insert-into Permissions
+          (db/execute! {:insert-into :permissions
                         :values      [{:object   (perms-path)
                                        :group_id (all-users-group-id)}]})
           (migrate!)
diff --git a/test/metabase/integrations/google_test.clj b/test/metabase/integrations/google_test.clj
index f0f8a0e0cfc..227de68bfa9 100644
--- a/test/metabase/integrations/google_test.clj
+++ b/test/metabase/integrations/google_test.clj
@@ -4,6 +4,7 @@
    [metabase.email-test :as et]
    [metabase.integrations.google :as google]
    [metabase.integrations.google.interface :as google.i]
+   [metabase.models.interface :as mi]
    [metabase.models.user :refer [User]]
    [metabase.public-settings.premium-features :as premium-features]
    [metabase.test :as mt]
@@ -129,9 +130,9 @@
       (mt/with-temp User [_ {:email "cam@sf-toucannery.com"}]
         (mt/with-temporary-setting-values [google-auth-auto-create-accounts-domain "metabase.com"]
           (testing "their account should return a UserInstance"
-            (is (schema= metabase.models.user.UserInstance
-                         (#'google/google-auth-fetch-or-create-user!
-                          "Cam" "Saul" "cam@sf-toucannery.com")))))))
+            (is (mi/instance-of? User
+                                 (#'google/google-auth-fetch-or-create-user!
+                                  "Cam" "Saul" "cam@sf-toucannery.com")))))))
 
     (testing "test that a user that doesn't exist with a *different* domain than the auto-create accounts domain gets an exception"
       (mt/with-temporary-setting-values [google-auth-auto-create-accounts-domain nil
@@ -146,8 +147,8 @@
         (mt/with-temporary-setting-values [google-auth-auto-create-accounts-domain "sf-toucannery.com"
                                            admin-email                             "rasta@toucans.com"]
           (try
-            (is (schema= metabase.models.user.UserInstance
-                         (#'google/google-auth-fetch-or-create-user!
-                          "Rasta" "Toucan" "rasta@sf-toucannery.com")))
+            (is (mi/instance-of? User
+                                 (#'google/google-auth-fetch-or-create-user!
+                                  "Rasta" "Toucan" "rasta@sf-toucannery.com")))
             (finally
               (db/delete! User :email "rasta@sf-toucannery.com"))))))))
diff --git a/test/metabase/models/card_test.clj b/test/metabase/models/card_test.clj
index acc41131d6f..7dcd52cb98d 100644
--- a/test/metabase/models/card_test.clj
+++ b/test/metabase/models/card_test.clj
@@ -2,8 +2,7 @@
   (:require
    [cheshire.core :as json]
    [clojure.test :refer :all]
-   [metabase.models
-    :refer [Card Collection Dashboard DashboardCard]]
+   [metabase.models :refer [Card Collection Dashboard DashboardCard]]
    [metabase.models.card :as card]
    [metabase.models.serialization.base :as serdes.base]
    [metabase.models.serialization.hash :as serdes.hash]
@@ -13,9 +12,7 @@
    [metabase.util :as u]
    [toucan.db :as db]
    [toucan.hydrate :as hydrate]
-   [toucan.util.test :as tt])
-  (:import
-   (java.time LocalDateTime)))
+   [toucan.util.test :as tt]))
 
 (deftest dashboard-count-test
   (testing "Check that the :dashboard_count delay returns the correct count of Dashboards a Card is in"
@@ -353,9 +350,9 @@
 
 (deftest identity-hash-test
   (testing "Card hashes are composed of the name and the collection's hash"
-    (let [now (LocalDateTime/of 2022 9 1 12 34 56)]
-      (mt/with-temp* [Collection  [coll  {:name "field-db" :location "/" :created_at now}]
-                      Card        [card  {:name "the card" :collection_id (:id coll) :created_at now}]]
+    (let [now #t "2022-09-01T12:34:56"]
+      (mt/with-temp* [Collection [coll  {:name "field-db" :location "/" :created_at now}]
+                      Card       [card  {:name "the card" :collection_id (:id coll) :created_at now}]]
         (is (= "5199edf0"
                (serdes.hash/raw-hash ["the card" (serdes.hash/identity-hash coll) now])
                (serdes.hash/identity-hash card)))))))
diff --git a/test/metabase/models/collection_test.clj b/test/metabase/models/collection_test.clj
index 3093835c580..3f308f06732 100644
--- a/test/metabase/models/collection_test.clj
+++ b/test/metabase/models/collection_test.clj
@@ -24,9 +24,7 @@
    [metabase.util.schema :as su]
    [schema.core :as s]
    [toucan.db :as db]
-   [toucan.hydrate :refer [hydrate]])
-  (:import
-   (java.time LocalDateTime)))
+   [toucan.hydrate :refer [hydrate]]))
 
 (use-fixtures :once (fixtures/initialize :db :test-users :test-users-personal-collections))
 
@@ -113,16 +111,14 @@
                     Card       [card       {:collection_id (u/the-id collection)}]]
       (db/update! Collection (u/the-id collection)
         :archived true)
-      (is (= true
-             (db/select-one-field :archived Card :id (u/the-id card))))))
+      (is (true? (db/select-one-field :archived Card :id (u/the-id card))))))
 
   (testing "check that unarchiving a Collection unarchives its Cards as well"
     (mt/with-temp* [Collection [collection {:archived true}]
                     Card       [card       {:collection_id (u/the-id collection), :archived true}]]
       (db/update! Collection (u/the-id collection)
         :archived false)
-      (is (= false
-             (db/select-one-field :archived Card :id (u/the-id card)))))))
+      (is (false? (db/select-one-field :archived Card :id (u/the-id card)))))))
 
 (deftest validate-name-test
   (testing "check that collections' names cannot be blank"
@@ -395,8 +391,7 @@
   (testing "We should be able to UPDATE a Collection and give it a new, *valid* location"
     (mt/with-temp* [Collection [collection-1]
                     Collection [collection-2]]
-      (is (= true
-             (db/update! Collection (u/the-id collection-1) :location (collection/location-path collection-2)))))))
+      (is (true? (db/update! Collection (u/the-id collection-1) :location (collection/location-path collection-2)))))))
 
 (deftest crud-validate-ancestors-test
   (testing "Make sure we can't INSERT a Collection with an non-existent ancestors"
@@ -1635,7 +1630,7 @@
 
 (deftest identity-hash-test
   (testing "Collection hashes are composed of the name, namespace, and parent collection's hash"
-    (let [now (LocalDateTime/of 2022 9 1 12 34 56)]
+    (let [now #t "2022-09-01T12:34:56"]
       (mt/with-temp* [Collection [c1  {:name       "top level"
                                        :created_at now
                                        :namespace  "yolocorp"
diff --git a/test/metabase/models/field_test.clj b/test/metabase/models/field_test.clj
index f303297ea34..6883d68f028 100644
--- a/test/metabase/models/field_test.clj
+++ b/test/metabase/models/field_test.clj
@@ -34,7 +34,7 @@
                                                         :fallback-type nil}]]
     (testing (format "Field with unknown %s in DB should fall back to %s" column fallback-type)
       (mt/with-temp Field [field]
-        (db/execute! {:update Field
+        (db/execute! {:update :metabase_field
                       :set    {column (u/qualified-name unknown-type)}
                       :where  [:= :id (u/the-id field)]})
         (is (= fallback-type
diff --git a/test/metabase/models/field_values_test.clj b/test/metabase/models/field_values_test.clj
index 3bdb18a17b1..1dc9ae74a36 100644
--- a/test/metabase/models/field_values_test.clj
+++ b/test/metabase/models/field_values_test.clj
@@ -141,7 +141,7 @@
           (is (= :full (:type (field-values/get-or-create-full-field-values! (db/select-one Field :id (mt/id :categories :name))))))))
 
       (testing "if an old FieldValues Exists, make sure we still return the full FieldValues and update last_used_at"
-        (db/execute! {:update FieldValues
+        (db/execute! {:update :metabase_fieldvalues
                       :where [:and
                               [:= :field_id (mt/id :categories :name)]
                               [:= :type "full"]]
@@ -156,9 +156,9 @@
   (testing "If FieldValues were saved as a map, normalize them to a sequence on the way out"
     (mt/with-temp FieldValues [fv {:field_id (mt/id :venues :id)
                                    :values   (json/generate-string ["1" "2" "3"])}]
-      (db/execute! {:update FieldValues
-                    :set    {:human_readable_values (json/generate-string {"1" "a", "2" "b", "3" "c"})}
-                    :where  [:= :id (:id fv)]})
+      (is (db/execute! {:update :metabase_fieldvalues
+                        :set    {:human_readable_values (json/generate-string {"1" "a", "2" "b", "3" "c"})}
+                        :where  [:= :id (:id fv)]}))
       (is (= ["a" "b" "c"]
              (:human_readable_values (db/select-one FieldValues :id (:id fv))))))))
 
@@ -182,7 +182,7 @@
               field-id        (db/select-one-field :id Field :table_id table-id :name "CATEGORY_ID")
               field-values-id (db/select-one-field :id FieldValues :field_id field-id)]
           ;; Add in human readable values for remapping
-          (db/update! FieldValues field-values-id {:human_readable_values ["a" "b" "c"]})
+          (is (db/update! FieldValues field-values-id {:human_readable_values ["a" "b" "c"]}))
           (let [expected-original-values {:values                [1 2 3]
                                           :human_readable_values ["a" "b" "c"]}
                 expected-updated-values  {:values                [-2 -1 0 1 2 3]
diff --git a/test/metabase/models/login_history_test.clj b/test/metabase/models/login_history_test.clj
index 32e8d675c0c..fe32ef2c939 100644
--- a/test/metabase/models/login_history_test.clj
+++ b/test/metabase/models/login_history_test.clj
@@ -71,13 +71,13 @@
                              @mt/inbox))
                 (let [message (-> @mt/inbox (get email) first :body first :content)
                       site-url (public-settings/site-url)]
-                  (testing (format "\nMessage = %s" (pr-str message))
+                  (testing (format "\nMessage = %s\nsite-url = %s" (pr-str message) (pr-str site-url))
                     (is (string? message))
                     (when (string? message)
                       (doseq [expected-str [(format "We've noticed a new login on your <a href=\"%s\">Metabase</a> account."
-                                                    site-url)
+                                                    (or site-url ""))
                                             (format "We noticed a login on your <a href=\"%s\">Metabase</a> account from a new device."
-                                                    site-url)
+                                                    (or site-url ""))
                                             "Browser (Chrome/Windows) - San Francisco, California, United States"
                                             ;; `format-human-readable` has slightly different output on different JVMs
                                             (u.date/format-human-readable #t "2021-04-02T15:52:00-07:00[US/Pacific]")]]
diff --git a/test/metabase/models/metric_test.clj b/test/metabase/models/metric_test.clj
index 82fa19554b7..5d7830a1847 100644
--- a/test/metabase/models/metric_test.clj
+++ b/test/metabase/models/metric_test.clj
@@ -26,13 +26,13 @@
     (mt/with-temp Metric [{:keys [id]} {:creator_id (mt/user->id :rasta)}]
       (testing "you should not be able to change the creator_id of a Metric"
         (is (thrown-with-msg?
-             UnsupportedOperationException
+             Exception
              #"You cannot update the creator_id of a Metric"
              (db/update! Metric id {:creator_id (mt/user->id :crowberto)}))))
 
       (testing "you shouldn't be able to set it to `nil` either"
         (is (thrown-with-msg?
-             UnsupportedOperationException
+             Exception
              #"You cannot update the creator_id of a Metric"
              (db/update! Metric id {:creator_id nil}))))
 
diff --git a/test/metabase/models/native_query_snippet_test.clj b/test/metabase/models/native_query_snippet_test.clj
index 6d0a96799b1..4c0179445a0 100644
--- a/test/metabase/models/native_query_snippet_test.clj
+++ b/test/metabase/models/native_query_snippet_test.clj
@@ -12,7 +12,7 @@
   (testing "You shouldn't be allowed to update the creator_id of a NativeQuerySnippet"
     (mt/with-temp NativeQuerySnippet [{snippet-id :id} {:name "my-snippet", :content "wow", :creator_id (mt/user->id :lucky)}]
       (is (thrown-with-msg?
-           UnsupportedOperationException
+           Exception
            #"You cannot update the creator_id of a NativeQuerySnippet\."
            (db/update! NativeQuerySnippet snippet-id :creator_id (mt/user->id :rasta))))
       (is (= (mt/user->id :lucky)
diff --git a/test/metabase/models/segment_test.clj b/test/metabase/models/segment_test.clj
index 4dd61474c72..e655bf8930c 100644
--- a/test/metabase/models/segment_test.clj
+++ b/test/metabase/models/segment_test.clj
@@ -15,13 +15,15 @@
   (testing "Updating"
     (mt/with-temp Segment [{:keys [id]} {:creator_id (mt/user->id :rasta)}]
       (testing "you should not be able to change the creator_id of a Segment"
-        (is (thrown?
-             UnsupportedOperationException
+        (is (thrown-with-msg?
+             Exception
+             #"You cannot update the creator_id of a Segment"
              (db/update! Segment id {:creator_id (mt/user->id :crowberto)}))))
 
       (testing "you shouldn't be able to set it to `nil` either"
-        (is (thrown?
-             UnsupportedOperationException
+        (is (thrown-with-msg?
+             Exception
+             #"You cannot update the creator_id of a Segment"
              (db/update! Segment id {:creator_id nil}))))
 
       (testing "calling `update!` with a value that is the same as the current value shouldn't throw an Exception"
diff --git a/test/metabase/models/session_test.clj b/test/metabase/models/session_test.clj
index f4b54dace53..d9dd50ab6a6 100644
--- a/test/metabase/models/session_test.clj
+++ b/test/metabase/models/session_test.clj
@@ -20,20 +20,18 @@
 
 (deftest new-session-include-test-test
   (testing "when creating a new Session, it should come back with an added `:type` key"
-    (is (= {:id              "092797dd-a82a-4748-b393-697d7bb9ab65"
-            :user_id         (mt/user->id :trashbird)
-            :anti_csrf_token nil
-            :type            :normal}
-           (mt/derecordize
-            (new-session))))))
+    (is (=? {:id              "092797dd-a82a-4748-b393-697d7bb9ab65"
+             :user_id         (mt/user->id :trashbird)
+             :anti_csrf_token nil
+             :type            :normal}
+            (new-session)))))
 
 (deftest embedding-test
   (testing "if request is an embedding request, we should get ourselves an embedded Session"
     (binding [mw.misc/*request* {:headers {"x-metabase-embedded" "true"}}]
       (with-redefs [session/random-anti-csrf-token (constantly "315c1279c6f9f873bf1face7afeee420")]
-        (is (= {:id              "092797dd-a82a-4748-b393-697d7bb9ab65"
-                :user_id         (mt/user->id :trashbird)
-                :anti_csrf_token "315c1279c6f9f873bf1face7afeee420"
-                :type            :full-app-embed}
-               (mt/derecordize
-                (new-session))))))))
+        (is (=? {:id              "092797dd-a82a-4748-b393-697d7bb9ab65"
+                 :user_id         (mt/user->id :trashbird)
+                 :anti_csrf_token "315c1279c6f9f873bf1face7afeee420"
+                 :type            :full-app-embed}
+                (new-session)))))))
diff --git a/test/metabase/models/setting/multi_setting_test.clj b/test/metabase/models/setting/multi_setting_test.clj
index 483fba21904..12a5fc209fc 100644
--- a/test/metabase/models/setting/multi_setting_test.clj
+++ b/test/metabase/models/setting/multi_setting_test.clj
@@ -33,7 +33,7 @@
     (is (= "Green Friend"
            (multi-setting-test-bird-name)))
     (is (thrown-with-msg?
-         UnsupportedOperationException
+         Exception
          #"You cannot set :multi-setting-test-bird-name; it is a read-only setting"
          (multi-setting-test-bird-name! "Parroty"))))
   (testing :yellow-friend
@@ -69,6 +69,6 @@
             (is (not (resolve 'multi-setting-read-only!))))
           (testing "Should not be able to set the Setting with `setting/set!`"
             (is (thrown-with-msg?
-                 UnsupportedOperationException
+                 Exception
                  #"You cannot set multi-setting-read-only; it is a read-only setting"
                  (setting/set! :multi-setting-read-only "Parroty")))))))))
diff --git a/test/metabase/models/user_test.clj b/test/metabase/models/user_test.clj
index a07fca3d0ef..3fd7aa05328 100644
--- a/test/metabase/models/user_test.clj
+++ b/test/metabase/models/user_test.clj
@@ -428,8 +428,8 @@
                  (db/select-one-field :locale User :id user-id)))))
       (testing "invalid locale"
         (is (thrown-with-msg?
-             Exception
-             #"Assert failed: \(i18n/available-locale\? locale\)"
+             Throwable
+             #"Assert failed: Invalid locale: \"en_XX\""
              (mt/with-temp User [_ {:locale "en_XX"}])))))
 
     (testing "updating a User"
@@ -440,8 +440,8 @@
                  (db/select-one-field :locale User :id user-id))))
         (testing "invalid locale"
           (is (thrown-with-msg?
-               AssertionError
-               #"Assert failed: \(i18n/available-locale\? locale\)"
+               Throwable
+               #"Assert failed: Invalid locale: \"en_XX\""
                (db/update! User user-id :locale "en_XX"))))))))
 
 (deftest normalize-locale-test
diff --git a/test/metabase/query_processor/middleware/add_dimension_projections_test.clj b/test/metabase/query_processor/middleware/add_dimension_projections_test.clj
index ef05c3103d6..df634d6e2e5 100644
--- a/test/metabase/query_processor/middleware/add_dimension_projections_test.clj
+++ b/test/metabase/query_processor/middleware/add_dimension_projections_test.clj
@@ -15,6 +15,10 @@
 
 ;;; ----------------------------------------- add-fk-remaps (pre-processing) -----------------------------------------
 
+(defn- add-fk-remaps [query]
+  (mt/with-everything-store
+    (#'qp.add-dimension-projections/add-fk-remaps query)))
+
 (def ^:private remapped-field
   (delay
     {:id                        1000
@@ -40,16 +44,17 @@
                                         {:source-field                                (mt/id :venues :category_id)
                                          ::qp.add-dimension-projections/new-field-dimension-id 1000}]
                 :dimension             @remapped-field}]
-              (#'qp.add-dimension-projections/remap-column-infos
-               [[:field (mt/id :venues :price) nil]
-                [:field (mt/id :venues :longitude) nil]
-                [:field (mt/id :venues :category_id) nil]])))))))
+              (mt/with-everything-store
+                (#'qp.add-dimension-projections/remap-column-infos
+                 [[:field (mt/id :venues :price) nil]
+                  [:field (mt/id :venues :longitude) nil]
+                  [:field (mt/id :venues :category_id) nil]]))))))))
 
 (deftest add-fk-remaps-add-fields-test
   (do-with-fake-remappings-for-category-id
    (fn []
      (testing "make sure FK remaps add an entry for the FK field to `:fields`, and returns a pair of [dimension-info updated-query]"
-       (let [{:keys [remaps query]} (#'qp.add-dimension-projections/add-fk-remaps
+       (let [{:keys [remaps query]} (add-fk-remaps
                                      (mt/mbql-query venues
                                        {:fields [$price $longitude $category_id]}))]
          (is (= [@remapped-field]
@@ -77,7 +82,7 @@
                                         {:source-field               %category_id
                                          ::some-other-namespaced-key true}])]
          (testing (format "\ncategories.name field options = %s" (pr-str category-name-options))
-           (let [{:keys [remaps query]} (#'qp.add-dimension-projections/add-fk-remaps
+           (let [{:keys [remaps query]} (add-fk-remaps
                                          (mt/mbql-query venues
                                            {:fields [$price
                                                      $category_id
@@ -100,13 +105,13 @@
 
              (testing "Preprocessing query again should not result in duplicate columns being added"
                (is (query= query
-                           (:query (#'qp.add-dimension-projections/add-fk-remaps query))))))))))))
+                           (:query (add-fk-remaps query))))))))))))
 
 (deftest add-fk-remaps-replace-order-bys-test
   (testing "adding FK remaps should replace any existing order-bys for a field with order bys for the FK remapping Field"
     (do-with-fake-remappings-for-category-id
      (fn []
-       (let [{:keys [remaps query]} (#'qp.add-dimension-projections/add-fk-remaps
+       (let [{:keys [remaps query]} (add-fk-remaps
                                      (mt/mbql-query venues
                                        {:fields   [$price $longitude $category_id]
                                         :order-by [[:asc $category_id]]}))]
@@ -132,7 +137,7 @@
   (testing "adding FK remaps should replace any existing breakouts for a field with order bys for the FK remapping Field"
     (do-with-fake-remappings-for-category-id
      (fn []
-       (let [{:keys [remaps query]} (#'qp.add-dimension-projections/add-fk-remaps
+       (let [{:keys [remaps query]} (add-fk-remaps
                                      (mt/mbql-query venues
                                        {:breakout    [$category_id]
                                         :aggregation [[:count]]}))]
@@ -153,7 +158,7 @@
   (testing "make sure FK remaps work with nested queries"
     (do-with-fake-remappings-for-category-id
      (fn []
-       (let [{:keys [remaps query]} (#'qp.add-dimension-projections/add-fk-remaps
+       (let [{:keys [remaps query]} (add-fk-remaps
                                      (mt/mbql-query venues
                                        {:source-query {:source-table $$venues
                                                        :fields       [$price $longitude $category_id]}}))]
@@ -311,7 +316,8 @@
                                                                                  :human_readable_field_id   (mt/id :products :title)
                                                                                  :field_name                "PRODUCT_ID"
                                                                                  :human_readable_field_name "TITLE"}]))
-                     (#'qp.add-dimension-projections/add-remapped-columns query))))))))))
+                     (mt/with-everything-store
+                       (#'qp.add-dimension-projections/add-remapped-columns query)))))))))))
 
 (deftest fk-remaps-with-multiple-columns-with-same-name-test
   (testing "Make sure we remap to the correct column when some of them have duplicate names"
@@ -320,7 +326,7 @@
                                                         {:fields   [$name $category_id]
                                                          :order-by [[:asc $name]]
                                                          :limit    4})
-            {remap-info :remaps, preprocessed :query} (#'qp.add-dimension-projections/add-fk-remaps query)
+            {remap-info :remaps, preprocessed :query} (add-fk-remaps query)
             dimension-id                              (db/select-one-id Dimension
                                                         :field_id                (mt/id :venues :category_id)
                                                         :human_readable_field_id (mt/id :categories :name))]
@@ -379,7 +385,7 @@
               receiver-dimension-id                     (db/select-one-id Dimension
                                                           :field_id                (mt/id :messages :receiver_id)
                                                           :human_readable_field_id (mt/id :users :name))
-              {remap-info :remaps, preprocessed :query} (#'qp.add-dimension-projections/add-fk-remaps query)]
+              {remap-info :remaps, preprocessed :query} (add-fk-remaps query)]
           (testing "Pre-processing"
             (testing "Remap info"
               (is (query= (mt/$ids messages
@@ -462,7 +468,7 @@
                                  &PRODUCTS__via__PRODUCT_ID.orders.product_id->products.title]
                         :limit  2})
                      (:query
-                      (#'qp.add-dimension-projections/add-fk-remaps
+                      (add-fk-remaps
                        (mt/mbql-query products
                          {:joins  [{:strategy     :left-join
                                     :source-query {:source-table $$orders}
diff --git a/test/metabase/query_processor/middleware/fetch_source_query_test.clj b/test/metabase/query_processor/middleware/fetch_source_query_test.clj
index 69dbb4f6c63..14aa26d89bc 100644
--- a/test/metabase/query_processor/middleware/fetch_source_query_test.clj
+++ b/test/metabase/query_processor/middleware/fetch_source_query_test.clj
@@ -250,15 +250,16 @@
                                    :query    {:source-table (str "card__" card-id)}}
             save-error            (try
                                     ;; `db/update!` will fail because it will try to validate the query when it saves
-                                    (db/execute! {:update Card
+                                    (db/execute! {:update :report_card
                                                   :set    {:dataset_query (json/generate-string circular-source-query)}
                                                   :where  [:= :id card-id]})
                                     nil
                                     (catch Throwable e
                                       (str "Failed to save Card:" e)))]
         ;; Make sure save isn't the thing throwing the Exception
-        (is (thrown?
+        (is (thrown-with-msg?
              clojure.lang.ExceptionInfo
+             #"Circular dependency"
              (or save-error
                  (resolve-card-id-source-tables circular-source-query)))))))
 
@@ -273,14 +274,15 @@
         ;; Make sure save isn't the thing throwing the Exception
         (let [save-error (try
                            ;; `db/update!` will fail because it will try to validate the query when it saves,
-                           (db/execute! {:update Card
+                           (db/execute! {:update :report_card
                                          :set    {:dataset_query (json/generate-string (circular-source-query card-2-id))}
                                          :where  [:= :id card-1-id]})
                            nil
                            (catch Throwable e
                              (str "Failed to save Card:" e)))]
-          (is (thrown?
+          (is (thrown-with-msg?
                clojure.lang.ExceptionInfo
+               #"Circular dependency"
                (or save-error
                    (resolve-card-id-source-tables (circular-source-query card-1-id))))))))))
 
diff --git a/test/metabase/server/middleware/session_test.clj b/test/metabase/server/middleware/session_test.clj
index c6be49b1f4c..a8c25cfaf07 100644
--- a/test/metabase/server/middleware/session_test.clj
+++ b/test/metabase/server/middleware/session_test.clj
@@ -309,7 +309,7 @@
       (db/insert! Session {:id      (str test-uuid)
                            :user_id (mt/user->id :lucky)})
         ;; use low-level `execute!` because updating is normally disallowed for Sessions
-      (db/execute! {:update Session, :set {:created_at (java.sql.Date. 0)}, :where [:= :id (str test-uuid)]})
+      (db/execute! {:update :core_session, :set {:created_at (t/instant 0)}, :where [:= :id (str test-uuid)]})
       (is (= nil
              (#'mw.session/current-user-info-for-session (str test-uuid) nil)))
       (finally
diff --git a/test/metabase/test.clj b/test/metabase/test.clj
index b24616e5a42..71fedddb7b9 100644
--- a/test/metabase/test.clj
+++ b/test/metabase/test.clj
@@ -19,7 +19,6 @@
    [metabase.http-client :as client]
    [metabase.models :refer [PermissionsGroupMembership User]]
    [metabase.models.permissions-group :as perms-group]
-   [metabase.plugins.classloader :as classloader]
    [metabase.query-processor :as qp]
    [metabase.query-processor-test :as qp.test]
    [metabase.query-processor.context :as qp.context]
@@ -43,7 +42,6 @@
    [metabase.test.util.i18n :as i18n.tu]
    [metabase.test.util.log :as tu.log]
    [metabase.test.util.timezone :as test.tz]
-   [metabase.util :as u]
    [pjstadig.humane-test-output :as humane-test-output]
    [potemkin :as p]
    [toucan.db :as db]
@@ -263,14 +261,6 @@
   set-test-drivers!
   with-test-drivers])
 
-;; ee-only stuff
-(u/ignore-exceptions
-  (classloader/require 'metabase-enterprise.sandbox.test-util)
-  (eval '(potemkin/import-vars [metabase-enterprise.sandbox.test-util
-                                with-gtaps
-                                with-gtaps-for-user
-                                with-user-attributes])))
-
 ;;; TODO -- move all the stuff below into some other namespace and import it here.
 
 (defn do-with-clock [clock thunk]
diff --git a/test/metabase/test/data/users.clj b/test/metabase/test/data/users.clj
index 32f4e649565..87c3dc092c6 100644
--- a/test/metabase/test/data/users.clj
+++ b/test/metabase/test/data/users.clj
@@ -187,13 +187,13 @@
       (when-not user-email
         (throw (ex-info "User does not exist" {:user user})))
       (try
-        (db/execute! {:update User
+        (db/execute! {:update :core_user
                       :set    {:password      (u.password/hash-bcrypt user-email)
                                :password_salt ""}
                       :where  [:= :id user-id]})
         (apply client/client {:username user-email, :password user-email} args)
         (finally
-          (db/execute! {:update User
+          (db/execute! {:update :core_user
                         :set    old-password-info
                         :where  [:= :id user-id]}))))))
 
diff --git a/test/metabase/util/encryption_test.clj b/test/metabase/util/encryption_test.clj
index 2a557d0af25..b7fca2eb065 100644
--- a/test/metabase/util/encryption_test.clj
+++ b/test/metabase/util/encryption_test.clj
@@ -24,8 +24,10 @@
   "Run `body` with the encryption secret key temporarily bound to `secret-key`. Useful for testing how functions behave
   with and without encryption disabled."
   {:style/indent 1}
-  [^String secret-key, & body]
-  `(do-with-secret-key ~secret-key (fn [] ~@body)))
+  [^String secret-key & body]
+  `(let [secret-key# ~secret-key]
+     (testing (format "\nwith secret key %s" (pr-str secret-key#))
+       (do-with-secret-key secret-key# (fn [] ~@body)))))
 
 (def ^:private secret   (encryption/secret-key->hash "Orw0AAyzkO/kPTLJRxiyKoBHXa/d6ZcO+p+gpZO/wSQ="))
 (def ^:private secret-2 (encryption/secret-key->hash "0B9cD6++AME+A7/oR7Y2xvPRHX3cHA2z7w+LbObd/9Y="))
-- 
GitLab