Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Lint against implicit `:id` behavior in toucan (#85768)

Ethan McCue9fe42fdf14e7
diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn
index 1edc2e678cb..b65df3abda0 100644
--- a/.clj-kondo/config.edn
+++ b/.clj-kondo/config.edn
@@ -74,6 +74,7 @@
:metabase/no-jsqlparser-imports {:level :warning}
:metabase/prefer-with-dynamic-fn-redefs {:level :warning}
:metabase/t2-query-namespace {:level :warning}
+ :metabase/t2-implicit-pk {:level :warning}
:metabase/table-or-field-query {:level :warning}
;; App-DB query hygiene: a value reaching a value slot unmarked, and a query written as
;; `:column value` pairs rather than a map. Off by default and enabled per namespace under
@@ -248,7 +249,9 @@
metabase.util/run-count!
next.jdbc/execute!
;; pure validator: parses a keyword and throws on a bad one, touches no state
- metabase.mcp.v2.tools.question/check-semantic-type!}}
+ metabase.mcp.v2.tools.question/check-semantic-type!
+ ;; pure validator: throws unless its argument is a map or nil, touches no state
+ metabase.util.honey-sql-2/assert-map-or-nil!}}
:metabase/i-like-making-cams-eyes-bleed-with-horrifically-long-tests
{:level :warning
diff --git a/.clj-kondo/src/hooks/metabase/toucan/db_ns.clj b/.clj-kondo/src/hooks/metabase/toucan/db_ns.clj
index a5cf258d5fa..fb4a65b5fe3 100644
--- a/.clj-kondo/src/hooks/metabase/toucan/db_ns.clj
+++ b/.clj-kondo/src/hooks/metabase/toucan/db_ns.clj
@@ -313,10 +313,145 @@
(hooks/sexpr value) (hooks/sexpr value))
:type :metabase/unsafe-app-db-query))))
+(def ^:private model-index
+ "For each Toucan 2 fn that accepts a bare primary key, the index of the model among its arguments."
+ '{select 0
+ select-one 0
+ select-pks-set 0
+ select-pks-vec 0
+ select-one-pk 0
+ reducible-select 0
+ count 0
+ exists? 0
+ delete! 0
+ update! 0
+ update-returning-pks! 0
+ reducible-update 0
+ reducible-update-returning-pks 0
+ select-one-fn 1
+ select-fn-set 1
+ select-fn-vec 1
+ select-fn-reducible 1
+ select-pk->fn 1
+ select-fn->pk 1
+ select-fn->fn 2})
+
+(def ^:private trailing-changes-fns
+ "Fns whose arglist ends in a changes map, so the bare primary key is the second-to-last argument."
+ '#{update! update-returning-pks! reducible-update reducible-update-returning-pks})
+
+(def ^:private map-returning-fns
+ "Fns whose call returns a map -- or throws, given a string -- so a call to one can never carry a string into
+ the query slot."
+ '#{assoc assoc-in assoc-some dissoc select-keys update update-in})
+
+(def ^:private seeded-fns
+ "Fns that return their first argument when nothing applies, so they return a map only when seeded with one."
+ '#{cond-> cond->> -> ->> some-> some->> into})
+
+(def ^:private branching-fns
+ "Fns whose result is one of their branches, so they return a map only when every branch is one."
+ '#{if if-not if-let if-some when when-not when-let when-some or})
+
+(def ^:private map-asserting-fns
+ "`h2x/assert-map-or-nil!`, which throws for anything but a map or nil, so a call to it can never carry a string."
+ '#{metabase.util.honey-sql-2/assert-map-or-nil!})
+
+(defn- resolved-symbol
+ "`sym` with its namespace alias resolved, or `sym` itself when Kondo cannot resolve it."
+ [sym]
+ (or (try
+ (when-let [{resolved-ns :ns, resolved-name :name} (hooks/resolve {:name sym})]
+ (symbol (str resolved-ns) (str resolved-name)))
+ (catch Exception _ nil))
+ sym))
+
+(defn- map-form?
+ "Whether `node` statically yields a map (or nil), so passing it after the model is conditions or a query,
+ never a string. A fn named for a query proves nothing -- it could return a string -- so only the shape of the
+ form counts, or a call to [[map-asserting-fns]], which checks at runtime."
+ [node]
+ (cond
+ (hooks/map-node? node) true
+ (and (hooks/token-node? node) (nil? (hooks/sexpr node))) true
+ (hooks/list-node? node)
+ (let [[head & args] (:children node)
+ sym (some-> head hooks/sexpr)
+ f (when (symbol? sym) (symbol (name sym)))]
+ (boolean
+ (cond
+ (and (symbol? sym)
+ (contains? map-asserting-fns (resolved-symbol sym))) true
+ (contains? map-returning-fns f) true
+ (contains? seeded-fns f) (some-> (first args) map-form?)
+ ;; `(merge s {...})` throws for a string `s`, so one map argument is enough.
+ (= 'merge f) (some map-form? args)
+ (contains? branching-fns f) (let [branches (case f
+ (if if-not if-let if-some) (rest args)
+ (when when-not when-let when-some) [(last args)]
+ or args)]
+ (and (seq branches) (every? map-form? branches))))))
+ :else false))
+
+(defn- implicit-pk-node?
+ "Whether `node`, as the lone query argument after a model, is read by Toucan as a primary key.
+
+ A keyword names a query, and a string or vector literal is a query written in place. A form that yields a
+ map ([[map-form?]]), or an identity query, is a query too. Anything else -- a symbol, a number, a call -- is
+ reported, because Toucan reads a non-map value as a primary key, and a string one as a query: written as
+ `:id x`, a string is bound as a value instead."
+ [node]
+ (not (or (map-form? node)
+ (hooks/keyword-node? node)
+ (hooks/string-node? node)
+ (hooks/vector-node? node)
+ (let [head (some-> node :children first hooks/sexpr)]
+ (and (hooks/list-node? node) (symbol? head) (= "identity-query" (name head)))))))
+
+(def ^:private pk-columns
+ "Models whose primary key is not `:id`, mirroring their `t2/primary-keys` methods."
+ {:model/FieldUserSettings :field_id
+ :model/TableUserSettings :table_id
+ :model/Setting :key
+ :model/QueryCache :query_hash
+ :model/QueryAction :action_id
+ :model/ImplicitAction :action_id})
+
+(defn- pk-column
+ "The primary key column to suggest for `model-node`: `:id`, unless [[pk-columns]] names another. A model
+ that is not a literal keyword could be any model, so it gets `:toucan/pk`, which matches on whatever that
+ model's primary key is."
+ [model-node]
+ (let [model (if (hooks/vector-node? model-node)
+ (some-> model-node :children first hooks/sexpr)
+ (some-> model-node hooks/sexpr))]
+ (if (keyword? model)
+ (get pk-columns model :id)
+ :toucan/pk)))
+
+(defn- lint-implicit-pk!
+ "Register a `:metabase/t2-implicit-pk` finding when a primary key is passed bare, as in
+ `(t2/select-one :model/Card id)`, rather than as `(t2/select-one :model/Card :id id)`."
+ [node]
+ (let [[fn-node & args] (:children node)
+ verb (some-> fn-node hooks/sexpr name symbol)]
+ (when-let [i (get model-index verb)]
+ (let [after-model (drop (inc i) args)
+ n-query (if (contains? trailing-changes-fns verb) 2 1)]
+ (when (= n-query (count after-model))
+ (let [pk (first after-model)]
+ (when (implicit-pk-node? pk)
+ (hooks/reg-finding!
+ (assoc (meta pk)
+ :message (format "Pass the primary key as `%s %s` rather than bare to `%s`"
+ (pk-column (nth args i)) (hooks/sexpr pk) (hooks/sexpr fn-node))
+ :type :metabase/t2-implicit-pk)))))))))
+
(defn lint-query-call
"Register a `:metabase/t2-query-namespace` finding when a Toucan 2 query call appears outside a `<module>.db`
namespace."
[{:keys [node ns filename] :as input}]
+ (lint-implicit-pk! node)
(when (and ns
(not (db-namespace? (modules/config input) ns))
(not (test-file? filename)))
diff --git a/.clj-kondo/test/hooks/metabase/toucan/db_ns_test.clj b/.clj-kondo/test/hooks/metabase/toucan/db_ns_test.clj
index 40c99af1c14..f1a392ad933 100644
--- a/.clj-kondo/test/hooks/metabase/toucan/db_ns_test.clj
+++ b/.clj-kondo/test/hooks/metabase/toucan/db_ns_test.clj
@@ -6,14 +6,15 @@
[hooks.metabase.toucan.db-ns :as toucan.db-ns]))
(defn- confinement-findings
- "Only the `t2-query-namespace` findings, so these tests are not affected by the query-hygiene
- linter that shares this hook."
+ "Only the `t2-query-namespace` findings, so these tests are not affected by the other linters
+ that share this hook."
[findings]
(filter #(= :metabase/t2-query-namespace (:type %)) findings))
(defn- lint-query-call [form ns-sym & [filename modules]]
(binding [clj-kondo.impl.utils/*ctx* {:config {:linters {:metabase/t2-query-namespace {:level :warning}
- :metabase/unsafe-app-db-query {:level :warning}}}
+ :metabase/unsafe-app-db-query {:level :warning}
+ :metabase/t2-implicit-pk {:level :warning}}}
:ignores (atom nil)
:findings (atom [])
:namespaces (atom {})}]
@@ -44,7 +45,7 @@
(is (=? [{:type :metabase/t2-query-namespace}]
(lint-query-call '(t2/delete! :model/Card :id 1) 'metabase.queries.dashboards-db))))
(testing "files in a test source tree are exempt even when the namespace name doesn't look like a test"
- (is (empty? (lint-query-call '(t2/update! :model/User 1 {:sso_source nil}) 'metabase.sso.test-helpers
+ (is (empty? (lint-query-call '(t2/update! :model/User :id 1 {:sso_source nil}) 'metabase.sso.test-helpers
"test/metabase/sso/test_helpers.clj")))
(is (empty? (lint-query-call '(t2/select :model/Card) 'metabase-enterprise.remote-sync.test-helpers
"/repo/enterprise/backend/test/metabase_enterprise/remote_sync/test_helpers.clj"))))
@@ -333,3 +334,79 @@
(testing "an expression entry built the same way is still reported"
(is (=? [{:message #"`v`.*"}]
(lint-query-call '(t2/query (assoc q :select [[v :label]])) 'metabase.foo.db)))))
+
+(defn- implicit-pk-findings [form]
+ (filter #(= :metabase/t2-implicit-pk (:type %))
+ (lint-query-call form 'metabase.foo.db)))
+
+(deftest ^:parallel t2-implicit-pk-test
+ (testing "a bare primary key is reported, wherever the model sits in the arglist"
+ (are [form] (=? [{:message #"Pass the primary key as `:id id`.*"}] (implicit-pk-findings form))
+ '(t2/select-one :model/Card id)
+ '(t2/select :model/Card id)
+ '(t2/select-one [:model/Card :name] id)
+ '(t2/exists? :model/Card id)
+ '(t2/count :model/Card id)
+ '(t2/delete! :model/Card id)
+ '(t2/update! :model/Card id {:name "x"})
+ '(t2/select-one-fn :name :model/Card id)
+ '(t2/select-fn-set :name :model/Card id)
+ '(t2/select-fn->fn :id :name :model/Card id)
+ '(toucan2.core/select-one :model/Card id)))
+ (testing "a number or a call is a primary key too"
+ (is (=? [{:message #".*`:id 1`.*"}] (implicit-pk-findings '(t2/select-one :model/Card 1))))
+ (is (=? [{:message #".*`:id \(query-id q\)`.*"}]
+ (implicit-pk-findings '(t2/select-one :model/Card (query-id q)))))
+ (is (=? [{:message #".*`:id \(u/the-id card\)`.*"}]
+ (implicit-pk-findings '(t2/select-one :model/Card (u/the-id card))))))
+ (testing "a model whose primary key is not :id gets its own column in the message"
+ (is (=? [{:message #".*`:table_id table-id`.*"}]
+ (implicit-pk-findings '(t2/update! :model/TableUserSettings table-id {:x 1}))))
+ (is (=? [{:message #".*`:action_id action-id`.*"}]
+ (implicit-pk-findings '(t2/select-one :model/QueryAction action-id)))))
+ (testing "a model that is not a literal keyword gets :toucan/pk, which matches on that model's own primary key"
+ (is (=? [{:message #".*`:toucan/pk id`.*"}] (implicit-pk-findings '(t2/delete! model id))))
+ (is (=? [{:message #".*`:toucan/pk pk`.*"}] (implicit-pk-findings '(t2/update! (:model entity) pk changes)))))
+ (testing "a value that could be a string is reported, since Toucan reads a bare string as a query"
+ (are [form] (=? [{:type :metabase/t2-implicit-pk}] (implicit-pk-findings form))
+ '(t2/select :model/Card (str "SELECT * FROM report_card WHERE name = '" n "'"))
+ ;; a fn named for a query could still return SQL
+ '(t2/select :metadata/table (metadata-where :metadata/table db-id spec))
+ '(t2/select :model/Exploration (my-explorations-query user-id limit offset))
+ ;; threaded or branching forms return a map only when every way out of them is one
+ '(t2/select :model/Card (cond-> q flag (assoc :where w)))
+ '(t2/select :model/Card (-> (base-query) (sql.helpers/where w)))
+ '(t2/count :model/Card (or (run-where filters) {}))
+ '(t2/select :model/Card (if flag {:where w} q))
+ '(t2/select :model/Card (merge base extra))
+ ;; only the real `h2x/assert-map-or-nil!` counts, not any fn of that name
+ '(t2/select :model/Card (my.ns/assert-map-or-nil! q))
+ ;; a map literal inside a call is no proof the call returns a map
+ '(t2/select-one :model/Card (t2/insert-returning-pk! :model/Card {:name "x"}))))
+ (testing "an explicit primary key, or a query written in place, is fine"
+ (are [form] (empty? (implicit-pk-findings form))
+ '(t2/select-one :model/Card :id id)
+ '(t2/select-one :model/Card :toucan/pk id)
+ '(t2/select-one :model/Card)
+ '(t2/select :model/Card {:where [:= :id id]})
+ '(t2/select :model/Card :named-query)
+ '(t2/select :model/Card "SELECT * FROM report_card")
+ '(t2/select :model/Card ["SELECT * FROM report_card WHERE id = ?" id])
+ '(t2/select :model/Card nil)
+ '(t2/select :model/Card (t2.identity-query/identity-query rows))
+ ;; `h2x/assert-map-or-nil!` throws for anything but a map, so its result can't be a string
+ '(t2/select :metadata/table (metabase.util.honey-sql-2/assert-map-or-nil! (metadata-where :metadata/table db-id spec)))
+ '(t2/update! :model/X (metabase.util.honey-sql-2/assert-map-or-nil! conditions) {:x 1})
+ ;; forms that can only yield a map
+ '(t2/select :model/Card (cond-> {} where (assoc :where where)))
+ '(t2/select :model/Card (m/assoc-some {} :where where))
+ '(t2/select :model/Card (assoc q :limit 1))
+ '(t2/update! :model/Session (cond-> (assoc conditions :ended_at nil) flag (update :id f)) {:x 1})
+ '(t2/select :model/Card (merge base {:limit 1}))
+ '(t2/select :model/Card (if flag {:where w} {}))
+ '(t2/select :model/Card (when flag {:where w}))
+ '(t2/update! :model/Card {:name "x"})
+ '(t2/update! :model/Card :id id {:name "x"})
+ '(t2/update! :model/Card {:collection_id coll-id} {:name "x"})
+ '(t2/insert! :model/Card card)
+ '(t2/select-one-fn :name :model/Card :id id))))
diff --git a/dev/src/dev/api/prototype.clj b/dev/src/dev/api/prototype.clj
index 32a30d284a0..feb6f8a2926 100644
--- a/dev/src/dev/api/prototype.clj
+++ b/dev/src/dev/api/prototype.clj
@@ -81,7 +81,7 @@
[:id ms/PositiveInt]]
_query-params
body]
- (t2/update! (prototype-table) id
+ (t2/update! (prototype-table) :id id
{:type type
:content (json/encode body)})
(assoc body :id id))
@@ -93,7 +93,7 @@
[:id ms/PositiveInt]]
_query-params
body]
- (api/check-404 (t2/delete! (prototype-table) id))
+ (api/check-404 (t2/delete! (prototype-table) :id id))
{:id id})
(api.macros/defendpoint :delete "/:type/all"
diff --git a/dev/src/dev/debug_qp/bulk_compile_cards.clj b/dev/src/dev/debug_qp/bulk_compile_cards.clj
index 8dd19aa05ee..4f0c274b544 100644
--- a/dev/src/dev/debug_qp/bulk_compile_cards.clj
+++ b/dev/src/dev/debug_qp/bulk_compile_cards.clj
@@ -35,7 +35,7 @@
(.submit pool ^Callable
(fn []
(try
- (let [card-query (t2/select-one-fn :dataset_query :model/Card card-id)
+ (let [card-query (t2/select-one-fn :dataset_query :model/Card :id card-id)
{:keys [query params error]} (try
(qp.compile/compile card-query)
(catch Throwable e
diff --git a/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj b/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj
index 9e9ba0d51c3..47969331f24 100644
--- a/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj
@@ -61,7 +61,7 @@
"Apply `changes` to the User with `user-id`."
[user-id :- ::lib.schema.id/user
changes :- ::users.schema/user.update]
- (t2/update! :model/User user-id changes))
+ (t2/update! :model/User :id user-id changes))
(mu/defn sample-database-exists?
"Whether the sample Database exists."
@@ -87,9 +87,9 @@
"Apply `changes` to the Database with `database-id`."
[database-id :- ::lib.schema.id/database
changes :- ::warehouses.schema/database.update]
- (t2/update! :model/Database database-id changes))
+ (t2/update! :model/Database :id database-id changes))
(mu/defn delete-database!
"Delete the Database with `database-id`."
[database-id :- ::lib.schema.id/database]
- (t2/delete! :model/Database database-id))
+ (t2/delete! :model/Database :id database-id))
diff --git a/enterprise/backend/src/metabase_enterprise/audit_app/db.clj b/enterprise/backend/src/metabase_enterprise/audit_app/db.clj
index 44df390d9e1..ce59d6c9584 100644
--- a/enterprise/backend/src/metabase_enterprise/audit_app/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/audit_app/db.clj
@@ -36,7 +36,7 @@
"Set the engine of the Database with `database-id`."
[database-id :- ::lib.schema.id/database
engine :- :string]
- (t2/update! :model/Database database-id {:engine engine}))
+ (t2/update! :model/Database :id database-id {:engine engine}))
(mu/defn delete-database!
"Delete the Database with `database-id`."
@@ -157,12 +157,12 @@
"Apply `changes` to the Table with `table-id`."
[table-id :- ::lib.schema.id/table
changes :- (mut/select-keys ::warehouse-schema.schema/table.update [:active :name :schema :is_defective_duplicate])]
- (t2/update! :model/Table table-id changes))
+ (t2/update! :model/Table :id table-id changes))
(mu/defn delete-table!
"Delete the Table with `table-id`."
[table-id :- ::lib.schema.id/table]
- (t2/delete! :model/Table table-id))
+ (t2/delete! :model/Table :id table-id))
(mu/defn field-names-of-table
"The `:id` and `:name` of the Fields of the Table with `table-id`."
@@ -190,7 +190,7 @@
"Apply `changes` to the Card with `card-id`."
[card-id :- ::lib.schema.id/card
changes :- (mut/select-keys ::queries.schema/card.update [:dataset_query :result_metadata])]
- (t2/update! :model/Card card-id changes))
+ (t2/update! :model/Card :id card-id changes))
(mu/defn first-superuser
"The `:id` and `:email` of the oldest superuser, or nil."
diff --git a/enterprise/backend/src/metabase_enterprise/content_verification/db.clj b/enterprise/backend/src/metabase_enterprise/content_verification/db.clj
index 4fbc10067db..00f4d8b9f11 100644
--- a/enterprise/backend/src/metabase_enterprise/content_verification/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/content_verification/db.clj
@@ -9,9 +9,9 @@
(mu/defn card-exists?
"Whether a Card with `id` exists."
[id :- ::lib.schema.id/card]
- (t2/exists? :model/Card id))
+ (t2/exists? :model/Card :id id))
(mu/defn dashboard-exists?
"Whether a Dashboard with `id` exists."
[id :- ::lib.schema.id/dashboard]
- (t2/exists? :model/Dashboard id))
+ (t2/exists? :model/Dashboard :id id))
diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.clj
index 2c149b59f8c..d670e11f60d 100644
--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/db.clj
@@ -57,7 +57,7 @@
"Apply `changes` to the CustomVizPlugin with `plugin-id`, returning the number updated."
[plugin-id :- ms/PositiveInt
changes :- ::custom-viz-plugin.schema/custom-viz-plugin.update]
- (t2/update! :model/CustomVizPlugin plugin-id changes))
+ (t2/update! :model/CustomVizPlugin :id plugin-id changes))
(mu/defn delete-plugin!
"Delete the CustomVizPlugin with `plugin-id`, returning the number deleted."
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/db.clj b/enterprise/backend/src/metabase_enterprise/dependencies/db.clj
index 767f0c2597b..fa0637c04b1 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/db.clj
@@ -1103,8 +1103,8 @@
`updated_at`."
[card-id :- ::lib.schema.id/card
result-metadata :- [:maybe ::lib.schema.metadata/card.result-metadata]]
- (t2/update! :model/Card card-id {:result_metadata result-metadata
- :updated_at :updated_at}))
+ (t2/update! :model/Card :id card-id {:result_metadata result-metadata
+ :updated_at :updated_at}))
;;; ------------------------------------------- Analysis finding job -------------------------------------------
diff --git a/enterprise/backend/src/metabase_enterprise/gsheets/db.clj b/enterprise/backend/src/metabase_enterprise/gsheets/db.clj
index 478e7ce6d4c..5ad79512225 100644
--- a/enterprise/backend/src/metabase_enterprise/gsheets/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/gsheets/db.clj
@@ -26,4 +26,4 @@
"Apply `changes` to the Database with `database-id`, returning the number updated."
[database-id :- ::lib.schema.id/database
changes :- ::warehouses.schema/database.update]
- (t2/update! :model/Database database-id changes))
+ (t2/update! :model/Database :id database-id changes))
diff --git a/enterprise/backend/src/metabase_enterprise/metabot/db.clj b/enterprise/backend/src/metabase_enterprise/metabot/db.clj
index 514e0cdf9a8..16833d972ae 100644
--- a/enterprise/backend/src/metabase_enterprise/metabot/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/metabot/db.clj
@@ -94,7 +94,7 @@
"Set the maximum usage of the MetabotGroupLimit with `limit-id`."
[limit-id :- ms/PositiveInt
max-usage :- [:maybe :int]]
- (t2/update! :model/MetabotGroupLimit limit-id {:max_usage max-usage}))
+ (t2/update! :model/MetabotGroupLimit :id limit-id {:max_usage max-usage}))
(mu/defn delete-group-limit!
"Delete the MetabotGroupLimit of the group with `group-id`."
@@ -123,7 +123,7 @@
"Set the maximum usage of the MetabotInstanceLimit with `limit-id`."
[limit-id :- ms/PositiveInt
max-usage :- [:maybe :int]]
- (t2/update! :model/MetabotInstanceLimit limit-id {:max_usage max-usage}))
+ (t2/update! :model/MetabotInstanceLimit :id limit-id {:max_usage max-usage}))
(mu/defn delete-instance-limit!
"Delete the MetabotInstanceLimit of the Tenant with `tenant-id`."
diff --git a/enterprise/backend/src/metabase_enterprise/mfa/db.clj b/enterprise/backend/src/metabase_enterprise/mfa/db.clj
index 8e9981cb6d7..f4d011bc094 100644
--- a/enterprise/backend/src/metabase_enterprise/mfa/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/mfa/db.clj
@@ -108,7 +108,7 @@
"Apply `changes` to the AuthIdentity with `auth-identity-id`, returning the number updated."
[auth-identity-id :- ms/PositiveInt
changes :- (mut/select-keys ::auth-identity.schema/auth-identity.update [:credentials :confirmed_at])]
- (t2/update! :model/AuthIdentity auth-identity-id changes))
+ (t2/update! :model/AuthIdentity :id auth-identity-id changes))
(mu/defn delete-totp-identity!
"Delete the TOTP AuthIdentity of the User with `user-id`, returning the number deleted."
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj
index a1b4b2d624b..c789f59b50c 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj
@@ -678,7 +678,7 @@
"Apply `changes` to the RemoteSyncObject with `rso-id`."
[rso-id :- ms/PositiveInt
changes :- ::remote-sync.schema/remote-sync-object.update]
- (t2/update! :model/RemoteSyncObject rso-id changes))
+ (t2/update! :model/RemoteSyncObject :id rso-id changes))
(mu/defn set-rsos-status!
"Set the status of the RemoteSyncObjects with `rso-ids` to `status` as of `timestamp`."
@@ -722,7 +722,7 @@
(mu/defn delete-rso!
"Delete the RemoteSyncObject with `rso-id`."
[rso-id :- ms/PositiveInt]
- (t2/delete! :model/RemoteSyncObject rso-id))
+ (t2/delete! :model/RemoteSyncObject :id rso-id))
(mu/defn delete-rsos!
"Delete the RemoteSyncObjects with `rso-ids`."
@@ -821,19 +821,19 @@
"Apply `changes` to the RemoteSyncTask with `task-id`."
[task-id :- ms/PositiveInt
changes :- ::remote-sync.schema/remote-sync-task.update]
- (t2/update! :model/RemoteSyncTask task-id changes))
+ (t2/update! :model/RemoteSyncTask :id task-id changes))
(mu/defn end-task!
"Apply `changes` to the RemoteSyncTask with `task-id` and mark it ended now."
[task-id :- ms/PositiveInt
changes :- ::remote-sync.schema/remote-sync-task.update]
- (t2/update! :model/RemoteSyncTask task-id (assoc changes :ended_at :%now)))
+ (t2/update! :model/RemoteSyncTask :id task-id (assoc changes :ended_at :%now)))
(mu/defn report-task-progress!
"Record `progress` for the RemoteSyncTask with `task-id`, stamping the progress report time."
[task-id :- ms/PositiveInt
progress :- number?]
- (t2/update! :model/RemoteSyncTask task-id {:progress progress, :last_progress_report_at :%now}))
+ (t2/update! :model/RemoteSyncTask :id task-id {:progress progress, :last_progress_report_at :%now}))
(mu/defn touch-task!
"Stamp the heartbeat time of the RemoteSyncTask with `task-id` if it has not ended, returning the number of rows
diff --git a/enterprise/backend/src/metabase_enterprise/replacement/db.clj b/enterprise/backend/src/metabase_enterprise/replacement/db.clj
index a657fc412e2..cb862373104 100644
--- a/enterprise/backend/src/metabase_enterprise/replacement/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/replacement/db.clj
@@ -122,7 +122,7 @@
"Apply `changes` to the Card with `card-id`, returning the number updated."
[card-id :- ::lib.schema.id/card
changes :- ::queries.schema/card.update]
- (t2/update! :model/Card card-id changes))
+ (t2/update! :model/Card :id card-id changes))
(mu/defn transform
"The Transform with `transform-id`, or nil."
@@ -133,7 +133,7 @@
"Apply `changes` to the Transform with `transform-id`, returning the number updated."
[transform-id :- ::lib.schema.id/transform
changes :- ::transforms.schema/transform.update]
- (t2/update! :model/Transform transform-id changes))
+ (t2/update! :model/Transform :id transform-id changes))
(mu/defn segment
"The Segment with `segment-id`, or nil."
@@ -144,7 +144,7 @@
"Apply `changes` to the Segment with `segment-id`, returning the number updated."
[segment-id :- ::lib.schema.id/segment
changes :- ::segments.schema/segment.update]
- (t2/update! :model/Segment segment-id changes))
+ (t2/update! :model/Segment :id segment-id changes))
(mu/defn measure
"The Measure with `measure-id`, or nil."
@@ -155,7 +155,7 @@
"Apply `changes` to the Measure with `measure-id`, returning the number updated."
[measure-id :- ::lib.schema.id/measure
changes :- ::measures.schema/measure.update]
- (t2/update! :model/Measure measure-id changes))
+ (t2/update! :model/Measure :id measure-id changes))
(mu/defn dashboard
"The Dashboard with `dashboard-id`, or nil."
@@ -166,7 +166,7 @@
"Apply `changes` to the Dashboard with `dashboard-id`, returning the number updated."
[dashboard-id :- ::lib.schema.id/dashboard
changes :- ::dashboards.schema/dashboard.update]
- (t2/update! :model/Dashboard dashboard-id changes))
+ (t2/update! :model/Dashboard :id dashboard-id changes))
(mu/defn dashboard-cards
"The DashboardCards of the Dashboard with `dashboard-id`."
@@ -177,7 +177,7 @@
"Apply `changes` to the DashboardCard with `dashcard-id`, returning the number updated."
[dashcard-id :- ::lib.schema.id/dashcard
changes :- ::dashboards.schema/dashboard-card.update]
- (t2/update! :model/DashboardCard dashcard-id changes))
+ (t2/update! :model/DashboardCard :id dashcard-id changes))
(mu/defn table-database-id
"The Database ID of the Table with `table-id`."
diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/db.clj b/enterprise/backend/src/metabase_enterprise/sandbox/db.clj
index 5e5318edc56..042213cbed0 100644
--- a/enterprise/backend/src/metabase_enterprise/sandbox/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/sandbox/db.clj
@@ -103,7 +103,7 @@
"Apply `changes` to the Sandbox with `sandbox-id`, returning the number updated."
[sandbox-id :- ::lib.schema.id/sandbox
changes :- (mut/select-keys ::sandbox.schema/sandbox.update [:card_id :attribute_remappings])]
- (t2/update! :model/Sandbox sandbox-id changes))
+ (t2/update! :model/Sandbox :id sandbox-id changes))
(mu/defn delete-sandbox!
"Delete the Sandbox with `sandbox-id`, returning the number deleted."
@@ -134,7 +134,7 @@
"Set the login attributes of the User with `user-id`, returning the number of rows updated."
[user-id :- ::lib.schema.id/user
login-attributes :- [:maybe users.schema/LoginAttributes]]
- (t2/update! :model/User user-id {:login_attributes login-attributes}))
+ (t2/update! :model/User :id user-id {:login_attributes login-attributes}))
(mu/defn user-attributes-reducible
"Reducible merged JWT and login attribute maps of the Users that have any."
@@ -213,4 +213,4 @@
"Set the result metadata of the Card with `card-id`, returning the number updated."
[card-id :- ::lib.schema.id/card
result-metadata :- [:maybe ::queries.schema/card.result-metadata]]
- (t2/update! :model/Card card-id {:result_metadata result-metadata}))
+ (t2/update! :model/Card :id card-id {:result_metadata result-metadata}))
diff --git a/enterprise/backend/src/metabase_enterprise/scim/db.clj b/enterprise/backend/src/metabase_enterprise/scim/db.clj
index d777e3b383b..c51e6d2152a 100644
--- a/enterprise/backend/src/metabase_enterprise/scim/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/scim/db.clj
@@ -86,7 +86,7 @@
"Apply `changes` to the User with `user-id`, returning the number updated."
[user-id :- ::lib.schema.id/user
changes :- ::users.schema/user.update]
- (t2/update! :model/User user-id changes))
+ (t2/update! :model/User :id user-id changes))
(mu/defn user-group-memberships
"Rows of User ID, group name, and group entity ID for the memberships of the Users with `user-ids`, excluding the
@@ -145,12 +145,12 @@
"Apply `changes` to the PermissionsGroup with `group-id`, returning the number updated."
[group-id :- ms/PositiveInt
changes :- (mut/select-keys ::permissions.schema/permissions-group.update [:name :entity_id :magic_group_type :is_tenant_group])]
- (t2/update! :model/PermissionsGroup group-id changes))
+ (t2/update! :model/PermissionsGroup :id group-id changes))
(mu/defn delete-group!
"Delete the PermissionsGroup with `group-id`, returning the number deleted."
[group-id :- ms/PositiveInt]
- (t2/delete! :model/PermissionsGroup group-id))
+ (t2/delete! :model/PermissionsGroup :id group-id))
(mu/defn group-member-user-ids
"The user IDs of the members of the PermissionsGroup with `group-id`."
diff --git a/enterprise/backend/src/metabase_enterprise/security_center/db.clj b/enterprise/backend/src/metabase_enterprise/security_center/db.clj
index a4bf059c3c1..b63813b02eb 100644
--- a/enterprise/backend/src/metabase_enterprise/security_center/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/security_center/db.clj
@@ -55,19 +55,19 @@
"Apply `changes` to the SecurityAdvisory with `id`, returning the number updated."
[id :- ms/PositiveInt
changes :- (mut/select-keys ::security-center.schema/security-advisory.update [:match_status :last_evaluated_at :acknowledged_by :acknowledged_at :last_notified_at])]
- (t2/update! :model/SecurityAdvisory id changes))
+ (t2/update! :model/SecurityAdvisory :id id changes))
(mu/defn record-advisory-evaluation!
"Apply `changes` to the SecurityAdvisory with `id` and stamp `last_evaluated_at` with now, returning the number
updated."
[id :- ms/PositiveInt
changes :- (mut/select-keys ::security-center.schema/security-advisory.update [:match_status :acknowledged_by :acknowledged_at])]
- (t2/update! :model/SecurityAdvisory id (assoc changes :last_evaluated_at :%now)))
+ (t2/update! :model/SecurityAdvisory :id id (assoc changes :last_evaluated_at :%now)))
(mu/defn record-advisory-notification!
"Set `last_notified_at` of the SecurityAdvisory with `id` to now, returning the number updated."
[id :- ms/PositiveInt]
- (t2/update! :model/SecurityAdvisory id {:last_notified_at :%now}))
+ (t2/update! :model/SecurityAdvisory :id id {:last_notified_at :%now}))
(mu/defn upsert-advisory!
"Insert or update a SecurityAdvisory by `:advisory_id`. On insert, `:match_status` starts as `:unknown` until the
diff --git a/enterprise/backend/src/metabase_enterprise/support_access_grants/db.clj b/enterprise/backend/src/metabase_enterprise/support_access_grants/db.clj
index e52cf47bde5..74156f519dc 100644
--- a/enterprise/backend/src/metabase_enterprise/support_access_grants/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/support_access_grants/db.clj
@@ -73,7 +73,7 @@
"Apply `changes` to the SupportAccessGrantLog with `grant-id`, returning the number updated."
[grant-id :- ms/PositiveInt
changes :- (mut/select-keys ::support-access-grants.schema/support-access-grant-log.update [:revoked_at :revoked_by_user_id])]
- (t2/update! :model/SupportAccessGrantLog grant-id changes))
+ (t2/update! :model/SupportAccessGrantLog :id grant-id changes))
(mu/defn user
"The User with `user-id`, or nil."
@@ -104,7 +104,7 @@
"Apply `changes` to the User with `user-id`, returning the number updated."
[user-id :- ::lib.schema.id/user
changes :- (mut/select-keys ::users.schema/user.update [:is_active :is_superuser])]
- (t2/update! :model/User user-id changes))
+ (t2/update! :model/User :id user-id changes))
(mu/defn unended-session-exists-for-user?
"Whether the User with `user-id` has a Session whose ending has not been recorded."
@@ -155,7 +155,7 @@
[:map {:closed true}
[:user_agent {:optional true} [:maybe :string]]
[:timestamp {:optional true} [:or ms/TemporalInstant :string]]]]]]]]]
- (t2/update! :model/AuthIdentity auth-identity-id changes))
+ (t2/update! :model/AuthIdentity :id auth-identity-id changes))
(mu/defn expire-auth-identities!
"Set the expiry of the AuthIdentities with `auth-identity-ids` to `expires-at`, returning the number updated."
diff --git a/enterprise/backend/src/metabase_enterprise/transform_testing/db.clj b/enterprise/backend/src/metabase_enterprise/transform_testing/db.clj
index d99a8ef622f..7add856c762 100644
--- a/enterprise/backend/src/metabase_enterprise/transform_testing/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/transform_testing/db.clj
@@ -100,7 +100,7 @@
"Apply `updates` to the TransformTest with `id`."
[id :- ms/PositiveInt
updates :- ::transform-testing.schema/transform-test.update]
- (t2/update! :model/TransformTest id updates))
+ (t2/update! :model/TransformTest :id id updates))
(mu/defn delete-transform-test!
"Delete the TransformTest with `id`."
diff --git a/enterprise/backend/src/metabase_enterprise/transforms/db.clj b/enterprise/backend/src/metabase_enterprise/transforms/db.clj
index b33a46dd569..c64dfa2e18d 100644
--- a/enterprise/backend/src/metabase_enterprise/transforms/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/transforms/db.clj
@@ -12,7 +12,7 @@
number updated."
[transform-id :- ::lib.schema.id/transform
dependencies-json :- :string]
- (t2/update! (t2/table-name :model/Transform) transform-id {:table_dependencies dependencies-json}))
+ (t2/update! (t2/table-name :model/Transform) :id transform-id {:table_dependencies dependencies-json}))
(mu/defn succeeded-run-counts-by-meter
"Rows of `:metered_as` and `:cnt` of the TransformRuns that succeeded on `date`."
diff --git a/enterprise/backend/test/metabase/notification/payload/execute_ee_test.clj b/enterprise/backend/test/metabase/notification/payload/execute_ee_test.clj
index db3d0e07e68..87d94cd7048 100644
--- a/enterprise/backend/test/metabase/notification/payload/execute_ee_test.clj
+++ b/enterprise/backend/test/metabase/notification/payload/execute_ee_test.clj
@@ -116,7 +116,7 @@
(is (= 1 (t2/count :model/QueryCache))
"The query should have been cached exactly once")))
(let [first-updated-at (cache-updated-at)]
- (t2/update! :model/Card card-id {:visualization_settings edited-setting})
+ (t2/update! :model/Card :id card-id {:visualization_settings edited-setting})
(testing "after card edit, cache-hit run reflects the two-column setting"
(let [result (run-sub!)]
(is (= 1 (t2/count :model/QueryCache))
diff --git a/enterprise/backend/test/metabase_enterprise/action_v2/api_test.clj b/enterprise/backend/test/metabase_enterprise/action_v2/api_test.clj
index a825ac17e4a..fc3b7f2fda0 100644
--- a/enterprise/backend/test/metabase_enterprise/action_v2/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/action_v2/api_test.clj
@@ -444,12 +444,12 @@
(action-v2.tu/with-test-tables! [table-id [{:id 'auto-inc-type
:o [t :null]}
{:primary-key [:id]}]]
- (let [table-name-kw (t2/select-one-fn (comp keyword :name) [:model/Table :name] table-id)
+ (let [table-name-kw (t2/select-one-fn (comp keyword :name) [:model/Table :name] :id table-id)
field-id (t2/select-one-fn :id [:model/Field :id] :table_id table-id :name "o")
driver driver/*driver*
get-qp-state (fn [] (map #(zipmap [:id :o] %) (table-rows table-id)))
get-db-state (fn [] (sql-jdbc/query driver (lib.metadata/database (mt/metadata-provider)) {:select [:*] :from [table-name-kw]}))]
- (t2/update! :model/Field field-id {:coercion_strategy coercion-strategy})
+ (t2/update! :model/Field :id field-id {:coercion_strategy coercion-strategy})
(testing "create"
(let [row {:o input}
{outputs :outputs} (action-v2.tu/create-rows! table-id [row])
diff --git a/enterprise/backend/test/metabase_enterprise/action_v2/test_util.clj b/enterprise/backend/test/metabase_enterprise/action_v2/test_util.clj
index a906fb06020..5a863c009ca 100644
--- a/enterprise/backend/test/metabase_enterprise/action_v2/test_util.clj
+++ b/enterprise/backend/test/metabase_enterprise/action_v2/test_util.clj
@@ -68,8 +68,8 @@
(sync-new-table! db table-name)))
(defn toggle-data-editing-enabled! [db-id on-or-off]
- (let [current-settings (t2/select-one-fn :settings :model/Database db-id)]
- (t2/update! :model/Database db-id {:settings (assoc current-settings :database-enable-table-editing (boolean on-or-off))})))
+ (let [current-settings (t2/select-one-fn :settings :model/Database :id db-id)]
+ (t2/update! :model/Database :id db-id {:settings (assoc current-settings :database-enable-table-editing (boolean on-or-off))})))
(defmacro with-data-editing-enabled! [on-or-off & body]
`(mt/with-temp-vals-in-db :model/Database (mt/id) {:settings {:database-enable-table-editing ~on-or-off}}
@@ -85,7 +85,7 @@
(defn do-with-test-tables!
"Impl of [[with-test-tables!]]."
[[column-map create-table-opts] thunk]
- (let [db (t2/select-one :model/Database (mt/id))
+ (let [db (t2/select-one :model/Database :id (mt/id))
driver (:engine db)
auto-inc-type (driver/upload-type->database-type driver :metabase.upload/auto-incrementing-int-pk)
column-map (walk/postwalk-replace {'auto-inc-type auto-inc-type} column-map)
diff --git a/enterprise/backend/test/metabase_enterprise/advanced_config/models/notification_test.clj b/enterprise/backend/test/metabase_enterprise/advanced_config/models/notification_test.clj
index 4284632ee04..c6cef99b8a1 100644
--- a/enterprise/backend/test/metabase_enterprise/advanced_config/models/notification_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/advanced_config/models/notification_test.clj
@@ -37,7 +37,7 @@
:update
#(mt/with-temp [:model/PulseChannel {pulse-channel-id :id} {:pulse_id pulse-id}]
- (t2/update! :model/PulseChannel pulse-channel-id {:details {:emails emails}})))]
+ (t2/update! :model/PulseChannel :id pulse-channel-id {:details {:emails emails}})))]
(if fail?
(testing "should fail"
(is (thrown-with-msg?
diff --git a/enterprise/backend/test/metabase_enterprise/advanced_permissions/models/permissions/block_permissions_test.clj b/enterprise/backend/test/metabase_enterprise/advanced_permissions/models/permissions/block_permissions_test.clj
index 4a8d075e977..80cb56ee0eb 100644
--- a/enterprise/backend/test/metabase_enterprise/advanced_permissions/models/permissions/block_permissions_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/advanced_permissions/models/permissions/block_permissions_test.clj
@@ -429,7 +429,7 @@
(is (= [[1]]
(mt/rows (mt/user-http-request :rasta :post 202 (format "card/%d/query" card-id)))))
;; block a single table on the db:
- (let [tables-in-db (map :id (:tables (t2/hydrate (t2/select-one :model/Database db-id) :tables)))
+ (let [tables-in-db (map :id (:tables (t2/hydrate (t2/select-one :model/Database :id db-id) :tables)))
table-id (rand-nth tables-in-db)]
(data-perms/set-table-permissions! (perms-group/all-users) :perms/view-data {table-id :blocked}))
(is (thrown-with-msg?
diff --git a/enterprise/backend/test/metabase_enterprise/api/session_test.clj b/enterprise/backend/test/metabase_enterprise/api/session_test.clj
index 1c37fb74feb..42d324b80e4 100644
--- a/enterprise/backend/test/metabase_enterprise/api/session_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/api/session_test.clj
@@ -269,19 +269,19 @@
[:end_reason :ended_by_user_id :key_hashed]))
external-session (session! external)
internal-session (session! internal)]
- (t2/update! (t2/table-name :model/Tenant) tenant-id {:is_active false})
+ (t2/update! (t2/table-name :model/Tenant) :id tenant-id {:is_active false})
(#'session-cleanup/cleanup-sessions!)
(is (= {:end_reason "tenant-deactivated", :ended_by_user_id nil, :key_hashed nil}
(ended external-session)))
(is (nil? (:end_reason (ended internal-session)))
"a user without a tenant is unaffected")
(testing "with tenants switched off, a user with any tenant at all is not live"
- (t2/update! (t2/table-name :model/Tenant) tenant-id {:is_active true})
+ (t2/update! (t2/table-name :model/Tenant) :id tenant-id {:is_active true})
(mt/with-temporary-setting-values [use-tenants false]
;; switching tenants off deactivates their users, and that deactivation ends their sessions on the
;; spot; reactivate through the raw table and start a fresh session, so that the tenant predicate
;; is the only thing rejecting it
- (t2/update! (t2/table-name :model/User) external {:is_active true})
+ (t2/update! (t2/table-name :model/User) :id external {:is_active true})
(let [another (session! external)]
(#'session-cleanup/cleanup-sessions!)
(is (= "tenant-deactivated" (:end_reason (ended another)))))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/audit_app/api/user_test.clj b/enterprise/backend/test/metabase_enterprise/audit_app/api/user_test.clj
index 0bbb4336233..56721a39723 100644
--- a/enterprise/backend/test/metabase_enterprise/audit_app/api/user_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/audit_app/api/user_test.clj
@@ -45,7 +45,7 @@
(letfn [(describe-objects []
{:num-subscriptions (+ (t2/count :model/PulseChannelRecipient :user_id user-id)
(t2/count :model/NotificationRecipient :user_id user-id))
- :alert-archived? (t2/select-one-fn (comp not :active) :model/Notification (:id alert))
+ :alert-archived? (t2/select-one-fn (comp not :active) :model/Notification :id (:id alert))
:dashboard-subscription-archived? (t2/select-one-fn :archived :model/Pulse :id dash-sub-id)})
(api-delete-subscriptions! [request-user-name-or-id expected-status-code]
(mt/user-http-request request-user-name-or-id
diff --git a/enterprise/backend/test/metabase_enterprise/audit_app/audit_test.clj b/enterprise/backend/test/metabase_enterprise/audit_app/audit_test.clj
index 6ba2443a9ef..bb1caa47a46 100644
--- a/enterprise/backend/test/metabase_enterprise/audit_app/audit_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/audit_app/audit_test.clj
@@ -234,7 +234,7 @@
syncs (atom 0)]
(ee.audit.settings/last-analytics-views-checksum! 0)
;; any engine other than the host's takes the ::updated path
- (t2/update! :model/Database (:id audit-db) {:engine (if (= :postgres (mdb/db-type)) "h2" "postgres")})
+ (t2/update! :model/Database :id (:id audit-db) {:engine (if (= :postgres (mdb/db-type)) "h2" "postgres")})
(mt/with-dynamic-fn-redefs [ee-audit/views-checksum (constantly 12345)
sync.core/sync-database! (fn [& _] (swap! syncs inc))]
(is (= ::ee-audit/updated (#'ee-audit/maybe-install-audit-db!)))
@@ -346,7 +346,7 @@
:query {:source-table orig-id}}}]
(testing "precondition: an interrupted host-adjust + schema sync duplicates the view row"
;; flip the schema to a value the host driver will not report, so the sync diff mismatches
- (t2/update! :model/Table orig-id {:schema (if (nil? (:schema v-content)) "public" nil)})
+ (t2/update! :model/Table :id orig-id {:schema (if (nil? (:schema v-content)) "public" nil)})
(sync/sync-database! (:id (t2/select-one :model/Database :is_audit true)) {:scan :schema})
(is (= 2 (t2/count :model/Table :db_id audit/audit-db-id :name (:name v-content)))
"stale-schema sync should produce a duplicate pair")
@@ -384,7 +384,7 @@
:table_id orig-id
:dataset_query {:database audit/audit-db-id :type :query :query {:source-table orig-id}}}]
(testing "precondition: a real Mode A duplicate pair, customer card on the new/active row"
- (t2/update! :model/Table orig-id {:schema (if (nil? (:schema v-content)) "public" nil)})
+ (t2/update! :model/Table :id orig-id {:schema (if (nil? (:schema v-content)) "public" nil)})
(sync/sync-database! (:id (t2/select-one :model/Database :is_audit true)) {:scan :schema})
(let [rows (t2/select [:model/Table :id :active] :db_id audit/audit-db-id
{:where [:= [:lower :name] "v_content"]})
diff --git a/enterprise/backend/test/metabase_enterprise/audit_app/permissions_test.clj b/enterprise/backend/test/metabase_enterprise/audit_app/permissions_test.clj
index f9a79b9c6bb..289a121b9ff 100644
--- a/enterprise/backend/test/metabase_enterprise/audit_app/permissions_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/audit_app/permissions_test.clj
@@ -52,7 +52,7 @@
:db_id audit/audit-db-id
{:where [:in [:lower :name] audit-app.permissions/audit-db-view-names]})]
(when-not (some-> audit-view :name u/lower-case-en (str/starts-with? "v_"))
- (sync/sync-database! (:id (t2/select-one :model/Database audit/audit-db-id))))
+ (sync/sync-database! (:id (t2/select-one :model/Database :id audit/audit-db-id))))
(is (partial=
{:status :completed}
(qp/process-query
diff --git a/enterprise/backend/test/metabase_enterprise/cache/config_test.clj b/enterprise/backend/test/metabase_enterprise/cache/config_test.clj
index 63484cc49fb..36ce93eb9c0 100644
--- a/enterprise/backend/test/metabase_enterprise/cache/config_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/cache/config_test.clj
@@ -68,7 +68,7 @@
(swap! card-ids conj (:id card))
{:state :success})
(unpersist! [_ _database _persisted-info]))
- current-state! (fn [] (t2/select-one-fn :state :model/PersistedInfo (u/the-id prefreshing)))]
+ current-state! (fn [] (t2/select-one-fn :state :model/PersistedInfo :id (u/the-id prefreshing)))]
;; ensure ee path is taken
(mt/with-premium-features #{:cache-granular-controls}
(is (= "refreshing" (current-state!)))
diff --git a/enterprise/backend/test/metabase_enterprise/cache/task/refresh_cache_configs_test.clj b/enterprise/backend/test/metabase_enterprise/cache/task/refresh_cache_configs_test.clj
index 824ae34e9a2..182650ac55b 100644
--- a/enterprise/backend/test/metabase_enterprise/cache/task/refresh_cache_configs_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/cache/task/refresh_cache_configs_test.clj
@@ -684,7 +684,7 @@
(@#'task.cache/refresh-cache-configs!)
(is (= 0 @call-count))
(mt/with-additional-premium-features #{:cache-preemptive}
- (t2/update! :model/CacheConfig (:id cc) (assoc cc :next_run_at nil))
+ (t2/update! :model/CacheConfig :id (:id cc) (assoc cc :next_run_at nil))
(is (true? (premium-features/enable-preemptive-caching?)))
(@#'task.cache/refresh-cache-configs!)
(is (= 2 @call-count)))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/content_diagnostics/api_test.clj b/enterprise/backend/test/metabase_enterprise/content_diagnostics/api_test.clj
index 22bd6e14fa8..56b08cffd1f 100644
--- a/enterprise/backend/test/metabase_enterprise/content_diagnostics/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/content_diagnostics/api_test.clj
@@ -226,7 +226,7 @@
;; A partial new scan can leave two active rows. Only the newest may count.
(insert-counted-findings! :dashboard first-id [:duplicate_name])
(let [newest-stale (first (insert-counted-findings! :dashboard second-id [:stale]))]
- (t2/update! :model/ContentDiagnosticsFinding (:id newest-stale) {:invalidated_at (t/offset-date-time)}))
+ (t2/update! :model/ContentDiagnosticsFinding :id (:id newest-stale) {:invalidated_at (t/offset-date-time)}))
(is (= expected (mt/user-http-request :crowberto :get 200 "ee/content-diagnostics/counts")))
(testing "optional table filters and pagination never narrow badge populations"
(is (= expected (mt/user-http-request :crowberto :get 200 "ee/content-diagnostics/counts"
@@ -258,7 +258,7 @@
(insert-counted-findings! :dashboard id [:stale :duplicate_name :slow :empty :sparse :crowded]))
(is (= (update-vals baseline inc)
(mt/user-http-request :rasta :get 200 "ee/content-diagnostics/counts")))
- (t2/update! :model/Dashboard visible-dash {:collection_id hidden})
+ (t2/update! :model/Dashboard :id visible-dash {:collection_id hidden})
(is (= baseline (mt/user-http-request :rasta :get 200 "ee/content-diagnostics/counts")))
(perms/grant-collection-read-permissions! (perms/all-users-group) hidden)
(is (= (update-vals baseline #(+ % 2))
diff --git a/enterprise/backend/test/metabase_enterprise/content_diagnostics/duplicated_test.clj b/enterprise/backend/test/metabase_enterprise/content_diagnostics/duplicated_test.clj
index 1ff3ed909e5..ec86231861c 100644
--- a/enterprise/backend/test/metabase_enterprise/content_diagnostics/duplicated_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/content_diagnostics/duplicated_test.clj
@@ -283,7 +283,7 @@
fb (by-entity [:card card-b])]
(is (some? fa))
(is (some? fb))
- (t2/update! :model/Card card-b {:name (str prefix " Renamed Unique")})
+ (t2/update! :model/Card :id card-b {:name (str prefix " Renamed Unique")})
(scan/scan!)
(testing "both prior findings are soft-invalidated and neither entity has an active one"
(is (some? (:invalidated_at (t2/select-one :model/ContentDiagnosticsFinding :id (:id fa)))))
@@ -327,8 +327,8 @@
:model/Card {card-b :id} {:collection_id coll-id :name nm :type :model :view_count 7 :display :table}]
(scan/scan!)
;; Visualization display is live context, not frozen with the scan verdict.
- (t2/update! :model/Card card-a {:display :bar})
- (t2/update! :model/Card card-b {:display :line})
+ (t2/update! :model/Card :id card-a {:display :bar})
+ (t2/update! :model/Card :id card-b {:display :line})
(let [resp (mt/user-http-request :crowberto :get 200 "ee/content-diagnostics/duplicated"
:query prefix)
by-id (into {} (map (juxt (juxt :entity_type :entity_id) identity)) (:data resp))]
@@ -390,7 +390,7 @@
(is (contains? by-type "transform"))
(is (not (contains? (get-in by-type ["transform" :details]) :view_count))))
(testing "view_count is hydrated live at read time, not frozen at scan time"
- (t2/update! :model/Card card-id {:view_count 99})
+ (t2/update! :model/Card :id card-id {:view_count 99})
(let [card-f (some #(when (= "card" (:entity_type %)) %)
(:data (mt/user-http-request :crowberto :get 200
"ee/content-diagnostics/duplicated" :query prefix)))]
diff --git a/enterprise/backend/test/metabase_enterprise/content_diagnostics/models/finding_test.clj b/enterprise/backend/test/metabase_enterprise/content_diagnostics/models/finding_test.clj
index 38bd0f70fd5..233cd6f9ea7 100644
--- a/enterprise/backend/test/metabase_enterprise/content_diagnostics/models/finding_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/content_diagnostics/models/finding_test.clj
@@ -31,7 +31,7 @@
:invalidated_at nil}
row)))
(testing "stamping invalidated_at round-trips (the active-set filter's column)"
- (t2/update! :model/ContentDiagnosticsFinding fid {:invalidated_at (t/offset-date-time)})
+ (t2/update! :model/ContentDiagnosticsFinding :id fid {:invalidated_at (t/offset-date-time)})
(is (some? (:invalidated_at (t2/select-one :model/ContentDiagnosticsFinding :id fid))))))))
(deftest stale-threshold-setting-default-test
diff --git a/enterprise/backend/test/metabase_enterprise/content_diagnostics/scan_test.clj b/enterprise/backend/test/metabase_enterprise/content_diagnostics/scan_test.clj
index dd0498dd44d..cbc15b78c75 100644
--- a/enterprise/backend/test/metabase_enterprise/content_diagnostics/scan_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/content_diagnostics/scan_test.clj
@@ -175,7 +175,7 @@
:parameterized false :running_time 30000 :result_rows 0}]
;; the body can only be written once the copy has an id, and `collection_id` rides along
;; because the document's after-update syncs it onto every card the document owns
- (t2/update! :model/Document doc-id
+ (t2/update! :model/Document :id doc-id
{:collection_id coll-id
:document {:type "doc"
:content [{:type "cardEmbed" :attrs {:id doc-card}}]}})
@@ -279,7 +279,7 @@
:model/Card {resolved :id} {:collection_id coll-id :last_used_at (stale-instant)}
:model/Card {still :id} {:collection_id coll-id :last_used_at (stale-instant)}]
(scan/scan!) ; scan 1: both stale
- (t2/update! :model/Card resolved {:last_used_at (fresh-instant)}) ; resolved is now fresh
+ (t2/update! :model/Card :id resolved {:last_used_at (fresh-instant)}) ; resolved is now fresh
(scan/scan!) ; scan 2: only `still` is stale
(let [active (set (map :entity_id (t2/select :model/ContentDiagnosticsFinding
:entity_type :card
@@ -495,7 +495,7 @@
(testing "card has no owner column → owner is null"
(is (nil? (get-in row [:details :owner]))))))
(testing "invalidating the latest hides the entity AND drops it from total; older row does NOT resurface"
- (t2/update! :model/ContentDiagnosticsFinding new-id {:invalidated_at (t/offset-date-time)})
+ (t2/update! :model/ContentDiagnosticsFinding :id new-id {:invalidated_at (t/offset-date-time)})
(let [resp (fetch)
ids (fetched-ids resp)]
(is (not (contains? ids new-id)))
@@ -608,7 +608,7 @@
(is (contains? (fetched-ids resp) pers-fid))
(is (= 2 (:total resp)))))
(testing "exclusion is live: moving the card out of the personal collection re-surfaces it"
- (t2/update! :model/Card pers-card {:collection_id reg-id})
+ (t2/update! :model/Card :id pers-card {:collection_id reg-id})
(let [ids (fetched-ids (fetch))] ; default (exclude personal)
(is (contains? ids pers-fid)))))))))))) ; now in a regular collection → returned
diff --git a/enterprise/backend/test/metabase_enterprise/content_diagnostics/slow_test.clj b/enterprise/backend/test/metabase_enterprise/content_diagnostics/slow_test.clj
index adba1fef7b5..c22a7fedffe 100644
--- a/enterprise/backend/test/metabase_enterprise/content_diagnostics/slow_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/content_diagnostics/slow_test.clj
@@ -515,7 +515,7 @@
(is (contains? by-type "transform"))
(is (not (contains? (get-in by-type ["transform" :details]) :view_count))))
(testing "view_count is hydrated live at read time, not frozen at scan time"
- (t2/update! :model/Card card-id {:view_count 99})
+ (t2/update! :model/Card :id card-id {:view_count 99})
(let [card-f (some #(when (= "card" (:entity_type %)) %)
(:data (mt/user-http-request :crowberto :get 200
"ee/content-diagnostics/slow" :query prefix)))]
diff --git a/enterprise/backend/test/metabase_enterprise/content_verification/api/collection_test.clj b/enterprise/backend/test/metabase_enterprise/content_verification/api/collection_test.clj
index fe1421fa855..fcdacf8fb44 100644
--- a/enterprise/backend/test/metabase_enterprise/content_verification/api/collection_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/content_verification/api/collection_test.clj
@@ -29,7 +29,7 @@
(partial instance? java.time.temporal.Temporal)]]
[:type [:maybe :string]]]
resp))
- (is (= :official (t2/select-one-fn :authority_level :model/Collection (:id resp))))))
+ (is (= :official (t2/select-one-fn :authority_level :model/Collection :id (:id resp))))))
(testing "but the type has to be valid"
(mt/user-http-request :crowberto :post 400 "collection"
{:name "foo" :authority_level "invalid-type"})))
@@ -51,7 +51,7 @@
[:model/Collection {id :id} {:authority_level nil}]
(is (= "official"
(:authority_level (mt/user-http-request :crowberto :put 200 (format "collection/%d" id) {:authority_level "official"}))))
- (is (= :official (t2/select-one-fn :authority_level :model/Collection id)))))
+ (is (= :official (t2/select-one-fn :authority_level :model/Collection :id id)))))
(testing "Non-admins can patch without the :authority_level"
(mt/with-temp [:model/Collection collection {:name "whatever" :authority_level "official"}]
(is (= "official"
@@ -63,7 +63,7 @@
[:model/Collection {id :id} {:authority_level nil}]
(is (= "official"
(:authority_level (mt/user-http-request :crowberto :put 200 (format "collection/%d" id) {:authority_level "official"}))))
- (is (= :official (t2/select-one-fn :authority_level :model/Collection id)))))))
+ (is (= :official (t2/select-one-fn :authority_level :model/Collection :id id)))))))
(testing "fails to update if doesn't have any premium features"
(mt/with-premium-features #{}
(mt/with-temp
@@ -78,12 +78,12 @@
(mt/with-temp
[:model/Collection {id :id} {:authority_level "official"}]
(mt/user-http-request :crowberto :put 200 (format "collection/%d" id) {:authority_level "official" :name "New name"})
- (is (= "New name" (t2/select-one-fn :name :model/Collection id)))))
+ (is (= "New name" (t2/select-one-fn :name :model/Collection :id id)))))
(testing "authority_level is not set and update payload contains the key but does not change"
(mt/with-temp
[:model/Collection {id :id} {}]
(mt/user-http-request :crowberto :put 200 (format "collection/%d" id) {:authority_level nil :name "New name"})
- (is (= "New name" (t2/select-one-fn :name :model/Collection id))))))))
+ (is (= "New name" (t2/select-one-fn :name :model/Collection :id id))))))))
(deftest moderation-review-test
(mt/with-temp
@@ -116,7 +116,7 @@
(mt/with-temp [:model/Collection {id :id} {:authority_level "official"}]
(is (nil? (:authority_level (mt/user-http-request :crowberto :put 200 (format "collection/%d" id)
{:authority_level nil}))))
- (is (nil? (t2/select-one-fn :authority_level :model/Collection id)))))))
+ (is (nil? (t2/select-one-fn :authority_level :model/Collection :id id)))))))
(deftest non-admin-cannot-set-authority-level-test
(testing "PUT /api/collection/:id with :authority_level is rejected (403) for a non-admin"
diff --git a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin_test.clj b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin_test.clj
index 986067e1ae6..3f0fce16245 100644
--- a/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/custom_viz_plugin/models/custom_viz_plugin_test.clj
@@ -67,7 +67,7 @@
:display_name "status-test"
:status :active}]
(is (= :active (:status (t2/select-one :model/CustomVizPlugin :id id))))
- (t2/update! :model/CustomVizPlugin id {:status :error})
+ (t2/update! :model/CustomVizPlugin :id id {:status :error})
(is (= :error (:status (t2/select-one :model/CustomVizPlugin :id id)))))))
;;; ------------------------------------------------- Serialization --------------------------------------------------
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/checks_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/checks_test.clj
index 56fcef96b96..946e516d094 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/checks_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/checks_test.clj
@@ -161,7 +161,7 @@
(fn [_card-id _collection-id]
(mt/with-temp [:model/DataApp app {:name "wasps"}
:model/Card {elsewhere-id :id} {:dataset_query (data-apps.tu/venues-query)}]
- (t2/delete! :model/Collection (:resource_collection_id app))
+ (t2/delete! :model/Collection :id (:resource_collection_id app))
(testing "an app without a collection can use no card, not even one in the root collection"
(is (= (error-message :cards elsewhere-id)
(run-query 400 (card-query elsewhere-id) (as-app "wasps")))))
@@ -271,7 +271,7 @@
(mt/user-http-request :crowberto :post 400 (format "card/%d/query/csv" elsewhere-id) as-data-app))))
(testing "an app without a collection runs no card, not even one in the root collection"
(mt/with-temp [:model/DataApp app {:name "wasps"}]
- (t2/delete! :model/Collection (:resource_collection_id app))
+ (t2/delete! :model/Collection :id (:resource_collection_id app))
(is (= (card-error elsewhere-id)
(mt/user-http-request :crowberto :post 400 (format "card/%d/query" elsewhere-id) (as-app "wasps"))))))
(testing "an ID of no card is not found, as for any request"
@@ -442,7 +442,7 @@
(is (seq (:values (mt/user-http-request :crowberto :get 200 (format "card/%d/params/venue/values" card-id)
as-data-app)))))
(testing "a parameter whose values come from a card outside the app's collection is refused"
- (t2/update! :model/Card source-id {:collection_id nil})
+ (t2/update! :model/Card :id source-id {:collection_id nil})
(doseq [url ["card/%d/params/venue/values" "card/%d/params/venue/search/Red" "card/%d/params/venue/remapping?value=Red"]]
(is (= (card-error source-id)
(mt/user-http-request :crowberto :get 400 (format url card-id) as-data-app))
@@ -575,7 +575,7 @@
(do-with-rename-action!
elsewhere-collection-id
(fn [elsewhere-id]
- (t2/delete! :model/Collection (:resource_collection_id app))
+ (t2/delete! :model/Collection :id (:resource_collection_id app))
(testing "an app without a collection lists no action"
(is (= [] (mt/user-http-request :crowberto :get 200 "action" (as-app "wasps")))))
(testing "and reads or runs none"
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/csp_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/csp_test.clj
index ad21b1d8a59..46b62b604f4 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/csp_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/csp_test.clj
@@ -50,7 +50,7 @@
(mt/with-premium-features #{:data-apps}
(is (= ["https://api.example.com"] (mw.security/data-app-connect-src-hosts app-name)))
(testing "including a disabled app's, whose document only superusers reach"
- (t2/update! :model/DataApp app-id {:enabled false})
+ (t2/update! :model/DataApp :id app-id {:enabled false})
(is (= ["https://api.example.com"] (mw.security/data-app-connect-src-hosts app-name))))))
(testing "without the feature it falls back to []"
(mt/with-premium-features #{}
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj
index 7d8bad3971b..59fe34465fa 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj
@@ -249,7 +249,7 @@
(mt/with-temp [:model/DataApp app {}
:model/PermissionsGroup group {}]
(group-access/add-groups! app [(:id group)])
- (t2/update! :model/PermissionsGroup (:id group) {:is_tenant_group true})
+ (t2/update! :model/PermissionsGroup :id (:id group) {:is_tenant_group true})
(mt/user-http-request :rasta :delete 403 (data-apps.tu/app-url app "groups" (:id group)))
(is (= [(:id group)] (mapv :id (group-access/assigned-groups app))))
(mt/user-http-request :crowberto :delete 204 (data-apps.tu/app-url app "groups" (:id group)))
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/group_access_warnings_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/group_access_warnings_test.clj
index 0d8d52f68c2..b70956d439b 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/group_access_warnings_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/group_access_warnings_test.clj
@@ -115,7 +115,7 @@
(perms/set-database-permission! (:id group) (mt/id) :perms/view-data :blocked)
(group-access/add-groups! app [(:id group)])
(deps.test/synchronously-run-dependency-job!)
- (t2/update! :model/NativeQuerySnippet (:id snippet) {:content "CHECKINS"})
+ (t2/update! :model/NativeQuerySnippet :id (:id snippet) {:content "CHECKINS"})
(deps.test/synchronously-run-dependency-job!)
(is (=? [{:group_id (:id group) :missing_tables [{:id (mt/id :checkins)}]}]
(group-access/permission-warnings app))))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/invariants_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/invariants_test.clj
index b40caa8c564..446cab3da6e 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/invariants_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/invariants_test.clj
@@ -97,12 +97,12 @@
(let [action-id (insert-query-action! collection-id "Reads own" (reading-card own-id))]
(testing "changing its query to read a card outside is refused"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"can read only the app's own cards"
- (t2/update! :model/QueryAction action-id {:dataset_query (reading-card outside-id)})))))
+ (t2/update! :model/QueryAction :action_id action-id {:dataset_query (reading-card outside-id)})))))
(testing "moving an action that reads a card outside into the collection is refused"
(mt/with-temp [:model/Collection {other-id :id} {:namespace :data-actions}]
(let [action-id (insert-query-action! other-id "Moved in" (reading-card outside-id))]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"can read only the app's own cards"
- (t2/update! :model/Action action-id {:collection_id collection-id})))
+ (t2/update! :model/Action :id action-id {:collection_id collection-id})))
(is (= other-id (t2/select-one-fn :collection_id :model/Action :id action-id))))))))))))
(defn- insert-implicit-action!
@@ -160,10 +160,10 @@
(mt/with-temp [:model/Collection {other-id :id} {:namespace :data-actions}]
(let [action-id (insert-implicit-action! other-id "Elsewhere" (mt/id :venues))]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"published to the Library"
- (t2/update! :model/Action action-id {:collection_id collection-id})))
+ (t2/update! :model/Action :id action-id {:collection_id collection-id})))
(is (= other-id (t2/select-one-fn :collection_id :model/Action :id action-id)))
(data-apps.tu/with-published-tables! [(mt/id :venues)]
- (t2/update! :model/Action action-id {:collection_id collection-id})
+ (t2/update! :model/Action :id action-id {:collection_id collection-id})
(is (= collection-id (t2/select-one-fn :collection_id :model/Action :id action-id)))))))))))
(deftest two-data-apps-cannot-share-collection-test
@@ -250,8 +250,8 @@
{:location (str "/" other-id "/")}]]
(testing (pr-str changes)
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"stays a top-level collection of data apps"
- (t2/update! :model/Collection collection-id changes)))))
- (t2/update! :model/Collection collection-id {:archive_operation_id nil :is_remote_synced true :description "Birds"})
+ (t2/update! :model/Collection :id collection-id changes)))))
+ (t2/update! :model/Collection :id collection-id {:archive_operation_id nil :is_remote_synced true :description "Birds"})
(is (true? (t2/select-one-fn :is_remote_synced :model/Collection :id collection-id)))
(is (= "Birds" (t2/select-one-fn :description :model/Collection :id collection-id))))))))
@@ -273,7 +273,7 @@
(testing label
(let [action-id (insert-query-action! other-id (str "Moved " label) query columns)]
(is (thrown-with-msg? clojure.lang.ExceptionInfo message
- (t2/update! :model/Action action-id {:collection_id collection-id})))
+ (t2/update! :model/Action :id action-id {:collection_id collection-id})))
(is (= other-id (t2/select-one-fn :collection_id :model/Action :id action-id))))))))
(testing "an action of a model"
(mt/with-actions-enabled
@@ -285,7 +285,7 @@
(t2/insert! :model/QueryAction {:action_id action-id :database_id (mt/id)
:dataset_query (lib/native-query (mt/metadata-provider) "SELECT 1")})
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"goes in the model's collection"
- (t2/update! :model/Action action-id {:collection_id collection-id})))
+ (t2/update! :model/Action :id action-id {:collection_id collection-id})))
(is (= model-coll (t2/select-one-fn :collection_id :model/Action :id action-id)))))))))))
(deftest card-in-apps-collection-reads-only-published-tables-through-its-macros-test
@@ -331,10 +331,10 @@
:creator_id (mt/user->id :crowberto)
:collection_id collection-id
:dataset_query (data-apps.tu/venues-query)}))]
- (t2/update! :model/Card card-id {:name "Renamed" :description "Still venues"})
+ (t2/update! :model/Card :id card-id {:name "Renamed" :description "Still venues"})
(is (= "Renamed" (t2/select-one-fn :name :model/Card :id card-id)))
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"not VENUES"
- (t2/update! :model/Card card-id {:dataset_query (lib/limit (data-apps.tu/venues-query) 10)}))))))))
+ (t2/update! :model/Card :id card-id {:dataset_query (lib/limit (data-apps.tu/venues-query) 10)}))))))))
(deftest card-in-apps-collection-is-in-no-document-test
(testing "a card that belongs to a document elsewhere can't be in an app's collection"
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/models/data_app_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/models/data_app_test.clj
index ef9f95de157..be803cf8d9d 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/models/data_app_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/models/data_app_test.clj
@@ -19,20 +19,20 @@
(deftest bundle-hash-follows-the-bundle-test
(mt/with-temp [:model/DataApp {id :id} {:bundle bundle-bytes}]
- (let [hash #(t2/select-one-fn :bundle_hash :model/DataApp id)
+ (let [hash #(t2/select-one-fn :bundle_hash :model/DataApp :id id)
v1 (hash)]
(is (= 64 (count v1)) "the insert computes the hash from the bundle")
- (t2/update! :model/DataApp id {:display_name "Renamed"})
+ (t2/update! :model/DataApp :id id {:display_name "Renamed"})
(is (= v1 (hash)) "a change that leaves the bundle alone keeps its hash")
- (t2/update! :model/DataApp id {:display_name "Renamed"})
+ (t2/update! :model/DataApp :id id {:display_name "Renamed"})
(is (= v1 (hash)) "an update that changes nothing is a no-op")
- (t2/update! :model/DataApp id {:bundle (.getBytes "OTHER" "UTF-8")})
+ (t2/update! :model/DataApp :id id {:bundle (.getBytes "OTHER" "UTF-8")})
(is (not= v1 (hash)))
- (t2/update! :model/DataApp id {:bundle nil})
+ (t2/update! :model/DataApp :id id {:bundle nil})
(is (nil? (hash)))
(testing "the hash is never written directly"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"bundle hash is computed from its bundle"
- (t2/update! :model/DataApp id {:bundle_hash "stale"})))))))
+ (t2/update! :model/DataApp :id id {:bundle_hash "stale"})))))))
(deftest insert-requires-resource-collection-test
(testing "the API creates an app's collection, so an insert without one is refused"
@@ -44,29 +44,29 @@
(mt/with-temp [:model/Collection {other-id :id} {:name "Other" :namespace :data-apps}
:model/DataApp {id :id collection-id :resource_collection_id} {}]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"resource collection cannot be changed"
- (t2/update! :model/DataApp id {:resource_collection_id other-id})))
+ (t2/update! :model/DataApp :id id {:resource_collection_id other-id})))
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"resource collection cannot be changed"
- (t2/update! :model/DataApp id {:resource_collection_id nil})))
- (is (= collection-id (t2/select-one-fn :resource_collection_id :model/DataApp id)))
+ (t2/update! :model/DataApp :id id {:resource_collection_id nil})))
+ (is (= collection-id (t2/select-one-fn :resource_collection_id :model/DataApp :id id)))
(testing "an update that names the same collection is not a change"
- (t2/update! :model/DataApp id {:resource_collection_id collection-id :display_name "Renamed"})
- (is (= "Renamed" (t2/select-one-fn :display_name :model/DataApp id))))))
+ (t2/update! :model/DataApp :id id {:resource_collection_id collection-id :display_name "Renamed"})
+ (is (= "Renamed" (t2/select-one-fn :display_name :model/DataApp :id id))))))
(deftest app-without-collection-can-be-given-one-test
(mt/with-temp [:model/DataApp {id :id collection-id :resource_collection_id} {}
:model/DataApp {taken-id :resource_collection_id} {}
:model/Collection {other-id :id} {:namespace :data-apps}]
- (t2/delete! :model/Collection collection-id)
- (is (nil? (t2/select-one-fn :resource_collection_id :model/DataApp id)))
+ (t2/delete! :model/Collection :id collection-id)
+ (is (nil? (t2/select-one-fn :resource_collection_id :model/DataApp :id id)))
(testing "another app's collection is refused"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"already belongs to another data app"
- (t2/update! :model/DataApp id {:resource_collection_id taken-id}))))
- (t2/update! :model/DataApp id {:resource_collection_id other-id})
- (is (= other-id (t2/select-one-fn :resource_collection_id :model/DataApp id)))))
+ (t2/update! :model/DataApp :id id {:resource_collection_id taken-id}))))
+ (t2/update! :model/DataApp :id id {:resource_collection_id other-id})
+ (is (= other-id (t2/select-one-fn :resource_collection_id :model/DataApp :id id)))))
(deftest delete-removes-the-resource-collection-the-app-owns-test
(mt/with-temp [:model/DataApp {id :id collection-id :resource_collection_id} {}]
- (t2/delete! :model/DataApp id)
+ (t2/delete! :model/DataApp :id id)
(is (not (t2/exists? :model/Collection :id collection-id)))))
(deftest writes-are-normalized-and-validated-against-the-schema-test
@@ -74,11 +74,11 @@
:bundle_path "./dist/index.js"
:allowed_hosts ["https://API.example.com/"]}]
(is (=? {:display_name "M" :bundle_path "dist/index.js" :version 1 :allowed_hosts ["https://api.example.com"]}
- (t2/select-one :model/DataApp id)))
+ (t2/select-one :model/DataApp :id id)))
(testing "an update with an invalid column is refused"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"does not match schema"
- (t2/update! :model/DataApp id {:bundle_path "../escape.js"})))
- (is (= "dist/index.js" (t2/select-one-fn :bundle_path :model/DataApp id)))))
+ (t2/update! :model/DataApp :id id {:bundle_path "../escape.js"})))
+ (is (= "dist/index.js" (t2/select-one-fn :bundle_path :model/DataApp :id id)))))
(testing "an insert without a required manifest column is refused"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"does not match schema"
(t2/insert! :model/DataApp {:name "x" :bundle_path "i.js"}))))
@@ -88,7 +88,7 @@
(deftest to-json-never-includes-the-bundle-bytes-test
(mt/with-temp [:model/DataApp {id :id} {:display_name "M" :bundle bundle-bytes}]
- (let [app (t2/select-one [:model/DataApp :bundle :display_name] id)
+ (let [app (t2/select-one [:model/DataApp :bundle :display_name] :id id)
decoded (json/decode (json/encode app))]
(is (contains? app :bundle) "the instance selected with its bundle carries the raw bytes")
(is (not (contains? decoded "bundle"))
@@ -99,7 +99,7 @@
(mt/with-temp [:model/DataApp {id :id app-name :name} {:display_name "M"
:bundle bundle-bytes
:allowed_hosts ["https://api.example.com"]}]
- (is (not (contains? (t2/select-one :model/DataApp id) :bundle)))
+ (is (not (contains? (t2/select-one :model/DataApp :id id) :bundle)))
(is (= "BUNDLEBYTES" (String. ^bytes (data-apps.db/data-app-bundle id) "UTF-8")))
(testing "data-app-by-slug returns metadata without the bundle blob"
(let [app (data-apps.db/data-app-by-slug app-name)]
@@ -111,10 +111,10 @@
(mt/with-temp [:model/DataApp {without-id :id} {}
:model/DataApp {with-id :id} {:allowed_hosts ["https://a.com" "https://b.com"]}]
(testing "a row stored with NULL allowed_hosts reads back as []"
- (is (= [] (:allowed_hosts (t2/select-one :model/DataApp without-id)))))
+ (is (= [] (:allowed_hosts (t2/select-one :model/DataApp :id without-id)))))
(testing "a stored list round-trips through the JSON transform"
(is (= ["https://a.com" "https://b.com"]
- (:allowed_hosts (t2/select-one :model/DataApp with-id)))))))
+ (:allowed_hosts (t2/select-one :model/DataApp :id with-id)))))))
(deftest permissions-test
(mt/with-temp [:model/DataApp {id :id} {}]
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/search_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/search_test.clj
index 86777b05de4..d4bde3fa760 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/search_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/search_test.clj
@@ -210,5 +210,5 @@
(mt/with-premium-features #{:data-apps}
(mt/with-temp [:model/DataApp {app-id :id} {:name "sandpiper-sightings" :display_name "Shorebirds"}]
(is (contains? (found-data-apps :crowberto :models "data-app") app-id))
- (t2/delete! :model/DataApp app-id)
+ (t2/delete! :model/DataApp :id app-id)
(is (= {} (found-data-apps :crowberto :models "data-app"))))))
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/serialization_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/serialization_test.clj
index 738058af3e9..f940300fe0f 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/serialization_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/serialization_test.clj
@@ -90,7 +90,7 @@
(->> (file-seq (io/file dump-dir "collections"))
(filter #(.isFile ^java.io.File %))
(map (comp :entity_id yaml/from-file))))))
- (t2/delete! :model/DataApp (:id app))
+ (t2/delete! :model/DataApp :id (:id app))
(import! dump-dir)
(let [imported (t2/select-one :model/DataApp :entity_id (:entity_id app))]
(is (=? {:name "sales-ops"
@@ -221,7 +221,7 @@
(doseq [path ["data_app__sales_ops.yaml" "data_app__sales_ops/venues_list.yaml"
"data_app__sales_ops/rename_venue.yaml"]]
(is (.exists (io/file dump-dir "collections" "data_apps" path)) path)))
- (t2/delete! :model/DataApp app-id)
+ (t2/delete! :model/DataApp :id app-id)
(is (not (t2/exists? :model/Card :entity_id question-eid)) "deleting the app deletes its collection's cards")
(import! dump-dir)
(let [imported (t2/select-one :model/DataApp :entity_id app-entity-id)
diff --git a/enterprise/backend/test/metabase_enterprise/data_studio/api/table_test.clj b/enterprise/backend/test/metabase_enterprise/data_studio/api/table_test.clj
index 210a577da30..f4f1253548f 100644
--- a/enterprise/backend/test/metabase_enterprise/data_studio/api/table_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_studio/api/table_test.clj
@@ -39,7 +39,7 @@
(mt/with-premium-features #{:transforms-basic :hosting}
(mt/with-temp [:model/Transform transform {}
:model/Table {table-id :id} {:transform_id (:id transform)}]
- (t2/delete! :model/Transform (:id transform))
+ (t2/delete! :model/Transform :id (:id transform))
(testing "metabase_table.transform_id -> transform.id is ON DELETE SET NULL, not left dangling"
(is (nil? (user-table-fn :transform_id table-id))))
(testing "GET /api/table/:id does not crash"
diff --git a/enterprise/backend/test/metabase_enterprise/data_studio/permissions/can_read_test.clj b/enterprise/backend/test/metabase_enterprise/data_studio/permissions/can_read_test.clj
index 746b553b80f..65276e43a28 100644
--- a/enterprise/backend/test/metabase_enterprise/data_studio/permissions/can_read_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_studio/permissions/can_read_test.clj
@@ -37,7 +37,7 @@
(perms/set-database-permission! group-id (mt/id) :perms/view-data view-data)
(perms/set-database-permission! group-id (mt/id) :perms/create-queries :no)
(when table-is-published?
- (t2/update! :model/Table (mt/id :venues) {:is_published true :collection_id collection-id}))
+ (t2/update! :model/Table :id (mt/id :venues) {:is_published true :collection_id collection-id}))
(if collection-readable?
(perms/grant-collection-read-permissions! group-id collection-id)
(do
diff --git a/enterprise/backend/test/metabase_enterprise/data_studio/permissions/query_test.clj b/enterprise/backend/test/metabase_enterprise/data_studio/permissions/query_test.clj
index 8632090ba5a..514d038855c 100644
--- a/enterprise/backend/test/metabase_enterprise/data_studio/permissions/query_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_studio/permissions/query_test.clj
@@ -40,7 +40,7 @@
(mt/with-temp [:model/User {user-id :id} {}
:model/Collection {collection-id :id} {:type "library-data"}]
(try
- (schema.table-user-settings/upsert-user-settings (t2/select-one :model/Table (mt/id :venues))
+ (schema.table-user-settings/upsert-user-settings (t2/select-one :model/Table :id (mt/id :venues))
{:is_published true
:collection_id collection-id})
(let [all-users (perms/all-users-group)]
@@ -53,7 +53,7 @@
(perms/set-table-permission! all-users (mt/id :venues) :perms/create-queries :no))
(f user-id collection-id)
(finally
- (schema.table-user-settings/unset-user-settings! (t2/select-one :model/Table (mt/id :venues))
+ (schema.table-user-settings/unset-user-settings! (t2/select-one :model/Table :id (mt/id :venues))
[:is_published :collection_id])))))))
(deftest published-table-test
@@ -81,7 +81,7 @@
(perms/set-database-permission! group-id (mt/id) :perms/view-data view-data)
(perms/set-database-permission! group-id (mt/id) :perms/create-queries :no)
(when table-is-published?
- (t2/update! :model/Table (mt/id :venues) {:is_published true :collection_id collection-id}))
+ (t2/update! :model/Table :id (mt/id :venues) {:is_published true :collection_id collection-id}))
(if collection-readable?
(perms/grant-collection-read-permissions! group-id collection-id)
(do
@@ -109,7 +109,7 @@
(mt/with-temp [:model/User {user-id :id} {:email "[email protected]"}
:model/Collection collection {:type "library-data"}]
;; Publish the venues table into this collection
- (t2/update! :model/Table (mt/id :venues) {:is_published true :collection_id (u/the-id collection)})
+ (t2/update! :model/Table :id (mt/id :venues) {:is_published true :collection_id (u/the-id collection)})
(let [all-users (perms/all-users-group)]
;; Set database-level permissions first to establish baseline
(perms/set-database-permission! all-users (mt/id) :perms/view-data :blocked)
@@ -217,7 +217,7 @@
{:gtaps {:venues {:query (mt/mbql-query venues {:filter [:= $venues.price 4]})}}}
(mt/with-temp [:model/Collection {collection-id :id} {:type "library-data"}]
(try
- (t2/update! :model/Table (mt/id :venues) {:is_published true :collection_id collection-id})
+ (t2/update! :model/Table :id (mt/id :venues) {:is_published true :collection_id collection-id})
(perms/grant-collection-read-permissions! &group collection-id)
(testing "POST /api/dataset row count reflects the sandbox filter, not the full table"
(let [full-count (mt/with-test-user :crowberto
@@ -233,4 +233,4 @@
(is (every? #(= 4 (nth % price-index)) (mt/rows result))
"every returned row has price = 4, per the sandbox filter")))
(finally
- (t2/update! :model/Table (mt/id :venues) {:is_published false :collection_id nil}))))))))
+ (t2/update! :model/Table :id (mt/id :venues) {:is_published false :collection_id nil}))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/database_routing/api_test.clj b/enterprise/backend/test/metabase_enterprise/database_routing/api_test.clj
index 6e78cb251dc..fd28114bf60 100644
--- a/enterprise/backend/test/metabase_enterprise/database_routing/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/database_routing/api_test.clj
@@ -75,7 +75,7 @@
:model/DatabaseRouter {router-id :id} {:database_id db-id :user_attribute "foo"}]
(mt/user-http-request :crowberto :put 200 (str "ee/database-routing/router-database/" db-id)
{:user_attribute "bar"})
- (is (= "bar" (t2/select-one-fn :user_attribute :model/DatabaseRouter router-id)))))
+ (is (= "bar" (t2/select-one-fn :user_attribute :model/DatabaseRouter :id router-id)))))
(deftest deleting-database-routers-works
(mt/with-temp [:model/Database {db-id :id} {}
@@ -151,8 +151,8 @@
:model/Database {dest-db-id :id} {:router_database_id db-id}
:model/DatabaseRouter _ {:database_id db-id :user_attribute "foo"}]
(mt/user-http-request :crowberto :delete 204 (str "database/" db-id))
- (is (not (t2/exists? :model/Database dest-db-id)))
- (is (not (t2/exists? :model/Database db-id)))))
+ (is (not (t2/exists? :model/Database :id dest-db-id)))
+ (is (not (t2/exists? :model/Database :id db-id)))))
(deftest destination-databases-are-hidden-from-regular-database-api
(mt/with-temp [:model/Database {db-id :id} {}
diff --git a/enterprise/backend/test/metabase_enterprise/database_routing/connections_test.clj b/enterprise/backend/test/metabase_enterprise/database_routing/connections_test.clj
index 05ae1f8a7c4..567a72642b4 100644
--- a/enterprise/backend/test/metabase_enterprise/database_routing/connections_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/database_routing/connections_test.clj
@@ -167,9 +167,9 @@
(let [router-id (u/the-id router-db)
table (t2/select-one :model/Table :db_id router-id :name "acct")
owner (t2/select-one :model/Field :table_id (:id table) :name "owner")]
- (t2/update! :model/Field (:id owner) {:has_field_values "list"})
- (field-values/create-or-update-full-field-values! (t2/select-one :model/Field (:id owner)))
- (t2/update! :model/Database router-id {:is_on_demand true})
+ (t2/update! :model/Field :id (:id owner) {:has_field_values "list"})
+ (field-values/create-or-update-full-field-values! (t2/select-one :model/Field :id (:id owner)))
+ (t2/update! :model/Database :id router-id {:is_on_demand true})
(mt/with-temp [:model/DatabaseRouter _ {:database_id router-id :user_attribute "db_name"}]
(mt/with-current-user (mt/user->id :rasta)
(sync.field-values/update-field-values-for-on-demand-dbs! [(:id owner)]))
diff --git a/enterprise/backend/test/metabase_enterprise/database_routing/e2e_test.clj b/enterprise/backend/test/metabase_enterprise/database_routing/e2e_test.clj
index 6d4689c78a8..c538264a5ae 100644
--- a/enterprise/backend/test/metabase_enterprise/database_routing/e2e_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/database_routing/e2e_test.clj
@@ -421,7 +421,7 @@
;; Router: a normal synced DB that owns the Table/Field rows (matches prod + the H2 `with-routing-setup!`).
(mt/dataset (router-dataset driver/*driver*)
(let [router (mt/db)]
- (t2/update! :model/Database (u/the-id router)
+ (t2/update! :model/Database :id (u/the-id router)
{:details (merge (:details router)
(router-dataset-details driver/*driver*))})
(let [router (t2/select-one :model/Database :id (u/the-id router))]
@@ -480,7 +480,7 @@
[["us-east-1-foo"]
["us-east-1-bar"]]]])
(let [router (mt/db)]
- (t2/update! :model/Database (u/the-id router)
+ (t2/update! :model/Database :id (u/the-id router)
{:details (assoc (:details router) :dbname nil)})
(let [router (t2/select-one :model/Database :id (u/the-id router))]
(sync/sync-database! (:id router) {:scan :schema})
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/analysis_finding_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/analysis_finding_test.clj
index 873aef424e2..08fb6cf948a 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/analysis_finding_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/analysis_finding_test.clj
@@ -196,9 +196,9 @@
:model/Dependency _ {:from_entity_type :card :from_entity_id c-id
:to_entity_type :card :to_entity_id p-id}]
(run-jobs!)
- (t2/update! :model/Card gp-id {:name "Renamed"})
+ (t2/update! :model/Card :id gp-id {:name "Renamed"})
(is (empty? (filter #{gp-id p-id c-id} (analyzed-ids! run-jobs!))))
- (t2/update! :model/Card gp-id {:dataset_query (lib/query mp (lib.metadata/table mp (mt/id :orders)))})
+ (t2/update! :model/Card :id gp-id {:dataset_query (lib/query mp (lib.metadata/table mp (mt/id :orders)))})
(is (= #{gp-id p-id}
(set (filter #{gp-id p-id c-id} (analyzed-ids! run-jobs!)))))))))))
@@ -244,7 +244,7 @@
:source-tables []
:body "def transform():\n pass"}}]
(lib-be/with-metadata-provider-cache
- (deps.analysis-finding/upsert-analysis! (t2/select-one :model/Transform transform-id)))
+ (deps.analysis-finding/upsert-analysis! (t2/select-one :model/Transform :id transform-id)))
(is (=? {:result true}
(t2/select-one :model/AnalysisFinding :entity_type :transform :entity_id transform-id)))
(is (empty? (models.analysis-finding-error/errors-for-entity :transform transform-id))))))))
@@ -361,7 +361,7 @@
:from_entity_id child-card-id
:to_entity_type :card
:to_entity_id parent-card-id}]
- (t2/update! :model/Card parent-card-id {:dataset_query (lib/query mp (lib.metadata/table mp (mt/id :orders)))})
+ (t2/update! :model/Card :id parent-card-id {:dataset_query (lib/query mp (lib.metadata/table mp (mt/id :orders)))})
(assert-has-analyses
{:card {parent-card-id nil}})
(is (nil? (t2/select-one-fn :analysis_version :model/AnalysisFindingStatus
@@ -382,7 +382,7 @@
:to_entity_type :card
:to_entity_id parent-card-id}]
(analyzed-by-job!)
- (t2/update! :model/Card parent-card-id {:dataset_query (lib/query mp orders)})
+ (t2/update! :model/Card :id parent-card-id {:dataset_query (lib/query mp orders)})
(deps.test/synchronously-run-dependency-job!)
(is (= #{[:card parent-card-id] [:card child-card-id]}
(analyzed-among! [:card parent-card-id] [:card child-card-id])))))))))
@@ -396,9 +396,9 @@
:model/Dependency _ {:from_entity_type :card :from_entity_id child-id
:to_entity_type :card :to_entity_id parent-id}]
(analyzed-by-job!)
- (t2/update! :model/Card parent-id {:dataset_query (lib/native-query mp "select * from orders")
- :result_metadata (get-in (qp/process-query (lib/native-query mp "select * from orders"))
- [:data :results_metadata :columns])})
+ (t2/update! :model/Card :id parent-id {:dataset_query (lib/native-query mp "select * from orders")
+ :result_metadata (get-in (qp/process-query (lib/native-query mp "select * from orders"))
+ [:data :results_metadata :columns])})
(deps.test/synchronously-run-dependency-job!)
(is (= #{[:card parent-id] [:card child-id]}
(analyzed-among! [:card parent-id] [:card child-id]))))))))
@@ -420,7 +420,7 @@
:type :table}}
:model/Card {other-card-id :id} {:dataset_query (lib/query mp orders)}]
(analyzed-by-job!)
- (t2/update! :model/Card parent-card-id {:dataset_query (lib/query mp orders)})
+ (t2/update! :model/Card :id parent-card-id {:dataset_query (lib/query mp orders)})
(is (= #{[:card parent-card-id] [:transform transform-id]}
(analyzed-among! [:card parent-card-id] [:transform transform-id] [:card other-card-id]))))))))))
@@ -435,7 +435,7 @@
:target {:schema "public"
:name "sample"
:type :table}}]
- (is (= 1 (t2/update! :model/Transform transform-id
+ (is (= 1 (t2/update! :model/Transform :id transform-id
{:source {:type :query
:query (lib/query mp (lib.metadata/table mp (mt/id :orders)))}})))))))))
@@ -451,8 +451,8 @@
:name "sample"
:type :table}}]
(analyzed-by-job!)
- (t2/update! :model/Transform transform-id {:source {:type :query
- :query (lib/query mp (lib.metadata/table mp (mt/id :orders)))}})
+ (t2/update! :model/Transform :id transform-id {:source {:type :query
+ :query (lib/query mp (lib.metadata/table mp (mt/id :orders)))}})
(is (= #{[:transform transform-id]} (analyzed-among! [:transform transform-id])))))))))
(deftest ^:synchronized transform-update-triggers-native-transforms-test
@@ -465,7 +465,7 @@
:target {:schema "public"
:name "sample"
:type :table}}]
- (is (= 1 (t2/update! :model/Transform transform-id
+ (is (= 1 (t2/update! :model/Transform :id transform-id
{:source {:type :query
:query (lib/native-query mp "select * from orders")}}))))))))
@@ -508,7 +508,7 @@
price-field-id (mt/id :products :price)]
(mt/with-temp [:model/Segment {segment-id :id} {:table_id products-id
:definition {:filter [:> [:field price-field-id nil] 50]}}]
- (is (= 1 (t2/update! :model/Segment segment-id
+ (is (= 1 (t2/update! :model/Segment :id segment-id
{:definition {:filter [:< [:field price-field-id nil] 50]}})))))))))
(deftest ^:synchronized segment-update-analyzes-segment-and-dependents-test
@@ -524,7 +524,7 @@
(lib.metadata/segment (mt/metadata-provider)
segment-id))}]
(analyzed-by-job!)
- (t2/update! :model/Segment segment-id {:definition {:filter [:< [:field price-field-id nil] 50]}})
+ (t2/update! :model/Segment :id segment-id {:definition {:filter [:< [:field price-field-id nil] 50]}})
(is (= #{[:segment segment-id] [:card card-id]}
(analyzed-among! [:segment segment-id] [:card card-id]))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
index ab418bd8e1d..b05c1d8787a 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
@@ -450,7 +450,7 @@
:target {:schema "PUBLIC"
:name "inactive_transform_table"}}]
;; Simulate the transform having been run: link it to its (now inactive) target table
- (t2/update! :model/Transform transform-id {:target_table_id table-id})
+ (t2/update! :model/Transform :id transform-id {:target_table_id table-id})
(deps.hooks/after-transform-run transform-id table-id)
(deps.test/synchronously-run-dependency-job!)
(testing "GET /graph/dependents returns the inactive table as a child"
@@ -1255,7 +1255,7 @@
:name "referenced_transform_table"}}]
;; Simulate the referenced transform having been run: link it to its target table
;; so the table→transform dep is visible in the dependency graph.
- (t2/update! :model/Transform referenced-transform-id {:target_table_id referenced-table-id})
+ (t2/update! :model/Transform :id referenced-transform-id {:target_table_id referenced-table-id})
(deps.hooks/after-transform-run referenced-transform-id referenced-table-id)
(deps.test/synchronously-run-dependency-job!)
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=transform&query=unreftest")]
@@ -1481,7 +1481,7 @@
(let [internal-model (create-model-card! user "Internal Model - intbreaking")
dependent-card (create-dependent-card-on-model! user internal-model "Dependent - intbreaking")]
[internal-model dependent-card]))]
- (t2/update! :model/Card (:id internal-model) {:creator_id config/internal-mb-user-id})
+ (t2/update! :model/Card :id (:id internal-model) {:creator_id config/internal-mb-user-id})
(lib-be/with-metadata-provider-cache
(break-model-card! (t2/select-one :model/Card :id (:id internal-model))))
(lib-be/with-metadata-provider-cache
@@ -1877,7 +1877,7 @@
:creator_id (:id user)}
:model/Dependency _dep {:from_entity_type "card", :from_entity_id (:id card)
:to_entity_type "table", :to_entity_id (:id table)}]
- (t2/update! :model/Table (:id table) {:active false})
+ (t2/update! :model/Table :id (:id table) {:active false})
(lib-be/with-metadata-provider-cache
(run-analysis-for-card! (:id card)))
(testing "the dependent card's analysis is now broken, attributing the inactive table as the source"
@@ -2230,9 +2230,9 @@
{mid-id :id} (create-dependent! base-card user "Mid")
{high-id :id} (create-dependent! base-card user "High")]
(deps.test/synchronously-run-dependency-job!)
- (t2/update! :model/Card low-id {:view_count 10})
- (t2/update! :model/Card mid-id {:view_count 50})
- (t2/update! :model/Card high-id {:view_count 100})
+ (t2/update! :model/Card :id low-id {:view_count 10})
+ (t2/update! :model/Card :id mid-id {:view_count 50})
+ (t2/update! :model/Card :id high-id {:view_count 100})
(is (=? [{:data {:view_count 10}} {:data {:view_count 50}} {:data {:view_count 100}}]
(get-dependents base-card-id :sort-column :view-count :sort-direction :asc)))
(is (=? [{:data {:view_count 100}} {:data {:view_count 50}} {:data {:view_count 10}}]
@@ -2249,8 +2249,8 @@
:row 0 :col 0 :size_x 4 :size_y 4})
(events/publish-event! :event/dashboard-update {:object (t2/select-one :model/Dashboard :id dashboard-id) :user-id (mt/user->id :crowberto)})
(deps.test/synchronously-run-dependency-job!)
- (t2/update! :model/Card low-id {:view_count 10})
- (t2/update! :model/Card high-id {:view_count 100})
+ (t2/update! :model/Card :id low-id {:view_count 10})
+ (t2/update! :model/Card :id high-id {:view_count 100})
(is (=? [{:data {:view_count 10}} {:data {:view_count 100}} {:data {:view_count 200}}]
(get-dependents base-card-id :sort-column :view-count :sort-direction :asc)))
(is (=? [{:data {:view_count 200}} {:data {:view_count 100}} {:data {:view_count 10}}]
@@ -2346,8 +2346,8 @@
archived-dep-b (create-dependent-card-on-model! user model-card-b "Archived Dep B - errvistest")]
[model-card-a model-card-b visible-dep-a visible-dep-b archived-dep-a archived-dep-b]))]
;; Archive the archived dependents
- (t2/update! :model/Card (:id archived-dep-a) {:archived true})
- (t2/update! :model/Card (:id archived-dep-b) {:archived true})
+ (t2/update! :model/Card :id (:id archived-dep-a) {:archived true})
+ (t2/update! :model/Card :id (:id archived-dep-b) {:archived true})
;; Break both models
(lib-be/with-metadata-provider-cache
(break-model-card! model-card-a)
@@ -2443,8 +2443,8 @@
archived-dep-a-2 (create-dependent-card-on-model! user model-card-a "Archived Dep A2 - sortviserr")]
[model-card-a model-card-b visible-dep-a visible-dep-b archived-dep-a-1 archived-dep-a-2]))]
;; Archive model-a's extra dependents
- (t2/update! :model/Card (:id archived-dep-a-1) {:archived true})
- (t2/update! :model/Card (:id archived-dep-a-2) {:archived true})
+ (t2/update! :model/Card :id (:id archived-dep-a-1) {:archived true})
+ (t2/update! :model/Card :id (:id archived-dep-a-2) {:archived true})
;; Insert errors directly to ensure we control exactly what's in the DB
;; Model A: 1 visible error, 2 archived errors = 3 total
;; Model B: 2 visible errors = 2 total
@@ -3208,7 +3208,7 @@
(is (= #{app-id} (dependent-ids :crowberto))))
(testing "a user sees the enabled apps whose collection they can read"
(is (= #{} (dependent-ids :rasta)))
- (t2/update! :model/DataApp app-id {:enabled true})
+ (t2/update! :model/DataApp :id app-id {:enabled true})
(is (= #{app-id} (dependent-ids :rasta)))))
(mt/with-premium-features #{:dependencies}
(testing "without the data apps feature, the dependents list has no data apps, even for an admin"
@@ -3274,7 +3274,7 @@
:bundle_path "birds.js"
:bundle (byte-array [1 2 3])}]
(testing "a full row read counts"
- (is (seq (deps.test/data-app-bundle-reads #(t2/select-one :model/DataApp app-id)))))
+ (is (seq (deps.test/data-app-bundle-reads #(t2/select-one :model/DataApp :id app-id)))))
(doseq [endpoint ["ee/dependencies/graph" "ee/dependencies/graph/dependents" "ee/dependencies/graph/broken"]]
(testing endpoint
(is (= [] (deps.test/data-app-bundle-reads
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/hooks_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/hooks_test.clj
index 2e8f5d73f5e..fbc4d7f03f1 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/hooks_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/hooks_test.clj
@@ -37,7 +37,7 @@
before (status-row-count)]
(mt/with-dynamic-fn-redefs [grouper/submit! (fn [_queue write] (swap! submitted conj write))]
(deps.test/do-with-immediate-hook-writes
- #(t2/update! :model/Card card-id {:dataset_query (table-query :orders)})))
+ #(t2/update! :model/Card :id card-id {:dataset_query (table-query :orders)})))
(is (= before (status-row-count)))
(is (= [{:dependency-jobs true}] @submitted)))))))
@@ -48,7 +48,7 @@
(let [submitted (atom [])]
(mt/with-dynamic-fn-redefs [grouper/submit! (fn [_queue write] (swap! submitted conj write))]
(deps.test/do-with-immediate-hook-writes
- #(t2/update! :model/Card card-id {:dataset_query (table-query :orders)})))
+ #(t2/update! :model/Card :id card-id {:dataset_query (table-query :orders)})))
(is (= [] @submitted)))))))
(deftest update-marking-nothing-triggers-nothing-test
@@ -58,7 +58,7 @@
(let [submitted (atom [])]
(mt/with-dynamic-fn-redefs [grouper/submit! (fn [_queue write] (swap! submitted conj write))]
(deps.test/do-with-immediate-hook-writes
- #(t2/update! :model/Field field-id {:last_analyzed (t/offset-date-time)})))
+ #(t2/update! :model/Field :id field-id {:last_analyzed (t/offset-date-time)})))
(is (= [] @submitted)))))))
(deftest output-columns-mark-dependents-test
@@ -79,14 +79,14 @@
(deps.test/record-result-metadata-processed! card)
(write!)
(deps.test/result-metadata-pending? card))]
- (is (not (marks? card-id #(t2/update! :model/Card source-id {:name "Renamed"}))))
- (is (marks? card-id #(t2/update! :model/Card metric-id {:name "Renamed"})))
+ (is (not (marks? card-id #(t2/update! :model/Card :id source-id {:name "Renamed"}))))
+ (is (marks? card-id #(t2/update! :model/Card :id metric-id {:name "Renamed"})))
(mt/with-temp-vals-in-db :model/Field (mt/id :venues :price) {:position 5}
- (is (marks? source-id #(t2/update! :model/Field (mt/id :venues :price) {:position 0}))))
+ (is (marks? source-id #(t2/update! :model/Field :id (mt/id :venues :price) {:position 0}))))
(mt/with-temp-vals-in-db :model/Table (mt/id :venues) {:schema "PUBLIC"}
- (is (marks? source-id #(t2/update! :model/Table (mt/id :venues) {:schema "OTHER"}))))
+ (is (marks? source-id #(t2/update! :model/Table :id (mt/id :venues) {:schema "OTHER"}))))
(mt/with-temp [:model/TableUserSettings _ {:table_id (mt/id :venues)}]
- (is (not (marks? source-id #(t2/update! :model/TableUserSettings (mt/id :venues)
+ (is (not (marks? source-id #(t2/update! :model/TableUserSettings :table_id (mt/id :venues)
{:caveats "Careful"}))))))))))
(deftest card-metadata-dependents-see-test
@@ -99,7 +99,7 @@
(let [metadata (t2/select-one-fn :result_metadata :model/Card :id source-id)
marks? (fn [f]
(deps.test/record-result-metadata-processed! card-id)
- (t2/update! :model/Card source-id {:result_metadata (mapv f metadata)})
+ (t2/update! :model/Card :id source-id {:result_metadata (mapv f metadata)})
(deps.test/result-metadata-pending? card-id))]
(is (not (marks? #(assoc % :fingerprint {:global {:distinct-count 3}}))))
(is (marks? #(cond-> % (= "NAME" (:name %)) (assoc :display_name "Renamed")))))))))
@@ -157,9 +157,9 @@
:model/FieldValues fv {:field_id (mt/id :venues :price) :type :full
:values [1 2 3 4] :human_readable_values []}]
(processed!)
- (t2/update! :model/FieldValues (:id fv) {:values [1 2 3 4 5]})
+ (t2/update! :model/FieldValues :id (:id fv) {:values [1 2 3 4 5]})
(is (not (both-pending?)))
- (t2/update! :model/FieldValues (:id fv) {:human_readable_values ["$" "$$" "$$$" "$$$$" "$$$$$"]})
+ (t2/update! :model/FieldValues :id (:id fv) {:human_readable_values ["$" "$$" "$$$" "$$$$" "$$$$$"]})
(is (both-pending?))))))))
(deftest batched-marks-test
@@ -183,8 +183,8 @@
(reset! submitted [])
(deps.test/do-with-immediate-hook-writes
#(dependencies.hooks/with-batched-marks
- (t2/update! :model/Field (mt/id :venues :price) {:position 0})
- (t2/update! :model/Field (mt/id :venues :name) {:position 1})))
+ (t2/update! :model/Field :id (mt/id :venues :price) {:position 0})
+ (t2/update! :model/Field :id (mt/id :venues :name) {:position 1})))
(is (= [[:table #{(mt/id :venues)}]] @marks))
(is (= [{:dependency-jobs true}] @submitted))
(is (deps.test/result-metadata-pending? card-id))))))))))
@@ -210,9 +210,9 @@
(mt/with-premium-features #{:dependencies}
(mt/with-temp [:model/Card {card-id :id} {:dataset_query (table-query :products)}]
(computed! :card card-id)
- (t2/update! :model/Card card-id {:name "Renamed"})
+ (t2/update! :model/Card :id card-id {:name "Renamed"})
(is (not (pending? :card card-id)))
- (t2/update! :model/Card card-id {:dataset_query (table-query :orders)})
+ (t2/update! :model/Card :id card-id {:dataset_query (table-query :orders)})
(is (pending? :card card-id))))))
(deftest dashboard-parts-mark-dashboard-test
@@ -232,7 +232,7 @@
{:dashboard_id dashboard-id :card_id card-id
:row 0 :col 0 :size_x 4 :size_y 4})))))
(testing "pointing a dashboard card at another card"
- (is (changes? #(t2/update! :model/DashboardCard @dashcard {:card_id other-id}))))
+ (is (changes? #(t2/update! :model/DashboardCard :id @dashcard {:card_id other-id}))))
(testing "adding a series"
(is (changes? #(t2/insert! :model/DashboardCardSeries {:dashboardcard_id @dashcard :card_id card-id
:position 0}))))
@@ -265,13 +265,13 @@
(write!)
(deps.test/result-metadata-pending? card-id))]
(mt/with-temp-vals-in-db :model/Table table-id {:display_name "Venues"}
- (is (changes? #(t2/update! :model/Table table-id {:display_name "Places"}))))
+ (is (changes? #(t2/update! :model/Table :id table-id {:display_name "Places"}))))
(mt/with-temp-vals-in-db :model/Field field-id {:display_name "Price"}
- (is (changes? #(t2/update! :model/Field field-id {:display_name "Cost"}))))
+ (is (changes? #(t2/update! :model/Field :id field-id {:display_name "Cost"}))))
(mt/with-temp [:model/FieldUserSettings _ {:field_id field-id :display_name "Cost"}]
(is (changes? (fn [] (t2/update! :model/FieldUserSettings :field_id field-id {:display_name "Price"})))))
(is (changes? #(t2/insert! :model/TableUserSettings {:table_id table-id :display_name "Places"})))
- (is (changes? #(t2/update! :model/TableUserSettings table-id {:display_name "Spots"})))
+ (is (changes? #(t2/update! :model/TableUserSettings :table_id table-id {:display_name "Spots"})))
(is (changes? #(t2/delete! :model/TableUserSettings :table_id table-id)))
(let [dimension-id (atom nil)]
(is (changes? #(reset! dimension-id (t2/insert-returning-pk! :model/Dimension
@@ -345,11 +345,11 @@
(t2/insert! :model/Dependency {:from_entity_type :card :from_entity_id card-b
:to_entity_type :card :to_entity_id card-a})
(let [cascade (save! #(t2/with-transaction [_conn]
- (t2/update! :model/Card card-a {:dataset_query (table-query :orders)})
+ (t2/update! :model/Card :id card-a {:dataset_query (table-query :orders)})
(deliver a-saved true)
- (t2/update! :model/Card card-b {:dataset_query (lib/limit (card-query card-a) 5)})))
+ (t2/update! :model/Card :id card-b {:dataset_query (lib/limit (card-query card-a) 5)})))
single (save! #(do (deref a-saved 10000 nil)
- (t2/update! :model/Card card-b {:dataset_query (lib/limit (card-query card-a) 11)})))]
+ (t2/update! :model/Card :id card-b {:dataset_query (lib/limit (card-query card-a) 11)})))]
(is (= [:committed :committed]
[(deref cascade 30000 :timeout) (deref single 30000 :timeout)]))))))))
@@ -385,8 +385,8 @@
:entity_id transform-id
:result true
:analyzed_at :%now}]
- (t2/delete! :model/Database db-id)
- (is (nil? (t2/select-one :model/Database db-id))
+ (t2/delete! :model/Database :id db-id)
+ (is (nil? (t2/select-one :model/Database :id db-id))
"the Database row is actually gone")
(is (pending? :transform transform-id))
(deps.test/synchronously-run-dependency-job!)
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/models/dependency_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/models/dependency_test.clj
index 6324be20e89..63269fcbec3 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/models/dependency_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/models/dependency_test.clj
@@ -204,13 +204,13 @@
(mt/with-temp [:model/Transform transform]
(is (not (t2/exists? :model/DependencyStatus :entity_type :transform :entity_id (:id transform))))
(computed! :transform (:id transform))
- (t2/update! :model/Transform (:id transform) {:source {:type "query" :query (mt/mbql-query products)}})
+ (t2/update! :model/Transform :id (:id transform) {:source {:type "query" :query (mt/mbql-query products)}})
(is (pending? :transform (:id transform)))))
(testing "snippets"
(mt/with-temp [:model/NativeQuerySnippet snippet]
(is (not (t2/exists? :model/DependencyStatus :entity_type :snippet :entity_id (:id snippet))))
(computed! :snippet (:id snippet))
- (t2/update! :model/NativeQuerySnippet (:id snippet) {:content "new content"})
+ (t2/update! :model/NativeQuerySnippet :id (:id snippet) {:content "new content"})
(is (pending? :snippet (:id snippet))))))))))
(deftest dependency-status-absent-until-backfill-on-card-create-test
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.clj
index 512a18bfa9c..17f19a4a62c 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/result_metadata_test.clj
@@ -96,7 +96,7 @@
:model/Card {after-native-id :id} {:dataset_query (card-query native-id)}]
(run-jobs!)
(is (nil? (column question-id "Grand total")))
- (t2/update! :model/Card model-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id model-id {:dataset_query (add-grand-total (table-query :orders))})
(is (pending? question-id))
(run-jobs!)
(is (some? (column question-id "Grand total")))
@@ -105,7 +105,7 @@
(is (nil? (column after-native-id "Grand total"))))
(is (not-any? pending? [model-id question-id nested-id]))
(testing "a column no longer inferred is removed"
- (t2/update! :model/Card model-id {:dataset_query (table-query :orders)})
+ (t2/update! :model/Card :id model-id {:dataset_query (table-query :orders)})
(run-jobs!)
(is (nil? (column question-id "Grand total")))
(is (nil? (column nested-id "Grand total"))))))))
@@ -137,7 +137,7 @@
stored (->> (t2/select-one-fn :result_metadata :model/Card :id card-id)
(remove #(= "PRICE" (:name %)))
(mapv #(cond-> % (= "ID" (:name %)) (assoc :fingerprint marker))))]
- (t2/update! :model/Card card-id {:result_metadata stored})
+ (t2/update! :model/Card :id card-id {:result_metadata stored})
(run-jobs!)
(reprocess! card-id)
(run-jobs!)
@@ -159,7 +159,7 @@
(lib/ref (lib.metadata/field mp (mt/id :orders :id))))]))]
(mt/with-temp [:model/Card {joined-id :id} {:dataset_query joined}]
(run-jobs!)
- (t2/update! :model/Card model-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id model-id {:dataset_query (add-grand-total (table-query :orders))})
(run-jobs!)
(is (some? (column joined-id "Grand total")))))))))
@@ -171,7 +171,7 @@
:model/Card {internal-id :id} {:dataset_query (card-query model-id)
:creator_id config/internal-mb-user-id}]
(run-jobs!)
- (t2/update! :model/Card model-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id model-id {:dataset_query (add-grand-total (table-query :orders))})
(run-jobs!)
(is (some? (column card-id "Grand total")))
(is (nil? (column internal-id "Grand total")))))))
@@ -182,9 +182,9 @@
(mt/with-temp [:model/Card {model-id :id} {:type :model :dataset_query (table-query :orders)}
:model/Card {card-id :id} {:dataset_query (card-query model-id)}]
(run-jobs!)
- (t2/update! :model/Card model-id {:result_metadata (rename-column (t2/select-one-fn :result_metadata :model/Card
- :id model-id)
- "TOTAL" "Grand total")})
+ (t2/update! :model/Card :id model-id {:result_metadata (rename-column (t2/select-one-fn :result_metadata :model/Card
+ :id model-id)
+ "TOTAL" "Grand total")})
(is (pending? card-id))
(run-jobs!)
(is (= "Grand total" (:display_name (column card-id "TOTAL"))))))))
@@ -194,9 +194,9 @@
(with-dependencies-feature
(mt/with-temp [:model/Card {model-id :id} {:type :model :dataset_query (table-query :orders)}]
(run-jobs!)
- (t2/update! :model/Card model-id {:result_metadata (rename-column (t2/select-one-fn :result_metadata :model/Card
- :id model-id)
- "TOTAL" "Grand total")})
+ (t2/update! :model/Card :id model-id {:result_metadata (rename-column (t2/select-one-fn :result_metadata :model/Card
+ :id model-id)
+ "TOTAL" "Grand total")})
(mt/with-temp [:model/FieldUserSettings _ {:field_id (mt/id :orders :total) :display_name "Order total"}]
(is (pending? model-id))
(run-jobs!)
@@ -225,7 +225,7 @@
(run-jobs!)
(let [column-name #(:name (first (t2/select-one-fn :result_metadata :model/Card :id card-id)))]
(is (= "count" (column-name)))
- (t2/update! :model/Measure measure-id
+ (t2/update! :model/Measure :id measure-id
{:definition (-> (table-query :orders)
(lib/aggregate (lib/avg (lib.metadata/field (mt/metadata-provider)
(mt/id :orders :total)))))})
@@ -247,7 +247,7 @@
(run-jobs!)
(let [base-type #(:base_type (first (t2/select-one-fn :result_metadata :model/Card :id card-id)))]
(is (isa? (base-type) :type/Integer))
- (t2/update! :model/Measure inner-id
+ (t2/update! :model/Measure :id inner-id
{:definition (-> (table-query :orders)
(lib/aggregate (lib/avg (lib.metadata/field (mt/metadata-provider)
(mt/id :orders :total)))))})
@@ -283,7 +283,7 @@
(mt/with-temp [:model/FieldUserSettings _ {:field_id (mt/id :orders :total) :display_name "Order total"}]
(is (pos? (rederive-during-inference!
card-id
- (once! #(t2/update! :model/Card card-id {:dataset_query (add-grand-total (table-query :orders))})))))
+ (once! #(t2/update! :model/Card :id card-id {:dataset_query (add-grand-total (table-query :orders))})))))
(is (some? (column card-id "Grand total")))
(is (pending? card-id))
(run-jobs!)
@@ -315,7 +315,7 @@
(mt/with-temp [:model/Card {source-id :id} {:dataset_query (by-unit :month)}
:model/Card {card-id :id} {:dataset_query (card-query source-id)}]
(run-jobs!)
- (t2/update! :model/Card source-id {:dataset_query (by-unit :year)})
+ (t2/update! :model/Card :id source-id {:dataset_query (by-unit :year)})
(run-jobs!)
(is (=? {:display_name "Created At: Year" :unit :year}
(column card-id "CREATED_AT"))))))))
@@ -329,16 +329,16 @@
:model/Card {card-id :id} {:dataset_query (card-query source-id)}]
(run-jobs!)
(is (isa? (:base_type (column card-id "X")) :type/Number))
- (t2/update! :model/Card source-id {:dataset_query (with (lib/concat total "!"))})
+ (t2/update! :model/Card :id source-id {:dataset_query (with (lib/concat total "!"))})
(run-jobs!)
(is (= :type/Text (:base_type (column card-id "X"))))
(testing "within one root type too, since no run measured the card's types"
- (t2/update! :model/Card source-id {:dataset_query (with (lib/+ (lib.metadata/field (mt/metadata-provider)
- (mt/id :orders :quantity))
- 1))})
+ (t2/update! :model/Card :id source-id {:dataset_query (with (lib/+ (lib.metadata/field (mt/metadata-provider)
+ (mt/id :orders :quantity))
+ 1))})
(run-jobs!)
(is (= :type/Integer (:base_type (column card-id "X"))))
- (t2/update! :model/Card source-id {:dataset_query (with (lib/* total 1.5))})
+ (t2/update! :model/Card :id source-id {:dataset_query (with (lib/* total 1.5))})
(run-jobs!)
(is (= :type/Float (:base_type (column card-id "X"))))))))))
@@ -369,7 +369,7 @@
(mt/with-temp [:model/Card {source-id :id} {:dataset_query (table-query :orders)}
:model/Card {card-id :id} {:dataset_query (card-query source-id)}]
(run-jobs!)
- (t2/update! :model/Card source-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id source-id {:dataset_query (add-grand-total (table-query :orders))})
(do-with-inference (fn [_infer _query _card] (throw (ex-info "Inference failed" {})))
run-jobs!)
(is (nil? (column card-id "Grand total")))
@@ -392,7 +392,7 @@
:creator_id (mt/user->id :rasta)
:database_id (mt/id)
:dataset_query (card-query source-id)})]
- (t2/update! :model/Card source-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id source-id {:dataset_query (add-grand-total (table-query :orders))})
(mt/with-premium-features #{:dependencies}
(deps.result-metadata/update-result-metadata! 1000))
(run-jobs!)
@@ -429,9 +429,9 @@
:creator_id (mt/user->id :rasta)
:database_id (mt/id)
:dataset_query (card-query source-id)})]
- (t2/update! :model/Card source-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id source-id {:dataset_query (add-grand-total (table-query :orders))})
(deps.result-metadata/update-result-metadata! 1000)
- (t2/update! :model/Card card-id {:name "Renamed"})
+ (t2/update! :model/Card :id card-id {:name "Renamed"})
(run-jobs!)
(is (some? (column card-id "Grand total")))))))))
@@ -454,7 +454,7 @@
(deps.test/synchronously-run-dependency-job!)
(let [submitted (atom [])
before (t2/select-one-fn :updated_at :model/Card :id card-id)]
- (t2/update! :model/Card source-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id source-id {:dataset_query (add-grand-total (table-query :orders))})
(deps.test/synchronously-run-dependency-job!)
(mt/with-dynamic-fn-redefs [grouper/submit! (fn [_queue write] (swap! submitted conj write))]
(rederive!)
@@ -488,7 +488,7 @@
gives the converted query new uuids"
(with-dependencies-feature
(mt/with-temp [:model/Card {card-id :id} {:dataset_query (table-query :venues)}]
- (t2/update! (t2/table-name :model/Card) card-id
+ (t2/update! (t2/table-name :model/Card) :id card-id
{:dataset_query (json/encode {:database (mt/id)
:type :query
:query {:source-table (mt/id :venues)
@@ -506,8 +506,8 @@
(mt/with-temp [:model/Card {source-id :id} {:dataset_query (table-query :orders)}
:model/Card {card-id :id} {:dataset_query (table-query :venues)}]
(run-jobs!)
- (t2/update! :model/Card card-id {:dataset_query (card-query source-id)})
- (t2/update! :model/Card source-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id card-id {:dataset_query (card-query source-id)})
+ (t2/update! :model/Card :id source-id {:dataset_query (add-grand-total (table-query :orders))})
(run-jobs!)
(is (some? (column card-id "Grand total")))))))
@@ -534,7 +534,7 @@
(mt/with-temp [:model/Card {source-id :id} {:dataset_query (table-query :orders)}
:model/Card {card-id :id} {:dataset_query (card-query source-id)}]
(run-jobs!)
- (t2/update! :model/Card source-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id source-id {:dataset_query (add-grand-total (table-query :orders))})
(let [inferred (atom #{})]
(do-with-inference (fn [infer query card]
(swap! inferred conj (:id card))
@@ -554,8 +554,8 @@
:result_metadata (native-run-metadata "SELECT ID, NAME FROM VENUES")}
:model/Card {card-id :id} {:dataset_query (card-query native-id)}]
(run-jobs!)
- (t2/update! :model/Card native-id {:dataset_query (lib/native-query (mt/metadata-provider)
- "SELECT ID, NAME, PRICE FROM VENUES")})
+ (t2/update! :model/Card :id native-id {:dataset_query (lib/native-query (mt/metadata-provider)
+ "SELECT ID, NAME, PRICE FROM VENUES")})
(run-jobs!)
(is (nil? (column card-id "PRICE")))
(store-run-metadata! native-id (native-run-metadata "SELECT ID, NAME, PRICE FROM VENUES"))
@@ -603,10 +603,10 @@
(if (= card-id (:id entity))
(throw (ex-info "Computation failed" {}))
(calculate entity-type entity)))]
- (t2/update! :model/Card card-id {:dataset_query (card-query source-id)
- :description "edited"})
+ (t2/update! :model/Card :id card-id {:dataset_query (card-query source-id)
+ :description "edited"})
(dependencies.db/mark-dependency-statuses-stale! {:card #{card-id}})
- (t2/update! :model/Card source-id {:dataset_query (add-grand-total (table-query :orders))})
+ (t2/update! :model/Card :id source-id {:dataset_query (add-grand-total (table-query :orders))})
(run-jobs!)))
(is (nil? (column card-id "Grand total")))
(is (pending? card-id))))))
@@ -700,7 +700,7 @@
(let [locked (promise)
save (future
(t2/with-transaction [_]
- (t2/update! :model/Card card-id {:name "Saved"})
+ (t2/update! :model/Card :id card-id {:name "Saved"})
(deliver locked true)
(Thread/sleep 1000)))]
@locked
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/sync_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/sync_test.clj
index 4b4d2736529..1d515b00df2 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/sync_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/sync_test.clj
@@ -47,7 +47,7 @@
;; NOTE: The metadata provider caches must be small here - if the cache spans a sync it will see
;; old values after the sync!
(lib-be/with-metadata-provider-cache
- (deps.analysis-finding/upsert-analysis! (t2/select-one :model/Card card-id)))
+ (deps.analysis-finding/upsert-analysis! (t2/select-one :model/Card :id card-id)))
(testing "Initial analysis succeeds"
(is (true? (t2/select-one-fn :result :model/AnalysisFinding
:entity_type :card :entity_id card-id)))
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/task/dependency_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/task/dependency_test.clj
index 166126b7efa..1a2c1cd8093 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/task/dependency_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/task/dependency_test.clj
@@ -508,7 +508,7 @@
"{{snippet: birds outer}}")}]
(backfill-all-existing-entities!)
(is (= #{(mt/id :venues)} (table-dependency-ids :card card-id)))
- (t2/update! :model/NativeQuerySnippet inner-id {:content "CHECKINS"})
+ (t2/update! :model/NativeQuerySnippet :id inner-id {:content "CHECKINS"})
(backfill-all-existing-entities!)
(is (= #{(mt/id :checkins)} (table-dependency-ids :card card-id)))))))
@@ -522,7 +522,7 @@
:model/Card {card-id :id} {:dataset_query (lib/native-query (mt/metadata-provider)
"{{snippet: window outer}}")}]
(backfill-all-existing-entities!)
- (t2/update! :model/NativeQuerySnippet outer-id {:content "SELECT * FROM {{snippet: window inner}}"})
+ (t2/update! :model/NativeQuerySnippet :id outer-id {:content "SELECT * FROM {{snippet: window inner}}"})
(deps.test/record-analysis-finding-processed! :card card-id)
(backfill-dependencies-single-trigger!)
(is (deps.test/analysis-finding-pending? :card card-id))))))
@@ -582,7 +582,7 @@
(into #{} (map #(dissoc % :id)
(t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard)))))
(t2/delete! :model/DashboardCard :id basic-dashcard-id)
- (t2/update! :model/Dashboard dashboard-id {:parameters []})
+ (t2/update! :model/Dashboard :id dashboard-id {:parameters []})
(mt/with-temp [:model/Card {scalar-card-id :id} {:dataset_query (-> (lib/query mp products)
(lib/aggregate (lib/count)))
:display :scalar}
@@ -656,7 +656,7 @@
:to_entity_id column-click-target-dashboard-id}}
(into #{} (map #(dissoc % :id)
(t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard)))))
- (t2/delete! :model/Dashboard dashboard-id)
+ (t2/delete! :model/Dashboard :id dashboard-id)
(deps.test/synchronously-run-dependency-job!)
(is (empty? (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard)))))))))
@@ -697,7 +697,7 @@
{:type "smartLink"
:attrs {"entityId" products-id
"model" "table"}}]}]})]
- (t2/update! :model/Document document-id updated-doc)
+ (t2/update! :model/Document :id document-id updated-doc)
(deps.test/synchronously-run-dependency-job!)
(is (=? #{{:from_entity_type :document
:from_entity_id document-id
@@ -709,7 +709,7 @@
:to_entity_id products-id}}
(into #{} (map #(dissoc % :id)
(t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document)))))
- (t2/delete! :model/Document document-id)
+ (t2/delete! :model/Document :id document-id)
(deps.test/synchronously-run-dependency-job!)
(is (empty? (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document))))))))))
@@ -731,7 +731,7 @@
:to_entity_id card1-id}}
(into #{} (map #(dissoc % :id)
(t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox)))))
- (t2/update! :model/Sandbox sandbox-id (assoc sandbox :card_id card2-id))
+ (t2/update! :model/Sandbox :id sandbox-id (assoc sandbox :card_id card2-id))
(deps.test/synchronously-run-dependency-job!)
(is (=? #{{:from_entity_type :sandbox
:from_entity_id sandbox-id
@@ -739,7 +739,7 @@
:to_entity_id card2-id}}
(into #{} (map #(dissoc % :id)
(t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox)))))
- (t2/delete! :model/Sandbox sandbox-id)
+ (t2/delete! :model/Sandbox :id sandbox-id)
(deps.test/synchronously-run-dependency-job!)
(is (empty? (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox))))))))
@@ -755,7 +755,7 @@
(is (t2/exists? :model/Dependency :from_entity_type :card :from_entity_id card-id
:to_entity_type :table :to_entity_id (mt/id :products)))
(is (not (pending? :card card-id)))
- (t2/update! :model/Card card-id {:dataset_query (lib/query mp orders)})
+ (t2/update! :model/Card :id card-id {:dataset_query (lib/query mp orders)})
(assert-pending :card card-id)))))))
(deftest metric-dimensions-update-marks-stale-and-includes-mapped-table-test
@@ -769,7 +769,7 @@
;; uncurated, so the after-insert dimension auto-sync would seed dimensions from the query and
;; overwrite mappings passed to with-temp. A plain update sticks — the after-update hook only
;; re-syncs when `:dataset_query` changes.
- (t2/update! :model/Card card-id
+ (t2/update! :model/Card :id card-id
{:dimension_mappings [{:type :table
:dimension-id "550e8400-e29b-41d4-a716-446655440000"
:table-id (mt/id :categories)
@@ -792,7 +792,7 @@
(assert-pending :snippet snippet-id)
(deps.test/synchronously-run-dependency-job!)
(is (not (pending? :snippet snippet-id)))
- (t2/update! :model/NativeQuerySnippet snippet-id {:content "SELECT 2"})
+ (t2/update! :model/NativeQuerySnippet :id snippet-id {:content "SELECT 2"})
(assert-pending :snippet snippet-id))))))
(deftest ^:synchronized native-transform-create-sets-dependencies-test
@@ -887,7 +887,7 @@
:to_entity_id transform-id}]
(t2/select :model/Dependency :to_entity_id transform-id :to_entity_type :transform))))
(testing "keeping target"
- (t2/update! :model/Transform transform-id {:source (update source :body str "\n")})
+ (t2/update! :model/Transform :id transform-id {:source (update source :body str "\n")})
(assert-pending :transform transform-id)
(deps.test/synchronously-run-dependency-job!)
(is (=? [{:from_entity_type :table
@@ -896,7 +896,7 @@
:to_entity_id transform-id}]
(t2/select :model/Dependency :to_entity_id transform-id :to_entity_type :transform))))
(testing "changing target update"
- (t2/update! :model/Transform transform-id {:target (assoc target :name "test_table2")})
+ (t2/update! :model/Transform :id transform-id {:target (assoc target :name "test_table2")})
(deps.test/synchronously-run-dependency-job!)
(is (empty?
(t2/select :model/Dependency :to_entity_id transform-id :to_entity_type :transform))))))))))
@@ -919,7 +919,7 @@
:to_entity_id transform-id}]
(t2/select :model/Dependency :to_entity_id transform-id :to_entity_type :transform))))
(testing "keeping target"
- (t2/update! :model/Transform transform-id {:source (assoc source :query (lib/native-query mp "select * from orders limit 10"))})
+ (t2/update! :model/Transform :id transform-id {:source (assoc source :query (lib/native-query mp "select * from orders limit 10"))})
(assert-pending :transform transform-id)
(deps.test/synchronously-run-dependency-job!)
(is (=? [{:from_entity_type :table
@@ -928,7 +928,7 @@
:to_entity_id transform-id}]
(t2/select :model/Dependency :to_entity_id transform-id :to_entity_type :transform))))
(testing "changing target update"
- (t2/update! :model/Transform transform-id {:target (assoc target :name "test_table2")})
+ (t2/update! :model/Transform :id transform-id {:target (assoc target :name "test_table2")})
(deps.test/synchronously-run-dependency-job!)
(is (empty?
(t2/select :model/Dependency :to_entity_id transform-id :to_entity_type :transform))))))))))
@@ -951,7 +951,7 @@
(into #{} (map #(dissoc % :id)
(t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment))))))
(testing "updating segment definition recalculates dependencies"
- (t2/update! :model/Segment segment-id {:definition {:filter [:= [:field category-field-id nil] "Widget"]}})
+ (t2/update! :model/Segment :id segment-id {:definition {:filter [:= [:field category-field-id nil] "Widget"]}})
(assert-pending :segment segment-id)
(deps.test/synchronously-run-dependency-job!)
(is (= #{{:from_entity_type :segment
@@ -961,7 +961,7 @@
(into #{} (map #(dissoc % :id)
(t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment))))))
(testing "deleting segment removes all dependencies"
- (t2/delete! :model/Segment segment-id)
+ (t2/delete! :model/Segment :id segment-id)
(deps.test/synchronously-run-dependency-job!)
(is (empty? (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment)))))))))
@@ -1011,8 +1011,8 @@
(into #{} (map #(dissoc % :id)
(t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))))
(testing "updating measure definition recalculates dependencies"
- (t2/update! :model/Measure measure-id {:definition (-> (lib/query mp orders)
- (lib/aggregate (lib/sum subtotal)))})
+ (t2/update! :model/Measure :id measure-id {:definition (-> (lib/query mp orders)
+ (lib/aggregate (lib/sum subtotal)))})
(assert-pending :measure measure-id)
(deps.test/synchronously-run-dependency-job!)
(is (= #{{:from_entity_type :measure
@@ -1022,7 +1022,7 @@
(into #{} (map #(dissoc % :id)
(t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))))
(testing "deleting measure removes all dependencies"
- (t2/delete! :model/Measure measure-id)
+ (t2/delete! :model/Measure :id measure-id)
(deps.test/synchronously-run-dependency-job!)
(is (empty? (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))))))))
@@ -1043,13 +1043,13 @@
(is (= #{[:table (mt/id :venues)]}
(action-deps action-id))))
(testing "updating an action's query recalculates its dependencies"
- (t2/update! :model/QueryAction action-id {:dataset_query (sql-query "checkins")})
+ (t2/update! :model/QueryAction :action_id action-id {:dataset_query (sql-query "checkins")})
(assert-pending :action action-id)
(deps.test/synchronously-run-dependency-job!)
(is (= #{[:table (mt/id :checkins)]}
(action-deps action-id))))
(testing "deleting an action removes its dependencies and status"
- (t2/delete! :model/Action action-id)
+ (t2/delete! :model/Action :id action-id)
(deps.test/synchronously-run-dependency-job!)
(is (empty? (action-deps action-id)))
(is (not (t2/exists? :model/DependencyStatus :entity_type :action :entity_id action-id)))))))))
@@ -1078,7 +1078,7 @@
(is (= {:dependencies #{implicit-id query-id}, :statuses #{implicit-id query-id}}
(action-dependency-rows [implicit-id query-id]))))
(testing "deleting the model removes the dependency rows of its actions"
- (t2/delete! :model/Card model-id)
+ (t2/delete! :model/Card :id model-id)
(deps.test/synchronously-run-dependency-job!)
(is (= {:dependencies #{}, :statuses #{}}
(action-dependency-rows [implicit-id query-id]))))))))
@@ -1103,7 +1103,7 @@
(is (= #{implicit-id query-id}
(:statuses (action-dependency-rows [implicit-id query-id])))))
(testing "deleting the database removes the dependency rows of the actions of its models"
- (t2/delete! :model/Database db-id)
+ (t2/delete! :model/Database :id db-id)
(deps.test/synchronously-run-dependency-job!)
(is (= {:dependencies #{}, :statuses #{}}
(action-dependency-rows [implicit-id query-id]))))
@@ -1176,7 +1176,7 @@
(mt/with-temp [:model/Card {card-id :id :as card} {:dataset_query (query :products)}
:model/Card {other-id :id} {:dataset_query (query :products)}]
(let [exported (serdes/extract-one "Card" {} card)]
- (t2/update! :model/Card card-id {:dataset_query (query :orders)})
+ (t2/update! :model/Card :id card-id {:dataset_query (query :orders)})
(deps.test/synchronously-run-dependency-job!)
(is (= #{[:table (mt/id :orders)]} (card-deps card-id)))
(load! [exported])
@@ -1194,7 +1194,7 @@
(mt/with-temp [:model/Card {source-id :id} {:dataset_query (deps.test/table-query :orders)}
:model/Card {card-id :id} {:dataset_query (deps.test/table-query :venues)}]
(deps.test/synchronously-run-dependency-job!)
- (t2/update! :model/Card card-id {:dataset_query (deps.test/card-query source-id)})
+ (t2/update! :model/Card :id card-id {:dataset_query (deps.test/card-query source-id)})
(deps.test/record-analysis-finding-processed! :card card-id)
(deps.test/synchronously-run-dependency-job!)
(is (deps.test/analysis-finding-pending? :card card-id)))))))
@@ -1228,17 +1228,17 @@
(deps.test/synchronously-run-dependency-job!)
(is (= #{[:card card-id] [:card added-id] [:action action-id]} (data-app-deps app-id))))
(testing "a card moved out of the collection stops being one"
- (t2/update! :model/Card added-id {:collection_id other-collection-id})
+ (t2/update! :model/Card :id added-id {:collection_id other-collection-id})
(assert-pending :data-app app-id)
(deps.test/synchronously-run-dependency-job!)
(is (= #{[:card card-id] [:action action-id]} (data-app-deps app-id)))))
(testing "a deleted action stops being one"
- (t2/delete! :model/Action action-id)
+ (t2/delete! :model/Action :id action-id)
(assert-pending :data-app app-id)
(deps.test/synchronously-run-dependency-job!)
(is (= #{[:card card-id]} (data-app-deps app-id))))
(testing "deleting the app removes its dependencies and status"
- (t2/delete! :model/DataApp app-id)
+ (t2/delete! :model/DataApp :id app-id)
(deps.test/synchronously-run-dependency-job!)
(is (empty? (data-app-deps app-id)))
(is (not (t2/exists? :model/DependencyStatus :entity_type :data-app :entity_id app-id))))))))))
@@ -1252,10 +1252,10 @@
:model/Collection collection {:namespace "data-apps"}
:model/Card card {:dataset_query (lib/query mp (lib.metadata/table mp (mt/id :venues)))
:collection_id (:id collection)}]
- (t2/delete! :model/Collection (:resource_collection_id app))
+ (t2/delete! :model/Collection :id (:resource_collection_id app))
(deps.test/synchronously-run-dependency-job!)
(is (empty? (data-app-deps (:id app))))
- (t2/update! :model/DataApp (:id app) {:resource_collection_id (:id collection)})
+ (t2/update! :model/DataApp :id (:id app) {:resource_collection_id (:id collection)})
(assert-pending :data-app (:id app))
(deps.test/synchronously-run-dependency-job!)
(is (= #{[:card (:id card)]} (data-app-deps (:id app))))))))))
@@ -1269,7 +1269,7 @@
:bundle_path "birds.js"
:bundle (byte-array [1 2 3])}]
(testing "a full row read counts"
- (is (seq (deps.test/data-app-bundle-reads #(t2/select-one :model/DataApp app-id)))))
+ (is (seq (deps.test/data-app-bundle-reads #(t2/select-one :model/DataApp :id app-id)))))
(is (= [] (deps.test/data-app-bundle-reads deps.test/synchronously-run-dependency-job!)))
(assert-processed :data-app app-id))))))
@@ -1283,7 +1283,7 @@
:model/Collection {other-collection-id :id} {}]
(mt/with-model-cleanup [:model/Card]
(testing "a full row read counts"
- (is (seq (deps.test/data-app-bundle-reads #(t2/select-one :model/DataApp app-id)))))
+ (is (seq (deps.test/data-app-bundle-reads #(t2/select-one :model/DataApp :id app-id)))))
(testing "adding a card"
(let [card (assoc (mt/with-temp-defaults :model/Card)
:collection_id collection-id
@@ -1292,9 +1292,9 @@
(let [card-id (t2/select-one-pk :model/Card :collection_id collection-id)]
(testing "moving a card out"
(is (= [] (deps.test/data-app-bundle-reads
- #(t2/update! :model/Card card-id {:collection_id other-collection-id})))))
+ #(t2/update! :model/Card :id card-id {:collection_id other-collection-id})))))
(testing "moving a card in"
(is (= [] (deps.test/data-app-bundle-reads
- #(t2/update! :model/Card card-id {:collection_id collection-id})))))
+ #(t2/update! :model/Card :id card-id {:collection_id collection-id})))))
(testing "deleting a card"
- (is (= [] (deps.test/data-app-bundle-reads #(t2/delete! :model/Card card-id)))))))))))))
+ (is (= [] (deps.test/data-app-bundle-reads #(t2/delete! :model/Card :id card-id)))))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/impersonation/driver_test.clj b/enterprise/backend/test/metabase_enterprise/impersonation/driver_test.clj
index e594f9da75d..de84b678d69 100644
--- a/enterprise/backend/test/metabase_enterprise/impersonation/driver_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/impersonation/driver_test.clj
@@ -923,7 +923,7 @@
(mt/as-admin (persist-models!))
(impersonation.util-test/with-impersonations! {:impersonations [{:db-id (mt/id) :attribute "impersonation_attr"}]
:attributes {"impersonation_attr" "impersonation_role"}}
- (let [details (t2/select-one-fn :details :model/Database (mt/id))
+ (let [details (t2/select-one-fn :details :model/Database :id (mt/id))
spec (sql-jdbc.conn/connection-details->spec :postgres details)]
;; Create impersonation_role on test DB so that the non-admin can execute queries
(doseq [statement ["DROP ROLE IF EXISTS \"impersonation_role\";"
@@ -1031,7 +1031,7 @@
(with-impersonation-db!
(let [tables-set #(->> (driver/describe-database
driver/*driver*
- (driver.u/ensure-lib-database (t2/select-one :model/Database (mt/id))))
+ (driver.u/ensure-lib-database (t2/select-one :model/Database :id (mt/id))))
:tables
(into #{}))
default-table-set (tables-set)]
diff --git a/enterprise/backend/test/metabase_enterprise/library/validation_test.clj b/enterprise/backend/test/metabase_enterprise/library/validation_test.clj
index ede7f39ff66..2f88c51badd 100644
--- a/enterprise/backend/test/metabase_enterprise/library/validation_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/library/validation_test.clj
@@ -89,7 +89,7 @@
(t2/insert! :model/Card (merge (mt/with-temp-defaults :model/Card) {:type card-type :collection_id (:id allow-dashboards)}))))))
(testing "Cannot turn a dashboard question into a standalone question"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Can only add dashboards to the 'Dashboards' collection"
- (t2/update! :model/Card (:id dashboard-card) {:dashboard_id nil}))))
+ (t2/update! :model/Card :id (:id dashboard-card) {:dashboard_id nil}))))
(testing "Can add collections iff they have the same :type"
(let [new-coll (merge (mt/with-temp-defaults :model/Collection)
{:location (str "/" (:id allow-dashboards) "/")})]
@@ -118,7 +118,7 @@
:model/Card metric {:collection_id (:id allow-metrics) :type :metric}]
(testing "A metric can't be moved into the Dashboards collection by giving it a dashboard"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Can only add dashboards to the 'Dashboards' collection"
- (t2/update! :model/Card (:id metric) {:dashboard_id (:id dashboard)}))))
+ (t2/update! :model/Card :id (:id metric) {:dashboard_id (:id dashboard)}))))
(testing "Serdes loads dashboard questions before their dashboard"
(binding [mi/*deserializing?* true]
(is (some? (t2/insert! :model/Card (merge (mt/with-temp-defaults :model/Card)
@@ -176,9 +176,9 @@
:is_published true})))))
(testing "Cannot move a published table to a regular collection"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Tables can only be added to"
- (t2/update! :model/Table (:id table) {:collection_id (:id regular)}))))
+ (t2/update! :model/Table :id (:id table) {:collection_id (:id regular)}))))
(testing "Can move a table out to no collection"
- (is (some? (t2/update! :model/Table (:id table) {:collection_id nil})))))))
+ (is (some? (t2/update! :model/Table :id (:id table) {:collection_id nil})))))))
(deftest cannot-update-library-collections
(mt/with-premium-features #{:library}
@@ -191,7 +191,7 @@
(testing (str "Checking type " (:type col))
(is (thrown-with-msg? clojure.lang.ExceptionInfo
#"Cannot update properties on a semantic layer collection"
- (t2/update! :model/Collection (:id col) {:name "New Name"})))))))))
+ (t2/update! :model/Collection :id (:id col) {:name "New Name"})))))))))
(deftest unpublish-tables-in-archived-collection-test
(mt/with-premium-features #{:library}
@@ -263,11 +263,11 @@
:location (str "/" (:id metrics-parent) "/")}]
(testing "Cannot move a library-data collection into a library-metrics parent"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Can only add metrics"
- (t2/update! :model/Collection (:id data-child)
+ (t2/update! :model/Collection :id (:id data-child)
{:location (str "/" (:id metrics-parent) "/")}))))
(testing "Cannot move a library-metrics collection into a library-data parent"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Can only add tables"
- (t2/update! :model/Collection (:id metrics-child)
+ (t2/update! :model/Collection :id (:id metrics-child)
{:location (str "/" (:id data-parent) "/")}))))
(testing "Cannot move a library-data collection via API to a library-metrics parent"
(is (= "Can only add metrics to the 'Metrics' collection"
@@ -296,16 +296,16 @@
(:id coll)))]
(testing "Cannot move the Library collection itself into a vanilla collection"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Cannot update properties on a semantic layer collection"
- (t2/update! :model/Collection (:id library-root) {:location vanilla-location}))))
+ (t2/update! :model/Collection :id (:id library-root) {:location vanilla-location}))))
(testing "Cannot move a top-level Data collection into a vanilla collection"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Cannot update properties on a semantic layer collection"
- (t2/update! :model/Collection (:id data-root) {:location vanilla-location}))))
+ (t2/update! :model/Collection :id (:id data-root) {:location vanilla-location}))))
(testing "Cannot move a top-level Metrics collection into a vanilla collection"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Cannot update properties on a semantic layer collection"
- (t2/update! :model/Collection (:id metrics-root) {:location vanilla-location})))))
+ (t2/update! :model/Collection :id (:id metrics-root) {:location vanilla-location})))))
(testing "Cannot move a Data subcollection into a vanilla collection"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Cannot move a semantic layer collection outside the semantic layer"
- (t2/update! :model/Collection (:id data-sub) {:location vanilla-location}))))
+ (t2/update! :model/Collection :id (:id data-sub) {:location vanilla-location}))))
(testing "Cannot move a Metrics subcollection into a vanilla collection"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Cannot move a semantic layer collection outside the semantic layer"
- (t2/update! :model/Collection (:id metrics-sub) {:location vanilla-location}))))))))
+ (t2/update! :model/Collection :id (:id metrics-sub) {:location vanilla-location}))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/metabot/tools/construct_test.clj b/enterprise/backend/test/metabase_enterprise/metabot/tools/construct_test.clj
index ba5e69205ec..8083f68cb51 100644
--- a/enterprise/backend/test/metabase_enterprise/metabot/tools/construct_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/metabot/tools/construct_test.clj
@@ -28,7 +28,7 @@
(mapv #(lib.metadata/field mp (mt/id table %)) fields))))
(defn- source-field-query [key-table key-column target-table]
- (let [db (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))
field #(vector db "PUBLIC" %1 %2)]
{:lib/type "mbql/query"
:stages [{:lib/type "mbql.stage/mbql" :source-table [db "PUBLIC" "CHECKINS"]
@@ -87,7 +87,7 @@
(perms/set-table-permission! &group (mt/id :venues) :perms/create-queries :query-builder)
(mt/with-temp-vals-in-db :model/Database (mt/id) {:name "Native sandbox"}
(let [card-id (t2/select-one-fn :card_id :model/Sandbox :table_id (mt/id :checkins) :group_id (u/the-id &group))
- card-before (t2/select-one :model/Card card-id)
+ card-before (t2/select-one :model/Card :id card-id)
snapshot #(hash-map :executions (t2/count :model/QueryExecution) :cache (t2/count :model/QueryCache))
before (snapshot)
build! #(construct/execute-representations-query (source-field-query "CHECKINS" "VENUE_ID" "VENUES"))
@@ -99,14 +99,14 @@
control (binding [qp.pipeline/*execute* observe-execute]
(mt/with-dynamic-fn-redefs [construct/assert-source-fields-reach-their-tables! identity]
(build!)))
- card-after-control (t2/select-one :model/Card card-id)
+ card-after-control (t2/select-one :model/Card :id card-id)
actual (binding [qp.pipeline/*execute* observe-execute] (build!))]
(is (nil? (:result_metadata card-before)))
(is (= card-before card-after-control))
(is (map? (get-in actual [:structured-output :query])))
(is (empty? @warehouse) "Construction must not execute warehouse SQL")
(is (not-any? :admin @warehouse) "Construction must not execute SQL as admin")
- (is (= card-before (t2/select-one :model/Card card-id)) "Construction must not write Card metadata")
+ (is (= card-before (t2/select-one :model/Card :id card-id)) "Construction must not write Card metadata")
(is (= before (snapshot)))
(let [control-result (qp/process-query (get-in control [:structured-output :query]))
actual-result (qp/process-query (get-in actual [:structured-output :query]))]
@@ -130,7 +130,7 @@
(lib/query mp (lib.metadata/table mp (mt/id :venues))))
:remappings {:cat ["variable" [:field (mt/id :venues :category_id) nil]]}}}
:attributes attributes}
- (t2/update! :model/Database (mt/id) {:name "Metabot sandbox"})
+ (t2/update! :model/Database :id (mt/id) {:name "Metabot sandbox"})
(let [query (count-query "VENUES")]
(doseq [tool [construct/construct-notebook-query-tool
slackbot-query/slackbot-construct-notebook-query-tool]]
@@ -144,7 +144,7 @@
(deftest construct-tools-preprocess-sandboxed-queries-test
(met/with-gtaps! {:gtaps {:orders {:query (orders-sandbox-query)}}}
- (t2/update! :model/Database (mt/id) {:name "Metabot sandbox"})
+ (t2/update! :model/Database :id (mt/id) {:name "Metabot sandbox"})
(let [compilations (atom 0)
executions (atom 0)
query (count-query "ORDERS")]
@@ -174,7 +174,7 @@
(met/with-gtaps! {:gtaps {:venues {:query (lib/native-query
(mt/metadata-provider)
"SELECT ID, NAME, CATEGORY_ID, PRICE FROM VENUES WHERE PRICE = 1")}}}
- (t2/update! :model/Database (mt/id) {:name "Metabot sandbox"})
+ (t2/update! :model/Database :id (mt/id) {:name "Metabot sandbox"})
(let [card-id (t2/select-one-fn :card_id :model/Sandbox :table_id (mt/id :venues))
executions (atom 0)
execute qp.pipeline/*execute*
diff --git a/enterprise/backend/test/metabase_enterprise/metabot/tools/field_stats_test.clj b/enterprise/backend/test/metabase_enterprise/metabot/tools/field_stats_test.clj
index e7031e16ffa..77b0ad4fde8 100644
--- a/enterprise/backend/test/metabase_enterprise/metabot/tools/field_stats_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/metabot/tools/field_stats_test.clj
@@ -49,7 +49,7 @@
(try
;; Clear the fingerprint -- pre-#436 (and pre this fix, for this call site) this would have
;; forced an unsandboxed on-demand refingerprint via get-or-create-fingerprint!.
- (t2/update! :model/Field field-id {:fingerprint nil :fingerprint_version 0})
+ (t2/update! :model/Field :id field-id {:fingerprint nil :fingerprint_version 0})
(let [result (metabot.tools.field-stats/field-values
{:entity-type "table", :entity-id table-id, :field-id field-id})]
(testing "no fingerprint statistics are returned to the sandboxed user"
@@ -57,7 +57,7 @@
(testing "no fingerprint was computed or saved to the shared Field row"
(is (nil? (t2/select-one-fn :fingerprint :model/Field :id field-id)))))
(finally
- (t2/update! :model/Field field-id {:fingerprint original-fp})))))))
+ (t2/update! :model/Field :id field-id {:fingerprint original-fp})))))))
(deftest fingerprint-withheld-for-sandboxed-user-test
(testing "An existing global fingerprint is withheld from a sandboxed user, even though it's already
@@ -117,12 +117,12 @@
(is (nil? (get-in result [:structured-output :value_metadata :statistics])))))
(testing "a missing fingerprint is not computed or saved"
(try
- (t2/update! :model/Field field-id {:fingerprint nil :fingerprint_version 0})
+ (t2/update! :model/Field :id field-id {:fingerprint nil :fingerprint_version 0})
(metabot.tools.field-stats/field-values
{:entity-type "table", :entity-id table-id, :field-id field-id})
(is (nil? (t2/select-one-fn :fingerprint :model/Field :id field-id)))
(finally
- (t2/update! :model/Field field-id {:fingerprint original-fp})))))))))
+ (t2/update! :model/Field :id field-id {:fingerprint original-fp})))))))))
(deftest fingerprint-withheld-for-routed-user-test
(testing "A database-routed user gets no fingerprint statistics, and no on-demand refingerprint is
@@ -140,7 +140,7 @@
{:entity-type "table", :entity-id (:id table), :field-id (:id field)})]
(is (nil? (get-in result [:structured-output :value_metadata :statistics])))))
(testing "a missing fingerprint is not computed or saved"
- (t2/update! :model/Field (:id field) {:fingerprint nil :fingerprint_version 0})
+ (t2/update! :model/Field :id (:id field) {:fingerprint nil :fingerprint_version 0})
(metabot.tools.field-stats/field-values
{:entity-type "table", :entity-id (:id table), :field-id (:id field)})
(is (nil? (t2/select-one-fn :fingerprint :model/Field :id (:id field))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/mfa/email_otp_test.clj b/enterprise/backend/test/metabase_enterprise/mfa/email_otp_test.clj
index c45f86a8995..58bc79288d5 100644
--- a/enterprise/backend/test/metabase_enterprise/mfa/email_otp_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/mfa/email_otp_test.clj
@@ -69,7 +69,7 @@
(let [code (verification/set-email-otp! user-id)]
;; back-date the expiry
(let [ai (t2/select-one :model/AuthIdentity :id ai-id)]
- (t2/update! :model/AuthIdentity ai-id
+ (t2/update! :model/AuthIdentity :id ai-id
{:credentials (assoc-in (:credentials ai) [:email_otp :exp]
(dec (quot (System/currentTimeMillis) 1000)))}))
(is (false? (boolean (verification/verify-attempt! user-id code (fresh-jti)))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/mfa/login_flow_test.clj b/enterprise/backend/test/metabase_enterprise/mfa/login_flow_test.clj
index 3373b030f17..e80708a69c7 100644
--- a/enterprise/backend/test/metabase_enterprise/mfa/login_flow_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/mfa/login_flow_test.clj
@@ -150,13 +150,13 @@
(deftest deactivated-user-cannot-verify-test
(with-enrolled-rasta! [secret]
(let [resp (mt/client :post 200 "session" (mt/user->credentials :rasta))]
- (t2/update! :model/User (mt/user->id :rasta) {:is_active false})
+ (t2/update! :model/User :id (mt/user->id :rasta) {:is_active false})
(try
(testing "a challenge token does not outlive the account: deactivated mid-challenge gets the same 401 as a bad token"
(mt/client :post 401 "session/mfa/verify"
{:challenge_token (:challenge_token resp) :code (totp/generate-code secret)}))
(finally
- (t2/update! :model/User (mt/user->id :rasta) {:is_active true}))))))
+ (t2/update! :model/User :id (mt/user->id :rasta) {:is_active true}))))))
(deftest successful-verify-does-not-count-toward-throttle-test
(with-enrolled-rasta! [secret]
diff --git a/enterprise/backend/test/metabase_enterprise/mfa/verification_test.clj b/enterprise/backend/test/metabase_enterprise/mfa/verification_test.clj
index 7b938ec323b..7f8cce16974 100644
--- a/enterprise/backend/test/metabase_enterprise/mfa/verification_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/mfa/verification_test.clj
@@ -188,7 +188,7 @@
rotated (encryption-test/with-secret-key k2
(encryption/maybe-encrypt plaintext))]
(is (encryption/possibly-encrypted-string? raw) "sanity: stored under key A as ciphertext")
- (t2/update! :auth_identity ai-id {:credentials rotated}))
+ (t2/update! :auth_identity :id ai-id {:credentials rotated}))
(encryption-test/with-secret-key k2
(is (true? (boolean (verification/verify-attempt! user-id (totp/generate-code secret) (fresh-jti))))
"the rotated enrollment verifies under the new key"))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
index 21cc2b07293..482418b4430 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
@@ -1023,7 +1023,7 @@
(let [task (pull!)]
(is (remote-sync.task/successful? task))
(is (= "pulled" (get-in task [:outcome :kind]))))
- (is (not (t2/exists? :model/Card (:id model))))
+ (is (not (t2/exists? :model/Card :id (:id model))))
(is (false? (remote-sync.object/dirty?)))
(is (not (t2/exists? :model/RemoteSyncObject :model_type "Action")))))))
@@ -1036,7 +1036,7 @@
(let [task (pull!)]
(is (remote-sync.task/successful? task))
(is (= "pulled" (get-in task [:outcome :kind]))))
- (is (= :question (t2/select-one-fn :type :model/Card (:id model))))
+ (is (= :question (t2/select-one-fn :type :model/Card :id (:id model))))
(is (false? (remote-sync.object/dirty?)))
(is (not (t2/exists? :model/RemoteSyncObject :model_type "Action")))))))
@@ -1088,8 +1088,8 @@
(testing "a normal pull after another instance's change keeps the action"
(commit-remote! {:upsert {model-path (str/replace (repo-file model-path) "name: Venues Model" "name: Renamed Model")}})
(is (remote-sync.task/successful? (pull!)))
- (is (= "Renamed Model" (t2/select-one-fn :name :model/Card (:id model))))
- (is (t2/exists? :model/Action action-id))))))))
+ (is (= "Renamed Model" (t2/select-one-fn :name :model/Card :id (:id model))))
+ (is (t2/exists? :model/Action :id action-id))))))))
;;; ------------------------------------------------- Current Task Endpoint -------------------------------------------------
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/card_api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/card_api_test.clj
index 83aafb8b8bb..abf9704bc42 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/card_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/card_api_test.clj
@@ -29,7 +29,7 @@
(is (= "Uses content that is not remote synced." (:message response)))
(is (seq (:non-remote-synced-models response))))
(testing "card is not moved - transaction rolled back"
- (is (nil? (t2/select-one-fn :collection_id :model/Card root-card-id)))))))
+ (is (nil? (t2/select-one-fn :collection_id :model/Card :id root-card-id)))))))
(deftest bulk-move-depended-on-card-out-of-remote-synced-test
(testing "POST /api/card/collections rejects bulk-moving a remote-synced card that is depended on by other remote-synced content out of the synced set (GHY-3791)"
@@ -47,7 +47,7 @@
(is (= "Used by remote synced content." (:message response)))
(is (seq (:remote-synced-models response))))
(testing "card is not moved - transaction rolled back"
- (is (= synced-id (t2/select-one-fn :collection_id :model/Card source-card-id)))))))
+ (is (= synced-id (t2/select-one-fn :collection_id :model/Card :id source-card-id)))))))
(deftest bulk-move-into-remote-synced-with-remote-synced-deps-succeeds-test
(testing "POST /api/card/collections allows bulk-moving a card whose dependencies are all remote-synced into a remote-synced collection (GHY-3791)"
@@ -62,4 +62,4 @@
(mt/user-http-request :crowberto :post 200 "card/collections"
{:collection_id synced-id
:card_ids [mover-id]})))
- (is (= synced-id (t2/select-one-fn :collection_id :model/Card mover-id))))))
+ (is (= synced-id (t2/select-one-fn :collection_id :model/Card :id mover-id))))))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/content_hash_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/content_hash_test.clj
index e482a04caff..405803a99bb 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/content_hash_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/content_hash_test.clj
@@ -184,7 +184,7 @@
:status "synced"
:content_hash (source/row->content-hash {:model_type "Card" :model_id (:id card)})
:status_changed_at (t/offset-date-time)})
- (t2/update! :model/Card (:id card) {:name "Renamed"})
+ (t2/update! :model/Card :id (:id card) {:name "Renamed"})
(events/publish-event! :event/card-update {:object (t2/select-one :model/Card :id (:id card))
:previous-object card
:user-id (mt/user->id :rasta)})
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/custom_collections_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/custom_collections_test.clj
index 6445ff5b2d8..c684e343833 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/custom_collections_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/custom_collections_test.clj
@@ -46,14 +46,14 @@
:is_remote_synced true})))))
(mt/with-temp [:model/Collection {coll-id :id} {:location "/"}]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"syncs only the Library"
- (t2/update! :model/Collection coll-id {:type "remote-synced"})))))))
+ (t2/update! :model/Collection :id coll-id {:type "remote-synced"})))))))
(deftest keeps-synced-collections-editable-test
(mt/with-temp [:model/Collection {coll-id :id} {:location "/"}]
(t2/query {:update :collection :set {:is_remote_synced true} :where [:= :id coll-id]})
- (t2/update! :model/Collection coll-id {:name "Renamed"})
+ (t2/update! :model/Collection :id coll-id {:name "Renamed"})
(is (= "Renamed" (t2/select-one-fn :name :model/Collection :id coll-id)))
- (t2/update! :model/Collection coll-id {:is_remote_synced false})
+ (t2/update! :model/Collection :id coll-id {:is_remote_synced false})
(is (false? (t2/select-one-fn :is_remote_synced :model/Collection :id coll-id)))))
(deftest allows-library-and-other-namespaces-test
@@ -63,8 +63,8 @@
(fn []
(let [library (collection/create-library-collection!)
data (t2/select-one :model/Collection :type collection/library-data-collection-type)]
- (t2/update! :model/Collection (:id library) {:is_remote_synced true})
- (t2/update! :model/Collection (:id data) {:is_remote_synced true})
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced true})
+ (t2/update! :model/Collection :id (:id data) {:is_remote_synced true})
(is (true? (t2/select-one-fn :is_remote_synced :model/Collection :id (:id data))))
(mt/with-temp [:model/Collection {inner-id :id} {:location (str (:location data) (:id data) "/") :type nil :is_remote_synced true}]
(is (true? (t2/select-one-fn :is_remote_synced :model/Collection :id inner-id))))))))
@@ -92,7 +92,7 @@
(settings/remote-sync-custom-collections-enabled! "false")))
(mt/user-http-request :crowberto :put 400 "setting/remote-sync-custom-collections-enabled" {:value false})
(is (true? (settings/remote-sync-custom-collections-enabled)))
- (t2/update! :model/Collection coll-id {:is_remote_synced false})
+ (t2/update! :model/Collection :id coll-id {:is_remote_synced false})
(settings/remote-sync-custom-collections-enabled! false)
(is (false? (settings/remote-sync-custom-collections-enabled))))))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj
index 72d1605ed92..ff401e75d40 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj
@@ -438,7 +438,7 @@
(collection/check-allowed-content :dashboard-question collection-id))))
(mt/with-temp [:model/Dashboard {dashboard-id :id} {:name "Elsewhere"}]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"can hold only questions, metrics, and query actions"
- (t2/update! :model/Dashboard dashboard-id {:collection_id collection-id})))
+ (t2/update! :model/Dashboard :id dashboard-id {:collection_id collection-id})))
(is (nil? (t2/select-one-fn :collection_id :model/Dashboard :id dashboard-id)))))))))
(deftest a-card-in-an-apps-collection-stays-what-a-pull-accepts-test
@@ -454,9 +454,9 @@
(mt/with-temporary-setting-values [enable-public-sharing true]
(mt/user-http-request :crowberto :post 400 (str "card/" card-id "/public_link")))
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"must be a question or metric"
- (t2/update! :model/Card card-id {:archived true})))
+ (t2/update! :model/Card :id card-id {:archived true})))
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"must be a question or metric"
- (t2/update! :model/Card card-id {:type :model})))
+ (t2/update! :model/Card :id card-id {:type :model})))
(is (=? {:archived false :public_uuid nil :type :question} (t2/select-one :model/Card :id card-id))))
(testing "a card that is already public can't be moved in"
(mt/with-temp [:model/Card {public-id :id} {:name "Already public"
@@ -464,7 +464,7 @@
:public_uuid (str (random-uuid))
:made_public_by_id (mt/user->id :crowberto)}]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"must be a question or metric"
- (t2/update! :model/Card public-id {:collection_id collection-id})))
+ (t2/update! :model/Card :id public-id {:collection_id collection-id})))
(is (nil? (t2/select-one-fn :collection_id :model/Card :id public-id)))))
(testing "the export keeps its file"
(is (= :success (:status (export! mock))))
@@ -575,7 +575,7 @@
(is (= :success (:status (import-at! mock "main" :force? true))))
(let [before (resource-files mock)]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"stays a top-level collection of data apps"
- (t2/update! :model/Collection (shop-collection-id) {:archived true})))
+ (t2/update! :model/Collection :id (shop-collection-id) {:archived true})))
(is (= :success (:status (export! mock))))
(is (= before (resource-files mock)))
(testing "deleting the app still deletes its collection"
@@ -662,12 +662,12 @@
(let [query-before (t2/select-one-fn :dataset_query :model/Card :id card-id)]
(and (is (thrown-with-msg? clojure.lang.ExceptionInfo message (save! query)))
(is (thrown-with-msg? clojure.lang.ExceptionInfo message
- (t2/update! :model/Card card-id {:dataset_query query})))
+ (t2/update! :model/Card :id card-id {:dataset_query query})))
(is (= query-before (t2/select-one-fn :dataset_query :model/Card :id card-id))))))]
(testing "a table published to the Library, and a Library metric, are fine"
(save! venues)
(save! (lib/aggregate venues (lib.metadata/metric mp library-metric-id)))
- (t2/update! :model/Card card-id {:dataset_query (lib/aggregate venues (lib/count))}))
+ (t2/update! :model/Card :id card-id {:dataset_query (lib/aggregate venues (lib/count))}))
(testing "a table that isn't published is refused"
(refused? #"can read only tables published to the Library, not USERS"
(lib/query mp (lib.metadata/table mp (mt/id :users)))))
@@ -700,7 +700,7 @@
(let [card-id (t2/select-one-pk :model/Card :entity_id question-eid)]
(mt/with-temporary-setting-values [enable-embedding-modular true]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"must be a question or metric"
- (t2/update! :model/Card card-id {:embedding_params {}})))
+ (t2/update! :model/Card :id card-id {:embedding_params {}})))
(testing "a card elsewhere takes them"
(mt/with-temp [:model/Card {other-id :id} {:name "Elsewhere"}]
(mt/user-http-request :crowberto :put 200 (str "card/" other-id) {:embedding_params {}}))))
@@ -715,7 +715,7 @@
(let [collection-id (shop-collection-id)
before (resource-files mock)]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"stays a top-level collection of data apps"
- (t2/update! :model/Collection collection-id {:authority_level "official"})))
+ (t2/update! :model/Collection :id collection-id {:authority_level "official"})))
(mt/with-temp [:model/Collection other {:name "Other root" :namespace :data-apps}]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"You cannot move a data app's collection"
(collection/move-collection! (t2/select-one :model/Collection :id collection-id)
@@ -739,7 +739,7 @@
(let [copy-id (t2/select-one-pk :model/Action :collection_id (shop-collection-id))
before (resource-files mock)]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"can't be archived"
- (t2/update! :model/Action copy-id {:archived true})))
+ (t2/update! :model/Action :id copy-id {:archived true})))
(testing "the source can still be archived"
(mt/with-actions-enabled
(mt/user-http-request :crowberto :put 200 (str "action/" action-id) {:archived true})))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
index 85d45d84247..5364075ffb1 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
@@ -202,7 +202,7 @@
(t2/insert! :model/RemoteSyncObject {:model_type "Action" :model_id action-id :model_name "Create Venue"
:model_collection_id synced-id :status "synced"
:status_changed_at (t/offset-date-time)})
- (t2/update! :model/Card model-id {:collection_id plain-id})
+ (t2/update! :model/Card :id model-id {:collection_id plain-id})
(events/publish-event! :event/action-update {:object (t2/select-one :model/Action :id action-id)
:user-id (mt/user->id :rasta)})
(is (=? {:status "removed"} (action-rso action-id)))))))
@@ -447,7 +447,7 @@
(deftest snippet-event-when-library-not-synced-no-entry-test
(testing "snippet events don't create entries when Library is not synced"
(when-let [library (collection/library-collection)]
- (t2/update! :model/Collection (:id library) {:is_remote_synced false}))
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced false}))
(mt/with-temp [:model/Collection snippet-collection {:name "Snippets" :namespace "snippets"}
:model/NativeQuerySnippet snippet {:name "Test Snippet"
:content "SELECT 1"
@@ -1059,14 +1059,14 @@
:collection_id (:id remote-sync-collection)}]
(track-as-synced! "Document" doc)
;; Trash the doc
- (t2/update! :model/Document (:id doc) {:archived true})
+ (t2/update! :model/Document :id (:id doc) {:archived true})
(events/publish-event! :event/document-update
{:object (assoc doc :archived true)
:user-id (mt/user->id :rasta)})
(let [soft-delete-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id doc))]
(is (= "delete" (:status soft-delete-entry))))
;; Permanently delete from trash
- (t2/delete! :model/Document (:id doc))
+ (t2/delete! :model/Document :id (:id doc))
(events/publish-event! :event/document-delete
{:object doc :user-id (mt/user->id :rasta)})
;; The remote sync object entry should still exist with delete status
@@ -1216,7 +1216,7 @@
["FieldUserSettings" (:id curated) "update"]
["Dimension" (:id remapped) "update"]}
(tracked)))
- (t2/update! :model/TableUserSettings (:id table) {:is_published false :collection_id nil})
+ (t2/update! :model/TableUserSettings :table_id (:id table) {:is_published false :collection_id nil})
(events/publish-event! :event/table-unpublish
{:object (assoc table :is_published false :collection_id nil)
:user-id (mt/user->id :rasta)})
@@ -1612,7 +1612,7 @@
:model_table_id (:id table)
:status "synced"
:status_changed_at (t/offset-date-time)})
- (t2/update! :model/Table (:id table) {:collection_id (:id normal)})
+ (t2/update! :model/Table :id (:id table) {:collection_id (:id normal)})
(events/publish-event! :event/field-update {:object field :user-id (mt/user->id :rasta)})
(is (=? [{:model_type "FieldUserSettings" :model_id (:id field) :status "removed"}]
(t2/select :model/RemoteSyncObject))))))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj
index c4a541f9ec6..ea54bf179d6 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj
@@ -121,11 +121,11 @@
{:object (t2/select-one :model/Collection :id (:id library))
:user-id (mt/user->id :rasta)}))]
(testing "the Library becoming remote-synced tracks existing entries"
- (t2/update! :model/Collection (:id library) {:is_remote_synced true})
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced true})
(publish!)
(is (=? {:status "create"} (rso entry))))
(testing "the Library ceasing to be remote-synced removes their tracking rows"
- (t2/update! :model/Collection (:id library) {:is_remote_synced false})
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced false})
(publish!)
(is (nil? (rso entry))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj
index aaa7868d980..03dc4dbfb2d 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj
@@ -111,7 +111,7 @@
(let [a-eid (t2/select-one-fn :entity_id :model/Card :id card-a)
a-path (path-for-eid mock a-eid)
files-before (files mock)]
- (t2/update! :model/Card card-a {:description "edited in place"})
+ (t2/update! :model/Card :id card-a {:description "edited in place"})
(set-status! "Card" card-a "update")
(let [task (new-task!)
result (impl/export! (source.p/snapshot mock) task "edit")
@@ -128,8 +128,8 @@
(deftest multiple-in-place-updates-use-incremental-path-test
(with-exported-collection!
(fn [{:keys [mock card-a card-b]}]
- (t2/update! :model/Card card-a {:description "edit A"})
- (t2/update! :model/Card card-b {:description "edit B"})
+ (t2/update! :model/Card :id card-a {:description "edit A"})
+ (t2/update! :model/Card :id card-b {:description "edit B"})
(set-status! "Card" card-a "update")
(set-status! "Card" card-b "update")
(let [task (new-task!)
@@ -143,7 +143,7 @@
(deftest collection-in-place-edit-uses-incremental-path-test
(with-exported-collection!
(fn [{:keys [mock coll-id]}]
- (t2/update! :model/Collection coll-id {:description "collection note"})
+ (t2/update! :model/Collection :id coll-id {:description "collection note"})
(set-status! "Collection" coll-id "update")
(let [task (new-task!)
result (impl/export! (source.p/snapshot mock) task "edit collection")]
@@ -155,7 +155,7 @@
(testing "GHY-4642: a collection's path is its contents' directory, so a rename re-exports everything and moves the contents"
(with-exported-collection!
(fn [{:keys [mock coll-id card-a card-b]}]
- (t2/update! :model/Collection coll-id {:name "Marketing Reports"})
+ (t2/update! :model/Collection :id coll-id {:name "Marketing Reports"})
(set-status! "Collection" coll-id "update")
(let [task (new-task!)
result (impl/export! (source.p/snapshot mock) task "rename collection")]
@@ -173,7 +173,7 @@
(fn [{:keys [mock card-a]}]
(let [a-eid (t2/select-one-fn :entity_id :model/Card :id card-a)
old-path (path-for-eid mock a-eid)]
- (t2/update! :model/Card card-a {:name "Card A Renamed"})
+ (t2/update! :model/Card :id card-a {:name "Card A Renamed"})
(set-status! "Card" card-a "update")
(let [task (new-task!)
result (impl/export! (source.p/snapshot mock) task "rename")
@@ -196,7 +196,7 @@
b-path (path-for-eid mock b-eid)]
;; A real delete means the entity is archived, so it can't be re-serialized — the incremental
;; delete must work from the stored file_path alone, without re-extracting the entity.
- (t2/update! :model/Card card-b {:archived true})
+ (t2/update! :model/Card :id card-b {:archived true})
(set-status! "Card" card-b "delete")
(let [task (new-task!)
result (impl/export! (source.p/snapshot mock) task "delete B")
@@ -305,7 +305,7 @@
;; Simulate the post-import state where file_path hasn't been recorded yet: a rename then can't
;; resolve the old path, so we fall back to the full export (which reconciles stale files).
(t2/update! :model/RemoteSyncObject :model_type "Card" :model_id card-a {:file_path nil})
- (t2/update! :model/Card card-a {:name "Card A Renamed"})
+ (t2/update! :model/Card :id card-a {:name "Card A Renamed"})
(set-status! "Card" card-a "update")
(let [task (new-task!)
result (impl/export! (source.p/snapshot mock) task "rename")]
@@ -318,7 +318,7 @@
(fn [{:keys [mock card-b]}]
;; A real delete (archive) with no stored file_path can't resolve its path incrementally, so it
;; falls back to full — which drops the archived entity's file, producing a real commit.
- (t2/update! :model/Card card-b {:archived true})
+ (t2/update! :model/Card :id card-b {:archived true})
(t2/update! :model/RemoteSyncObject :model_type "Card" :model_id card-b {:file_path nil})
(set-status! "Card" card-b "delete")
(let [task (new-task!)
@@ -365,7 +365,7 @@
(fn [{:keys [mock card-a card-b]}]
;; One incremental-able update batched with a delete that has no stored path (so it can't be
;; handled incrementally) -> the whole batch falls back to a full export.
- (t2/update! :model/Card card-a {:description "edit A"})
+ (t2/update! :model/Card :id card-a {:description "edit A"})
(set-status! "Card" card-a "update")
(t2/update! :model/RemoteSyncObject :model_type "Card" :model_id card-b {:file_path nil})
(set-status! "Card" card-b "delete")
@@ -385,7 +385,7 @@
(t2/update! :model/RemoteSyncObject :model_type "Card" :model_id card-a {:file_path nil})
(swap! (:files-atom mock) assoc-in ["main" a-path]
(str/replace (get (files mock) a-path) a-eid "different0entity0id0x"))
- (t2/update! :model/Card card-a {:description "edit A"})
+ (t2/update! :model/Card :id card-a {:description "edit A"})
(set-status! "Card" card-a "update")
(let [task (new-task!)
result (impl/export! (source.p/snapshot mock) task "collision")]
@@ -403,7 +403,7 @@
;; occupied — not free — and fall back to full rather than clobber an unidentifiable entity.
(t2/update! :model/RemoteSyncObject :model_type "Card" :model_id card-a {:file_path nil})
(swap! (:files-atom mock) assoc-in ["main" a-path] "name: Not A Serialized Entity\nother: value\n")
- (t2/update! :model/Card card-a {:description "edit A"})
+ (t2/update! :model/Card :id card-a {:description "edit A"})
(set-status! "Card" card-a "update")
(let [task (new-task!)
result (impl/export! (source.p/snapshot mock) task "unparseable occupant")]
@@ -421,7 +421,7 @@
;; export rather than crashing the whole export.
(t2/update! :model/RemoteSyncObject :model_type "Card" :model_id card-a {:file_path nil})
(swap! (:files-atom mock) assoc-in ["main" a-path] "a: b: c")
- (t2/update! :model/Card card-a {:description "edit A"})
+ (t2/update! :model/Card :id card-a {:description "edit A"})
(set-status! "Card" card-a "update")
(let [task (new-task!)
result (impl/export! (source.p/snapshot mock) task "malformed occupant")]
@@ -438,7 +438,7 @@
(let [a-eid (t2/select-one-fn :entity_id :model/Card :id card-a)]
;; A real content change keeps the staged commit non-empty, isolating the path-selection behavior
;; under test from the empty-commit skip.
- (t2/update! :model/Card card-a {:description "re-created A"})
+ (t2/update! :model/Card :id card-a {:description "re-created A"})
(set-status! "Card" card-a "create")
(let [task (new-task!)]
(impl/export! (source.p/snapshot mock) task "re-create A")
@@ -494,7 +494,7 @@
;; A stale file in a now-disabled content dir, alongside an ordinary card edit. The edit stays on
;; the incremental path AND the stale transforms file is deleted in the same commit.
(swap! (:files-atom mock) assoc-in ["main" "transforms/old/old.yaml"] "stale transform")
- (t2/update! :model/Card card-a {:description "edit A"})
+ (t2/update! :model/Card :id card-a {:description "edit A"})
(set-status! "Card" card-a "update")
(let [a-eid (t2/select-one-fn :entity_id :model/Card :id card-a)
task (new-task!)]
@@ -552,7 +552,7 @@
(seed-create-row! "Card" x-id)
(impl/export! (source.p/snapshot mock) (new-task!) "add x") ; X now in repo, Y still not
;; Edit X to reference the external card Y, then export the single in-place change.
- (t2/update! :model/Card x-id {:dataset_query (card-source-query y-id)})
+ (t2/update! :model/Card :id x-id {:dataset_query (card-source-query y-id)})
(set-status! "Card" x-id "update")
(let [task (new-task!)]
(impl/export! (source.p/snapshot mock) task "reference Y")
@@ -613,7 +613,7 @@
y-eid (t2/select-one-fn :entity_id :model/Card :id y-id)]
(impl/export! (source.p/snapshot mock) (new-task!) "init")
(is (entity-exported? mock y-eid) "the referenced synced card is in the repo")
- (t2/update! :model/Card x-id {:description "edit"})
+ (t2/update! :model/Card :id x-id {:description "edit"})
(set-status! "Card" x-id "update")
(let [task (new-task!)]
(impl/export! (source.p/snapshot mock) task "edit")
@@ -629,11 +629,11 @@
(testing "a repo produced by an incremental in-place edit imports back to the edited content"
(with-exported-collection!
(fn [{:keys [mock card-a]}]
- (t2/update! :model/Card card-a {:description "edited via incremental"})
+ (t2/update! :model/Card :id card-a {:description "edited via incremental"})
(set-status! "Card" card-a "update")
(impl/export! (source.p/snapshot mock) (new-task!) "edit")
;; diverge the DB from the repo, then import the repo back over it
- (t2/update! :model/Card card-a {:description "local divergence"})
+ (t2/update! :model/Card :id card-a {:description "local divergence"})
(is (= :success (:status (impl/import! (source.p/snapshot mock) (new-task!) :force? true)))
"import succeeds")
(is (= "edited via incremental" (t2/select-one-fn :description :model/Card :id card-a))
@@ -644,11 +644,11 @@
(with-exported-collection!
(fn [{:keys [mock card-a]}]
(let [a-eid (t2/select-one-fn :entity_id :model/Card :id card-a)]
- (t2/update! :model/Card card-a {:name "Renamed A"})
+ (t2/update! :model/Card :id card-a {:name "Renamed A"})
(set-status! "Card" card-a "update")
(impl/export! (source.p/snapshot mock) (new-task!) "rename")
;; rename back locally, then import the repo
- (t2/update! :model/Card card-a {:name "Card A"})
+ (t2/update! :model/Card :id card-a {:name "Card A"})
(is (= :success (:status (impl/import! (source.p/snapshot mock) (new-task!) :force? true)))
"import succeeds")
(is (= "Renamed A" (t2/select-one-fn :name :model/Card :id card-a))
@@ -713,7 +713,7 @@
;; Simulate the remote diverging: a new, non-colliding upstream file the local instance never imported.
(swap! (:files-atom mock) assoc-in ["main" ghost-path]
"name: Ghost\nentity_id: ghostUpstream00000001\nserdes/meta:\n- id: ghostUpstream00000001\n model: Card\n")
- (t2/update! :model/Card card-a {:description "local edit"})
+ (t2/update! :model/Card :id card-a {:description "local edit"})
(set-status! "Card" card-a "update")
(testing "an ordinary (incremental) export preserves the upstream file — so it is NOT an overwrite"
(let [task (new-task!)]
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/init_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/init_test.clj
index aeafc62bd86..1a7332e7a36 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/init_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/init_test.clj
@@ -149,7 +149,7 @@
(deftest remote-sync-shutdown-fails-this-jvms-running-tasks-test
(testing "shutdown fails every task whose worker runs in this JVM and leaves a stale open row from elsewhere untouched"
(let [other-id (new-task-id)
- _ (t2/update! :model/RemoteSyncTask other-id
+ _ (t2/update! :model/RemoteSyncTask :id other-id
{:last_progress_report_at (t/minus (t/offset-date-time) (t/hours 2))})
own-id (new-task-id)
release (promise)
@@ -173,7 +173,7 @@
(testing "boot closes open task rows whose owner has been silent past the window and leaves fresh ones alone"
(mt/with-temporary-setting-values [:remote-sync-url nil]
(let [stale-id (new-task-id)
- _ (t2/update! :model/RemoteSyncTask stale-id
+ _ (t2/update! :model/RemoteSyncTask :id stale-id
{:last_progress_report_at (t/minus (t/offset-date-time) (t/hours 2))})
fresh-id (new-task-id)]
(#'init/remote-sync-init)
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/metric_dimension_api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/metric_dimension_api_test.clj
index e9b5eae58b5..214efbd041e 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/metric_dimension_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/metric_dimension_api_test.clj
@@ -36,7 +36,7 @@
(t2/insert! :model/RemoteSyncObject
{:model_type "Card"
:model_id card-id
- :model_name (t2/select-one-fn :name :model/Card card-id)
+ :model_name (t2/select-one-fn :name :model/Card :id card-id)
:status "synced"
:content_hash (source/row->content-hash {:model_type "Card" :model_id card-id})
:status_changed_at (t/offset-date-time)}))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/models/remote_sync_task_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/models/remote_sync_task_test.clj
index 420dbc43334..49f18e68db0 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/models/remote_sync_task_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/models/remote_sync_task_test.clj
@@ -317,7 +317,7 @@
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
old-time (t/minus (t/offset-date-time) (t/hours 2))]
(try
- (t2/update! :model/RemoteSyncTask (:id task)
+ (t2/update! :model/RemoteSyncTask :id (:id task)
{:last_progress_report_at old-time})
(let [stale-task (t2/select-one :model/RemoteSyncTask :id (:id task))]
(is (true? (rst/timed-out? stale-task))))
@@ -338,7 +338,7 @@
(testing "timed-out? returns false for completed task even with old last_progress_report_at"
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
old-time (t/minus (t/offset-date-time) (t/hours 2))]
- (t2/update! :model/RemoteSyncTask (:id task)
+ (t2/update! :model/RemoteSyncTask :id (:id task)
{:last_progress_report_at old-time})
(rst/complete-sync-task! (:id task))
(let [completed-task (t2/select-one :model/RemoteSyncTask :id (:id task))]
@@ -348,7 +348,7 @@
(testing "timed-out? returns false for failed task even with old last_progress_report_at"
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
old-time (t/minus (t/offset-date-time) (t/hours 2))]
- (t2/update! :model/RemoteSyncTask (:id task)
+ (t2/update! :model/RemoteSyncTask :id (:id task)
{:last_progress_report_at old-time})
(rst/fail-sync-task! (:id task) "Task failed")
(let [failed-task (t2/select-one :model/RemoteSyncTask :id (:id task))]
@@ -359,7 +359,7 @@
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
boundary-time (t/minus (t/offset-date-time) (t/minutes 4))]
(try
- (t2/update! :model/RemoteSyncTask (:id task)
+ (t2/update! :model/RemoteSyncTask :id (:id task)
{:last_progress_report_at boundary-time})
(let [boundary-task (t2/select-one :model/RemoteSyncTask :id (:id task))]
(is (false? (rst/timed-out? boundary-task))))
@@ -371,8 +371,8 @@
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
old-time (t/minus (t/offset-date-time) (t/hours 2))]
(try
- (t2/update! :model/RemoteSyncTask (:id task) {:last_progress_report_at old-time
- :last_heartbeat_at (t/offset-date-time)})
+ (t2/update! :model/RemoteSyncTask :id (:id task) {:last_progress_report_at old-time
+ :last_heartbeat_at (t/offset-date-time)})
(is (false? (rst/timed-out? (t2/select-one :model/RemoteSyncTask :id (:id task)))))
(finally
(rst/complete-sync-task! (:id task))))))
@@ -380,8 +380,8 @@
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
old-time (t/minus (t/offset-date-time) (t/hours 2))]
(try
- (t2/update! :model/RemoteSyncTask (:id task) {:last_progress_report_at (t/offset-date-time)
- :last_heartbeat_at old-time})
+ (t2/update! :model/RemoteSyncTask :id (:id task) {:last_progress_report_at (t/offset-date-time)
+ :last_heartbeat_at old-time})
(is (true? (rst/timed-out? (t2/select-one :model/RemoteSyncTask :id (:id task)))))
(finally
(rst/complete-sync-task! (:id task))))))
@@ -389,8 +389,8 @@
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
old-time (t/minus (t/offset-date-time) (t/hours 2))]
(try
- (t2/update! :model/RemoteSyncTask (:id task) {:last_progress_report_at old-time
- :last_heartbeat_at nil})
+ (t2/update! :model/RemoteSyncTask :id (:id task) {:last_progress_report_at old-time
+ :last_heartbeat_at nil})
(is (true? (rst/timed-out? (t2/select-one :model/RemoteSyncTask :id (:id task)))))
(finally
(rst/complete-sync-task! (:id task)))))))
@@ -400,8 +400,8 @@
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
old-time (t/minus (t/offset-date-time) (t/hours 2))]
(try
- (t2/update! :model/RemoteSyncTask (:id task) {:last_progress_report_at old-time
- :last_heartbeat_at (t/offset-date-time)})
+ (t2/update! :model/RemoteSyncTask :id (:id task) {:last_progress_report_at old-time
+ :last_heartbeat_at (t/offset-date-time)})
(is (= (:id task) (:id (rst/current-task))))
(finally
(rst/complete-sync-task! (:id task))))))
@@ -409,8 +409,8 @@
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
old-time (t/minus (t/offset-date-time) (t/hours 2))]
(try
- (t2/update! :model/RemoteSyncTask (:id task) {:last_progress_report_at (t/offset-date-time)
- :last_heartbeat_at old-time})
+ (t2/update! :model/RemoteSyncTask :id (:id task) {:last_progress_report_at (t/offset-date-time)
+ :last_heartbeat_at old-time})
(is (nil? (rst/current-task)))
(finally
(rst/complete-sync-task! (:id task)))))))
@@ -434,7 +434,7 @@
(let [task (rst/create-sync-task! "import" (mt/user->id :rasta))
old-time (t/minus (t/offset-date-time) (t/hours 2))]
(try
- (t2/update! :model/RemoteSyncTask (:id task) {:last_progress_report_at old-time})
+ (t2/update! :model/RemoteSyncTask :id (:id task) {:last_progress_report_at old-time})
(let [before (t2/select-one :model/RemoteSyncTask :id (:id task))]
(is (nil? (:last_heartbeat_at before)))
(is (= 1 (remote-sync.db/touch-task! (:id task))))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/permissions_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/permissions_test.clj
index 50546272606..37fcd7248a0 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/permissions_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/permissions_test.clj
@@ -371,14 +371,14 @@
(mt/with-temp [:model/Collection {library-coll-id :id} {:name "Library Collection"
:is_remote_synced true}]
(testing "Published tables in remote-synced collections have can_write=false"
- (t2/update! :model/Table (mt/id :venues)
+ (t2/update! :model/Table :id (mt/id :venues)
{:is_published true
:collection_id library-coll-id})
(try
(is (false? (mi/can-write? (t2/select-one :model/Table :id (mt/id :venues))))
"Published table in remote-synced collection should not be writable when remote-sync-type is read-only")
(finally
- (t2/update! :model/Table (mt/id :venues)
+ (t2/update! :model/Table :id (mt/id :venues)
{:is_published false
:collection_id nil})))))))))
@@ -389,14 +389,14 @@
(mt/with-temp [:model/Collection {library-coll-id :id} {:name "Library Collection"
:is_remote_synced true}]
(testing "Published tables in remote-synced collections have can_write=true"
- (t2/update! :model/Table (mt/id :venues)
+ (t2/update! :model/Table :id (mt/id :venues)
{:is_published true
:collection_id library-coll-id})
(try
(is (true? (mi/can-write? (t2/select-one :model/Table :id (mt/id :venues))))
"Published table in remote-synced collection should be writable when remote-sync-type is read-write")
(finally
- (t2/update! :model/Table (mt/id :venues)
+ (t2/update! :model/Table :id (mt/id :venues)
{:is_published false
:collection_id nil})))))))))
@@ -407,14 +407,14 @@
(mt/with-temp [:model/Collection {library-coll-id :id} {:name "Library Collection"
:is_remote_synced true}]
(testing "Unpublished tables in remote-synced collections have can_write=true"
- (t2/update! :model/Table (mt/id :venues)
+ (t2/update! :model/Table :id (mt/id :venues)
{:is_published false
:collection_id library-coll-id})
(try
(is (true? (mi/can-write? (t2/select-one :model/Table :id (mt/id :venues))))
"Unpublished table in remote-synced collection should be writable even when remote-sync-type is read-only")
(finally
- (t2/update! :model/Table (mt/id :venues)
+ (t2/update! :model/Table :id (mt/id :venues)
{:is_published false
:collection_id nil})))))))))
@@ -427,14 +427,14 @@
(testing (str "When remote-sync-type is " remote-sync-setting)
(mt/with-temporary-setting-values [settings/remote-sync-type remote-sync-setting]
(testing "Published tables in regular collections have can_write=true"
- (t2/update! :model/Table (mt/id :venues)
+ (t2/update! :model/Table :id (mt/id :venues)
{:is_published true
:collection_id regular-coll-id})
(try
(is (true? (mi/can-write? (t2/select-one :model/Table :id (mt/id :venues))))
"Published table in regular collection should be writable regardless of remote-sync-type")
(finally
- (t2/update! :model/Table (mt/id :venues)
+ (t2/update! :model/Table :id (mt/id :venues)
{:is_published false
:collection_id nil})))))))))))
@@ -447,7 +447,7 @@
(mt/with-temp-vals-in-db :model/Table (mt/id :venues) {:is_published true :collection_id coll-id}
(mt/with-temp-vals-in-db :model/Field (mt/id :venues :name) {:visibility_type :sensitive}
(testing "published tables in remote-synced collections are not writable when remote-sync-type is read-only"
- (is (false? (mi/can-write? (t2/select-one :model/Table (mt/id :venues)))))
+ (is (false? (mi/can-write? (t2/select-one :model/Table :id (mt/id :venues)))))
(is (false? (:can_write (mt/user-http-request :crowberto :get 200
(str "table/" (mt/id :venues) "/query_metadata")
:include_editable_data_model true)))))
@@ -589,14 +589,14 @@
(testing "Fields on published tables in remote-synced collections have can_write=false"
(let [table-id (mt/id :venues)
field-id (mt/id :venues :name)]
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published true
:collection_id library-coll-id})
(try
(is (false? (mi/can-write? (t2/select-one :model/Field :id field-id)))
"Field on published table in remote-synced collection should not be writable when remote-sync-type is read-only")
(finally
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published false
:collection_id nil}))))))))))
@@ -609,14 +609,14 @@
(testing "Fields on published tables in remote-synced collections have can_write=true"
(let [table-id (mt/id :venues)
field-id (mt/id :venues :name)]
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published true
:collection_id library-coll-id})
(try
(is (true? (mi/can-write? (t2/select-one :model/Field :id field-id)))
"Field on published table in remote-synced collection should be writable when remote-sync-type is read-write")
(finally
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published false
:collection_id nil}))))))))))
@@ -630,7 +630,7 @@
:is_remote_synced true}]
(testing "Segments on published tables in remote-synced collections have can_write=false"
(let [table-id (mt/id :venues)]
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published true
:collection_id library-coll-id})
(try
@@ -641,7 +641,7 @@
(is (false? (mi/can-write? (t2/select-one :model/Segment :id segment-id)))
"Segment on published table in remote-synced collection should not be writable when remote-sync-type is read-only"))
(finally
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published false
:collection_id nil}))))))))))
@@ -653,7 +653,7 @@
:is_remote_synced true}]
(testing "Segments on published tables in remote-synced collections have can_write=true"
(let [table-id (mt/id :venues)]
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published true
:collection_id library-coll-id})
(try
@@ -664,7 +664,7 @@
(is (true? (mi/can-write? (t2/select-one :model/Segment :id segment-id)))
"Segment on published table in remote-synced collection should be writable when remote-sync-type is read-write"))
(finally
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published false
:collection_id nil}))))))))))
@@ -676,7 +676,7 @@
:is_remote_synced true}]
(testing "Segment creation should be blocked on published tables in remote-synced collections"
(let [table-id (mt/id :venues)]
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published true
:collection_id library-coll-id})
(try
@@ -688,7 +688,7 @@
:definition {}}))
"Segment creation should be blocked on published table in remote-synced collection when remote-sync-type is read-only"))
(finally
- (t2/update! :model/Table table-id
+ (t2/update! :model/Table :id table-id
{:is_published false
:collection_id nil}))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj
index d92ba18e886..3a6b97599c5 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj
@@ -220,13 +220,13 @@
(mt/with-temp [:model/NativeQuerySnippet snippet {:name "Test Snippet" :content "SELECT 1"}]
;; Ensure library exists and is not synced initially
(when-let [library (collection/library-collection)]
- (t2/update! :model/Collection (:id library) {:is_remote_synced false}))
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced false}))
(t2/delete! :model/RemoteSyncObject :model_type "NativeQuerySnippet")
(is (zero? (t2/count :model/RemoteSyncObject :model_type "NativeQuerySnippet"))
"Should have no snippet tracking initially")
;; Enable Library sync and verify snippets get tracked
(when-let [library (collection/library-collection)]
- (t2/update! :model/Collection (:id library) {:is_remote_synced true})
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced true})
(events/publish-event! :event/collection-update
{:object (t2/select-one :model/Collection :id (:id library))
:user-id (mt/user->id :rasta)})
@@ -235,7 +235,7 @@
:model_id (:id snippet))
"Snippet should be tracked after Library becomes synced")
;; Disable Library sync and verify snippets get untracked
- (t2/update! :model/Collection (:id library) {:is_remote_synced false})
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced false})
(events/publish-event! :event/collection-update
{:object (t2/select-one :model/Collection :id (:id library))
:user-id (mt/user->id :rasta)})
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj
index 21a67a885be..c223b41574f 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj
@@ -707,7 +707,7 @@ is_sample: false
mock-source (test-helpers/create-mock-source :initial-files initial-files)]
(is (some #(str/includes? % "transforms_collection") (keys (get @(:files-atom mock-source) "main"))))
(is (some #(str/includes? % "child_transform") (keys (get @(:files-atom mock-source) "main"))))
- (t2/update! :model/Collection coll-id {:archived true})
+ (t2/update! :model/Collection :id coll-id {:archived true})
(events/publish-event! :event/collection-update
{:object (t2/select-one :model/Collection :id coll-id)
:user-id (mt/user->id :rasta)})
@@ -884,7 +884,7 @@ serdes/meta:
(let [library (t2/insert-returning-instance! :model/PythonLibrary {:path "common.py" :source "# test"})]
(t2/update! :model/RemoteSyncObject {:model_type "PythonLibrary" :model_id (:id library)}
{:status "synced"})
- (t2/update! :model/PythonLibrary (:id library) {:source "# updated"})
+ (t2/update! :model/PythonLibrary :id (:id library) {:source "# updated"})
(let [entry (t2/select-one :model/RemoteSyncObject
:model_type "PythonLibrary"
:model_id (:id library))]
@@ -1342,13 +1342,13 @@ serdes/meta:
(mt/with-temp [:model/Transform {transform-id :id} {:name "Orders Summary"}
:model/TransformTest {test-id :id} {:transform_id transform-id :name "My test"}]
(is (= "create" (:status (transform-test-rso test-id))))
- (t2/update! :model/RemoteSyncObject (:id (transform-test-rso test-id))
+ (t2/update! :model/RemoteSyncObject :id (:id (transform-test-rso test-id))
{:status "synced" :status_changed_at (t/offset-date-time)})
- (t2/update! :model/TransformTest test-id {:name "Renamed test"})
+ (t2/update! :model/TransformTest :id test-id {:name "Renamed test"})
(is (=? {:status "update" :model_name "Renamed test"} (transform-test-rso test-id)))
- (t2/update! :model/RemoteSyncObject (:id (transform-test-rso test-id))
+ (t2/update! :model/RemoteSyncObject :id (:id (transform-test-rso test-id))
{:status "synced" :status_changed_at (t/offset-date-time)})
- (t2/delete! :model/TransformTest test-id)
+ (t2/delete! :model/TransformTest :id test-id)
(is (= "delete" (:status (transform-test-rso test-id)))))))))
(deftest transform-delete-marks-its-tests-deleted-test
@@ -1359,9 +1359,9 @@ serdes/meta:
remote-sync-type :read-write]
(mt/with-temp [:model/Transform {transform-id :id} {:name "Orders Summary"}
:model/TransformTest {test-id :id} {:transform_id transform-id :name "My test"}]
- (t2/update! :model/RemoteSyncObject (:id (transform-test-rso test-id))
+ (t2/update! :model/RemoteSyncObject :id (:id (transform-test-rso test-id))
{:status "synced" :status_changed_at (t/offset-date-time)})
- (t2/delete! :model/Transform transform-id)
+ (t2/delete! :model/Transform :id transform-id)
(is (false? (t2/exists? :model/TransformTest :id test-id)))
(is (= "delete" (:status (transform-test-rso test-id)))))))))
@@ -1404,8 +1404,8 @@ serdes/meta:
(is (= :success (:status (impl/export! (source.p/snapshot mock) (new-export-task!) "init"))))
(let [old-path (test-path)]
(is (str/ends-with? old-path "/etl/orders_summary/no_nulls.yaml"))
- (t2/update! :model/Transform transform-id {:name "Orders Report"})
- (events/publish-event! :event/transform-update {:object (t2/select-one :model/Transform transform-id)})
+ (t2/update! :model/Transform :id transform-id {:name "Orders Report"})
+ (events/publish-event! :event/transform-update {:object (t2/select-one :model/Transform :id transform-id)})
(testing "renaming the transform marks its test for update"
(is (= "update" (:status (t2/select-one :model/RemoteSyncObject :model_type "TransformTest" :model_id test-id)))))
(is (= :success (:status (impl/export! (source.p/snapshot mock) (new-export-task!) "rename"))))
diff --git a/enterprise/backend/test/metabase_enterprise/replacement/api_test.clj b/enterprise/backend/test/metabase_enterprise/replacement/api_test.clj
index 0d3c259eb59..21c9457297d 100644
--- a/enterprise/backend/test/metabase_enterprise/replacement/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/replacement/api_test.clj
@@ -369,7 +369,7 @@
(mt/test-drivers (mt/normal-drivers-with-feature :transforms/table)
(mt/with-premium-features #{:dependencies}
(let [mp (mt/metadata-provider)
- schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
+ schema (t2/select-one-fn :schema :model/Table :id (mt/id :orders))]
(with-transform-cleanup! [target {:type "table"
:schema schema
:name "model_transform"}]
@@ -459,7 +459,7 @@
(mt/test-drivers (mt/normal-drivers-with-feature :transforms/table :left-join)
(mt/with-premium-features #{:dependencies}
(let [mp (mt/metadata-provider)
- schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
+ schema (t2/select-one-fn :schema :model/Table :id (mt/id :orders))]
(with-transform-cleanup! [target {:type "table"
:schema schema
:name "model_transform_shapes"}]
diff --git a/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.clj b/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.clj
index fd1751a22b1..53384c76b5b 100644
--- a/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/replacement/field_refs_test.clj
@@ -37,7 +37,7 @@
:aggregation [[:count {}]]
:breakout [[:field {} (mt/id :orders :id)]]}
{:filters [[:= {} [:field {} "ID"] 1]]}]}}
- (t2/select-one :model/Card card-id)))))))
+ (t2/select-one :model/Card :id card-id)))))))
(deftest card-upgrade-field-refs!-viz-settings-test
(testing "should upgrade refs in viz settings"
@@ -92,7 +92,7 @@
:pivot_table.collapsed_rows
{:rows ["ID"]
:value [10]}}}
- (t2/select-one :model/Card card-id)))))))
+ (t2/select-one :model/Card :id card-id)))))))
(deftest card-upgrade-field-refs!-viz-settings-broken-test
(testing "should ignore refs in viz settings that cannot be resolved"
@@ -113,7 +113,7 @@
{:rows ["ID"]
:columns [[:field 9999 nil]]
:values ["count" [:aggregation 1]]}}}
- (t2/select-one :model/Card card-id)))))))
+ (t2/select-one :model/Card :id card-id)))))))
(deftest card-upgrade-field-refs!-parameters-test
(testing "should upgrade refs in `:values_source_config` of parameters"
@@ -133,7 +133,7 @@
(is (=? {:parameters [{:name "category"
:values_source_config {:card_id card1-id
:value_field [:field "CATEGORY" {}]}}]}
- (t2/select-one :model/Card card2-id)))))))
+ (t2/select-one :model/Card :id card2-id)))))))
(deftest card-upgrade-field-refs!-non-card-sourced-parameters-test
(testing "should not change parameters that don't reference cards"
@@ -145,10 +145,10 @@
:name "category"
:type :string/=}]}]
(replacement.field-refs/upgrade-field-refs! [:card card-id])
- (is (= updated-at (:updated_at (t2/select-one :model/Card card-id)))
+ (is (= updated-at (:updated_at (t2/select-one :model/Card :id card-id)))
"Card should not be updated when parameters don't reference cards")
(is (= [{:id "test-param" :name "category" :type :string/=}]
- (:parameters (t2/select-one :model/Card card-id)))
+ (:parameters (t2/select-one :model/Card :id card-id)))
"Parameters should be unchanged")))))
(deftest card-upgrade-field-refs!-native-query-test
@@ -158,7 +158,7 @@
(mt/with-temp [:model/Card {card-id :id} {:dataset_query query}]
(replacement.field-refs/upgrade-field-refs! [:card card-id])
(is (=? {:dataset_query {:stages [{:native "SELECT * FROM orders"}]}}
- (t2/select-one :model/Card card-id)))))))
+ (t2/select-one :model/Card :id card-id)))))))
(deftest card-upgrade-field-refs!-native-query-preserves-result-metadata-test
(testing "should preserve `:result_metadata` for native queries when parameters change"
@@ -180,7 +180,7 @@
{:card_id source-card-id
:value_field (field-id-ref mp (mt/id :products :category))}}]}]
(replacement.field-refs/upgrade-field-refs! [:card card-id])
- (let [card (t2/select-one :model/Card card-id)]
+ (let [card (t2/select-one :model/Card :id card-id)]
(testing "result_metadata should be preserved"
(is (=? result-metadata
(:result_metadata card))))
@@ -194,7 +194,7 @@
(mt/with-temp [:model/Card {card-id :id, updated-at :updated_at} {:dataset_query query
:result_metadata result-metadata}]
(replacement.field-refs/upgrade-field-refs! [:card card-id])
- (is (= updated-at (:updated_at (t2/select-one :model/Card card-id)))
+ (is (= updated-at (:updated_at (t2/select-one :model/Card :id card-id)))
"Card should not be updated when native query has no changes")))))
(deftest card-upgrade-field-refs!-broken-query-test
@@ -202,10 +202,10 @@
(let [mp (mt/metadata-provider)]
(mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/native-query mp "SELECT 1")}]
;; simulate a broken query by updating the dataset_query directly
- (t2/update! :model/Card card-id {:dataset_query {}})
+ (t2/update! :model/Card :id card-id {:dataset_query {}})
(replacement.field-refs/upgrade-field-refs! [:card card-id])
(is (=? {:dataset_query {}}
- (t2/select-one :model/Card card-id)))))))
+ (t2/select-one :model/Card :id card-id)))))))
(deftest card-upgrade-field-refs!-broken-source-card-test
(testing "should not crash when a parameter references a card with a broken query"
@@ -220,12 +220,12 @@
{:card_id broken-card-id
:value_field [:field 1 nil]}}]}]
;; simulate a broken source card
- (t2/update! :model/Card broken-card-id {:dataset_query {}})
+ (t2/update! :model/Card :id broken-card-id {:dataset_query {}})
(replacement.field-refs/upgrade-field-refs! [:card card-id])
(is (=? {:parameters [{:name "category"
:values_source_config {:card_id broken-card-id
:value_field [:field 1 nil]}}]}
- (t2/select-one :model/Card card-id)))))))
+ (t2/select-one :model/Card :id card-id)))))))
(deftest card-upgrade-field-refs!-nonexistent-source-card-test
(testing "should not crash when a parameter references a non-existent card"
@@ -240,12 +240,12 @@
{:card_id source-card-id
:value_field [:field 1 nil]}}]}]
;; delete the source card to simulate a non-existent reference
- (t2/delete! :model/Card source-card-id)
+ (t2/delete! :model/Card :id source-card-id)
(replacement.field-refs/upgrade-field-refs! [:card card-id])
(is (=? {:parameters [{:name "category"
:values_source_config {:card_id source-card-id
:value_field [:field 1 nil]}}]}
- (t2/select-one :model/Card card-id)))))))
+ (t2/select-one :model/Card :id card-id)))))))
(deftest card-upgrade-field-refs!-join-alias-suffix-test
(testing "should correctly resolve a name ref disambiguated by a join-alias-derived numeric suffix (e.g. ID_2)"
@@ -258,7 +258,7 @@
(replacement.field-refs/upgrade-field-refs! [:card card-id])
(is (=? {:dataset_query {:stages [{:source-table (mt/id :orders)}
{:filters [[:not-null {} [:field {} "Products__ID"]]]}]}}
- (t2/select-one :model/Card card-id)))))))
+ (t2/select-one :model/Card :id card-id)))))))
(deftest card-upgrade-field-refs!-nested-card-source-test
(testing "should upgrade a numeric field-id ref in a card sourced from another card (nested indirection)"
@@ -271,7 +271,7 @@
(replacement.field-refs/upgrade-field-refs! [:card child-id])
(is (=? {:dataset_query {:stages [{:source-card parent-id
:filters [[:= {} [:field {} "ID"] 1]]}]}}
- (t2/select-one :model/Card child-id)))))))))
+ (t2/select-one :model/Card :id child-id)))))))))
(deftest card-upgrade-field-refs!-no-changes-test
(testing "should not update a card when there are no changes"
@@ -279,7 +279,7 @@
query (lib/query mp (lib.metadata/table mp (mt/id :orders)))]
(mt/with-temp [:model/Card {card-id :id, updated-at :updated_at} {:dataset_query query}]
(replacement.field-refs/upgrade-field-refs! [:card card-id])
- (is (= updated-at (:updated_at (t2/select-one :model/Card card-id))))))))
+ (is (= updated-at (:updated_at (t2/select-one :model/Card :id card-id))))))))
;;; ------------------------------------------------ Transform --------------------------------------------------------
@@ -298,7 +298,7 @@
:query {:stages [{:source-table (mt/id :orders)
:breakout [[:field {} (mt/id :orders :id)]]}
{:filters [[:= {} [:field {} "ID"] 1]]}]}}}
- (t2/select-one :model/Transform transform-id)))))))
+ (t2/select-one :model/Transform :id transform-id)))))))
(deftest transform-upgrade-field-refs!-native-query-test
(testing "should not change a transform with a native query"
@@ -329,7 +329,7 @@
:source {:type "query" :query query}
:target {:database (mt/id) :type "table" :name "out"}}]
(replacement.field-refs/upgrade-field-refs! [:transform transform-id])
- (is (= updated-at (:updated_at (t2/select-one :model/Transform transform-id))))))))
+ (is (= updated-at (:updated_at (t2/select-one :model/Transform :id transform-id))))))))
;;; ------------------------------------------------- Segment ----------------------------------------------------------
@@ -345,7 +345,7 @@
:where [:= :id segment-id]})
(replacement.field-refs/upgrade-field-refs! [:segment segment-id])
;; segments return nil when the query is not valid
- (is (nil? (:definition (t2/select-one :model/Segment segment-id))))))))
+ (is (nil? (:definition (t2/select-one :model/Segment :id segment-id))))))))
(deftest segment-upgrade-field-refs!-no-changes-test
(testing "should not update a segment when there are no changes"
@@ -355,7 +355,7 @@
(mt/with-temp [:model/Segment {segment-id :id, updated-at :updated_at} {:table_id (mt/id :orders)
:definition query}]
(replacement.field-refs/upgrade-field-refs! [:segment segment-id])
- (is (= updated-at (:updated_at (t2/select-one :model/Segment segment-id))))))))
+ (is (= updated-at (:updated_at (t2/select-one :model/Segment :id segment-id))))))))
;;; ------------------------------------------------- Measure ----------------------------------------------------------
@@ -371,7 +371,7 @@
(replacement.field-refs/upgrade-field-refs! [:measure measure-id])
(is (=? {:definition {:stages [{:source-table (mt/id :orders)
:aggregation [[:sum {} [:field {} (mt/id :orders :total)]]]}]}}
- (t2/select-one :model/Measure measure-id)))))))
+ (t2/select-one :model/Measure :id measure-id)))))))
(deftest measure-upgrade-field-refs!-broken-query-test
(testing "should not crash or update a measure with a broken definition"
@@ -386,7 +386,7 @@
:where [:= :id measure-id]})
(replacement.field-refs/upgrade-field-refs! [:measure measure-id])
;; Measure return {} when query is invalid
- (is (= {} (:definition (t2/select-one :model/Measure measure-id))))))))
+ (is (= {} (:definition (t2/select-one :model/Measure :id measure-id))))))))
(deftest measure-upgrade-field-refs!-no-changes-test
(testing "should not update a measure when there are no changes"
@@ -397,7 +397,7 @@
:name "test measure"
:definition query}]
(replacement.field-refs/upgrade-field-refs! [:measure measure-id])
- (is (= updated-at (:updated_at (t2/select-one :model/Measure measure-id))))))))
+ (is (= updated-at (:updated_at (t2/select-one :model/Measure :id measure-id))))))))
;;; ------------------------------------------------ Dashboard --------------------------------------------------------
@@ -416,7 +416,7 @@
(is (=? {:parameters [{:name "category"
:values_source_config {:card_id card-id
:value_field [:field "CATEGORY" {}]}}]}
- (t2/select-one :model/Dashboard dashboard-id)))))))
+ (t2/select-one :model/Dashboard :id dashboard-id)))))))
(deftest dashboard-upgrade-field-refs!-parameter-mappings-test
(testing "should upgrade refs in dashcard parameter mappings"
@@ -435,7 +435,7 @@
(is (=? {:parameter_mappings [{:parameter_id "my-param"
:card_id card-id
:target [:dimension [:field "ID" {}] {:stage-number 1}]}]}
- (t2/select-one :model/DashboardCard dashcard-id)))))))
+ (t2/select-one :model/DashboardCard :id dashcard-id)))))))
(deftest dashboard-upgrade-field-refs!-broken-source-card-test
(testing "should not crash when a dashcard references a card with a broken query"
@@ -448,10 +448,10 @@
:card_id card-id
:target (dimension-field-id-ref mp (mt/id :orders :id))}]}]
;; simulate a broken card
- (t2/update! :model/Card card-id {:dataset_query {}})
+ (t2/update! :model/Card :id card-id {:dataset_query {}})
(replacement.field-refs/upgrade-field-refs! [:dashboard dashboard-id])
(is (=? {:parameter_mappings [{:target (dimension-field-id-ref mp (mt/id :orders :id))}]}
- (t2/select-one :model/DashboardCard dashcard-id)))))))
+ (t2/select-one :model/DashboardCard :id dashcard-id)))))))
(defn- make-click-behavior
[card-id target]
@@ -488,7 +488,7 @@
{(json/encode [:name "ID"])
{:click_behavior (make-click-behavior target-card-id target)}}}}]
(replacement.field-refs/upgrade-field-refs! [:dashboard dashboard-id])
- (let [viz (:visualization_settings (t2/select-one :model/DashboardCard dashcard-id))
+ (let [viz (:visualization_settings (t2/select-one :model/DashboardCard :id dashcard-id))
viz-key (keyword (json/encode target))]
(testing "global click behavior dimension should be upgraded"
(is (=? {:click_behavior
@@ -518,5 +518,5 @@
:card_id card-id
:target (dimension-field-id-ref mp (mt/id :orders :id))}]}]
(replacement.field-refs/upgrade-field-refs! [:dashboard dashboard-id])
- (is (= dash-updated (:updated_at (t2/select-one :model/Dashboard dashboard-id))))
- (is (= dc-updated (:updated_at (t2/select-one :model/DashboardCard dashcard-id))))))))
+ (is (= dash-updated (:updated_at (t2/select-one :model/Dashboard :id dashboard-id))))
+ (is (= dc-updated (:updated_at (t2/select-one :model/DashboardCard :id dashcard-id))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.clj b/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.clj
index ad757017ed0..2c62d55e158 100644
--- a/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/replacement/source_swap_test.clj
@@ -29,7 +29,7 @@
(replacement.source-swap/swap-source! [:card card-id]
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
- (let [card (t2/select-one :model/Card card-id)]
+ (let [card (t2/select-one :model/Card :id card-id)]
(is (= (mt/id :reviews) (:table_id card)))
(is (= (mt/id :reviews)
(get-in card [:dataset_query :stages 0 :source-table]))))))))))
@@ -50,7 +50,7 @@
[:card old-source-id]
[:card new-source-id])
(is (= new-source-id
- (get-in (t2/select-one :model/Card card-id)
+ (get-in (t2/select-one :model/Card :id card-id)
[:dataset_query :stages 0 :source-card])))))))))
(deftest card-swap-source!-native-query-test
@@ -65,7 +65,7 @@
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
(is (= "SELECT ID FROM PUBLIC.REVIEWS"
- (lib/raw-native-query (:dataset_query (t2/select-one :model/Card card-id)))))))))))
+ (lib/raw-native-query (:dataset_query (t2/select-one :model/Card :id card-id)))))))))))
(deftest card-swap-source!-native-query-preserves-result-metadata-test
(testing "swap-source! should preserve `:result_metadata` for native queries"
@@ -80,7 +80,7 @@
(replacement.source-swap/swap-source! [:card card-id]
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
- (let [card (t2/select-one :model/Card card-id)]
+ (let [card (t2/select-one :model/Card :id card-id)]
(is (= "SELECT ID FROM PUBLIC.REVIEWS"
(lib/raw-native-query (:dataset_query card))))
(is (=? [{:name "ID" :base_type :type/Integer}]
@@ -92,11 +92,11 @@
(mt/with-test-user :rasta
(let [mp (mt/metadata-provider)]
(mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/native-query mp "SELECT 1")}]
- (t2/update! :model/Card card-id {:dataset_query {}})
+ (t2/update! :model/Card :id card-id {:dataset_query {}})
(replacement.source-swap/swap-source! [:card card-id]
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
- (is (= {} (:dataset_query (t2/select-one :model/Card card-id))))))))))
+ (is (= {} (:dataset_query (t2/select-one :model/Card :id card-id))))))))))
(deftest card-swap-source!-updates-parameter-values-source-config-card-id-test
(testing "swap-source! should update card_id in card parameter values_source_config for card-to-card swaps"
@@ -118,7 +118,7 @@
[:card new-source-id])
(testing ":parameters JSONB on the card is updated"
(is (= new-source-id
- (-> (t2/select-one :model/Card card-id)
+ (-> (t2/select-one :model/Card :id card-id)
:parameters first :values_source_config :card_id))))
(testing "parameter_card row is synced"
(is (= new-source-id
@@ -145,7 +145,7 @@
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
(is (= old-source-id
- (-> (t2/select-one :model/Card card-id)
+ (-> (t2/select-one :model/Card :id card-id)
:parameters first :values_source_config :card_id)))))))))
;;; ------------------------------------------------ Transform --------------------------------------------------------
@@ -164,7 +164,7 @@
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
(is (= (mt/id :reviews)
- (get-in (t2/select-one :model/Transform transform-id)
+ (get-in (t2/select-one :model/Transform :id transform-id)
[:source :query :stages 0 :source-table])))))))))
(deftest transform-swap-source!-broken-query-test
@@ -198,7 +198,7 @@
(replacement.source-swap/swap-source! [:segment segment-id]
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
- (let [segment (t2/select-one :model/Segment segment-id)]
+ (let [segment (t2/select-one :model/Segment :id segment-id)]
(is (= (mt/id :reviews) (:table_id segment)))
(is (= (mt/id :reviews)
(get-in segment [:definition :stages 0 :source-table]))))))))))
@@ -235,7 +235,7 @@
(replacement.source-swap/swap-source! [:measure measure-id]
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
- (let [measure (t2/select-one :model/Measure measure-id)]
+ (let [measure (t2/select-one :model/Measure :id measure-id)]
(is (= (mt/id :reviews) (:table_id measure)))
(is (= (mt/id :reviews)
(get-in measure [:definition :stages 0 :source-table]))))))))))
@@ -278,7 +278,7 @@
[:card new-source-id])
(testing ":parameters JSONB on the dashboard is updated"
(is (= new-source-id
- (-> (t2/select-one :model/Dashboard dashboard-id)
+ (-> (t2/select-one :model/Dashboard :id dashboard-id)
:parameters first :values_source_config :card_id))))
(testing "parameter_card row is synced"
(is (= new-source-id
@@ -304,7 +304,7 @@
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
(is (= old-source-id
- (-> (t2/select-one :model/Dashboard dashboard-id)
+ (-> (t2/select-one :model/Dashboard :id dashboard-id)
:parameters first :values_source_config :card_id)))))))))
(deftest dashboard-swap-source!-parameter-mappings-card-to-card-test
@@ -327,7 +327,7 @@
(replacement.source-swap/swap-source! [:dashboard dashboard-id]
[:card old-card-id]
[:card new-card-id])
- (let [dashcard (t2/select-one :model/DashboardCard dashcard-id)]
+ (let [dashcard (t2/select-one :model/DashboardCard :id dashcard-id)]
(is (=? {:parameter_mappings [{:parameter_id "my-param"
:card_id old-card-id
:target [:dimension [:field (mt/id :orders :id) {}]]}]}
@@ -353,7 +353,7 @@
(replacement.source-swap/swap-source! [:dashboard dashboard-id]
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
- (let [updated-target (get-in (t2/select-one :model/DashboardCard dashcard-id)
+ (let [updated-target (get-in (t2/select-one :model/DashboardCard :id dashcard-id)
[:parameter_mappings 0 :target])]
(is (=? [:dimension [:field (mt/id :products :category)
{:source-field (mt/id :reviews :product_id)}]]
@@ -395,7 +395,7 @@
(replacement.source-swap/swap-source! [:dashboard dashboard-id]
[:table (mt/id :orders)]
[:table (mt/id :reviews)])
- (let [viz (:visualization_settings (t2/select-one :model/DashboardCard dashcard-id))
+ (let [viz (:visualization_settings (t2/select-one :model/DashboardCard :id dashcard-id))
viz-key (keyword (json/encode target))]
(is (=? {:click_behavior
{:targetId target-card-id
@@ -417,7 +417,7 @@
(replacement.field-refs/upgrade-field-refs! [:card card-id])
(mt/with-model-cleanup [:model/Dependency]
;; Create a dependency: card -> orders table
- (events/publish-event! :event/card-create {:object (t2/select-one :model/Card card-id)
+ (events/publish-event! :event/card-create {:object (t2/select-one :model/Card :id card-id)
:user-id (mt/user->id :rasta)})
(deps.test/synchronously-run-dependency-job!)
(is (t2/exists? :model/Dependency
@@ -447,7 +447,7 @@
:definition query}]
(replacement.field-refs/upgrade-field-refs! [:segment segment-id])
(mt/with-model-cleanup [:model/Dependency]
- (events/publish-event! :event/segment-create {:object (t2/select-one :model/Segment segment-id)
+ (events/publish-event! :event/segment-create {:object (t2/select-one :model/Segment :id segment-id)
:user-id (mt/user->id :rasta)})
(deps.test/synchronously-run-dependency-job!)
(is (t2/exists? :model/Dependency
@@ -477,7 +477,7 @@
:definition query}]
(replacement.field-refs/upgrade-field-refs! [:measure measure-id])
(mt/with-model-cleanup [:model/Dependency]
- (events/publish-event! :event/measure-create {:object (t2/select-one :model/Measure measure-id)
+ (events/publish-event! :event/measure-create {:object (t2/select-one :model/Measure :id measure-id)
:user-id (mt/user->id :rasta)})
(deps.test/synchronously-run-dependency-job!)
(is (t2/exists? :model/Dependency
@@ -506,7 +506,7 @@
:target {:database (mt/id) :type "table" :name "out"}}]
(replacement.field-refs/upgrade-field-refs! [:transform transform-id])
(mt/with-model-cleanup [:model/Dependency]
- (events/publish-event! :event/transform-create {:object (t2/select-one :model/Transform transform-id)
+ (events/publish-event! :event/transform-create {:object (t2/select-one :model/Transform :id transform-id)
:user-id (mt/user->id :rasta)})
(deps.test/synchronously-run-dependency-job!)
(is (t2/exists? :model/Dependency
@@ -533,12 +533,12 @@
(mt/with-temp [:model/Card {card-id :id} {:dataset_query query
:table_id (mt/id :orders)}]
(replacement.field-refs/upgrade-field-refs! [:card card-id])
- (let [card-before (t2/select-one :model/Card card-id)]
+ (let [card-before (t2/select-one :model/Card :id card-id)]
;; Swap a source that doesn't appear in this query
(replacement.source-swap/swap-source! [:card card-id]
[:table (mt/id :people)]
[:table (mt/id :reviews)])
- (let [card-after (t2/select-one :model/Card card-id)]
+ (let [card-after (t2/select-one :model/Card :id card-id)]
(is (= (:dataset_query card-before) (:dataset_query card-after))
"Query should not change")
(is (= (:table_id card-before) (:table_id card-after))
@@ -560,7 +560,7 @@
[:table (mt/id :reviews)])
;; For MBQL queries, result_metadata should NOT be the old stale value
;; because :verified-result-metadata? is NOT set, so model hooks recalculate it
- (let [card (t2/select-one :model/Card card-id)]
+ (let [card (t2/select-one :model/Card :id card-id)]
(is (not= result-metadata (:result_metadata card))
"Old result_metadata should not be force-preserved for MBQL queries"))))))))
@@ -576,12 +576,12 @@
{:dashboard_id dashboard-id
:card_id card-id
:parameter_mappings []}]
- (let [dashcard-before (t2/select-one :model/DashboardCard dashcard-id)]
+ (let [dashcard-before (t2/select-one :model/DashboardCard :id dashcard-id)]
;; Swap from a source that doesn't affect dashcard params
(replacement.source-swap/swap-source! [:dashboard dashboard-id]
[:table (mt/id :people)]
[:table (mt/id :reviews)])
- (let [dashcard-after (t2/select-one :model/DashboardCard dashcard-id)]
+ (let [dashcard-after (t2/select-one :model/DashboardCard :id dashcard-id)]
(is (= (:parameter_mappings dashcard-before) (:parameter_mappings dashcard-after)))
(is (= (:visualization_settings dashcard-before) (:visualization_settings dashcard-after)))))))))))
@@ -602,11 +602,11 @@
:card_id old-card-id
:target [:dimension
[:field "ID" {:base-type :type/Integer}]]}]}]
- (let [original-pm (:parameter_mappings (t2/select-one :model/DashboardCard dashcard-id))]
+ (let [original-pm (:parameter_mappings (t2/select-one :model/DashboardCard :id dashcard-id))]
(replacement.source-swap/swap-source! [:dashboard dashboard-id]
[:card old-card-id]
[:card new-card-id])
;; The parameter_mappings should be updated (walked through)
- (let [updated-pm (:parameter_mappings (t2/select-one :model/DashboardCard dashcard-id))]
+ (let [updated-pm (:parameter_mappings (t2/select-one :model/DashboardCard :id dashcard-id))]
(is (not= original-pm updated-pm)
"parameter_mappings should have been updated")))))))))
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 2e8eba8470a..5f933848ab8 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/field_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/field_test.clj
@@ -108,7 +108,7 @@
(field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :venues :price)))
(let [field-id (mt/id :venues :price)
full-fv-id (t2/select-one-pk :model/FieldValues :field_id field-id :type :full)]
- (t2/update! :model/FieldValues full-fv-id
+ (t2/update! :model/FieldValues :id full-fv-id
{:human_readable_values ["$" "$$" "$$$" "$$$$"]})
;; sanity test without gtap
(is (= [[1 "$"] [2 "$$"] [3 "$$$"] [4 "$$$$"]]
@@ -191,7 +191,7 @@
new-values ["foo" "bar"]]
(testing "Sanity check: make sure FieldValues exist"
(is (some? fv-id)))
- (t2/update! :model/FieldValues fv-id
+ (t2/update! :model/FieldValues :id fv-id
{:values new-values})
(mt/with-dynamic-fn-redefs [field-values/distinct-values (constantly {:values (map vector new-values)
:has_more_values false})]
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 35003040d08..987238dfbef 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
@@ -45,8 +45,8 @@
{:filter [:and [:> $id 1] [:< $id 4]]})]
(Thread/sleep 1)
(mt/with-test-user :crowberto
- (t2/update! :model/Card card-id {:dataset_query new-query
- :updated_at (t/local-date-time)})))
+ (t2/update! :model/Card :id card-id {:dataset_query new-query
+ :updated_at (t/local-date-time)})))
(params.field-values/get-or-create-field-values! f)
(is (= [(range 4 6)
(range 2 4)]
@@ -66,7 +66,7 @@
(is (= 5 (count (:values (id->values (mt/id :categories :name))))))
(is (= {} (id->values (mt/id :categories :id))))
(is (nil? (params.field-values/get-or-create-field-values!
- (t2/select-one :model/Field (mt/id :categories :id)))))
+ (t2/select-one :model/Field :id (mt/id :categories :id)))))
(testing "no warehouse query runs for the field without FieldValues"
(is (= #{(mt/id :categories :name)}
(t2/select-fn-set :field_id :model/FieldValues
@@ -83,7 +83,7 @@
{:gtaps {:categories {:remappings {"State" [:dimension [:field (mt/id :categories :name) nil]]}}}
:attributes login-attributes}
(ee-params.field-values/hash-input-for-sandbox field)))
- field (t2/select-one :model/Field (mt/id :categories :name))]
+ field (t2/select-one :model/Field :id (mt/id :categories :name))]
(mt/with-temp [:model/User {user-id-1 :id} {}
:model/User {user-id-2 :id} {}]
(testing "2 users with the same attribute"
@@ -111,7 +111,7 @@
(testing "gtap with card and remappings"
;; hack so that we don't have to setup all the sandbox permissions the table
(mt/with-dynamic-fn-redefs [ee-params.field-values/field-is-sandboxed? (constantly true)]
- (let [field (t2/select-one :model/Field (mt/id :categories :name))
+ (let [field (t2/select-one :model/Field :id (mt/id :categories :name))
hash-input-for-user-id-with-attributes (fn [user-id login-attributes field]
(mt/with-temp-vals-in-db :model/User user-id {:login_attributes login-attributes}
(request/with-current-user user-id
@@ -221,7 +221,7 @@
(mt/with-premium-features #{:sandboxes}
;; hack so that we don't have to setup all the sandbox permissions for the table
(mt/with-dynamic-fn-redefs [ee-params.field-values/field-is-sandboxed? (constantly true)]
- (let [field (t2/select-one :model/Field (mt/id :orders :user_id))
+ (let [field (t2/select-one :model/Field :id (mt/id :orders :user_id))
hash-input (fn [user-id login-attributes]
(mt/with-temp-vals-in-db :model/User user-id {:login_attributes login-attributes}
(request/with-current-user user-id
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/models/sandbox_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/models/sandbox_test.clj
index f7d955ad499..11a31eb06c0 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/models/sandbox_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/models/sandbox_test.clj
@@ -25,7 +25,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"You cannot change the table ID of a sandbox once it has been created"
- (t2/update! :model/Sandbox (:id gtap) {:table_id (mt/id :checkins)}))))))
+ (t2/update! :model/Sandbox :id (:id gtap) {:table_id (mt/id :checkins)}))))))
(deftest disallow-queries-that-add-columns-test
(testing "Don't allow saving a Sandboxing query that contains columns not in the Table it replaces (#13715)"
@@ -44,7 +44,7 @@
:result_metadata (qp.preprocess/query->expected-cols query)}
:model/Sandbox gtap {:table_id (mt/id :venues)
:group_id (u/the-id (perms-group/all-users))}]
- (t2/update! :model/Sandbox (:id gtap) {:card_id (:id card)})
+ (t2/update! :model/Sandbox :id (:id gtap) {:card_id (:id card)})
:ok))
"Update query for Card associated with an existing GTAP"
@@ -54,7 +54,7 @@
:model/Sandbox _ {:table_id (mt/id :venues)
:group_id (u/the-id (perms-group/all-users))
:card_id (:id card)}]
- (t2/update! :model/Card (:id card) {:dataset_query query})
+ (t2/update! :model/Card :id (:id card) {:dataset_query query})
:ok))}]
(testing (str "\n" msg "\n")
(testing "sanity check"
@@ -87,7 +87,7 @@
:result_metadata metadata}
:model/Sandbox gtap {:table_id (mt/id :venues)
:group_id (u/the-id (perms-group/all-users))}]
- (t2/update! :model/Sandbox (:id gtap) {:card_id (:id card)})
+ (t2/update! :model/Sandbox :id (:id gtap) {:card_id (:id card)})
:ok))
"Update query for Card associated with an existing GTAP"
@@ -97,7 +97,7 @@
:model/Sandbox _ {:table_id (mt/id :venues)
:group_id (u/the-id (perms-group/all-users))
:card_id (:id card)}]
- (t2/update! :model/Card (:id card) {:result_metadata metadata})
+ (t2/update! :model/Card :id (:id card) {:result_metadata metadata})
:ok))}]
(testing (str "\n" msg "\n")
(is (thrown-with-msg?
@@ -226,15 +226,15 @@
(guarded-writes-test
with-card-policy
(fn [{:keys [card]}]
- [["query" card-msg #(t2/update! :model/Card (:id card) {:dataset_query (mt/mbql-query venues {:limit 1})})]
- ["result metadata" card-msg #(t2/update! :model/Card (:id card)
+ [["query" card-msg #(t2/update! :model/Card :id (:id card) {:dataset_query (mt/mbql-query venues {:limit 1})})]
+ ["result metadata" card-msg #(t2/update! :model/Card :id (:id card)
{:result_metadata (venues-cols "ID" "NAME" "LATITUDE")})]
- ["archive" card-msg #(t2/update! :model/Card (:id card) {:archived true})]
- ["delete" card-msg #(t2/delete! :model/Card (:id card))]]))
+ ["archive" card-msg #(t2/update! :model/Card :id (:id card) {:archived true})]
+ ["delete" card-msg #(t2/delete! :model/Card :id (:id card))]]))
(untouched-test
with-card-policy
(fn [{:keys [other]}]
- (t2/update! :model/Card (:id other) {:dataset_query (mt/mbql-query venues {:limit 1})})))))
+ (t2/update! :model/Card :id (:id other) {:dataset_query (mt/mbql-query venues {:limit 1})})))))
(defn- with-snippet-policy
"A policy whose snippet `outer` splices in snippet `inner`, which in turn reads Card `nested-card` through a
@@ -261,21 +261,21 @@
(guarded-writes-test
with-snippet-policy
(fn [{:keys [inner outer nested-card]}]
- [["content" snippet-msg #(t2/update! :model/NativeQuerySnippet (:id outer)
+ [["content" snippet-msg #(t2/update! :model/NativeQuerySnippet :id (:id outer)
{:content "1 = 1"})]
- ["name" snippet-msg #(t2/update! :model/NativeQuerySnippet (:id outer)
+ ["name" snippet-msg #(t2/update! :model/NativeQuerySnippet :id (:id outer)
{:name (mt/random-name)})]
- ["archive" snippet-msg #(t2/update! :model/NativeQuerySnippet (:id outer)
+ ["archive" snippet-msg #(t2/update! :model/NativeQuerySnippet :id (:id outer)
{:archived true})]
- ["content of the nested snippet" snippet-msg #(t2/update! :model/NativeQuerySnippet (:id inner)
+ ["content of the nested snippet" snippet-msg #(t2/update! :model/NativeQuerySnippet :id (:id inner)
{:content "2 = 2"})]
- ["query of the nested Card" card-msg #(t2/update! :model/Card (:id nested-card)
+ ["query of the nested Card" card-msg #(t2/update! :model/Card :id (:id nested-card)
{:dataset_query (mt/mbql-query venues)})]
- ["delete" snippet-msg #(t2/delete! :model/NativeQuerySnippet (:id outer))]]))
+ ["delete" snippet-msg #(t2/delete! :model/NativeQuerySnippet :id (:id outer))]]))
(untouched-test
with-snippet-policy
(fn [{:keys [other]}]
- (t2/update! :model/NativeQuerySnippet (:id other) {:content "2 = 2"})))))
+ (t2/update! :model/NativeQuerySnippet :id (:id other) {:content "2 = 2"})))))
(defn- venues-query []
(let [mp (mt/metadata-provider)]
@@ -309,16 +309,16 @@
(guarded-writes-test
with-segment-policy
(fn [{:keys [inner outer]}]
- [["definition" segment-msg #(t2/update! :model/Segment (:id outer)
+ [["definition" segment-msg #(t2/update! :model/Segment :id (:id outer)
{:definition (price-above 4)})]
- ["archive" segment-msg #(t2/update! :model/Segment (:id outer) {:archived true})]
- ["definition of the nested segment" segment-msg #(t2/update! :model/Segment (:id inner)
+ ["archive" segment-msg #(t2/update! :model/Segment :id (:id outer) {:archived true})]
+ ["definition of the nested segment" segment-msg #(t2/update! :model/Segment :id (:id inner)
{:definition (price-above 4)})]
- ["delete" segment-msg #(t2/delete! :model/Segment (:id outer))]]))
+ ["delete" segment-msg #(t2/delete! :model/Segment :id (:id outer))]]))
(untouched-test
with-segment-policy
(fn [{:keys [other]}]
- (t2/update! :model/Segment (:id other) {:definition (price-above 5)})))))
+ (t2/update! :model/Segment :id (:id other) {:definition (price-above 5)})))))
(defn- sum-where-measure-definition
"A Measure definition summing VENUES.PRICE over the rows matching `segment-id`."
@@ -368,16 +368,16 @@
(guarded-writes-test
with-measure-policy
(fn [{:keys [segment measure]}]
- [["definition of the nested segment" segment-msg #(t2/update! :model/Segment (:id segment)
+ [["definition of the nested segment" segment-msg #(t2/update! :model/Segment :id (:id segment)
{:definition (price-above 3)})]
- ["definition" measure-msg #(t2/update! :model/Measure (:id measure)
+ ["definition" measure-msg #(t2/update! :model/Measure :id (:id measure)
{:definition (sum-of-price 2)})]
- ["archive" measure-msg #(t2/update! :model/Measure (:id measure) {:archived true})]
- ["delete" measure-msg #(t2/delete! :model/Measure (:id measure))]]))
+ ["archive" measure-msg #(t2/update! :model/Measure :id (:id measure) {:archived true})]
+ ["delete" measure-msg #(t2/delete! :model/Measure :id (:id measure))]]))
(untouched-test
with-measure-policy
(fn [{:keys [other]}]
- (t2/update! :model/Measure (:id other) {:definition (sum-of-price 2)})))))
+ (t2/update! :model/Measure :id (:id other) {:definition (sum-of-price 2)})))))
(deftest non-admin-cannot-rewrite-a-policy-snippet-through-the-api-test
(testing "SEC-1094: a non-admin with native access to an unrelated Database only cannot rewrite a policy snippet"
@@ -453,7 +453,7 @@
run-card (fn [user]
(mt/rows (mt/user-http-request user :post 202 (format "card/%d/query" card-id))))]
(mt/with-test-user :crowberto
- (t2/update! :model/Card card-id {:result_metadata (venues-cols "ID" "NAME")}))
+ (t2/update! :model/Card :id card-id {:result_metadata (venues-cols "ID" "NAME")}))
(testing "the non-admin's query succeeds"
(is (seq (run-card :rasta))))
(testing "the drifted metadata is not overwritten by the non-admin's run"
@@ -552,7 +552,7 @@
(testing "deleting is refused and nothing is deleted"
(let [before (+ (t2/count :model/Card :collection_id (:id coll))
(t2/count :model/NativeQuerySnippet :collection_id (:id coll)))]
- (is (thrown-with-msg? clojure.lang.ExceptionInfo msg (t2/delete! :model/Collection (:id coll))))
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo msg (t2/delete! :model/Collection :id (:id coll))))
(is (t2/exists? :model/Collection :id (:id coll)))
(is (= before (+ (t2/count :model/Card :collection_id (:id coll))
(t2/count :model/NativeQuerySnippet :collection_id (:id coll)))))))))
@@ -562,7 +562,7 @@
(archive-collection! coll)
(is (true? (archived? coll))))
(testing "and deleted"
- (is (= 1 (t2/delete! :model/Collection (:id coll)))))))))))
+ (is (= 1 (t2/delete! :model/Collection :id (:id coll)))))))))))
(testing "an admin may archive and then delete all of them"
(with-mixed-policies!
(fn [colls]
@@ -573,4 +573,4 @@
(is (true? (archived? coll)))))
(doseq [coll (vals colls)]
(testing (:name coll)
- (is (= 1 (t2/delete! :model/Collection (:id coll)))))))))))))
+ (is (= 1 (t2/delete! :model/Collection :id (:id coll)))))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/sandboxing_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/sandboxing_test.clj
index 97fdbab418f..116ea8d6570 100644
--- a/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/sandboxing_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/sandboxing_test.clj
@@ -1198,7 +1198,7 @@
metadata (get-in results [:data :results_metadata :columns])]
(is (seq metadata))
(mt/with-test-user :crowberto
- (t2/update! :model/Card card-id {:result_metadata metadata}))))
+ (t2/update! :model/Card :id card-id {:result_metadata metadata}))))
(deftest native-fk-remapping-test
(testing "FK remapping should still work for questions with native sandboxes (EE #520)"
@@ -1624,9 +1624,9 @@
:model/Sandbox
:group_id (:id &group)
:table_id (mt/id :venues))]
- (is (nil? (t2/select-one-fn :result_metadata :model/Card sandbox-card-id)))
+ (is (nil? (t2/select-one-fn :result_metadata :model/Card :id sandbox-card-id)))
(is (= 10 (count (mt/rows (streaming.test-util/process-query-basic-streaming :api (mt/mbql-query venues))))))
- (is (not (nil? (t2/select-one-fn :result_metadata :model/Card sandbox-card-id))))))))
+ (is (not (nil? (t2/select-one-fn :result_metadata :model/Card :id sandbox-card-id))))))))
(deftest filter-by-column-sandboxing-test
(mt/test-drivers (mt/normal-drivers)
diff --git a/enterprise/backend/test/metabase_enterprise/scim/v2/api_test.clj b/enterprise/backend/test/metabase_enterprise/scim/v2/api_test.clj
index 3ab6dc326d8..29f8e1bb320 100644
--- a/enterprise/backend/test/metabase_enterprise/scim/v2/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/scim/v2/api_test.clj
@@ -100,7 +100,7 @@
:emails [{:value "[email protected]"}]
:active true
:locale nil
- :groups [{:value (t2/select-one-fn :entity_id :model/PermissionsGroup (:id group))
+ :groups [{:value (t2/select-one-fn :entity_id :model/PermissionsGroup :id (:id group))
:display "Test Group"}]
:meta {:resourceType "User"}}
response)))))
@@ -377,7 +377,7 @@
{:schemas ["urn:ietf:params:scim:schemas:core:2.0:Group"]
:id entity-id
:displayName "Test Group"
- :members [{:value (t2/select-one-fn :entity_id :model/User (mt/user->id :rasta))
+ :members [{:value (t2/select-one-fn :entity_id :model/User :id (mt/user->id :rasta))
:display "[email protected]"}]
:meta {:resourceType "Group"}}
response)))))
diff --git a/enterprise/backend/test/metabase_enterprise/search/entity_retrieval/reconcile_test.clj b/enterprise/backend/test/metabase_enterprise/search/entity_retrieval/reconcile_test.clj
index 049b164f9c7..cbe595b6cb2 100644
--- a/enterprise/backend/test/metabase_enterprise/search/entity_retrieval/reconcile_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/search/entity_retrieval/reconcile_test.clj
@@ -180,14 +180,14 @@
(testing "renaming the table mints a new name doc_id and GCs the old one"
(let [old-name-id (->> (docs-for ds "table" table-id)
(filter #(= "name" (:doc_type %))) first :doc_id)]
- (t2/update! :model/Table table-id {:display_name "Sales Orders"})
+ (t2/update! :model/Table :id table-id {:display_name "Sales Orders"})
(reconcile/reconcile! ds (constantly model))
(let [names (filter #(= "name" (:doc_type %)) (docs-for ds "table" table-id))]
(is (= 1 (count names)))
(is (= "Sales Orders" (:doc_text (first names))))
(is (not= old-name-id (:doc_id (first names)))))))
(testing "unpublishing the table removes it from the library, GCing all its docs"
- (t2/update! :model/Table table-id {:is_published false})
+ (t2/update! :model/Table :id table-id {:is_published false})
(reconcile/reconcile! ds (constantly model))
(is (empty? (docs-for ds "table" table-id)))
(is (seq (docs-for ds "metric" metric-id)) "the metric is untouched")))))))
@@ -360,8 +360,8 @@
(reconcile/reconcile! ds (constantly model))
;; `edited` is renamed (old name doc -> orphan, new name doc -> to-insert);
;; `leaving` is unpublished (its docs -> orphans, with nothing in to-insert).
- (t2/update! :model/Table edited {:display_name "Edited New"})
- (t2/update! :model/Table leaving {:is_published false})
+ (t2/update! :model/Table :id edited {:display_name "Edited New"})
+ (t2/update! :model/Table :id leaving {:is_published false})
;; force the insert of the only to-insert batch (edited's new name doc) to fail.
(mt/with-dynamic-fn-redefs [reconcile/insert-batch! (fn [& _] (throw (ex-info "boom" {})))]
(reconcile/reconcile! ds (constantly model)))
diff --git a/enterprise/backend/test/metabase_enterprise/security_center/notification_test.clj b/enterprise/backend/test/metabase_enterprise/security_center/notification_test.clj
index bf914500e16..13ee7eaa201 100644
--- a/enterprise/backend/test/metabase_enterprise/security_center/notification_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/security_center/notification_test.clj
@@ -239,7 +239,7 @@
(is (nil? (:last_notified_at advisory)))
(with-send-redef (constantly nil)
(notification/notify-advisory! advisory))
- (is (some? (:last_notified_at (t2/select-one :model/SecurityAdvisory (:id advisory))))))))
+ (is (some? (:last_notified_at (t2/select-one :model/SecurityAdvisory :id (:id advisory))))))))
(deftest notify-advisory-does-not-update-on-send-failure-test
(testing "last_notified_at is NOT set when send-notification! throws"
@@ -250,7 +250,7 @@
(with-send-redef (fn [& _] (throw (ex-info "boom" {})))
(is (thrown-with-msg? Exception #"boom"
(notification/notify-advisory! advisory))))
- (is (nil? (:last_notified_at (t2/select-one :model/SecurityAdvisory (:id advisory))))))))
+ (is (nil? (:last_notified_at (t2/select-one :model/SecurityAdvisory :id (:id advisory))))))))
;;; -------------------------------------------- Recipient resolution -------------------------------------------------
@@ -476,7 +476,7 @@
(with-send-redef (fn [& _] (throw (delivery-failure :channel/slack)))
(is (= {"email" "success" "slack" "failure"}
(tracked-results! #(notification/notify-advisory! advisory))))))
- (is (some? (:last_notified_at (t2/select-one :model/SecurityAdvisory (:id advisory)))))))))
+ (is (some? (:last_notified_at (t2/select-one :model/SecurityAdvisory :id (:id advisory)))))))))
(deftest notify-advisory-every-channel-failed-test
(testing "when no channel delivers, notify-advisory! throws and last_notified_at stays unset, so the next sync retries"
@@ -490,7 +490,7 @@
(is (= {"email" "failure" "slack" "failure"}
(tracked-results! #(is (thrown-with-msg? Exception #"Failed to deliver"
(notification/notify-advisory! advisory)))))))))
- (is (nil? (:last_notified_at (t2/select-one :model/SecurityAdvisory (:id advisory))))))))
+ (is (nil? (:last_notified_at (t2/select-one :model/SecurityAdvisory :id (:id advisory))))))))
(deftest notify-advisory-partial-delivery-through-the-pipeline-test
(testing "the real send: email delivers, the Slack post fails, and the advisory counts as notified"
@@ -511,4 +511,4 @@
(swap! sent conj channel-type))]
(notification/notify-advisory! advisory))
(is (= [:channel/email] @sent)))))
- (is (some? (:last_notified_at (t2/select-one :model/SecurityAdvisory (:id advisory))))))))
+ (is (some? (:last_notified_at (t2/select-one :model/SecurityAdvisory :id (:id advisory))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/security_center/task/sync_advisories_test.clj b/enterprise/backend/test/metabase_enterprise/security_center/task/sync_advisories_test.clj
index 6181b54cd39..5eedbb83a36 100644
--- a/enterprise/backend/test/metabase_enterprise/security_center/task/sync_advisories_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/security_center/task/sync_advisories_test.clj
@@ -89,6 +89,6 @@
(mt/with-dynamic-fn-redefs [premium-features/security-center-enabled? (constantly true)
fetch/sync-advisories! (constantly nil)]
(#'sync-advisories/sync-and-evaluate!)
- (let [updated (t2/select-one :model/SecurityAdvisory (:id advisory))]
+ (let [updated (t2/select-one :model/SecurityAdvisory :id (:id advisory))]
(is (= :active (:match_status updated)))
(is (some? (:last_evaluated_at updated)))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj
index 06ee5b7de5b..d1a758db20a 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj
@@ -343,7 +343,7 @@
(snowplow-test/pop-event-data-and-user-id!)
;; Modify entities in the database
(t2/update! :model/Dashboard {:id (:id dash)} {:name "urquan"})
- (t2/delete! :model/Card (:id card))
+ (t2/delete! :model/Card :id (:id card))
(let [re-indexed? (atom false)
_res (mt/with-dynamic-fn-redefs [search/reindex! (fn [& _] (reset! re-indexed? true) (future nil))]
(mt/user-http-request :crowberto :post 200 "ee/serialization/import?reindex=false"
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/dependency_validation_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/dependency_validation_test.clj
index 6ca2f9cb2e6..e25759a8f5a 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/dependency_validation_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/dependency_validation_test.clj
@@ -164,16 +164,16 @@
(doseq [{:keys [label query-filter viz-settings delete! msg-re]}
[{:label "a Field referenced in the query"
:query-filter (fn [field-id _seg-id] [:> [:field field-id nil] 1])
- :delete! (fn [field-id _seg-id] (t2/delete! :model/Field field-id))
+ :delete! (fn [field-id _seg-id] (t2/delete! :model/Field :id field-id))
:msg-re #"Field .* is missing from the source database"}
{:label "a Segment referenced in the query"
:query-filter (fn [_field-id seg-id] [:segment seg-id])
- :delete! (fn [_field-id seg-id] (t2/delete! :model/Segment seg-id))
+ :delete! (fn [_field-id seg-id] (t2/delete! :model/Segment :id seg-id))
:msg-re #"Segment .* is missing from the source database"}
{:label "a Field referenced only in visualization_settings"
:viz-settings (fn [field-id] {:column_settings {(str "[\"ref\",[\"field\"," field-id ",null]]")
{:column_title "X"}}})
- :delete! (fn [field-id _seg-id] (t2/delete! :model/Field field-id))
+ :delete! (fn [field-id _seg-id] (t2/delete! :model/Field :id field-id))
:msg-re #"Field .* is missing from the source database"}]]
(testing label
(ts/with-temp-dpc [:model/Field {field-id :id} {:table_id table-id :name "F" :base_type :type/Integer}
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/e2e_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/e2e_test.clj
index 4420c9746cd..52ab4f4208f 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/e2e_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/e2e_test.clj
@@ -714,9 +714,9 @@
new-coll-id (t2/select-one-pk :model/Collection :entity_id coll-eid)
new-card-id (t2/select-one-pk :model/Card :entity_id card-eid)]
(is (= new-dash-id (:dashboard_id
- (t2/select-one :model/Card new-card-id))))
+ (t2/select-one :model/Card :id new-card-id))))
(is (= new-coll-id (:collection_id
- (t2/select-one :model/Card new-card-id))))))))))))))
+ (t2/select-one :model/Card :id new-card-id))))))))))))))
(deftest database-routing-test
(testing "Destination Databases and Database Routers are excluded from serialization"
@@ -1015,10 +1015,10 @@
[:field %products.category {:join-alias "Products"}]]}]})}]
;; Populate the native source card's result_metadata the way the app does when a user runs and
;; saves the query. This is the state serdes must preserve across the round-trip.
- (let [source-cols (-> (qp/process-query (t2/select-one-fn :dataset_query (card-schema/selection) native-id))
+ (let [source-cols (-> (qp/process-query (t2/select-one-fn :dataset_query (card-schema/selection) :id native-id))
(get-in [:data :results_metadata :columns]))
source-names (mapv :name source-cols)]
- (t2/update! :model/Card native-id {:result_metadata source-cols})
+ (t2/update! :model/Card :id native-id {:result_metadata source-cols})
(let [extraction (serdes/with-cache (into [] (extract/extract {})))]
(storage/store! (seq extraction) (storage.files/file-writer dump-dir)))
(ts/with-db dest-db
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj
index b3f262e6a2d..8e1286c3550 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj
@@ -1717,8 +1717,8 @@
{:type "link"
:linkType "question"
:targetId deleted-card-id}}}}}]
- (t2/delete! :model/Card deleted-card-id)
- (t2/delete! :model/Dashboard deleted-dash-id)
+ (t2/delete! :model/Card :id deleted-card-id)
+ (t2/delete! :model/Dashboard :id deleted-dash-id)
(testing "the references to deleted cards and dashboards are ignored"
(is (= #{[{:model "Dashboard" :id clickdash-eid :label "dashboard"}]
[{:model "Collection" :id coll-eid :label "some_collection"}]
@@ -1939,7 +1939,7 @@
{:card-id (:id c)}))]
(when-not (= (:status res) :completed)
(throw (ex-info "Query failed" res)))
- (let [ser (serdes/extract-one "Card" nil (t2/select-one :model/Card (:id c)))]
+ (let [ser (serdes/extract-one "Card" nil (t2/select-one :model/Card :id (:id c)))]
(is (=? {:fk_target_field_id [string? "PUBLIC" "CATEGORIES" "ID"]}
(->> (:result_metadata ser)
(u/seek #(and (= (:name %) "CATEGORY_ID")
@@ -1959,7 +1959,7 @@
[:model/Card {card-id :id} {:type :model
:dataset_query (mt/query venues)
:result_metadata overridden}]
- (let [extracted (serdes/extract-one "Card" nil (t2/select-one :model/Card card-id))
+ (let [extracted (serdes/extract-one "Card" nil (t2/select-one :model/Card :id card-id))
by-name (u/index-by :name (:result_metadata extracted))]
(is (every? #(re-matches #"Custom .*" (:display_name %))
(:result_metadata extracted)))
@@ -1987,7 +1987,7 @@
:base_type :type/Text
:effective_type :type/Text
:semantic_type :type/Title}]}]
- (let [extracted (serdes/extract-one "Card" nil (t2/select-one :model/Card card-id))
+ (let [extracted (serdes/extract-one "Card" nil (t2/select-one :model/Card :id card-id))
by-name (u/index-by :name (:result_metadata extracted))]
(testing "physical passthrough column keeps its types"
(is (= :type/Integer (:base_type (get by-name "project_id"))))
@@ -2409,7 +2409,7 @@
:schema "public"
:name "orphan_target"}}]
;; Delete the database — ON DELETE SET NULL nulls source_database_id and target_db_id.
- (t2/delete! :model/Database db-id)
+ (t2/delete! :model/Database :id db-id)
(let [reloaded (t2/hydrate (t2/select-one :model/Transform :id transform-id) :tags :indexes)
ser (serdes/extract-one "Transform" {} reloaded)]
(is (nil? (:source_database_id reloaded))
@@ -2846,7 +2846,7 @@
:model/Card {card-id :id} {:name "MBQL Card"
:dataset_query (mbql5-query db-id table-id)
:display :table}]
- (let [ser (serdes/extract-one "Card" {} (t2/select-one :model/Card card-id))]
+ (let [ser (serdes/extract-one "Card" {} (t2/select-one :model/Card :id card-id))]
(is (not (contains? ser :table_id))
"table_id should be omitted — derivable from dataset_query")
(is (not (contains? ser :query_type))
@@ -2864,7 +2864,7 @@
:database_id db-id
:dataset_query {}
:display :table}]
- (let [ser (serdes/extract-one "Card" {} (t2/select-one :model/Card card-id))]
+ (let [ser (serdes/extract-one "Card" {} (t2/select-one :model/Card :id card-id))]
(is (= "Test DB" (:database_id ser))
"database_id should be kept when query is empty"))))))
@@ -2877,7 +2877,7 @@
:model/Card {card-id :id} {:name "MBQL Card"
:dataset_query (mbql5-query db-id table-id)
:display :table}]
- (let [ser (serdes/extract-one "Card" {} (t2/select-one :model/Card card-id))
+ (let [ser (serdes/extract-one "Card" {} (t2/select-one :model/Card :id card-id))
deps (serdes/deserialization-dependencies ser)]
(is (not-any? #(some (fn [step] (#{"Database" "Table" "Field"} (:model step))) %) deps)
"Database/Table/Field should not be dependencies"))))))
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj
index 9327273e019..d873c4fad5e 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj
@@ -259,7 +259,7 @@
(is (true? (:is_stub stub)))
(is (= {:type/Currency true :type/City true}
(into {} (map (juxt first second)) (vals (settings)))))
- (t2/update! :model/Database (:id stub) {:engine :h2 :details (:details (mt/db)) :is_stub false})
+ (t2/update! :model/Database :id (:id stub) {:engine :h2 :details (:details (mt/db)) :is_stub false})
(sync/sync-db-metadata! (:id (t2/select-one :model/Database :id (:id stub))))
(testing "sync reactivates the stub Fields and gives them their real base types"
(is (=? [{:name "NAME" :active true :base_type :type/Text}
@@ -329,11 +329,11 @@
table (ts/create! :model/Table :name "customers" :db_id (:id db) :owner_user_id (:id owner))
file (ts/extract-one "Table" (:id table))
load! (fn [entity] (serdes.load/load-metabase! (ts/ingestion-in-memory [entity])))]
- (t2/update! :model/Table (:id table) {:owner_user_id nil})
+ (t2/update! :model/Table :id (:id table) {:owner_user_id nil})
(load! file)
- (is (= (:id owner) (t2/select-one-fn :owner_user_id :model/Table (:id table))))
+ (is (= (:id owner) (t2/select-one-fn :owner_user_id :model/Table :id (:id table))))
(load! (assoc file :owner_user_id (:id other)))
- (is (= (:id other) (t2/select-one-fn :owner_user_id :model/Table (:id table))))))))
+ (is (= (:id other) (t2/select-one-fn :owner_user_id :model/Table :id (:id table))))))))
(deftest legacy-table-user-settings-fields-import-test
(testing "a settings file written before Field settings got files of their own replaces its Table's Field settings"
@@ -361,7 +361,7 @@
email (ts/create! :model/Field :name "email" :table_id (:id table))
_ (t2/insert! :model/FieldUserSettings {:field_id (:id email) :description "edited"})
settings (ts/extract-one "FieldUserSettings" (:id email))]
- (t2/update! :model/FieldUserSettings (:id email) {:display_name "Local"})
+ (t2/update! :model/FieldUserSettings :field_id (:id email) {:display_name "Local"})
(serdes.load/load-metabase! (ts/ingestion-in-memory [settings]))
(is (=? {:description "edited" :display_name nil}
(t2/select-one :model/FieldUserSettings :field_id (:id email))))))))
@@ -1933,7 +1933,7 @@
:details {:let-user-control-scheduling true}
:metadata_sync_schedule "0 10 * * * ? *"
:cache_field_values_schedule "0 0 16 * * ? *")]
- (t2/delete! :model/Database (:id db))
+ (t2/delete! :model/Database :id (:id db))
(serdes.load/load-metabase! (ts/ingestion-in-memory [file]))
(is (=? {:metadata_sync_schedule "0 10 * * * ? *"
:cache_field_values_schedule "0 0 16 * * ? *"}
@@ -2037,9 +2037,9 @@
(serdes.load/load-metabase! (ts/ingestion-in-memory extract1))
(ts/with-db source-db
;; delete the 1st series and update the 3rd series to have position 0, and the 2nd series to have position 1
- (t2/delete! :model/DashboardCardSeries (:id series1s))
- (t2/update! :model/DashboardCardSeries (:id series3s) {:position 0})
- (t2/update! :model/DashboardCardSeries (:id series2s) {:position 1})
+ (t2/delete! :model/DashboardCardSeries :id (:id series1s))
+ (t2/update! :model/DashboardCardSeries :id (:id series3s) {:position 0})
+ (t2/update! :model/DashboardCardSeries :id (:id series2s) {:position 1})
(let [extract2 (into [] (serdes.extract/extract {:no-settings true :no-data-model true}))]
(ts/with-db dest-db
(let [series-card2d (t2/select-one :model/Card :entity_id (:entity_id series-card2s))
@@ -2300,7 +2300,7 @@
(ts/with-db source-db
(let [coll (ts/create! :model/Collection :name "coll")
card (ts/create! :model/Card :name "self-ref card" :collection_id (:id coll))
- _ (t2/update! :model/Card (:id card)
+ _ (t2/update! :model/Card :id (:id card)
{:parameters [(card-sourced-param (:id card))]})
ser (into [] (serdes.extract/extract {:no-settings true
:no-data-model false}))]
@@ -2323,8 +2323,8 @@
(let [coll (ts/create! :model/Collection :name "coll")
card-a (ts/create! :model/Card :name "card a" :collection_id (:id coll))
card-b (ts/create! :model/Card :name "card b" :collection_id (:id coll))
- _ (t2/update! :model/Card (:id card-a) {:parameters [(card-sourced-param (:id card-b))]})
- _ (t2/update! :model/Card (:id card-b) {:parameters [(card-sourced-param (:id card-a))]})
+ _ (t2/update! :model/Card :id (:id card-a) {:parameters [(card-sourced-param (:id card-b))]})
+ _ (t2/update! :model/Card :id (:id card-b) {:parameters [(card-sourced-param (:id card-a))]})
ser (into [] (serdes.extract/extract {:no-settings true
:no-data-model false}))]
(testing "loading on top of the existing cards"
@@ -2353,7 +2353,7 @@
dash (ts/create! :model/Dashboard :name "dash" :collection_id (:id coll))
card (ts/create! :model/Card :name "dq card" :type :question :dashboard_id (:id dash))
_ (ts/create! :model/DashboardCard :dashboard_id (:id dash) :card_id (:id card))
- _ (t2/update! :model/Dashboard (:id dash)
+ _ (t2/update! :model/Dashboard :id (:id dash)
{:parameters [(card-sourced-param (:id card))]})
ser (into [] (serdes.extract/extract {:no-settings true
:no-data-model false}))]
@@ -2529,10 +2529,10 @@
{:model "Field" :id "field"}
{:model "Field" :id "field"}]}
(ts/extract-one "Field" (:id f3))))
- (t2/update! :model/Field (:id f3) {:description "some new one"})
+ (t2/update! :model/Field :id (:id f3) {:description "some new one"})
(is (serdes.load/load-metabase! (ts/ingestion-in-memory ser)))
(is (= "desc"
- (t2/select-one-fn :description :model/Field (:id f3)))))))
+ (t2/select-one-fn :description :model/Field :id (:id f3)))))))
(deftest field-data-sensitivity-round-trip-test
(testing "data_sensitivity travels through export and import on both Field and FieldUserSettings"
@@ -3457,18 +3457,18 @@
(let [import! (fn [job-id active]
(serdes.load/load-metabase!
(ts/ingestion-in-memory [(assoc (ts/extract-one "TransformJob" job-id) :active active)]))
- (t2/select-one [:model/TransformJob :active :built_in_type] job-id))]
+ (t2/select-one [:model/TransformJob :active :built_in_type] :id job-id))]
(testing "an import keeps active on an existing built-in job"
(is (=? {:active false :built_in_type "hourly"} (import! built-in-id true)))
- (t2/update! :transform_job built-in-id {:active true})
+ (t2/update! :transform_job :id built-in-id {:active true})
(is (=? {:active true :built_in_type "hourly"} (import! built-in-id false))))
(testing "an import keeps active on an existing custom job"
(is (=? {:active false :built_in_type nil} (import! custom-id true)))
- (t2/update! :transform_job custom-id {:active true})
+ (t2/update! :transform_job :id custom-id {:active true})
(is (=? {:active true :built_in_type nil} (import! custom-id false))))
(testing "an import inserts a job with the column default for active"
(let [extracted (assoc (ts/extract-one "TransformJob" custom-id) :active false)]
- (t2/delete! :model/TransformJob custom-id)
+ (t2/delete! :model/TransformJob :id custom-id)
(serdes.load/load-metabase! (ts/ingestion-in-memory [extracted]))
(is (=? {:active true}
(t2/select-one [:model/TransformJob :active] :entity_id (:entity_id extracted))))
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/metric_dimensions_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/metric_dimensions_test.clj
index 3cb53a03061..81c44e0aed1 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/metric_dimensions_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/metric_dimensions_test.clj
@@ -187,7 +187,7 @@
(prepare-destination!)
(serdes.load/load-metabase! (ingestion-in-memory (extract-source))))
(ts/with-db source-db
- (t2/update! :model/Card (-> source :card :id)
+ (t2/update! :model/Card :id (-> source :card :id)
{:dimensions (filterv #(= dim-a-id (:id %))
(-> source :card :dimensions))
:dimension_mappings (filterv #(= dim-a-id (:dimension-id %))
diff --git a/enterprise/backend/test/metabase_enterprise/session_management/api_test.clj b/enterprise/backend/test/metabase_enterprise/session_management/api_test.clj
index 8a8b34f403a..d39db3a505e 100644
--- a/enterprise/backend/test/metabase_enterprise/session_management/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/session_management/api_test.clj
@@ -159,7 +159,7 @@
(testing "the default population includes internal and external sessions"
(is (= {:active (+ live-before 2), :ended ended-before}
(mt/user-http-request :crowberto :get 200 "ee/session-management/counts"))))
- (t2/update! :model/Tenant tenant-id {:is_active false})
+ (t2/update! :model/Tenant :id tenant-id {:is_active false})
(testing "an inactive tenant's sessions move to ended"
(is (= {:active (inc live-before), :ended (inc ended-before)}
(mt/user-http-request :crowberto :get 200 "ee/session-management/counts")))))))))
@@ -279,7 +279,7 @@
;; `:event/user-credentials-revoked`, whose handler deletes the user's sessions outright (SEC-863). Going
;; through the model would leave no row for the liveness predicate to reject, so this test would pass even
;; with `[:= :user.is_active true]` deleted from `live-session-conditions`.
- (t2/update! (t2/table-name :model/User) user-id {:is_active false})
+ (t2/update! (t2/table-name :model/User) :id user-id {:is_active false})
(is (t2/exists? (t2/table-name :model/Session) :id session-id)
"the session row survives deactivation; it is the predicate that must reject it")
(let [response (list-sessions user-id)]
@@ -519,7 +519,7 @@
(testing "tenancy=external shows only them"
(is (= #{ext-session} (listed :tenancy "external"))))
(testing "a session belonging to a deactivated tenant is not live at all"
- (t2/update! :model/Tenant tenant-id {:is_active false})
+ (t2/update! :model/Tenant :id tenant-id {:is_active false})
(is (= #{int-session} (listed))))))))))
;;; +----------------------------------------------------------------------------------------------------------------+
diff --git a/enterprise/backend/test/metabase_enterprise/session_management/query_test.clj b/enterprise/backend/test/metabase_enterprise/session_management/query_test.clj
index 65d02c878a4..dcc2419233f 100644
--- a/enterprise/backend/test/metabase_enterprise/session_management/query_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/session_management/query_test.clj
@@ -105,7 +105,7 @@
;; `:event/user-credentials-revoked`, whose handler deletes the user's sessions outright (SEC-863). Going
;; through the model would leave nothing for `[:= :user.is_active true]` to reject, and this test would pass
;; with that predicate deleted.
- (t2/update! (t2/table-name :model/User) user-id {:is_active false})
+ (t2/update! (t2/table-name :model/User) :id user-id {:is_active false})
(is (t2/exists? (t2/table-name :model/Session) :id id)
"the session row survives deactivation; it is the predicate that must reject it")
(is (= #{} (listed-ids lp :user-id user-id)))
diff --git a/enterprise/backend/test/metabase_enterprise/snippet_collections/api/native_query_snippet_test.clj b/enterprise/backend/test/metabase_enterprise/snippet_collections/api/native_query_snippet_test.clj
index 61b915271e8..246f6d0dc0b 100644
--- a/enterprise/backend/test/metabase_enterprise/snippet_collections/api/native_query_snippet_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/snippet_collections/api/native_query_snippet_test.clj
@@ -112,7 +112,7 @@
(doseq [dest-collection [dest root-collection]]
(letfn [(has-perms? []
;; make sure the Snippet is back in the original Collection if it was changed
- (t2/update! :model/NativeQuerySnippet (:id snippet) {:collection_id (:id source-collection)})
+ (t2/update! :model/NativeQuerySnippet :id (:id snippet) {:collection_id (:id source-collection)})
(let [response (mt/user-http-request :rasta :put (format "native-query-snippet/%d" (:id snippet))
{:collection_id (:id dest-collection)})]
(cond
diff --git a/enterprise/backend/test/metabase_enterprise/sso/integrations/jwt_bearer_grant_test.clj b/enterprise/backend/test/metabase_enterprise/sso/integrations/jwt_bearer_grant_test.clj
index a26eed39a00..7cbb17b8336 100644
--- a/enterprise/backend/test/metabase_enterprise/sso/integrations/jwt_bearer_grant_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sso/integrations/jwt_bearer_grant_test.clj
@@ -157,11 +157,11 @@
(testing "an existing user gets a token with provisioning off"
(mt/with-temporary-setting-values [jwt-user-provisioning-enabled? false]
(is (=? {:access_token string?} (token! email)))))
- (t2/update! :model/User user-id {:is_active false})
+ (t2/update! :model/User :id user-id {:is_active false})
(testing "a deactivated user is refused with provisioning off, and reactivated with it on"
(is (=? {:error "invalid_grant"} (refused)))
(is (=? {:access_token string?} (token! email)))
- (is (true? (t2/select-one-fn :is_active :model/User user-id))))))))
+ (is (true? (t2/select-one-fn :is_active :model/User :id user-id))))))))
(deftest exchange-non-personal-user-test
(testing "a JWT naming an API key's user or the internal user is refused, and leaves that user as it was"
@@ -377,6 +377,6 @@
(str "Bearer " access-token)}}})))))
(testing "deactivating the user revokes the token"
(is (some? (mcp-session access-token)))
- (t2/update! :model/User (t2/select-one-pk :model/User :email email) {:is_active false})
+ (t2/update! :model/User :id (t2/select-one-pk :model/User :email email) {:is_active false})
(is (=? {:error {:message "Invalid bearer token"}}
(:body (mcp-request 401 access-token nil "initialize" {:capabilities {}}))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/sso/integrations/jwt_test.clj b/enterprise/backend/test/metabase_enterprise/sso/integrations/jwt_test.clj
index fc43966bca5..575e2abf722 100644
--- a/enterprise/backend/test/metabase_enterprise/sso/integrations/jwt_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sso/integrations/jwt_test.clj
@@ -1455,7 +1455,7 @@
:last_name "User"}
default-jwt-secret))]
(is (sso.test-setup/successful-login? response))
- (let [tenant (t2/select-one :model/Tenant tenant-id)]
+ (let [tenant (t2/select-one :model/Tenant :id tenant-id)]
(testing "existing 'plan' attribute is preserved, not overwritten"
(is (= "enterprise" (get (:attributes tenant) "plan"))))
(testing "new 'region' attribute is added"
diff --git a/enterprise/backend/test/metabase_enterprise/sso/models/relay_state_test.clj b/enterprise/backend/test/metabase_enterprise/sso/models/relay_state_test.clj
index 185bbd57b57..e3d35c3d567 100644
--- a/enterprise/backend/test/metabase_enterprise/sso/models/relay_state_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/sso/models/relay_state_test.clj
@@ -70,7 +70,7 @@
(mt/with-model-cleanup [:model/SsoRelayState]
(let [key (store! {:continue-url "http://localhost:3000/auth/sso"})]
;; backdate so the entry is already expired
- (t2/update! :model/SsoRelayState (stored-id key) {:expires_at (t/minus (t/offset-date-time) (t/seconds 1))})
+ (t2/update! :model/SsoRelayState :id (stored-id key) {:expires_at (t/minus (t/offset-date-time) (t/seconds 1))})
(is (nil? (relay-state/find-unexpired key))))))
(testing "find-unexpired ignores values that aren't our keys (legacy Base64 RelayState)"
(is (nil? (relay-state/find-unexpired "aHR0cDovL2xvY2FsaG9zdA==")))))
@@ -90,7 +90,7 @@
(mt/with-model-cleanup [:model/SsoRelayState]
(let [live (store! {:continue-url "http://localhost:3000/auth/sso" :origin "*"})
expired (store! {:continue-url "http://localhost:3000/auth/sso" :origin "*"})]
- (t2/update! :model/SsoRelayState (stored-id expired) {:expires_at (t/minus (t/offset-date-time) (t/seconds 1))})
+ (t2/update! :model/SsoRelayState :id (stored-id expired) {:expires_at (t/minus (t/offset-date-time) (t/seconds 1))})
;; delete-expired! operates globally, so don't assert an exact count (other tests may leave rows) —
;; just confirm our expired entry is purged and the live one survives.
(is (pos? (relay-state/delete-expired!)))
diff --git a/enterprise/backend/test/metabase_enterprise/stale/api_test.clj b/enterprise/backend/test/metabase_enterprise/stale/api_test.clj
index b73b9d28b1a..fd6b06aa662 100644
--- a/enterprise/backend/test/metabase_enterprise/stale/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/stale/api_test.clj
@@ -69,7 +69,7 @@
(with-collection-hierarchy! [{:keys [a b]}]
(stale.test/with-stale-items [:model/Card card {:collection_id (:id a)}
:model/Card hidden {:collection_id (:id b)}]
- (t2/update! :model/Collection (:id b) {:archived true})
+ (t2/update! :model/Collection :id (:id b) {:archived true})
(let [result (mt/user-http-request :crowberto :get 200 (stale-url a) :is_recursive true)
ids (->> result :data (map (juxt :model :id)) set)]
(is (contains? ids ["card" (u/the-id card)]))
diff --git a/enterprise/backend/test/metabase_enterprise/support_access_grants/core_test.clj b/enterprise/backend/test/metabase_enterprise/support_access_grants/core_test.clj
index 879ee7ab41c..739b1921f07 100644
--- a/enterprise/backend/test/metabase_enterprise/support_access_grants/core_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/support_access_grants/core_test.clj
@@ -413,7 +413,7 @@
(is (t2/exists? :model/Session :user_id support-user-id :ended_at nil)))
(testing "once the grant window has passed the sweep revokes access"
;; Move the grant's end into the past; `revoked_at` stays nil, so nothing else cleans up.
- (t2/update! :model/SupportAccessGrantLog (:id grant)
+ (t2/update! :model/SupportAccessGrantLog :id (:id grant)
{:grant_end_timestamp (t/minus (t/instant) (t/minutes 1))})
(grants/expire-ended-grants!)
(is (not (:is_superuser (t2/select-one :model/User :id support-user-id)))
@@ -442,7 +442,7 @@
(t2/insert! :model/Session {:id "otheruser001"
:user_id other-user-id
:session_key (str (random-uuid))})
- (t2/update! :model/SupportAccessGrantLog (:id grant)
+ (t2/update! :model/SupportAccessGrantLog :id (:id grant)
{:grant_end_timestamp (t/minus (t/instant) (t/minutes 1))})
(grants/expire-ended-grants!)
(is (:is_superuser (t2/select-one :model/User :id other-user-id)))
@@ -468,7 +468,7 @@
create-started (promise)
original-revoke-user-access! (dynamic-redefs/original-fn
#'sag.model/revoke-support-user-access!)]
- (t2/update! :model/SupportAccessGrantLog (:id ended-grant)
+ (t2/update! :model/SupportAccessGrantLog :id (:id ended-grant)
{:grant_end_timestamp (t/minus (t/instant) (t/minutes 1))})
(mt/with-dynamic-fn-redefs
[sag.model/revoke-support-user-access!
@@ -490,7 +490,7 @@
(deliver allow-teardown true)
(is (not= ::timeout (deref expire-result 5000 ::timeout)))
(let [new-grant (deref create-result 5000 ::timeout)
- support-user (t2/select-one :model/User support-user-id)
+ support-user (t2/select-one :model/User :id support-user-id)
auth-identity (t2/select-one :model/AuthIdentity
:user_id support-user-id
:provider "support-access-grant")]
diff --git a/enterprise/backend/test/metabase_enterprise/support_access_grants/models/support_access_grant_log_test.clj b/enterprise/backend/test/metabase_enterprise/support_access_grants/models/support_access_grant_log_test.clj
index febcc9d5250..ab73f3d2a34 100644
--- a/enterprise/backend/test/metabase_enterprise/support_access_grants/models/support_access_grant_log_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/support_access_grants/models/support_access_grant_log_test.clj
@@ -30,7 +30,7 @@
:user_id support-user-id
:session_key "test1"
:auth_identity_id (t2/select-one-pk :model/AuthIdentity :user_id support-user-id)}]
- (t2/update! :model/SupportAccessGrantLog grant-id {:notes "Updated notes"})
+ (t2/update! :model/SupportAccessGrantLog :id grant-id {:notes "Updated notes"})
(is (nil? (t2/select-one-fn :ended_at :model/Session :id session-id))
"Session should still be live after non-revocation update")
(is (nil? (:expires_at (t2/select-one :model/AuthIdentity :provider "password" :user_id support-user-id)))
@@ -68,8 +68,8 @@
:user_id other-user-id
:provider "password")}]
(let [revoked-timestamp (t/offset-date-time)]
- (t2/update! :model/SupportAccessGrantLog grant-id {:revoked_at revoked-timestamp
- :revoked_by_user_id grant-creator-id})
+ (t2/update! :model/SupportAccessGrantLog :id grant-id {:revoked_at revoked-timestamp
+ :revoked_by_user_id grant-creator-id})
(is (=? {:end_reason "support-grant-revoked", :ended_by_user_id grant-creator-id, :key_hashed nil}
(t2/select-one :model/Session :id support-session-id))
"Support user session should be ended, attributed to the revoker, and its key destroyed")
diff --git a/enterprise/backend/test/metabase_enterprise/support_access_grants/provider_test.clj b/enterprise/backend/test/metabase_enterprise/support_access_grants/provider_test.clj
index 35f6aed000e..f863644172c 100644
--- a/enterprise/backend/test/metabase_enterprise/support_access_grants/provider_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/support_access_grants/provider_test.clj
@@ -164,7 +164,7 @@
auth-identity (t2/select-one :model/AuthIdentity
:user_id user-id
:provider "support-access-grant")]
- (t2/update! :model/AuthIdentity (:id auth-identity)
+ (t2/update! :model/AuthIdentity :id (:id auth-identity)
{:credentials (assoc (:credentials auth-identity)
:expires_at (t/minus (t/offset-date-time) (t/hours 1)))})
(let [result (provider/authenticate :provider/support-access-grant {:token token})]
diff --git a/enterprise/backend/test/metabase_enterprise/support_access_grants/session_integration_test.clj b/enterprise/backend/test/metabase_enterprise/support_access_grants/session_integration_test.clj
index 58fcbe0d584..23e83d5f888 100644
--- a/enterprise/backend/test/metabase_enterprise/support_access_grants/session_integration_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/support_access_grants/session_integration_test.clj
@@ -340,7 +340,7 @@
:ticket_number "TICKET-FIRST"))))
;; Deactivate the support user (simulates admin action or cleanup)
(let [support-user (t2/select-one [:model/User :id :is_active] :email email)]
- (t2/update! :model/User (:id support-user) {:is_active false})
+ (t2/update! :model/User :id (:id support-user) {:is_active false})
(is (false? (:is_active (t2/select-one [:model/User :is_active]
:id (:id support-user))))
"User should be deactivated"))
diff --git a/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj b/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj
index 5a7c763a152..b8e8af71cf3 100644
--- a/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj
@@ -407,7 +407,7 @@
(mt/with-model-cleanup [:model/Collection]
(let [{id :id} (mt/user-http-request :crowberto :post 200 "collection/" {:namespace collection/shared-tenant-ns
:name (mt/random-name)})
- coll (t2/select-one :model/Collection id)]
+ coll (t2/select-one :model/Collection :id id)]
(is (some? coll))
(is (= collection/shared-tenant-ns (:namespace coll))))))))
@@ -421,7 +421,7 @@
(mt/with-temp [:model/Collection {parent-id :id} {:namespace collection/shared-tenant-ns}]
(let [id (:id (mt/user-http-request :crowberto :post 200 "collection/" {:name (mt/random-name)
:parent_id parent-id}))
- coll (t2/select-one :model/Collection id)]
+ coll (t2/select-one :model/Collection :id id)]
(is (some? id))
(is (= collection/shared-tenant-ns (:namespace coll))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/tenants/models_test.clj b/enterprise/backend/test/metabase_enterprise/tenants/models_test.clj
index 08cda94c5cd..9a476472d1c 100644
--- a/enterprise/backend/test/metabase_enterprise/tenants/models_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/tenants/models_test.clj
@@ -133,7 +133,7 @@
(is (thrown-with-msg?
Exception
#"You are not allowed to change the owner of a Tenant Collection."
- (t2/update! :model/Collection tenant-collection-id
+ (t2/update! :model/Collection :id tenant-collection-id
{:personal_owner_id user-id}))))))))))
(deftest cannot-change-namespace-after-creation-test
@@ -145,7 +145,7 @@
(is (thrown-with-msg?
Exception
#"cannot move a Collection to a different namespace"
- (t2/update! :model/Collection tenant-collection-id
+ (t2/update! :model/Collection :id tenant-collection-id
{:namespace nil})))))))))
;;; +----------------------------------------------------------------------------------------------------------------+
@@ -172,10 +172,10 @@
(is (thrown-with-msg? clojure.lang.ExceptionInfo
#"You don't have permissions to do that"
(collection/maybe-localize-tenant-collection-names
- [(t2/select-one :model/Collection tenant2-coll-id)])))
+ [(t2/select-one :model/Collection :id tenant2-coll-id)])))
(is (= ["Our data"
"Regular Collection"]
- (map :name (collection/maybe-localize-tenant-collection-names [(t2/select-one :model/Collection tenant1-coll-id)
+ (map :name (collection/maybe-localize-tenant-collection-names [(t2/select-one :model/Collection :id tenant1-coll-id)
regular-coll]))))))))))
(deftest maybe-localize-tenant-collection-name-single-test
diff --git a/enterprise/backend/test/metabase_enterprise/tenants/search_test.clj b/enterprise/backend/test/metabase_enterprise/tenants/search_test.clj
index 5a2506b52a2..c6804bf54e1 100644
--- a/enterprise/backend/test/metabase_enterprise/tenants/search_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/tenants/search_test.clj
@@ -24,7 +24,7 @@
:model/Card {model-name :name} {:name "Dedicated Tenant Model"
:type :model
:collection_id tenant-collection-id}]
- (t2/select-one :model/Collection tenant-collection-id)
+ (t2/select-one :model/Collection :id tenant-collection-id)
(let [results (->> (mt/user-http-request :crowberto :get 200 "search" :q "Dedicated Tenant Model")
:data
(filter #(= (:model %) "dataset"))
diff --git a/enterprise/backend/test/metabase_enterprise/tenants/user_api_test.clj b/enterprise/backend/test/metabase_enterprise/tenants/user_api_test.clj
index a8c1804a502..abf652cdf16 100644
--- a/enterprise/backend/test/metabase_enterprise/tenants/user_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/tenants/user_api_test.clj
@@ -155,7 +155,7 @@
;; make the change
(mt/user-http-request :crowberto :put 200 (str "user/" user-id) {:tenant_id nil})
(testing "the user is now a normal user"
- (is (nil? (t2/select-one-fn :tenant_id :model/User user-id))))
+ (is (nil? (t2/select-one-fn :tenant_id :model/User :id user-id))))
(testing "the user is now ONLY a member of the All Users group"
(is (= #{(u/the-id (perms/all-users-group))}
(t2/select-fn-set :group_id :model/PermissionsGroupMembership :user_id user-id)))))))))
@@ -176,7 +176,7 @@
;; make the change
(mt/user-http-request :crowberto :put 200 (str "user/" user-id) {:tenant_id tenant-id})
(testing "the user is now a tenant user"
- (is (= tenant-id (t2/select-one-fn :tenant_id :model/User user-id))))
+ (is (= tenant-id (t2/select-one-fn :tenant_id :model/User :id user-id))))
(testing "the user is now ONLY a member of All tenant users"
(is (= #{(u/the-id (perms/all-external-users-group))}
(t2/select-fn-set :group_id :model/PermissionsGroupMembership :user_id user-id)))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/transform_testing/api_e2e_test.clj b/enterprise/backend/test/metabase_enterprise/transform_testing/api_e2e_test.clj
index dd28cf1ac08..25215efdab6 100644
--- a/enterprise/backend/test/metabase_enterprise/transform_testing/api_e2e_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transform_testing/api_e2e_test.clj
@@ -97,7 +97,7 @@
(is (nil? (:cell-mismatches pass))))))
(testing "DELETE removes the test"
(mt/user-http-request :crowberto :delete 204 path)
- (is (not (t2/exists? :model/TransformTest (:id created))))
+ (is (not (t2/exists? :model/TransformTest :id (:id created))))
(mt/user-http-request :crowberto :get 404 path))
(finally
(t2/delete! :model/TransformTest :id (:id created)))))))))))
@@ -146,4 +146,4 @@
(is (= "Unauthenticated" (mt/client :post 401 run-path))))
(testing "a user with no transform access cannot run someone else's test"
(mt/user-http-request :rasta :post 403 run-path)
- (is (t2/exists? :model/TransformTest test-id)))))))
+ (is (t2/exists? :model/TransformTest :id test-id)))))))
diff --git a/enterprise/backend/test/metabase_enterprise/transform_testing/api_test.clj b/enterprise/backend/test/metabase_enterprise/transform_testing/api_test.clj
index b1e09c81261..dd8b9f4c67d 100644
--- a/enterprise/backend/test/metabase_enterprise/transform_testing/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transform_testing/api_test.clj
@@ -80,10 +80,10 @@
(mt/user-http-request :crowberto :put 200 path {:name "Renamed" :transform_id other-id}))))
(testing "DELETE removes the test"
(mt/user-http-request :crowberto :delete 204 path)
- (is (not (t2/exists? :model/TransformTest (:id created))))
+ (is (not (t2/exists? :model/TransformTest :id (:id created))))
(mt/user-http-request :crowberto :get 404 path))
(finally
- (t2/delete! :model/TransformTest (:id created))))))))
+ (t2/delete! :model/TransformTest :id (:id created))))))))
(deftest write-endpoints-refuse-a-test-that-could-not-run-test
(with-transforms-enabled
@@ -113,7 +113,7 @@
(let [path (str "ee/transform-test/" test-id)
response (mt/user-http-request :crowberto :put 400 path {:inputs []})]
(is (= "transform-test.missing-inputs" (:error-code response)))
- (is (= (:inputs (t2/select-one :model/TransformTest test-id))
+ (is (= (:inputs (t2/select-one :model/TransformTest :id test-id))
(mapv #(update % :format keyword) inputs))))
(testing "while an update that touches nothing a run reads is let through"
(is (=? {:name "Renamed"}
@@ -189,7 +189,7 @@
(mt/user-http-request :lucky :put 403 path {:name "nope"})
(mt/user-http-request :lucky :delete 403 path)
(mt/user-http-request :lucky :post 403 (str path "/run"))))
- (is (t2/exists? :model/TransformTest test-id))))))
+ (is (t2/exists? :model/TransformTest :id test-id))))))
(deftest list-runs-test
(with-transforms-enabled
diff --git a/enterprise/backend/test/metabase_enterprise/transform_testing/audit_test.clj b/enterprise/backend/test/metabase_enterprise/transform_testing/audit_test.clj
index 85766cabd5c..b1c1e3a1067 100644
--- a/enterprise/backend/test/metabase_enterprise/transform_testing/audit_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transform_testing/audit_test.clj
@@ -37,7 +37,7 @@
:model "TransformTest"}
(mt/latest-audit-log-entry :transform-test-create transform-test-id))))
(testing "update"
- (t2/update! :model/TransformTest transform-test-id {:name "Renamed"})
+ (t2/update! :model/TransformTest :id transform-test-id {:name "Renamed"})
(is (= {:model_id transform-test-id
:user_id (mt/user->id :crowberto)
:details {:transform_id transform-id
@@ -73,7 +73,7 @@
:model "TransformTestRun"}
(mt/latest-audit-log-entry :transform-test-run-start run-id))))
(testing "cluster reaping records the timeout"
- (t2/update! :model/TransformTestRun run-id {:last_heartbeat (minutes-ago 10)})
+ (t2/update! :model/TransformTestRun :id run-id {:last_heartbeat (minutes-ago 10)})
(is (= [run-id] (mapv :id (transform-testing.run-tracking/reap-orphaned-runs! 5))))
(is (= {:model_id run-id
:user_id initiated-by
diff --git a/enterprise/backend/test/metabase_enterprise/transform_testing/models_test.clj b/enterprise/backend/test/metabase_enterprise/transform_testing/models_test.clj
index 4dce2317c01..dab6311758b 100644
--- a/enterprise/backend/test/metabase_enterprise/transform_testing/models_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transform_testing/models_test.clj
@@ -182,7 +182,7 @@
:model/TransformTest {test-id :id} {:transform_id transform-id
:inputs inputs
:expectations [empty-expectation]}]
- (is (some? (caught #(t2/update! :model/TransformTest test-id {:expectations [{:type "empty" :name "x"}]}))))
+ (is (some? (caught #(t2/update! :model/TransformTest :id test-id {:expectations [{:type "empty" :name "x"}]}))))
(testing "and the stored value is unchanged"
(is (= ["no orphan rows"]
(mapv :name (:expectations (t2/select-one :model/TransformTest :id test-id)))))))))
@@ -202,7 +202,7 @@
:inputs []
:expectations []}]
(with-redefs [events/publish-event! (fn [topic event] (swap! published conj [topic event]))]
- (t2/delete! :model/Transform transform-id))
+ (t2/delete! :model/Transform :id transform-id))
(testing "the rows are gone"
(is (false? (t2/exists? :model/TransformTest :id test-id)))
(is (false? (t2/exists? :model/TransformTest :id other-id))))
@@ -234,7 +234,7 @@
(is (nil? (:end_time started)))
(is (some? (:last_heartbeat started))))
(testing "the owning process heartbeats its registered run"
- (t2/update! :model/TransformTestRun run-id {:last_heartbeat (minutes-ago 10)})
+ (t2/update! :model/TransformTestRun :id run-id {:last_heartbeat (minutes-ago 10)})
(transform-testing.run-tracking/heartbeat-and-reconcile-runs!)
(is (recent? (t2/select-one-fn :last_heartbeat :model/TransformTestRun :id run-id))))
(testing "finishing sets a terminal status and end time"
@@ -266,7 +266,7 @@
(mt/with-temp [:model/Transform {transform-id :id} {}
:model/TransformTest {transform-test-id :id} {:transform_id transform-id}]
(let [{run-id :id} (transform-testing.run-tracking/start-run! transform-test-id)]
- (t2/delete! :model/TransformTest transform-test-id)
+ (t2/delete! :model/TransformTest :id transform-test-id)
(is (nil? (t2/select-one-fn :transform_test_id :model/TransformTestRun :id run-id)))
(is (= 1 (transform-testing.run-tracking/finish-run! run-id :passed)))
(is (= :passed (t2/select-one-fn :status :model/TransformTestRun :id run-id))))))
diff --git a/enterprise/backend/test/metabase_enterprise/transform_testing/revision_test.clj b/enterprise/backend/test/metabase_enterprise/transform_testing/revision_test.clj
index 858b604b9d4..0a580458edf 100644
--- a/enterprise/backend/test/metabase_enterprise/transform_testing/revision_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transform_testing/revision_test.clj
@@ -41,7 +41,7 @@
(is (= "Original" (get-in creation [:object :name])))
(is (= (mt/user->id :crowberto) (:user_id creation)))))
(testing "an update records the changed editable fields"
- (t2/update! :model/TransformTest transform-test-id {:name "Renamed"})
+ (t2/update! :model/TransformTest :id transform-test-id {:name "Renamed"})
(let [[updated creation] (revisions/revisions :model/TransformTest transform-test-id)]
(is (= "Renamed" (get-in updated [:object :name])))
(is (false? (:is_creation updated)))
@@ -54,7 +54,7 @@
(mt/with-temp [:model/Transform {transform-id :id} {}
:model/TransformTest {transform-test-id :id} {:transform_id transform-id
:name "Original"}]
- (t2/update! :model/TransformTest transform-test-id {:name "Renamed"})
+ (t2/update! :model/TransformTest :id transform-test-id {:name "Renamed"})
(let [creation (last (revisions/revisions :model/TransformTest transform-test-id))]
(mt/user-http-request :crowberto :post 200 "revision/revert"
{:entity "transform-test"
@@ -92,7 +92,7 @@
(mt/with-temp [:model/Transform {transform-id :id} {}
:model/TransformTest {transform-test-id :id} {:transform_id transform-id
:name "Original"}]
- (t2/update! :model/TransformTest transform-test-id {:name "Renamed"})
+ (t2/update! :model/TransformTest :id transform-test-id {:name "Renamed"})
(is (=? [{:is_creation false
:description "renamed this Transform test from \"Original\" to \"Renamed\"."}
{:is_creation true
@@ -107,7 +107,7 @@
(mt/with-temp [:model/Transform {transform-id :id} {}
:model/TransformTest {transform-test-id :id} {:transform_id transform-id
:name "Original"}]
- (t2/update! :model/TransformTest transform-test-id {:name "Renamed"})
+ (t2/update! :model/TransformTest :id transform-test-id {:name "Renamed"})
(mt/with-dynamic-fn-redefs [revision.diff/model-str->i18n-str
(fn [model-str]
(throw (IllegalArgumentException. (str "No matching clause: " model-str))))]
diff --git a/enterprise/backend/test/metabase_enterprise/transforms/incremental_test.clj b/enterprise/backend/test/metabase_enterprise/transforms/incremental_test.clj
index 5d29130f841..3825be149ec 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms/incremental_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms/incremental_test.clj
@@ -166,12 +166,12 @@
(some-> result :data :rows first first bigint)))
(defn- get-checkpoint-value [transform-id]
- (let [transform (t2/select-one :model/Transform transform-id)
+ (let [transform (t2/select-one :model/Transform :id transform-id)
{:keys [last_checkpoint_value]} transform]
(when last_checkpoint_value
(let [source-incremental-strategy (get-in transform [:source :source-incremental-strategy])
field-id (:checkpoint-filter-field-id source-incremental-strategy)
- field (t2/select-one :model/Field field-id)]
+ field (t2/select-one :model/Field :id field-id)]
(#'transforms-base.u/parse-checkpoint-value (:base_type field) last_checkpoint_value)))))
(defn- compare-checkpoint-values
@@ -186,7 +186,7 @@
(defn- insert-test-products!
"Insert new products into the transforms_products table."
[products]
- (let [[schema source-table-name] (t2/select-one-fn (juxt :schema :name) :model/Table (mt/id :transforms_products))
+ (let [[schema source-table-name] (t2/select-one-fn (juxt :schema :name) :model/Table :id (mt/id :transforms_products))
spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
table-sql (sql.u/quote-name driver/*driver* :table schema source-table-name)
field-sql #(sql.u/quote-name driver/*driver* :field %)]
@@ -216,7 +216,7 @@
(defn- delete-test-products!
[products]
- (let [[schema source-table-name] (t2/select-one-fn (juxt :schema :name) :model/Table (mt/id :transforms_products))
+ (let [[schema source-table-name] (t2/select-one-fn (juxt :schema :name) :model/Table :id (mt/id :transforms_products))
spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
delete-sql (format "DELETE FROM %s WHERE %s IN (%s)"
(sql.u/quote-name driver/*driver* :table schema source-table-name)
@@ -240,7 +240,7 @@
(defn- target-table-gen [prefix]
{:type :table
:name prefix
- :schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))
+ :schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))
:database (mt/id)})
(deftest create-incremental-transform-test
@@ -301,7 +301,7 @@
(is (compare-checkpoint-values checkpoint-type expected-initial-checkpoint checkpoint)
(format "Checkpoint should be MAX(%s) from all 16 rows" (:field-name checkpoint-config)))))))
(testing "Second run with no new data adds nothing"
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(execute-transform-with-ordering! transform transform-type (:field-name checkpoint-config) {:run-method :manual})
(let [row-count (get-table-row-count target-table)
distinct-timestamps (get-distinct-timestamp-count target-table)]
@@ -314,7 +314,7 @@
:category "Gadget"
:price 379.99
:created-at "2024-01-20T10:00:00"}]
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(execute-transform-with-ordering! transform transform-type (:field-name checkpoint-config) {:run-method :manual})
(let [row-count (get-table-row-count target-table)
distinct-timestamps (get-distinct-timestamp-count target-table)
@@ -348,7 +348,7 @@
(is (nil? (mt/user-http-request :crowberto :post 204 (format "transform/%s/reset-checkpoint" (:id transform)))))
(is (nil? (get-checkpoint-value (:id transform)))))
(testing "the next run reprocesses the full source table, not just the tail"
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(execute-transform-with-ordering! transform :mbql (:field-name checkpoint-config) {:run-method :manual})
(is (= 17 (get-table-row-count target-table))
"full reload replaces the target with all 17 source rows"))))))))))))
@@ -367,7 +367,7 @@
{:keys [expected-initial-checkpoint]} checkpoint-config
initial-payload (make-incremental-transform-payload "Switch Transform" target-table transform-type checkpoint-config)]
(mt/with-temp [:model/Transform transform initial-payload]
- (let [get-transform #(t2/select-one :model/Transform (:id transform))]
+ (let [get-transform #(t2/select-one :model/Transform :id (:id transform))]
(testing "Initial incremental run processes all data"
(execute-transform-with-ordering! transform transform-type (:field-name checkpoint-config) {:run-method :manual})
(transforms.tu/wait-for-table (:name target-table) 10000)
@@ -393,7 +393,7 @@
(is (= "table" (-> updated :target :type)))
(is (nil? (-> updated :source :source-incremental-strategy)))))
(testing "Non-incremental run overwrites all data"
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(execute-transform-with-ordering! transform transform-type (:field-name checkpoint-config) {:run-method :manual})
(let [row-count (get-table-row-count target-table)
distinct-timestamps (get-distinct-timestamp-count target-table)]
@@ -440,7 +440,7 @@
(is (= "table-incremental" (-> updated :target :type)))
(is (= "checkpoint" (-> updated :source :source-incremental-strategy :type)))))
(testing "First incremental run after switch recreates table with checkpoint"
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(execute-transform-with-ordering! transform transform-type (:field-name checkpoint-config) {:run-method :manual})
(let [row-count (get-table-row-count target-table)
distinct-timestamps (get-distinct-timestamp-count target-table)
@@ -449,7 +449,7 @@
(is (= 1 distinct-timestamps) "Should have 1 distinct timestamp")
(is (compare-checkpoint-values checkpoint-type expected-initial-checkpoint checkpoint) "Checkpoint should be computed from existing data"))))
(testing "Second incremental run with no new data"
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(execute-transform-with-ordering! transform transform-type (:field-name checkpoint-config) {:run-method :manual})
(let [row-count (get-table-row-count target-table)
distinct-timestamps (get-distinct-timestamp-count target-table)]
@@ -462,7 +462,7 @@
:category "Gadget"
:price 379.99
:created-at "2024-01-20T10:00:00"}]
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(execute-transform-with-ordering! transform transform-type (:field-name checkpoint-config) {:run-method :manual})
(let [row-count (get-table-row-count target-table)
checkpoint (get-checkpoint-value (:id transform))]
@@ -479,7 +479,7 @@
(with-transform-cleanup! [target-table "unsupported_type_test"]
(let [name-field-id (mt/id :transforms_products :name)
table-id (mt/id :transforms_products)
- schema (t2/select-one-fn :schema :model/Table table-id)
+ schema (t2/select-one-fn :schema :model/Table :id table-id)
transform-payload {:name "Invalid Checkpoint Type Transform"
:source {:type "query"
:query {:database (mt/id)
@@ -540,7 +540,7 @@
(testing "sync has picked up table"
(is (=? {:name target-table} (t2/select-one :model/Table :name target-table))))
(testing "checkpoint is set from source table MAX even though query returned no rows"
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(is (some? (:last_checkpoint_value transform))
"Checkpoint is computed from source table, not query output"))))))))))
@@ -605,7 +605,7 @@
:target-incremental-strategy {:type "append"}}]
(mt/with-temp [:model/Transform transform {:name "test transform" :source source, :target target}]
;; Mark the field as inactive
- (t2/update! :model/Field field-id {:active false})
+ (t2/update! :model/Field :id field-id {:active false})
(try
(testing "Transform execution fails with inactive checkpoint field"
(is (thrown-with-msg?
@@ -614,7 +614,7 @@
(transforms.execute/execute! transform {:run-method :manual}))))
(finally
;; Restore field to active state for other tests
- (t2/update! :model/Field field-id {:active true})))))))))))
+ (t2/update! :model/Field :id field-id {:active true})))))))))))
(deftest changing-query-keeps-checkpoint-test
(mt/test-drivers #{:postgres}
@@ -652,16 +652,16 @@
(transforms.execute/execute! transform {:run-method :manual})
(is (= 16 (count (pg-table-rows db-spec target-table)))))
(t2/update! :model/Transform
- (:id transform)
+ :id (:id transform)
{:source (make-source "SELECT id FROM {{source_table}} AS s ORDER BY id DESC")})
(testing "run after query change with no new data keeps same row count"
- (transforms.execute/execute! (t2/select-one :model/Transform (:id transform)) {:run-method :manual})
+ (transforms.execute/execute! (t2/select-one :model/Transform :id (:id transform)) {:run-method :manual})
(is (= 16 (count (pg-table-rows db-spec target-table)))
"Checkpoint preserved across query change, no new rows added"))
(testing "after inserting new data, incremental run appends"
(with-insert-test-products!
[{:name "New Product" :category "Test" :price 99.99 :created-at "2024-01-21T10:00:00"}]
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(transforms.execute/execute! transform {:run-method :manual})
(is (= 17 (count (pg-table-rows db-spec target-table)))
"Should append 1 new row after query change")))))))))))
@@ -697,7 +697,7 @@
(is (compare-checkpoint-values checkpoint-type expected-initial-checkpoint checkpoint)
(format "Checkpoint should be MAX(%s) from all 16 rows" field-name))))
(testing "Second run without new data adds nothing"
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(transforms.execute/execute! transform {:run-method :manual})
(let [row-count (get-table-row-count target-table)]
(is (= 16 row-count) "Should still have 16 rows, no new data"))))
@@ -708,7 +708,7 @@
:category "Electronics"
:price 299.99
:created-at "2024-01-21T10:00:00"}]
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(transforms.execute/execute! transform {:run-method :manual})
(let [row-count (get-table-row-count target-table)
checkpoint (get-checkpoint-value (:id transform))]
@@ -749,7 +749,7 @@
(testing "append run preserves the indexes"
(with-insert-test-products! [{:name "Incremental Index Product" :category "Gadget"
:price 379.99 :created-at "2024-01-20T10:00:00"}]
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(execute-transform-with-ordering! transform transform-type checkpoint-field
{:run-method :manual})
(is (= expected (physical-indexes (mt/db) schema table-name)))))))))))))))))
@@ -781,12 +781,12 @@
(testing "the watermark survives the request untouched"
(is (some? (get-checkpoint-value (:id transform)))))
(testing "the next run rebuilds and the index lands in the warehouse"
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(execute-transform-with-ordering! transform :mbql checkpoint-field {:run-method :manual})
(is (contains? (physical-indexes (mt/db) (:schema target) table-name) "mid_run_idx"))
(is (= :succeeded (t2/select-one-fn :status :model/TableIndex
:transform_id (:id transform)
:index_name "mid_run_idx")))))
(testing "once settled, the run after that appends again"
- (let [transform (t2/select-one :model/Transform (:id transform))]
+ (let [transform (t2/select-one :model/Transform :id (:id transform))]
(is (not (transforms-base.u/full-incremental-run? transform))))))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/transforms/merge_test.clj b/enterprise/backend/test/metabase_enterprise/transforms/merge_test.clj
index 82278be66a3..6b0a677d57d 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms/merge_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms/merge_test.clj
@@ -80,7 +80,7 @@
(defn- target-table-gen [prefix]
{:type :table
:name prefix
- :schema (t2/select-one-fn :schema :model/Table (mt/id :order_status))
+ :schema (t2/select-one-fn :schema :model/Table :id (mt/id :order_status))
:database (mt/id)})
(defn- merge-source-query []
@@ -115,7 +115,7 @@
(defn- insert-order-status!
"Append `rows` (vectors of `[order-id status change-seq]`) to the source table."
[rows]
- (let [[schema table-name] (t2/select-one-fn (juxt :schema :name) :model/Table (mt/id :order_status))
+ (let [[schema table-name] (t2/select-one-fn (juxt :schema :name) :model/Table :id (mt/id :order_status))
spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
values (str/join ", " (map (fn [[oid st sq]] (format "(%d, '%s', %d)" oid st sq)) rows))
sql (format "INSERT INTO %s (%s) VALUES %s"
@@ -150,7 +150,7 @@
(target-status-by-order target-table))))
(testing "new events update existing keys in place and insert new ones"
(insert-order-status! [[1 "shipped" 4] [4 "created" 5]])
- (transforms.execute/execute! (t2/select-one :model/Transform (:id transform))
+ (transforms.execute/execute! (t2/select-one :model/Transform :id (:id transform))
{:run-method :manual})
(is (= {1 "shipped", 2 "created", 3 "created", 4 "created"}
(target-status-by-order target-table))
@@ -164,7 +164,7 @@
(with-transform-cleanup! [target-table {:type :table
:name "merge_temporal"
:schema (t2/select-one-fn :schema :model/Table
- (mt/id :order_status_ts))
+ :id (mt/id :order_status_ts))
:database (mt/id)}]
(let [q (fn [f] (sql.u/quote-name driver/*driver* :field f))
ts-field-id (t2/select-one-pk :model/Field :name "changed_at"
@@ -191,7 +191,7 @@
:unique-key [{:name "order_id"}]}})}
insert! (fn [rows]
(let [[schema tbl] (t2/select-one-fn (juxt :schema :name) :model/Table
- (mt/id :order_status_ts))
+ :id (mt/id :order_status_ts))
spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
values (str/join ", " (map (fn [[oid st ts]]
(format "(%d, '%s', '%s')" oid st ts))
@@ -217,7 +217,7 @@
(read-target))))
(testing "a second run with a temporal watermark upserts changed keys and inserts new ones"
(insert! [[1 "shipped" "2026-02-01T10:00:00"] [4 "created" "2026-02-02T10:00:00"]])
- (transforms.execute/execute! (t2/select-one :model/Transform (:id transform))
+ (transforms.execute/execute! (t2/select-one :model/Transform :id (:id transform))
{:run-method :manual})
(is (= {1 "shipped", 2 "created", 3 "created", 4 "created"}
(read-target))
@@ -234,7 +234,7 @@
"no field-id before the first run — the target table doesn't exist yet")
(transforms.execute/execute! transform {:run-method :manual})
(transforms.tu/wait-for-table (:name target-table) 10000)
- (let [reloaded (t2/select-one :model/Transform (:id transform))
+ (let [reloaded (t2/select-one :model/Transform :id (:id transform))
unique-key (-> reloaded :target :target-incremental-strategy :unique-key)
target-tbl-id (:target_table_id reloaded)
expected (t2/select-one-pk :model/Field :name "order_id"
@@ -251,7 +251,7 @@
(with-transform-cleanup! [target-table {:type :table
:name "merge_lookback"
:schema (t2/select-one-fn :schema :model/Table
- (mt/id :order_status_lb))
+ :id (mt/id :order_status_lb))
:database (mt/id)}]
(let [q (fn [f] (sql.u/quote-name driver/*driver* :field f))
ts-field-id (t2/select-one-pk :model/Field :name "changed_at"
@@ -279,7 +279,7 @@
:unique-key [{:name "order_id"}]}})}
insert! (fn [rows]
(let [[schema tbl] (t2/select-one-fn (juxt :schema :name) :model/Table
- (mt/id :order_status_lb))
+ :id (mt/id :order_status_lb))
spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
values (str/join ", " (map (fn [[oid st ts]]
(format "(%d, '%s', '%s')" oid st ts))
@@ -300,13 +300,13 @@
:count (count rows)}))
delete-order! (fn [order-id]
(let [[schema tbl] (t2/select-one-fn (juxt :schema :name) :model/Table
- (mt/id :order_status_lb))
+ :id (mt/id :order_status_lb))
spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
sql (format "DELETE FROM %s WHERE %s = %d"
(sql.u/quote-name driver/*driver* :table schema tbl)
(q "order_id") order-id)]
(driver/execute-raw-queries! driver/*driver* spec [[sql]])))
- watermark (fn [id] (t2/select-one-fn :last_checkpoint_value :model/Transform id))]
+ watermark (fn [id] (t2/select-one-fn :last_checkpoint_value :model/Transform :id id))]
(mt/with-temp [:model/Transform transform payload]
(testing "first run builds the full target and records the watermark"
(transforms.execute/execute! transform {:run-method :manual})
@@ -320,7 +320,7 @@
;; inside the window; order 1's original row (01-30T10:00) is outside it.
(let [wm-before (watermark (:id transform))]
(insert! [[1 "shipped" "2026-01-31T00:00:00"] [4 "created" "2026-02-01T10:00:00"]])
- (transforms.execute/execute! (t2/select-one :model/Transform (:id transform))
+ (transforms.execute/execute! (t2/select-one :model/Transform :id (:id transform))
{:run-method :manual})
(is (= {:by-order {1 "shipped", 2 "created", 3 "created", 4 "created"} :count 4}
(read-target))
@@ -332,7 +332,7 @@
(:checkpoint_lo_value run)))))))
(testing "a run with no new rows leaves the target and the watermark unchanged"
(let [before (watermark (:id transform))]
- (transforms.execute/execute! (t2/select-one :model/Transform (:id transform))
+ (transforms.execute/execute! (t2/select-one :model/Transform :id (:id transform))
{:run-method :manual})
(is (= {:by-order {1 "shipped", 2 "created", 3 "created", 4 "created"} :count 4}
(read-target)))
@@ -345,7 +345,7 @@
;; slide back (see get-source-range-params' `hi`).
(let [before (watermark (:id transform))]
(delete-order! 4)
- (transforms.execute/execute! (t2/select-one :model/Transform (:id transform))
+ (transforms.execute/execute! (t2/select-one :model/Transform :id (:id transform))
{:run-method :manual})
(is (= before (watermark (:id transform)))
"the watermark must not regress when the max row disappears from the source")
@@ -361,11 +361,11 @@
(with-transform-cleanup! [target-table {:type :table
:name "merge_lookback_unix"
:schema (t2/select-one-fn :schema :model/Table
- (mt/id :order_status_unix))
+ :id (mt/id :order_status_unix))
:database (mt/id)}]
(let [q (fn [f] (sql.u/quote-name driver/*driver* :field f))
ts-field-id (mt/id :order_status_unix :changed_at)
- _ (t2/update! :model/Field ts-field-id
+ _ (t2/update! :model/Field :id ts-field-id
{:coercion_strategy :Coercion/UNIXSeconds->DateTime
:effective_type :type/Instant})
payload {:name "Unix Timestamp Lookback Merge"
@@ -383,7 +383,7 @@
:unique-key [{:name "order_id"}]}})}
insert! (fn [rows]
(let [[schema tbl] (t2/select-one-fn (juxt :schema :name) :model/Table
- (mt/id :order_status_unix))
+ :id (mt/id :order_status_unix))
spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
values (str/join ", " (map (fn [[oid st ts]]
(format "(%d, '%s', %d)" oid st ts))
@@ -408,7 +408,7 @@
(transforms.tu/wait-for-table (:name target-table) 10000)
(is (= {:by-order {1 "created", 2 "created", 3 "created"} :count 3}
(read-target)))
- (let [wm (t2/select-one-fn :last_checkpoint_value :model/Transform (:id transform))]
+ (let [wm (t2/select-one-fn :last_checkpoint_value :model/Transform :id (:id transform))]
(is (re-find #"T" (str wm))
"the watermark encodes as a temporal value, not the raw epoch number")))
(testing "a late-arriving epoch inside the lookback window is upserted on rerun"
@@ -416,7 +416,7 @@
;; epoch 1950000 is behind the watermark but inside the window; order 1's
;; original row (1000000) is outside it.
(insert! [[1 "shipped" 2100000] [4 "created" 1950000]])
- (transforms.execute/execute! (t2/select-one :model/Transform (:id transform))
+ (transforms.execute/execute! (t2/select-one :model/Transform :id (:id transform))
{:run-method :manual})
(is (= {:by-order {1 "shipped", 2 "created", 3 "created", 4 "created"} :count 4}
(read-target))
@@ -430,7 +430,7 @@
(with-transform-cleanup! [target-table {:type :table
:name "merge_composite"
:schema (t2/select-one-fn :schema :model/Table
- (mt/id :order_region_status))
+ :id (mt/id :order_region_status))
:database (mt/id)}]
(let [q (fn [f] (sql.u/quote-name driver/*driver* :field f))
seq-field-id (t2/select-one-pk :model/Field :name "change_seq"
@@ -458,7 +458,7 @@
{:name "region"}]}})}
insert! (fn [rows]
(let [[schema tbl] (t2/select-one-fn (juxt :schema :name) :model/Table
- (mt/id :order_region_status))
+ :id (mt/id :order_region_status))
spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
values (str/join ", " (map (fn [[oid rg st sq]]
(format "(%d, '%s', '%s', %d)" oid rg st sq))
@@ -484,7 +484,7 @@
(read-target))))
(testing "new events upsert one composite key and insert another"
(insert! [[1 "us" "shipped" 4] [3 "us" "created" 5]])
- (transforms.execute/execute! (t2/select-one :model/Transform (:id transform))
+ (transforms.execute/execute! (t2/select-one :model/Transform :id (:id transform))
{:run-method :manual})
(is (= {[1 "us"] "shipped", [1 "eu"] "created", [2 "us"] "created", [3 "us"] "created"}
(read-target))
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_inspector/context_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_inspector/context_test.clj
index 1e49b9f0038..3f596c390d8 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms_inspector/context_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms_inspector/context_test.clj
@@ -250,7 +250,7 @@
(mt/test-drivers (mt/normal-drivers-with-feature :left-join)
(testing "build-context populates column-matches when target exists"
;; Use products table as a fake target to avoid running a transform
- (let [products-table (t2/select-one :model/Table (mt/id :products))
+ (let [products-table (t2/select-one :model/Table :id (mt/id :products))
transform {:id 1
:source {:type :query
:query (joined-orders-products-query)}
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_inspector/e2e_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_inspector/e2e_test.clj
index 0e1af68b47a..9ee9f9ada2f 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms_inspector/e2e_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms_inspector/e2e_test.clj
@@ -227,7 +227,7 @@
(mt/with-temp [:model/Transform {tid :id :as transform} transform-data]
(transforms.execute/execute! transform {:run-method :manual})
(transforms.tu/wait-for-table target-name 10000)
- (let [transform' (t2/select-one :model/Transform tid)
+ (let [transform' (t2/select-one :model/Transform :id tid)
result (run-inspector-loop transform')]
(assert-inspector-loop result :mbql)))))))
@@ -244,6 +244,6 @@
(mt/with-temp [:model/Transform {tid :id :as transform} transform-data]
(transforms.execute/execute! transform {:run-method :manual})
(transforms.tu/wait-for-table target-name 10000)
- (let [transform' (t2/select-one :model/Transform tid)
+ (let [transform' (t2/select-one :model/Transform :id tid)
result (run-inspector-loop transform')]
(assert-inspector-loop result :native)))))))
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_inspector/lens_output_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_inspector/lens_output_test.clj
index 1d463d4c764..80ccbb7d5a2 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms_inspector/lens_output_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms_inspector/lens_output_test.clj
@@ -34,7 +34,7 @@
(defn- build-table-info
"Build a table info map with fields from a real table."
[table-id]
- (let [table (t2/select-one :model/Table table-id)
+ (let [table (t2/select-one :model/Table :id table-id)
fields (collect-field-metadata table-id)]
{:table_id table-id
:table_name (:name table)
@@ -88,12 +88,12 @@
:join-structure join-structure}
:visited-fields {:all #{(mt/id :orders :product_id) (mt/id :products :id)}}
:has-column-matches? true
- :column-matches [{:output-column (:name (t2/select-one :model/Field (mt/id :products :price)))
- :output-field {:name (:name (t2/select-one :model/Field (mt/id :products :price)))
+ :column-matches [{:output-column (:name (t2/select-one :model/Field :id (mt/id :products :price)))
+ :output-field {:name (:name (t2/select-one :model/Field :id (mt/id :products :price)))
:id (mt/id :products :price)
:base_type :type/Float}
:input-columns [{:source-table-id (mt/id :orders)
- :source-table-name (:name (t2/select-one :model/Table (mt/id :orders)))
+ :source-table-name (:name (t2/select-one :model/Table :id (mt/id :orders)))
:name "TOTAL"
:id (mt/id :orders :total)}]}]}))
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_inspector_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_inspector_test.clj
index 6667dd2bb12..327aeb12ac5 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms_inspector_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms_inspector_test.clj
@@ -74,7 +74,7 @@
(transforms.execute/execute! transform {:run-method :manual})
(transforms.tu/wait-for-table target-name 10000)
;; Reload transform to get latest state
- (let [transform' (t2/select-one :model/Transform tid)
+ (let [transform' (t2/select-one :model/Transform :id tid)
result (inspector/discover-lenses transform')]
(is (= :ready (:status result)))
(is (some? (:target result)))
@@ -100,7 +100,7 @@
(mt/with-temp [:model/Transform {tid :id :as transform} transform-data]
(transforms.execute/execute! transform {:run-method :manual})
(transforms.tu/wait-for-table target-name 10000)
- (let [transform' (t2/select-one :model/Transform tid)
+ (let [transform' (t2/select-one :model/Transform :id tid)
result (inspector/discover-lenses transform')]
(testing "sources contain table metadata"
(let [source (first (:sources result))]
@@ -134,7 +134,7 @@
(mt/with-temp [:model/Transform {tid :id :as transform} transform-data]
(transforms.execute/execute! transform {:run-method :manual})
(transforms.tu/wait-for-table target-name 10000)
- (let [transform' (t2/select-one :model/Transform tid)
+ (let [transform' (t2/select-one :model/Transform :id tid)
lens (inspector/get-lens transform' "generic-summary" nil)]
(is (= "generic-summary" (:id lens)))
(is (= "Data Summary" (:display_name lens)))
@@ -174,7 +174,7 @@
(mt/with-temp [:model/Transform {tid :id :as transform} transform-data]
(transforms.execute/execute! transform {:run-method :manual})
(transforms.tu/wait-for-table target-name 10000)
- (let [transform' (t2/select-one :model/Transform tid)
+ (let [transform' (t2/select-one :model/Transform :id tid)
lens (inspector/get-lens transform' "join-analysis" nil)]
(is (= "join-analysis" (:id lens)))
(is (= "Join Analysis" (:display_name lens)))
@@ -204,7 +204,7 @@
(mt/with-temp [:model/Transform {tid :id :as transform} transform-data]
(transforms.execute/execute! transform {:run-method :manual})
(transforms.tu/wait-for-table target-name 10000)
- (let [transform' (t2/select-one :model/Transform tid)]
+ (let [transform' (t2/select-one :model/Transform :id tid)]
;; A simple query without joins shouldn't have join-analysis applicable
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Lens data not available"
(inspector/get-lens transform' "join-analysis" nil))))))))))
@@ -238,7 +238,7 @@
(mt/with-temp [:model/Transform {tid :id :as transform} transform-data]
(transforms.execute/execute! transform {:run-method :manual})
(transforms.tu/wait-for-table target-name 10000)
- (let [transform' (t2/select-one :model/Transform tid)
+ (let [transform' (t2/select-one :model/Transform :id tid)
result (inspector/discover-lenses transform')]
(testing "join-analysis is in available lenses"
(is (some #(= "join-analysis" (:id %)) (:available_lenses result))))
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_python/e2e_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_python/e2e_test.clj
index e7472106544..9020507dc3d 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms_python/e2e_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms_python/e2e_test.clj
@@ -26,7 +26,7 @@
"\n"
"def add_greeting(name):\n"
" return f'Hello, {name}!'\n"))
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
;; Create and run a transform that uses the library
(with-transform-cleanup! [{table-name :name :as target} {:type "table"
:schema schema
@@ -64,7 +64,7 @@
(mt/test-drivers #{:postgres}
(mt/with-premium-features #{:transforms-basic :transforms-python :hosting}
(mt/dataset transforms-dataset/transforms-test
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [{table-name :name :as target} {:type "table"
:schema schema
:name "target_table"}]
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_python/execute_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_python/execute_test.clj
index d8f4a44a61f..77fadef1809 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms_python/execute_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms_python/execute_test.clj
@@ -22,7 +22,7 @@
(mt/test-drivers #{:mysql :postgres}
(mt/with-premium-features #{:transforms-python :transforms-basic}
(mt/dataset transforms-dataset/transforms-test
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [{table-name :name :as target} {:type "table"
:schema schema
:name "swap_tbl"}]
@@ -40,7 +40,7 @@
(transforms.tu/wait-for-table table-name 10000)
(let [initial-rows (transforms.tu/table-rows table-name)]
(is (= [["Alice" 25] ["Bob" 30]] initial-rows) "Initial data should be Alice and Bob")
- (t2/update! :model/Transform (:id transform)
+ (t2/update! :model/Transform :id (:id transform)
{:source {:type "python"
:source-tables []
:source-database (mt/id)
@@ -55,7 +55,7 @@
(original-rename-tables-atomic! driver db-id rename-pairs))]
(let [transform-future (future
(transforms-python.execute/execute-python-transform!
- (t2/select-one :model/Transform (:id transform))
+ (t2/select-one :model/Transform :id (:id transform))
{:run-method :manual}))]
(is (= [["Alice" 25] ["Bob" 30]]
(transforms.tu/table-rows table-name))
@@ -71,7 +71,7 @@
(mt/test-drivers #{:mysql :postgres}
(mt/with-premium-features #{:transforms-python :transforms-basic}
(mt/dataset transforms-dataset/transforms-test
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [{table-name :name :as target} {:type "table"
:schema schema
:name "cleanup_"}]
@@ -100,7 +100,7 @@
(mt/test-drivers #{:postgres}
(mt/with-premium-features #{:transforms-python :transforms-basic}
(mt/dataset transforms-dataset/transforms-test
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [target {:type "table"
:schema schema
:name "timeout_test"}]
@@ -135,7 +135,7 @@
(mt/test-drivers #{:postgres}
(mt/with-premium-features #{:transforms-python :transforms-basic}
(mt/dataset transforms-dataset/transforms-test
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [target {:type "table"
:schema schema
:name "unresolved_test"}]
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_python/job_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_python/job_test.clj
index 0d05934b8df..c4dbe7a57f5 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms_python/job_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms_python/job_test.clj
@@ -21,7 +21,7 @@
(mt/with-premium-features #{:transforms-python :transforms-basic :hosting}
(mt/dataset transforms-dataset/transforms-test
(transforms.tu/with-transform-cleanup! [target {:type "table"
- :schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))
+ :schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))
:name "target_table"}]
(mt/with-temp
[:model/TransformTag {tag-id :id} {:name "every second"}
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_python/ordering_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_python/ordering_test.clj
index bf762a82f91..aca3394d5c4 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms_python/ordering_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms_python/ordering_test.clj
@@ -51,7 +51,7 @@
:model/Field _ {:table_id table1 :name "foo"}
:model/Transform {t1 :id} (py-tx [(transforms.tu/source-table-entry "orders" (mt/id :orders))] "output_1")
:model/Transform {t2 :id} (py-tx [(transforms.tu/source-table-entry "output_1" table1)] "output_2")]
- (t2/update! :model/Transform t1 {:target_table_id table1})
+ (t2/update! :model/Transform :id t1 {:target_table_id table1})
(is (= {t1 #{}
t2 #{t1}}
(:dependencies (ordering/transform-ordering #{t1 t2} (t2/select :model/Transform :id [:in [t1 t2]]))))))))))
@@ -69,8 +69,8 @@
:model/Transform {t3 :id} (py-tx [(transforms.tu/source-table-entry "output_1" table1)
(transforms.tu/source-table-entry "output_2" table2)]
"final_output")]
- (t2/update! :model/Transform t1 {:target_table_id table1})
- (t2/update! :model/Transform t2 {:target_table_id table2})
+ (t2/update! :model/Transform :id t1 {:target_table_id table1})
+ (t2/update! :model/Transform :id t2 {:target_table_id table2})
(is (= {t1 #{}
t2 #{}
t3 #{t1 t2}}
@@ -95,8 +95,8 @@
:model/Transform {t3 :id} (sql-tx {:database (mt/id)
:type "query"
:query {:source-table table2}} "final_output")]
- (t2/update! :model/Transform t1 {:target_table_id table1})
- (t2/update! :model/Transform t2 {:target_table_id table2})
+ (t2/update! :model/Transform :id t1 {:target_table_id table1})
+ (t2/update! :model/Transform :id t2 {:target_table_id table2})
(is (= {t1 #{}
t2 #{t1}
t3 #{t2}}
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_python/transforms_api_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_python/transforms_api_test.clj
index a2909fd4c75..a3a703f8027 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms_python/transforms_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms_python/transforms_api_test.clj
@@ -140,7 +140,7 @@
(mt/test-drivers (mt/normal-drivers-with-feature :transforms/table)
(mt/with-premium-features #{:transforms-basic :transforms-python :hosting}
(mt/dataset transforms-dataset/transforms-test
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [{table-name :name :as target} {:type "table"
:schema schema
:name "target_table"}]
@@ -293,7 +293,7 @@
(disj :snowflake :redshift :bigquery-cloud-sdk))
(mt/with-premium-features #{:transforms-basic :transforms-python :hosting}
(mt/dataset transforms-dataset/transforms-test
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(doseq [{:keys [expected
expect-early-feedback
expect-status
@@ -465,7 +465,7 @@
(disj :snowflake :bigquery-cloud-sdk :redshift :mongo))
(mt/with-premium-features #{:transforms-basic :transforms-python :hosting}
(mt/dataset transforms-dataset/transforms-test
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-redefs [transforms-python.execute/python-message-loop-sleep-duration (Duration/ofMillis fast-log-polling-ms)]
(with-transform-cleanup! [target {:type "table"
:schema schema
diff --git a/modules/drivers/bigquery-cloud-sdk/src/metabase/driver/bigquery_cloud_sdk/db.clj b/modules/drivers/bigquery-cloud-sdk/src/metabase/driver/bigquery_cloud_sdk/db.clj
index 4d983cb1b1f..7ea17faa8c1 100644
--- a/modules/drivers/bigquery-cloud-sdk/src/metabase/driver/bigquery_cloud_sdk/db.clj
+++ b/modules/drivers/bigquery-cloud-sdk/src/metabase/driver/bigquery_cloud_sdk/db.clj
@@ -14,7 +14,7 @@
"Set the details of the Database with `database-id`, returning the number updated."
[database-id :- ::lib.schema.id/database
details :- ::warehouses.schema/database.details]
- (t2/update! :model/Database database-id {:details details}))
+ (t2/update! :model/Database :id database-id {:details details}))
(mu/defn set-table-schemas!
"Set the schema of the Tables of the Database with `database-id` that do not have `schema` yet, overwriting any
diff --git a/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj b/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj
index 3c260953981..e2cd60b570d 100644
--- a/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj
+++ b/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj
@@ -1025,7 +1025,7 @@
(testing "Dispatcher identifies this as a non-batch-able table"
(is (false? (#'sync.field-values/can-batch-distinct? (lib.metadata/database (mt/metadata-provider)) table))))
(testing "Distinct values come back correctly via the fallback per-field path"
- (t2/update! :model/Field category-field-id {:has_field_values :list})
+ (t2/update! :model/Field :id category-field-id {:has_field_values :list})
(t2/delete! :model/FieldValues :field_id category-field-id)
(sync.field-values/sync-fields-grouped-by-table! [category-field])
(is (= #{"coffee" "tea" "matcha"}
@@ -1046,7 +1046,7 @@
(catch Exception e
(sync/sync-database! (mt/id) {:scan :schema})
(throw e))))]
- (t2/update! :model/Field category-field-id {:has_field_values :search})
+ (t2/update! :model/Field :id category-field-id {:has_field_values :search})
(t2/delete! :model/FieldValues :field_id category-field-id)
(= [["coffee"]]
(mt/user-http-request :crowberto :get 200 (format "/field/%d/search/%d" category-field-id category-field-id)
@@ -1060,7 +1060,7 @@
native-dataset
;; Fake fk relationship for bigquery because apparently fk on bigquery is not a thing.
;; We want this to test whether chain filter add a filter on partitioned fields from joned tables.
- (t2/update! :model/Field (mt/id :cf_product :category_id) {:fk_target_field_id (mt/id :cf_category :id)})
+ (t2/update! :model/Field :id (mt/id :cf_product :category_id) {:fk_target_field_id (mt/id :cf_category :id)})
(mt/with-temp
[:model/Card card-category {:database_id (mt/id)
:table_id (mt/id :cf_category)
@@ -1608,7 +1608,7 @@
;; hence, assert it was not called anymore here
(is (= 0 @call-count) "convert-dataset-id-to-filters! should not have been called any more times"))
;; now, so we need to manually update the temp DB again here, to force the "old" structure
- (let [updated? (pos? (t2/update! :model/Database db-id {:details {:dataset-id "my-dataset"}}))]
+ (let [updated? (pos? (t2/update! :model/Database :id db-id {:details {:dataset-id "my-dataset"}}))]
(is updated?)
(let [updated (t2/select-one :model/Database :id db-id)]
(is (nil? (get-in updated [:details :dataset-id])))
diff --git a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_impersonation_test.clj b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_impersonation_test.clj
index 5556a616690..239d80aba50 100644
--- a/modules/drivers/clickhouse/test/metabase/driver/clickhouse_impersonation_test.clj
+++ b/modules/drivers/clickhouse/test/metabase/driver/clickhouse_impersonation_test.clj
@@ -189,13 +189,13 @@
(defn- with-ssh-tunnel*! [tunnel-details f]
(let [base-details (t2/select-one-fn :details 'Database :id (mt/id))]
;; Set up SSH tunnel
- (t2/update! 'Database (mt/id) {:details (merge base-details tunnel-details)})
+ (t2/update! 'Database :id (mt/id) {:details (merge base-details tunnel-details)})
;; Discard any existing connection pool to make sure the new one uses it.
(sql-jdbc.conn/invalidate-pool-for-db! (mt/id))
;; Run the test body
(f)
;; Clean up
- (t2/update! 'Database (mt/id) {:details base-details})
+ (t2/update! 'Database :id (mt/id) {:details base-details})
(sql-jdbc.conn/invalidate-pool-for-db! (mt/id))))
(defmacro ^:private with-ssh-tunnel! [tunnel-details & body]
diff --git a/modules/drivers/databricks/test/metabase/driver/databricks_test.clj b/modules/drivers/databricks/test/metabase/driver/databricks_test.clj
index fc45acd7e6e..f7e12714792 100644
--- a/modules/drivers/databricks/test/metabase/driver/databricks_test.clj
+++ b/modules/drivers/databricks/test/metabase/driver/databricks_test.clj
@@ -394,11 +394,11 @@
:active true))))
(is (= 1 (count (mt/rows (mt/run-mbql-query venues {:limit 1})))))))
(testing "With multi-level-schema on"
- (t2/update! :model/Database db-id {:details (assoc details
- :multi-level-schema true
- :schema-filters-patterns multi-pattern)})
+ (t2/update! :model/Database :id db-id {:details (assoc details
+ :multi-level-schema true
+ :schema-filters-patterns multi-pattern)})
(mt/with-db
- (t2/select-one :model/Database db-id)
+ (t2/select-one :model/Database :id db-id)
(sync/sync-database! (mt/id))
(is (= #{(format "%s.%s" (:catalog details) "test-data")
(format "%s.%s" multicatalog multicatalog-schema)}
@@ -410,9 +410,9 @@
:active true))))
(is (= 1 (count (mt/rows (mt/run-mbql-query venues {:limit 1})))))))
(testing "With multi-level-schema off"
- (t2/update! :model/Database db-id {:details (assoc details :multi-level-schema false)})
+ (t2/update! :model/Database :id db-id {:details (assoc details :multi-level-schema false)})
(mt/with-db
- (t2/select-one :model/Database db-id)
+ (t2/select-one :model/Database :id db-id)
(sync/sync-database! (mt/id))
(is (= #{"test-data"} (t2/select-fn-set :schema :model/Table :db_id (mt/id) :active true)))
(is (= 52 (count (t2/select
@@ -441,13 +441,13 @@
(is (= #{"test-data"}
(t2/select-fn-set :schema :model/Table :db_id (mt/id))))))
(testing "With multi-level-schema on, schemas are qualified"
- (t2/update! :model/Database db-id {:details (assoc details
- :multi-level-schema true
- :schema-filters-patterns multi-pattern)})
+ (t2/update! :model/Database :id db-id {:details (assoc details
+ :multi-level-schema true
+ :schema-filters-patterns multi-pattern)})
;; Deactivate its tables for testing
(t2/update! :model/Table {:db_id db-id} {:active false})
(mt/with-db
- (t2/select-one :model/Database db-id)
+ (t2/select-one :model/Database :id db-id)
(sync/sync-database! (mt/id))
(is (= #{(format "%s.%s" (:catalog details) "test-data")
(format "%s.%s" multicatalog multicatalog-schema)}
@@ -469,7 +469,7 @@
:schema-filters-type "inclusion"
:schema-filters-patterns (str/join ", " schema-filters)))}]
(mt/with-db
- (t2/select-one :model/Database db-id)
+ (t2/select-one :model/Database :id db-id)
(sync/sync-database! (mt/id) {:scan :schema})
(let [table-schemas (t2/select-fn-set :schema :model/Table :db_id (mt/id) :active true)]
(is (= schema-filters table-schemas))
diff --git a/modules/drivers/druid-jdbc/test/metabase/driver/druid_jdbc_test.clj b/modules/drivers/druid-jdbc/test/metabase/driver/druid_jdbc_test.clj
index 48e7668697e..df39d34e65f 100644
--- a/modules/drivers/druid-jdbc/test/metabase/driver/druid_jdbc_test.clj
+++ b/modules/drivers/druid-jdbc/test/metabase/driver/druid_jdbc_test.clj
@@ -151,7 +151,7 @@
(mt/with-temporary-setting-values [driver.settings/nested-field-columns-value-length-limit 10]
(testing "nested fields when length limit is exceeded"
(is (= #{}
- (sql-jdbc.sync.interface/describe-nested-field-columns driver/*driver* (lib.metadata/database (mt/metadata-provider)) (t2/select-one :model/Table (mt/id :json)))))))
+ (sql-jdbc.sync.interface/describe-nested-field-columns driver/*driver* (lib.metadata/database (mt/metadata-provider)) (t2/select-one :model/Table :id (mt/id :json)))))))
(testing "nested fields when length limit is exceeded"
(is (= #{{:name "json_bit → noop",
:database-type "timestamp",
@@ -216,7 +216,7 @@
:json-unfolding false,
:visibility-type :normal,
:nfc-path [:json_bit "title"]}}
- (sql-jdbc.sync.interface/describe-nested-field-columns driver/*driver* (lib.metadata/database (mt/metadata-provider)) (t2/select-one :model/Table (mt/id :json)))))))))
+ (sql-jdbc.sync.interface/describe-nested-field-columns driver/*driver* (lib.metadata/database (mt/metadata-provider)) (t2/select-one :model/Table :id (mt/id :json)))))))))
(defn- db-dbms-version [db-or-id]
(t2/select-one-fn :dbms_version :model/Database :id (u/the-id db-or-id)))
@@ -233,7 +233,7 @@
(tqpt/with-flattened-dbdef
(let [db (mt/db)
version-on-load (db-dbms-version db)
- _ (t2/update! :model/Database (u/the-id db) {:dbms_version nil})
+ _ (t2/update! :model/Database :id (u/the-id db) {:dbms_version nil})
db (t2/select-one :model/Database :id (u/the-id db))
version-after-update (db-dbms-version db)
_ (sync-dbms-ver/sync-dbms-version! (driver.u/lib-database (:id db)))]
diff --git a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj
index 125e513dcb5..ef8cf4464c5 100644
--- a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj
+++ b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj
@@ -956,7 +956,7 @@
[(format "CREATE OR REPLACE DYNAMIC TABLE \"%s\".\"PUBLIC\".\"metabase_fan\" target_lag = DOWNSTREAM warehouse = 'COMPUTE_WH' AS
SELECT * FROM \"%s\".\"PUBLIC\".\"metabase_users\" WHERE \"%s\".\"PUBLIC\".\"metabase_users\".\"name\" LIKE 'MB_%%';"
db-name db-name db-name)])
- (sync/sync-database! (:id (t2/select-one :model/Database (mt/id))) {:scan :schema})
+ (sync/sync-database! (:id (t2/select-one :model/Database :id (mt/id))) {:scan :schema})
(thunk))))
(defmacro with-dynamic-table!
@@ -1160,7 +1160,7 @@
(let [pre-coerce-table (t2/select-one :model/Table :db_id (mt/id) :name table-name)
pre-coerce-field (t2/select-one :model/Field :table_id (:id pre-coerce-table) :name "text_column")]
;; user enables coercion: this TEXT column is really an integer
- (t2/update! :model/Field (:id pre-coerce-field)
+ (t2/update! :model/Field :id (:id pre-coerce-field)
{:coercion_strategy :Coercion/String->Integer
:effective_type :type/Integer})
(run-sql! [(format (str "CREATE OR REPLACE TABLE %s AS "
@@ -1194,7 +1194,7 @@
(field-user-settings/upsert-user-settings v4-field
{:coercion_strategy :Coercion/String->Integer
:effective_type :type/Integer})
- (t2/update! :model/Field (:id v4-field)
+ (t2/update! :model/Field :id (:id v4-field)
{:coercion_strategy :Coercion/String->Integer
:effective_type :type/Integer})
(run-sql! [(format (str "CREATE OR REPLACE TABLE %s AS "
@@ -1428,12 +1428,12 @@
(testing (format "use-password: %s private-key-options: %s uses-secret? %s" use-password options uses-secret?)
(spit pk-path pk-key)
(is (= 3 (count all-possible-details)))
- (t2/update! (t2/table-name :model/Database) (mt/id) {:details (json/encode details)})
+ (t2/update! (t2/table-name :model/Database) :id (mt/id) {:details (json/encode details)})
(testing "Connection succeeds and migration occurs"
(log/with-no-logs
(log.capture/with-log-messages-for-level [messages [metabase.warehouses.models.database :info]]
(is (= details-to-succeed
- (database/maybe-test-and-migrate-details! (assoc (t2/select-one :model/Database (mt/id))
+ (database/maybe-test-and-migrate-details! (assoc (t2/select-one :model/Database :id (mt/id))
:details details))))
(let [success-re #"^Successfully connected, migrating to: (.*)"
msgs (messages)
@@ -1446,7 +1446,7 @@
(is (= {:keys success-keys
:keys-removed keys-removed}
migrating-to))))
- (let [migrated-details (:details (t2/select-one :model/Database (mt/id)))
+ (let [migrated-details (:details (t2/select-one :model/Database :id (mt/id)))
expected-migrated (cond-> details-to-succeed
uses-secret? (assoc :private-key-id secret-id)
:always (dissoc :private-key-options :private-key-value :private-key-path))]
@@ -1519,8 +1519,8 @@
:type :query
:query {:source-table (:id table)}})))))
;; Cleanup
- (u/ignore-exceptions (t2/delete! :model/Database (:id db)))
- (u/ignore-exceptions (t2/delete! :model/Table (:id table)))
+ (u/ignore-exceptions (t2/delete! :model/Database :id (:id db)))
+ (u/ignore-exceptions (t2/delete! :model/Table :id (:id table)))
(u/ignore-exceptions (t2/delete! :model/Field :id [:in (map :id fields)]))
(u/ignore-exceptions (t2/delete! :model/FieldValues :field_id [:in (map :id fields)]))))))
@@ -1567,8 +1567,8 @@
:type :query
:query {:source-table (:id table)}})))))
;; Cleanup
- (u/ignore-exceptions (t2/delete! :model/Database (:id db)))
- (u/ignore-exceptions (t2/delete! :model/Table (:id table)))
+ (u/ignore-exceptions (t2/delete! :model/Database :id (:id db)))
+ (u/ignore-exceptions (t2/delete! :model/Table :id (:id table)))
(u/ignore-exceptions (t2/delete! :model/Field :id [:in (map :id fields)]))
(u/ignore-exceptions (t2/delete! :model/FieldValues :field_id [:in (map :id fields)]))))))
@@ -2079,7 +2079,7 @@
(deftest have-select-privelege?-timeout-test
(mt/test-driver :snowflake
- (let [{schema :schema, table-name :name} (t2/select-one :model/Table (mt/id :checkins))]
+ (let [{schema :schema, table-name :name} (t2/select-one :model/Table :id (mt/id :checkins))]
(qp.store/with-metadata-provider (mt/id)
(testing "checking select privilege defaults to allow on timeout (#56737)"
(mt/with-dynamic-fn-redefs [sql-jdbc.describe-database/simple-select-probe-query (constantly ["SELECT SYSTEM$WAIT(3, 'SECONDS')"])]
@@ -2141,9 +2141,9 @@
(mt/with-temp [:model/Database rsa-db {:engine :snowflake :details rsa-details}]
(let [original-priv-key (get-db-priv-key rsa-db)
updating-rsa-db (merge rsa-db {:details rsa-details-2})
- _ (t2/update! :model/Database (:id rsa-db) updating-rsa-db)
+ _ (t2/update! :model/Database :id (:id rsa-db) updating-rsa-db)
details-changed? (not= (:details rsa-db) (:details updating-rsa-db))
- new-rsa-db (t2/select-one :model/Database (:id rsa-db))
+ new-rsa-db (t2/select-one :model/Database :id (:id rsa-db))
priv-key-after-update (get-db-priv-key new-rsa-db)
_ (events/publish-event! :event/database-update {:object new-rsa-db
:user-id 1
diff --git a/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj b/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj
index 434556130a5..1a3458e78ed 100644
--- a/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj
+++ b/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj
@@ -1147,7 +1147,7 @@
(mt/test-driver :sqlserver
(mt/dataset bigint-identity-data
(is (= :type/BigInteger
- (t2/select-one-fn :base_type :model/Field (mt/id :bigint_identity_test :id))))))))
+ (t2/select-one-fn :base_type :model/Field :id (mt/id :bigint_identity_test :id))))))))
(def ^:private udt-alias-db-details
(delay (mt/dbdef->connection-details :sqlserver :db {:database-name "udt_alias_test"})))
diff --git a/src/metabase/actions/db.clj b/src/metabase/actions/db.clj
index 0067cffe317..5fc811f89af 100644
--- a/src/metabase/actions/db.clj
+++ b/src/metabase/actions/db.clj
@@ -151,7 +151,7 @@
"Apply `changes` to the Action with `action-id`, returning the number updated."
[action-id :- ::lib.schema.id/action
changes :- ::actions.schema/action.for-update]
- (t2/update! :model/Action action-id changes))
+ (t2/update! :model/Action :id action-id changes))
(mu/defn insert-query-action!
"Insert the QueryAction `action`, returning the number inserted."
@@ -167,13 +167,13 @@
"Apply `changes` to the QueryAction with `action-id`, returning the number updated."
[action-id :- ::lib.schema.id/action
changes :- ::actions.schema/query-action.update]
- (t2/update! :model/QueryAction action-id changes))
+ (t2/update! :model/QueryAction :action_id action-id changes))
(mu/defn update-implicit-action!
"Apply `changes` to the ImplicitAction with `action-id`, returning the number updated."
[action-id :- ::lib.schema.id/action
changes :- ::actions.schema/implicit-action.update]
- (t2/update! :model/ImplicitAction action-id changes))
+ (t2/update! :model/ImplicitAction :action_id action-id changes))
(mu/defn delete-query-action!
"Delete the QueryAction of the Action with `action-id`, returning the number deleted."
diff --git a/src/metabase/actions_rest/db.clj b/src/metabase/actions_rest/db.clj
index 44f484c1f1b..a7d61f004d4 100644
--- a/src/metabase/actions_rest/db.clj
+++ b/src/metabase/actions_rest/db.clj
@@ -55,4 +55,4 @@
[action-id :- ::lib.schema.id/action
public-uuid :- [:maybe :string]
made-public-by-id :- [:maybe ::lib.schema.id/user]]
- (t2/update! :model/Action action-id {:public_uuid public-uuid, :made_public_by_id made-public-by-id}))
+ (t2/update! :model/Action :id action-id {:public_uuid public-uuid, :made_public_by_id made-public-by-id}))
diff --git a/src/metabase/agent_api/db.clj b/src/metabase/agent_api/db.clj
index da7bc14d7ab..6447b3f6c78 100644
--- a/src/metabase/agent_api/db.clj
+++ b/src/metabase/agent_api/db.clj
@@ -65,13 +65,13 @@
"Apply `changes` to the DashboardCard with `dashcard-id`, returning the number updated."
[dashcard-id :- ::lib.schema.id/dashcard
changes :- (mut/select-keys ::dashboards.schema/dashboard-card.update [:visualization_settings :row :col])]
- (t2/update! :model/DashboardCard dashcard-id changes))
+ (t2/update! :model/DashboardCard :id dashcard-id changes))
(mu/defn update-dashboard!
"Apply `changes` to the Dashboard with `dashboard-id`, returning the number updated."
[dashboard-id :- ::lib.schema.id/dashboard
changes :- (mut/select-keys ::dashboards.schema/dashboard.update [:name :description :collection_id :archived :archived_directly])]
- (t2/update! :model/Dashboard dashboard-id changes))
+ (t2/update! :model/Dashboard :id dashboard-id changes))
(mu/defn active-user-by-email
"The active User with `email`, compared case-insensitively, or nil."
diff --git a/src/metabase/api_keys/db.clj b/src/metabase/api_keys/db.clj
index 402a50c1716..7ca92657153 100644
--- a/src/metabase/api_keys/db.clj
+++ b/src/metabase/api_keys/db.clj
@@ -47,12 +47,12 @@
(mu/defn api-key-exists?
"Whether an ApiKey with `id` exists."
[id :- ms/PositiveInt]
- (t2/exists? :model/ApiKey id))
+ (t2/exists? :model/ApiKey :id id))
(mu/defn delete-api-key!
"Delete the ApiKey with `id`."
[id :- ms/PositiveInt]
- (t2/delete! :model/ApiKey id))
+ (t2/delete! :model/ApiKey :id id))
(mu/defn api-key-groups
"The group name, group id, and api key id of the PermissionsGroups of the ApiKeys with `api-key-ids`."
diff --git a/src/metabase/app_db/custom_migrations.clj b/src/metabase/app_db/custom_migrations.clj
index 72fa44ed327..263332ff2c6 100644
--- a/src/metabase/app_db/custom_migrations.clj
+++ b/src/metabase/app_db/custom_migrations.clj
@@ -858,7 +858,7 @@
(filter :visualization_settings))
(completing
(fn [_ {:keys [id visualization_settings]}]
- (t2/update! :report_dashboardcard id
+ (t2/update! :report_dashboardcard :id id
{:visualization_settings (json/encode visualization_settings)})))
nil
;; flamber wrote a manual postgres migration that this faithfully recreates: see
diff --git a/src/metabase/app_db/custom_migrations/metrics_v2.clj b/src/metabase/app_db/custom_migrations/metrics_v2.clj
index 9d6b5235ba6..996da40b612 100644
--- a/src/metabase/app_db/custom_migrations/metrics_v2.clj
+++ b/src/metabase/app_db/custom_migrations/metrics_v2.clj
@@ -131,8 +131,8 @@
(run! (fn [card]
(let [dataset-query (:dataset_query card)]
(when-let [rewritten (rewrite-metric-consuming-card dataset-query metric-id->metric-card-id)]
- (t2/update! :report_card (:id card) {:dataset_query rewritten
- :dataset_query_metrics_v2_migration_backup dataset-query}))))
+ (t2/update! :report_card :id (:id card) {:dataset_query rewritten
+ :dataset_query_metrics_v2_migration_backup dataset-query}))))
(t2/reducible-query {:select [:id :dataset_query]
:from [:report_card]
:where [:like [:lower :dataset_query] "%[\"metric\",%"]})))))
@@ -148,4 +148,4 @@
" SET dataset_query = dataset_query_metrics_v2_migration_backup"
" WHERE dataset_query_metrics_v2_migration_backup IS NOT NULL")])
(t2/delete! :report_card :collection_id metric-v2-coll-id)
- (t2/delete! :collection metric-v2-coll-id)))
+ (t2/delete! :collection :id metric-v2-coll-id)))
diff --git a/src/metabase/app_db/query.clj b/src/metabase/app_db/query.clj
index c7a14a832c8..2506b93c6b5 100644
--- a/src/metabase/app_db/query.clj
+++ b/src/metabase/app_db/query.clj
@@ -263,7 +263,8 @@
(if-let [existing (apply t2/select-one model select-kvs)]
(let [pk (pk-of existing)]
(if-let [updated (update-fn existing)]
- (do (t2/update! model pk updated)
+ ;; `model` is any model, so match on its own primary key, which may not be `:id` or may be composite.
+ (do (t2/update! model :toucan/pk pk updated)
;; the primary key may have been changed by the update, and this is OK.
(pk-of (merge existing updated)))
;; update-fn returned nil — no update needed, return existing pk.
diff --git a/src/metabase/auth_identity/db.clj b/src/metabase/auth_identity/db.clj
index c7ae56d517e..31e41f0742a 100644
--- a/src/metabase/auth_identity/db.clj
+++ b/src/metabase/auth_identity/db.clj
@@ -55,13 +55,13 @@
"Apply `changes` to the AuthIdentity with `id`, returning the number updated."
[id :- ms/PositiveInt
changes :- AuthIdentityRow]
- (t2/update! :model/AuthIdentity id changes))
+ (t2/update! :model/AuthIdentity :id [:auto/param id] changes))
(mu/defn touch-auth-identity!
"Set `last_used_at` of the AuthIdentity with `id` to now, returning the number updated. `id` may be nil (no
matching AuthIdentity), which updates nothing."
[id :- [:maybe ms/PositiveInt]]
- (t2/update! :model/AuthIdentity id {:last_used_at :%now}))
+ (t2/update! :model/AuthIdentity :id [:auto/param id] {:last_used_at :%now}))
(mu/defn delete-auth-identities!
"Delete the AuthIdentities of the User with `user-id` at `provider`, returning the number deleted."
@@ -109,7 +109,7 @@
(mu/defn user-login-status
"The id, active flag, and last login of the User with `user-id`, or nil."
[user-id :- ::lib.schema.id/user]
- (t2/select-one [:model/User :id :is_active :last_login] user-id))
+ (t2/select-one [:model/User :id :is_active :last_login] :id [:auto/param user-id]))
(mu/defn user-active?
"Whether the User with `user-id` is active."
@@ -120,7 +120,7 @@
"Apply `changes` to the User with `user-id`, returning the number updated."
[user-id :- ::lib.schema.id/user
changes :- ::users.schema/user.update]
- (t2/update! :model/User user-id changes))
+ (t2/update! :model/User :id [:auto/param user-id] changes))
(mu/defn insert-user-returning-login-columns!
"Insert the User `row` and return its id, last login, active flag, and tenant id."
diff --git a/src/metabase/cache/db.clj b/src/metabase/cache/db.clj
index 64c6df86256..254e135a71b 100644
--- a/src/metabase/cache/db.clj
+++ b/src/metabase/cache/db.clj
@@ -6,6 +6,7 @@
[metabase.app-db.core :as app-db]
[metabase.cache.schema :as cache.schema]
[metabase.lib.schema.id :as lib.schema.id]
+ [metabase.util.honey-sql-2 :as h2x]
[metabase.util.malli :as mu]
[metabase.util.malli.schema :as ms]
[toucan2.core :as t2]))
@@ -98,10 +99,11 @@
limit :- [:maybe ms/PositiveInt]
offset :- [:maybe ms/IntGreaterThanOrEqualToZero]]
(t2/select :model/CacheConfig
- (cond-> (base-query models collection id)
- sort-column (assoc :order-by [[(sort-column->order-by sort-column) sort-direction]])
- limit (assoc :limit limit)
- offset (assoc :offset offset))))
+ (h2x/assert-map-or-nil!
+ (cond-> (base-query models collection id)
+ sort-column (assoc :order-by [[(sort-column->order-by sort-column) sort-direction]])
+ limit (assoc :limit limit)
+ offset (assoc :offset offset)))))
(mu/defn cache-config-count-row
"The `:count` row of the CacheConfigs [[cache-configs-page]] pages through."
diff --git a/src/metabase/channel/db.clj b/src/metabase/channel/db.clj
index 456e10073db..8c8483ec742 100644
--- a/src/metabase/channel/db.clj
+++ b/src/metabase/channel/db.clj
@@ -42,7 +42,7 @@
"Apply `changes` to the Channel with `id`, returning the number updated."
[id :- ms/PositiveInt
changes :- ChannelRow]
- (t2/update! :model/Channel id changes))
+ (t2/update! :model/Channel :id id changes))
(mu/defn accepted-admin-emails
"The emails of the active personal superusers who have logged in at least once, in id order."
diff --git a/src/metabase/collections/db.clj b/src/metabase/collections/db.clj
index a55625783d4..8abb81cc070 100644
--- a/src/metabase/collections/db.clj
+++ b/src/metabase/collections/db.clj
@@ -8,6 +8,7 @@
[metabase.collections.schema :as collections.schema]
[metabase.lib.schema.id :as lib.schema.id]
[metabase.models.serialization :as serdes]
+ [metabase.util.honey-sql-2 :as h2x]
[metabase.util.malli :as mu]
[metabase.util.malli.schema :as ms]
[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay]
@@ -292,7 +293,7 @@
builders like `visible-collection-filter-clause`, which live in `metabase.collections.models.collection` and so
can't be called from here without a require cycle (that namespace already requires this one)."
[query]
- (t2/select :model/Collection query))
+ (t2/select :model/Collection (h2x/assert-map-or-nil! query)))
;;; ---------------------------------------------- Collection writes ----------------------------------------------
@@ -305,7 +306,7 @@
"Apply `changes` to the ::collections.schema/collection with `collection-id`, returning the number updated."
[collection-id :- ::lib.schema.id/collection
changes :- (mut/select-keys ::collections.schema/collection.update [:name :description :archived :location :personal_owner_id :slug :namespace :authority_level :entity_id :created_at :type :is_sample :archive_operation_id :archived_directly :is_remote_synced])]
- (t2/update! :model/Collection collection-id changes))
+ (t2/update! :model/Collection :id collection-id changes))
(mu/defn clear-remote-synced-flags!
"Mark every remote-synced ::collections.schema/collection as not remote-synced, returning the number updated."
@@ -685,7 +686,7 @@
(mu/defn user-type
"The type of the User with `user-id`."
[user-id :- ::lib.schema.id/user]
- (t2/select-one-fn :type :model/User user-id))
+ (t2/select-one-fn :type :model/User :id user-id))
(mu/defn user-name-parts-by-id
"A map of ID to the first name, last name, and email of the Users with `user-ids`."
diff --git a/src/metabase/comments/db.clj b/src/metabase/comments/db.clj
index 55aef5f3cd9..1d3ad980c3c 100644
--- a/src/metabase/comments/db.clj
+++ b/src/metabase/comments/db.clj
@@ -10,6 +10,7 @@
[metabase.users.core :as users]
[metabase.users.models.user :as user]
[metabase.users.settings :as users.settings]
+ [metabase.util.honey-sql-2 :as h2x]
[metabase.util.malli :as mu]
[metabase.util.malli.schema :as ms]
[toucan2.core :as t2]))
@@ -92,12 +93,12 @@
"Apply `changes` to the Comment with `id`, returning the number updated."
[id :- ms/PositiveInt
changes :- (mut/select-keys ::comments.schema/comment.update [:content :is_resolved])]
- (t2/update! :model/Comment id changes))
+ (t2/update! :model/Comment :id id changes))
(mu/defn soft-delete-comment!
"Mark the Comment with `id` deleted now, returning the number updated."
[id :- ms/PositiveInt]
- (t2/update! :model/Comment id {:deleted_at [:now]}))
+ (t2/update! :model/Comment :id id {:deleted_at [:now]}))
(defn- restrict-to-visible-users
"Narrow `clauses` (from `user/filter-clauses`) to the users the current user should see: superusers see
@@ -120,11 +121,12 @@
[limit :- [:maybe ms/PositiveInt]
offset :- [:maybe ms/IntGreaterThanOrEqualToZero]]
(t2/select [:model/User :id :first_name :last_name :email]
- (-> (user/filter-clauses {:limit limit :offset offset})
- restrict-to-visible-users
- (sql.helpers/order-by [:%lower.first_name :asc]
- [:%lower.last_name :asc]
- [:id :asc]))))
+ (h2x/assert-map-or-nil!
+ (-> (user/filter-clauses {:limit limit :offset offset})
+ restrict-to-visible-users
+ (sql.helpers/order-by [:%lower.first_name :asc]
+ [:%lower.last_name :asc]
+ [:id :asc])))))
(mu/defn mentionable-user-count
"The `:count` of the active Users the current user may @mention."
diff --git a/src/metabase/dashboards/db.clj b/src/metabase/dashboards/db.clj
index 6725388f55a..3b398db4ae7 100644
--- a/src/metabase/dashboards/db.clj
+++ b/src/metabase/dashboards/db.clj
@@ -34,7 +34,7 @@
`:archived`, `:collection_id`, `:cache_ttl`, ...), and a narrowed schema refuses every one of them."
[dashboard-id :- ::lib.schema.id/dashboard
changes :- ::dashboards.schema/dashboard.update]
- (t2/update! :model/Dashboard dashboard-id changes))
+ (t2/update! :model/Dashboard :id dashboard-id changes))
(mu/defn delete-dashboard-revisions!
"Delete the Revisions of the Dashboard with `dashboard-id`, returning the number deleted."
@@ -218,7 +218,7 @@
"Apply `changes` to the DashboardCard with `dashcard-id`, returning the number updated."
[dashcard-id :- ::lib.schema.id/dashcard
changes :- ::dashboards.schema/dashboard-card.update]
- (t2/update! :model/DashboardCard dashcard-id changes))
+ (t2/update! :model/DashboardCard :id dashcard-id changes))
(mu/defn delete-dashcards!
"Delete the DashboardCards with `dashcard-ids`, returning the number deleted."
@@ -360,7 +360,8 @@
[[link-card-info-rows]], or nil."
[model :- :string
id :- [:or :int :string]]
- (t2/select-one (serdes/link-card-model->toucan-model model) (link-card-info-query-for-model model id)))
+ (t2/select-one (serdes/link-card-model->toucan-model model)
+ (h2x/assert-map-or-nil! (link-card-info-query-for-model model id))))
(defn- link-card-info-query
[link-card-model->ids]
@@ -391,7 +392,7 @@
"Apply `changes` to the DashboardTab with `tab-id`, returning the number updated."
[tab-id :- ms/PositiveInt
changes :- (mut/select-keys ::dashboards.schema/dashboard-tab.update [:name :position])]
- (t2/update! :model/DashboardTab tab-id changes))
+ (t2/update! :model/DashboardTab :id tab-id changes))
(mu/defn delete-dashboard-tabs!
"Delete the DashboardTabs with `tab-ids`, returning the number deleted."
diff --git a/src/metabase/dashboards_rest/db.clj b/src/metabase/dashboards_rest/db.clj
index 95cb07bafa1..934285235d5 100644
--- a/src/metabase/dashboards_rest/db.clj
+++ b/src/metabase/dashboards_rest/db.clj
@@ -60,7 +60,7 @@
"Apply `changes` to the Dashboard with `dashboard-id`."
[dashboard-id :- ::lib.schema.id/dashboard
changes :- ::dashboards.schema/dashboard.update]
- (t2/update! :model/Dashboard dashboard-id changes))
+ (t2/update! :model/Dashboard :id dashboard-id changes))
(mu/defn delete-dashboard!
"Delete the Dashboard with `dashboard-id`."
diff --git a/src/metabase/documents/db.clj b/src/metabase/documents/db.clj
index c27e61f1bd2..33ee94e5ba7 100644
--- a/src/metabase/documents/db.clj
+++ b/src/metabase/documents/db.clj
@@ -66,7 +66,7 @@
"Apply `changes` to the Document with `id`, returning the number updated."
[id :- ms/PositiveInt
changes :- ::documents.schema/document.update]
- (t2/update! :model/Document id changes))
+ (t2/update! :model/Document :id id changes))
(mu/defn delete-document!
"Delete the Document with `id`, returning the number deleted."
@@ -121,7 +121,7 @@
"Apply `changes` to the Card with `card-id`, returning the number updated."
[card-id :- ::lib.schema.id/card
changes :- (mut/select-keys ::queries.schema/card.update [:archived :archived_directly])]
- (t2/update! :model/Card card-id changes))
+ (t2/update! :model/Card :id card-id changes))
(mu/defn update-cards-for-document!
"Apply `changes` to the Cards of the Document with `document-id`, returning the number updated."
diff --git a/src/metabase/embedding_rest/db.clj b/src/metabase/embedding_rest/db.clj
index 73ed769e641..ae541b48b93 100644
--- a/src/metabase/embedding_rest/db.clj
+++ b/src/metabase/embedding_rest/db.clj
@@ -81,7 +81,7 @@
"Apply `changes` to the EmbeddingTheme with `id`."
[id :- ms/PositiveInt
changes :- (mut/select-keys ::embedding.schema/embedding-theme.update [:name :settings])]
- (t2/update! :model/EmbeddingTheme id changes))
+ (t2/update! :model/EmbeddingTheme :id id changes))
(mu/defn delete-embedding-theme!
"Delete the EmbeddingTheme with `id`."
diff --git a/src/metabase/explorations/db.clj b/src/metabase/explorations/db.clj
index 9f4a4604e6b..267d83e5b58 100644
--- a/src/metabase/explorations/db.clj
+++ b/src/metabase/explorations/db.clj
@@ -13,6 +13,7 @@
[metabase.queries.core :as queries]
[metabase.queries.schema :as queries.schema]
[metabase.util :as u]
+ [metabase.util.honey-sql-2 :as h2x]
[metabase.util.malli :as mu]
[metabase.util.malli.schema :as ms]
[toucan2.core :as t2]))
@@ -83,7 +84,7 @@
[user-id :- ::lib.schema.id/user
limit :- [:maybe ms/PositiveInt]
offset :- [:maybe ms/IntGreaterThanOrEqualToZero]]
- (t2/select :model/Exploration (my-explorations-query user-id limit offset)))
+ (t2/select :model/Exploration (h2x/assert-map-or-nil! (my-explorations-query user-id limit offset))))
(mu/defn exploration-creator-id-for-thread
"The creator of the Exploration owning the ExplorationThread with `thread-id`."
@@ -101,7 +102,7 @@
"Apply `changes` to the Exploration with `exploration-id`."
[exploration-id :- ms/PositiveInt
changes :- (mut/select-keys ::explorations.schema/exploration.update [:name :description :archived :archived_directly :collection_id :collection_position])]
- (t2/update! :model/Exploration exploration-id changes))
+ (t2/update! :model/Exploration :id exploration-id changes))
(mu/defn delete-exploration!
"Delete the Exploration with `exploration-id`."
@@ -199,7 +200,7 @@
"Apply `changes` to the ExplorationThread with `thread-id`."
[thread-id :- ms/PositiveInt
changes :- (mut/select-keys ::explorations.schema/exploration-thread.update [:started_at :analysis_started_at :completed_at :query_plan_transcript])]
- (t2/update! :model/ExplorationThread thread-id changes))
+ (t2/update! :model/ExplorationThread :id thread-id changes))
(mu/defn cancel-thread!
"Mark the uncompleted ExplorationThread with `thread-id` canceled and completed at `now`, returning the number of
@@ -375,7 +376,7 @@
"Apply `changes` to the ExplorationPage with `page-id`."
[page-id :- ms/PositiveInt
changes :- (mut/select-keys ::explorations.schema/exploration-page.update [:starred])]
- (t2/update! :model/ExplorationPage page-id changes))
+ (t2/update! :model/ExplorationPage :id page-id changes))
(mu/defn update-pages!
"Apply `changes` to the ExplorationPages with `page-ids`."
@@ -500,7 +501,7 @@
"Apply `changes` to the ExplorationQuery with `query-id`."
[query-id :- ms/PositiveInt
changes :- (mut/select-keys ::explorations.schema/exploration-query.update [:dataset_query :name :data_access_token :status :started_at :finished_at])]
- (t2/update! :model/ExplorationQuery query-id changes))
+ (t2/update! :model/ExplorationQuery :id query-id changes))
(mu/defn fail-pending-query!
"Mark the pending ExplorationQuery with `query-id` as errored with `message` at `finished-at`, returning the number
diff --git a/src/metabase/glossary/db.clj b/src/metabase/glossary/db.clj
index 6f8295e8762..22cef5a8fe7 100644
--- a/src/metabase/glossary/db.clj
+++ b/src/metabase/glossary/db.clj
@@ -35,7 +35,7 @@
[id :- ms/PositiveInt
term :- :string
definition :- :string]
- (t2/update! :model/Glossary id {:term term :definition definition}))
+ (t2/update! :model/Glossary :id id {:term term :definition definition}))
(mu/defn delete-glossary-entry!
"Delete the Glossary entry with `id`."
diff --git a/src/metabase/indexed_entities/db.clj b/src/metabase/indexed_entities/db.clj
index 149a33412bc..4f84f6d7df5 100644
--- a/src/metabase/indexed_entities/db.clj
+++ b/src/metabase/indexed_entities/db.clj
@@ -32,7 +32,7 @@
(mu/defn delete-model-index!
"Delete the ModelIndex with `id`, returning the number deleted."
[id :- ms/PositiveInt]
- (t2/delete! :model/ModelIndex id))
+ (t2/delete! :model/ModelIndex :id id))
(mu/defn card
"The Card with `card-id`, or nil."
@@ -53,18 +53,18 @@
"Record `error-message` on the ModelIndex with `id` and stamp its indexing time, returning the number updated."
[id :- ms/PositiveInt
error-message :- :string]
- (t2/update! :model/ModelIndex id {:state "error"
- :error error-message
- :indexed_at :%now}))
+ (t2/update! :model/ModelIndex :id id {:state "error"
+ :error error-message
+ :indexed_at :%now}))
(mu/defn mark-model-index-indexed!
"Set the ModelIndex with `id` to `state`, clear its error, and stamp its indexing time, returning the number
updated."
[id :- ms/PositiveInt
state :- :string]
- (t2/update! :model/ModelIndex id {:indexed_at :%now
- :error nil
- :state state}))
+ (t2/update! :model/ModelIndex :id id {:indexed_at :%now
+ :error nil
+ :state state}))
(mu/defn delete-model-index-values!
"Delete the ModelIndexValues of the ModelIndex with `model-index-id` for the model primary keys `model-pks`,
diff --git a/src/metabase/indexes_rest/db.clj b/src/metabase/indexes_rest/db.clj
index 83484c14f21..c5bd4bec602 100644
--- a/src/metabase/indexes_rest/db.clj
+++ b/src/metabase/indexes_rest/db.clj
@@ -27,10 +27,10 @@
"Set the `structured` definition of the TableIndex with `id`."
[id :- ms/PositiveInt
structured :- [:maybe ::indexes.schema/table-index.structured]]
- (t2/update! :model/TableIndex id {:structured structured}))
+ (t2/update! :model/TableIndex :id id {:structured structured}))
(mu/defn set-table-index-status!
"Set the `status` of the TableIndex with `id`."
[id :- ms/PositiveInt
status :- [:or :keyword :string]]
- (t2/update! :model/TableIndex id {:status status}))
+ (t2/update! :model/TableIndex :id id {:status status}))
diff --git a/src/metabase/lib_be/db.clj b/src/metabase/lib_be/db.clj
index 6e252a84ac7..d716dc51a54 100644
--- a/src/metabase/lib_be/db.clj
+++ b/src/metabase/lib_be/db.clj
@@ -5,6 +5,7 @@
[honey.sql.helpers :as sql.helpers]
[metabase.lib.metadata.protocols :as lib.metadata.protocols]
[metabase.lib.schema.id :as lib.schema.id]
+ [metabase.util.honey-sql-2 :as h2x]
[metabase.util.malli :as mu]
[toucan2.core :as t2]))
@@ -16,7 +17,7 @@
(mu/defn database
"The `:metadata/database` with `database-id`, or nil."
[database-id :- ::lib.schema.id/database]
- (t2/select-one :metadata/database database-id))
+ (t2/select-one :metadata/database :id database-id))
;;; ----------------------------------------------- Lib metadata -----------------------------------------------
;;;
@@ -129,46 +130,48 @@
"The `:metadata/table` rows for `database-id` picked out by `metadata-spec`."
[database-id :- ::lib.schema.id/database
metadata-spec :- ::lib.metadata.protocols/metadata-spec]
- (t2/select :metadata/table (metadata-where :metadata/table database-id metadata-spec)))
+ (t2/select :metadata/table (h2x/assert-map-or-nil! (metadata-where :metadata/table database-id metadata-spec))))
(mu/defn columns
"The `:metadata/column` rows for `database-id` picked out by `metadata-spec`."
[database-id :- ::lib.schema.id/database
metadata-spec :- ::lib.metadata.protocols/metadata-spec]
- (t2/select :metadata/column (metadata-where :metadata/column database-id metadata-spec)))
+ (t2/select :metadata/column (h2x/assert-map-or-nil! (metadata-where :metadata/column database-id metadata-spec))))
(mu/defn cards
"The `:metadata/card` rows for `database-id` picked out by `metadata-spec`."
[database-id :- ::lib.schema.id/database
metadata-spec :- ::lib.metadata.protocols/metadata-spec]
- (t2/select :metadata/card (metadata-where :metadata/card database-id metadata-spec)))
+ (t2/select :metadata/card (h2x/assert-map-or-nil! (metadata-where :metadata/card database-id metadata-spec))))
(mu/defn metrics
"The `:metadata/metric` rows for `database-id` picked out by `metadata-spec`."
[database-id :- ::lib.schema.id/database
metadata-spec :- ::lib.metadata.protocols/metadata-spec]
- (t2/select :metadata/metric (metadata-where :metadata/metric database-id metadata-spec)))
+ (t2/select :metadata/metric (h2x/assert-map-or-nil! (metadata-where :metadata/metric database-id metadata-spec))))
(mu/defn segments
"The `:metadata/segment` rows for `database-id` picked out by `metadata-spec`."
[database-id :- ::lib.schema.id/database
metadata-spec :- ::lib.metadata.protocols/metadata-spec]
- (t2/select :metadata/segment (metadata-where :metadata/segment database-id metadata-spec)))
+ (t2/select :metadata/segment (h2x/assert-map-or-nil! (metadata-where :metadata/segment database-id metadata-spec))))
(mu/defn measures
"The `:metadata/measure` rows for `database-id` picked out by `metadata-spec`."
[database-id :- ::lib.schema.id/database
metadata-spec :- ::lib.metadata.protocols/metadata-spec]
- (t2/select :metadata/measure (metadata-where :metadata/measure database-id metadata-spec)))
+ (t2/select :metadata/measure (h2x/assert-map-or-nil! (metadata-where :metadata/measure database-id metadata-spec))))
(mu/defn native-query-snippets
"The `:metadata/native-query-snippet` rows picked out by `metadata-spec`."
[database-id :- ::lib.schema.id/database
metadata-spec :- ::lib.metadata.protocols/metadata-spec]
- (t2/select :metadata/native-query-snippet (metadata-where :metadata/native-query-snippet database-id metadata-spec)))
+ (t2/select :metadata/native-query-snippet
+ (h2x/assert-map-or-nil! (metadata-where :metadata/native-query-snippet database-id metadata-spec))))
(mu/defn transforms
"The `:metadata/transform` rows picked out by `metadata-spec`."
[database-id :- ::lib.schema.id/database
metadata-spec :- ::lib.metadata.protocols/metadata-spec]
- (t2/select :metadata/transform (metadata-where :metadata/transform database-id metadata-spec)))
+ (t2/select :metadata/transform
+ (h2x/assert-map-or-nil! (metadata-where :metadata/transform database-id metadata-spec))))
diff --git a/src/metabase/lib_metric/db.clj b/src/metabase/lib_metric/db.clj
index 9ed565f6e38..77198906115 100644
--- a/src/metabase/lib_metric/db.clj
+++ b/src/metabase/lib_metric/db.clj
@@ -4,6 +4,7 @@
(:require
[honey.sql.helpers :as sql.helpers]
[metabase.lib.schema.id :as lib.schema.id]
+ [metabase.util.honey-sql-2 :as h2x]
[metabase.util.malli :as mu]
[metabase.util.malli.schema :as ms]
[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay]
@@ -46,7 +47,7 @@
[:name {:optional true} [:maybe [:set :string]]]
[:table-ids {:optional true} [:maybe [:set ::lib.schema.id/table]]]
[:card-ids {:optional true} [:maybe [:set ::lib.schema.id/card]]]]]
- (t2/select :metadata/metric (metric-where metadata-spec)))
+ (t2/select :metadata/metric (h2x/assert-map-or-nil! (metric-where metadata-spec))))
(defn- measure-where
"The `:where` map for the `:metadata/measure` rows picked out by `metadata-spec` (its `:id`, `:name`, and
@@ -67,4 +68,4 @@
[:id {:optional true} [:maybe [:set ms/PositiveInt]]]
[:name {:optional true} [:maybe [:set :string]]]
[:table-ids {:optional true} [:maybe [:set ::lib.schema.id/table]]]]]
- (t2/select :metadata/measure (measure-where metadata-spec)))
+ (t2/select :metadata/measure (h2x/assert-map-or-nil! (measure-where metadata-spec))))
diff --git a/src/metabase/measures/db.clj b/src/metabase/measures/db.clj
index 8d2516c2907..f10d0caf8ca 100644
--- a/src/metabase/measures/db.clj
+++ b/src/metabase/measures/db.clj
@@ -40,7 +40,7 @@
"Apply `changes` to the Measure with `id`."
[id :- ::lib.schema.id/measure
changes :- (mut/select-keys ::measures.schema/measure.update [:name :description :archived :definition])]
- (t2/update! :model/Measure id changes))
+ (t2/update! :model/Measure :id id changes))
(mu/defn table
"The Table with `table-id`, or nil."
@@ -62,4 +62,4 @@
[id :- ::lib.schema.id/measure
dimensions :- [:maybe sequential?]
dimension-mappings :- [:maybe [:sequential ::measures.schema/measure.dimension-mapping]]]
- (t2/update! :model/Measure id {:dimensions dimensions, :dimension_mappings dimension-mappings}))
+ (t2/update! :model/Measure :id id {:dimensions dimensions, :dimension_mappings dimension-mappings}))
diff --git a/src/metabase/metabot/db.clj b/src/metabase/metabot/db.clj
index 57fa7c8640d..36602b8164f 100644
--- a/src/metabase/metabot/db.clj
+++ b/src/metabase/metabot/db.clj
@@ -15,6 +15,7 @@
[metabase.models.interface :as mi]
[metabase.premium-features.core :as premium-features]
[metabase.util :as u]
+ [metabase.util.honey-sql-2 :as h2x]
[metabase.util.malli :as mu]
[metabase.util.malli.schema :as ms]
[metabase.warehouse-schema-overlay.core :as warehouse-schema-overlay]
@@ -53,7 +54,7 @@
"Apply `changes` to the Metabot with `metabot-id`."
[metabot-id :- ms/PositiveInt
changes :- (mut/select-keys ::metabot.schema/metabot.update [:use_verified_content :collection_id])]
- (t2/update! :model/Metabot metabot-id changes))
+ (t2/update! :model/Metabot :id metabot-id changes))
;;; --------------------------------------------- Metabot prompts ---------------------------------------------
@@ -101,12 +102,13 @@
[:card.name :model_name]
:created_at
:updated_at]
- (cond-> (prompts-for-metabot-query metabot-id card-type card-id)
- true (assoc :order-by (if sample?
- (prompt-sample-order-by)
- [[:card.name :asc] [:id :asc]]))
- limit (assoc :limit limit)
- offset (assoc :offset offset))))
+ (h2x/assert-map-or-nil!
+ (cond-> (prompts-for-metabot-query metabot-id card-type card-id)
+ true (assoc :order-by (if sample?
+ (prompt-sample-order-by)
+ [[:card.name :asc] [:id :asc]]))
+ limit (assoc :limit limit)
+ offset (assoc :offset offset)))))
(mu/defn prompt-count
"The number of MetabotPrompts of the Metabot with `metabot-id` whose Card is within scope, optionally restricted to
@@ -114,7 +116,7 @@
[metabot-id :- ms/PositiveInt
card-type :- [:maybe [:enum "metric" "model"]]
card-id :- [:maybe ::lib.schema.id/card]]
- (t2/count :model/MetabotPrompt (prompts-for-metabot-query metabot-id card-type card-id)))
+ (t2/count :model/MetabotPrompt (h2x/assert-map-or-nil! (prompts-for-metabot-query metabot-id card-type card-id))))
(mu/defn prompt-count-for-metabot
"The number of MetabotPrompts of the Metabot with `metabot-id`."
@@ -356,7 +358,7 @@
"Apply `changes` to the MetabotMessage with `message-id`."
[message-id :- ms/PositiveInt
changes :- ::metabot.schema/metabot-message.update]
- (t2/update! :model/MetabotMessage message-id changes))
+ (t2/update! :model/MetabotMessage :id message-id changes))
(mu/defn soft-delete-messages-where!
"Soft-delete the MetabotMessages matching `conditions` on behalf of `deleted-by-user-id`, returning the number of
@@ -373,8 +375,8 @@
(let [{:keys [id]} conditions
conditions (cond-> conditions
(coll? id) (assoc :id [:in id]))]
- (t2/update! :model/MetabotMessage conditions {:deleted_at [:now]
- :deleted_by_user_id deleted-by-user-id})))
+ (t2/update! :model/MetabotMessage (h2x/assert-map-or-nil! conditions) {:deleted_at [:now]
+ :deleted_by_user_id deleted-by-user-id})))
(mu/defn insert-used-tables!
"Insert the MetabotUsedTable `rows`."
@@ -425,7 +427,7 @@
"The `columns` of the Database with `database-id`."
[columns :- [:sequential :keyword]
database-id :- ::lib.schema.id/database]
- (t2/select-one columns database-id))
+ (t2/select-one columns :id database-id))
(mu/defn database-exists?
"Whether a Database with `database-id` exists."
@@ -807,8 +809,9 @@
given, caps the number of rows returned."
[metabot-id :- ms/PositiveInt
limit :- [:maybe ms/PositiveInt]]
- (t2/select :model/Card (-> (metabot-metrics-and-models-query metabot-id limit)
- (update :order-by (fnil conj []) [:report_card.id]))))
+ (t2/select :model/Card (h2x/assert-map-or-nil!
+ (-> (metabot-metrics-and-models-query metabot-id limit)
+ (update :order-by (fnil conj []) [:report_card.id])))))
(mu/defn card-entity-ids
"A map of Card ID to entity ID for `card-ids`."
@@ -886,8 +889,8 @@
[card-id :- ::lib.schema.id/card
conversation-id :- :string
chart-id :- :string]
- (t2/update! (t2/table-name :model/Card) card-id {:metabot_conversation_id conversation-id
- :metabot_chart_id chart-id}))
+ (t2/update! (t2/table-name :model/Card) :id card-id {:metabot_conversation_id conversation-id
+ :metabot_chart_id chart-id}))
;;; ----------------------------------------------- Collections -----------------------------------------------
diff --git a/src/metabase/model_persistence/db.clj b/src/metabase/model_persistence/db.clj
index 17569a498fa..d576965aa9f 100644
--- a/src/metabase/model_persistence/db.clj
+++ b/src/metabase/model_persistence/db.clj
@@ -68,7 +68,7 @@
;; card_id is set to null when the corresponding card is deleted
[:= :p.card_id nil]]}]
(tracing/with-span :tasks "task.persist.find-deletable" {:db/statement (tracing/best-effort-sanitize-sql hsql)}
- (t2/select :model/PersistedInfo hsql))))
+ (t2/select :model/PersistedInfo (h2x/assert-map-or-nil! hsql)))))
(mu/defn refreshable-persisted-infos
"The PersistedInfos of the Database with `database-id` in one of `states` whose Card is an unarchived
@@ -85,7 +85,7 @@
[:= :c.type "model"]]}]
(tracing/with-span :tasks "task.persist.find-refreshable" {:db/id database-id
:db/statement (tracing/best-effort-sanitize-sql hsql)}
- (t2/select :model/PersistedInfo hsql))))
+ (t2/select :model/PersistedInfo (h2x/assert-map-or-nil! hsql)))))
(mu/defn persisted-infos-by-ids
"The PersistedInfos with `ids`."
@@ -147,7 +147,7 @@
"Apply `changes` to the PersistedInfo with `id`, returning the number updated."
[id :- ms/PositiveInt
changes :- ::model-persistence.schema/persisted-info.update]
- (t2/update! :model/PersistedInfo id changes))
+ (t2/update! :model/PersistedInfo :id id changes))
(mu/defn begin-persisted-info-refresh!
"Mark the PersistedInfo with `id` as refreshing `definition` (with `query-hash`), starting now, returning the number
@@ -155,11 +155,11 @@
[id :- ms/PositiveInt
definition :- [:maybe ::model-persistence.schema/persisted-info.definition]
query-hash :- [:maybe :string]]
- (t2/update! :model/PersistedInfo id {:definition definition
- :query_hash query-hash
- :active false
- :refresh_end nil
- :state "refreshing"}))
+ (t2/update! :model/PersistedInfo :id id {:definition definition
+ :query_hash query-hash
+ :active false
+ :refresh_end nil
+ :state "refreshing"}))
(mu/defn end-persisted-info-refresh!
"Record the outcome of the refresh of the PersistedInfo with `id`: `state` (\"persisted\" or \"error\"), whether
@@ -168,9 +168,9 @@
active? :- :boolean
state :- [:enum "persisted" "error"]
error :- [:maybe :string]]
- (t2/update! :model/PersistedInfo id {:active active?
- :state state
- :error error}))
+ (t2/update! :model/PersistedInfo :id id {:active active?
+ :state state
+ :error error}))
(mu/defn deactivate-all-persisted-infos!
"Deactivate every PersistedInfo and move it to `state`, returning the number updated."
@@ -181,7 +181,7 @@
"Deactivate the PersistedInfo with `id` and move it to `state`, returning the number updated."
[id :- ms/PositiveInt
state :- :string]
- (t2/update! :model/PersistedInfo id {:active false, :state state, :state_change_at :%now}))
+ (t2/update! :model/PersistedInfo :id id {:active false, :state state, :state_change_at :%now}))
(mu/defn deactivate-persisted-infos-for-database!
"Deactivate the PersistedInfos of the Database with `database-id` and move them to `state`, returning the
@@ -201,7 +201,7 @@
(mu/defn reset-persisted-info-to-creating!
"Deactivate the PersistedInfo with `id` and move it back to creating, returning the number updated."
[id :- ms/PositiveInt]
- (t2/update! :model/PersistedInfo id {:active false, :state "creating", :state_change_at :%now}))
+ (t2/update! :model/PersistedInfo :id id {:active false, :state "creating", :state_change_at :%now}))
(mu/defn ready-deletable-persisted-infos!
"Move the deletable PersistedInfos of the Database with `database-id` to `state`, returning the number updated."
@@ -262,4 +262,4 @@
"Apply `changes` to the Database with `database-id`, returning the number updated."
[database-id :- ::lib.schema.id/database
changes :- (mut/select-keys ::warehouses.schema/database.update [:settings])]
- (t2/update! :model/Database database-id changes))
+ (t2/update! :model/Database :id database-id changes))
diff --git a/src/metabase/models/db.clj b/src/metabase/models/db.clj
index 3d2819c05e3..2f72527f049 100644
--- a/src/metabase/models/db.clj
+++ b/src/metabase/models/db.clj
@@ -174,7 +174,8 @@
"Apply `entity`'s `:row` (a column diff) to `entity`'s `:model` row with `id`, returning the number updated."
[id :- [:or :int :string]
entity :- ::model-row]
- (t2/update! (:model entity) id (:row entity)))
+ ;; `entity`'s model is any model, so match on its own primary key, which may not be `:id`.
+ (t2/update! (:model entity) :toucan/pk id (:row entity)))
(mu/defn insert-entity!
"Insert `entity`'s `:row` into `entity`'s `:model` and return the inserted instance."
@@ -195,7 +196,8 @@
"Delete the `model` row with `id`, returning the number deleted."
[model :- [:or :keyword symbol?]
id :- [:maybe [:or :int :string]]]
- (t2/delete! model id))
+ ;; `model` is any model, so match on its own primary key, which may not be `:id`.
+ (t2/delete! model :toucan/pk id))
(mu/defn delete-entities-with-ids!
"Delete the `model` rows whose `id-column` is one of `ids`, returning the number deleted."
diff --git a/src/metabase/native_query_snippets/db.clj b/src/metabase/native_query_snippets/db.clj
index 9314cfe94d8..6feb7d94f32 100644
--- a/src/metabase/native_query_snippets/db.clj
+++ b/src/metabase/native_query_snippets/db.clj
@@ -40,7 +40,7 @@
"Apply `changes` to the NativeQuerySnippet with `id`."
[id :- ::lib.schema.id/native-query-snippet
changes :- (mut/select-keys ::native-query-snippets.schema/native-query-snippet.update [:description :collection_id :archived :content :name])]
- (t2/update! :model/NativeQuerySnippet id changes))
+ (t2/update! :model/NativeQuerySnippet :id id changes))
(mu/defn snippet-id-by-name
"The id of the NativeQuerySnippet named `snippet-name`, or nil."
diff --git a/src/metabase/notification/db.clj b/src/metabase/notification/db.clj
index 21b20421063..8a6c311044a 100644
--- a/src/metabase/notification/db.clj
+++ b/src/metabase/notification/db.clj
@@ -209,12 +209,12 @@
(mu/defn deactivate-notification!
"Mark the Notification with `notification-id` inactive, returning the number updated."
[notification-id :- ms/PositiveInt]
- (t2/update! :model/Notification notification-id {:active false}))
+ (t2/update! :model/Notification :id notification-id {:active false}))
(mu/defn delete-notification!
"Delete the Notification with `notification-id`, returning the number deleted."
[notification-id :- ms/PositiveInt]
- (t2/delete! :model/Notification notification-id))
+ (t2/delete! :model/Notification :id notification-id))
(mu/defn delete-notifications!
"Delete the Notifications with `notification-ids`, returning the number deleted."
@@ -236,7 +236,7 @@
(mu/defn notification-card-exists?
"Whether a NotificationCard with `notification-card-id` exists."
[notification-card-id :- ::lib.schema.id/card]
- (t2/exists? :model/NotificationCard notification-card-id))
+ (t2/exists? :model/NotificationCard :id notification-card-id))
(mu/defn notification-card-card-id
"The `:card_id` of the NotificationCard with `notification-card-id`."
@@ -251,7 +251,7 @@
(mu/defn delete-notification-card!
"Delete the NotificationCard with `notification-card-id`, returning the number deleted."
[notification-card-id :- ::lib.schema.id/card]
- (t2/delete! :model/NotificationCard notification-card-id))
+ (t2/delete! :model/NotificationCard :id notification-card-id))
;;; --------------------------------------- NotificationSubscription ---------------------------------------
@@ -351,7 +351,7 @@
(mu/defn delete-recipient!
"Delete the NotificationRecipient with `recipient-id`, returning the number deleted."
[recipient-id :- ms/PositiveInt]
- (t2/delete! :model/NotificationRecipient recipient-id))
+ (t2/delete! :model/NotificationRecipient :id recipient-id))
(mu/defn delete-user-recipients-for-notification!
"Delete the NotificationRecipients for the User with `user-id` on the Notification with `notification-id`,
@@ -663,8 +663,9 @@
nil."
[notification-id :- ms/PositiveInt]
(t2/select-one :model/Notification
- (-> (admin-base-list-query {:skip-run-joins? true})
- (sql.helpers/where [:= :notification.id notification-id]))))
+ (h2x/assert-map-or-nil!
+ (-> (admin-base-list-query {:skip-run-joins? true})
+ (sql.helpers/where [:= :notification.id notification-id])))))
;;; ------------------------------------------- Other models -------------------------------------------
@@ -672,7 +673,7 @@
"The instance of `model` (a model keyword, or a `[model & columns]` vector) with `id`, or nil."
[model :- [:or :keyword [:sequential :keyword]]
id :- [:maybe ms/PositiveInt]]
- (t2/select-one model id))
+ (t2/select-one model :id id))
(mu/defn card
"The Card with `card-id`, or nil."
diff --git a/src/metabase/oauth_server/db.clj b/src/metabase/oauth_server/db.clj
index b7740eee7bf..6ad400a681e 100644
--- a/src/metabase/oauth_server/db.clj
+++ b/src/metabase/oauth_server/db.clj
@@ -113,7 +113,7 @@
"Apply `row` to the OAuthClient with primary key `id`, returning the number updated."
[id :- ms/PositiveInt
row :- ::oauth-server.schema/oauth-client.update]
- (t2/update! :model/OAuthClient id row))
+ (t2/update! :model/OAuthClient :id id row))
(mu/defn insert-authorization-code!
"Insert the OAuthAuthorizationCode `row`, returning the number inserted."
diff --git a/src/metabase/permissions/db.clj b/src/metabase/permissions/db.clj
index cf761ffa325..bf99951b41a 100644
--- a/src/metabase/permissions/db.clj
+++ b/src/metabase/permissions/db.clj
@@ -540,7 +540,7 @@
"Apply `changes` to the CollectionPermissionGraphRevision with `revision-id`."
[revision-id :- ms/PositiveInt
changes :- (mut/select-keys ::permissions.schema/collection-permission-graph-revision.update [:before :after])]
- (t2/update! :model/CollectionPermissionGraphRevision revision-id changes))
+ (t2/update! :model/CollectionPermissionGraphRevision :id revision-id changes))
;;; ----------------------------------------------- Collections -----------------------------------------------
@@ -706,7 +706,7 @@
"Apply `changes` to the User with `user-id`."
[user-id :- ::lib.schema.id/user
changes :- (mut/select-keys ::users.schema/user.update [:is_superuser :is_data_analyst])]
- (t2/update! :model/User user-id changes))
+ (t2/update! :model/User :id user-id changes))
(mu/defn update-users!
"Apply `changes` to the Users with `user-ids`."
diff --git a/src/metabase/permissions_rest/db.clj b/src/metabase/permissions_rest/db.clj
index f1ef3c4174c..c5faa7a6460 100644
--- a/src/metabase/permissions_rest/db.clj
+++ b/src/metabase/permissions_rest/db.clj
@@ -82,7 +82,7 @@
"Set the name of the PermissionsGroup with `id`, returning the number updated."
[id :- ms/PositiveInt
group-name :- :string]
- (t2/update! :model/PermissionsGroup id {:name group-name}))
+ (t2/update! :model/PermissionsGroup :id id {:name group-name}))
(mu/defn delete-permissions-group!
"Delete the PermissionsGroup with `id`, returning the number deleted."
@@ -119,7 +119,7 @@
"Set the group manager flag of the PermissionsGroupMembership with `id`, returning the number updated."
[id :- ms/PositiveInt
group-manager? :- :boolean]
- (t2/update! :model/PermissionsGroupMembership id {:is_group_manager group-manager?}))
+ (t2/update! :model/PermissionsGroupMembership :id id {:is_group_manager group-manager?}))
(mu/defn non-destination-database-ids
"The ids of the Databases that are not routing destinations, excluding `excluded-database-id` (nil for no
diff --git a/src/metabase/pulse/db.clj b/src/metabase/pulse/db.clj
index 2a3b4d5cd1a..a9962a86cb6 100644
--- a/src/metabase/pulse/db.clj
+++ b/src/metabase/pulse/db.clj
@@ -211,7 +211,7 @@
"Apply `changes` to the Pulse with `pulse-id`."
[pulse-id :- ::lib.schema.id/pulse
changes :- ::pulse.schema/pulse.update]
- (t2/update! :model/Pulse pulse-id changes))
+ (t2/update! :model/Pulse :id pulse-id changes))
(mu/defn update-pulses-for-dashboard!
"Apply `changes` to the Pulses of the Dashboard with `dashboard-id`, leaving `updated_at` untouched."
@@ -332,7 +332,7 @@
"Apply `changes` to the PulseChannel with `channel-id`."
[channel-id :- ms/PositiveInt
changes :- ::pulse.schema/pulse-channel.update]
- (t2/update! :model/PulseChannel channel-id changes))
+ (t2/update! :model/PulseChannel :id channel-id changes))
(mu/defn set-pulse-channels-enabled!
"Set the enabled flag of the PulseChannels of the Pulse with `pulse-id`."
diff --git a/src/metabase/queries/db.clj b/src/metabase/queries/db.clj
index 369e5ee0126..81adb9d8c5d 100644
--- a/src/metabase/queries/db.clj
+++ b/src/metabase/queries/db.clj
@@ -153,7 +153,7 @@
"Apply `changes` to the Card with `card-id`, returning the number updated."
[card-id :- ::lib.schema.id/card
changes :- ::queries.schema/card.update]
- (t2/update! :model/Card card-id changes))
+ (t2/update! :model/Card :id card-id changes))
;;; ------------------------------------------- Card statistics -------------------------------------------
@@ -293,7 +293,7 @@
"Apply `changes` to the Dashboard with `dashboard-id`, returning the number updated."
[dashboard-id :- ::lib.schema.id/dashboard
changes :- ::dashboards.schema/dashboard.update]
- (t2/update! :model/Dashboard dashboard-id changes))
+ (t2/update! :model/Dashboard :id dashboard-id changes))
(mu/defn dashcards-for-card
"The DashboardCards showing the Card with `card-id`."
diff --git a/src/metabase/queries_rest/db.clj b/src/metabase/queries_rest/db.clj
index 61981cf8aeb..2a1ece7bcff 100644
--- a/src/metabase/queries_rest/db.clj
+++ b/src/metabase/queries_rest/db.clj
@@ -141,7 +141,7 @@
"Apply `changes` to the Card with `card-id`."
[card-id :- ::lib.schema.id/card
changes :- (mut/select-keys ::queries.schema/card.update [:collection_position :collection_id :public_uuid :made_public_by_id])]
- (t2/update! :model/Card card-id changes))
+ (t2/update! :model/Card :id card-id changes))
(mu/defn actions-for-model
"The Actions of the model Card with `model-id`."
diff --git a/src/metabase/query_processor/db.clj b/src/metabase/query_processor/db.clj
index 352f28b7c92..35f4cf1a8f7 100644
--- a/src/metabase/query_processor/db.clj
+++ b/src/metabase/query_processor/db.clj
@@ -67,8 +67,8 @@
"Set the result metadata of the Card with `card-id` without touching `updated_at`."
[card-id :- ::lib.schema.id/card
result-metadata :- [:maybe ::lib.schema.metadata/card.result-metadata]]
- (t2/update! :model/Card card-id {:result_metadata result-metadata
- :updated_at :updated_at}))
+ (t2/update! :model/Card :id card-id {:result_metadata result-metadata
+ :updated_at :updated_at}))
(mu/defn update-cards-last-used-at!
"Move `last_used_at` of each Card in `card-id->timestamp` forward to its timestamp, without touching `updated_at`."
diff --git a/src/metabase/revisions/db.clj b/src/metabase/revisions/db.clj
index 925ede6fd42..d3e340e9c32 100644
--- a/src/metabase/revisions/db.clj
+++ b/src/metabase/revisions/db.clj
@@ -53,7 +53,7 @@
"Apply `entity`'s `:row` (a column diff) to `entity`'s `:model` row with `id`, returning the number updated."
[id :- ms/PositiveInt
entity :- RevisionedRow]
- (t2/update! (:model entity) id (:row entity)))
+ (t2/update! (:model entity) :id id (:row entity)))
(mu/defn parameter-card-ids
"The Card ids of the ParameterCards of the `parameterized-object-type` with `parameterized-object-id`."
diff --git a/src/metabase/sample_data/db.clj b/src/metabase/sample_data/db.clj
index 38e0bf5181d..34ee97ba284 100644
--- a/src/metabase/sample_data/db.clj
+++ b/src/metabase/sample_data/db.clj
@@ -48,7 +48,7 @@
"Apply `changes` to the Database with `database-id`, returning the number updated."
[database-id :- ::lib.schema.id/database
changes :- (mut/select-keys ::warehouses.schema/database.update [:engine :details :settings])]
- (t2/update! :model/Database database-id changes))
+ (t2/update! :model/Database :id database-id changes))
(mu/defn set-database-tables-schema!
"Set the `schema` of every Table of the Database with `database-id`, returning the number updated."
diff --git a/src/metabase/segments/db.clj b/src/metabase/segments/db.clj
index 2df37e708a8..b6519c333ea 100644
--- a/src/metabase/segments/db.clj
+++ b/src/metabase/segments/db.clj
@@ -42,7 +42,7 @@
"Apply `changes` to the Segment with `id`."
[id :- ::lib.schema.id/segment
changes :- (mut/select-keys ::segments.schema/segment.update [:description :caveats :points_of_interest :archived :definition :name :show_in_getting_started])]
- (t2/update! :model/Segment id changes))
+ (t2/update! :model/Segment :id id changes))
(mu/defn table
"The Table with `table-id`, or nil."
diff --git a/src/metabase/session/db.clj b/src/metabase/session/db.clj
index cb843c04571..a0a490e1407 100644
--- a/src/metabase/session/db.clj
+++ b/src/metabase/session/db.clj
@@ -143,7 +143,7 @@
"Set the `credentials` of the AuthIdentity with `auth-identity-id`."
[auth-identity-id :- ms/PositiveInt
credentials :- [:maybe ::auth-identity.schema/auth-identity.credentials]]
- (t2/update! :model/AuthIdentity auth-identity-id {:credentials credentials}))
+ (t2/update! :model/AuthIdentity :id auth-identity-id {:credentials credentials}))
(mu/defn auth-identity-provider
"The `:provider` of the AuthIdentity with `auth-identity-id`, or nil."
diff --git a/src/metabase/settings/db.clj b/src/metabase/settings/db.clj
index 9a3873a8d2a..7c4653102f8 100644
--- a/src/metabase/settings/db.clj
+++ b/src/metabase/settings/db.clj
@@ -63,4 +63,4 @@
"Store `settings-json` as the user-local settings of the User with `user-id`, returning the number updated."
[user-id :- ::lib.schema.id/user
settings-json :- :string]
- (t2/update! :model/User user-id {:settings settings-json}))
+ (t2/update! :model/User :id [:auto/param user-id] {:settings settings-json}))
diff --git a/src/metabase/sync/db.clj b/src/metabase/sync/db.clj
index 9225daf11a1..6c57dc5ebcd 100644
--- a/src/metabase/sync/db.clj
+++ b/src/metabase/sync/db.clj
@@ -88,7 +88,7 @@
"Apply `changes` to the Database with `database-id`, returning the number updated."
[database-id :- ::lib.schema.id/database
changes :- ::warehouses.schema/database.update]
- (t2/update! :model/Database database-id changes))
+ (t2/update! :model/Database :id database-id changes))
;;; ------------------------------------------------- Table -------------------------------------------------
@@ -237,7 +237,7 @@
"Apply `changes` to the Table with `table-id`, returning the number updated."
[table-id :- ::lib.schema.id/table
changes :- ::warehouse-schema.schema/table.update]
- (t2/update! :model/Table table-id changes))
+ (t2/update! :model/Table :id table-id changes))
(mu/defn update-tables!
"Apply `changes` to the Tables with `table-ids`, returning the number updated."
@@ -494,7 +494,7 @@
"Apply `changes` to the Field with `field-id`, returning the number updated."
[field-id :- ::lib.schema.id/field
changes :- ::warehouse-schema.schema/field.update]
- (t2/update! :model/Field field-id changes))
+ (t2/update! :model/Field :id field-id changes))
(mu/defn update-field-by-name!
"Apply `changes` to the Field named `field-name` of the Table with `table-id`, returning the number updated."
@@ -593,8 +593,8 @@
(t2/select-one [:model/Field :id :fk_target_field_id :has_field_values] :id fk-id
{:from [(warehouse-schema-overlay/field-query {:user-settings? false})]}))]
(if (and field (not= pk-id (:fk_target_field_id field)))
- (t2/update! :model/Field fk-id (cond-> {:fk_target_field_id pk-id :semantic_type :type/FK}
- (= :auto-list (:has_field_values field)) (assoc :has_field_values nil)))
+ (t2/update! :model/Field :id fk-id (cond-> {:fk_target_field_id pk-id :semantic_type :type/FK}
+ (= :auto-list (:has_field_values field)) (assoc :has_field_values nil)))
0)))
(defn- data-sensitivity-to-scan-clause
@@ -646,7 +646,7 @@
"Set the `data_sensitivity` of the Field with `field-id` to `data-sensitivity`, returning the number updated."
[field-id :- ::lib.schema.id/field
data-sensitivity :- [:or :keyword :string]]
- (t2/update! :model/Field field-id {:data_sensitivity data-sensitivity}))
+ (t2/update! :model/Field :id field-id {:data_sensitivity data-sensitivity}))
(def ^:private classifier-data-sensitivity-clause
"Honey SQL clause matching Fields whose non-null `data_sensitivity` has no value in the `FieldUserSettings` mirror,
diff --git a/src/metabase/task_history/db.clj b/src/metabase/task_history/db.clj
index 8f0ce3f8883..36d120820b8 100644
--- a/src/metabase/task_history/db.clj
+++ b/src/metabase/task_history/db.clj
@@ -95,14 +95,15 @@
limit :- [:maybe ms/PositiveInt]
offset :- [:maybe ms/IntGreaterThanOrEqualToZero]]
(t2/select :model/TaskRun
- (cond-> (merge (run-where filters) (runs-order-by sort-column sort-direction))
- limit (assoc :limit limit)
- offset (assoc :offset offset))))
+ (h2x/assert-map-or-nil!
+ (cond-> (merge (run-where filters) (runs-order-by sort-column sort-direction))
+ limit (assoc :limit limit)
+ offset (assoc :offset offset)))))
(mu/defn task-run-count
"The number of TaskRuns matching `filters` (see [[run-where]] for the supported keys)."
[filters :- RunFilters]
- (t2/count :model/TaskRun (or (run-where filters) {})))
+ (t2/count :model/TaskRun (h2x/assert-map-or-nil! (or (run-where filters) {}))))
(mu/defn task-run
"The TaskRun with `id`, or nil."
@@ -192,7 +193,7 @@
"Apply `changes` to the TaskHistory row with `id`."
[id :- ms/PositiveInt
changes :- ::task-history.schema/task-history.update]
- (t2/update! :model/TaskHistory id changes))
+ (t2/update! :model/TaskHistory :id id changes))
(mu/defn insert-task-history!
"Insert the TaskHistory `row` and return its id."
diff --git a/src/metabase/testing_api/db.clj b/src/metabase/testing_api/db.clj
index 0fb77ffefd9..28a3d43b292 100644
--- a/src/metabase/testing_api/db.clj
+++ b/src/metabase/testing_api/db.clj
@@ -95,7 +95,7 @@
"Set the `tenant_id` of the User with `user-id`."
[user-id :- ::lib.schema.id/user
tenant-id :- ms/PositiveInt]
- (t2/update! :model/User user-id {:tenant_id tenant-id}))
+ (t2/update! :model/User :id user-id {:tenant_id tenant-id}))
(mu/defn delete-ai-usage-logs-for-user-and-conversation!
"Delete the AiUsageLog rows of the User with `user-id` in the conversation `conversation-id`, returning the number
diff --git a/src/metabase/timeline/db.clj b/src/metabase/timeline/db.clj
index d82b30514c9..ad82e86da0e 100644
--- a/src/metabase/timeline/db.clj
+++ b/src/metabase/timeline/db.clj
@@ -51,7 +51,7 @@
"Apply `changes` to the Timeline with `id`, returning the number updated."
[id :- ms/PositiveInt
changes :- (mut/select-keys ::timeline.schema/timeline.update [:name :default :description :icon :collection_id :archived])]
- (t2/update! :model/Timeline id changes))
+ (t2/update! :model/Timeline :id id changes))
(mu/defn set-timeline-events-archived!
"Set the archived flag of the TimelineEvents of the Timeline with `timeline-id`, returning the number updated."
@@ -110,7 +110,7 @@
"Apply `changes` to the TimelineEvent with `id`, returning the number updated."
[id :- ms/PositiveInt
changes :- (mut/select-keys ::timeline.schema/timeline-event.update [:name :description :timestamp :time_matters :timezone :icon :timeline_id :archived])]
- (t2/update! :model/TimelineEvent id changes))
+ (t2/update! :model/TimelineEvent :id id changes))
(mu/defn delete-timeline-event!
"Delete the TimelineEvent with `id`, returning the number deleted."
diff --git a/src/metabase/transforms/db.clj b/src/metabase/transforms/db.clj
index 7f8192856f0..346830ad93a 100644
--- a/src/metabase/transforms/db.clj
+++ b/src/metabase/transforms/db.clj
@@ -83,12 +83,12 @@
"Apply `changes` to the Transform with `transform-id`."
[transform-id :- ::lib.schema.id/transform
changes :- ::transforms.schema/transform.update]
- (t2/update! :model/Transform transform-id changes))
+ (t2/update! :model/Transform :id transform-id changes))
(mu/defn delete-transform!
"Delete the Transform with `transform-id`."
[transform-id :- ::lib.schema.id/transform]
- (t2/delete! :model/Transform transform-id))
+ (t2/delete! :model/Transform :id transform-id))
;;; ---------------------------------------------- Transform tags ----------------------------------------------
@@ -471,7 +471,7 @@
[transform-ids :- [:maybe [:or
[:set ::lib.schema.id/transform]
[:sequential ::lib.schema.id/transform]]]]
- (t2/select :model/TransformRun (latest-run-start-times-query transform-ids)))
+ (t2/select :model/TransformRun (h2x/assert-map-or-nil! (latest-run-start-times-query transform-ids))))
(mu/defn insert-run!
"Insert `run` and return the new instance."
diff --git a/src/metabase/transforms_base/db.clj b/src/metabase/transforms_base/db.clj
index 3497b1dc174..666c89d7460 100644
--- a/src/metabase/transforms_base/db.clj
+++ b/src/metabase/transforms_base/db.clj
@@ -11,7 +11,7 @@
(mu/defn transform-source
"The source of the Transform with `transform-id`, or nil."
[transform-id :- ::lib.schema.id/transform]
- (t2/select-one-fn :source [:model/Transform :id :source] transform-id))
+ (t2/select-one-fn :source [:model/Transform :id :source] :id transform-id))
(mu/defn transforms-for-ordering
"The id, name, target, target Table id, source Database id, and table dependencies of every Transform
@@ -31,7 +31,7 @@
changes :- [:map {:closed true}
[:last_checkpoint_value {:optional true} [:maybe :string]]
[:target_table_id {:optional true} [:maybe ::lib.schema.id/table]]]]
- (t2/update! :model/Transform transform-id changes))
+ (t2/update! :model/Transform :id transform-id changes))
(mu/defn update-transform-run!
"Apply `changes` to the TransformRun with `run-id`."
@@ -40,7 +40,7 @@
[:checkpoint_filter_field_id {:optional true} [:maybe ::lib.schema.id/field]]
[:checkpoint_lo_value {:optional true} [:maybe :string]]
[:checkpoint_hi_value {:optional true} [:maybe :string]]]]
- (t2/update! :model/TransformRun run-id changes))
+ (t2/update! :model/TransformRun :id run-id changes))
(mu/defn database-exists?
"Whether a Database with `database-id` exists."
@@ -80,7 +80,7 @@
[:schema {:optional true} [:maybe :string]]
[:active {:optional true} [:maybe :boolean]]
[:transform_id {:optional true} [:maybe ::lib.schema.id/transform]]]]
- (t2/update! :model/Table table-id changes))
+ (t2/update! :model/Table :id table-id changes))
(mu/defn mark-table-index-failed!
"Mark the TableIndex named `index-name` of the Transform with `transform-id` failed with `error-message`."
diff --git a/src/metabase/transforms_rest/db.clj b/src/metabase/transforms_rest/db.clj
index be51fbb47f1..004ee29dcde 100644
--- a/src/metabase/transforms_rest/db.clj
+++ b/src/metabase/transforms_rest/db.clj
@@ -19,7 +19,7 @@
(mu/defn reset-checkpoint!
"Clear the stored checkpoint value of the Transform with `id`."
[id :- ::lib.schema.id/transform]
- (t2/update! :model/Transform id {:last_checkpoint_value nil}))
+ (t2/update! :model/Transform :id id {:last_checkpoint_value nil}))
;;; ---------------------------------------------------- Tags ------------------------------------------------------
@@ -42,7 +42,7 @@
"Set the name of the TransformTag with `tag-id`."
[tag-id :- ms/PositiveInt
name :- :string]
- (t2/update! :model/TransformTag tag-id {:name name}))
+ (t2/update! :model/TransformTag :id tag-id {:name name}))
(mu/defn delete-tag!
"Delete the TransformTag with `tag-id`."
@@ -86,7 +86,7 @@
"Apply `updates` to the TransformJob with `job-id`."
[job-id :- ms/PositiveInt
updates :- (mut/select-keys ::transforms.schema/transform-job.update [:name :description :schedule :ui_display_type])]
- (t2/update! :model/TransformJob job-id updates))
+ (t2/update! :model/TransformJob :id job-id updates))
(mu/defn delete-job!
"Delete the TransformJob with `job-id`."
diff --git a/src/metabase/upload/db.clj b/src/metabase/upload/db.clj
index 87070d268b9..f75c9546f32 100644
--- a/src/metabase/upload/db.clj
+++ b/src/metabase/upload/db.clj
@@ -39,9 +39,9 @@
[database-id :- ::lib.schema.id/database
schema-name :- [:maybe :string]
table-prefix :- [:maybe :string]]
- (t2/update! :model/Database database-id {:uploads_enabled true
- :uploads_schema_name schema-name
- :uploads_table_prefix table-prefix}))
+ (t2/update! :model/Database :id database-id {:uploads_enabled true
+ :uploads_schema_name schema-name
+ :uploads_table_prefix table-prefix}))
(mu/defn active-fields-for-table
"The active Fields of the Table with `table-id`."
@@ -72,21 +72,21 @@
[:in [:lower :name] (keys name->display-name)]]}))
:let [lower-name (u/lower-case-en name)]
:when (= display_name (humanization/name->human-readable-name lower-name))]
- (t2/update! :model/Field id {:display_name (name->display-name lower-name)}))))
+ (t2/update! :model/Field :id id {:display_name (name->display-name lower-name)}))))
(mu/defn mark-table-upload!
"Flag the Table with `table-id` as an authoritative, writable upload table."
[table-id :- ::lib.schema.id/table]
- (t2/update! :model/Table table-id {:is_upload true
- :data_authority :authoritative
- :data_source :upload
- :is_writable true}))
+ (t2/update! :model/Table :id table-id {:is_upload true
+ :data_authority :authoritative
+ :data_source :upload
+ :is_writable true}))
(mu/defn set-field-display-name!
"Set the display name of the Field with `field-id`."
[field-id :- ::lib.schema.id/field
display-name :- :string]
- (t2/update! :model/Field field-id {:display_name display-name}))
+ (t2/update! :model/Field :id field-id {:display_name display-name}))
(mu/defn unarchived-models-for-table
"The query-relevant columns of the unarchived model Cards of the Table with `table-id`."
@@ -108,7 +108,7 @@
"Set the result metadata of the Card with `card-id`."
[card-id :- ::lib.schema.id/card
result-metadata :- [:maybe ::queries.schema/card.result-metadata]]
- (t2/update! :model/Card card-id {:result_metadata result-metadata}))
+ (t2/update! :model/Card :id card-id {:result_metadata result-metadata}))
(mu/defn deactivate-table!
"Mark the Table with `table-id` inactive."
diff --git a/src/metabase/users/db.clj b/src/metabase/users/db.clj
index a3afa960b0c..e48a88f72f3 100644
--- a/src/metabase/users/db.clj
+++ b/src/metabase/users/db.clj
@@ -108,7 +108,7 @@
(mu/defn set-user-last-login-now!
"Set `last_login` of the User with `user-id` to now."
[user-id :- ::lib.schema.id/user]
- (t2/update! :model/User user-id {:last_login :%now}))
+ (t2/update! :model/User :id user-id {:last_login :%now}))
(mu/defn user-settings
"The `:settings` of the User with `user-id`, or nil."
diff --git a/src/metabase/users_rest/db.clj b/src/metabase/users_rest/db.clj
index a5970d10132..6985cc26d5e 100644
--- a/src/metabase/users_rest/db.clj
+++ b/src/metabase/users_rest/db.clj
@@ -9,6 +9,7 @@
[metabase.users.models.user :as user]
[metabase.users.schema :as users.schema]
[metabase.util :as u]
+ [metabase.util.honey-sql-2 :as h2x]
[metabase.util.malli :as mu]
[toucan2.core :as t2]))
@@ -23,19 +24,19 @@
"Set the name of the Collection with `collection-id`."
[collection-id :- ::lib.schema.id/collection
collection-name :- :string]
- (t2/update! :model/Collection collection-id {:name collection-name}))
+ (t2/update! :model/Collection :id collection-id {:name collection-name}))
(mu/defn users-with-columns
"The `columns` of the Users matching `filters` (see [[metabase.users.schema/user-filters]])."
[columns :- [:sequential :keyword]
filters :- ::users.schema/user-filters]
- (t2/select (into [:model/User] columns) (user/filter-clauses filters)))
+ (t2/select (into [:model/User] columns) (h2x/assert-map-or-nil! (user/filter-clauses filters))))
(mu/defn user-count
"The number of Users matching `filters` (see [[metabase.users.schema/user-filters]]), ignoring any `:sort`,
`:limit`, or `:offset` in `filters`."
[filters :- ::users.schema/user-filters]
- (t2/count :model/User (users/filter-clauses-without-paging (user/filter-clauses filters))))
+ (t2/count :model/User (h2x/assert-map-or-nil! (users/filter-clauses-without-paging (user/filter-clauses filters)))))
(mu/defn distinct-user-count
"The `:count` of distinct Users matching `filters` (see [[metabase.users.schema/user-filters]]), ignoring any
@@ -102,7 +103,7 @@
"Apply `changes` to the User with `user-id`."
[user-id :- ::lib.schema.id/user
changes :- ::users.schema/user.update]
- (t2/update! :model/User user-id changes))
+ (t2/update! :model/User :id user-id changes))
(mu/defn user
"The User with `user-id`, or nil."
diff --git a/src/metabase/util/honey_sql_2.clj b/src/metabase/util/honey_sql_2.clj
index fc36a71de11..452e6a159af 100644
--- a/src/metabase/util/honey_sql_2.clj
+++ b/src/metabase/util/honey_sql_2.clj
@@ -42,6 +42,16 @@
[s]
(like-pattern (u/lower-case-en s) #(str % "%")))
+(defn assert-map-or-nil!
+ "`honeysql`, a Honey SQL query or conditions map (or nil), to pass to a Toucan 2 call such as `t2/select` after the
+ model. Throws for anything else.
+
+ The `:metabase/t2-implicit-pk` linter accepts a call to this where it would otherwise ask for `:id`."
+ [honeysql]
+ (when-not (or (nil? honeysql) (map? honeysql))
+ (throw (ex-info "Expected a Honey SQL map" {:value honeysql})))
+ honeysql)
+
;;; `[:inline <clojure.lang.Ratio>] should emit something wrapped in parens. Because otherwise the result could be
;;; something unintended. e.g.
;;;
diff --git a/src/metabase/warehouse_schema/db.clj b/src/metabase/warehouse_schema/db.clj
index 9d4d3936933..f3519ab2619 100644
--- a/src/metabase/warehouse_schema/db.clj
+++ b/src/metabase/warehouse_schema/db.clj
@@ -119,7 +119,7 @@
"Apply `changes` to the ::warehouse-schema.schema/field with `field-id`, returning the number updated."
[field-id :- ::lib.schema.id/field
changes :- (mut/select-keys ::warehouse-schema.schema/field.update [:position])]
- (t2/update! :model/Field field-id changes))
+ (t2/update! :model/Field :id field-id changes))
(mu/defn clear-fk-targets-to-field!
"Clear the FK semantic type and target of every ::warehouse-schema.schema/field targeting the ::warehouse-schema.schema/field with `field-id`, returning the number
@@ -173,7 +173,7 @@
"Set the display name of the ::warehouse-schema.schema/field with `id`, returning the number updated."
[id :- ::lib.schema.id/field
display-name :- :string]
- (t2/update! :model/Field id {:display_name display-name}))
+ (t2/update! :model/Field :id id {:display_name display-name}))
;;; -------------------------------------------- FieldUserSettings --------------------------------------------
@@ -186,7 +186,7 @@
(mu/defn field-user-settings-exist?
"Whether the ::warehouse-schema.schema/field with `field-id` has a FieldUserSettings row."
[field-id :- ::lib.schema.id/field]
- (t2/exists? :model/FieldUserSettings field-id))
+ (t2/exists? :model/FieldUserSettings :field_id field-id))
(def ^:private field-user-settings-update-keys
"The columns an insert or update of a FieldUserSettings accepts."
@@ -227,7 +227,7 @@
"Apply `changes` to the FieldUserSettings of the ::warehouse-schema.schema/field with `field-id`, returning the number updated."
[field-id :- ::lib.schema.id/field
changes :- (mut/select-keys ::warehouse-schema.schema/field-user-settings.update field-user-settings-update-keys)]
- (t2/update! :model/FieldUserSettings field-id changes))
+ (t2/update! :model/FieldUserSettings :field_id field-id changes))
(mu/defn field-ids-with-user-settings :- [:set ::lib.schema.id/field]
"The ids, among `field-ids`, of the Fields that have a FieldUserSettings row."
@@ -271,7 +271,7 @@
(mu/defn table-user-settings-exist?
"Whether the ::warehouse-schema.schema/table with `table-id` has a TableUserSettings row."
[table-id :- ::lib.schema.id/table]
- (t2/exists? :model/TableUserSettings table-id))
+ (t2/exists? :model/TableUserSettings :table_id table-id))
(mu/defn table-ids-with-user-settings :- [:set ::lib.schema.id/table]
"The ids, among `table-ids`, of the Tables that already have a TableUserSettings row."
@@ -294,7 +294,7 @@
number updated."
[table-id :- ::lib.schema.id/table
changes :- (mut/select-keys ::warehouse-schema.schema/table-user-settings.update table-user-settings-update-keys)]
- (t2/update! :model/TableUserSettings table-id changes))
+ (t2/update! :model/TableUserSettings :table_id table-id changes))
(mu/defn delete-table-user-settings!
"Delete the TableUserSettings of the ::warehouse-schema.schema/table with `table-id`, returning the number deleted."
@@ -385,7 +385,7 @@
"Apply `changes` to the FieldValues with `field-values-id`, returning the number updated."
[field-values-id :- ms/PositiveInt
changes :- (mut/select-keys ::warehouse-schema.schema/field-values.update [:has_more_values :values :human_readable_values])]
- (t2/update! :model/FieldValues field-values-id changes))
+ (t2/update! :model/FieldValues :id field-values-id changes))
(mu/defn find-or-insert-full-field-values!
"The full FieldValues of the ::warehouse-schema.schema/field with `field-id`, inserting one with `has-more-values`, `values`, and no
@@ -401,7 +401,7 @@
(mu/defn touch-field-values!
"Stamp `last_used_at` on the FieldValues with `field-values-id`, returning the number updated."
[field-values-id :- ms/PositiveInt]
- (t2/update! :model/FieldValues field-values-id {:last_used_at :%now}))
+ (t2/update! :model/FieldValues :id field-values-id {:last_used_at :%now}))
(mu/defn delete-field-values!
"Delete the FieldValues with `field-values-ids`, returning the number deleted."
@@ -533,7 +533,7 @@
"Set the display name of the ::warehouse-schema.schema/table with `id`, returning the number updated."
[id :- ::lib.schema.id/table
display-name :- :string]
- (t2/update! :model/Table id {:display_name display-name}))
+ (t2/update! :model/Table :id id {:display_name display-name}))
;;; ------------------------------------------------ ::warehouses.schema/database ------------------------------------------------
diff --git a/src/metabase/warehouse_schema_rest/db.clj b/src/metabase/warehouse_schema_rest/db.clj
index c01ce648929..54ad7f7f778 100644
--- a/src/metabase/warehouse_schema_rest/db.clj
+++ b/src/metabase/warehouse_schema_rest/db.clj
@@ -52,7 +52,7 @@
"Apply `changes` to the Dimension with `id`."
[id :- ::lib.schema.id/dimension
changes :- (mut/select-keys ::warehouse-schema.schema/dimension.update [:type :name :human_readable_field_id])]
- (t2/update! :model/Dimension id changes))
+ (t2/update! :model/Dimension :id id changes))
(mu/defn rename-dimension-for-field!
"Set the name of the Dimension of the Field with `field-id`."
diff --git a/src/metabase/warehouses/db.clj b/src/metabase/warehouses/db.clj
index 3f07a45a7c7..ded820b7076 100644
--- a/src/metabase/warehouses/db.clj
+++ b/src/metabase/warehouses/db.clj
@@ -38,13 +38,13 @@
"Set the connection details of the Database with `database-id`, returning the number updated."
[database-id :- ::lib.schema.id/database
details :- ::warehouses.schema/database.details]
- (t2/update! :model/Database database-id {:details details}))
+ (t2/update! :model/Database :id database-id {:details details}))
(mu/defn set-database-provider-name!
"Set the provider name of the Database with `database-id`, returning the number updated."
[database-id :- ::lib.schema.id/database
provider-name :- :string]
- (t2/update! :model/Database database-id {:provider_name provider-name}))
+ (t2/update! :model/Database :id database-id {:provider_name provider-name}))
(mu/defn health-check-candidate-ids
"The `:id` of the lowest-id non-audit, non-sample, non-stub, non-destination Database of each engine."
diff --git a/src/metabase/warehouses_rest/db.clj b/src/metabase/warehouses_rest/db.clj
index 113cbfe02b4..52969f60d17 100644
--- a/src/metabase/warehouses_rest/db.clj
+++ b/src/metabase/warehouses_rest/db.clj
@@ -258,7 +258,7 @@
"Apply `changes` to the Database with `database-id`, returning the number updated."
[database-id :- ::lib.schema.id/database
changes :- ::warehouses.schema/database.update]
- (t2/update! :model/Database database-id changes))
+ (t2/update! :model/Database :id database-id changes))
(mu/defn delete-destination-databases!
"Delete the routing destination Databases of the Database with `router-database-id`, returning the number deleted."
diff --git a/test/metabase/actions/actions_test.clj b/test/metabase/actions/actions_test.clj
index d5c00ebc9e2..76f25de423b 100644
--- a/test/metabase/actions/actions_test.clj
+++ b/test/metabase/actions/actions_test.clj
@@ -610,7 +610,7 @@
(let [ssh-port (.getPort ssh-server)
table-id (mt/id :categories)]
(let [details (t2/select-one-fn :details 'Database :id (mt/id))]
- (t2/update! 'Database (mt/id)
+ (t2/update! 'Database :id (mt/id)
;; enable ssh tunnel
{:details (assoc details
:tunnel-enabled true
diff --git a/test/metabase/actions/models_test.clj b/test/metabase/actions/models_test.clj
index 0ebd867594b..eb755be2051 100644
--- a/test/metabase/actions/models_test.clj
+++ b/test/metabase/actions/models_test.clj
@@ -342,10 +342,10 @@
(mt/with-model-cleanup [:model/Action]
(let [of-table (action/insert! {:type :implicit :name "T" :kind :row/create :table_id table-id})
of-database (action/insert! {:type :implicit :name "U" :kind :row/create :table_id other-id})]
- (t2/delete! :model/Table table-id)
+ (t2/delete! :model/Table :id table-id)
(is (not (t2/exists? :model/Action :id of-table)))
(is (t2/exists? :model/Action :id of-database))
- (t2/delete! :model/Database db-id)
+ (t2/delete! :model/Database :id db-id)
(is (not (t2/exists? :model/Action :id of-database))))))))
(deftest model-less-implicit-action-fields-test
@@ -377,9 +377,9 @@
(is (= coll-id (t2/select-one-fn :collection_id :model/Action :id action-id))))
(testing "and can't be moved out of it"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"A model's action goes in the model's collection"
- (t2/update! :model/Action action-id {:collection_id other-id})))
+ (t2/update! :model/Action :id action-id {:collection_id other-id})))
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"A model's action goes in the model's collection"
- (t2/update! :model/Action action-id {:collection_id nil}))))
+ (t2/update! :model/Action :id action-id {:collection_id nil}))))
(testing "nor be inserted in another collection"
(mt/with-model-cleanup [:model/Action]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"A model's action goes in the model's collection"
@@ -390,7 +390,7 @@
:database_id (mt/id)
:dataset_query (lib/native-query (mt/metadata-provider) "select 1")})))))
(testing "moving the model moves its actions"
- (t2/update! :model/Card model-id {:collection_id other-id})
+ (t2/update! :model/Card :id model-id {:collection_id other-id})
(is (= other-id (t2/select-one-fn :collection_id :model/Action :id action-id))))))))
(deftest model-action-has-no-table-test
@@ -410,7 +410,7 @@
(mt/with-actions [_ {:type :model :dataset_query (table-query :categories)}
{:keys [action-id]} {:type :query}]
(binding [mi/*deserializing?* true]
- (t2/update! :model/Action action-id {:model_id other-id :collection_id other-coll}))
+ (t2/update! :model/Action :id action-id {:model_id other-id :collection_id other-coll}))
(is (= {:model_id other-id :collection_id other-coll}
(t2/select-one [:model/Action :model_id :collection_id] :id action-id)))))))
@@ -442,15 +442,15 @@
(mt/with-actions [{:keys [action-id model-id]} {:type :query}]
(mt/with-temp [:model/Dashboard {dashboard-id :id} {}
:model/DashboardCard {dashcard-id :id} {:action_id action-id :dashboard_id dashboard-id}]
- (is (false? (t2/select-one-fn :archived :model/Action action-id)))
- (t2/update! :model/Card model-id {:type :question})
+ (is (false? (t2/select-one-fn :archived :model/Action :id action-id)))
+ (t2/update! :model/Card :id model-id {:type :question})
(is (not (t2/exists? :model/Action :id action-id)))
(is (not (t2/exists? :model/DashboardCard :id dashcard-id))))))
(testing "Implicit actions are deleted if their model is converted to a saved question"
(mt/with-actions [{:keys [action-id model-id]} {:type :implicit}]
- (is (false? (t2/select-one-fn :archived :model/Action action-id)))
- (t2/update! :model/Card model-id {:type :question})
- (is (false? (t2/exists? :model/Action action-id))))))))
+ (is (false? (t2/select-one-fn :archived :model/Action :id action-id)))
+ (t2/update! :model/Card :id model-id {:type :question})
+ (is (false? (t2/exists? :model/Action :id action-id))))))))
(deftest model-to-saved-question-test-2
(mt/test-drivers (mt/normal-drivers-with-feature :actions/custom)
@@ -460,9 +460,9 @@
;; here to make sure we don't made that mistake again
(testing "Don't archive actions if updates a model dataset_query"
(mt/with-actions [{:keys [action-id model-id]} {}]
- (is (false? (t2/select-one-fn :archived :model/Action action-id)))
- (t2/update! :model/Card model-id {:dataset_query (mt/mbql-query users {:limit 1})})
- (is (false? (t2/select-one-fn :archived :model/Action action-id))))))))
+ (is (false? (t2/select-one-fn :archived :model/Action :id action-id)))
+ (t2/update! :model/Card :id model-id {:dataset_query (mt/mbql-query users {:limit 1})})
+ (is (false? (t2/select-one-fn :archived :model/Action :id action-id))))))))
(deftest exclude-auto-increment-fields-for-create-implicit-actions-test
(mt/test-drivers (mt/normal-drivers-with-feature :actions/custom)
diff --git a/test/metabase/activity_feed/models/recent_views_test.clj b/test/metabase/activity_feed/models/recent_views_test.clj
index 629bc96d60a..01c20e7029f 100644
--- a/test/metabase/activity_feed/models/recent_views_test.clj
+++ b/test/metabase/activity_feed/models/recent_views_test.clj
@@ -380,7 +380,7 @@
(recent-views/update-users-recent-views! (mt/user->id :rasta) :model/Dashboard dash-id-3 :view)
(is (= dash-id-3 (recent-views/most-recently-viewed-dashboard-id (mt/user->id :rasta))))
(testing "archived dashboards are not returned (#45223)"
- (t2/update! :model/Dashboard dash-id-3 {:archived true})
+ (t2/update! :model/Dashboard :id dash-id-3 {:archived true})
(is (= dash-id (recent-views/most-recently-viewed-dashboard-id (mt/user->id :rasta))))))))
(deftest id-pruning-test
diff --git a/test/metabase/agent_api/api_test.clj b/test/metabase/agent_api/api_test.clj
index 42baa210955..fd4a99a57ed 100644
--- a/test/metabase/agent_api/api_test.clj
+++ b/test/metabase/agent_api/api_test.clj
@@ -253,7 +253,7 @@
"Canonical name of the application database \u2014 the literal string the LLM is expected
to put as the first element of every portable FK in a representations query."
[]
- (t2/select-one-fn :name :model/Database (mt/id)))
+ (t2/select-one-fn :name :model/Database :id (mt/id)))
(defn- orders-query
"Build a portable MBQL 5 representations external-query map against the `ORDERS` table in
diff --git a/test/metabase/api_keys/api_test.clj b/test/metabase/api_keys/api_test.clj
index b5d3ffdb972..b671fdd0929 100644
--- a/test/metabase/api_keys/api_test.clj
+++ b/test/metabase/api_keys/api_test.clj
@@ -170,7 +170,7 @@
:post 200 "api-key"
{:group_id group-id-1
:name (str (random-uuid))})
- _ (assert (t2/exists? :model/ApiKey id))
+ _ (assert (t2/exists? :model/ApiKey :id id))
_ (is (= "Cool Friends" (-> create-resp :group :name)))
api-user-id (t2/select-one-fn :user_id :model/ApiKey :id id)
member-of-group? (fn [group-id]
@@ -183,7 +183,7 @@
(is (=? {:group {:id group-id-2, :name "Uncool Friends"}}
(mt/user-http-request :crowberto :put 200 (format "api-key/%s" id) {:group_id group-id-2})))
(is (= "Uncool Friends"
- (t2/select-one-fn :name :model/PermissionsGroup group-id-2)))
+ (t2/select-one-fn :name :model/PermissionsGroup :id group-id-2)))
(is (not (member-of-group? group-id-1)))
(is (member-of-group? group-id-2))))))
@@ -198,11 +198,11 @@
:name name-1})
api-user-id (-> (t2/select-one :model/ApiKey :id id) (t2/hydrate :user) :user :id)]
(testing "before the change..."
- (is (= name-1 (:common_name (t2/select-one :model/User api-user-id)))))
+ (is (= name-1 (:common_name (t2/select-one :model/User :id api-user-id)))))
(testing "after the change..."
(mt/user-http-request :crowberto :put 200 (str "api-key/" id)
{:name name-2})
- (is (= name-2 (:common_name (t2/select-one :model/User api-user-id)))))
+ (is (= name-2 (:common_name (t2/select-one :model/User :id api-user-id)))))
(testing "the shape of the response is correct"
(is (= #{:created_at :updated_at :updated_by :id :group :name :masked_key :last_used_at}
(set (keys (mt/user-http-request :crowberto :put 200 (str "api-key/" id)
@@ -304,7 +304,7 @@
(testing "Creation was audit logged"
(is (=? {:details {:name "My API Key"
:group {:name "Cool Friends"}
- :user_id (t2/select-one-fn :user_id :model/ApiKey id)}
+ :user_id (t2/select-one-fn :user_id :model/ApiKey :id id)}
:model "ApiKey"
:model_id id
:user_id (mt/user->id :crowberto)}
diff --git a/test/metabase/api_keys/models/api_key_test.clj b/test/metabase/api_keys/models/api_key_test.clj
index 27a4bfa2bfc..7dc87a4ff0d 100644
--- a/test/metabase/api_keys/models/api_key_test.clj
+++ b/test/metabase/api_keys/models/api_key_test.clj
@@ -12,5 +12,5 @@
:creator_id (mt/user->id :crowberto)
:updated_by_id (mt/user->id :crowberto)}]
(is (= 1
- (t2/delete! :model/ApiKey api-key-id)))
+ (t2/delete! :model/ApiKey :id api-key-id)))
(is (true? (t2/select-one-fn :is_active :model/User :id (mt/user->id :crowberto))))))
diff --git a/test/metabase/app_db/custom_migrations/metrics_v2_test.clj b/test/metabase/app_db/custom_migrations/metrics_v2_test.clj
index 59360a3389d..33637cd7f94 100644
--- a/test/metabase/app_db/custom_migrations/metrics_v2_test.clj
+++ b/test/metabase/app_db/custom_migrations/metrics_v2_test.clj
@@ -229,7 +229,7 @@
(let [migration-coll (t2/select-one :collection :name "Migrated Metrics v1")
coll-permissions (t2/select :permissions :object [:like (str "/collection/" (:id migration-coll) "/%")])
metric-cards (t2/select :report_card :collection_id (:id migration-coll))
- rewritten-card (t2/select-one :report_card card-id)
+ rewritten-card (t2/select-one :report_card :id card-id)
rewritten-query (-> rewritten-card :dataset_query normalized-query)]
(is (= 1 (count metric-cards)))
(is (int? card-id))
@@ -245,6 +245,6 @@
(testing "rollback"
(migrate! :down 50)
(let [migtation-coll (t2/select-one :collection :name "Migrated Metrics v1")
- reverted-card (t2/select-one :report_card card-id)]
+ reverted-card (t2/select-one :report_card :id card-id)]
(is (nil? migtation-coll))
(is (= original-query (:dataset_query reverted-card))))))))
diff --git a/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj b/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj
index 3ae1d88726b..c97119f0c0a 100644
--- a/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj
+++ b/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj
@@ -24,7 +24,7 @@
(defn migrate-alert!
[scheduler pulse-id]
- (->> (#'pulse-to-notification/alert->notification! scheduler (t2/select-one :pulse pulse-id))
+ (->> (#'pulse-to-notification/alert->notification! scheduler (t2/select-one :pulse :id pulse-id))
(map :id)
(map (partial t2/select-one :model/Notification))
(map models.notification/hydrate-notification)
@@ -76,7 +76,7 @@
(testing "has one subscription, one email handler with one recipient"
(let [alert-id (create-alert! {} card-id [{:channel_type "email"
:recipients [{:user_id (mt/user->id :rasta)}]}])
- alert (t2/select-one :model/Pulse alert-id)
+ alert (t2/select-one :model/Pulse :id alert-id)
alert-triggers (pulse-channel-test/send-pulse-triggers alert-id)
notification (first (migrate-alert! (task/scheduler) alert-id))]
(testing "sanity check that there is a trigger for the alert to begin with"
diff --git a/test/metabase/app_db/custom_migrations_test.clj b/test/metabase/app_db/custom_migrations_test.clj
index f3b4b687cbe..7036b5dc098 100644
--- a/test/metabase/app_db/custom_migrations_test.clj
+++ b/test/metabase/app_db/custom_migrations_test.clj
@@ -1117,28 +1117,28 @@
(testing "the options is merged into settings correctly"
(is (= {:persist-models-enabled true
:database-enable-actions true}
- (t2/select-one-fn :settings :model/Database success-id)))
+ (t2/select-one-fn :settings :model/Database :id success-id)))
(testing "even when settings is nil"
(is (= {:persist-models-enabled true}
- (t2/select-one-fn :settings :model/Database options-nil-settings-id))))
+ (t2/select-one-fn :settings :model/Database :id options-nil-settings-id))))
(testing "even when settings is empty"
(is (= {:persist-models-enabled true}
- (t2/select-one-fn :settings :model/Database options-empty-settings-id)))))
+ (t2/select-one-fn :settings :model/Database :id options-empty-settings-id)))))
(testing "nil or empty options doesn't break migration"
(is (= {:database-enable-actions true}
- (t2/select-one-fn :settings :model/Database nil-options-id)))
+ (t2/select-one-fn :settings :model/Database :id nil-options-id)))
(is (= {:database-enable-actions true}
- (t2/select-one-fn :settings :model/Database empty-options-id)))))
+ (t2/select-one-fn :settings :model/Database :id empty-options-id)))))
(testing "rollback migration"
(migrate! :down 46)
(testing "the persist-models-enabled is assoced back to options"
(is (= {:options "{\"persist-models-enabled\":true}"
:settings {:database-enable-actions true}}
- (t2/select-one [:model/Database :settings :options] success-id))))
+ (t2/select-one [:model/Database :settings :options] :id success-id))))
(testing "if settings doesn't have :persist-models-enabled, then options is empty map"
(is (= {:options nil
:settings {:database-enable-actions true}}
- (t2/select-one [:model/Database :settings :options] empty-options-id)))))))))]
+ (t2/select-one [:model/Database :settings :options] :id empty-options-id)))))))))]
(do-test false)
(encryption-test/with-secret-key "dont-tell-anyone-about-this"
(do-test true))))
@@ -1637,7 +1637,7 @@
session (t2/insert-returning-instance! :core_session {:user_id user-id
:id (str (random-uuid))
:created_at :%now})]
- (t2/update! :core_session (:id session) {:anti_csrf_token "normal"})
+ (t2/update! :core_session :id (:id session) {:anti_csrf_token "normal"})
(testing "created_at shouldn't change if there is an update"
(is (= (:created_at session)
(t2/select-one-fn :created_at :core_session :id (:id session))))))))))
@@ -1673,21 +1673,21 @@
:model_id (:id card-2)
:user_id user-id}))]
(testing "sanity check revision object"
- (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision card-revision-id)]
+ (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision :id card-revision-id)]
(testing "doesn't have type"
(is (not (contains? card-revision-object "type"))))
(testing "has dataset"
(is (contains? card-revision-object "dataset")))))
(testing "after migration card revisions should have type"
(migrate!)
- (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision card-revision-id)
- model-revision-object (t2/select-one-fn (comp json/decode :object) :revision model-revision-id)]
+ (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision :id card-revision-id)
+ model-revision-object (t2/select-one-fn (comp json/decode :object) :revision :id model-revision-id)]
(is (= "question" (get card-revision-object "type")))
(is (= "model" (get model-revision-object "type")))))
(testing "rollback should remove type and keep dataset"
(migrate! :down 48)
- (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision card-revision-id)
- model-revision-object (t2/select-one-fn (comp json/decode :object) :revision model-revision-id)]
+ (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision :id card-revision-id)
+ model-revision-object (t2/select-one-fn (comp json/decode :object) :revision :id model-revision-id)]
(is (contains? card-revision-object "dataset"))
(is (contains? model-revision-object "dataset"))
(is (not (contains? card-revision-object "type")))
@@ -1708,12 +1708,12 @@
:model_id (:id card)
:user_id user-id}))]
(testing "sanity check revision object"
- (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision card-revision-id)]
+ (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision :id card-revision-id)]
(testing "doesn't have type"
(is (not (contains? card-revision-object "type"))))))
(testing "after migration card revisions should have type"
(migrate!)
- (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision card-revision-id)]
+ (let [card-revision-object (t2/select-one-fn (comp json/decode :object) :revision :id card-revision-id)]
(is (= "question" (get card-revision-object "type")))
(testing "original visualization_settings should be preserved"
(is (= viz-settings
@@ -2716,8 +2716,8 @@
(migrate!)
(is (= {"_@foo" "bar"}
(json/decode (:attribute_remappings (t2/select-one :sandboxes :id sandbox-id)))))
- (is (= "_@foo" (:attribute (t2/select-one :connection_impersonations impersonation-id))))
- (is (= "_@foo" (:user_attribute (t2/select-one :db_router db-router-id))))
+ (is (= "_@foo" (:attribute (t2/select-one :connection_impersonations :id impersonation-id))))
+ (is (= "_@foo" (:user_attribute (t2/select-one :db_router :id db-router-id))))
(is (= {"_@foo" "bar"}
(json/decode (t2/select-one-fn :login_attributes :core_user :id user-id))))
(is (= {"_@foo" "bang"}
diff --git a/test/metabase/app_db/internal_user_test.clj b/test/metabase/app_db/internal_user_test.clj
index 63f940f983a..4242943f14d 100644
--- a/test/metabase/app_db/internal_user_test.clj
+++ b/test/metabase/app_db/internal_user_test.clj
@@ -9,7 +9,7 @@
(deftest internal-user-is-in-all-users-test
(testing "The internal user should be in the All Users group, just like any other user."
- (let [memberships (-> (t2/select-one :model/User config/internal-mb-user-id)
+ (let [memberships (-> (t2/select-one :model/User :id config/internal-mb-user-id)
(t2/hydrate :user_group_memberships)
:user_group_memberships
(->> (map :id)))
@@ -20,7 +20,7 @@
(testing "GET /api/user"
;; since the Internal user is inactive, we only need to check in the `:include_deactivated` `true`
(let [{:keys [data total]} (mt/user-http-request :crowberto :get 200 "user", :include_deactivated true)
- internal-user-email (t2/select-one-fn :email :model/User config/internal-mb-user-id)]
+ internal-user-email (t2/select-one-fn :email :model/User :id config/internal-mb-user-id)]
(testing "does not return the internal user"
(is (not-any? (comp #{internal-user-email} :email) data)))
(testing "does not count the internal user"
diff --git a/test/metabase/app_db/params_test.clj b/test/metabase/app_db/params_test.clj
index 2dce541fca6..66ac2e9ef31 100644
--- a/test/metabase/app_db/params_test.clj
+++ b/test/metabase/app_db/params_test.clj
@@ -25,7 +25,7 @@
(deftest marker-binds-on-the-write-path-test
(testing "a marked value is bound in an update"
(mt/with-temp [:model/ContentTranslation {id :id} {:locale "de" :msgid "a" :msgstr "b"}]
- (t2/update! :model/ContentTranslation id {:msgstr [:auto/param "updated"]})
+ (t2/update! :model/ContentTranslation :id id {:msgstr [:auto/param "updated"]})
(is (= "updated" (:msgstr (t2/select-one :model/ContentTranslation :id id))))))
(testing "and in an insert"
(mt/with-temp [:model/ContentTranslation _ {:locale "de" :msgid "a" :msgstr "b"}]
diff --git a/test/metabase/app_db/schema_migrations_test.clj b/test/metabase/app_db/schema_migrations_test.clj
index 480bfdeb6a4..ddd5c7566c3 100644
--- a/test/metabase/app_db/schema_migrations_test.clj
+++ b/test/metabase/app_db/schema_migrations_test.clj
@@ -1166,7 +1166,7 @@
(migrate!)
(testing "After the migration, fields are deactivated correctly"
(doseq [[active? field] active+field]
- (is (= active? (t2/select-one-fn :active :metabase_field (:id field))))))))))
+ (is (= active? (t2/select-one-fn :active :metabase_field :id (:id field))))))))))
(deftest ^:mb/old-migrations-test populate-new-permission-fields-works
(testing "Migration v49.2024-08-21T08:33:10"
@@ -2483,9 +2483,9 @@
:model_id dash-id
:timestamp :%now}))]
(migrate!)
- (is (= 1 (t2/select-one-fn :view_count :metabase_table table-id)))
- (is (= 1 (t2/select-one-fn :view_count :report_card card-id)))
- (is (= 2 (t2/select-one-fn :view_count :report_dashboard dash-id)))))))
+ (is (= 1 (t2/select-one-fn :view_count :metabase_table :id table-id)))
+ (is (= 1 (t2/select-one-fn :view_count :report_card :id card-id)))
+ (is (= 2 (t2/select-one-fn :view_count :report_dashboard :id dash-id)))))))
(deftest ^:mb/old-migrations-test trash-migrations-test
(impl/test-migrations ["v50.2024-05-29T14:04:47" "v50.2024-05-29T18:42:15"] [migrate!]
@@ -2710,7 +2710,7 @@
(testing "Site locale is migrated from zh to zh_CN"
(impl/test-migrations "v54.2025-03-17T18:52:59" [migrate!]
(let [user-id (:id (create-raw-user! (mt/random-email)))]
- (t2/update! (t2/table-name :model/User) user-id {:locale "zh"})
+ (t2/update! (t2/table-name :model/User) :id user-id {:locale "zh"})
(migrate!)
(is (= "zh_CN" (t2/select-one-fn :locale (t2/table-name :model/User) :id user-id)))))))
@@ -3460,7 +3460,7 @@
(testing "an existing field reads NULL"
(is (nil? (t2/select-one-fn :data_sensitivity :metabase_field :id field-id))))
(testing "a value writes and reads back on metabase_field"
- (t2/update! :metabase_field field-id {:data_sensitivity "PII"})
+ (t2/update! :metabase_field :id field-id {:data_sensitivity "PII"})
(is (= "PII" (t2/select-one-fn :data_sensitivity :metabase_field :id field-id))))
(testing "a value writes and reads back on the user-settings mirror"
(t2/insert! :metabase_field_user_settings {:field_id field-id :data_sensitivity "SYS_TELEMETRY"})
@@ -3928,7 +3928,7 @@
event-date #(t2/select-one-fn :timestamp :timeline_event :id event-id)
before (event-date)]
(migrate!)
- (t2/update! :timeline_event event-id {:archived true})
+ (t2/update! :timeline_event :id event-id {:archived true})
(is (= before (event-date)))))))
(deftest add-library-dashboards-section-test
@@ -4008,7 +4008,7 @@
(is (false? (:finished (message aborted))))
(is (nil? (:finished (message in-flight)))))
(testing "the column stores a reason"
- (t2/update! :metabot_message completed {:finish_reason "content-filter"})
+ (t2/update! :metabot_message :id completed {:finish_reason "content-filter"})
(is (= "content-filter" (:finish_reason (message completed)))))
(testing "rolling back drops the column and keeps the rows"
(migrate! :down 64)
@@ -4046,7 +4046,7 @@
(is (contains? (message) :context_window_full))
(is (nil? (:context_window_full (message)))))
(testing "the column stores the verdict"
- (t2/update! :metabot_message message-id {:context_window_full true})
+ (t2/update! :metabot_message :id message-id {:context_window_full true})
(is (true? (:context_window_full (message)))))
(testing "rolling back drops the column and keeps the row"
(migrate! :down 64)
diff --git a/test/metabase/audit_app/events/audit_log_test.clj b/test/metabase/audit_app/events/audit_log_test.clj
index 77586c1b6f4..6d668134fed 100644
--- a/test/metabase/audit_app/events/audit_log_test.clj
+++ b/test/metabase/audit_app/events/audit_log_test.clj
@@ -711,8 +711,8 @@
:started_at (t/offset-date-time 2025 9 30 14 0 0)
:ended_at (t/offset-date-time 2025 9 30 14 0 0)}]
(testing "event published with re-fetched task after version is set"
- (t2/update! :model/RemoteSyncTask task-id {:version "abc123"})
- (let [completed-task (t2/select-one :model/RemoteSyncTask task-id)]
+ (t2/update! :model/RemoteSyncTask :id task-id {:version "abc123"})
+ (let [completed-task (t2/select-one :model/RemoteSyncTask :id task-id)]
(events/publish-event! :event/remote-sync-import
{:object completed-task
:details {:branch "main"}
diff --git a/test/metabase/auth_identity/core_test.clj b/test/metabase/auth_identity/core_test.clj
index 8fed05da343..123b1d70339 100644
--- a/test/metabase/auth_identity/core_test.clj
+++ b/test/metabase/auth_identity/core_test.clj
@@ -28,7 +28,7 @@
(:metadata auth-identity))))))
(testing "can update an AuthIdentity"
(let [auth-identity (t2/select-one :model/AuthIdentity :user_id (:id user) :provider "password")]
- (t2/update! :model/AuthIdentity (:id auth-identity)
+ (t2/update! :model/AuthIdentity :id (:id auth-identity)
{:credentials {:password_hash "new_hash"
:password_salt "new_salt"}})
(let [updated (t2/select-one :model/AuthIdentity :id (:id auth-identity))]
diff --git a/test/metabase/auth_identity/models/auth_identity_test.clj b/test/metabase/auth_identity/models/auth_identity_test.clj
index 9b0fefc32ac..ad0253074bf 100644
--- a/test/metabase/auth_identity/models/auth_identity_test.clj
+++ b/test/metabase/auth_identity/models/auth_identity_test.clj
@@ -49,7 +49,7 @@
(let [auth-identity (t2/select-one :model/AuthIdentity :user_id user-id :provider "password")
auth-identity-id (:id auth-identity)
new-password "new-password-456"]
- (t2/update! :model/AuthIdentity auth-identity-id
+ (t2/update! :model/AuthIdentity :id auth-identity-id
{:credentials {:plaintext_password new-password}})
(let [updated (t2/select-one :model/AuthIdentity :id auth-identity-id)
{:keys [password_hash password_salt]} (:credentials updated)]
@@ -70,7 +70,7 @@
auth-identity-id (:id auth-identity)
original-hash (get-in auth-identity [:credentials :password_hash])
original-salt (get-in auth-identity [:credentials :password_salt])]
- (t2/update! :model/AuthIdentity auth-identity-id
+ (t2/update! :model/AuthIdentity :id auth-identity-id
{:metadata {:last_login "2024-01-01"}})
(let [updated (t2/select-one :model/AuthIdentity :id auth-identity-id)]
(is (= original-hash (get-in updated [:credentials :password_hash]))
@@ -98,7 +98,7 @@
:provider "google"
:metadata {:email "[email protected]"}})
auth-identity-id (:id auth-identity)]
- (t2/update! :model/AuthIdentity auth-identity-id
+ (t2/update! :model/AuthIdentity :id auth-identity-id
{:metadata {:email "[email protected]"}})
(let [updated (t2/select-one :model/AuthIdentity :id auth-identity-id)]
(is (= "[email protected]" (get-in updated [:metadata :email]))
diff --git a/test/metabase/auth_identity/session_test.clj b/test/metabase/auth_identity/session_test.clj
index b23c2583fb9..746b4112734 100644
--- a/test/metabase/auth_identity/session_test.clj
+++ b/test/metabase/auth_identity/session_test.clj
@@ -176,7 +176,7 @@
(auth-identity/set-password! (:id user) "test-password")
(let [expires-at (t/plus (t/offset-date-time) (t/days 7))
password-auth (t2/select-one :model/AuthIdentity :user_id (:id user) :provider "password")]
- (t2/update! :model/AuthIdentity (:id password-auth) {:expires_at expires-at})
+ (t2/update! :model/AuthIdentity :id (:id password-auth) {:expires_at expires-at})
(let [device-info {:device_id "test-device-expires"
:embedded false
:token_exchange false
diff --git a/test/metabase/bookmarks/api_test.clj b/test/metabase/bookmarks/api_test.clj
index 9bfb6abfe4e..5c98634461f 100644
--- a/test/metabase/bookmarks/api_test.clj
+++ b/test/metabase/bookmarks/api_test.clj
@@ -154,10 +154,10 @@
(bookmarked-items :rasta)))
(testing "moving each item into an unreadable collection (admin action; nothing archived) hides its bookmark"
;; stand in for the admin PUT /api/card|document ... {:collection_id hidden} in the attack
- (t2/update! :model/Card card-id {:collection_id hidden-id})
- (t2/update! :model/Dashboard dash-id {:collection_id hidden-id})
- (t2/update! :model/Document doc-id {:collection_id hidden-id})
- (t2/update! :model/Exploration expl-id {:collection_id hidden-id})
+ (t2/update! :model/Card :id card-id {:collection_id hidden-id})
+ (t2/update! :model/Dashboard :id dash-id {:collection_id hidden-id})
+ (t2/update! :model/Document :id doc-id {:collection_id hidden-id})
+ (t2/update! :model/Exploration :id expl-id {:collection_id hidden-id})
(is (= #{} (bookmarked-items :rasta))))))))
(deftest bookmark-card-type-tracks-current-card-type-test
@@ -165,7 +165,7 @@
(mt/with-temp [:model/Card {card-id :id} {:name "My Card"}]
(mt/user-http-request :rasta :post 200 (str "bookmark/card/" card-id))
(is (= "question" (:card_type (first (mt/user-http-request :rasta :get 200 "bookmark")))))
- (t2/update! :model/Card card-id {:type :model})
+ (t2/update! :model/Card :id card-id {:type :model})
(is (= "model" (:card_type (first (mt/user-http-request :rasta :get 200 "bookmark"))))))))
(defn bookmark-models [user-id & models]
diff --git a/test/metabase/channel/email/messages_test.clj b/test/metabase/channel/email/messages_test.clj
index 81b980427b7..b031b9d968e 100644
--- a/test/metabase/channel/email/messages_test.clj
+++ b/test/metabase/channel/email/messages_test.clj
@@ -130,7 +130,7 @@
:updated_by_id (mt/user->id :crowberto)}]
;; `mt/with-temp` creates Users with `last_login = nil`, which the recipient filter treats as
;; "invited but not accepted." Mark one as having logged in to represent an accepted admin.
- (t2/update! :model/User (:id accepted-admin) {:last_login :%now})
+ (t2/update! :model/User :id (:id accepted-admin) {:last_login :%now})
(let [emails (set (#'messages/all-admin-recipients))]
(testing "includes admins who have accepted their invitation"
(is (contains? emails "[email protected]")))
diff --git a/test/metabase/channel/impl/http_test.clj b/test/metabase/channel/impl/http_test.clj
index 7616ebdd4a6..638e12d49b5 100644
--- a/test/metabase/channel/impl/http_test.clj
+++ b/test/metabase/channel/impl/http_test.clj
@@ -397,11 +397,11 @@
[notification {:card {:dataset_query (mt/mbql-query checkins {:aggregation [:count]})}
:handlers [{:channel_type :channel/http
:channel_id chn-id}]}]
- (notification/send-notification! (t2/select-one :model/Notification (:id notification)) :notification/sync? true)
+ (notification/send-notification! (t2/select-one :model/Notification :id (:id notification)) :notification/sync? true)
(is (=? {:body {:type "alert"
:alert_id (-> notification :payload :id)
:alert_creator_id (mt/malli=? int?)
- :alert_creator_name (t2/select-one-fn :common_name :model/User (:creator_id notification))
+ :alert_creator_name (t2/select-one-fn :common_name :model/User :id (:creator_id notification))
:data {:type "question"
:question_id (-> notification :payload :card_id)
:question_name (-> notification :payload :card :name)
diff --git a/test/metabase/channel/models/channel_test.clj b/test/metabase/channel/models/channel_test.clj
index 936362bdb49..328c0baf94d 100644
--- a/test/metabase/channel/models/channel_test.clj
+++ b/test/metabase/channel/models/channel_test.clj
@@ -17,7 +17,7 @@
(encryption-test/with-secret-key "secret"
(mt/with-model-cleanup [:model/Channel]
(let [channel (t2/insert-returning-instance! :model/Channel notification.tu/default-can-connect-channel)]
- (is (encryption/possibly-encrypted-string? (t2/select-one-fn :details :channel (:id channel)))))))))
+ (is (encryption/possibly-encrypted-string? (t2/select-one-fn :details :channel :id (:id channel)))))))))
(deftest channel-details-json-encoding-test
(testing "JSON-encoding a Channel includes :details only for callers who can write it"
@@ -48,15 +48,15 @@
:channel_type "metabase-test"
:enabled true}]
(testing "do not try to delete pulse-channel if active doesn't change"
- (is (pos? (t2/update! :model/Channel id {:name "New name"})))
- (is (zero? (t2/update! :model/Channel id {:active true})))
- (is (t2/exists? :model/PulseChannel pc-id)))
+ (is (pos? (t2/update! :model/Channel :id id {:name "New name"})))
+ (is (zero? (t2/update! :model/Channel :id id {:active true})))
+ (is (t2/exists? :model/PulseChannel :id pc-id)))
(testing "deactivate channel"
- (t2/update! :model/Channel id {:active false})
+ (t2/update! :model/Channel :id id {:active false})
(testing "will delete pulse channels"
- (is (not (t2/exists? :model/PulseChannel pc-id))))
+ (is (not (t2/exists? :model/PulseChannel :id pc-id))))
(testing "will change the name"
- (is (= (format "DEACTIVATED_%d New name" id) (t2/select-one-fn :name :model/Channel id)))))))
+ (is (= (format "DEACTIVATED_%d New name" id) (t2/select-one-fn :name :model/Channel :id id)))))))
(deftest channel-template-email-details-test
(mt/with-model-cleanup [:model/ChannelTemplate]
@@ -113,9 +113,9 @@
:details {:type :email/handlebars-text
:subject "Hello"
:body "Original body"}}]
- (t2/update! :model/ChannelTemplate id {:details {:type :email/handlebars-text
- :subject "Hello"
- :body "Updated body"}})
+ (t2/update! :model/ChannelTemplate :id id {:details {:type :email/handlebars-text
+ :subject "Hello"
+ :body "Updated body"}})
(is (= 1.0 (mt/metric-value system :metabase-notification/template-update
{:channel-type :channel/email})))))))
diff --git a/test/metabase/channel/rest/api/channel_test.clj b/test/metabase/channel/rest/api/channel_test.clj
index 50b4dadef50..7356cb1fec7 100644
--- a/test/metabase/channel/rest/api/channel_test.clj
+++ b/test/metabase/channel/rest/api/channel_test.clj
@@ -28,22 +28,22 @@
(testing "can update channel name"
(mt/user-http-request :crowberto :put 200 (str "channel/" (:id channel))
{:name "New Name"})
- (is (= "New Name" (t2/select-one-fn :name :model/Channel (:id channel)))))
+ (is (= "New Name" (t2/select-one-fn :name :model/Channel :id (:id channel)))))
(testing "can update channel details even if it fails to connect"
(mt/user-http-request :crowberto :put 200 (str "channel/" (:id channel))
{:details {:return-type "return-value"
:return-value false}})
(is (= {:return-type "return-value"
:return-value false}
- (t2/select-one-fn :details :model/Channel (:id channel)))))
+ (t2/select-one-fn :details :model/Channel :id (:id channel)))))
(testing "can update channel description"
(mt/user-http-request :crowberto :put 200 (str "channel/" (:id channel))
{:description "New description"})
- (is (= "New description" (t2/select-one-fn :description :model/Channel (:id channel)))))
+ (is (= "New description" (t2/select-one-fn :description :model/Channel :id (:id channel)))))
(testing "can disable a channel"
(mt/user-http-request :crowberto :put 200 (str "channel/" (:id channel))
{:active false})
- (is (= false (t2/select-one-fn :active :model/Channel (:id channel))))))))
+ (is (= false (t2/select-one-fn :active :model/Channel :id (:id channel))))))))
(deftest create-channel-with-existing-name-error-test
(mt/with-temp [:model/Channel _chn default-test-channel]
diff --git a/test/metabase/cmd/dump_to_h2_test.clj b/test/metabase/cmd/dump_to_h2_test.clj
index bc460106e19..5177bae4d72 100644
--- a/test/metabase/cmd/dump_to_h2_test.clj
+++ b/test/metabase/cmd/dump_to_h2_test.clj
@@ -86,7 +86,7 @@
;; the update and dump below trigger
(mdb.encryption/encrypt-db driver/*driver* (:data-source mdb.connection/*application-db*) nil)
(t2/insert! :model/Setting {:key "dump-to-h2-test-setting", :value "baz"})
- (t2/update! :model/Database 1 {:details {:db "/tmp/test.db"}})
+ (t2/update! :model/Database :id 1 {:details {:db "/tmp/test.db"}})
(dump-to-h2/dump-to-h2! h2-file-plaintext {:dump-plaintext? true})
(dump-to-h2/dump-to-h2! h2-file-enc {:dump-plaintext? false})
(dump-to-h2/dump-to-h2! h2-file-default-enc)))
diff --git a/test/metabase/cmd/rotate_encryption_key_test.clj b/test/metabase/cmd/rotate_encryption_key_test.clj
index 31b58c385a3..02ed3f6883b 100644
--- a/test/metabase/cmd/rotate_encryption_key_test.clj
+++ b/test/metabase/cmd/rotate_encryption_key_test.clj
@@ -111,10 +111,10 @@
(encryption-test/with-secret-key k1
(t2/insert! :model/Setting {:key "rotate-test-encrypted-setting", :value "encrypted with k1"})
(mdb.encryption/encrypt-db driver/*driver* data-source nil)
- (t2/update! :model/Database 1 {:details {:db "/tmp/test.db"}})
+ (t2/update! :model/Database :id 1 {:details {:db "/tmp/test.db"}})
;; other encrypted-json columns that must also be re-encrypted on rotation
- (t2/update! :model/Database 1 {:settings {:database-enable-actions true}})
- (t2/update! :model/User @user-id {:settings {:locale "en"}})
+ (t2/update! :model/Database :id 1 {:settings {:database-enable-actions true}})
+ (t2/update! :model/User :id @user-id {:settings {:locale "en"}})
(let [secret (first (t2/insert-returning-instances! :model/Secret {:name "My Secret (encrypted)"
:kind "password"
:value (.getBytes secret-val StandardCharsets/UTF_8)
@@ -172,7 +172,7 @@
(is (thrown? clojure.lang.ExceptionInfo (t2/select-one-fn :details :model/Database :name "k2")))
(is (= {:db "/tmp/k3.db"} (t2/select-one-fn :details :model/Database :name "k3")))))
(testing "rotate-encryption-key! to nil decrypts the encrypted keys"
- (t2/update! :model/Database 1 {:details {:db "/tmp/test.db"}})
+ (t2/update! :model/Database :id 1 {:details {:db "/tmp/test.db"}})
(t2/update! :model/Database {:name "k3"} {:details {:db "/tmp/test.db"}})
(encryption-test/with-secret-key k2 ; with the last key that we rotated to in the test
(rotate-encryption-key! nil))
diff --git a/test/metabase/collections/models/collection_test.clj b/test/metabase/collections/models/collection_test.clj
index 6cda6bc279d..af5f8105199 100644
--- a/test/metabase/collections/models/collection_test.clj
+++ b/test/metabase/collections/models/collection_test.clj
@@ -250,7 +250,7 @@
(mt/with-temp [:model/Collection collection]
(is (thrown?
Exception
- (t2/update! :model/Collection (u/the-id collection)
+ (t2/update! :model/Collection :id (u/the-id collection)
{:name ""}))))))
;;; +----------------------------------------------------------------------------------------------------------------+
@@ -552,11 +552,11 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Invalid Collection location: path is invalid"
- (t2/update! :model/Collection (u/the-id collection) {:location "/a/"})))))
+ (t2/update! :model/Collection :id (u/the-id collection) {:location "/a/"})))))
(testing "We should be able to UPDATE a Collection and give it a new, *valid* location"
(mt/with-temp [:model/Collection collection-1 {}
:model/Collection collection-2 {}]
- (is (pos? (t2/update! :model/Collection (u/the-id collection-1) {:location (collection/location-path collection-2)}))))))
+ (is (pos? (t2/update! :model/Collection :id (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"
@@ -569,7 +569,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Invalid Collection location: some or all ancestors do not exist"
- (t2/update! :model/Collection (u/the-id collection) {:location (collection/location-path (nonexistent-collection-id))}))))))
+ (t2/update! :model/Collection :id (u/the-id collection) {:location (collection/location-path (nonexistent-collection-id))}))))))
(deftest delete-descendant-collections-test
(testing "When we delete a Collection do its descendants get deleted as well?"
@@ -1135,7 +1135,7 @@
;; | |
;; +-> F -> G +-> F -> G
(with-collection-hierarchy! [{:keys [e], :as collections}]
- (t2/update! :model/Collection (u/the-id e) {:archived true})
+ (t2/update! :model/Collection :id (u/the-id e) {:archived true})
(is (= {"A" {"B" {}
"C" {"D" {}
"F" {"G" {}}}}}
@@ -1328,28 +1328,28 @@
(let [personal-collection (collection/user->personal-collection my-cool-user)]
(is (thrown?
Exception
- (t2/update! :model/Collection (u/the-id personal-collection) {:archived true}))))))
+ (t2/update! :model/Collection :id (u/the-id personal-collection) {:archived true}))))))
(testing "Make sure we're not allowed to *move* a Personal Collection"
(mt/with-temp [:model/User my-cool-user {}
:model/Collection some-other-collection {}]
(let [personal-collection (collection/user->personal-collection my-cool-user)]
(is (thrown?
Exception
- (t2/update! :model/Collection (u/the-id personal-collection)
+ (t2/update! :model/Collection :id (u/the-id personal-collection)
{:location (collection/location-path some-other-collection)}))))))
(testing "Make sure we're not allowed to change the owner of a Personal Collection"
(mt/with-temp [:model/User my-cool-user]
(let [personal-collection (collection/user->personal-collection my-cool-user)]
(is (thrown?
Exception
- (t2/update! :model/Collection (u/the-id personal-collection) {:personal_owner_id (mt/user->id :crowberto)}))))))
+ (t2/update! :model/Collection :id (u/the-id personal-collection) {:personal_owner_id (mt/user->id :crowberto)}))))))
(testing "We are not allowed to change the authority_level of a Personal Collection"
(mt/with-temp [:model/User my-cool-user]
(let [personal-collection (collection/user->personal-collection my-cool-user)]
(is (thrown-with-msg?
Exception
#"You are not allowed to change the authority level of a Personal Collection."
- (t2/update! :model/Collection (u/the-id personal-collection) {:authority_level "official"}))))))
+ (t2/update! :model/Collection :id (u/the-id personal-collection) {:authority_level "official"}))))))
(testing "Does hydrating `:personal_collection_id` force creation of Personal Collections?"
(mt/with-temp [:model/User temp-user]
(is (malli= [:map [:personal_collection_id ms/PositiveInt]]
@@ -1371,7 +1371,7 @@
:model/Collection {sneaky-coll :id} {:location (format "/%d/%d/" top-level-coll personal-coll)}]
(let [check-is-personal (fn [id-or-ids]
(if (int? id-or-ids)
- (-> (t2/select-one :model/Collection id-or-ids)
+ (-> (t2/select-one :model/Collection :id id-or-ids)
(t2/hydrate :is_personal)
:is_personal)
(as-> (t2/select :model/Collection :id [:in id-or-ids] {:order-by [:id]}) collections
@@ -1387,7 +1387,7 @@
(check-is-personal [deep-personal-coll sneaky-coll])))))
(testing "root collection shouldn't be hydrated"
(is (= nil (t2/hydrate nil :is_personal)))
- (is (= [nil true] (map :is_personal (t2/hydrate [nil (t2/select-one :model/Collection personal-coll)] :is_personal)))))))))))
+ (is (= [nil true] (map :is_personal (t2/hydrate [nil (t2/select-one :model/Collection :id personal-coll)] :is_personal)))))))))))
(deftest hydrate-is-personal-without-any-personal-collections-test
(testing "batched hydration works on a fresh instance where no Personal Collection has been created yet"
@@ -1433,7 +1433,7 @@
;; Root Collection Root Collection > A
(with-personal-and-impersonal-collections [group {[a] :personal}]
(perms/grant-collection-read-permissions! group collection/root-collection)
- (t2/update! :model/Collection (u/the-id a) {:location (collection/children-location collection/root-collection)})
+ (t2/update! :model/Collection :id (u/the-id a) {:location (collection/children-location collection/root-collection)})
(is (= #{"/collection/root/read/"
"/collection/A/read/"}
(group->perms [a] group)))))
@@ -1444,7 +1444,7 @@
;; Root Collection > B Root Collection > B > A
(with-personal-and-impersonal-collections [group {[a] :personal, [b] :root}]
(perms/grant-collection-read-permissions! group b)
- (t2/update! :model/Collection (u/the-id a) {:location (collection/children-location b)})
+ (t2/update! :model/Collection :id (u/the-id a) {:location (collection/children-location b)})
(is (= #{"/collection/A/read/"
"/collection/B/read/"}
(group->perms [a b] group))))))
@@ -1456,7 +1456,7 @@
;; Root Collection Root Collection > B
(with-personal-and-impersonal-collections [group {[a b] :personal}]
(perms/grant-collection-readwrite-permissions! group collection/root-collection)
- (t2/update! :model/Collection (u/the-id b) {:location (collection/children-location collection/root-collection)})
+ (t2/update! :model/Collection :id (u/the-id b) {:location (collection/children-location collection/root-collection)})
(is (= #{"/collection/root/"
"/collection/B/"}
(group->perms [a b] group)))))
@@ -1467,7 +1467,7 @@
;; Root Collection > C Root Collection > C > B
(with-personal-and-impersonal-collections [group {[a b] :personal, [c] :root}]
(perms/grant-collection-readwrite-permissions! group c)
- (t2/update! :model/Collection (u/the-id b) {:location (collection/children-location c)})
+ (t2/update! :model/Collection :id (u/the-id b) {:location (collection/children-location c)})
(is (= #{"/collection/B/"
"/collection/C/"}
(group->perms [a b c] group))))))))
@@ -1479,7 +1479,7 @@
;; Root Collection > C Root Collection > C > A > B
(with-personal-and-impersonal-collections [group {[a b] :personal, [c] :root}]
(perms/grant-collection-readwrite-permissions! group c)
- (t2/update! :model/Collection (u/the-id a) {:location (collection/children-location c)})
+ (t2/update! :model/Collection :id (u/the-id a) {:location (collection/children-location c)})
(is (= #{"/collection/A/"
"/collection/B/"
"/collection/C/"}
@@ -1496,7 +1496,7 @@
;; Root Collection > A Root Collection
(with-personal-and-impersonal-collections [group {[a] :root}]
(perms/grant-collection-readwrite-permissions! group a)
- (t2/update! :model/Collection (u/the-id a) {:location (lucky-collection-children-location)})
+ (t2/update! :model/Collection :id (u/the-id a) {:location (lucky-collection-children-location)})
(is (= #{}
(group->perms [a] group)))))
(testing "to a descendant of a Personal Collection, we should *delete* perms entries for it"
@@ -1505,7 +1505,7 @@
;; Root Collection > B Root Collection
(with-personal-and-impersonal-collections [group {[a] :personal, [b] :root}]
(perms/grant-collection-readwrite-permissions! group b)
- (t2/update! :model/Collection (u/the-id b) {:location (collection/children-location a)})
+ (t2/update! :model/Collection :id (u/the-id b) {:location (collection/children-location a)})
(is (= #{}
(group->perms [a b] group))))))
(testing "from a non-Personal Collection"
@@ -1516,7 +1516,7 @@
(with-personal-and-impersonal-collections [group {[a b] :root}]
(perms/grant-collection-readwrite-permissions! group a)
(perms/grant-collection-readwrite-permissions! group b)
- (t2/update! :model/Collection (u/the-id b) {:location (lucky-collection-children-location)})
+ (t2/update! :model/Collection :id (u/the-id b) {:location (lucky-collection-children-location)})
(is (= #{"/collection/A/"}
(group->perms [a b] group)))))
(testing "to a descendant of a Personal Collection, we should *delete* perms entries for it"
@@ -1526,7 +1526,7 @@
(with-personal-and-impersonal-collections [group {[a] :personal, [b c] :root}]
(perms/grant-collection-readwrite-permissions! group b)
(perms/grant-collection-readwrite-permissions! group c)
- (t2/update! :model/Collection (u/the-id c) {:location (collection/children-location a)})
+ (t2/update! :model/Collection :id (u/the-id c) {:location (collection/children-location a)})
(is (= #{"/collection/B/"}
(group->perms [a b c] group)))))))
(testing "Deleting perms should apply recursively as well..."
@@ -1536,7 +1536,7 @@
(with-personal-and-impersonal-collections [group {[a] :personal, [b c] :root}]
(perms/grant-collection-readwrite-permissions! group b)
(perms/grant-collection-readwrite-permissions! group c)
- (t2/update! :model/Collection (u/the-id b) {:location (collection/children-location a)})
+ (t2/update! :model/Collection :id (u/the-id b) {:location (collection/children-location a)})
(is (= #{}
(group->perms [a b c] group))))))
@@ -1585,7 +1585,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"You cannot move a Collection to a different namespace once it has been created"
- (t2/update! :model/Collection (:id parent-collection) {:namespace child-namespace})))))))
+ (t2/update! :model/Collection :id (:id parent-collection) {:namespace child-namespace})))))))
(deftest check-special-collection-namespace-cannot-be-personal-collection
(testing "You should not be able to create a Personal Collection with a non-nil `:namespace`."
@@ -2592,7 +2592,7 @@
:dataset_query (mt/mbql-query venues)}]
(let [card-before-update (t2/select-one :model/Card :id card-id)]
;; mirror the DB state after a restore has been applied within the update transaction
- (t2/update! :model/Card card-id {:archived false})
+ (t2/update! :model/Card :id card-id {:archived false})
(is (some? (collection/check-for-remote-sync-update card-before-update))
"Restoring an item in a remote-synced collection should not throw")))))
@@ -2609,7 +2609,7 @@
:dataset_query (mt/mbql-query nil {:source-table (str "card__" base-card-id)})}]
(let [card-before-update (t2/select-one :model/Card :id base-card-id)]
;; mirror the DB state after an archive has been applied within the update transaction
- (t2/update! :model/Card base-card-id {:archived true})
+ (t2/update! :model/Card :id base-card-id {:archived true})
(is (thrown-with-msg? clojure.lang.ExceptionInfo
#"Used by remote synced content."
(collection/check-for-remote-sync-update card-before-update))
@@ -2960,7 +2960,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"A remote-synced Collection can only be placed in another remote-synced Collection or the root Collection"
- (t2/update! :model/Collection (:id remote-synced-collection)
+ (t2/update! :model/Collection :id (:id remote-synced-collection)
{:location (format "/%d/" (:id regular-parent))}))))))))
(deftest moving-into-remote-synced-enhanced-test
@@ -3402,7 +3402,7 @@
(deftest update-sets-remote-sync-test
(mt/with-temp [:model/Collection {id :id} {}]
(t2/update! :model/Collection :id id {:type "remote-synced"})
- (let [collection (t2/select-one :model/Collection id)]
+ (let [collection (t2/select-one :model/Collection :id id)]
(is (nil? (:type collection)))
(is (true? (:is_remote_synced collection))))))
diff --git a/test/metabase/collections/test_utils.clj b/test/metabase/collections/test_utils.clj
index 96e0bc4535c..9f739f1606f 100644
--- a/test/metabase/collections/test_utils.clj
+++ b/test/metabase/collections/test_utils.clj
@@ -60,10 +60,10 @@
(if-let [library (collection/library-collection)]
(let [original-synced (:is_remote_synced library)]
(try
- (t2/update! :model/Collection (:id library) {:is_remote_synced true})
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced true})
(f)
(finally
- (t2/update! :model/Collection (:id library) {:is_remote_synced (boolean original-synced)}))))
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced (boolean original-synced)}))))
;; No library collection exists, create one for the test
(mt/with-temp [:model/Collection _ {:name "Library" :type collection/library-collection-type :is_remote_synced true :location "/"}]
(f))))
@@ -80,10 +80,10 @@
(if-let [library (collection/library-collection)]
(let [original-synced (:is_remote_synced library)]
(try
- (t2/update! :model/Collection (:id library) {:is_remote_synced false})
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced false})
(f)
(finally
- (t2/update! :model/Collection (:id library) {:is_remote_synced (boolean original-synced)}))))
+ (t2/update! :model/Collection :id (:id library) {:is_remote_synced (boolean original-synced)}))))
(f)))
(defmacro with-library-not-synced
diff --git a/test/metabase/collections_rest/api_test.clj b/test/metabase/collections_rest/api_test.clj
index 5eb46f05099..00094ac1f58 100644
--- a/test/metabase/collections_rest/api_test.clj
+++ b/test/metabase/collections_rest/api_test.clj
@@ -2603,9 +2603,9 @@
:model/Dashboard {dash-id :id} {:collection_id coll-id}
:model/Card {card-id :id} {:collection_id coll-id :dataset_query (mt/mbql-query venues)}
:model/DashboardCard _ {:dashboard_id dash-id :card_id card-id}]
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card-id)))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card-id)))
(mt/user-http-request :crowberto :post 200 (format "collection/%d/move-dashboard-question-candidates" coll-id))
- (is (= dash-id (t2/select-one-fn :dashboard_id :model/Card card-id)))))))
+ (is (= dash-id (t2/select-one-fn :dashboard_id :model/Card :id card-id)))))))
(deftest ^:parallel post-move-dashboard-question-candidates-root-collection
(testing "POST /api/collection/:id/move-dashboard-question-candidates"
@@ -2614,7 +2614,7 @@
:model/Card {card-id :id} {:collection_id nil :dataset_query (mt/mbql-query venues)}
:model/DashboardCard _ {:dashboard_id dash-id :card_id card-id}]
(mt/user-http-request :crowberto :post 200 "collection/root/move-dashboard-question-candidates")
- (is (= dash-id (t2/select-one-fn :dashboard_id :model/Card card-id)))))))
+ (is (= dash-id (t2/select-one-fn :dashboard_id :model/Card :id card-id)))))))
(deftest ^:parallel post-move-dashboard-question-candidates-non-admin
(testing "POST /api/collection/:id/move-dashboard-question-candidates"
@@ -2633,7 +2633,7 @@
:model/DashboardCard _ {:dashboard_id dash1-id :card_id card-id}
:model/DashboardCard _ {:dashboard_id dash2-id :card_id card-id}]
(mt/user-http-request :crowberto :post 200 (format "collection/%d/move-dashboard-question-candidates" coll-id))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card-id)))))))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card-id)))))))
(deftest post-move-dashboard-question-candidates-nonexistent
(testing "POST /api/collection/:id/move-dashboard-question-candidates"
@@ -2649,7 +2649,7 @@
:model/Card {card-id :id} {:collection_id coll-id :archived true}
:model/DashboardCard _ {:dashboard_id dash-id :card_id card-id}]
(mt/user-http-request :crowberto :post 200 (format "collection/%d/move-dashboard-question-candidates" coll-id))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card-id)))))))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card-id)))))))
(deftest post-move-dashboard-question-candidates-archived-dashboard
(testing "POST /api/collection/:id/move-dashboard-question-candidates"
@@ -2659,7 +2659,7 @@
:model/Card {card-id :id} {:collection_id coll-id}
:model/DashboardCard _ {:dashboard_id dash-id :card_id card-id}]
(mt/user-http-request :crowberto :post 200 (format "collection/%d/move-dashboard-question-candidates" coll-id))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card-id)))))))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card-id)))))))
(deftest post-move-dashboard-question-candidates-different-collection
(testing "POST /api/collection/:id/move-dashboard-question-candidates"
@@ -2670,7 +2670,7 @@
:model/Card {card-id :id} {:collection_id coll2-id}
:model/DashboardCard _ {:dashboard_id dash-id :card_id card-id}]
(mt/user-http-request :crowberto :post 200 (format "collection/%d/move-dashboard-question-candidates" coll2-id))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card-id)))))))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card-id)))))))
(deftest post-move-dashboard-question-candidates-specific-cards
(testing "POST /api/collection/:id/move-dashboard-question-candidates"
@@ -2684,17 +2684,17 @@
:model/DashboardCard _ {:dashboard_id dash1-id :card_id card2-id}
:model/DashboardCard _ {:dashboard_id dash1-id :card_id card3-id}]
(testing "initially no cards should have dashboard_id set"
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card1-id)))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card2-id)))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card3-id))))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card1-id)))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card2-id)))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card3-id))))
(testing "move only card1 and card2"
(mt/user-http-request :crowberto :post 200
(format "collection/%d/move-dashboard-question-candidates" coll-id)
{:card_ids #{card1-id card2-id}}))
(testing "verify only specified cards were moved"
- (is (= dash1-id (t2/select-one-fn :dashboard_id :model/Card card1-id)))
- (is (= dash1-id (t2/select-one-fn :dashboard_id :model/Card card2-id)))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card3-id))))))))
+ (is (= dash1-id (t2/select-one-fn :dashboard_id :model/Card :id card1-id)))
+ (is (= dash1-id (t2/select-one-fn :dashboard_id :model/Card :id card2-id)))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card3-id))))))))
(deftest move-dashboard-question-candidates-is-atomic-test
(testing "POST /api/collection/:id/move-dashboard-question-candidates is atomic"
@@ -2705,8 +2705,8 @@
:model/DashboardCard _ {:dashboard_id dash-id :card_id card1-id}
:model/DashboardCard _ {:dashboard_id dash-id :card_id card2-id}]
;; Initially no cards should have dashboard_id set
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card1-id)))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card2-id)))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card1-id)))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card2-id)))
;; Mock card/update-card! to fail on the second call
(mt/with-dynamic-fn-redefs [card/update-card!
(let [call-count (atom 0)]
@@ -2718,8 +2718,8 @@
(mt/user-http-request :crowberto :post 500
(format "collection/%d/move-dashboard-question-candidates" coll-id)))
;; Verify neither card was moved (operation rolled back)
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card1-id)))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card card2-id))))))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card1-id)))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id card2-id))))))
(deftest ^:synchronized fetch-root-items-limit-and-offset-test
(testing "GET /api/collection/root/items"
@@ -3920,18 +3920,18 @@
(testing "C was NOT deleted"
(is (t2/exists? :model/Collection :id coll-c-id)))
(testing "C was moved to the root collection (a's parent)"
- (is (= "/" (:location (t2/select-one :model/Collection coll-c-id)))))
+ (is (= "/" (:location (t2/select-one :model/Collection :id coll-c-id)))))
(testing "C is still archived"
- (is (:archived (t2/select-one :model/Collection coll-c-id))))
+ (is (:archived (t2/select-one :model/Collection :id coll-c-id))))
(testing "Dashboards in A and B were deleted"
- (is (not (t2/exists? :model/Dashboard dash-a-id)))
- (is (not (t2/exists? :model/Dashboard dash-b-id))))
+ (is (not (t2/exists? :model/Dashboard :id dash-a-id)))
+ (is (not (t2/exists? :model/Dashboard :id dash-b-id))))
(testing "Dashboard in C was not deleted"
- (is (t2/exists? :model/Dashboard dash-c-id)))
+ (is (t2/exists? :model/Dashboard :id dash-c-id)))
(testing "Collection D still exists in C"
- (is (t2/exists? :model/Collection coll-d-id))
+ (is (t2/exists? :model/Collection :id coll-d-id))
(is (= (str "/" coll-c-id "/")
- (t2/select-one-fn :location :model/Collection coll-d-id))))))
+ (t2/select-one-fn :location :model/Collection :id coll-d-id))))))
(deftest collection-delete-middle-hoists-survivor
(mt/with-temp [:model/Collection {a-id :id :as a} {}
@@ -3945,10 +3945,10 @@
(is (not (t2/exists? :model/Collection :id b-id))))
(testing "c survives + is still archived"
(is (t2/exists? :model/Collection :id c-id))
- (is (:archived (t2/select-one :model/Collection c-id))))
+ (is (:archived (t2/select-one :model/Collection :id c-id))))
(testing "c hoisted under a"
(is (= (str "/" a-id "/")
- (:location (t2/select-one :model/Collection c-id)))))))
+ (:location (t2/select-one :model/Collection :id c-id)))))))
(deftest collection-deep-prune-multiple-ancestors
(mt/with-temp [:model/Collection {a-id :id :as a} {}
@@ -3962,9 +3962,9 @@
(is (not (t2/exists? :model/Collection :id a-id)))
(is (not (t2/exists? :model/Collection :id b-id))))
(testing "c at root"
- (is (= "/" (:location (t2/select-one :model/Collection c-id)))))
+ (is (= "/" (:location (t2/select-one :model/Collection :id c-id)))))
(testing "d still under c"
- (is (= (str "/" c-id "/") (:location (t2/select-one :model/Collection d-id)))))))
+ (is (= (str "/" c-id "/") (:location (t2/select-one :model/Collection :id d-id)))))))
(deftest collection-multiple-survivor-subtrees-hoist
(mt/with-temp
@@ -3983,8 +3983,8 @@
(testing "c leaves survive, both at root and still archived"
(doseq [cid [c1-id c2-id]]
(is (t2/exists? :model/Collection :id cid))
- (is (= "/" (:location (t2/select-one :model/Collection cid))))
- (is (:archived (t2/select-one :model/Collection cid)))))))
+ (is (= "/" (:location (t2/select-one :model/Collection :id cid))))
+ (is (:archived (t2/select-one :model/Collection :id cid)))))))
(deftest collection-deletion-path-normalization-and-dashboard-cascade
(mt/with-temp
@@ -3999,11 +3999,11 @@
(mt/user-http-request :rasta :put 200 (str "/collection/" a-id) {:archived true})
(mt/user-http-request :crowberto :delete 200 (str "/collection/" a-id))
(testing "no double slashes; root is exactly '/'"
- (is (= "/" (:location (t2/select-one :model/Collection c-id)))))
+ (is (= "/" (:location (t2/select-one :model/Collection :id c-id)))))
(testing "dashboards in deleted nodes gone; dashboard in survivor intact"
- (is (not (t2/exists? :model/Dashboard da-id)))
- (is (not (t2/exists? :model/Dashboard db-id)))
- (is (t2/exists? :model/Dashboard dc-id)))))
+ (is (not (t2/exists? :model/Dashboard :id da-id)))
+ (is (not (t2/exists? :model/Dashboard :id db-id)))
+ (is (t2/exists? :model/Dashboard :id dc-id)))))
(deftest collection-deletion-prohibitions
(mt/with-temp [:model/Collection {a-id :id} {}]
diff --git a/test/metabase/dashboards/models/dashboard_card_test.clj b/test/metabase/dashboards/models/dashboard_card_test.clj
index 21267e24445..e210056900e 100644
--- a/test/metabase/dashboards/models/dashboard_card_test.clj
+++ b/test/metabase/dashboards/models/dashboard_card_test.clj
@@ -371,7 +371,7 @@
:visualization_settings {}})]
(is (thrown-with-msg?
clojure.lang.ExceptionInfo #"must be an integer"
- (t2/update! :model/DashboardCard (:id dc)
+ (t2/update! :model/DashboardCard :id (:id dc)
{:visualization_settings
{:link {:entity {:id {:raw "x"} :model "card"}}}})))))
(testing "a legitimate integer id still works"
@@ -406,7 +406,7 @@
:visualization_settings {}})]
(is (thrown-with-msg?
clojure.lang.ExceptionInfo #"must be an integer"
- (t2/update! :model/DashboardCard (:id dc)
+ (t2/update! :model/DashboardCard :id (:id dc)
{:visualization_settings
{:click_behavior {:type "link" :linkType "question" :targetId {:raw "x"}}}})))))
(testing "a legitimate integer target id still works"
diff --git a/test/metabase/dashboards/models/dashboard_test.clj b/test/metabase/dashboards/models/dashboard_test.clj
index f6a66fb34a9..cbab9f36e1b 100644
--- a/test/metabase/dashboards/models/dashboard_test.clj
+++ b/test/metabase/dashboards/models/dashboard_test.clj
@@ -112,16 +112,16 @@
(do-with-dashboard-subscription!
(fn [{:keys [dash-id pulse-id pc-id]}]
(let [pc-ids-before (trigger-pc-ids pulse-id)]
- (t2/update! :model/Dashboard dash-id {:archived true})
+ (t2/update! :model/Dashboard :id dash-id {:archived true})
(testing "archiving a Dashboard keeps its Pulse, PulseChannel, PulseCard and SendPulse trigger"
- (is (=? {:archived false} (t2/select-one :model/Pulse pulse-id)))
- (is (=? {:enabled true} (t2/select-one :model/PulseChannel pc-id)))
+ (is (=? {:archived false} (t2/select-one :model/Pulse :id pulse-id)))
+ (is (=? {:enabled true} (t2/select-one :model/PulseChannel :id pc-id)))
(is (= 1 (t2/count :model/PulseCard :pulse_id pulse-id)))
(is (= pc-ids-before (trigger-pc-ids pulse-id))))
- (t2/update! :model/Dashboard dash-id {:archived false})
+ (t2/update! :model/Dashboard :id dash-id {:archived false})
(testing "restoring the Dashboard leaves the subscription as it was"
- (is (=? {:archived false} (t2/select-one :model/Pulse pulse-id)))
- (is (=? {:enabled true} (t2/select-one :model/PulseChannel pc-id)))
+ (is (=? {:archived false} (t2/select-one :model/Pulse :id pulse-id)))
+ (is (=? {:enabled true} (t2/select-one :model/PulseChannel :id pc-id)))
(is (= 1 (t2/count :model/PulseCard :pulse_id pulse-id)))
(is (= pc-ids-before (trigger-pc-ids pulse-id))))))))
@@ -129,10 +129,10 @@
(do-with-dashboard-subscription!
(fn [{:keys [dash-id pulse-id]}]
(testing "a subscription the user deleted before the Dashboard was trashed stays deleted after restore"
- (t2/update! :model/Pulse pulse-id {:archived true})
- (t2/update! :model/Dashboard dash-id {:archived true})
- (t2/update! :model/Dashboard dash-id {:archived false})
- (is (=? {:archived true} (t2/select-one :model/Pulse pulse-id)))
+ (t2/update! :model/Pulse :id pulse-id {:archived true})
+ (t2/update! :model/Dashboard :id dash-id {:archived true})
+ (t2/update! :model/Dashboard :id dash-id {:archived false})
+ (is (=? {:archived true} (t2/select-one :model/Pulse :id pulse-id)))
(is (= #{} (pulse-channel-test/send-pulse-triggers pulse-id)))))))
(deftest archive-collection-keeps-dashboard-subscriptions-test
@@ -140,29 +140,29 @@
(fn [{:keys [coll-id dash-id pulse-id pc-id]}]
(let [pc-ids-before (trigger-pc-ids pulse-id)]
(mt/with-current-user (mt/user->id :crowberto)
- (collection/archive-or-unarchive-collection! (t2/select-one :model/Collection coll-id) {:archived true})
+ (collection/archive-or-unarchive-collection! (t2/select-one :model/Collection :id coll-id) {:archived true})
(testing "archiving the parent Collection leaves the subscription and its trigger as they were"
;; the trashed Dashboard is what stops the trigger from sending
- (is (=? {:archived true} (t2/select-one :model/Dashboard dash-id)))
- (is (=? {:archived false} (t2/select-one :model/Pulse pulse-id)))
- (is (=? {:enabled true} (t2/select-one :model/PulseChannel pc-id)))
+ (is (=? {:archived true} (t2/select-one :model/Dashboard :id dash-id)))
+ (is (=? {:archived false} (t2/select-one :model/Pulse :id pulse-id)))
+ (is (=? {:enabled true} (t2/select-one :model/PulseChannel :id pc-id)))
(is (= pc-ids-before (trigger-pc-ids pulse-id))))
- (collection/archive-or-unarchive-collection! (t2/select-one :model/Collection coll-id) {:archived false})
+ (collection/archive-or-unarchive-collection! (t2/select-one :model/Collection :id coll-id) {:archived false})
(testing "restoring the Collection leaves the subscription and its trigger as they were"
- (is (=? {:archived false} (t2/select-one :model/Pulse pulse-id)))
- (is (=? {:enabled true} (t2/select-one :model/PulseChannel pc-id)))
+ (is (=? {:archived false} (t2/select-one :model/Pulse :id pulse-id)))
+ (is (=? {:enabled true} (t2/select-one :model/PulseChannel :id pc-id)))
(is (= pc-ids-before (trigger-pc-ids pulse-id)))))))))
(deftest archive-collection-keeps-deleted-subscription-deleted-test
(do-with-dashboard-subscription!
(fn [{:keys [coll-id pulse-id pc-id]}]
(testing "a subscription the user deleted before its Collection was trashed stays deleted after restore"
- (t2/update! :model/Pulse pulse-id {:archived true})
+ (t2/update! :model/Pulse :id pulse-id {:archived true})
(mt/with-current-user (mt/user->id :crowberto)
- (collection/archive-or-unarchive-collection! (t2/select-one :model/Collection coll-id) {:archived true})
- (collection/archive-or-unarchive-collection! (t2/select-one :model/Collection coll-id) {:archived false}))
- (is (=? {:archived true} (t2/select-one :model/Pulse pulse-id)))
- (is (=? {:enabled false} (t2/select-one :model/PulseChannel pc-id)))
+ (collection/archive-or-unarchive-collection! (t2/select-one :model/Collection :id coll-id) {:archived true})
+ (collection/archive-or-unarchive-collection! (t2/select-one :model/Collection :id coll-id) {:archived false}))
+ (is (=? {:archived true} (t2/select-one :model/Pulse :id pulse-id)))
+ (is (=? {:enabled false} (t2/select-one :model/PulseChannel :id pc-id)))
(is (= #{} (pulse-channel-test/send-pulse-triggers pulse-id)))))))
(deftest delete-dashboard-deletes-subscriptions-test
@@ -171,18 +171,18 @@
(do-with-dashboard-subscription!
(fn [{:keys [dash-id pulse-id]}]
(when archived?
- (t2/update! :model/Dashboard dash-id {:archived true}))
- (t2/delete! :model/Dashboard dash-id)
- (is (nil? (t2/select-one :model/Pulse pulse-id)))
+ (t2/update! :model/Dashboard :id dash-id {:archived true}))
+ (t2/delete! :model/Dashboard :id dash-id)
+ (is (nil? (t2/select-one :model/Pulse :id pulse-id)))
(is (= #{} (pulse-channel-test/send-pulse-triggers pulse-id))))))))
(deftest delete-collection-deletes-trashed-dashboard-subscriptions-test
(testing "hard deleting a Collection holding a directly trashed Dashboard deletes its Pulse and SendPulse triggers"
(do-with-dashboard-subscription!
(fn [{:keys [coll-id dash-id pulse-id]}]
- (t2/update! :model/Dashboard dash-id {:archived true})
- (t2/delete! :model/Collection coll-id)
- (is (nil? (t2/select-one :model/Pulse pulse-id)))
+ (t2/update! :model/Dashboard :id dash-id {:archived true})
+ (t2/delete! :model/Collection :id coll-id)
+ (is (nil? (t2/select-one :model/Pulse :id pulse-id)))
(is (= #{} (pulse-channel-test/send-pulse-triggers pulse-id)))))))
(deftest ^:parallel parameter-card-test
@@ -202,9 +202,9 @@
(mt/with-temp [:model/Card {card-id :id} {}
:model/Dashboard {dashboard-id :id} {:parameters [default-parameter]}]
(is (nil? (t2/select-one :model/ParameterCard :card_id card-id)))
- (t2/update! :model/Dashboard dashboard-id {:parameters [(merge default-parameter
- {:values_source_type "card"
- :values_source_config {:card_id card-id}})]})
+ (t2/update! :model/Dashboard :id dashboard-id {:parameters [(merge default-parameter
+ {:values_source_type "card"
+ :values_source_config {:card_id card-id}})]})
(is (=? {:card_id card-id
:parameterized_object_type :dashboard
:parameterized_object_id dashboard-id
@@ -231,7 +231,7 @@
:values_source_type "card"
:values_source_config {:card_id source-card-id}}]}]
(mt/with-dynamic-fn-redefs [parameter-card/upsert-or-delete-from-parameters! (fn [& _] (throw (ex-info "Should not be called" {})))]
- (t2/update! :model/Dashboard dashboard-id {:name "new name"})))))
+ (t2/update! :model/Dashboard :id dashboard-id {:name "new name"})))))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Collections Permissions Tests |
@@ -302,7 +302,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"A Dashboard can only go in Collections in the \"default\"(?: or :[a-z\-]+)+ namespace."
- (t2/update! :model/Dashboard card-id {:collection_id collection-id})))))))
+ (t2/update! :model/Dashboard :id card-id {:collection_id collection-id})))))))
(deftest ^:parallel validate-parameters-test
(testing "Should validate Dashboard :parameters when"
@@ -319,7 +319,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#":parameters must be a sequence of maps with :id and :type keys"
- (t2/update! :model/Dashboard id {:parameters [{:id 100}]})))))))
+ (t2/update! :model/Dashboard :id id {:parameters [{:id 100}]})))))))
(deftest normalize-parameters-test
(testing ":parameters should get normalized when coming out of the DB"
diff --git a/test/metabase/dashboards_rest/api_test.clj b/test/metabase/dashboards_rest/api_test.clj
index c4abdc5c28a..e0ac75b3857 100644
--- a/test/metabase/dashboards_rest/api_test.clj
+++ b/test/metabase/dashboards_rest/api_test.clj
@@ -131,7 +131,7 @@
(mt/with-temp [:model/Collection collection]
(grant-collection-perms-fn! (perms-group/all-users) collection)
(doseq [dashboard-or-id dashboards-or-ids]
- (t2/update! :model/Dashboard (u/the-id dashboard-or-id) {:collection_id (u/the-id collection)}))
+ (t2/update! :model/Dashboard :id (u/the-id dashboard-or-id) {:collection_id (u/the-id collection)}))
(f))))
(defmacro ^:private with-dashboards-in-readable-collection! [dashboards-or-ids & body]
@@ -678,7 +678,7 @@
(-> (dashboard-response (mt/user-http-request :rasta :get 200 (format "dashboard/%d" dashboard-id)))
:collection_authority_level)))
(let [collection-id (:collection_id (mt/user-http-request :rasta :get 200 (format "dashboard/%d" dashboard-id)))]
- (t2/update! :model/Collection collection-id {:authority_level "official"}))
+ (t2/update! :model/Collection :id collection-id {:authority_level "official"}))
(is (= "official"
(-> (dashboard-response (mt/user-http-request :rasta :get 200 (format "dashboard/%d" dashboard-id)))
:collection_authority_level)))))))))
@@ -1292,7 +1292,7 @@
copied-card-id (t2/select-one-fn :card_id :model/DashboardCard :dashboard_id (:id response))]
(is (not= (:id card) copied-card-id))
(is (= [(:id timeline)]
- (get-in (t2/select-one :model/Card copied-card-id)
+ (get-in (t2/select-one :model/Card :id copied-card-id)
[:visualization_settings :timeline.selected_timeline_ids]))))))))
(deftest add-card-with-restricted-timeline-to-shared-dashboard-test
@@ -1390,8 +1390,8 @@
:action_id action-id
:card_id model-id
:row 0 :col 0 :size_x 4 :size_y 4}]
- (t2/update! :model/Card model-id {:display :line
- :visualization_settings {:timeline.selected_timeline_ids [(:id timeline)]}})
+ (t2/update! :model/Card :id model-id {:display :line
+ :visualization_settings {:timeline.selected_timeline_ids [(:id timeline)]}})
(perms/revoke-collection-permissions! (perms-group/all-users) restricted)
(with-dashboards-in-writeable-collection! [public-id]
(api.card-test/with-cards-in-readable-collection! [model-id]
@@ -1852,7 +1852,7 @@
[dashboard-or-id]
(let [dashboard (t2/hydrate (if (map? dashboard-or-id)
dashboard-or-id
- (t2/select-one :model/Dashboard dashboard-or-id))
+ (t2/select-one :model/Dashboard :id dashboard-or-id))
:dashcards)]
(sort dashboard-card/dashcard-comparator (:dashcards dashboard))))
@@ -2132,14 +2132,14 @@
(defn- current-cards
"Returns the current ordered cards of a dashboard."
[dashboard-id]
- (-> (t2/select-one :model/Dashboard dashboard-id)
+ (-> (t2/select-one :model/Dashboard :id dashboard-id)
(t2/hydrate [:dashcards :series])
:dashcards))
(defn- tabs
"Returns the tabs of a dashboard."
[dashboard-id]
- (-> (t2/select-one :model/Dashboard dashboard-id)
+ (-> (t2/select-one :model/Dashboard :id dashboard-id)
(t2/hydrate :tabs)
:tabs))
@@ -2558,7 +2558,7 @@
:parameter_mappings [{:parameter_id "abc"
:card_id card-id
:target [:dimension [:field-id (mt/id :venues :id)]]}]}]}))]
- (is (some? (t2/select-one :model/DashboardCard (:id (first resp))))))))
+ (is (some? (t2/select-one :model/DashboardCard :id (:id (first resp))))))))
(testing "PUT /api/dashboard/:id/cards accepts expression as parammeter's target"
(mt/with-temp [:model/Dashboard {dashboard-id :id} {}
:model/Card {card-id :id} {:dataset_query (mt/mbql-query venues {:expressions {"A" [:+ (mt/$ids $venues.price) 1]}})}]
@@ -2572,7 +2572,7 @@
:parameter_mappings [{:parameter_id "abc"
:card_id card-id
:target [:dimension [:expression "A"]]}]}]}))]
- (is (some? (t2/select-one :model/DashboardCard (:id (first resp)))))))))
+ (is (some? (t2/select-one :model/DashboardCard :id (:id (first resp)))))))))
(deftest new-dashboard-card-with-additional-series-test
(mt/with-temp [:model/Dashboard {dashboard-id :id} {}
@@ -3623,7 +3623,7 @@
(testing "GET /api/dashboard/:id/params/:param-key/values"
(testing "If some Dashboard parameters do not have valid Field IDs, we should ignore them"
(with-chain-filter-fixtures [{:keys [dashcard card dashboard]}]
- (t2/update! :model/DashboardCard (:id dashcard)
+ (t2/update! :model/DashboardCard :id (:id dashcard)
{:parameter_mappings [{:parameter_id "_CATEGORY_NAME_"
:card_id (:id card)
:target [:dimension (mt/$ids venues $category_id->categories.name)]}
@@ -4312,7 +4312,7 @@
:action_id action-id
:card_id model-id}]
(let [execute-path (format "dashboard/%s/dashcard/%s/execute" dashboard-id dashcard-id)]
- (t2/update! :model/Action action-id {:archived true :archived_directly true})
+ (t2/update! :model/Action :id action-id {:archived true :archived_directly true})
(is (= "Not found."
(mt/user-http-request :crowberto :post 404 execute-path {:parameters {"id" 1}})))
(mt/user-http-request :crowberto :put 200 (str "action/" action-id) {:archived false})
@@ -4980,8 +4980,8 @@
:model/PulseChannelRecipient _ {:pulse_channel_id good-pulse-channel-id
:user_id (mt/user->id :crowberto)}]
(testing "The pulses are active"
- (is (false? (t2/select-one-fn :archived :model/Pulse bad-pulse-id)))
- (is (false? (t2/select-one-fn :archived :model/Pulse good-pulse-id))))
+ (is (false? (t2/select-one-fn :archived :model/Pulse :id bad-pulse-id)))
+ (is (false? (t2/select-one-fn :archived :model/Pulse :id good-pulse-id))))
(mt/with-fake-inbox
(let [{:keys [parameters]} (dashboard-response (mt/user-http-request
:rasta :put 200 (str "dashboard/" dash-id)
@@ -5003,9 +5003,9 @@
(testing "The dashboard parameters were removed"
(is (empty? parameters)))
(testing "The broken pulse was archived"
- (is (true? (t2/select-one-fn :archived :model/Pulse bad-pulse-id))))
+ (is (true? (t2/select-one-fn :archived :model/Pulse :id bad-pulse-id))))
(testing "The unbroken pulse is still active"
- (is (false? (t2/select-one-fn :archived :model/Pulse good-pulse-id))))
+ (is (false? (t2/select-one-fn :archived :model/Pulse :id good-pulse-id))))
(testing "The dashboard and pulse creators were emailed about the removed pulse"
(set (keys inbox)))))
@@ -5384,7 +5384,7 @@
:template-tags {}})}
:model/DashboardCard {dashcard-id :id} {:card_id card-id
:dashboard_id dashboard-id}]
- (let [original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard dashboard-id)]
+ (let [original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard :id dashboard-id)]
(mt/with-temporary-setting-values [synchronous-batch-updates true]
(mt/user-http-request :crowberto :post 202
(format "dashboard/%s/dashcard/%s/card/%s/query" dashboard-id dashcard-id card-id)))
@@ -5546,28 +5546,28 @@
(mt/with-temp [:model/Dashboard {dash-id :id} {}
:model/Card {card-id :id} {:dashboard_id dash-id}]
(mt/user-http-request :crowberto :put 200 (str "dashboard/" dash-id) {:archived "true"})
- (is (t2/select-one-fn :archived :model/Card card-id))))
+ (is (t2/select-one-fn :archived :model/Card :id card-id))))
(testing "It gets unarchived with the dashboard"
(mt/with-temp [:model/Dashboard {dash-id :id} {}
:model/Card {card-id :id} {:dashboard_id dash-id}]
(mt/user-http-request :crowberto :put 200 (str "dashboard/" dash-id) {:archived "true"})
(mt/user-http-request :crowberto :put 200 (str "dashboard/" dash-id) {:archived "false"})
- (is (not (t2/select-one-fn :archived :model/Card card-id)))))
+ (is (not (t2/select-one-fn :archived :model/Card :id card-id)))))
(testing "It gets archived with the dashboard if the dashboard is archived from a collection"
(mt/with-temp [:model/Collection {coll-id :id} {}
:model/Dashboard {dash-id :id} {:collection_id coll-id}
:model/Card {card-id :id} {:dashboard_id dash-id}]
(mt/user-http-request :crowberto :put 200 (str "collection/" coll-id) {:archived "true"})
- (is (t2/select-one-fn :archived :model/Dashboard dash-id))
- (is (t2/select-one-fn :archived :model/Card card-id))))
+ (is (t2/select-one-fn :archived :model/Dashboard :id dash-id))
+ (is (t2/select-one-fn :archived :model/Card :id card-id))))
(testing "It gets unarchived with the dashboard if the dashboard is unarchived from a collection"
(mt/with-temp [:model/Collection {coll-id :id} {}
:model/Dashboard {dash-id :id} {:collection_id coll-id}
:model/Card {card-id :id} {:dashboard_id dash-id}]
(mt/user-http-request :crowberto :put 200 (str "collection/" coll-id) {:archived true})
(mt/user-http-request :crowberto :put 200 (str "collection/" coll-id) {:archived false})
- (is (not (t2/select-one-fn :archived :model/Dashboard dash-id)))
- (is (not (t2/select-one-fn :archived :model/Card card-id))))))
+ (is (not (t2/select-one-fn :archived :model/Dashboard :id dash-id)))
+ (is (not (t2/select-one-fn :archived :model/Card :id card-id))))))
(deftest ^:parallel dashboard-questions-are-archived-when-unused-and-vice-versa
(testing "The dashboard question is archived when it's removed from the dashboard"
@@ -5576,7 +5576,7 @@
:model/DashboardCard _ {:card_id card-id :dashboard_id dash-id}]
(mt/user-http-request :rasta :put 200 (str "dashboard/" dash-id) {:dashcards []})
(is (not (t2/exists? :model/DashboardCard :card_id card-id :dashboard_id dash-id)))
- (is (t2/select-one-fn :archived :model/Card card-id)))))
+ (is (t2/select-one-fn :archived :model/Card :id card-id)))))
(deftest ^:parallel dashboard-questions-are-archived-when-unused-and-vice-versa-2
(testing "The dashboard question is unarchived when it's re-added to the dashboard"
@@ -5588,7 +5588,7 @@
:size_y 10
:col 0 :row 0}]}))
(is (t2/exists? :model/DashboardCard :card_id card-id :dashboard_id dash-id))
- (is (not (t2/select-one-fn :archived :model/Card card-id))))))
+ (is (not (t2/select-one-fn :archived :model/Card :id card-id))))))
(deftest ^:parallel dashboard-items-works
(testing "Dashboard items is empty when the dashboard is a normal dashboard w/o DQs"
@@ -6467,9 +6467,9 @@
:model/DashboardCard _dc1 {:dashboard_id (:id d) :card_id (:id dq)}
:model/DashboardCard dc2 {:dashboard_id (:id d) :card_id (:id dq)}]
(mt/user-http-request :crowberto :put 200 (str "dashboard/" (:id d)) {:dashcards [dc2] :tabs []})
- (is (false? (t2/select-one-fn :archived :model/Card (:id dq))))
+ (is (false? (t2/select-one-fn :archived :model/Card :id (:id dq))))
(mt/user-http-request :crowberto :put 200 (str "dashboard/" (:id d)) {:dashcards [] :tabs []})
- (is (true? (t2/select-one-fn :archived :model/Card (:id dq)))))))
+ (is (true? (t2/select-one-fn :archived :model/Card :id (:id dq)))))))
(deftest removing-one-dq-does-not-affect-sibling-dq-test
(testing "PUT /api/dashboard/:id removing one Dashboard Question's dashcard leaves an unrelated Dashboard Question untouched"
@@ -6478,8 +6478,8 @@
:model/DashboardCard _dc-a {:dashboard_id (:id d) :card_id (:id dq-a)}
:model/DashboardCard dc-b {:dashboard_id (:id d) :card_id (:id dq-b)}]
(mt/user-http-request :crowberto :put 200 (str "dashboard/" (:id d)) {:dashcards [dc-b] :tabs []})
- (is (true? (t2/select-one-fn :archived :model/Card (:id dq-a))))
- (is (false? (t2/select-one-fn :archived :model/Card (:id dq-b)))))))
+ (is (true? (t2/select-one-fn :archived :model/Card :id (:id dq-a))))
+ (is (false? (t2/select-one-fn :archived :model/Card :id (:id dq-b)))))))
(deftest create-dashboard-blank-name-test
(testing "POST /api/dashboard with a whitespace-only name is rejected (#63176)"
diff --git a/test/metabase/data_studio/api/table_test.clj b/test/metabase/data_studio/api/table_test.clj
index ccf554224e6..45c73782620 100644
--- a/test/metabase/data_studio/api/table_test.clj
+++ b/test/metabase/data_studio/api/table_test.clj
@@ -433,7 +433,7 @@
:schema "PUBLIC"}]}
response))))
(testing "if products is already published, it appears in published_downstream when selecting it"
- (t2/update! :model/Table products-id {:is_published true})
+ (t2/update! :model/Table :id products-id {:is_published true})
(let [response (mt/user-http-request :crowberto :post 200 "data-studio/table/selection"
{:table_ids [products-id]})]
(is (=? {:selected_table {:id products-id
@@ -448,8 +448,8 @@
;; but orders is already unpublished, so published_downstream_tables should be empty
(is (= [] (:published_downstream_tables response)))))
(testing "when orders is published and we select products, orders appears in published_downstream"
- (t2/update! :model/Table orders-id {:is_published true})
- (t2/update! :model/Table products-id {:is_published true})
+ (t2/update! :model/Table :id orders-id {:is_published true})
+ (t2/update! :model/Table :id products-id {:is_published true})
(let [response (mt/user-http-request :crowberto :post 200 "data-studio/table/selection"
{:table_ids [products-id]})]
(is (=? {:selected_table {:id products-id
diff --git a/test/metabase/documents/api/document_test.clj b/test/metabase/documents/api/document_test.clj
index 3d62366410d..dab883198dd 100644
--- a/test/metabase/documents/api/document_test.clj
+++ b/test/metabase/documents/api/document_test.clj
@@ -211,7 +211,7 @@
:dataset_query (mt/mbql-query venues)
:archived true}]
;; Ensure the source document embeds the cards we expect to be copied (and one archived card that should not).
- (t2/update! :model/Document doc-id
+ (t2/update! :model/Document :id doc-id
{:document {:type "doc"
:content [{:type "cardEmbed" :attrs {:id card-1-id :name nil}}
{:type "paragraph"}
@@ -1781,10 +1781,10 @@
;; Simulate a failure during card archiving
(testing "failure during card archiving rolls back document archiving"
(let [orig-update! (mt/original-fn #'t2/update!)]
- (mt/with-dynamic-fn-redefs [t2/update! (fn [model id updates]
- (if (and (= model :model/Card) (:archived updates))
+ (mt/with-dynamic-fn-redefs [t2/update! (fn [model & args]
+ (if (and (= model :model/Card) (:archived (last args)))
(throw (ex-info "Simulated card archive failure" {}))
- (orig-update! model id updates)))]
+ (apply orig-update! model args)))]
(mt/user-http-request :crowberto
:put 500 (format "document/%s" doc-id)
{:archived true})
@@ -2241,7 +2241,7 @@
(is (= 200
(:status (mt/client-full-response :get (str "public/document/" uuid))))))
(testing "Document is not accessible after archiving"
- (t2/update! :model/Document (:id document) {:archived true})
+ (t2/update! :model/Document :id (:id document) {:archived true})
(is (= "Not found."
(mt/client :get 404 (str "public/document/" uuid))))))))))
@@ -2273,7 +2273,7 @@
:document {:type "doc"
:content [{:type "cardEmbed"
:attrs {:id card-id}}]}}]
- (t2/update! :model/Card card-id {:document_id doc-id})
+ (t2/update! :model/Card :id card-id {:document_id doc-id})
(mt/with-group-for-user [group :rasta {:name "Rasta Group"}]
(testing "Read-only users can download"
(perms/grant-collection-read-permissions! group coll-id)
@@ -2306,7 +2306,7 @@
:format_rows false
:pivot_results false})))
(testing "Archived document returns 404"
- (t2/update! :model/Document doc-id {:archived true})
+ (t2/update! :model/Document :id doc-id {:archived true})
(mt/user-http-request :rasta
:post 404
(format "document/%s/card/%s/query/csv" doc-id card-id)
@@ -2329,7 +2329,7 @@
:document {:type "doc"
:content [{:type "cardEmbed"
:attrs {:id card-id}}]}}]
- (t2/update! :model/Card card-id {:document_id doc-id})
+ (t2/update! :model/Card :id card-id {:document_id doc-id})
(let [all-users-group (perms/all-users-group)]
;; Grant collection read permissions so user can access the document
(perms/grant-collection-read-permissions! all-users-group coll-id)
@@ -2760,7 +2760,7 @@
:dataset_query (mt/native-query
{:query "SELECT COUNT(*) FROM VENUES"})
:display :scalar}]
- (t2/update! :model/Document doc-id {:document (card-embed-ast native-card-id)})
+ (t2/update! :model/Document :id doc-id {:document (card-embed-ast native-card-id)})
(perms/grant-collection-readwrite-permissions! (perms/all-users-group) coll-id)
(mt/with-restored-data-perms!
(data-perms/set-database-permission! (perms/all-users-group) (mt/id) :perms/create-queries :query-builder)
@@ -2785,7 +2785,7 @@
:document_id doc-id
:dataset_query (mt/mbql-query venues)
:visualization_settings {:timeline.selected_timeline_ids [timeline-id]}}]
- (t2/update! :model/Document doc-id {:document (card-embed-ast card-id)})
+ (t2/update! :model/Document :id doc-id {:document (card-embed-ast card-id)})
(perms/grant-collection-readwrite-permissions! (perms/all-users-group) coll-id)
(perms/revoke-collection-permissions! (perms/all-users-group) timeline-coll-id)
(let [result (mt/user-http-request :rasta :post 200 (format "document/%d/copy" doc-id)
diff --git a/test/metabase/documents/models/document_test.clj b/test/metabase/documents/models/document_test.clj
index f1be275550d..3768ce563f7 100644
--- a/test/metabase/documents/models/document_test.clj
+++ b/test/metabase/documents/models/document_test.clj
@@ -98,7 +98,7 @@
:document_id document-id
:collection_id old-collection-id}]
;; Update the document's collection_id
- (t2/update! :model/Document document-id {:collection_id new-collection-id})
+ (t2/update! :model/Document :id document-id {:collection_id new-collection-id})
;; Verify that associated cards were updated to match the new collection
(is (= new-collection-id (:collection_id (t2/select-one :model/Card :id card1-id))))
(is (= new-collection-id (:collection_id (t2/select-one :model/Card :id card2-id)))))))
@@ -113,7 +113,7 @@
:document_id document-id
:collection_id collection-id}]
;; Move document to no collection (nil)
- (t2/update! :model/Document document-id {:collection_id nil})
+ (t2/update! :model/Document :id document-id {:collection_id nil})
;; Verify that the card's collection_id was updated to nil
(is (nil? (:collection_id (t2/select-one :model/Card :id card-id)))))))
@@ -137,7 +137,7 @@
:model/Card {regular-card-id :id} {:name "Regular Card"
:collection_id old-collection-id}]
;; Update the document's collection_id
- (t2/update! :model/Document document-id {:collection_id new-collection-id})
+ (t2/update! :model/Document :id document-id {:collection_id new-collection-id})
;; Verify only the correct card was updated
(is (= new-collection-id (:collection_id (t2/select-one :model/Card :id in-document-card-id))))
;; Verify other cards were NOT updated
@@ -159,14 +159,14 @@
(testing "moving document to personal collection moves associated cards"
(mt/with-current-user user-id
;; As the personal collection owner, update should succeed
- (t2/update! :model/Document document-id {:collection_id personal-coll-id})
+ (t2/update! :model/Document :id document-id {:collection_id personal-coll-id})
;; Verify both document and card moved to personal collection
(is (= personal-coll-id (:collection_id (t2/select-one :model/Document :id document-id))))
(is (= personal-coll-id (:collection_id (t2/select-one :model/Card :id card-id))))))
(testing "moving document from personal collection works"
(mt/with-current-user user-id
;; Move back to regular collection
- (t2/update! :model/Document document-id {:collection_id regular-collection-id})
+ (t2/update! :model/Document :id document-id {:collection_id regular-collection-id})
;; Verify both document and card moved back
(is (= regular-collection-id (:collection_id (t2/select-one :model/Document :id document-id))))
(is (= regular-collection-id (:collection_id (t2/select-one :model/Card :id card-id)))))))))))
@@ -419,11 +419,11 @@
(testing "collection_position is stored and retrieved correctly"
(is (= 5 (:collection_position document)))))
(testing "collection_position can be updated"
- (t2/update! :model/Document document-id {:collection_position 10})
+ (t2/update! :model/Document :id document-id {:collection_position 10})
(let [updated-document (t2/select-one :model/Document :id document-id)]
(is (= 10 (:collection_position updated-document)))))
(testing "collection_position can be set to nil"
- (t2/update! :model/Document document-id {:collection_position nil})
+ (t2/update! :model/Document :id document-id {:collection_position nil})
(let [updated-document (t2/select-one :model/Document :id document-id)]
(is (nil? (:collection_position updated-document))))))))
@@ -797,13 +797,13 @@
(with-redefs [events/publish-event! (fn [topic event]
(swap! events-published conj [topic event]))]
(testing "events fire normally"
- (t2/update! :model/Document doc-id {:name "Updated Name"})
+ (t2/update! :model/Document :id doc-id {:name "Updated Name"})
(is (= 1 (count @events-published)))
(is (= :event/document-update (ffirst @events-published))))
(reset! events-published [])
(testing "events are suppressed during deserialization"
(binding [mi/*deserializing?* true]
- (t2/update! :model/Document doc-id {:name "Deserialized Name"}))
+ (t2/update! :model/Document :id doc-id {:name "Deserialized Name"}))
(is (empty? @events-published))))))))
(deftest never-viewed-document-reports-null-activity-anchor
diff --git a/test/metabase/documents/search_test.clj b/test/metabase/documents/search_test.clj
index 7a7308907ed..560741af90a 100644
--- a/test/metabase/documents/search_test.clj
+++ b/test/metabase/documents/search_test.clj
@@ -109,8 +109,8 @@
"Document read event should publish successfully"))
(testing "Document with higher view count appears in search"
;; Set the view count directly to test its search integration.
- (t2/update! :model/Document doc-id {:view_count 5
- :last_viewed_at (t/offset-date-time)})
+ (t2/update! :model/Document :id doc-id {:view_count 5
+ :last_viewed_at (t/offset-date-time)})
(search.tu/with-temp-index-table
(let [results (mt/user-http-request :crowberto :get 200 "search" {:q "Viewed" :models "document"})
doc-results (filter #(= "document" (:model %)) (:data results))]
@@ -121,7 +121,7 @@
(is (some #(= "view-count" (:name %)) (:scores doc-result))))))))
(testing "Document with recent view appears in search results"
(let [recent-time (t/minus (t/offset-date-time) (t/minutes 5))]
- (t2/update! :model/Document doc-id {:last_viewed_at recent-time})
+ (t2/update! :model/Document :id doc-id {:last_viewed_at recent-time})
(search.tu/with-temp-index-table
(let [results (mt/user-http-request :crowberto :get 200 "search" {:q "Viewed" :models "document"})
doc-results (filter #(= "document" (:model %)) (:data results))]
@@ -175,7 +175,7 @@
(testing "found by an original body term before the edit"
(let [results (mt/user-http-request :crowberto :get 200 "search" :q "initial" :models "document")]
(is (contains? (set (map :id (:data results))) doc-id))))
- (t2/update! :model/Document doc-id
+ (t2/update! :model/Document :id doc-id
{:document (documents.test-util/text->prose-mirror-ast "revised projections and forecasts")})
(testing "found by a term that appears only in the revised body"
(let [results (mt/user-http-request :crowberto :get 200 "search" :q "forecasts" :models "document")]
diff --git a/test/metabase/documents/view_log_test.clj b/test/metabase/documents/view_log_test.clj
index 99e14cb5021..5e735f2414f 100644
--- a/test/metabase/documents/view_log_test.clj
+++ b/test/metabase/documents/view_log_test.clj
@@ -68,9 +68,9 @@
(is (= 0 (:view_count document))
"view_count should be 0 before the event is published")
(events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})
- (is (= 1 (t2/select-one-fn :view_count :model/Document (:id document))))
+ (is (= 1 (t2/select-one-fn :view_count :model/Document :id (:id document))))
(events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})
- (is (= 2 (t2/select-one-fn :view_count :model/Document (:id document)))))))))
+ (is (= 2 (t2/select-one-fn :view_count :model/Document :id (:id document)))))))))
(deftest update-document-last-viewed-at-test
(let [now (-> (t/offset-date-time)
@@ -88,7 +88,7 @@
(#'documents.view-log/update-document-last-viewed-at!* [{:id (:id document) :timestamp one-hour-ago}
{:id (:id document) :timestamp two-hours-ago}])
(is (= one-hour-ago
- (-> (t2/select-one-fn :last_viewed_at :model/Document (:id document))
+ (-> (t2/select-one-fn :last_viewed_at :model/Document :id (:id document))
t/offset-date-time
(.withNano 0))))))
(testing "if the existing last_viewed_at is greater than the updating values, do not override it"
@@ -101,7 +101,7 @@
:last_viewed_at now}]
(#'documents.view-log/update-document-last-viewed-at!* [{:id (:id document) :timestamp one-hour-ago}])
(is (= now
- (-> (t2/select-one-fn :last_viewed_at :model/Document (:id document))
+ (-> (t2/select-one-fn :last_viewed_at :model/Document :id (:id document))
t/offset-date-time
(.withNano 0))))))))
diff --git a/test/metabase/driver/connection_test.clj b/test/metabase/driver/connection_test.clj
index d9d17d1f207..674a02cd779 100644
--- a/test/metabase/driver/connection_test.clj
+++ b/test/metabase/driver/connection_test.clj
@@ -70,7 +70,7 @@
(deftest effective-details-refuses-database-instance-test
(testing "effective-details takes only the Lib metadata of a Database, so a Database instance fails fast"
(is (thrown? clojure.lang.ExceptionInfo
- (driver.conn/effective-details (t2/select-one :model/Database (mt/id)))))))
+ (driver.conn/effective-details (t2/select-one :model/Database :id (mt/id)))))))
(deftest connection-telemetry-info-test
(testing "connection-telemetry-info describes the current connection context as prose, for logging only"
diff --git a/test/metabase/driver/mysql_test.clj b/test/metabase/driver/mysql_test.clj
index 87916bd350e..bba0501627b 100644
--- a/test/metabase/driver/mysql_test.clj
+++ b/test/metabase/driver/mysql_test.clj
@@ -1150,7 +1150,7 @@
(deftest have-select-privelege?-timeout-test
(mt/test-driver :mysql
- (let [{schema :schema, table-name :name} (t2/select-one :model/Table (mt/id :checkins))]
+ (let [{schema :schema, table-name :name} (t2/select-one :model/Table :id (mt/id :checkins))]
(qp.store/with-metadata-provider (mt/id)
(testing "checking select privilege defaults to allow on timeout (#56737)"
(mt/with-dynamic-fn-redefs [sql-jdbc.describe-database/simple-select-probe-query (constantly ["SELECT sleep(3)"])]
diff --git a/test/metabase/driver/postgres_test.clj b/test/metabase/driver/postgres_test.clj
index 7ecbc6501aa..d76fc3185da 100644
--- a/test/metabase/driver/postgres_test.clj
+++ b/test/metabase/driver/postgres_test.clj
@@ -1696,8 +1696,8 @@
(sync/sync-database! (:id database) {:scan :schema})
(is (= #{"id" "col_visible" "col_json" "col_json → key_a" "col_json_hidden" "col_json_hidden → key_b" "col_hidden"}
(active-fields database))))
- (t2/update! :model/Database (:id database) {:details (assoc details :user role :password "password")})
- (let [database (t2/select-one :model/Database (:id database))]
+ (t2/update! :model/Database :id (:id database) {:details (assoc details :user role :password "password")})
+ (let [database (t2/select-one :model/Database :id (:id database))]
(binding [sync-util/*log-exceptions-and-continue?* false]
(sync/sync-database! (:id database) {:scan :schema}))
(testing "after switching to a user with column-level grants, unreadable columns are retired and readable JSON is still unfolded"
@@ -2281,7 +2281,7 @@
(deftest have-select-privelege?-timeout-test
(mt/test-driver :postgres
- (let [{schema :schema, table-name :name} (t2/select-one :model/Table (mt/id :checkins))]
+ (let [{schema :schema, table-name :name} (t2/select-one :model/Table :id (mt/id :checkins))]
(qp.store/with-metadata-provider (mt/id)
(testing "checking select privilege defaults to allow on timeout (#56737)"
(mt/with-dynamic-fn-redefs [sql-jdbc.describe-database/simple-select-probe-query (constantly ["SELECT pg_sleep(3)"])]
diff --git a/test/metabase/driver/sql/transforms_test.clj b/test/metabase/driver/sql/transforms_test.clj
index b657a59b563..1664a65cbef 100644
--- a/test/metabase/driver/sql/transforms_test.clj
+++ b/test/metabase/driver/sql/transforms_test.clj
@@ -258,7 +258,7 @@
(mt/with-premium-features #{:transforms-basic}
(testing "a target name containing special characters is created and its rows round-trip"
(transforms.tu/with-transform-cleanup! [target {:type :table
- :schema (t2/select-one-fn :schema :model/Table (mt/id :venues))
+ :schema (t2/select-one-fn :schema :model/Table :id (mt/id :venues))
:name "qcq_a\\`b"
:database (mt/id)}]
(let [expected (venues-row-count)
@@ -282,7 +282,7 @@
(mt/test-drivers (disj (mt/normal-drivers-with-feature :transforms/table)
:bigquery-cloud-sdk :redshift :snowflake)
(mt/with-premium-features #{:transforms-basic}
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :venues))
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :venues))
written (venues-row-count)]
(transforms.tu/with-transform-cleanup! [target {:type :table :schema schema
:name "ctas_rows_affected_probe"
@@ -306,7 +306,7 @@
;; goes through `compile-insert`. No exclusions — a failing driver also undercounts INSERTs.
(mt/test-drivers (mt/normal-drivers-with-feature :transforms/table)
(mt/with-premium-features #{:transforms-basic}
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :venues))
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :venues))
written (venues-row-count)]
(transforms.tu/with-transform-cleanup! [target {:type :table :schema schema :name "insert_rows_affected_probe" :database (mt/id)}]
(let [transform {:source {:type "query" :query (venues-source-query)}
@@ -358,7 +358,7 @@
;; `rnq_a_b`, so the rename lands on a different table instead of failing
(doseq [dst ["rnq_a`b\\" "rnq-a-b"]]
(testing (str "renaming a table to " (pr-str dst) " keeps it as a single queryable table")
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))
src (str "rnq_src_" (subs (str (random-uuid)) 0 8))]
(try
(driver/create-table! driver/*driver* (mt/id) (keyword schema src)
diff --git a/test/metabase/driver/sql_jdbc/actions_test.clj b/test/metabase/driver/sql_jdbc/actions_test.clj
index 35abadbf11b..3bd5c76e3c2 100644
--- a/test/metabase/driver/sql_jdbc/actions_test.clj
+++ b/test/metabase/driver/sql_jdbc/actions_test.clj
@@ -98,7 +98,7 @@
(catch Exception e
(ex-data e))))
-(defn- field-id->name [id] (t2/select-one-fn :name :model/Field id))
+(defn- field-id->name [id] (t2/select-one-fn :name :model/Field :id id))
(mu/defn- test-action-error-handling! [f :- fn?]
(mt/test-drivers (filter #(isa? driver/hierarchy % :sql-jdbc) (mt/normal-drivers-with-feature :actions))
diff --git a/test/metabase/driver/sql_jdbc/connection_test.clj b/test/metabase/driver/sql_jdbc/connection_test.clj
index 4d3d2420ee9..af0429d83f6 100644
--- a/test/metabase/driver/sql_jdbc/connection_test.clj
+++ b/test/metabase/driver/sql_jdbc/connection_test.clj
@@ -379,7 +379,7 @@
(testing "The calculated hash should be different"
(is (not= (#'sql-jdbc.conn/jdbc-spec-hash (driver.u/ensure-lib-database db))
(#'sql-jdbc.conn/jdbc-spec-hash (driver.u/ensure-lib-database db-perturbed)))))
- (t2/update! :model/Database (mt/id) {:details (:details db-perturbed)})
+ (t2/update! :model/Database :id (mt/id) {:details (:details db-perturbed)})
(let [;; this call should result in the connection pool becoming invalidated, and the new hash value
;; being stored based upon these updated details
pool-spec-2 (sql-jdbc.conn/db->pooled-connection-spec (driver.u/ensure-lib-database db-perturbed))
@@ -404,7 +404,7 @@
(is (not= db-hash-1 db-hash-2)))))))
(finally
;; restore the original test DB details, no matter what just happened
- (t2/update! :model/Database (mt/id) {:details (:details db)})))))))
+ (t2/update! :model/Database :id (mt/id) {:details (:details db)})))))))
;;; Postgres-specific, so ok to hardcode driver names below.
;; [kondo-keep] suppresses a warning :redundant-ignore can't see; --audit rechecks
diff --git a/test/metabase/driver/sql_jdbc/sync/describe_database_test.clj b/test/metabase/driver/sql_jdbc/sync/describe_database_test.clj
index 42d067ca797..6a33c85b245 100644
--- a/test/metabase/driver/sql_jdbc/sync/describe_database_test.clj
+++ b/test/metabase/driver/sql_jdbc/sync/describe_database_test.clj
@@ -243,7 +243,7 @@
(get-method sql-jdbc.sync.interface/have-select-privilege? %))]
(mt/test-drivers (mt/normal-driver-select {:+parent :sql-jdbc
:+fns [default-have-select-privilege?]})
- (let [{schema :schema, table-name :name} (t2/select-one :model/Table (mt/id :checkins))]
+ (let [{schema :schema, table-name :name} (t2/select-one :model/Table :id (mt/id :checkins))]
(qp.store/with-metadata-provider (mt/id)
(testing (sql-jdbc.describe-database/simple-select-probe-query driver/*driver* schema table-name)
(doseq [auto-commit [true false]]
@@ -309,7 +309,7 @@
(defn- run-retry-have-select-privilege!
[probe-errors query-canceled probe-error-fn]
- (let [{schema :schema, table-name :name} (t2/select-one :model/Table (mt/id :checkins))]
+ (let [{schema :schema, table-name :name} (t2/select-one :model/Table :id (mt/id :checkins))]
(sql-jdbc.execute/do-with-connection-with-options
driver/*driver* (mt/id) nil
(fn [^Connection conn]
diff --git a/test/metabase/driver/sql_jdbc/sync/describe_table_test.clj b/test/metabase/driver/sql_jdbc/sync/describe_table_test.clj
index 74d113c5d43..698b7fdb4f0 100644
--- a/test/metabase/driver/sql_jdbc/sync/describe_table_test.clj
+++ b/test/metabase/driver/sql_jdbc/sync/describe_table_test.clj
@@ -293,7 +293,7 @@
nil
(fn [conn]
(is (= ["id"]
- (sql-jdbc.describe-table/get-table-pks driver/*driver* conn "test-data" (t2/select-one :model/Table (mt/id :venues)))))))))
+ (sql-jdbc.describe-table/get-table-pks driver/*driver* conn "test-data" (t2/select-one :model/Table :id (mt/id :venues)))))))))
;;; ------------------------------------------- Tests for netsed field columns --------------------------------------------
@@ -668,14 +668,14 @@
(testing "single column indexes are synced correctly"
(is (= #{{:type :normal-column-index :value "id"}
{:type :normal-column-index :value "indexed"}}
- (describe-table-indexes (t2/select-one :model/Table (mt/id :single_index))))))
+ (describe-table-indexes (t2/select-one :model/Table :id (mt/id :single_index))))))
(testing "for composite indexes, we only care about the 1st column"
(jdbc/execute! (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
(sql.tx/create-index-sql driver/*driver* "composite_index" ["first" "second"]))
(sync/sync-database! (mt/id))
(is (= #{{:type :normal-column-index :value "id"}
{:type :normal-column-index :value "first"}}
- (describe-table-indexes (t2/select-one :model/Table (mt/id :composite_index)))))))))
+ (describe-table-indexes (t2/select-one :model/Table :id (mt/id :composite_index)))))))))
(defmethod driver/database-supports? [::driver/driver ::unique-index]
[_driver _feature _database]
@@ -698,7 +698,7 @@
(sql.tx/create-index-sql driver/*driver* "unique_index" ["column"] {:method "hash"}))
(is (= #{{:type :normal-column-index :value "id"}
{:type :normal-column-index :value "column"}}
- (describe-table-indexes (t2/select-one :model/Table (mt/id :unique_index)))))))))
+ (describe-table-indexes (t2/select-one :model/Table :id (mt/id :unique_index)))))))))
(deftest describe-table-indexes-hashed-index-test
(mt/test-drivers (mt/normal-driver-select {:+parent :sql-jdbc
@@ -712,7 +712,7 @@
(sql.tx/create-index-sql driver/*driver* "hashed_index" ["column"] {:unique? true}))
(is (= #{{:type :normal-column-index :value "id"}
{:type :normal-column-index :value "column"}}
- (describe-table-indexes (t2/select-one :model/Table (mt/id :hashed_index)))))))))
+ (describe-table-indexes (t2/select-one :model/Table :id (mt/id :hashed_index)))))))))
(defmethod driver/database-supports? [::driver/driver ::clustered-index]
[_driver _feature _database]
@@ -736,7 +736,7 @@
"CLUSTER clustered_index USING idx_clustered_index_column;")
(is (= #{{:type :normal-column-index :value "id"}
{:type :normal-column-index :value "column"}}
- (describe-table-indexes (t2/select-one :model/Table (mt/id :clustered_index)))))))))
+ (describe-table-indexes (t2/select-one :model/Table :id (mt/id :clustered_index)))))))))
;; FIXME: sqlsever supports conditional index too, but the sqlserver jdbc does not return filter_condition
;; for those indexes so we can't filter those out.
@@ -759,7 +759,7 @@
(jdbc/execute! (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
(sql.tx/create-index-sql driver/*driver* "conditional_index" ["column"] {:condition "id > 2"}))
(is (= #{{:type :normal-column-index :value "id"}}
- (describe-table-indexes (t2/select-one :model/Table (mt/id :conditional_index)))))))))
+ (describe-table-indexes (t2/select-one :model/Table :id (mt/id :conditional_index)))))))))
(deftest describe-fields-are-sorted-test
(mt/test-drivers (mt/normal-drivers-with-feature :describe-fields)
diff --git a/test/metabase/driver/sql_jdbc_test.clj b/test/metabase/driver/sql_jdbc_test.clj
index 2c7f2154dc9..ca811bae04d 100644
--- a/test/metabase/driver/sql_jdbc_test.clj
+++ b/test/metabase/driver/sql_jdbc_test.clj
@@ -37,7 +37,7 @@
(testing "Make sure syncing a table that has a composite pks works"
(mt/test-driver (mt/normal-drivers-with-feature :describe-fields)
(mt/dataset dataset-definition-test/composite-pk
- (let [songs (t2/select-one :model/Table (mt/id :songs))
+ (let [songs (t2/select-one :model/Table :id (mt/id :songs))
fk-metadata (driver/describe-fields driver/*driver* (lib.metadata/database (mt/metadata-provider))
:table-names [(:name songs)]
:schema-names [(:schema songs)])]
diff --git a/test/metabase/driver_test.clj b/test/metabase/driver_test.clj
index 02eff38e300..2fa86cc0bed 100644
--- a/test/metabase/driver_test.clj
+++ b/test/metabase/driver_test.clj
@@ -139,7 +139,7 @@
(catch Exception _
false))))))
;; clean up the database
- (t2/delete! :model/Database (u/the-id db))))))))
+ (t2/delete! :model/Database :id (u/the-id db))))))))
(deftest check-can-connect-before-sync-test
(testing "Database sync should short-circuit and fail if the database at the connection has been deleted (metabase#7526)"
@@ -175,7 +175,7 @@
;; so fake it by changing the database details
(let [details (:details (mt/db))
new-details (merge details (tx/bad-connection-details driver/*driver*))]
- (t2/update! :model/Database (u/the-id db) {:details new-details}))
+ (t2/update! :model/Database :id (u/the-id db) {:details new-details}))
;; otherwise destroy the db and use the original details
(tx/destroy-db! driver/*driver* dbdef))
(testing "after deleting a database, sync should fail"
@@ -184,7 +184,7 @@
(testing "2: triggering the sync via the POST /api/database/:id/sync_schema endpoint should fail"
(mt/user-http-request :crowberto :post 422 (str "/database/" (u/the-id db) "/sync_schema"))))
;; clean up the database
- (t2/delete! :model/Database (u/the-id db))))))))
+ (t2/delete! :model/Database :id (u/the-id db))))))))
(deftest ^:parallel supports-table-privileges-matches-implementations-test
(mt/test-drivers (mt/normal-drivers-with-feature :table-privileges)
@@ -366,9 +366,9 @@
(deftest ^:parallel describe-table-fks-test
(testing "`describe-fks` should be usable in the way we used to use the old `describe-table-fks` method"
(mt/test-drivers (mt/normal-drivers-with-feature :metadata/key-constraints)
- (let [orders (t2/select-one [:model/Table :name :schema] (mt/id :orders))
- products (t2/select-one [:model/Table :name :schema] (mt/id :products))
- people (t2/select-one [:model/Table :name :schema] (mt/id :people))
+ (let [orders (t2/select-one [:model/Table :name :schema] :id (mt/id :orders))
+ products (t2/select-one [:model/Table :name :schema] :id (mt/id :products))
+ people (t2/select-one [:model/Table :name :schema] :id (mt/id :people))
fmt (partial ddl.i/format-name driver/*driver*)]
(is (= #{{:fk-table-schema (:schema orders)
:fk-table-name (:name orders)
@@ -395,9 +395,9 @@
(mt/test-drivers (mt/normal-drivers-with-feature :metadata/key-constraints)
(let [db (lib.metadata/database (mt/metadata-provider))
fmt (partial ddl.i/format-name driver/*driver*)
- orders (t2/select-one :model/Table (mt/id :orders))
- products (t2/select-one :model/Table (mt/id :products))
- people (t2/select-one :model/Table (mt/id :people))
+ orders (t2/select-one :model/Table :id (mt/id :orders))
+ products (t2/select-one :model/Table :id (mt/id :products))
+ people (t2/select-one :model/Table :id (mt/id :people))
entire-db-fks (driver/describe-fks driver/*driver* (driver.u/ensure-lib-database db))
schema-db-fks (driver/describe-fks driver/*driver* (driver.u/ensure-lib-database db)
:schema-names (when (:schema orders) [(:schema orders)]))
diff --git a/test/metabase/eid_translation/util_test.clj b/test/metabase/eid_translation/util_test.clj
index 6f38b61aa9c..cdfb5f6b390 100644
--- a/test/metabase/eid_translation/util_test.clj
+++ b/test/metabase/eid_translation/util_test.clj
@@ -97,7 +97,7 @@
:model/Segment {segment_id :id segment_eid :entity_id} {}
:model/Timeline {timeline_id :id timeline_eid :entity_id} {}]
(let [core_user_eid (u/generate-nano-id)]
- (t2/update! :model/User core_user_id {:entity_id core_user_eid})
+ (t2/update! :model/User :id core_user_id {:entity_id core_user_eid})
(is (= {action_eid {:id action_id :type :action :status :ok}
collection_eid {:id collection_id :type :collection :status :ok}
core_user_eid {:id core_user_id :type :user :status :ok}
diff --git a/test/metabase/embedding_rest/api/embed_test.clj b/test/metabase/embedding_rest/api/embed_test.clj
index effcbf3003b..c397eaa2df5 100644
--- a/test/metabase/embedding_rest/api/embed_test.clj
+++ b/test/metabase/embedding_rest/api/embed_test.clj
@@ -1268,11 +1268,11 @@
(mt/with-temporary-setting-values [enable-embedding-modular true]
(with-new-secret-key!
(api.card-test/with-card-param-values-fixtures [{:keys [card field-filter-card param-keys]}]
- (t2/update! :model/Card (:id field-filter-card)
+ (t2/update! :model/Card :id (:id field-filter-card)
{:enable_embedding true
:embedding_params (zipmap (map :slug (:parameters field-filter-card))
(repeat "enabled"))})
- (t2/update! :model/Card (:id card)
+ (t2/update! :model/Card :id (:id card)
{:enable_embedding true
:embedding_params (zipmap (map :slug (:parameters card))
(repeat "enabled"))})
@@ -1450,7 +1450,7 @@
(mt/with-additional-premium-features #{:sandboxes :advanced-permissions :impersonation}
(with-embedding-enabled-and-new-secret-key!
(api.dashboard-test/with-chain-filter-fixtures [{:keys [dashboard], :as m}]
- (t2/update! :model/Dashboard (u/the-id dashboard) {:enable_embedding true})
+ (t2/update! :model/Dashboard :id (u/the-id dashboard) {:enable_embedding true})
(letfn [(token [params]
(dash-token dashboard (when params {:params params})))
(values-url [& [params param-key]]
@@ -1470,7 +1470,7 @@
(deftest chain-filter-embedding-disabled-test
(with-chain-filter-fixtures! [{:keys [dashboard values-url search-url]}]
(testing "without embedding enabled for dashboard"
- (t2/update! :model/Dashboard (u/the-id dashboard) {:enable_embedding false})
+ (t2/update! :model/Dashboard :id (u/the-id dashboard) {:enable_embedding false})
(testing "GET /api/embed/dashboard/:token/params/:param-key/values"
(is (= "Embedding is not enabled for this object."
(client/client :get 400 (values-url)))))
@@ -1491,7 +1491,7 @@
(deftest params-with-static-list-test
(testing "embedding with parameter that has source is a static list"
(with-chain-filter-fixtures! [{:keys [dashboard values-url search-url]}]
- (t2/update! :model/Dashboard (:id dashboard)
+ (t2/update! :model/Dashboard :id (:id dashboard)
{:embedding_params {"static_category" "enabled", "static_category_label" "enabled"}})
(testing "Should work if the param we're fetching values for is enabled"
(testing "\nGET /api/embed/dashboard/:token/params/:param-key/values"
@@ -1506,7 +1506,7 @@
(deftest embed-dashboard-card-source-param-values-test
(testing "GET /api/embed/dashboard/:token/params/:key/values works for a card-source parameter"
(with-chain-filter-fixtures! [{:keys [dashboard values-url]}]
- (t2/update! :model/Dashboard (u/the-id dashboard)
+ (t2/update! :model/Dashboard :id (u/the-id dashboard)
{:parameters (mapv (fn [p] (cond-> p (= (:id p) "_CARD_") (assoc :slug "card")))
(:parameters dashboard))
:embedding_params {"card" "enabled"}})
@@ -1514,7 +1514,7 @@
(deftest chain-filter-enabled-params-test
(with-chain-filter-fixtures! [{:keys [dashboard values-url search-url]}]
- (t2/update! :model/Dashboard (:id dashboard)
+ (t2/update! :model/Dashboard :id (:id dashboard)
{:embedding_params {"category_id" "enabled", "category_name" "enabled", "price" "enabled"}})
(testing "Should work if the param we're fetching values for is enabled"
(testing "\nGET /api/embed/dashboard/:token/params/:param-key/values"
@@ -1555,7 +1555,7 @@
(mt/with-temp-copy-of-db
(mt/with-no-data-perms-for-all-users!
(with-chain-filter-fixtures! [{:keys [dashboard values-url search-url]}]
- (t2/update! :model/Dashboard (:id dashboard)
+ (t2/update! :model/Dashboard :id (:id dashboard)
{:embedding_params {"category_id" "enabled", "category_name" "enabled", "price" "enabled"}})
(testing "Should work if the param we're fetching values for is enabled"
(testing "\nGET /api/embed/dashboard/:token/params/:param-key/values"
@@ -1570,14 +1570,14 @@
(deftest chain-filter-locked-params-test
(with-chain-filter-fixtures! [{:keys [dashboard values-url search-url]}]
(testing "Requests should fail if searched param is locked"
- (t2/update! :model/Dashboard (:id dashboard)
+ (t2/update! :model/Dashboard :id (:id dashboard)
{:embedding_params {"category_id" "locked", "category_name" "locked"}})
(doseq [url [(values-url) (search-url)]]
(testing (str "\n" url)
(is (re= #"Cannot search for values: \"category_(?:(?:name)|(?:id))\" is not an enabled parameter."
(client/client :get 400 url))))))
(testing "Search param enabled\n"
- (t2/update! :model/Dashboard (:id dashboard)
+ (t2/update! :model/Dashboard :id (:id dashboard)
{:embedding_params {"category_id" "enabled", "category_name" "enabled", "price" "locked"}})
(testing "Requests should fail if the token is missing a locked parameter"
(doseq [url [(values-url) (search-url)]]
@@ -1603,14 +1603,14 @@
(deftest chain-filter-disabled-params-test
(with-chain-filter-fixtures! [{:keys [dashboard values-url search-url]}]
(testing "Requests should fail if searched param is disabled"
- (t2/update! :model/Dashboard (:id dashboard)
+ (t2/update! :model/Dashboard :id (:id dashboard)
{:embedding_params {"category_id" "disabled", "category_name" "disabled"}})
(doseq [url [(values-url) (search-url)]]
(testing (str "\n" url)
(is (re= #"Cannot search for values: \"category_(?:(?:name)|(?:id))\" is not an enabled parameter\."
(client/client :get 400 url))))))
(testing "Search param enabled\n"
- (t2/update! :model/Dashboard (:id dashboard)
+ (t2/update! :model/Dashboard :id (:id dashboard)
{:embedding_params {"category_id" "enabled", "category_name" "enabled", "price" "disabled"}})
(testing "Requests should fail if the token has a disabled parameter"
(doseq [url-fn [values-url search-url]
@@ -2099,7 +2099,7 @@
(with-temp-dashcard [dashcard {:dash {:enable_embedding true
:last_viewed_at #t "2000-01-01"}}]
(let [dashboard-id (t2/select-one-fn :id :model/Dashboard :id (:dashboard_id dashcard))
- original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard dashboard-id)]
+ original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard :id dashboard-id)]
(mt/with-temporary-setting-values [synchronous-batch-updates true]
(client/client :get 202 (dashcard-url dashcard))
(is (not= original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard :id dashboard-id))))))))))
@@ -2412,7 +2412,7 @@
:card_id (:id card)
:target [:dimension (mt/$ids venues $name)]}]}]
(with-embedding-enabled-and-new-secret-key!
- (t2/update! :model/Dashboard (:id dashboard)
+ (t2/update! :model/Dashboard :id (:id dashboard)
{:enable_embedding true
:embedding_params {"name_contains" "enabled"}})
(letfn [(dashcard-query-url [params]
diff --git a/test/metabase/embedding_rest/api/preview_embed_test.clj b/test/metabase/embedding_rest/api/preview_embed_test.clj
index 402c5ec5175..bf28f2a1ec9 100644
--- a/test/metabase/embedding_rest/api/preview_embed_test.clj
+++ b/test/metabase/embedding_rest/api/preview_embed_test.clj
@@ -649,9 +649,9 @@
(testing "embedding with parameter that has source is a static list"
(with-embedding-enabled-and-new-secret-key!
(api.dashboard-test/with-chain-filter-fixtures [{:keys [dashboard]}]
- (t2/update! :model/Dashboard (u/the-id dashboard) {:enable_embedding false ;; works without enabling embedding on the dashboard (#44962)
- :embedding_params {"static_category" "enabled"
- "static_category_label" "enabled"}})
+ (t2/update! :model/Dashboard :id (u/the-id dashboard) {:enable_embedding false ;; works without enabling embedding on the dashboard (#44962)
+ :embedding_params {"static_category" "enabled"
+ "static_category_label" "enabled"}})
(let [signed-token (dash-token dashboard)
url (format "preview_embed/dashboard/%s/params/%s/values" signed-token "_STATIC_CATEGORY_")]
(testing "Should work if the param we're fetching values for is enabled"
@@ -677,8 +677,8 @@
(testing "GET /api/preview_embed/dashboard/:token/params/:param-key/search/:prefix"
(with-embedding-enabled-and-new-secret-key!
(api.dashboard-test/with-chain-filter-fixtures [{:keys [dashboard]}]
- (t2/update! :model/Dashboard (u/the-id dashboard) {:enable_embedding false ;; works without enabling embedding on the dashboard (#44962)
- :embedding_params {"static_category_label" "enabled"}})
+ (t2/update! :model/Dashboard :id (u/the-id dashboard) {:enable_embedding false ;; works without enabling embedding on the dashboard (#44962)
+ :embedding_params {"static_category_label" "enabled"}})
(let [signed-token (dash-token dashboard)
search-url (format "preview_embed/dashboard/%s/params/%s/search/%s" signed-token "_STATIC_CATEGORY_LABEL_" "AF")]
(testing "Should work if the param we're fetching values for is enabled"
diff --git a/test/metabase/explorations/api_test.clj b/test/metabase/explorations/api_test.clj
index 2492d68fc1f..cd8a58a6e0b 100644
--- a/test/metabase/explorations/api_test.clj
+++ b/test/metabase/explorations/api_test.clj
@@ -106,7 +106,7 @@
:when (nil? (:dataset_query q))]
(when-let [ctx (qp.context/build-row-context q)]
(when-let [dq (qp.variants/dataset-query (:query_type q) ctx)]
- (t2/update! :model/ExplorationQuery (:id q)
+ (t2/update! :model/ExplorationQuery :id (:id q)
{:dataset_query dq
:data_access_token (perms/data-access-token
{:database-id (:database_id q)
@@ -283,7 +283,7 @@
:target [:field {} 999999999]
:table-id (mt/id :venues)}]
;; Replace whatever sync wrote with a minimal pair: one resolvable, one not.
- (t2/update! :model/Card (:id metric)
+ (t2/update! :model/Card :id (:id metric)
{:dimensions [{:id good-id :name "NAME" :display-name "Good"
:effective-type :type/Text}
{:id bad-id :name "ZZZ" :display-name "Unresolvable"
@@ -869,7 +869,7 @@
orig-tid (:id thread)]
(is (pos? (count (:queries thread))) "the first run materialized queries")
;; Simulate a finished run so we can prove restart clears the terminal-state gates.
- (t2/update! :model/ExplorationThread orig-tid
+ (t2/update! :model/ExplorationThread :id orig-tid
{:query_plan_started_at (t/offset-date-time)
:analysis_started_at (t/offset-date-time)
:completed_at (t/offset-date-time)})
@@ -910,7 +910,7 @@
tid (-> created :threads first :id)]
;; Perms ride the thread's parent exploration, resolved by `write-check-thread`.
;; Mark the thread terminal — restart refuses in-flight threads with a 409.
- (t2/update! :model/ExplorationThread tid {:completed_at (t/offset-date-time)})
+ (t2/update! :model/ExplorationThread :id tid {:completed_at (t/offset-date-time)})
(mt/user-http-request other :post 403 (format "exploration/thread/%d/restart" tid))
(let [resp (mt/user-http-request owner :post 200 (format "exploration/thread/%d/restart" tid))]
(is (= 1 (count (:threads resp))) "still a single thread after restart"))))))
@@ -928,7 +928,7 @@
:model/ExplorationThread
{:exploration_id expl-id :name "drill" :position 1
:completed_at (t/offset-date-time)}))]
- (t2/update! :model/ExplorationThread root-tid {:completed_at (t/offset-date-time)})
+ (t2/update! :model/ExplorationThread :id root-tid {:completed_at (t/offset-date-time)})
(mt/user-http-request u :post 200 (format "exploration/thread/%d/restart" root-tid))
(is (nil? (t2/select-one-fn :completed_at :model/ExplorationThread :id root-tid))
"the named (root) thread was reset")
@@ -1178,7 +1178,7 @@
:stored_result_id sr-id})))
(defn- mark-done! [query-id]
- (t2/update! :model/ExplorationQuery query-id {:status "done"}))
+ (t2/update! :model/ExplorationQuery :id query-id {:status "done"}))
(deftest exploration-query-result-streams-stored-result-test
(testing "GET /query/:id streams the stored worker result as JSON"
@@ -1230,7 +1230,7 @@
qid (-> resp :threads first :queries first :id)
;; stands in for a driver error carrying SQL and row values the reader can't query
secret "SECRET_VALUE_FROM_DRIVER_ERROR"]
- (t2/update! :model/ExplorationQuery qid {:status "error" :error_message secret})
+ (t2/update! :model/ExplorationQuery :id qid {:status "error" :error_message secret})
(testing "GET /query/:id — the endpoint that already allowlists its 409 payload"
(let [body (mt/user-http-request u :get 409 (format "exploration/query/%d" qid))]
(is (not (str/includes? (pr-str body) secret)))
@@ -1591,7 +1591,7 @@
:row_count 2}]
(store-fake-result! qid qp-out)
(mark-done! qid)
- (t2/update! :model/ExplorationQuery qid {:dataset_query (:dataset_query metric)})
+ (t2/update! :model/ExplorationQuery :id qid {:dataset_query (:dataset_query metric)})
(let [sr-id (t2/select-one-fn :stored_result_id :model/ExplorationQueryResult
:exploration_query_id qid)
before (t2/select :model/StoredResultUse :stored_result_id sr-id)
@@ -1649,7 +1649,7 @@
:row_count 2}]
(store-fake-result! qid qp-out)
(mark-done! qid)
- (t2/update! :model/ExplorationQuery qid {:dataset_query (:dataset_query metric)})
+ (t2/update! :model/ExplorationQuery :id qid {:dataset_query (:dataset_query metric)})
(let [doc (mt/user-http-request u :post 200
(format "exploration/%d/summary/append" expl-id)
(assoc append-display+viz :exploration_query_ids [qid]))
@@ -1717,7 +1717,7 @@
(store-fake-result! qid qp-out)
(mark-done! qid)
;; Give the EQ a real dataset_query so create-card! has a database_id to inherit.
- (t2/update! :model/ExplorationQuery qid {:dataset_query (:dataset_query metric)})
+ (t2/update! :model/ExplorationQuery :id qid {:dataset_query (:dataset_query metric)})
(let [src-sr-id (t2/select-one-fn :stored_result_id :model/ExplorationQueryResult
:exploration_query_id qid)
doc (t2/select-one :model/Document :id doc-id)
@@ -1757,7 +1757,7 @@
:row_count 2}]
(store-fake-result! qid qp-out)
(mark-done! qid)
- (t2/update! :model/ExplorationQuery qid {:dataset_query (:dataset_query metric)})
+ (t2/update! :model/ExplorationQuery :id qid {:dataset_query (:dataset_query metric)})
(mt/user-http-request u :post 200
(format "exploration/%d/summary/append" eid)
(assoc append-display+viz :exploration_query_ids [qid]))
@@ -2311,7 +2311,7 @@
that leaves canceled_at NULL"
(mt/with-model-cleanup [:model/ExplorationQuery :model/ExplorationThread :model/Exploration :model/Card]
(let [{:keys [thread-id]} (minimal-cancel-fixture! (mt/user->id :rasta) 1)
- _ (t2/update! :model/ExplorationThread thread-id
+ _ (t2/update! :model/ExplorationThread :id thread-id
{:completed_at (t/offset-date-time)})
resp (mt/user-http-request :rasta :post 200 (str "exploration/thread/" thread-id "/cancel"))]
(is (nil? (:canceled_at resp))
@@ -2618,7 +2618,7 @@
:dimensions [{:dimension-id (duid "price") :display-name "Price"}]})]
;; Mark the source thread as a follow-up so the next drill is nested. Any real page works;
;; a made-up id would violate the source_page_id FK.
- (t2/update! :model/ExplorationThread (:thread-id src) {:source_page_id (:page-id src)})
+ (t2/update! :model/ExplorationThread :id (:thread-id src) {:source_page_id (:page-id src)})
(mt/user-http-request :crowberto :post 200
(str "exploration/" (:exploration-id src) "/explore-further")
{:page_id (:page-id src)
@@ -2818,15 +2818,15 @@
(is (pos? (t2/count :model/ExplorationQuery :exploration_thread_id tid))
"its materialized queries are untouched"))
(testing "a canceled thread with a query still mid-QP-execution returns 409"
- (t2/update! :model/ExplorationThread tid
+ (t2/update! :model/ExplorationThread :id tid
{:canceled_at (t/offset-date-time)
:completed_at (t/offset-date-time)})
- (t2/update! :model/ExplorationQuery eq-id {:status "running" :started_at (t/offset-date-time)})
+ (t2/update! :model/ExplorationQuery :id eq-id {:status "running" :started_at (t/offset-date-time)})
(mt/user-http-request u :post 409 (format "exploration/thread/%d/restart" tid))
(is (some? (t2/select-one-fn :completed_at :model/ExplorationThread :id tid))
"the terminal stamp survives — nothing was reset"))
(testing "once no query is mid-execution, restart succeeds and leaves the thread claimable"
- (t2/update! :model/ExplorationQuery eq-id {:status "canceled"})
+ (t2/update! :model/ExplorationQuery :id eq-id {:status "canceled"})
(mt/user-http-request u :post 200 (format "exploration/thread/%d/restart" tid))
(let [thread (t2/select-one :model/ExplorationThread :id tid)]
;; exactly the state the planning worker's claim-unplanned-thread! predicate claims:
@@ -2869,7 +2869,7 @@
(doseq [qid qids]
(store-fake-result! qid qp-out)
(mark-done! qid)
- (t2/update! :model/ExplorationQuery qid {:dataset_query (:dataset_query metric)}))
+ (t2/update! :model/ExplorationQuery :id qid {:dataset_query (:dataset_query metric)}))
{:exploration-id (:id resp) :document-id (-> resp :document :id) :query-ids qids}))
(defn- combine-with-perms-stubbed!
@@ -2910,14 +2910,14 @@
doc (t2/select-one :model/Document :id document-id)
sr-2 (t2/select-one-fn :stored_result_id :model/ExplorationQueryResult
:exploration_query_id (second query-ids))]
- (t2/update! :model/StoredResult sr-2 {:data_access_token {:sandbox {1 "deadbeef"}}})
+ (t2/update! :model/StoredResult :id sr-2 {:data_access_token {:sandbox {1 "deadbeef"}}})
(is (thrown-with-msg?
clojure.lang.ExceptionInfo #"different data-access contexts"
(combine-with-perms-stubbed!
query-ids document-id (:collection_id doc) u
{:display "bar" :visualization-settings {}})))
(testing "and a source with no recorded lens at all is refused too"
- (t2/update! :model/StoredResult sr-2 {:data_access_token nil})
+ (t2/update! :model/StoredResult :id sr-2 {:data_access_token nil})
(is (thrown-with-msg?
clojure.lang.ExceptionInfo #"no recorded data-access context"
(combine-with-perms-stubbed!
@@ -2938,7 +2938,7 @@
(lib/aggregate (lib/count)))))]
;; Give the second source a genuinely different query, so "checked the first one" and
;; "checked them all" are distinguishable.
- (t2/update! :model/ExplorationQuery (second query-ids) {:dataset_query other-q})
+ (t2/update! :model/ExplorationQuery :id (second query-ids) {:dataset_query other-q})
(let [checked (atom [])]
(mt/with-dynamic-fn-redefs [query-perms/check-run-permissions-for-query
(fn [q] (swap! checked conj q) nil)]
diff --git a/test/metabase/explorations/derived_perms_test.clj b/test/metabase/explorations/derived_perms_test.clj
index f36aa1b67b5..28dc05f8804 100644
--- a/test/metabase/explorations/derived_perms_test.clj
+++ b/test/metabase/explorations/derived_perms_test.clj
@@ -393,7 +393,7 @@
(mt/with-temp [:model/Collection {coll-id :id} {}]
;; Put the exploration somewhere the viewer can read, so anything withheld below is withheld
;; by the data-access gate rather than by collection permissions.
- (t2/update! :model/Exploration expl-id {:collection_id coll-id})
+ (t2/update! :model/Exploration :id expl-id {:collection_id coll-id})
(perms/grant-collection-read-permissions! (perms-group/all-users) coll-id)
(mt/user-http-request :lucky :post 200 "comment/"
{:target_type "exploration"
diff --git a/test/metabase/explorations/impl_test.clj b/test/metabase/explorations/impl_test.clj
index bdedef8b2f4..78c39664489 100644
--- a/test/metabase/explorations/impl_test.clj
+++ b/test/metabase/explorations/impl_test.clj
@@ -451,7 +451,7 @@
(defn- wipe-dimensions!
"Simulate a metric row whose dimensions were never synced, bypassing Card transforms/hooks."
[metric-id]
- (t2/update! (t2/table-name :model/Card) metric-id {:dimensions nil :dimension_mappings nil}))
+ (t2/update! (t2/table-name :model/Card) :id metric-id {:dimensions nil :dimension_mappings nil}))
(deftest exploration-data-heals-missing-dimensions-test
(testing "a metric on an MBQL model with NULL dimensions is synced and persisted on read"
@@ -504,7 +504,7 @@
:database_id (mt/id)
:dataset_query (mt/native-query
{:query "SELECT ID, NAME FROM VENUES"})}]
- (t2/update! (t2/table-name :model/Card) (:id model) {:result_metadata nil})
+ (t2/update! (t2/table-name :model/Card) :id (:id model) {:result_metadata nil})
(mt/with-temp [:model/Card metric {:name "Metric on metadata-less model"
:type :metric
:database_id (mt/id)
diff --git a/test/metabase/explorations/runner_test.clj b/test/metabase/explorations/runner_test.clj
index b17372f8ec0..cbb75e02dec 100644
--- a/test/metabase/explorations/runner_test.clj
+++ b/test/metabase/explorations/runner_test.clj
@@ -426,7 +426,7 @@
Bypasses the API to keep these tests focused on the runner-side guards."
[thread-id]
(let [now (OffsetDateTime/now)]
- (t2/update! :model/ExplorationThread thread-id
+ (t2/update! :model/ExplorationThread :id thread-id
{:canceled_at now :completed_at now})))
(deftest run-query-skips-canceled-thread-test
@@ -510,7 +510,7 @@
(mt/with-temp [:model/User u {:email "[email protected]"}]
(let [thread (temp-thread! (:id u))
called (atom 0)]
- (t2/update! :model/ExplorationThread (:id thread) {:started_at (OffsetDateTime/now)})
+ (t2/update! :model/ExplorationThread :id (:id thread) {:started_at (OffsetDateTime/now)})
(cancel-thread! (:id thread))
(mt/with-dynamic-fn-redefs [metabase.explorations.query-plan/generate-query-plan!
(fn [_] (swap! called inc) :ok)]
@@ -525,7 +525,7 @@
;; Set started_at so the thread is past the draft phase. No EQs and no timeline pairs
;; means the two NOT-EXISTS predicates trivially hold — without canceled_at IS NULL, the
;; CAS would fire.
- (t2/update! :model/ExplorationThread (:id thread)
+ (t2/update! :model/ExplorationThread :id (:id thread)
{:started_at (OffsetDateTime/now)})
(cancel-thread! (:id thread))
(is (false? (claim-analysis-if-ready! (:id thread)))
@@ -540,7 +540,7 @@
completed_at nil, stranding the client on a spinner forever."
(mt/with-temp [:model/User u {:email "[email protected]"}]
(let [thread (temp-thread! (:id u))]
- (t2/update! :model/ExplorationThread (:id thread) {:started_at (OffsetDateTime/now)})
+ (t2/update! :model/ExplorationThread :id (:id thread) {:started_at (OffsetDateTime/now)})
;; no pending queries → the claim fires
(is (true? (claim-analysis-if-ready! (:id thread))))
(let [after (t2/select-one :model/ExplorationThread :id (:id thread))]
@@ -553,7 +553,7 @@
write cannot be lost to a crash after the claim commits"
(mt/with-temp [:model/User u {:email "[email protected]"}]
(let [thread (temp-thread! (:id u))]
- (t2/update! :model/ExplorationThread (:id thread) {:started_at (OffsetDateTime/now)})
+ (t2/update! :model/ExplorationThread :id (:id thread) {:started_at (OffsetDateTime/now)})
(runner/maybe-complete-thread! (:id thread))
(is (some? (:completed_at (t2/select-one :model/ExplorationThread :id (:id thread))))
"completed_at is set by the time maybe-complete-thread! returns")))))
@@ -597,7 +597,7 @@
:dataset_query (lib/->legacy-MBQL (let [mp (mt/metadata-provider)] (-> (lib/query mp (lib.metadata/table mp (mt/id :venues))) (lib/aggregate (lib/count)))))}]
(let [thread (temp-thread! (:id u))
called (atom 0)]
- (t2/update! :model/ExplorationThread (:id thread) {:started_at (OffsetDateTime/now)})
+ (t2/update! :model/ExplorationThread :id (:id thread) {:started_at (OffsetDateTime/now)})
(pending-query! (:id thread) (:id card)
(lib/->legacy-MBQL (let [mp (mt/metadata-provider)] (-> (lib/query mp (lib.metadata/table mp (mt/id :venues))) (lib/aggregate (lib/count))))))
(mt/with-dynamic-fn-redefs [metabase.explorations.query-plan/generate-query-plan!
@@ -614,7 +614,7 @@
(let [thread (temp-thread! (:id u))
called (atom 0)]
;; a planner that claimed this thread long ago and died before inserting anything
- (t2/update! :model/ExplorationThread (:id thread)
+ (t2/update! :model/ExplorationThread :id (:id thread)
{:started_at (.minusMinutes (OffsetDateTime/now) 30)
:query_plan_started_at (.minusMinutes (OffsetDateTime/now) 30)})
(mt/with-dynamic-fn-redefs [metabase.explorations.query-plan/generate-query-plan!
@@ -632,7 +632,7 @@
(let [thread (temp-thread! (:id u))
called (atom 0)]
;; the thread planned, produced no queries, and its analysis was already claimed/completed
- (t2/update! :model/ExplorationThread (:id thread)
+ (t2/update! :model/ExplorationThread :id (:id thread)
{:started_at (OffsetDateTime/now)
:analysis_started_at (OffsetDateTime/now)})
(mt/with-dynamic-fn-redefs [metabase.explorations.query-plan/generate-query-plan!
@@ -647,7 +647,7 @@
polling and the failure is diagnosable"
(mt/with-temp [:model/User u {:email "[email protected]"}]
(let [thread (temp-thread! (:id u))]
- (t2/update! :model/ExplorationThread (:id thread) {:started_at (OffsetDateTime/now)})
+ (t2/update! :model/ExplorationThread :id (:id thread) {:started_at (OffsetDateTime/now)})
(runner/fail-plan! (:id thread) "the queue gave up")
(let [after (t2/select-one :model/ExplorationThread :id (:id thread))]
(is (some? (:completed_at after))
@@ -667,7 +667,7 @@
:creator_id (:id u)
:dataset_query (lib/->legacy-MBQL (let [mp (mt/metadata-provider)] (-> (lib/query mp (lib.metadata/table mp (mt/id :venues))) (lib/aggregate (lib/count)))))}]
(let [thread (temp-thread! (:id u))]
- (t2/update! :model/ExplorationThread (:id thread) {:started_at (OffsetDateTime/now)})
+ (t2/update! :model/ExplorationThread :id (:id thread) {:started_at (OffsetDateTime/now)})
(pending-query! (:id thread) (:id card)
(lib/->legacy-MBQL (let [mp (mt/metadata-provider)] (-> (lib/query mp (lib.metadata/table mp (mt/id :venues))) (lib/aggregate (lib/count))))))
(runner/fail-plan! (:id thread) "a duplicate delivery ran out of retries")
@@ -707,7 +707,7 @@
(lib/->legacy-MBQL (let [mp (mt/metadata-provider)] (-> (lib/query mp (lib.metadata/table mp (mt/id :venues))) (lib/aggregate (lib/count))))))]
;; Backdate our pending row 100s; the global oldest-age must be at least that (MIN(created_at)
;; is no later than our row), regardless of other tests' pending rows.
- (t2/update! :model/ExplorationQuery (:id row)
+ (t2/update! :model/ExplorationQuery :id (:id row)
{:created_at (.minusSeconds (OffsetDateTime/now) 100)})
(is (>= (oldest-pending-age-seconds) 100)
"oldest-pending-age is at least the age of our backdated pending row")))))
diff --git a/test/metabase/glossary/api_test.clj b/test/metabase/glossary/api_test.clj
index 764fd4197c9..60562e7e8c0 100644
--- a/test/metabase/glossary/api_test.clj
+++ b/test/metabase/glossary/api_test.clj
@@ -16,7 +16,7 @@
:definition "Application Programming Interface"})
crowberto-id (mt/user->id :crowberto)
glossary-id (:id response)
- creator-id (t2/select-one-fn :creator_id :model/Glossary glossary-id)]
+ creator-id (t2/select-one-fn :creator_id :model/Glossary :id glossary-id)]
(is (= "API" (:term response)))
(is (= "Application Programming Interface" (:definition response)))
(is (pos-int? (:id response)))
diff --git a/test/metabase/health_inspector/core_test.clj b/test/metabase/health_inspector/core_test.clj
index 08ccbe06bb2..58ebd10495f 100644
--- a/test/metabase/health_inspector/core_test.clj
+++ b/test/metabase/health_inspector/core_test.clj
@@ -34,12 +34,12 @@
:entity_id (u/generate-nano-id)
:dataset_query (json/encode bad-query)
:description "bad query")
- bad (t2/insert! :report_card bad-card)]
+ bad (t2/insert-returning-pk! :report_card bad-card)]
(try
(let [{:keys [health message]} (hi/validate-queries)]
(is (< 0 health 100))
(is (= "Some queries are invalid." message)))
- (finally (t2/delete! :report_card bad))))))
+ (finally (t2/delete! :report_card :id bad))))))
(deftest report-db-test
(t2/delete! :health_inspector_runs)
diff --git a/test/metabase/indexed_entities/models/model_index_test.clj b/test/metabase/indexed_entities/models/model_index_test.clj
index ae3cec7f444..1f7171ba8de 100644
--- a/test/metabase/indexed_entities/models/model_index_test.clj
+++ b/test/metabase/indexed_entities/models/model_index_test.clj
@@ -75,7 +75,7 @@
(testing "When the values change the indexed values change"
;; update the filter on the model to simulate different values indexed
(t2/update! :model/Card
- (u/the-id model)
+ :id (u/the-id model)
{:dataset_query (mt/mbql-query products
{:filter [:and
[:> $id 10]
diff --git a/test/metabase/indexes/models/table_index_test.clj b/test/metabase/indexes/models/table_index_test.clj
index f1b3bbe505a..effed3745ec 100644
--- a/test/metabase/indexes/models/table_index_test.clj
+++ b/test/metabase/indexes/models/table_index_test.clj
@@ -76,18 +76,18 @@
:columns [{:name "d"}]}}]
(let [ids (table-index/mark-runnable-indexes-running! [create-id update-id failed-id running-id])]
(is (= #{create-id update-id failed-id running-id} ids))
- (is (= :running (t2/select-one-fn :status :model/TableIndex create-id)))
- (is (= :running (t2/select-one-fn :status :model/TableIndex update-id)))
- (is (= :running (t2/select-one-fn :status :model/TableIndex failed-id)))
- (is (= :running (t2/select-one-fn :status :model/TableIndex running-id)))
- (is (= :delete-pending (t2/select-one-fn :status :model/TableIndex deleted-id)))
- (t2/update! :model/TableIndex create-id {:status :succeeded})
+ (is (= :running (t2/select-one-fn :status :model/TableIndex :id create-id)))
+ (is (= :running (t2/select-one-fn :status :model/TableIndex :id update-id)))
+ (is (= :running (t2/select-one-fn :status :model/TableIndex :id failed-id)))
+ (is (= :running (t2/select-one-fn :status :model/TableIndex :id running-id)))
+ (is (= :delete-pending (t2/select-one-fn :status :model/TableIndex :id deleted-id)))
+ (t2/update! :model/TableIndex :id create-id {:status :succeeded})
(table-index/mark-unverified-running-indexes-failed! ids "not verified")
- (is (= :succeeded (t2/select-one-fn :status :model/TableIndex create-id)))
- (is (= :failed (t2/select-one-fn :status :model/TableIndex update-id)))
- (is (= :failed (t2/select-one-fn :status :model/TableIndex failed-id)))
- (is (= :failed (t2/select-one-fn :status :model/TableIndex running-id)))
- (is (= "not verified" (t2/select-one-fn :error_message :model/TableIndex update-id))))))
+ (is (= :succeeded (t2/select-one-fn :status :model/TableIndex :id create-id)))
+ (is (= :failed (t2/select-one-fn :status :model/TableIndex :id update-id)))
+ (is (= :failed (t2/select-one-fn :status :model/TableIndex :id failed-id)))
+ (is (= :failed (t2/select-one-fn :status :model/TableIndex :id running-id)))
+ (is (= "not verified" (t2/select-one-fn :error_message :model/TableIndex :id update-id))))))
(deftest mark-for-revalidation-test
(testing "every applicable request is flipped to :update-pending, clearing stale errors; delete-pending rows untouched"
@@ -113,11 +113,11 @@
:structured {:kind :btree :name "deleted_idx"
:columns [{:name "d"}]}}]
(table-index/mark-for-revalidation! transform-id)
- (is (= :update-pending (t2/select-one-fn :status :model/TableIndex create-id)))
- (is (= :update-pending (t2/select-one-fn :status :model/TableIndex succeeded-id)))
- (is (= :update-pending (t2/select-one-fn :status :model/TableIndex failed-id)))
- (is (nil? (t2/select-one-fn :error_message :model/TableIndex failed-id)) "stale error cleared")
- (is (= :delete-pending (t2/select-one-fn :status :model/TableIndex deleted-id)) "pending deletion not revived")))
+ (is (= :update-pending (t2/select-one-fn :status :model/TableIndex :id create-id)))
+ (is (= :update-pending (t2/select-one-fn :status :model/TableIndex :id succeeded-id)))
+ (is (= :update-pending (t2/select-one-fn :status :model/TableIndex :id failed-id)))
+ (is (nil? (t2/select-one-fn :error_message :model/TableIndex :id failed-id)) "stale error cleared")
+ (is (= :delete-pending (t2/select-one-fn :status :model/TableIndex :id deleted-id)) "pending deletion not revived")))
(testing "a nil transform-id is a no-op"
(is (nil? (table-index/mark-for-revalidation! nil)))))
@@ -134,7 +134,7 @@
;; :failed is included: its index DDL already ran against a materialized table, so only a full rebuild
;; safely re-attempts it instead of appending duplicate rows from the stale checkpoint.
(doseq [status [:create-pending :update-pending :delete-pending :running :failed]]
- (t2/update! :model/TableIndex index-id {:status status})
+ (t2/update! :model/TableIndex :id index-id {:status status})
(is (true? (table-index/pending-changes-for-transform? transform-id))
(str status " forces a full rebuild")))))
(testing "a nil transform-id is not pending"
@@ -193,10 +193,10 @@
:status :delete-pending
:structured {:kind :btree :name "deleted_idx"
:columns [{:name "c"}]}}]
- (t2/update! :model/Transform transform-id {:target (assoc (:target transform) :name (mt/random-name))})
- (is (= :update-pending (t2/select-one-fn :status :model/TableIndex create-id)))
- (is (= :update-pending (t2/select-one-fn :status :model/TableIndex succeeded-id)))
- (is (= :delete-pending (t2/select-one-fn :status :model/TableIndex deleted-id))))))
+ (t2/update! :model/Transform :id transform-id {:target (assoc (:target transform) :name (mt/random-name))})
+ (is (= :update-pending (t2/select-one-fn :status :model/TableIndex :id create-id)))
+ (is (= :update-pending (t2/select-one-fn :status :model/TableIndex :id succeeded-id)))
+ (is (= :delete-pending (t2/select-one-fn :status :model/TableIndex :id deleted-id))))))
(deftest deleting-transform-removes-its-indexes-test
(testing "the transform_id FK cascades, so deleting a transform drops its index requests"
@@ -205,5 +205,5 @@
:index_name "idx"
:structured {:kind :btree :name "idx" :columns [{:name "a"}]}})
(is (t2/exists? :model/TableIndex :transform_id transform-id))
- (t2/delete! :model/Transform transform-id)
+ (t2/delete! :model/Transform :id transform-id)
(is (not (t2/exists? :model/TableIndex :transform_id transform-id))))))
diff --git a/test/metabase/indexes_rest/api_test.clj b/test/metabase/indexes_rest/api_test.clj
index 832f09fc408..d39cdcce3dc 100644
--- a/test/metabase/indexes_rest/api_test.clj
+++ b/test/metabase/indexes_rest/api_test.clj
@@ -191,13 +191,13 @@
(mt/with-temp [:model/Transform {transform-id :id} (assoc (temp-incremental-transform-spec)
:last_checkpoint_value "100")]
(letfn [(full-run? []
- (transforms-base.u/full-incremental-run? (t2/select-one :model/Transform transform-id)))]
+ (transforms-base.u/full-incremental-run? (t2/select-one :model/Transform :id transform-id)))]
(testing "no index changes: the watermark alone decides, so the next run appends"
(is (not (full-run?))))
(testing "POST leaves the watermark alone; the pending row forces the rebuild"
(let [created (mt/user-http-request :crowberto :post 200 "index/request"
{:transform_id transform-id :structured btree})]
- (is (= "100" (t2/select-one-fn :last_checkpoint_value :model/Transform transform-id)))
+ (is (= "100" (t2/select-one-fn :last_checkpoint_value :model/Transform :id transform-id)))
(is (full-run?))
(testing "PUT keeps forcing it (update-pending)"
(mt/user-http-request :crowberto :put 200 (str "index/request/" (:id created))
@@ -207,7 +207,7 @@
(mt/user-http-request :crowberto :delete 204 (str "index/request/" (:id created)))
(is (full-run?)))
(testing "once the request settles, runs go back to appending"
- (t2/update! (t2/table-name :model/TableIndex) (:id created) {:status "succeeded"})
+ (t2/update! (t2/table-name :model/TableIndex) :id (:id created) {:status "succeeded"})
(is (not (full-run?)))))))))
(deftest inline-kind-index-name-test
diff --git a/test/metabase/lib_be/metadata/jvm_test.clj b/test/metabase/lib_be/metadata/jvm_test.clj
index c640939450a..467770c3c5f 100644
--- a/test/metabase/lib_be/metadata/jvm_test.clj
+++ b/test/metabase/lib_be/metadata/jvm_test.clj
@@ -19,7 +19,7 @@
[toucan2.core :as t2]))
(deftest ^:parallel fetch-field-test
- (let [field (t2/select-one :metadata/column (mt/id :categories :id))]
+ (let [field (t2/select-one :metadata/column :id (mt/id :categories :id))]
(is (not (me/humanize (mr/explain ::lib.schema.metadata/column field))))))
(deftest ^:parallel fetch-database-test
diff --git a/test/metabase/mcp/task/mcp_query_handle_gc_test.clj b/test/metabase/mcp/task/mcp_query_handle_gc_test.clj
index 12d45aead53..e6ac4fd1b57 100644
--- a/test/metabase/mcp/task/mcp_query_handle_gc_test.clj
+++ b/test/metabase/mcp/task/mcp_query_handle_gc_test.clj
@@ -25,7 +25,7 @@
(let [uid (mt/user->id :rasta)
old (mint! uid)
fresh (mint! uid)]
- (t2/update! :model/McpQueryHandle old {:created_at (hours-ago 25)}) ; default TTL is 24h
+ (t2/update! :model/McpQueryHandle :id old {:created_at (hours-ago 25)}) ; default TTL is 24h
(#'gc/gc-expired-query-handles!)
(testing "a handle older than the TTL is deleted"
(is (nil? (t2/select-one :model/McpQueryHandle :id old))))
@@ -37,7 +37,7 @@
(mt/with-temporary-setting-values [mcp-query-handle-ttl-hours 1]
(let [uid (mt/user->id :rasta)
h (mint! uid)]
- (t2/update! :model/McpQueryHandle h {:created_at (hours-ago 2)})
+ (t2/update! :model/McpQueryHandle :id h {:created_at (hours-ago 2)})
(#'gc/gc-expired-query-handles!)
(is (nil? (t2/select-one :model/McpQueryHandle :id h))
"a 2h-old handle is deleted when the TTL is set to 1h")))))
diff --git a/test/metabase/mcp/v2/api_test.clj b/test/metabase/mcp/v2/api_test.clj
index eedd0aabff7..f65c82aebe4 100644
--- a/test/metabase/mcp/v2/api_test.clj
+++ b/test/metabase/mcp/v2/api_test.clj
@@ -1257,7 +1257,7 @@
(defn- orders-query
"A portable MBQL 5 query over the test data Orders table."
[]
- (let [table (t2/select-one :model/Table (mt/id :orders))]
+ (let [table (t2/select-one :model/Table :id (mt/id :orders))]
{:lib/type "mbql/query"
:stages [{:lib/type "mbql.stage/mbql"
:source-table [(:name (mt/db)) (:schema table) (:name table)]
diff --git a/test/metabase/mcp/v2/redaction_test.clj b/test/metabase/mcp/v2/redaction_test.clj
index 7d05546c8b1..729e88f75ee 100644
--- a/test/metabase/mcp/v2/redaction_test.clj
+++ b/test/metabase/mcp/v2/redaction_test.clj
@@ -156,7 +156,7 @@
"The hydrated-and-redacted handlers of the persisted notification `notification-id`, as the
current user sees them."
[notification-id]
- (-> (t2/select-one :model/Notification notification-id)
+ (-> (t2/select-one :model/Notification :id notification-id)
redaction/hydrate-and-redact-notification
:handlers))
diff --git a/test/metabase/mcp/v2/tools/alert_test.clj b/test/metabase/mcp/v2/tools/alert_test.clj
index 82c596ecf4f..9d75630e9b6 100644
--- a/test/metabase/mcp/v2/tools/alert_test.clj
+++ b/test/metabase/mcp/v2/tools/alert_test.clj
@@ -538,12 +538,12 @@
:notification {:creator_id (mt/user->id :crowberto)}
:notification-card {:send_condition :goal_above}
:handlers []}]
- (t2/update! :model/NotificationCard (:payload_id notification) {:card_id card-id})
+ (t2/update! :model/NotificationCard :id (:payload_id notification) {:card_id card-id})
(testing "the fixture really stored a goal condition — with anything else stored, the
assertions below pass even against code that re-checks the goal on every update,
and this test guards nothing"
(is (= :goal_above (t2/select-one-fn :send_condition :model/NotificationCard
- (:payload_id notification)))))
+ :id (:payload_id notification)))))
(is (false? (:active (tool-result (call-tool! :crowberto v2.tu/all-scopes
(wire {:method "update" :id (:id notification)
:active false}))))))
diff --git a/test/metabase/mcp/v2/tools/browse_test.clj b/test/metabase/mcp/v2/tools/browse_test.clj
index 693227404da..859234c596f 100644
--- a/test/metabase/mcp/v2/tools/browse_test.clj
+++ b/test/metabase/mcp/v2/tools/browse_test.clj
@@ -748,7 +748,7 @@
:database_id tenant-b :table_id b-orders}]
;; The table is created on the router and moved: inserting it directly on a destination trips
;; the after-insert permission grant, which destinations are forbidden to carry.
- (t2/update! :model/Table b-orders {:db_id tenant-b})
+ (t2/update! :model/Table :id b-orders {:db_id tenant-b})
(mt/with-full-data-perms-for-all-users!
(mt/with-test-user :rasta
(is (mi/can-read? (t2/select-one :model/Database :id tenant-b))
diff --git a/test/metabase/mcp/v2/tools/content_test.clj b/test/metabase/mcp/v2/tools/content_test.clj
index a491d9fe9ca..3c27aa21836 100644
--- a/test/metabase/mcp/v2/tools/content_test.clj
+++ b/test/metabase/mcp/v2/tools/content_test.clj
@@ -1089,7 +1089,7 @@
(is (nil? (:error row)))
(is (re-find #"hello" (:content_markdown row))
"the read still returns the body")))
- (is (= 0 (t2/select-one-fn :view_count :model/Document doc-id))
+ (is (= 0 (t2/select-one-fn :view_count :model/Document :id doc-id))
"and left view_count alone"))))
(deftest get-content-dimensions-respects-a-curated-metric-test
@@ -1109,7 +1109,7 @@
(metrics/sync-dimensions! :metadata/metric metric-id)
(let [seeded (t2/select-one-fn :dimensions :model/Card :id metric-id)]
(is (seq seeded) "the metric must seed at least one dimension for this to prove anything")
- (t2/update! :model/Card metric-id {:dimensions (vec (take 1 seeded))})
+ (t2/update! :model/Card :id metric-id {:dimensions (vec (take 1 seeded))})
(mt/with-test-user :crowberto
(let [row (content-one {:items [{:type "metric" :id metric-id}] :include ["dimensions"]})
again (content-one {:items [{:type "metric" :id metric-id}] :include ["dimensions"]})]
@@ -1182,7 +1182,7 @@
(metrics/sync-dimensions! :metadata/metric metric-id)
(let [{:keys [dimensions dimension_mappings]} (t2/select-one :model/Card :id metric-id)
orphan-id (:id (first dimensions))]
- (t2/update! :model/Card metric-id
+ (t2/update! :model/Card :id metric-id
{:dimension_mappings (mapv #(cond-> %
(= orphan-id (:dimension-id %))
(assoc-in [:target 2] (mt/id :users :name)))
diff --git a/test/metabase/mcp/v2/tools/document_test.clj b/test/metabase/mcp/v2/tools/document_test.clj
index 343653187b8..a1238d3aef3 100644
--- a/test/metabase/mcp/v2/tools/document_test.clj
+++ b/test/metabase/mcp/v2/tools/document_test.clj
@@ -211,7 +211,7 @@
(let [doc-id (:id (created! (call {:method "create"
:name "Old name"
:content_markdown "Stable body."})))]
- (t2/update! :model/Document doc-id {:document unrenderable-body})
+ (t2/update! :model/Document :id doc-id {:document unrenderable-body})
(testing "a metadata-only update lands and is reported as the success it is — the write
commits before the response is built, so a body this tool can't render must not
turn a completed write into a failed call"
diff --git a/test/metabase/mcp/v2/tools/duplicate_test.clj b/test/metabase/mcp/v2/tools/duplicate_test.clj
index c23aa88d361..04e5587b99e 100644
--- a/test/metabase/mcp/v2/tools/duplicate_test.clj
+++ b/test/metabase/mcp/v2/tools/duplicate_test.clj
@@ -249,7 +249,7 @@
(doseq [[model id type] [[:model/Card card-id "question"]
[:model/Dashboard dash-id "dashboard"]
[:model/Document doc-id "document"]]]
- (t2/update! model id {:archived true :archived_directly true})
+ (t2/update! model :id id {:archived true :archived_directly true})
(testing type
(is (= (format "%s %d is in the trash — restore it before duplicating." (name model) id)
(tool-error (call-tool! :crowberto {:type type :id id}))))))
diff --git a/test/metabase/measures/models/measure_test.clj b/test/metabase/measures/models/measure_test.clj
index 4945c8f326f..52111988279 100644
--- a/test/metabase/measures/models/measure_test.clj
+++ b/test/metabase/measures/models/measure_test.clj
@@ -49,7 +49,7 @@
(is (thrown-with-msg?
Exception
#"does not exist"
- (t2/update! :model/Measure measure-id {:definition (measure-definition-referencing 99999)})))))
+ (t2/update! :model/Measure :id measure-id {:definition (measure-definition-referencing 99999)})))))
(testing "Updating a measure to reference itself should fail"
(mt/with-temp [:model/Measure {measure-id :id} {:name "Measure"
:table_id (mt/id :venues)
@@ -58,7 +58,7 @@
(is (thrown-with-msg?
Exception
#"[Cc]ycle"
- (t2/update! :model/Measure measure-id {:definition (measure-definition-referencing measure-id)})))))
+ (t2/update! :model/Measure :id measure-id {:definition (measure-definition-referencing measure-id)})))))
(testing "Updating a measure to create an indirect cycle should fail"
(mt/with-temp [:model/Measure {measure-1-id :id} {:name "Measure 1"
:table_id (mt/id :venues)
@@ -71,7 +71,7 @@
(is (thrown-with-msg?
Exception
#"[Cc]ycle"
- (t2/update! :model/Measure measure-1-id {:definition (measure-definition-referencing measure-2-id)}))))))
+ (t2/update! :model/Measure :id measure-1-id {:definition (measure-definition-referencing measure-2-id)}))))))
;;; ------------------------------------------------ Metric Reference Tests ------------------------------------------------
@@ -135,7 +135,7 @@
(is (thrown-with-msg?
Exception
#"[Mm]easures cannot reference metrics"
- (t2/update! :model/Measure measure-id
+ (t2/update! :model/Measure :id measure-id
{:definition (measure-definition (lib.metadata/metric mp metric-id))}))))))))
;;; ------------------------------------------------ MBQL4 Rejection Tests ------------------------------------------------
@@ -176,14 +176,14 @@
(is (thrown-with-msg?
Exception
#"Invalid measure definition"
- (t2/update! :model/Measure measure-id
+ (t2/update! :model/Measure :id measure-id
{:definition {:source-table (mt/id :venues)
:aggregation [[:count]]}}))))
(testing "MBQL4 full query"
(is (thrown-with-msg?
Exception
#"Invalid measure definition"
- (t2/update! :model/Measure measure-id
+ (t2/update! :model/Measure :id measure-id
{:definition {:database (mt/id)
:type :query
:query {:source-table (mt/id :venues)
diff --git a/test/metabase/metabot/agent/core_test.clj b/test/metabase/metabot/agent/core_test.clj
index 5457ace5d35..410f94e9749 100644
--- a/test/metabase/metabot/agent/core_test.clj
+++ b/test/metabase/metabot/agent/core_test.clj
@@ -993,7 +993,7 @@
claude/claude
(fn [opts]
(if (= 1 (count (swap! requests conj (claude/claude-request-body opts))))
- (do (t2/update! :model/Dashboard dashboard-id {:name "Ops updated"})
+ (do (t2/update! :model/Dashboard :id dashboard-id {:name "Ops updated"})
(metabot.settings/metabot-chat-system-prompt! "Use American spelling.")
(reset! semantic-search false)
(mut/mock-llm-response [{:type :tool-input
diff --git a/test/metabase/metabot/api/conversations_test.clj b/test/metabase/metabot/api/conversations_test.clj
index a7b8b44561f..d2eb483e0ba 100644
--- a/test/metabase/metabot/api/conversations_test.clj
+++ b/test/metabase/metabot/api/conversations_test.clj
@@ -91,7 +91,7 @@
found (first (filter #(= convo-id (:conversation_id %)) (:data response)))]
(is (some? found))
(is (= 2 (:message_count found)))
- (is (= (t/instant (t2/select-one-fn :created_at :model/MetabotMessage live-id))
+ (is (= (t/instant (t2/select-one-fn :created_at :model/MetabotMessage :id live-id))
(t/instant (t/offset-date-time (:last_message_at found))))))))))
(deftest list-conversations-orders-by-latest-conversation-or-message-created-at-test
@@ -703,7 +703,7 @@
(mt/user-http-request :crowberto :get 200
(str "metabot/conversations/" convo-id))))))
(testing "archived cards drop out of saved_entities"
- (t2/update! :model/Card (:id created) {:archived true})
+ (t2/update! :model/Card :id (:id created) {:archived true})
(is (= []
(:saved_entities
(mt/user-http-request :crowberto :get 200
diff --git a/test/metabase/metabot/api_test.clj b/test/metabase/metabot/api_test.clj
index dca0a8f3ff1..e0bb2589fed 100644
--- a/test/metabase/metabot/api_test.clj
+++ b/test/metabase/metabot/api_test.clj
@@ -1393,7 +1393,7 @@
{:type :usage :model "claude-sonnet-4-6" :usage {:promptTokens 100 :completionTokens 50}}
{:type :data :data-type "state" :data {:step 1}}
{:type :finish}])
- (t2/select-one :model/MetabotMessage assistant-msg-id)))
+ (t2/select-one :model/MetabotMessage :id assistant-msg-id)))
(finally
(t2/delete! :model/MetabotMessage :conversation_id conv-id)
(t2/delete! :model/MetabotConversation :id conv-id))))))
@@ -1435,7 +1435,7 @@
{:type :usage :model "claude-sonnet-4-6" :usage {:promptTokens 1 :completionTokens 1}}
{:type :finish}]
:turn-state {:todos [{:id "1"}]})
- (let [msg (t2/select-one :model/MetabotMessage assistant-msg-id)
+ (let [msg (t2/select-one :model/MetabotMessage :id assistant-msg-id)
part-types (into #{} (map :type) (:data msg))
data-types (into #{}
(keep #(when (str/starts-with? % "data-") (subs % 5)))
diff --git a/test/metabase/metabot/persistence_test.clj b/test/metabase/metabot/persistence_test.clj
index 5f82ed43d9b..d6aa2c515ff 100644
--- a/test/metabase/metabot/persistence_test.clj
+++ b/test/metabase/metabot/persistence_test.clj
@@ -460,14 +460,14 @@
(let [{:keys [assistant-msg-id]} (metabot-persistence/start-turn!
conversation-id "internal"
{:role "user" :content "hi"})
- created-at-before (:created_at (t2/select-one :model/MetabotMessage assistant-msg-id))
+ created-at-before (:created_at (t2/select-one :model/MetabotMessage :id assistant-msg-id))
_ (metabot-persistence/finalize-assistant-turn!
assistant-msg-id
[{:type :text :text "Hello"}
{:type :usage
:model "claude-sonnet-4-6"
:usage {:promptTokens 10 :completionTokens 5}}])
- row (t2/select-one :model/MetabotMessage assistant-msg-id)
+ row (t2/select-one :model/MetabotMessage :id assistant-msg-id)
rows (t2/select :model/MetabotMessage
:conversation_id conversation-id)]
(is (= 2 (count rows)) "no extra row inserted on finalize")
@@ -491,7 +491,7 @@
{:type :text :text "Hello"}
{:type :usage :model "claude" :usage {:promptTokens 250 :completionTokens 30}}])
(is (=? {:context_tokens 160 :total_tokens 280}
- (t2/select-one :model/MetabotMessage assistant-msg-id))))))
+ (t2/select-one :model/MetabotMessage :id assistant-msg-id))))))
(testing "a turn that observed no usage stores no context size"
(with-rasta-tx
(let [conversation-id (str (random-uuid))
@@ -500,7 +500,7 @@
{:role "user" :content "hi"})]
(metabot-persistence/finalize-assistant-turn!
assistant-msg-id [{:type :text :text "Hello"}])
- (is (nil? (:context_tokens (t2/select-one :model/MetabotMessage assistant-msg-id))))))))
+ (is (nil? (:context_tokens (t2/select-one :model/MetabotMessage :id assistant-msg-id))))))))
(deftest ^:parallel messages->client-messages-context-tokens-test
(testing "a message reports the context it occupied, and omits it when the turn observed no usage"
@@ -525,7 +525,7 @@
[{:type :text :text "partial"}]
:finished? false)
(is (=? {:finished false :error nil}
- (t2/select-one :model/MetabotMessage assistant-msg-id)))))
+ (t2/select-one :model/MetabotMessage :id assistant-msg-id)))))
(testing "errored: error map JSON-encoded into the error column"
(let [conversation-id (str (random-uuid))
error-data {:message "boom" :type "RuntimeException"}
@@ -535,7 +535,7 @@
(metabot-persistence/finalize-assistant-turn!
assistant-msg-id []
:error error-data)
- (let [row (t2/select-one :model/MetabotMessage assistant-msg-id)]
+ (let [row (t2/select-one :model/MetabotMessage :id assistant-msg-id)]
(is (true? (:finished row)))
(is (= error-data (json/decode+kw (:error row))))))))))
@@ -740,7 +740,7 @@
b-pk [{:type :text :text "reply-B"}])
;; soft-delete only turn B's assistant reply — its user row stays undeleted
;; and is now the most-recent non-deleted row overall.
- (t2/update! :model/MetabotMessage b-pk {:deleted_at (java.time.OffsetDateTime/now)})
+ (t2/update! :model/MetabotMessage :id b-pk {:deleted_at (java.time.OffsetDateTime/now)})
(is (= a-ext (metabot-persistence/leaf-external-id conversation-id))
"must not fall through to turn B's undeleted user row"))))))))
@@ -834,13 +834,13 @@
(is (= user-ext user-external-id))
(testing "old response is soft-deleted with the deleting user stamped"
(is (=? {:deleted_at some? :deleted_by_user_id (mt/user->id :rasta)}
- (t2/select-one :model/MetabotMessage a-pk))))
+ (t2/select-one :model/MetabotMessage :id a-pk))))
(testing "prompt row stays live"
(is (=? {:deleted_at nil}
(t2/select-one :model/MetabotMessage :external_id user-ext))))
(testing "fresh placeholder is the new leaf"
(is (=? {:finished nil :data [] :deleted_at nil}
- (t2/select-one :model/MetabotMessage assistant-msg-id)))
+ (t2/select-one :model/MetabotMessage :id assistant-msg-id)))
(is (= assistant-external-id
(metabot-persistence/leaf-external-id conversation-id))))
(testing "conversation-detail shows the prompt exactly once"
@@ -875,8 +875,8 @@
:conversation_id conversation-id :role "user")]
(metabot-persistence/retry-turn! conversation-id "internal" user-ext
:delete-message-ids [a-pk extra-pk])
- (is (some? (t2/select-one-fn :deleted_at :model/MetabotMessage a-pk)))
- (is (some? (t2/select-one-fn :deleted_at :model/MetabotMessage extra-pk)))))))))
+ (is (some? (t2/select-one-fn :deleted_at :model/MetabotMessage :id a-pk)))
+ (is (some? (t2/select-one-fn :deleted_at :model/MetabotMessage :id extra-pk)))))))))
(deftest start-turn-delete-message-ids-test
(testing "start-turn! soft-deletes :delete-message-ids alongside inserting the replacement rows"
@@ -1080,7 +1080,7 @@
assistant-msg-id
[{:type :text :text "x"}]
finalize-opts)
- (let [row (t2/select-one :model/MetabotMessage assistant-msg-id)]
+ (let [row (t2/select-one :model/MetabotMessage :id assistant-msg-id)]
[row (first (metabot-persistence/messages->client-messages
[row] {:include-errored? true}))])))))
@@ -1180,7 +1180,7 @@
(metabot-persistence/finalize-assistant-turn!
assistant-msg-id parts
:error error-data)
- (let [row (t2/select-one :model/MetabotMessage assistant-msg-id)]
+ (let [row (t2/select-one :model/MetabotMessage :id assistant-msg-id)]
(is (= {:message "The model provider failed to complete the response"}
(json/decode+kw (:error row)))
"the streamed errorText is persisted into the error column as a {:message ...} map")
@@ -1202,7 +1202,7 @@
(str (random-uuid)) "metabot-1"
{:role "user" :content "go"})]
(apply metabot-persistence/finalize-assistant-turn! assistant-msg-id parts finalize-opts)
- (t2/select-one :model/MetabotMessage assistant-msg-id))))
+ (t2/select-one :model/MetabotMessage :id assistant-msg-id))))
(deftest finalize-assistant-turn-persists-finish-reason-test
(testing "finalize-assistant-turn! records why a turn stopped early"
@@ -1409,7 +1409,7 @@
[{:type :text :text "ok"}]))
(is (=? {:finished true
:data [{:type "text" :text "ok"}]}
- (t2/select-one :model/MetabotMessage assistant-msg-id))
+ (t2/select-one :model/MetabotMessage :id assistant-msg-id))
"message UPDATE still landed")
(is (some #(re-find #"Failed to record metabot used tables" (:message %)) (logs))
"warn line captured")))))))
@@ -1625,7 +1625,7 @@
[{:type :text :text "reply"}]
:turn-state {:queries {"q2" {:database 2}}})]
(is (= {:queries {"q2" {:database 2}}}
- (t2/select-one-fn :state :model/MetabotMessage msg-id)))
+ (t2/select-one-fn :state :model/MetabotMessage :id msg-id)))
(is (nil? (t2/select-one-fn :state :model/MetabotConversation :id conversation-id)))))))
(deftest finalize-skips-empty-turn-state-test
@@ -1634,7 +1634,7 @@
(doseq [turn-opts [[] [:turn-state {}]]]
(let [conversation-id (str (random-uuid))
msg-id (apply seed-turn! conversation-id "hi" [{:type :text :text "reply"}] turn-opts)]
- (is (nil? (t2/select-one-fn :state :model/MetabotMessage msg-id))))))))
+ (is (nil? (t2/select-one-fn :state :model/MetabotMessage :id msg-id))))))))
(deftest conversation-state-rewinds-on-retry-test
(testing "a retried turn's soft-deleted state drops out of the reconstruction"
diff --git a/test/metabase/metabot/task/suggested_prompts_generator_test.clj b/test/metabase/metabot/task/suggested_prompts_generator_test.clj
index 436a24101af..4a794e793ae 100644
--- a/test/metabase/metabot/task/suggested_prompts_generator_test.clj
+++ b/test/metabase/metabot/task/suggested_prompts_generator_test.clj
@@ -41,13 +41,13 @@
{:table_questions []
:metric_questions []}))]
(testing "Non-verified card with use_verified_content=false generates prompts"
- (t2/update! :model/Metabot (:id original-metabot) {:use_verified_content false})
+ (t2/update! :model/Metabot :id (:id original-metabot) {:use_verified_content false})
(#'metabot.task.suggested-prompts-generator/maybe-generate-suggested-prompts!)
(let [prompts (t2/select :model/MetabotPrompt :card_id card-id)]
(is (seq prompts))))
(testing "Non-verified card with use_verified_content=true generates no prompts"
(t2/delete! :model/MetabotPrompt)
- (t2/update! :model/Metabot (:id original-metabot) {:use_verified_content true})
+ (t2/update! :model/Metabot :id (:id original-metabot) {:use_verified_content true})
(#'metabot.task.suggested-prompts-generator/maybe-generate-suggested-prompts!)
(let [prompts (t2/select :model/MetabotPrompt :card_id card-id)]
(is (empty? prompts))))
@@ -62,18 +62,18 @@
:most_recent true}]
(testing "with use_verified_content=true"
(t2/delete! :model/MetabotPrompt)
- (t2/update! :model/Metabot (:id original-metabot) {:use_verified_content true})
+ (t2/update! :model/Metabot :id (:id original-metabot) {:use_verified_content true})
(#'metabot.task.suggested-prompts-generator/maybe-generate-suggested-prompts!)
(let [prompts (t2/select :model/MetabotPrompt :card_id card-id)]
(is (seq prompts))))
(testing "with use_verified_content=false"
(t2/delete! :model/MetabotPrompt)
- (t2/update! :model/Metabot (:id original-metabot) {:use_verified_content false})
+ (t2/update! :model/Metabot :id (:id original-metabot) {:use_verified_content false})
(#'metabot.task.suggested-prompts-generator/maybe-generate-suggested-prompts!)
(let [prompts (t2/select :model/MetabotPrompt :card_id card-id)]
(is (seq prompts))))))
;; Reset metabot state
- (t2/update! :model/Metabot (:id original-metabot) {:use_verified_content false})))))))))
+ (t2/update! :model/Metabot :id (:id original-metabot) {:use_verified_content false})))))))))
(defn- enabled-builtin-metabots-with [internal? embedded?]
(mt/with-dynamic-fn-redefs [metabot.settings/metabot-enabled? (constantly internal?)
@@ -107,7 +107,7 @@
(fn [_]
{:table_questions [{:questions ["What is the total for this model?"]}]
:metric_questions []})]
- (run! #(t2/update! :model/Metabot % {:use_verified_content false}) [internal-id embedded-id])
+ (run! #(t2/update! :model/Metabot :id % {:use_verified_content false}) [internal-id embedded-id])
(#'metabot.task.suggested-prompts-generator/maybe-generate-suggested-prompts!)
(is (seq (t2/select :model/MetabotPrompt :metabot_id internal-id :card_id card-id))
"internal bot is seeded")
@@ -129,7 +129,7 @@
{card-id :id}
{:type :model
:dataset_query query}]
- (t2/update! :model/Metabot (:id original-metabot) {:use_verified_content false})
+ (t2/update! :model/Metabot :id (:id original-metabot) {:use_verified_content false})
(mt/with-dynamic-fn-redefs [premium-features/token-status
(constantly {:meters {:anthropic:claude-sonnet-4-6:tokens {:meter-value 1000000
:is-locked true}}})
diff --git a/test/metabase/metabot/tools/construct_representations_test.clj b/test/metabase/metabot/tools/construct_representations_test.clj
index a967923042d..fff8f136ee3 100644
--- a/test/metabase/metabot/tools/construct_representations_test.clj
+++ b/test/metabase/metabot/tools/construct_representations_test.clj
@@ -2772,7 +2772,7 @@
:model/Card {two-stage-id :id, two-stage-eid :entity_id}
{:name "Two-stage count" :type :metric
:dataset_query (-> (card-query c1-id) lib/append-stage (lib/aggregate (lib/count)))}]
- (t2/update! :model/Card c1-id {:dataset_query (table-query :products)})
+ (t2/update! :model/Card :id c1-id {:dataset_query (table-query :products)})
(mt/with-current-user (mt/user->id :crowberto)
(let [mp (mt/metadata-provider)
rows (fn [source metric-eid]
@@ -2811,7 +2811,7 @@
:type :metric
:dataset_query (lib/aggregate (table-query :products) (lib/count))}]
;; Straight to the table: the model's `:in` transform would not store a blank query.
- (t2/update! (t2/table-name :model/Card) metric-id {:dataset_query "{}"})
+ (t2/update! (t2/table-name :model/Card) :id metric-id {:dataset_query "{}"})
(mt/with-current-user (mt/user->id :crowberto)
(let [mp (lib-be/application-database-metadata-provider (mt/id))
query (assoc-in (lib/query mp (lib.metadata/table mp (mt/id :products)))
diff --git a/test/metabase/metabot/tools/entity_details_test.clj b/test/metabase/metabot/tools/entity_details_test.clj
index a0d3641e4de..776dcb9e5a7 100644
--- a/test/metabase/metabot/tools/entity_details_test.clj
+++ b/test/metabase/metabot/tools/entity_details_test.clj
@@ -651,7 +651,7 @@
:type :metric
:dataset_query (mt/mbql-query orders {:aggregation [[:count]]})}]
;; Straight to the table: the model's `:in` transform would not store a blank query.
- (t2/update! (t2/table-name :model/Card) metric-id {:dataset_query "{}"})
+ (t2/update! (t2/table-name :model/Card) :id metric-id {:dataset_query "{}"})
(is (= (mt/id :orders) (t2/select-one-fn :table_id :model/Card :id metric-id))
"the base table is still recorded, so it is there to be wrongly offered")
(mt/with-current-user (mt/user->id :crowberto)
diff --git a/test/metabase/metabot/tools/resources_test.clj b/test/metabase/metabot/tools/resources_test.clj
index 128daabbf8d..7ee351819e8 100644
--- a/test/metabase/metabot/tools/resources_test.clj
+++ b/test/metabase/metabot/tools/resources_test.clj
@@ -2148,9 +2148,9 @@
(mt/with-temp [:model/Document {id :id} {:name "Plan" :view_count 0}]
(mt/with-current-user (mt/user->id :crowberto)
(is (not (error? (read-uris {:uris [(str "metabase://document/" id)]}))))
- (is (= 0 (t2/select-one-fn :view_count :model/Document id)))
+ (is (= 0 (t2/select-one-fn :view_count :model/Document :id id)))
(documents/get-document id)
- (is (= 1 (t2/select-one-fn :view_count :model/Document id)))))))
+ (is (= 1 (t2/select-one-fn :view_count :model/Document :id id)))))))
(deftest ^:parallel uri-aspect-aliases-test
(doseq [[alias canonical] [["metabase://table/1/columns/2" "metabase://table/1/fields/2"]
diff --git a/test/metabase/metabot/tools/run_query_test.clj b/test/metabase/metabot/tools/run_query_test.clj
index 71be9840f4f..d3c3581e58d 100644
--- a/test/metabase/metabot/tools/run_query_test.clj
+++ b/test/metabase/metabot/tools/run_query_test.clj
@@ -494,7 +494,7 @@
:model/Field _ {:table_id table-id, :name "ID", :base_type :type/Integer}]
(let [mp (lib-be/application-database-metadata-provider db-id)
query (lib/prepare-for-serialization (lib/query mp (lib.metadata/table mp table-id)))]
- (t2/delete! :model/Database db-id)
+ (t2/delete! :model/Database :id db-id)
(is (= database-not-found (run-tool! {"q1" query} {:query_id "q1"})))))))
(defn- not-read-only
@@ -600,7 +600,7 @@
:dataset_query (card-query hidden-metabot-sql)}]
(perms/grant-collection-read-permissions! (perms-group/all-users) open)
(mark-saved-by-metabot! [metabot-sql-card metabot-mixed metabot-write-card edited-sql-card hidden-metabot-sql])
- (t2/update! :model/Card edited-sql-card {:display :bar})
+ (t2/update! :model/Card :id edited-sql-card {:display :bar})
(let [no-permission (refusal ::run-query/no-permission "You do not have permission to run query q1.")]
(testing "a saved question runs with SQL execution on or off, whether it is a notebook or a SQL question"
(doseq [[shape card-id] {"a notebook question" notebook-card
@@ -890,7 +890,7 @@
(mt/with-dynamic-fn-redefs [sql-tools/read-only-select?
(fn [driver sql]
(u/prog1 (read-only? driver sql)
- (t2/update! :model/NativeQuerySnippet snippet-id
+ (t2/update! :model/NativeQuerySnippet :id snippet-id
{:content "SELECT 2 AS N FOR UPDATE"})))]
(binding [qp.pipeline/*execute* (fn [_driver query respond]
(swap! driver-ran-sql conj (get-in query [:native :query]))
diff --git a/test/metabase/metabot/tools_test.clj b/test/metabase/metabot/tools_test.clj
index 444d5454c25..0eee78f8fb8 100644
--- a/test/metabase/metabot/tools_test.clj
+++ b/test/metabase/metabot/tools_test.clj
@@ -282,7 +282,7 @@
(str "QP accepted the rejected query: " (select-keys result [:status :row_count]))))))
(deftest construct-notebook-query-tool-wrong-source-field-test
- (let [db (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))
fk (fn [table column] [db "PUBLIC" table column])
venue-id (fk "CHECKINS" "VENUE_ID")
venues-join {:alias "Venues"
@@ -371,7 +371,7 @@
(assoc-in [0 :source-table] [db "PUBLIC" "CHECKINS"]))}))
(deftest construct-notebook-query-summary-fields-test
- (let [db (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))
fk (fn [table column] [db "PUBLIC" table column])
wrong ["field" {:source-field (fk "CHECKINS" "VENUE_ID")} (fk "CATEGORIES" "NAME")]
non-fk ["field" {:source-field (fk "CHECKINS" "DATE")} (fk "VENUES" "NAME")]
@@ -391,7 +391,7 @@
(is (= [[1000]] (mt/rows actual))))))))))
(deftest construct-notebook-query-supported-source-fields-test
- (let [db (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))
fk (fn [table column] [db "PUBLIC" table column])
venue-id (fk "CHECKINS" "VENUE_ID")
category-id (fk "VENUES" "CATEGORY_ID")
@@ -424,7 +424,7 @@
(get-in (construct-checkins-query db corrected) [:structured-output :query])))))))))))))))
(deftest construct-notebook-query-wrong-source-field-context-test
- (let [db (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))
correct ["field" {:source-field [db "PUBLIC" "VENUES" "CATEGORY_ID"]
:source-field-join-alias "Venues"}
[db "PUBLIC" "CATEGORIES" "NAME"]]
@@ -445,7 +445,7 @@
(str "but its `source-field` " (pr-str (get-in correct [1 :source-field])))))))))))
(deftest construct-notebook-query-direct-source-field-hint-test
- (let [db (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))
fk (fn [table column] [db "PUBLIC" table column])
user-id (fk "CHECKINS" "USER_ID")
query (fn [source-field]
@@ -463,7 +463,7 @@
(is (seq (mt/rows (qp/process-query (get-in (query user-id) [:structured-output :query])))))))))
(deftest construct-notebook-query-hidden-parent-key-hint-test
- (let [db (t2/select-one-fn :name :model/Database (mt/id))]
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))]
(mt/with-temp [:model/Field parent {:table_id (mt/id :venues)
:name "HIDDEN_PAYLOAD"
:base_type :type/JSON
@@ -539,7 +539,7 @@
(deftest construct-notebook-query-category-hints-test
(mt/with-current-user (mt/user->id :rasta)
(let [mp (mt/metadata-provider)
- db (t2/select-one-fn :name :model/Database (mt/id))
+ db (t2/select-one-fn :name :model/Database :id (mt/id))
fk (fn [table field] [db "PUBLIC" table field])
venues (checkins-venues-join db)
checkins (assoc-in (join-on-field db "Checkins" "CHECKINS" ["field" {} (fk "USERS" "ID")])
@@ -594,9 +594,9 @@
(deftest construct-notebook-query-model-source-field-hint-test
(mt/with-current-user (mt/user->id :rasta)
(let [mp (mt/metadata-provider)
- db (t2/select-one-fn :name :model/Database (mt/id))
+ db (t2/select-one-fn :name :model/Database :id (mt/id))
key-id (mt/id :checkins :venue_id)
- original-target (t2/select-one-fn :fk_target_field_id :model/Field key-id)
+ original-target (t2/select-one-fn :fk_target_field_id :model/Field :id key-id)
key-path [db "PUBLIC" "CHECKINS" "VENUE_ID"]
target-path [db "PUBLIC" "VENUES" "NAME"]
query (lib/with-fields (lib/query mp (lib.metadata/table mp (mt/id :checkins)))
@@ -605,7 +605,7 @@
(is (= :completed (:status result)))
(mt/with-temp [:model/Card {eid :entity_id card-id :id}
{:name "Stored venue key" :type :model :dataset_query query :result_metadata (get-in result [:data :cols])}]
- (let [metadata-before (t2/select-one-fn :result_metadata :model/Card card-id)
+ (let [metadata-before (t2/select-one-fn :result_metadata :model/Card :id card-id)
build! #(construct/execute-representations-query
{:lib/type "mbql/query"
:stages [{:lib/type "mbql.stage/mbql" :source-card eid
@@ -616,7 +616,7 @@
{:fk_target_field_id (mt/id :users :id)})
error (try (build!) (catch clojure.lang.ExceptionInfo e e))]
(is (= (mt/id :users :id) (:id (:target updated))))
- (is (= metadata-before (t2/select-one-fn :result_metadata :model/Card card-id)))
+ (is (= metadata-before (t2/select-one-fn :result_metadata :model/Card :id card-id)))
(is (= :wrong-source-field (:error (ex-data error))))
(assert-source-field-qp-failure! build!)
(is (not (str/includes? (or (ex-message error) "")
@@ -635,7 +635,7 @@
{:fk_target_field_id original-target}))))))))
(deftest construct-notebook-query-source-field-join-alias-hint-test
- (let [db (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))
fk (fn [table column] [db "PUBLIC" table column])
checkins-join {:alias "Checkins"
:strategy "left-join"
@@ -673,7 +673,7 @@
(is (= (set (first rows)) (set (second rows)))))))))
(deftest construct-notebook-query-dependent-implicit-joins-test
- (let [db (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))
fk (fn [table field] [db "PUBLIC" table field])
build! #(construct-checkins-query
db [{:aggregation [["count" {}]]
@@ -692,7 +692,7 @@
native (lib/native-query mp "SELECT VENUE_ID FROM CHECKINS")
result (qp/process-query native)
columns (get-in result [:data :cols])
- db (t2/select-one-fn :name :model/Database (mt/id))]
+ db (t2/select-one-fn :name :model/Database :id (mt/id))]
(is (seq columns))
(is (every? (comp nil? :id) columns))
(mt/with-temp [:model/Card {eid :entity_id} {:name "Native venue keys" :dataset_query native :result_metadata columns}]
@@ -707,7 +707,7 @@
(is (= (set control) (set (mt/rows (qp/process-query (get-in (build!) [:structured-output :query])))))))))))
(deftest construct-notebook-query-joined-key-propagation-test
- (let [db (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db (t2/select-one-fn :name :model/Database :id (mt/id))
stages [{:fields [["field" {} [db "PUBLIC" "CHECKINS" "ID"]]]
:joins [(assoc (checkins-venues-join db) :fields "none")]}
{:aggregation [["count" {}]]
@@ -722,7 +722,7 @@
(deftest construct-notebook-query-source-card-key-propagation-test
(let [mp (mt/metadata-provider)
- db (t2/select-one-fn :name :model/Database (mt/id))
+ db (t2/select-one-fn :name :model/Database :id (mt/id))
raw (lib/with-fields (lib/query mp (lib.metadata/table mp (mt/id :checkins)))
[(lib.metadata/field mp (mt/id :checkins :id))])
run! (fn [card-eid]
@@ -740,7 +740,7 @@
(deftest construct-notebook-query-source-card-field-permissions-test
(let [mp (mt/metadata-provider)
- db (t2/select-one-fn :name :model/Database (mt/id))
+ db (t2/select-one-fn :name :model/Database :id (mt/id))
query (lib/with-fields (lib/query mp (lib.metadata/table mp (mt/id :venues)))
[(lib.metadata/field mp (mt/id :venues :name))])]
(mt/with-temp [:model/Card {card-eid :entity_id} {:name "Venue names" :dataset_query query}]
@@ -760,7 +760,7 @@
(deftest construct-notebook-query-source-card-hint-permissions-test
(let [mp (mt/metadata-provider)
- db (t2/select-one-fn :name :model/Database (mt/id))
+ db (t2/select-one-fn :name :model/Database :id (mt/id))
category [db "PUBLIC" "VENUES" "CATEGORY_ID"]
target [db "PUBLIC" "VENUES" "NAME"]
query (lib/with-fields (lib/query mp (lib.metadata/table mp (mt/id :checkins)))
@@ -837,7 +837,7 @@
(deftest construct-notebook-query-tool-malformed-clauses-test
(testing "the model can retry after a malformed stage or clause"
(let [orders {:lib/type "mbql.stage/mbql"
- :source-table [(t2/select-one-fn :name :model/Database (mt/id)) "PUBLIC" "ORDERS"]}
+ :source-table [(t2/select-one-fn :name :model/Database :id (mt/id)) "PUBLIC" "ORDERS"]}
post-agg (assoc orders :aggregation [["count" {}]] :filters [[">" {} ["aggregation" {} 0] 1]])]
(mt/with-current-user (mt/user->id :rasta)
(doseq [[label stages] {"a number as `aggregation`"
@@ -862,7 +862,7 @@
:description "Orders by count."})))))))))
(deftest construct-notebook-query-tool-post-aggregation-errors-test
- (let [source [(t2/select-one-fn :name :model/Database (mt/id)) "PUBLIC" "ORDERS"]]
+ (let [source [(t2/select-one-fn :name :model/Database :id (mt/id)) "PUBLIC" "ORDERS"]]
(mt/with-current-user (mt/user->id :rasta)
(doseq [[error cases] {:post-agg-filter-with-trailing-clauses
[{:limit 5}
diff --git a/test/metabase/metrics/api_dimension_test.clj b/test/metabase/metrics/api_dimension_test.clj
index 44611124f66..30c8fd4d4b3 100644
--- a/test/metabase/metrics/api_dimension_test.clj
+++ b/test/metabase/metrics/api_dimension_test.clj
@@ -274,7 +274,7 @@
(assoc-in % [:target 2] (mt/id :users :name))
%)
dimension_mappings)]
- (t2/update! :model/Card (:id metric) {:dimension_mappings mappings})
+ (t2/update! :model/Card :id (:id metric) {:dimension_mappings mappings})
(let [response (mt/user-http-request :crowberto :get 200
(str "metric/" (:id metric) "/dimension"))]
(is (not (some #(= orphan-id (:id %)) (:added response)))))
@@ -518,7 +518,7 @@
a (:id (first added))
b (:id (second added))
defaults (fn [resp] (into #{} (comp (filter :default) (map :id)) resp))]
- (t2/update! :model/Card (:id metric)
+ (t2/update! :model/Card :id (:id metric)
{:dimensions (mapv #(assoc % :default true)
(t2/select-one-fn :dimensions :model/Card :id (:id metric)))})
(is (= #{a} (defaults (mt/user-http-request :crowberto :post 200
@@ -790,7 +790,7 @@
"would become permanent.")
(legacy-curated-metric!
(fn [metric-id]
- (t2/update! :model/Card metric-id {:name "Renamed"})
+ (t2/update! :model/Card :id metric-id {:name "Renamed"})
(let [{:keys [card_schema dimensions]} (stored-card metric-id)
stored-names (display-name-by-field-id dimensions)]
(is (= "Renamed" (t2/select-one-fn :name :model/Card :id metric-id))
@@ -812,7 +812,7 @@
(legacy-curated-metric!
(fn [metric-id]
;; `:dataset_query` is a migration trigger: upgrade 24 derives a metric's dimensions from it.
- (t2/update! :model/Card metric-id {:dataset_query (people-metric-query)})
+ (t2/update! :model/Card :id metric-id {:dataset_query (people-metric-query)})
(let [{:keys [card_schema dimensions]} (stored-card metric-id)
stored-names (display-name-by-field-id dimensions)]
(is (= card/current-card-schema-version card_schema)
@@ -829,7 +829,7 @@
(legacy-curated-metric!
(fn [metric-id]
(let [modernized (:dimensions (t2/select-one :model/Card :id metric-id))]
- (t2/update! :model/Card metric-id {:dimensions modernized})
+ (t2/update! :model/Card :id metric-id {:dimensions modernized})
(let [{:keys [card_schema dimensions]} (stored-card metric-id)
stored-names (display-name-by-field-id dimensions)]
(is (= card/current-card-schema-version card_schema))
diff --git a/test/metabase/metrics/api_test.clj b/test/metabase/metrics/api_test.clj
index 2600eb0bcd3..3b133a217f5 100644
--- a/test/metabase/metrics/api_test.clj
+++ b/test/metabase/metrics/api_test.clj
@@ -218,7 +218,7 @@
%)
dimension_mappings)]
(is (some? orphan-mapping))
- (t2/update! :model/Card (:id metric) {:dimension_mappings mappings})
+ (t2/update! :model/Card :id (:id metric) {:dimension_mappings mappings})
(let [response (mt/user-http-request :rasta :get 200 (str "metric/" (:id metric)))
response-ids (into #{} (map :id) (:dimensions response))
response-mapping-ids (into #{} (map :dimension_id) (:dimension_mappings response))]
diff --git a/test/metabase/metrics/core_test.clj b/test/metabase/metrics/core_test.clj
index a9ccb9bd3a7..0d98610df91 100644
--- a/test/metabase/metrics/core_test.clj
+++ b/test/metabase/metrics/core_test.clj
@@ -215,7 +215,7 @@
(let [first-dim (first (:dimensions (t2/select-one :model/Card :id (:id metric))))
dim-id (:id first-dim)]
;; Manually update the dimension to have a custom display name
- (t2/update! :model/Card (:id metric)
+ (t2/update! :model/Card :id (:id metric)
{:dimensions [{:id dim-id
:name (:name first-dim)
:display-name "My Custom Metric Dimension"
@@ -234,7 +234,7 @@
:database_id (mt/id)
:table_id (mt/id :venues)
:dataset_query (metric-query)}]
- (t2/update! :model/Card (:id metric) {:dataset_query {}})
+ (t2/update! :model/Card :id (:id metric) {:dataset_query {}})
(metrics/sync-dimensions! :metadata/metric (:id metric))
(let [reloaded (t2/select-one :model/Card :id (:id metric))]
(is (nil? (:dimensions reloaded))
@@ -284,7 +284,7 @@
(is (>= (count dimensions) 2)
"Venues should yield multiple dimensions to curate")
;; Simulate the user removing the first dimension (and its mapping).
- (t2/update! :model/Card (:id metric)
+ (t2/update! :model/Card :id (:id metric)
{:dimensions kept
:dimension_mappings kept-mappings})
(metrics/sync-dimensions! :metadata/metric (:id metric))
@@ -304,8 +304,8 @@
:dataset_query (metric-query)}]
(metrics/sync-dimensions! :metadata/metric (:id metric))
;; User removes every dimension; the empty `:dimensions` is authoritative, not "uninitialized".
- (t2/update! :model/Card (:id metric) {:dimensions []
- :dimension_mappings []})
+ (t2/update! :model/Card :id (:id metric) {:dimensions []
+ :dimension_mappings []})
(metrics/sync-dimensions! :metadata/metric (:id metric))
(is (zero? (count (t2/select-one-fn :dimensions :model/Card :id (:id metric))))
"Emptied dimensions must not be re-seeded"))))
@@ -326,7 +326,7 @@
;; reachable from venues), simulating a deleted column — keeping the rest of the
;; field ref (incl. :lib/uuid) intact.
orphan-mapping (assoc-in mapping [:target 2] (mt/id :users :name))]
- (t2/update! :model/Card (:id metric)
+ (t2/update! :model/Card :id (:id metric)
{:dimensions [dim]
:dimension_mappings [orphan-mapping]})
(metrics/sync-dimensions! :metadata/metric (:id metric))
@@ -385,7 +385,7 @@
(let [first-dim (first (:dimensions (t2/select-one :model/Measure :id (:id measure))))
dim-id (:id first-dim)]
;; Manually update the dimension to have a custom display name
- (t2/update! :model/Measure (:id measure)
+ (t2/update! :model/Measure :id (:id measure)
{:dimensions [{:id dim-id
:name (:name first-dim)
:display-name "My Custom Name"
@@ -413,7 +413,7 @@
(is (>= (count dimensions) 2)
"Venues should yield multiple dimensions")
;; Drop one dimension from storage; a full re-sync should bring it back.
- (t2/update! :model/Measure (:id measure)
+ (t2/update! :model/Measure :id (:id measure)
{:dimensions kept
:dimension_mappings kept-mappings})
(metrics/sync-dimensions! :metadata/measure (:id measure))
diff --git a/test/metabase/metrics/permissions_test.clj b/test/metabase/metrics/permissions_test.clj
index 3f2ee0bbb54..f6acc01b58e 100644
--- a/test/metabase/metrics/permissions_test.clj
+++ b/test/metabase/metrics/permissions_test.clj
@@ -43,7 +43,7 @@
[metric]
(let [{:keys [dimensions dimension-mappings]}
(metrics/compute-full-dimension-set (:entity_id metric) (:dataset_query metric))]
- (t2/update! :model/Card (:id metric)
+ (t2/update! :model/Card :id (:id metric)
{:dimensions dimensions, :dimension_mappings dimension-mappings})))
;;; ------------------------------------------------- Field Visibility Tests -------------------------------------------------
@@ -57,13 +57,13 @@
(mt/user-http-request :crowberto :get 200 (str "metric/" (:id metric)))
;; Now hide a field
(let [tax-field-id (mt/id :orders :tax)]
- (t2/update! :model/Field tax-field-id {:visibility_type :hidden})
+ (t2/update! :model/Field :id tax-field-id {:visibility_type :hidden})
(try
(let [dims (metric-dimensions :rasta (:id metric))]
(testing "hidden field should not appear as a dimension"
(is (not (contains? (dimension-names dims) "Tax")))))
(finally
- (t2/update! :model/Field tax-field-id {:visibility_type :normal})))))))
+ (t2/update! :model/Field :id tax-field-id {:visibility_type :normal})))))))
(deftest sensitive-fields-are-filtered-out-test
(testing "Dimensions based on sensitive fields are excluded from GET /api/metric/:id"
@@ -72,13 +72,13 @@
:dataset_query (mt/mbql-query orders {:aggregation [[:count]]})}]
(mt/user-http-request :crowberto :get 200 (str "metric/" (:id metric)))
(let [tax-field-id (mt/id :orders :tax)]
- (t2/update! :model/Field tax-field-id {:visibility_type :sensitive})
+ (t2/update! :model/Field :id tax-field-id {:visibility_type :sensitive})
(try
(let [dims (metric-dimensions :rasta (:id metric))]
(testing "sensitive field should not appear as a dimension"
(is (not (contains? (dimension-names dims) "Tax")))))
(finally
- (t2/update! :model/Field tax-field-id {:visibility_type :normal})))))))
+ (t2/update! :model/Field :id tax-field-id {:visibility_type :normal})))))))
(deftest normal-fields-are-included-test
(testing "Dimensions based on normal-visibility fields are included"
diff --git a/test/metabase/model_persistence/task/persist_refresh_test.clj b/test/metabase/model_persistence/task/persist_refresh_test.clj
index 3b0bd0138ac..21a00c6baa1 100644
--- a/test/metabase/model_persistence/task/persist_refresh_test.clj
+++ b/test/metabase/model_persistence/task/persist_refresh_test.clj
@@ -134,10 +134,10 @@
(unpersist! [_ _database _persisted-info]))
original-update! (mt/original-fn #'t2/update!)]
(testing "If saving the `persisted` (or `error`) state fails..."
- (mt/with-dynamic-fn-redefs [t2/update! (fn [model id update]
- (when (= "persisted" (:state update))
+ (mt/with-dynamic-fn-redefs [t2/update! (fn [model & args]
+ (when (= "persisted" (:state (last args)))
(throw (ex-info "simulated error" {})))
- (original-update! model id update))]
+ (apply original-update! model args))]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"simulated error"
(#'task.persist-refresh/refresh-tables! (u/the-id db) test-refresher nil))))
(testing "the PersistedInfo is left in the `refreshing` state"
@@ -335,7 +335,7 @@
;; [[metabase.channel.db/accepted-admin-emails]] filters on `last_login`. Record a login for our own
;; admin rather than relying on a shared test user, whose `last_login` is only set as a side effect of
;; some earlier test creating a session for them, and is therefore a matter of test ordering.
- (t2/update! :model/User (:id admin) {:last_login :%now})
+ (t2/update! :model/User :id (:id admin) {:last_login :%now})
(let [^org.quartz.Trigger trigger (#'task.persist-refresh/database-trigger db "0 0 0/8 * * ? *")]
(#'task.persist-refresh/save-task-history!
"persist-refresh" (u/the-id db)
diff --git a/test/metabase/models/interface_test.clj b/test/metabase/models/interface_test.clj
index daf62241213..b6393e6644e 100644
--- a/test/metabase/models/interface_test.clj
+++ b/test/metabase/models/interface_test.clj
@@ -94,11 +94,11 @@
(let [updated-at (:updated_at table)
new-name (u/qualified-name ::a-new-name)]
(is (= 1
- (t2/update! table (u/the-id table) {:name new-name})))
+ (t2/update! table :id (u/the-id table) {:name new-name})))
(is (=? {:id (:id table)
:name new-name
:updated_at (partial not= updated-at)}
- (t2/select-one [:model/Table :id :name :updated_at] (u/the-id table))))))))
+ (t2/select-one [:model/Table :id :name :updated_at] :id (u/the-id table))))))))
(deftest ^:parallel timestamped-property-do-not-stomp-on-explicit-values-test
(testing "The :timestamped property should not stomp on :created_at/:updated_at if they are explicitly specified"
@@ -128,7 +128,7 @@
(let [now (mi/current-timestamp)]
(mt/with-temp [:model/Field field {:created_at now}]
(is (= (u.date/format now)
- (u.date/format (t2/select-one-fn :created_at :model/Field (:id field)))))))))
+ (u.date/format (t2/select-one-fn :created_at :model/Field :id (:id field)))))))))
(defmethod mi/non-timestamped-fields :test-model/updated-at-tester [_]
#{:non_timestamped :other})
diff --git a/test/metabase/models/on_demand_test.clj b/test/metabase/models/on_demand_test.clj
index 536d7f04ec7..cec0c0a719c 100644
--- a/test/metabase/models/on_demand_test.clj
+++ b/test/metabase/models/on_demand_test.clj
@@ -87,7 +87,7 @@
(reset! updated-field-names #{})
;; now update the Card... since param didn't change at all FieldValues
;; should not be updated
- (t2/update! :model/Card (u/the-id card) card))))))))
+ (t2/update! :model/Card :id (u/the-id card) card))))))))
(deftest existing-card-test-2
(testing "Existing Card"
@@ -103,7 +103,7 @@
(mt/with-temp [:model/Field new-field {:table_id (u/the-id table)
:has_field_values "list"
:name "New Field"}]
- (t2/update! :model/Card (u/the-id card)
+ (t2/update! :model/Card :id (u/the-id card)
{:dataset_query (native-query-with-template-tag new-field)})))))))))
(deftest existing-card-test-3
@@ -118,7 +118,7 @@
(fn [{:keys [field card]}]
;; now change the query to one that references our Field in a
;; on-demand DB. Field should have updated values
- (t2/update! :model/Card (u/the-id card)
+ (t2/update! :model/Card :id (u/the-id card)
{:dataset_query (native-query-with-template-tag field)}))))))))
(deftest existing-card-test-4
@@ -130,7 +130,7 @@
{:db {:is_on_demand false}}
(fn [{:keys [card]}]
;; update the Card. Field should get updated values
- (t2/update! :model/Card (u/the-id card) card))))))))
+ (t2/update! :model/Card :id (u/the-id card) card))))))))
(deftest existing-card-test-5
(testing "Existing Card"
@@ -143,7 +143,7 @@
(fn [{:keys [field card]}]
;; now change the query to one that references a Field. Field should
;; not get values since DB is not On-Demand
- (t2/update! :model/Card (u/the-id card)
+ (t2/update! :model/Card :id (u/the-id card)
{:dataset_query (native-query-with-template-tag field)}))))))))
(deftest existing-card-test-6
@@ -159,7 +159,7 @@
(mt/with-temp [:model/Field new-field {:table_id (u/the-id table)
:has_field_values "list"
:name "New Field"}]
- (t2/update! :model/Card (u/the-id card)
+ (t2/update! :model/Card :id (u/the-id card)
{:dataset_query (native-query-with-template-tag new-field)})))))))))
;;; +----------------------------------------------------------------------------------------------------------------+
diff --git a/test/metabase/models/serialization/resolve/mp_test.clj b/test/metabase/models/serialization/resolve/mp_test.clj
index 58cd2af5d8a..d1b649b64c5 100644
--- a/test/metabase/models/serialization/resolve/mp_test.clj
+++ b/test/metabase/models/serialization/resolve/mp_test.clj
@@ -204,7 +204,7 @@
(testing "warm the provider's by-name cache while the table is still active"
(is (= [true] (mapv :active (by-name))))
(is (= (:id gone) (resolve/import-table-fk r [(:name db) "PUBLIC" "metabot2_cafef00dbabe01"]))))
- (t2/update! :model/Table (:id gone) {:active false})
+ (t2/update! :model/Table :id (:id gone) {:active false})
(testing "the cache still surfaces the stale ACTIVE row by name"
(is (= [true] (mapv :active (by-name)))))
(testing "...but import-table-fk misses: the app DB sees the inactive row, no stale-cache fallback"
diff --git a/test/metabase/models/util/spec_update_test.clj b/test/metabase/models/util/spec_update_test.clj
index 5d8cde875d3..a87166974f1 100644
--- a/test/metabase/models/util/spec_update_test.clj
+++ b/test/metabase/models/util/spec_update_test.clj
@@ -52,7 +52,7 @@
:root_id 1}}
new-data (-> existing-data
(assoc :name "Updated Test"))]
- (is (= [[:update! :root 1 {:name "Updated Test"}]]
+ (is (= [[:update! :root :toucan/pk 1 {:name "Updated Test"}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data basic-spec)))))))
@@ -66,8 +66,8 @@
new-data (-> existing-data
(assoc :name "Updated Test")
(assoc-in [:foo :name] "Updated Foo"))]
- (is (= [[:update! :root 1 {:name "Updated Test"}]
- [:update! :foo 2 {:name "Updated Foo" :root_id 1}]]
+ (is (= [[:update! :root :toucan/pk 1 {:name "Updated Test"}]
+ [:update! :foo :toucan/pk 2 {:name "Updated Foo" :root_id 1}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data basic-spec)))))))
@@ -109,7 +109,7 @@
new-data (assoc existing-data :foo {:id 3
:name "New Foo"
:root_id 1})]
- (is (= [[:delete! :foo 2]
+ (is (= [[:delete! :foo :toucan/pk 2]
[:insert-returning-pk! :foo {:name "New Foo" :root_id 1}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data basic-spec)))))))
@@ -122,7 +122,7 @@
:name "Foo 1"
:root_id 1}}
new-data (assoc existing-data :foo nil)]
- (is (= [[:delete! :foo 2]]
+ (is (= [[:delete! :foo :toucan/pk 2]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data basic-spec))))))
(testing "Deleting root record deletes nested model"
@@ -131,8 +131,8 @@
:foo {:id 2
:name "Foo 1"
:root_id 1}}]
- (is (= [[:delete! :root 1]
- [:delete! :foo 2]]
+ (is (= [[:delete! :root :toucan/pk 1]
+ [:delete! :foo :toucan/pk 2]]
(with-tracked-operations!
(spec-update/do-update! existing-data nil basic-spec)))))))
@@ -180,7 +180,7 @@
(assoc-in [:bars 0 :unrelated] "changed")
(update :bars conj {:id 3 :name "Bar 3" :unrelated "def"}))]
(is (= [[:insert! :bar [{:name "Bar 3" :root_id 1 :unrelated "def"}]]
- [:update! :bar 1 {:name "Updated Bar 1" :root_id 1 :unrelated "changed"}]]
+ [:update! :bar :toucan/pk 1 {:name "Updated Bar 1" :root_id 1 :unrelated "changed"}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data multi-row-spec)))))))
@@ -245,9 +245,9 @@
(assoc-in [:bars 0 :unrelated] "changed"))
spec))))
;; Operations include extra-cols when other columns change
- (is (= [[:update! :foo 1 {:name "Updated Test" :unrelated "changed"}]
+ (is (= [[:update! :foo :toucan/pk 1 {:name "Updated Test" :unrelated "changed"}]
[:insert! :bar [{:name "Bar 2" :unrelated "def" :foo_id 1}]]
- [:update! :bar 2 {:name "Updated Bar 1" :unrelated "changed" :foo_id 1}]]
+ [:update! :bar :toucan/pk 2 {:name "Updated Bar 1" :unrelated "changed" :foo_id 1}]]
(with-tracked-operations!
(spec-update/do-update! existing-data
(-> existing-data
@@ -328,16 +328,16 @@
(assoc :name "Updated Qux")
(assoc-in [:bar :name] "updated bar")))))]
(testing "Complex update with additions updates and deletions at multiple levels"
- (is (= [[:update! :foo "abc-123" {:name "Updated Foo"}]
+ (is (= [[:update! :foo :toucan/pk "abc-123" {:name "Updated Foo"}]
[:insert-returning-pk! :bar {:name "New Bar" :foo_id "abc-123"}]
[:insert! :bar_qux [{:name "qux4" :bar_id 2}]]
[:delete! :bar :id [:in [11]]]
- [:update! :bar 10 {:name "Updated Bar 1" :foo_id "abc-123"}]
+ [:update! :bar :toucan/pk 10 {:name "Updated Bar 1" :foo_id "abc-123"}]
[:insert! :bar_qux [{:name "new qux" :bar_id 10}]]
[:delete! :bar_qux :id [:in [101]]]
- [:update! :bar_qux 100 {:name "updated qux1" :bar_id 10}]
- [:update! :qux 20 {:name "Updated Qux" :foo_id "abc-123"}]
- [:update! :qux_bar 200 {:name "updated bar" :qux_id 20}]]
+ [:update! :bar_qux :toucan/pk 100 {:name "updated qux1" :bar_id 10}]
+ [:update! :qux :toucan/pk 20 {:name "Updated Qux" :foo_id "abc-123"}]
+ [:update! :qux_bar :toucan/pk 200 {:name "updated bar" :qux_id 20}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data complex-model-spec))))))))
@@ -358,7 +358,7 @@
(testing "adding 2 layers of nested sequential updates"
(let [existing-data {:id 1
:name "foo"}]
- (is (= [[:update! :foo 1 {:name "FOO"}]
+ (is (= [[:update! :foo :toucan/pk 1 {:name "FOO"}]
[:insert-returning-pk! :bar {:name "Bar 1" :foo_id 1}]
[:insert! :bar_qux [{:name "qux1" :bar_id 2} {:name "qux2" :bar_id 2}]]
[:insert-returning-pk! :bar {:name "Bar 2" :foo_id 1}]]
@@ -392,7 +392,7 @@
:name "Bar 1"
:foo_id "abc-123"
:quxes []}]}]
- (is (= [[:update! :bar 10 {:name "Updated Bar 1", :foo_id 1}]
+ (is (= [[:update! :bar :toucan/pk 10 {:name "Updated Bar 1", :foo_id 1}]
[:insert! :bar_qux [{:bar_id 10
:name "qux1"}]]]
(with-tracked-operations!
@@ -428,7 +428,7 @@
:child {:id 2
:name "Child"}}
new-data (assoc-in existing-data [:child :name] "Updated Child")]
- (is (= [[:update! :child 2 {:name "Updated Child"}]]
+ (is (= [[:update! :child :toucan/pk 2 {:name "Updated Child"}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data ref-in-parent-spec)))))))
@@ -440,8 +440,8 @@
:child {:id 2
:name "Child"}}
new-data (assoc existing-data :child nil)]
- (is (= [[:delete! :child 2]
- [:update! :parent 1 {:name "Parent", :child_id nil}]]
+ (is (= [[:delete! :child :toucan/pk 2]
+ [:update! :parent :toucan/pk 1 {:name "Parent", :child_id nil}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data ref-in-parent-spec)))))))
@@ -453,9 +453,9 @@
:child {:id 1
:name "Child"}}
new-data (assoc existing-data :child {:name "New Child"})]
- (is (= [[:delete! :child 1]
+ (is (= [[:delete! :child :toucan/pk 1]
[:insert-returning-pk! :child {:name "New Child"}]
- [:update! :parent 1 {:name "Parent", :child_id 2}]]
+ [:update! :parent :toucan/pk 1 {:name "Parent", :child_id 2}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data ref-in-parent-spec)))))))
@@ -467,9 +467,9 @@
:child {:id 2
:name "Child"}}
new-data (assoc existing-data :child nil)]
- (is (= [[:delete! :child 2]
- [:update! :parent 1 {:name "Parent"
- :child_id nil}]]
+ (is (= [[:delete! :child :toucan/pk 2]
+ [:update! :parent :toucan/pk 1 {:name "Parent"
+ :child_id nil}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data ref-in-parent-spec)))))))
@@ -479,7 +479,7 @@
:name "Parent"}
new-data (assoc existing-data :child {:name "Child"})]
(is (= [[:insert-returning-pk! :child {:name "Child"}]
- [:update! :parent 1 {:name "Parent", :child_id 2}]]
+ [:update! :parent :toucan/pk 1 {:name "Parent", :child_id 2}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data ref-in-parent-spec)))))))
@@ -522,8 +522,8 @@
(assoc-in [:customer :name] "Updated Customer")
(assoc-in [:payment :processor :name] "Updated PayCo")
(update :items conj {:product_name "Item 2" :quantity 1}))]
- (is (= [[:update! :customer 10 {:name "Updated Customer"}]
- [:update! :payment_processor 30 {:name "Updated PayCo"}]
+ (is (= [[:update! :customer :toucan/pk 10 {:name "Updated Customer"}]
+ [:update! :payment_processor :toucan/pk 30 {:name "Updated PayCo"}]
[:insert! :item [{:product_name "Item 2" :quantity 1 :order_id 1}]]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data complex-ref-in-parent-spec)))))))
@@ -574,8 +574,8 @@
new-data (-> existing-data
(assoc-in [:tasks 0 :assignee :name] "Updated User A")
(assoc-in [:tasks 1 :description] "Updated Task 2"))]
- (is (= [[:update! :task 11 {:description "Updated Task 2", :project_id 1, :assignee_id 101}]
- [:update! :user 100 {:name "Updated User A"}]]
+ (is (= [[:update! :task :toucan/pk 11 {:description "Updated Task 2", :project_id 1, :assignee_id 101}]
+ [:update! :user :toucan/pk 100 {:name "Updated User A"}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data multi-row-with-ref-spec)))))))
@@ -590,9 +590,9 @@
:assignee {:id 100
:name "User A"}}]}
new-data (assoc-in existing-data [:tasks 0 :assignee] {:name "New Assignee"})]
- (is (= [[:delete! :user 100]
+ (is (= [[:delete! :user :toucan/pk 100]
[:insert-returning-pk! :user {:name "New Assignee"}]
- [:update! :task 10 {:description "Task 1", :project_id 1, :assignee_id 2}]]
+ [:update! :task :toucan/pk 10 {:description "Task 1", :project_id 1, :assignee_id 2}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data multi-row-with-ref-spec)))))))
@@ -605,7 +605,7 @@
:project_id 1}]}
new-data (assoc-in existing-data [:tasks 0 :assignee] {:name "New Assignee"})]
(is (= [[:insert-returning-pk! :user {:name "New Assignee"}]
- [:update! :task 10 {:description "Task 1", :project_id 1, :assignee_id 2}]]
+ [:update! :task :toucan/pk 10 {:description "Task 1", :project_id 1, :assignee_id 2}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data multi-row-with-ref-spec)))))))
@@ -620,7 +620,7 @@
:assignee {:id 100
:name "User A"}}]}
new-data (update-in existing-data [:tasks 0] dissoc :assignee)]
- (is (= [[:delete! :user 100]
- [:update! :task 10 {:description "Task 1", :project_id 1, :assignee_id nil}]]
+ (is (= [[:delete! :user :toucan/pk 100]
+ [:update! :task :toucan/pk 10 {:description "Task 1", :project_id 1, :assignee_id nil}]]
(with-tracked-operations!
(spec-update/do-update! existing-data new-data multi-row-with-ref-spec)))))))
diff --git a/test/metabase/native_query_snippets/models/native_query_snippet_test.clj b/test/metabase/native_query_snippets/models/native_query_snippet_test.clj
index b7bb32635a2..c9369ad2c72 100644
--- a/test/metabase/native_query_snippets/models/native_query_snippet_test.clj
+++ b/test/metabase/native_query_snippets/models/native_query_snippet_test.clj
@@ -13,7 +13,7 @@
(is (thrown-with-msg?
Exception
#"You cannot update the creator_id of a NativeQuerySnippet\."
- (t2/update! :model/NativeQuerySnippet snippet-id {:creator_id (mt/user->id :rasta)})))
+ (t2/update! :model/NativeQuerySnippet :id snippet-id {:creator_id (mt/user->id :rasta)})))
(is (= (mt/user->id :lucky)
(t2/select-one-fn :creator_id :model/NativeQuerySnippet :id snippet-id))))))
@@ -33,7 +33,7 @@
:model/Collection {dest-collection-id :id} {:namespace dest}
:model/NativeQuerySnippet {snippet-id :id} (when source
{:collection_id source-collection-id})]
- (t2/update! :model/NativeQuerySnippet snippet-id {:collection_id (when dest dest-collection-id)})
+ (t2/update! :model/NativeQuerySnippet :id snippet-id {:collection_id (when dest dest-collection-id)})
(is (= (when dest dest-collection-id)
(t2/select-one-fn :collection_id :model/NativeQuerySnippet :id snippet-id))))))
(doseq [collection-namespace [nil "x"]]
@@ -55,7 +55,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"A NativeQuerySnippet can only go in Collections in the :snippets namespace"
- (t2/update! :model/NativeQuerySnippet snippet-id {:collection_id dest-collection-id})))))))
+ (t2/update! :model/NativeQuerySnippet :id snippet-id {:collection_id dest-collection-id})))))))
(deftest basic-param-finding-test
(testing "Can find params in a snippet"
diff --git a/test/metabase/native_query_snippets/models/snippet_persistence_test.clj b/test/metabase/native_query_snippets/models/snippet_persistence_test.clj
index 8323608aecf..83bd7b501d0 100644
--- a/test/metabase/native_query_snippets/models/snippet_persistence_test.clj
+++ b/test/metabase/native_query_snippets/models/snippet_persistence_test.clj
@@ -23,7 +23,7 @@
(is (contains? template-tags "snippet: Snippet A"))
(is (= snippet-a-id (get-in template-tags ["snippet: Snippet A" :snippet-id])))))
(testing "with Snippet A renamed to Snippet C"
- (t2/update! :model/NativeQuerySnippet snippet-a-id {:name "Snippet C"})
+ (t2/update! :model/NativeQuerySnippet :id snippet-a-id {:name "Snippet C"})
(testing "Snippet B should still refer to snippet-a-id"
(let [updated-tags (t2/select-one-fn :template_tags :model/NativeQuerySnippet :id snippet-b-id)]
;; The template tag key is still "snippet: Snippet A" because we haven't edited Snippet B
@@ -31,7 +31,7 @@
;; But it still points to the same snippet (now named Snippet C)
(is (= snippet-a-id (get-in updated-tags ["snippet: Snippet A" :snippet-id])))))
(testing "with Snippet B edited but preserving reference to Snippet A"
- (t2/update! :model/NativeQuerySnippet snippet-b-id
+ (t2/update! :model/NativeQuerySnippet :id snippet-b-id
{:content "SELECT id, name FROM orders {{snippet: Snippet A}} LIMIT 10"})
(let [edited-tags (t2/select-one-fn :template_tags :model/NativeQuerySnippet :id snippet-b-id)]
;; The reference text is still "snippet: Snippet A"
@@ -56,7 +56,7 @@
(let [template-tags (t2/select-one-fn :template_tags :model/NativeQuerySnippet :id snippet-ref-id)]
(is (= snippet-x-id (get-in template-tags ["snippet: Snippet X" :snippet-id])))
(testing "Changing the referenced snippet name should update the reference"
- (t2/update! :model/NativeQuerySnippet snippet-ref-id
+ (t2/update! :model/NativeQuerySnippet :id snippet-ref-id
{:content "SELECT * FROM users {{snippet: Snippet Y}}"})
(let [updated-tags (t2/select-one-fn :template_tags :model/NativeQuerySnippet :id snippet-ref-id)]
(is (not (contains? updated-tags "snippet: Snippet X")))
@@ -89,8 +89,8 @@
(is (= filter1-id (get-in template-tags ["snippet: Filter One" :snippet-id])))
(is (= filter2-id (get-in template-tags ["snippet: Filter Two" :snippet-id])))
(testing "After renaming referenced snippets, references should persist"
- (t2/update! :model/NativeQuerySnippet filter1-id {:name "Renamed Filter One"})
- (t2/update! :model/NativeQuerySnippet filter2-id {:name "Renamed Filter Two"})
+ (t2/update! :model/NativeQuerySnippet :id filter1-id {:name "Renamed Filter One"})
+ (t2/update! :model/NativeQuerySnippet :id filter2-id {:name "Renamed Filter Two"})
(let [updated-tags (t2/select-one-fn :template_tags :model/NativeQuerySnippet :id combined-id)]
(is (= filter1-id (get-in updated-tags ["snippet: Filter One" :snippet-id])))
(is (= filter2-id (get-in updated-tags ["snippet: Filter Two" :snippet-id])))))))))
@@ -110,7 +110,7 @@
(let [tags (t2/select-one-fn :template_tags :model/NativeQuerySnippet :id query-id)]
(is (= expensive-wrong-id (get-in tags ["snippet: expensive" :snippet-id])))))
;; Step 3: Rename the wrong snippet to "affordable" (fixing the mistake)
- (t2/update! :model/NativeQuerySnippet expensive-wrong-id {:name "affordable"})
+ (t2/update! :model/NativeQuerySnippet :id expensive-wrong-id {:name "affordable"})
(testing "After renaming, reference still points to same snippet (now 'affordable')"
(let [tags (t2/select-one-fn :template_tags :model/NativeQuerySnippet :id query-id)]
(is (= expensive-wrong-id (get-in tags ["snippet: expensive" :snippet-id]))
@@ -124,7 +124,7 @@
(is (= expensive-wrong-id (get-in tags ["snippet: expensive" :snippet-id]))
"Without re-saving, query still points to the old (now 'affordable') snippet")))
;; Step 5: Re-save the query (simulating user editing and saving)
- (t2/update! :model/NativeQuerySnippet query-id
+ (t2/update! :model/NativeQuerySnippet :id query-id
{:content "SELECT * FROM orders {{snippet: expensive}}"})
(testing "After re-saving the query, reference switches to the new exact-match snippet"
(let [tags (t2/select-one-fn :template_tags :model/NativeQuerySnippet :id query-id)]
diff --git a/test/metabase/notification/api/admin_test.clj b/test/metabase/notification/api/admin_test.clj
index 44ab34bd220..89daf26b480 100644
--- a/test/metabase/notification/api/admin_test.clj
+++ b/test/metabase/notification/api/admin_test.clj
@@ -977,8 +977,8 @@
{:notification_ids [(:id n1) (:id n2)]
:action "archive"})]
(is (= 2 (:updated resp)))
- (is (false? (t2/select-one-fn :active :model/Notification (:id n1))))
- (is (false? (t2/select-one-fn :active :model/Notification (:id n2))))
+ (is (false? (t2/select-one-fn :active :model/Notification :id (:id n1))))
+ (is (false? (t2/select-one-fn :active :model/Notification :id (:id n2))))
(testing "publishes :event/notification-update per notification so the admin action is audited"
(doseq [n [n1 n2]]
(is (= {:topic :notification-update
@@ -1001,7 +1001,7 @@
{:notification_ids [(:id n1)]
:action "change-creator"
:creator_id new-owner})
- (is (= new-owner (t2/select-one-fn :creator_id :model/Notification (:id n1)))))))
+ (is (= new-owner (t2/select-one-fn :creator_id :model/Notification :id (:id n1)))))))
(deftest bulk-change-owner-requires-owner-id-test
(testing "POST /bulk with action=change-creator and no creator_id returns 400"
@@ -1588,14 +1588,14 @@
(mt/user-http-request :rasta :put 403 (format "notification/%d" nid)
(assoc notification :creator_id (mt/user->id :lucky)))
(is (= (mt/user->id :rasta)
- (t2/select-one-fn :creator_id :model/Notification nid))
+ (t2/select-one-fn :creator_id :model/Notification :id nid))
"owner unchanged after non-superuser attempt")))
(testing "superuser can reassign owner"
(let [notification (mt/user-http-request :crowberto :get 200 (format "notification/%d" nid))]
(mt/user-http-request :crowberto :put 200 (format "notification/%d" nid)
(assoc notification :creator_id (mt/user->id :lucky)))
(is (= (mt/user->id :lucky)
- (t2/select-one-fn :creator_id :model/Notification nid))
+ (t2/select-one-fn :creator_id :model/Notification :id nid))
"owner reassigned after superuser PUT"))))))
;; ---------------------------------------------------------------------------------------------
diff --git a/test/metabase/notification/api/notification_test.clj b/test/metabase/notification/api/notification_test.clj
index e2e999058cc..90e5b38b2b0 100644
--- a/test/metabase/notification/api/notification_test.clj
+++ b/test/metabase/notification/api/notification_test.clj
@@ -269,7 +269,7 @@
(mt/user-http-request :crowberto :put 200 (format "notification/%d" (:id notification))
(update notification :handlers (fn [[handler]]
[(dissoc handler :template)])))
- (is (false? (t2/exists? :model/ChannelTemplate (:id created-template)))))
+ (is (false? (t2/exists? :model/ChannelTemplate :id (:id created-template)))))
(testing "and re-create it again"
(let [notification (mt/user-http-request :crowberto :put 200 (format "notification/%d" (:id notification))
(update notification :handlers (fn [[handler]]
@@ -487,14 +487,14 @@
(testing "\nthe notification and its payload keep their primary keys"
(is (=? {:active false
:payload_id payload-id}
- (t2/select-one :model/Notification notification-id)))
+ (t2/select-one :model/Notification :id notification-id)))
(is (true? (t2/exists? :model/NotificationCard :id payload-id)))))
(testing "a body naming a different notification id is ignored - the URL row is updated in place"
(is (=? {:id notification-id}
(put! 200 (assoc notification :id (inc notification-id)))))
(is (=? {:active true
:payload_id payload-id}
- (t2/select-one :model/Notification notification-id))))
+ (t2/select-one :model/Notification :id notification-id))))
(testing "a body payload naming a different payload row is ignored - the payload keeps its primary key"
(is (=? {:id notification-id}
(put! 200 (assoc-in notification [:payload :id] (inc payload-id)))))
@@ -514,11 +514,11 @@
(testing "superuser can reassign owner"
(put! :crowberto 200 {:creator_id (mt/user->id :lucky)})
(is (= (mt/user->id :lucky)
- (t2/select-one-fn :creator_id :model/Notification notification-id))))
+ (t2/select-one-fn :creator_id :model/Notification :id notification-id))))
(testing "non-superuser cannot reassign owner — even the current owner (403 from mi/can-update?)"
(put! :lucky 403 {:creator_id (mt/user->id :rasta)})
(is (= (mt/user->id :lucky)
- (t2/select-one-fn :creator_id :model/Notification notification-id))))
+ (t2/select-one-fn :creator_id :model/Notification :id notification-id))))
(testing "echoing back the unchanged creator_id is fine for non-superusers"
(put! :lucky 200 {:creator_id (mt/user->id :lucky)}))))))
@@ -774,9 +774,9 @@
change-notification-creator (fn [user-id]
;; :model/Notification prevents updating creator_id, so we need to use table
;; name
- (t2/update! :notification (:id notification) {:creator_id user-id}))
+ (t2/update! :notification :id (:id notification) {:creator_id user-id}))
move-card-collection (fn [user-id]
- (t2/update! :model/Card (-> notification :payload :card_id)
+ (t2/update! :model/Card :id (-> notification :payload :card_id)
{:collection_id (t2/select-one-pk :model/Collection :personal_owner_id user-id)}))]
(mt/with-premium-features #{}
(testing "admin can update"
@@ -879,17 +879,17 @@
:details {:type :email/handlebars-text
:subject "updated subject"
:body "<h1>updated body</h1>"}})]))
- original (t2/select-one :model/ChannelTemplate system-template-id)]
+ original (t2/select-one :model/ChannelTemplate :id system-template-id)]
(testing "the owner (non-admin) cannot overwrite the referenced template - the row is untouched"
(put! :rasta 403 (overwrite-with "renamed"))
(is (=? (select-keys original [:name :details])
- (select-keys (t2/select-one :model/ChannelTemplate system-template-id) [:name :details]))))
+ (select-keys (t2/select-one :model/ChannelTemplate :id system-template-id) [:name :details]))))
(testing "the owner (non-admin) cannot delete the referenced template by omitting it"
(put! :rasta 403 (fn [[handler]] [(dissoc handler :template :template_id)]))
- (is (true? (t2/exists? :model/ChannelTemplate system-template-id))))
+ (is (true? (t2/exists? :model/ChannelTemplate :id system-template-id))))
(testing "an admin can overwrite the template"
(put! :crowberto 200 (overwrite-with "admin-renamed"))
- (is (= "admin-renamed" (t2/select-one-fn :name :model/ChannelTemplate system-template-id))))))))))
+ (is (= "admin-renamed" (t2/select-one-fn :name :model/ChannelTemplate :id system-template-id))))))))))
(deftest send-saved-notification-permissions-test
(mt/with-temp [:model/User {third-user-id :id} {:is_superuser false}]
@@ -1119,7 +1119,7 @@
:handlers [{:channel_type "channel/email"
:recipients [{:type :notification-recipient/user
:user_id (mt/user->id :lucky)}]}]}]
- (let [card-id (-> (t2/select-one :model/Notification rasta-noti)
+ (let [card-id (-> (t2/select-one :model/Notification :id rasta-noti)
models.notification/hydrate-notification
:payload
:card_id)]
@@ -1152,7 +1152,7 @@
:handlers [{:channel_type "channel/email"
:recipients [{:type :notification-recipient/user
:user_id (mt/user->id :lucky)}]}]}]
- (let [card-id (-> (t2/select-one :model/Notification rasta-noti)
+ (let [card-id (-> (t2/select-one :model/Notification :id rasta-noti)
models.notification/hydrate-notification
:payload
:card_id)]
@@ -1200,7 +1200,7 @@
{:type :notification-recipient/user
:user_id (mt/user->id :lucky)}]}]}]
(mt/user-http-request user :post status (format "notification/%d/unsubscribe" noti-id))
- (thunk (models.notification/hydrate-notification (t2/select-one :model/Notification noti-id)))))
+ (thunk (models.notification/hydrate-notification (t2/select-one :model/Notification :id noti-id)))))
email-recipients (fn [notification]
(->> notification :handlers (m/find-first #(= :channel/email (:channel_type %))) :recipients))]
(testing "creator can unsubscribe themselves"
@@ -1235,7 +1235,7 @@
(notification.tu/with-channel-fixtures [:channel/email]
(mt/with-model-cleanup [:model/Notification]
(let [email-recipients (fn [noti-id]
- (->> (t2/select-one :model/Notification noti-id)
+ (->> (t2/select-one :model/Notification :id noti-id)
models.notification/hydrate-notification
:handlers
(m/find-first #(= :channel/email (:channel_type %)))
diff --git a/test/metabase/notification/events/notification_test.clj b/test/metabase/notification/events/notification_test.clj
index a2b563a5a61..0f1f9decb63 100644
--- a/test/metabase/notification/events/notification_test.clj
+++ b/test/metabase/notification/events/notification_test.clj
@@ -72,7 +72,7 @@
(-> [:user_id :int] (#'events.schema/with-hydrate :user user-hydra-model))]
{:user_id (mt/user->id :rasta)}
{:user_id (mt/user->id :rasta)
- :user (t2/select-one user-hydra-model (mt/user->id :rasta))}]
+ :user (t2/select-one user-hydra-model :id (mt/user->id :rasta))}]
["seq of maps"
[:sequential
[:map
@@ -80,9 +80,9 @@
[{:user_id (mt/user->id :rasta)}
{:user_id (mt/user->id :crowberto)}]
[{:user_id (mt/user->id :rasta)
- :user (t2/select-one user-hydra-model (mt/user->id :rasta))}
+ :user (t2/select-one user-hydra-model :id (mt/user->id :rasta))}
{:user_id (mt/user->id :crowberto)
- :user (t2/select-one user-hydra-model (mt/user->id :crowberto))}]]
+ :user (t2/select-one user-hydra-model :id (mt/user->id :crowberto))}]]
["ignore keys that don't need hydration"
[:map
(-> [:user_id :int] (#'events.schema/with-hydrate :user user-hydra-model))
@@ -90,7 +90,7 @@
{:user_id (mt/user->id :rasta)
:topic :user-joined}
{:user_id (mt/user->id :rasta)
- :user (t2/select-one user-hydra-model (mt/user->id :rasta))
+ :user (t2/select-one user-hydra-model :id (mt/user->id :rasta))
:topic :user-joined}]
["multiple hydration in the same map"
[:map
@@ -99,9 +99,9 @@
{:user_id (mt/user->id :rasta)
:creator_id (mt/user->id :crowberto)}
{:user_id (mt/user->id :rasta)
- :user (t2/select-one user-hydra-model (mt/user->id :rasta))
+ :user (t2/select-one user-hydra-model :id (mt/user->id :rasta))
:creator_id (mt/user->id :crowberto)
- :creator (t2/select-one user-hydra-model (mt/user->id :crowberto))}]
+ :creator (t2/select-one user-hydra-model :id (mt/user->id :crowberto))}]
["respect the options"
[:map
(-> [:user_id {:optional true} :int] (#'events.schema/with-hydrate :user user-hydra-model))]
diff --git a/test/metabase/notification/models_test.clj b/test/metabase/notification/models_test.clj
index c5818aa093a..6f3a3fa5fa2 100644
--- a/test/metabase/notification/models_test.clj
+++ b/test/metabase/notification/models_test.clj
@@ -37,7 +37,7 @@
(testing "success if :payload_type is supported"
(is (some? (t2/select-one
:model/Notification
- (t2/insert-returning-pk! :model/Notification {:payload_type :notification/system-event})))))
+ :id (t2/insert-returning-pk! :model/Notification {:payload_type :notification/system-event})))))
(testing "failed if payload_type is invalid"
(is (thrown-with-msg? Exception #"Value does not match schema*"
(t2/insert! :model/Notification {:payload_type :notification/not-existed}))))))
@@ -48,9 +48,9 @@
(is (thrown-with-msg?
java.lang.Exception
#"Update payload_type is not allowed."
- (t2/update! :model/Notification noti-id {:payload_type :notification/card
- :payload_id 1337
- :creator_id (mt/user->id :crowberto)})))))
+ (t2/update! :model/Notification :id noti-id {:payload_type :notification/card
+ :payload_id 1337
+ :creator_id (mt/user->id :crowberto)})))))
(testing "can't change payload id"
(mt/with-temp [:model/Notification {noti-id :id} {:payload_type :notification/card
:payload_id 1337
@@ -58,15 +58,15 @@
(is (thrown-with-msg?
java.lang.Exception
#"Update payload_id is not allowed."
- (t2/update! :model/Notification noti-id {:payload_id 1338})))))
+ (t2/update! :model/Notification :id noti-id {:payload_id 1338})))))
(testing "superusers can change creator_id"
(mt/with-temp [:model/Notification {noti-id :id} {:payload_type :notification/card
:payload_id 1337
:creator_id (mt/user->id :crowberto)}]
(mt/with-current-user (mt/user->id :crowberto)
- (t2/update! :model/Notification noti-id {:creator_id (mt/user->id :rasta)}))
+ (t2/update! :model/Notification :id noti-id {:creator_id (mt/user->id :rasta)}))
(is (= (mt/user->id :rasta)
- (t2/select-one-fn :creator_id :model/Notification noti-id)))))
+ (t2/select-one-fn :creator_id :model/Notification :id noti-id)))))
(testing "non-superusers and unauthenticated callers can't change creator_id"
(mt/with-temp [:model/Notification {noti-id :id} {:payload_type :notification/card
:payload_id 1337
@@ -76,7 +76,7 @@
(is (thrown-with-msg?
java.lang.Exception
#"Only superusers can change a notification's creator_id."
- (t2/update! :model/Notification noti-id {:creator_id (mt/user->id :lucky)})))))
+ (t2/update! :model/Notification :id noti-id {:creator_id (mt/user->id :lucky)})))))
(testing "non-superuser (bulk update via :id [:in …])"
;; The admin bulk endpoint uses this form; the model hook is the backstop in case the
;; endpoint's superuser check is ever relaxed or bypassed.
@@ -89,17 +89,17 @@
(is (thrown-with-msg?
java.lang.Exception
#"Only superusers can change a notification's creator_id."
- (t2/update! :model/Notification noti-id {:creator_id (mt/user->id :lucky)})))))))
+ (t2/update! :model/Notification :id noti-id {:creator_id (mt/user->id :lucky)})))))))
(deftest delete-notification-clean-up-payload-test
(testing "cleanup :model/NotificationCard on delete"
(notification.tu/with-card-notification [notification {}]
(let [notification-card-id (-> notification :payload :id)]
(testing "sanity check"
- (is (t2/exists? :model/NotificationCard notification-card-id)))
+ (is (t2/exists? :model/NotificationCard :id notification-card-id)))
(testing "delete notification will delete notification card"
- (t2/delete! :model/Notification (:id notification))
- (is (not (t2/exists? :model/NotificationCard notification-card-id))))))))
+ (t2/delete! :model/Notification :id (:id notification))
+ (is (not (t2/exists? :model/NotificationCard :id notification-card-id))))))))
(deftest delete-card-cleans-up-notifications-test
(testing "deleting a card should remove all associated notifications, both active and inactive"
@@ -120,13 +120,13 @@
[]
[])]
(testing "sanity: both notifications and notification cards exist"
- (is (t2/exists? :model/Notification (:id active-notification)))
- (is (t2/exists? :model/Notification (:id inactive-notification)))
+ (is (t2/exists? :model/Notification :id (:id active-notification)))
+ (is (t2/exists? :model/Notification :id (:id inactive-notification)))
(is (= 2 (t2/count :model/NotificationCard :card_id card-id))))
- (t2/delete! :model/Card card-id)
+ (t2/delete! :model/Card :id card-id)
(testing "both notifications should be removed when the card is deleted"
- (is (not (t2/exists? :model/Notification (:id active-notification))))
- (is (not (t2/exists? :model/Notification (:id inactive-notification)))))
+ (is (not (t2/exists? :model/Notification :id (:id active-notification))))
+ (is (not (t2/exists? :model/Notification :id (:id inactive-notification)))))
(testing "notification card payloads should also be removed"
(is (not (t2/exists? :model/NotificationCard :card_id card-id)))))))))
@@ -136,7 +136,7 @@
(let [sub-id (t2/insert-returning-pk! :model/NotificationSubscription {:type :notification-subscription/system-event
:event_name :event/card-create
:notification_id n-id})]
- (is (some? (t2/select-one :model/NotificationSubscription sub-id)))))
+ (is (some? (t2/select-one :model/NotificationSubscription :id sub-id)))))
(testing "fail if type is system event but event-name is nil"
(is (thrown-with-msg? Exception #"Value does not match schema"
(t2/insert! :model/NotificationSubscription {:type :notification-subscription/system-event
@@ -163,7 +163,7 @@
sub-id (t2/insert-returning-pk! :model/NotificationSubscription {:type :notification-subscription/system-event
:event_name random-event
:notification_id n-id})]
- (is (some? (t2/select-one :model/NotificationSubscription sub-id)))))
+ (is (some? (t2/select-one :model/NotificationSubscription :id sub-id)))))
(testing "failed if type is invalid"
(is (thrown-with-msg? Exception #"Must be a namespaced keyword under :event, got: :user-join"
(t2/insert! :model/NotificationSubscription {:type :notification-subscription/system-event
@@ -246,7 +246,7 @@
:template_id (:id tmpl-1)
:recipients [{:type :notification-recipient/user
:user_id (mt/user->id :rasta)}]}])]
- (t2/delete! :model/ChannelTemplate (:id tmpl-1))
+ (t2/delete! :model/ChannelTemplate :id (:id tmpl-1))
(is (=? {:template_id nil} (t2/select-one :model/NotificationHandler :notification_id (:id noti)))))))))
(deftest cross-check-channel-type-and-template-type-test
@@ -265,7 +265,7 @@
:notification_id (:id noti)
:template_id (:id slack-tmpl)}]
(is (thrown-with-msg? Exception #"Channel type and template type mismatch"
- (t2/update! :model/NotificationHandler (:id handler) {:template_id (:id email-tmpl)}))))))
+ (t2/update! :model/NotificationHandler :id (:id handler) {:template_id (:id email-tmpl)}))))))
(deftest notification-recipient-types-test
(mt/with-temp [:model/Notification {n-id :id} {}
@@ -345,29 +345,29 @@
"0 * * * * ? *")]
(notification.tu/send-notification-triggers sub-id)))
(testing "update trigger when cron schedule is changed"
- (t2/update! :model/NotificationSubscription sub-id {:cron_schedule "1 * * * * ? *"})
+ (t2/update! :model/NotificationSubscription :id sub-id {:cron_schedule "1 * * * * ? *"})
(is (= [(notification.tu/subscription->trigger-info
sub-id
"1 * * * * ? *")]
(notification.tu/send-notification-triggers sub-id))))
(testing "delete the trigger when type changes"
- (t2/update! :model/NotificationSubscription sub-id {:type :notification-subscription/system-event
- :cron_schedule nil
- :event_name :event/card-create})
+ (t2/update! :model/NotificationSubscription :id sub-id {:type :notification-subscription/system-event
+ :cron_schedule nil
+ :event_name :event/card-create})
(is (empty? (notification.tu/send-notification-triggers sub-id))))))
(testing "delete the trigger when delete subscription"
(let [sub-id (t2/insert-returning-pk! :model/NotificationSubscription {:type :notification-subscription/cron
:cron_schedule "0 * * * * ? *"
:notification_id noti-id})]
(is (not-empty (notification.tu/send-notification-triggers sub-id)))
- (t2/delete! :model/NotificationSubscription sub-id)
+ (t2/delete! :model/NotificationSubscription :id sub-id)
(is (empty? (notification.tu/send-notification-triggers sub-id)))))
(testing "delete notification will delete all subscription triggers"
(let [sub-id (t2/insert-returning-pk! :model/NotificationSubscription {:type :notification-subscription/cron
:cron_schedule "0 * * * * ? *"
:notification_id noti-id})]
(is (not-empty (notification.tu/send-notification-triggers sub-id)))
- (t2/delete! :model/Notification noti-id)
+ (t2/delete! :model/Notification :id noti-id)
(is (empty? (notification.tu/send-notification-triggers sub-id))))))))
(deftest subscription-trigger-timezone-is-report-timezone-test
@@ -397,10 +397,10 @@
(testing "sanity check that it has a trigger to begin with"
(is (= 2 (count (notification.tu/notification-triggers id)))))
(testing "disabled notification should remove triggers"
- (t2/update! :model/Notification id {:active false})
+ (t2/update! :model/Notification :id id {:active false})
(is (empty? (notification.tu/notification-triggers id))))
(testing "activate notification should restore triggers"
- (t2/update! :model/Notification id {:active true})
+ (t2/update! :model/Notification :id id {:active true})
(is (= 2 (count (notification.tu/notification-triggers id))))))))
(deftest v-alerts-schedule-type-test
diff --git a/test/metabase/notification/payload/impl/card_test.clj b/test/metabase/notification/payload/impl/card_test.clj
index 46a04fbdb0b..871d8da3b36 100644
--- a/test/metabase/notification/payload/impl/card_test.clj
+++ b/test/metabase/notification/payload/impl/card_test.clj
@@ -96,7 +96,7 @@
(is (=? {:body {:type "alert"
:alert_id (-> notification :payload :id)
:alert_creator_id (-> notification :creator_id)
- :alert_creator_name (t2/select-one-fn :common_name :model/User (:creator_id notification))
+ :alert_creator_name (t2/select-one-fn :common_name :model/User :id (:creator_id notification))
:data {:type "question"
:question_id card-id
:question_name notification.tu/default-card-name
@@ -178,7 +178,7 @@
(is (=? {:body {:type "alert"
:alert_id (-> notification :payload :id)
:alert_creator_id (-> notification :creator_id)
- :alert_creator_name (t2/select-one-fn :common_name :model/User (:creator_id notification))
+ :alert_creator_name (t2/select-one-fn :common_name :model/User :id (:creator_id notification))
:data (mt/malli=? :map)
:sent_at (mt/malli=? :any)}}
req)))})))))))))
@@ -427,14 +427,14 @@
(deftest send-once-archive-on-first-successful-send
(notification.tu/with-card-notification
[notification {:notification-card {:send_once true}}]
- (let [notification (t2/select-one :model/Notification (:id notification))]
+ (let [notification (t2/select-one :model/Notification :id (:id notification))]
(testing "do not archive if the send fail for any reason"
(mt/with-dynamic-fn-redefs [notification.payload/notification-payload (fn [& _args] (throw (ex-info "error" {})))]
(u/ignore-exceptions (notification/send-notification! notification))
- (is (true? (t2/select-one-fn :active :model/Notification (:id notification))))))
+ (is (true? (t2/select-one-fn :active :model/Notification :id (:id notification))))))
(testing "archive if the send is successful"
(notification/send-notification! notification)
- (is (false? (t2/select-one-fn :active :model/Notification (:id notification))))
+ (is (false? (t2/select-one-fn :active :model/Notification :id (:id notification))))
(testing "once archived, notifications will be skipped if trying to send"
(notification.tu/test-send-notification!
notification
@@ -463,16 +463,16 @@
{:channel/email
(fn [emails]
(is (zero? (count emails)))
- (is (true? (t2/select-one-fn :active :model/Notification (:id notification)))))}))
+ (is (true? (t2/select-one-fn :active :model/Notification :id (:id notification)))))}))
(testing "if the goal is met, notification is sent then archived"
;; flip the condition so the goal is met now
- (t2/update! :model/NotificationCard (get-in notification [:payload :id]) {:send_condition :goal_above})
+ (t2/update! :model/NotificationCard :id (get-in notification [:payload :id]) {:send_condition :goal_above})
(notification.tu/test-send-notification!
- (t2/select-one :model/Notification (:id notification))
+ (t2/select-one :model/Notification :id (:id notification))
{:channel/email
(fn [emails]
(is (= 1 (count emails)))
- (is (false? (t2/select-one-fn :active :model/Notification (:id notification)))))}))))
+ (is (false? (t2/select-one-fn :active :model/Notification :id (:id notification)))))}))))
(deftest non-user-email-test
(notification.tu/with-card-notification
@@ -581,22 +581,22 @@
[]
[@notification.tu/default-email-handler])]
(testing "sanity: notification is active"
- (is (true? (t2/select-one-fn :active :model/Notification (:id notification)))))
+ (is (true? (t2/select-one-fn :active :model/Notification :id (:id notification)))))
;; Simulate an orphaned notification: delete the NotificationCard directly.
;; This mirrors what happens in prod when there is no Malli validation and a card is deleted (FK cascade deletes NotificationCard)
;; but the Notification row itself survives.
- (t2/delete! :model/NotificationCard (:payload_id notification))
+ (t2/delete! :model/NotificationCard :id (:payload_id notification))
(testing "sanity: notification still exists but its payload record is gone"
- (is (t2/exists? :model/Notification (:id notification)))
- (is (not (t2/exists? :model/NotificationCard (:payload_id notification)))))
+ (is (t2/exists? :model/Notification :id (:id notification)))
+ (is (not (t2/exists? :model/NotificationCard :id (:payload_id notification)))))
(testing "sending the orphaned notification should delete it rather than crash forever"
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Card no longer exists"
(#'notification.send/send-notification-sync!
- (t2/select-one :model/Notification (:id notification))))))
+ (t2/select-one :model/Notification :id (:id notification))))))
(testing "the notification should be deleted"
- (is (not (t2/exists? :model/Notification (:id notification))))))))))
+ (is (not (t2/exists? :model/Notification :id (:id notification))))))))))
(defn- email->attachment-line-count
[email]
diff --git a/test/metabase/notification/send_test.clj b/test/metabase/notification/send_test.clj
index 2450056d454..22b002346cd 100644
--- a/test/metabase/notification/send_test.clj
+++ b/test/metabase/notification/send_test.clj
@@ -209,7 +209,7 @@
:channel_id (:id chn)
:recipients [{:type :notification-recipient/user :user_id (mt/user->id :crowberto)}]}])]
(testing "sending to a deactivated channel fails with a human-readable error, without retries (#76802)"
- (t2/update! :model/Channel (:id chn) {:active false})
+ (t2/update! :model/Channel :id (:id chn) {:active false})
(let [send-count (atom 0)]
(with-redefs [channel/send! (fn [& _] (swap! send-count inc))]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Failed to deliver"
diff --git a/test/metabase/notification/task/send_test.clj b/test/metabase/notification/task/send_test.clj
index f37b3210057..1d7cfa2bf02 100644
--- a/test/metabase/notification/task/send_test.clj
+++ b/test/metabase/notification/task/send_test.clj
@@ -107,7 +107,7 @@
;; other tests insert the same query
notification.execute/execute-card (fn [_creator-id card-id]
{:type :card
- :card (t2/select-one :model/Card card-id)
+ :card (t2/select-one :model/Card :id card-id)
:result {:status :completed :row_count 1 :data {:rows [[1]]}}})
channel/render-notification (fn [& _]
;; the worker waits until the test checked the run
@@ -120,7 +120,7 @@
(#'task.notification/send-notification* (t2/select-one-pk :model/NotificationSubscription
:notification_id (:id notification)))
(let [run-id (t2/select-one-pk :model/TaskRun :notification_id (:id notification))
- run-status #(t2/select-one-fn :status :model/TaskRun run-id)]
+ run-status #(t2/select-one-fn :status :model/TaskRun :id run-id)]
(is (= :started (run-status))
"the job has ended, and the run stays started while the worker sends")
(deliver release true)
@@ -155,7 +155,7 @@
(testing "deletes triggers for subscriptions that no longer exist"
(let [subscription-id (first (t2/select-pks-vec :model/NotificationSubscription
:notification_id (:id notification)))]
- (t2/delete! :notification_subscription subscription-id)
+ (t2/delete! :notification_subscription :id subscription-id)
(testing "sanity check that it has trigger before"
(is (not-empty (notification.tu/send-notification-triggers subscription-id))))
(notification.task.send-trigger/init-send-notification-triggers!)
@@ -177,12 +177,12 @@
(is (not-empty notification-triggers)))
(testing "skips triggers for inactive notifications"
;; Deactivate the notification
- (t2/update! :model/Notification (:id notification) {:active false})
+ (t2/update! :model/Notification :id (:id notification) {:active false})
(notification.task.send-trigger/init-send-notification-triggers!)
(is (empty? (notification.tu/send-notification-triggers subscription-id))))
(testing "recreates triggers when notification is reactivated"
;; Reactivate the notification
- (t2/update! :model/Notification (:id notification) {:active true})
+ (t2/update! :model/Notification :id (:id notification) {:active true})
(notification.task.send-trigger/init-send-notification-triggers!)
(is (= notification-triggers (notification.tu/send-notification-triggers subscription-id))))))))
diff --git a/test/metabase/notification/test_util.clj b/test/metabase/notification/test_util.clj
index a05f4a0cb55..a35c6b9f7bd 100644
--- a/test/metabase/notification/test_util.clj
+++ b/test/metabase/notification/test_util.clj
@@ -132,7 +132,7 @@
(try
(thunk (models.notification/hydrate-notification notification))
(finally
- (t2/delete! :model/Notification (:id notification))))))
+ (t2/delete! :model/Notification :id (:id notification))))))
(defmacro with-temp-notification
"Macro that sets up a temporary notification for testing.
diff --git a/test/metabase/oauth_server/api/admin_test.clj b/test/metabase/oauth_server/api/admin_test.clj
index bc1682fdc25..214be47acde 100644
--- a/test/metabase/oauth_server/api/admin_test.clj
+++ b/test/metabase/oauth_server/api/admin_test.clj
@@ -136,7 +136,7 @@
(testing "Events whose client has been deleted still surface (LEFT JOIN), with null client fields"
(mt/with-temp [:model/OAuthClient client (client-defaults)
:model/OAuthClientEvent event (event-defaults (:id client) "registered")]
- (t2/delete! :model/OAuthClient (:id client))
+ (t2/delete! :model/OAuthClient :id (:id client))
(let [rows (:data (mt/user-http-request :crowberto :get 200 "oauth/authorizations"))
row (first (filter #(= (:id event) (:id %)) rows))]
(is (some? row) "The orphaned audit event should still be returned")
diff --git a/test/metabase/oauth_server/events/revoke_on_deactivation_test.clj b/test/metabase/oauth_server/events/revoke_on_deactivation_test.clj
index 0fca4b856fd..80c45695598 100644
--- a/test/metabase/oauth_server/events/revoke_on_deactivation_test.clj
+++ b/test/metabase/oauth_server/events/revoke_on_deactivation_test.clj
@@ -68,12 +68,12 @@
auth-code (insert-auth-code! user-id)]
(is (not (revoked? :model/OAuthAccessToken access-token))
"token is live while the user is active")
- (t2/update! :model/User user-id {:is_active false})
+ (t2/update! :model/User :id user-id {:is_active false})
(is (revoked? :model/OAuthAccessToken access-token)
"deactivation revokes the token")
(is (not (t2/exists? :model/OAuthAuthorizationCode :code auth-code))
"deactivation deletes the pending authorization code")
(let [revoked-at (t2/select-one-fn :revoked_at :model/OAuthAccessToken :token access-token)]
- (t2/update! :model/User user-id {:is_active true})
+ (t2/update! :model/User :id user-id {:is_active true})
(is (= revoked-at (t2/select-one-fn :revoked_at :model/OAuthAccessToken :token access-token))
"reactivation does not un-revoke the pre-deactivation token"))))))
diff --git a/test/metabase/parameters/chain_filter_test.clj b/test/metabase/parameters/chain_filter_test.clj
index fa206366c00..97d00da12d8 100644
--- a/test/metabase/parameters/chain_filter_test.clj
+++ b/test/metabase/parameters/chain_filter_test.clj
@@ -942,7 +942,7 @@
(is (= 1 (t2/count :model/FieldValues :field_id field-id :type :advanced)))))
(testing "should search with the cached FieldValues when search without constraints"
(mt/with-temp
- [:model/Field field (-> (t2/select-one :model/Field (mt/id :categories :name))
+ [:model/Field field (-> (t2/select-one :model/Field :id (mt/id :categories :name))
(dissoc :id)
(assoc :name "NAME2"))
:model/FieldValues _ {:field_id (:id field)
@@ -980,7 +980,7 @@
(deftest use-cached-field-values-for-remapped-field-test
(testing "fetching a remapped field should returns remapped values (#21528)"
(mt/with-discard-model-updates! [:model/Field]
- (t2/update! :model/Field (mt/id :venues :category_id) {:has_field_values "list"})
+ (t2/update! :model/Field :id (mt/id :venues :category_id) {:has_field_values "list"})
(mt/with-column-remappings [venues.category_id categories.name]
(is (= {:values [[2 "American"] [3 "Artisan"] [4 "Asian"]]
:has_more_values false}
@@ -1049,12 +1049,12 @@
fvs (t2/select :model/FieldValues :field_id field-id)]
;; switch to "list" to prevent [[field-values/create-or-update-full-field-values!]]
;; from changing this to `nil` if the field is `auto-list` and exceeds threshholds
- (t2/update! :model/Field field-id {:has_field_values "list"})
+ (t2/update! :model/Field :id field-id {:has_field_values "list"})
(t2/delete! :model/FieldValues :field_id field-id)
(try
(thunk)
(finally
- (t2/update! :model/Field field-id {:has_field_values has_field_values})
+ (t2/update! :model/Field :id field-id {:has_field_values has_field_values})
(t2/insert! :model/FieldValues fvs))))))
(defmacro ^:private with-clean-field-values-for-field!
diff --git a/test/metabase/parameters/field_test.clj b/test/metabase/parameters/field_test.clj
index 2e393b02ae6..082603aebd9 100644
--- a/test/metabase/parameters/field_test.clj
+++ b/test/metabase/parameters/field_test.clj
@@ -80,13 +80,13 @@
;; Another field review.email => you set it up so that it's a FK to user.email
;; And the desired behavior is you can search for review.email, where the query
;; should query for email from user.email
- (t2/update! :model/Field (mt/id :categories :name) {:semantic_type :type/PK})
- (t2/update! :model/Field (mt/id :users :name) {:semantic_type :type/FK
- :has_field_values "search"
- :fk_target_field_id (mt/id :categories :name)})
+ (t2/update! :model/Field :id (mt/id :categories :name) {:semantic_type :type/PK})
+ (t2/update! :model/Field :id (mt/id :users :name) {:semantic_type :type/FK
+ :has_field_values "search"
+ :fk_target_field_id (mt/id :categories :name)})
(is (= [["African"]]
- (parameters.field/search-values (t2/select-one :model/Field (mt/id :users :name))
- (t2/select-one :model/Field (mt/id :users :name))
+ (parameters.field/search-values (t2/select-one :model/Field :id (mt/id :users :name))
+ (t2/select-one :model/Field :id (mt/id :users :name))
"African"
nil))))))
diff --git a/test/metabase/parameters/params_test.clj b/test/metabase/parameters/params_test.clj
index de7f8e43b28..1ecbce49b9b 100644
--- a/test/metabase/parameters/params_test.clj
+++ b/test/metabase/parameters/params_test.clj
@@ -55,7 +55,7 @@
(testing "Inactive Entity Name fields should not be hydrated (#65207)"
(let [name-field-id (mt/id :venues :name)]
(try
- (t2/update! :model/Field name-field-id {:active false})
+ (t2/update! :model/Field :id name-field-id {:active false})
(is (= {:name "ID"
:table_id (mt/id :venues)
:semantic_type :type/PK
@@ -64,7 +64,7 @@
(t2/hydrate :name_field)
mt/derecordize)))
(finally
- (t2/update! :model/Field name-field-id {:active true}))))))
+ (t2/update! :model/Field :id name-field-id {:active true}))))))
;;; -------------------------------------------------- param_fields --------------------------------------------------
diff --git a/test/metabase/permissions/models/collection/graph_test.clj b/test/metabase/permissions/models/collection/graph_test.clj
index a667cb12464..3c961796f84 100644
--- a/test/metabase/permissions/models/collection/graph_test.clj
+++ b/test/metabase/permissions/models/collection/graph_test.clj
@@ -602,7 +602,7 @@
new-graph (assoc before :groups {(u/the-id (perms-group/all-users)) {collection-id :read}})]
@(graph/update-graph! new-graph)
(is (malli= [:map [:id :int] [:user_id :int] [:before :some] [:after :some]]
- (t2/select-one :model/CollectionPermissionGraphRevision (inc (:revision before))))
+ (t2/select-one :model/CollectionPermissionGraphRevision :id (inc (:revision before))))
"Values for before and after should be present in the revision."))))))
(deftest issue-70596-large-collection-ids-test
diff --git a/test/metabase/permissions/models/data_permissions_test.clj b/test/metabase/permissions/models/data_permissions_test.clj
index 947a6594939..98886a8e50e 100644
--- a/test/metabase/permissions/models/data_permissions_test.clj
+++ b/test/metabase/permissions/models/data_permissions_test.clj
@@ -533,14 +533,14 @@
(data-perms/set-table-permission! group-id-1 table-id-1 :perms/view-data :unrestricted)
(is (= :unrestricted
(data-perms/table-permission-for-user user-id :perms/view-data database-id table-id-1)))
- (t2/update! :model/Table table-id-1 {:active false})
+ (t2/update! :model/Table :id table-id-1 {:active false})
(testing "Deactivated table has minimum permissions when reading straight from DB"
(is (= :blocked (data-perms/table-permission-for-user user-id :perms/view-data database-id table-id-1))))
(testing "Deactivated table has minimum permissions when reading from cache"
(data-perms/with-relevant-permissions-for-user user-id
(is (= :blocked (data-perms/table-permission-for-user user-id :perms/view-data database-id table-id-1)))))
(testing "Reactivating the table allows the perms to be read again"
- (t2/update! :model/Table table-id-1 {:active true})
+ (t2/update! :model/Table :id table-id-1 {:active true})
(is (= :unrestricted
(data-perms/table-permission-for-user user-id :perms/view-data database-id table-id-1))))))))
@@ -569,10 +569,10 @@
(testing "\na grant on an active table counts"
(check! true :yes))
(testing "\nthe same grant does not count once the table is deactivated"
- (t2/update! :model/Table table-id {:active false})
+ (t2/update! :model/Table :id table-id {:active false})
(check! false :no))
(testing "\nreactivating the table restores it"
- (t2/update! :model/Table table-id {:active true})
+ (t2/update! :model/Table :id table-id {:active true})
(check! true :yes)))))))
(deftest permissions-for-user-test
diff --git a/test/metabase/permissions/models/permissions_group_test.clj b/test/metabase/permissions/models/permissions_group_test.clj
index 27205a9a609..b3e930f51b1 100644
--- a/test/metabase/permissions/models/permissions_group_test.clj
+++ b/test/metabase/permissions/models/permissions_group_test.clj
@@ -45,7 +45,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"You cannot edit or delete the .* permissions group"
- (t2/update! :model/PermissionsGroup (u/the-id group) {:name "Cool People"}))))))))
+ (t2/update! :model/PermissionsGroup :id (u/the-id group) {:name "Cool People"}))))))))
(deftest ^:parallel new-users-test
(testing "newly created users should get added to the appropriate magic groups"
@@ -112,14 +112,14 @@
(testing "flipping the is_superuser bit should add/remove user from Admin group as appropriate"
(testing "setting is_superuser -> true should add user to Admin"
(mt/with-temp [:model/User {user-id :id}]
- (t2/update! :model/User user-id {:is_superuser true})
+ (t2/update! :model/User :id user-id {:is_superuser true})
(is (true? (t2/exists? :model/PermissionsGroupMembership, :user_id user-id, :group_id (u/the-id (perms-group/admin)))))))))
(deftest add-remove-from-admin-group-test-4
(testing "flipping the is_superuser bit should add/remove user from Admin group as appropriate"
(testing "setting is_superuser -> false should remove user from Admin"
(mt/with-temp [:model/User {user-id :id} {:is_superuser true}]
- (t2/update! :model/User user-id {:is_superuser false})
+ (t2/update! :model/User :id user-id {:is_superuser false})
(is (false? (t2/exists? :model/PermissionsGroupMembership, :user_id user-id, :group_id (u/the-id (perms-group/admin)))))))))
(deftest data-graph-for-group-check-all-groups-test
diff --git a/test/metabase/permissions/test_util.clj b/test/metabase/permissions/test_util.clj
index 4d71abe9295..6edf901c154 100644
--- a/test/metabase/permissions/test_util.clj
+++ b/test/metabase/permissions/test_util.clj
@@ -193,10 +193,10 @@
(let [user-id (u/the-id user-or-id)
original-value (t2/select-one-fn :is_data_analyst :model/User :id user-id)]
(try
- (t2/update! :model/User user-id {:is_data_analyst true})
+ (t2/update! :model/User :id user-id {:is_data_analyst true})
(thunk)
(finally
- (t2/update! :model/User user-id {:is_data_analyst original-value})))))
+ (t2/update! :model/User :id user-id {:is_data_analyst original-value})))))
(defmacro with-data-analyst-role!
"Runs `body` with the given user's `is_data_analyst` column set to true.
diff --git a/test/metabase/permissions_rest/api_test.clj b/test/metabase/permissions_rest/api_test.clj
index 4849241b0a5..ee41e41fbb8 100644
--- a/test/metabase/permissions_rest/api_test.clj
+++ b/test/metabase/permissions_rest/api_test.clj
@@ -120,10 +120,10 @@
(mt/with-premium-features #{}
(is (data-analyst-group-listed?))
(testing "deactivating the only member hides the group"
- (t2/update! :model/User user-id {:is_active false})
+ (t2/update! :model/User :id user-id {:is_active false})
(is (not (data-analyst-group-listed?))))
(testing "reactivating them brings it back, the membership having survived"
- (t2/update! :model/User user-id {:is_active true})
+ (t2/update! :model/User :id user-id {:is_active true})
(is (data-analyst-group-listed?))
(is (t2/exists? :model/PermissionsGroupMembership
:user_id user-id :group_id (data-analyst-group-id)))))))))
diff --git a/test/metabase/public_sharing_rest/api_documents_test.clj b/test/metabase/public_sharing_rest/api_documents_test.clj
index d17070f82ce..3871b1a3ded 100644
--- a/test/metabase/public_sharing_rest/api_documents_test.clj
+++ b/test/metabase/public_sharing_rest/api_documents_test.clj
@@ -72,7 +72,7 @@
:model/Card {card2-id :id} {:name "Card 2"
:dataset_query (mt/mbql-query venues {:limit 10})
:document_id (:id document)}]
- (t2/update! :model/Document (:id document)
+ (t2/update! :model/Document :id (:id document)
{:document (documents.test-util/cards->prose-mirror-ast [card1-id card2-id])})
(let [result (mt/client :get 200 (str "public/document/" (:public_uuid document)))]
(testing "response includes cards field"
@@ -112,7 +112,7 @@
(is (= 200
(:status (mt/client-full-response :get (str "public/document/" uuid))))))
(testing "Document is not accessible after archiving"
- (t2/update! :model/Document (:id document) {:archived true})
+ (t2/update! :model/Document :id (:id document) {:archived true})
(is (= "Not found."
(mt/client :get 404 (str "public/document/" uuid))))))))))
@@ -134,7 +134,7 @@
:model/Card card {:name "Test Card"
:dataset_query (mt/mbql-query venues {:limit 5})
:document_id (:id document)}]
- (t2/update! :model/Document (:id document)
+ (t2/update! :model/Document :id (:id document)
{:document (documents.test-util/cards->prose-mirror-ast [(:id card)])})
(let [result (mt/client :get 202 (format "public/document/%s/card/%d" (:public_uuid document) (:id card)))]
(is (some? result))
@@ -158,7 +158,7 @@
:model/Card card {:name "Export Test Card"
:dataset_query (mt/mbql-query venues {:limit 5})
:document_id (:id document)}]
- (t2/update! :model/Document (:id document)
+ (t2/update! :model/Document :id (:id document)
{:document (documents.test-util/cards->prose-mirror-ast [(:id card)])})
(testing "Can export card results as CSV"
(let [response (mt/client-full-response :post (format "public/document/%s/card/%d/csv"
diff --git a/test/metabase/public_sharing_rest/api_test.clj b/test/metabase/public_sharing_rest/api_test.clj
index 9fa3a460b95..c92903cfe49 100644
--- a/test/metabase/public_sharing_rest/api_test.clj
+++ b/test/metabase/public_sharing_rest/api_test.clj
@@ -160,7 +160,7 @@
(is (nil? (raw-public-uuid-prefix model id))))
(let [uuid (str (random-uuid))]
(testing "sharing encrypts the uuid at rest and derives the prefix"
- (t2/update! model id {:public_uuid uuid})
+ (t2/update! model :id id {:public_uuid uuid})
(let [raw (raw-public-uuid model id)]
(is (encryption/decryptable-string? raw) "public_uuid is stored as ciphertext")
(is (not= uuid raw) "public_uuid is not stored in plaintext")
@@ -170,13 +170,13 @@
(is (= id (public-sharing/public-uuid->id model uuid)) "resolves by uuid via the prefix lookup"))
(testing "an unrelated update while public sharing is disabled leaves uuid + prefix intact"
(mt/with-temporary-setting-values [enable-public-sharing false]
- (t2/update! model id {:name "renamed while unshared"}))
+ (t2/update! model :id id {:name "renamed while unshared"}))
(is (= uuid (encryption/maybe-decrypt (raw-public-uuid model id))) "public_uuid untouched")
(is (= (subs uuid 0 public-sharing/public-uuid-prefix-length) (raw-public-uuid-prefix model id))
"prefix untouched")
(is (= id (public-sharing/public-uuid->id model uuid)) "still resolves"))
(testing "unsharing clears uuid + prefix"
- (t2/update! model id {:public_uuid nil})
+ (t2/update! model :id id {:public_uuid nil})
(is (nil? (raw-public-uuid model id)))
(is (nil? (raw-public-uuid-prefix model id)))
(is (nil? (public-sharing/public-uuid->id model uuid)) "no longer resolves"))))
@@ -205,7 +205,7 @@
(mt/with-temporary-setting-values [enable-public-sharing true]
(mt/with-actions [{action-id :action-id} {}]
;; with-actions creates the action already shared; unshare it so the lifecycle starts from a clean slate
- (t2/update! :model/Action action-id {:public_uuid nil})
+ (t2/update! :model/Action :id action-id {:public_uuid nil})
(assert-public-uuid-lifecycle! :model/Action action-id))))))
(deftest ^:synchronized public-uuid-resolves-via-endpoint-test
@@ -239,7 +239,7 @@
(defn- assert-forged-plaintext-does-not-resolve!
[model id]
(let [uuid (str (random-uuid))]
- (t2/update! model id {:public_uuid uuid})
+ (t2/update! model :id id {:public_uuid uuid})
(is (= id (public-sharing/public-uuid->id model uuid)) "a genuine encrypted public_uuid resolves")
(let [forged (str (random-uuid))]
(set-raw-public-uuid! model id forged)
@@ -945,7 +945,7 @@
(is (= {:name true, :dashcards 1, :tabs 0}
(fetch-public-dashboard dash)))
(testing "We shouldn't see Cards that have been archived"
- (t2/update! :model/Card (u/the-id card) {:archived true})
+ (t2/update! :model/Card :id (u/the-id card) {:archived true})
(is (= {:name true, :dashcards 0, :tabs 0}
(fetch-public-dashboard dash)))))
(testing "dashboard with tabs should return tabs"
@@ -958,7 +958,7 @@
(testing "GET /api/public/dashboard/:uuid round-trips the dashboard's auto_apply_filters value"
(mt/with-temporary-setting-values [enable-public-sharing true]
(with-temp-public-dashboard [dash]
- (t2/update! :model/Dashboard (:id dash) {:auto_apply_filters false})
+ (t2/update! :model/Dashboard :id (:id dash) {:auto_apply_filters false})
(is (false? (:auto_apply_filters (client/client :get 200 (str "public/dashboard/" (:public_uuid dash))))))))))
(deftest public-dashboard-with-nested-card-and-parameter-test
@@ -1114,7 +1114,7 @@
(is (= "Not found."
(client/client :get 404 (dashcard-url dash card dashcard))))))
(testing "if the Card has been archived."
- (t2/update! :model/Card (u/the-id card) {:archived true})
+ (t2/update! :model/Card :id (u/the-id card) {:archived true})
(is (= "Not found."
(client/client :get 404 (dashcard-url dash card dashcard))))))))))
@@ -1200,7 +1200,7 @@
(mt/with-temp [:model/Collection {collection-id :id}]
(perms/revoke-collection-permissions! (perms-group/all-users) collection-id)
(with-temp-public-dashboard-and-card [dash {card-id :id, :as card} dashcard]
- (t2/update! :model/Card card-id {:collection_id collection-id})
+ (t2/update! :model/Card :id card-id {:collection_id collection-id})
(is (= "You don't have permissions to do that."
(mt/user-http-request :rasta :post 403 (format "card/%d/query" card-id)))
"Sanity check: shouldn't be allowed to run the query normally")
@@ -1216,8 +1216,8 @@
(mt/with-temp [:model/Collection {collection-id :id}]
(perms/revoke-collection-permissions! (perms-group/all-users) collection-id)
(with-temp-public-dashboard-and-card [dash {card-id :id, :as card} dashcard]
- (let [original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard (:id dash))]
- (t2/update! :model/Card card-id {:collection_id collection-id})
+ (let [original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard :id (:id dash))]
+ (t2/update! :model/Card :id card-id {:collection_id collection-id})
(mt/with-temporary-setting-values [synchronous-batch-updates true]
(mt/user-http-request :rasta :get 202 (dashcard-url dash card dashcard)))
(is (not= original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard :id (:id dash))))))))))))
@@ -1479,7 +1479,7 @@
(api.dashboard-test/with-chain-filter-fixtures [{:keys [dashboard param-keys]}]
(let [uuid (str (random-uuid))]
(is (= 1
- (t2/update! :model/Dashboard (u/the-id dashboard) {:public_uuid uuid})))
+ (t2/update! :model/Dashboard :id (u/the-id dashboard) {:public_uuid uuid})))
(testing "GET /api/public/dashboard/:uuid/params/:param-key/values"
(testing "parameter with source is a static list"
(is (= {:values [["African"] ["American"] ["Asian"]]
@@ -1518,10 +1518,10 @@
(let [card-uuid (str (random-uuid))
field-filter-uuid (str (random-uuid))]
(is (= 1
- (t2/update! :model/Card (u/the-id card) {:public_uuid card-uuid}))
+ (t2/update! :model/Card :id (u/the-id card) {:public_uuid card-uuid}))
"Enabled public setting on card")
(is (= 1
- (t2/update! :model/Card (u/the-id field-filter-card) {:public_uuid field-filter-uuid}))
+ (t2/update! :model/Card :id (u/the-id field-filter-card) {:public_uuid field-filter-uuid}))
"Enabled public setting on field-filter-card")
(testing "GET /api/public/card/:uuid/params/:param-key/values"
(testing "parameter with source is a static list"
@@ -1822,7 +1822,7 @@
(api.dashboard-test/with-chain-filter-fixtures [{:keys [dashboard param-keys]}]
(let [uuid (str (random-uuid))]
(is (= 1
- (t2/update! :model/Dashboard (u/the-id dashboard) {:public_uuid uuid})))
+ (t2/update! :model/Dashboard :id (u/the-id dashboard) {:public_uuid uuid})))
(testing "GET /api/public/dashboard/:uuid/params/:param-key/values"
(is (= {:values [[2 "American"] [3 "Artisan"] [4 "Asian"] [5 "BBQ"] [6 "Bakery"]]
:has_more_values false}
@@ -1837,7 +1837,7 @@
(api.card-test/with-card-param-values-fixtures [{:keys [card param-keys]}]
(let [uuid (str (random-uuid))]
(is (= 1
- (t2/update! :model/Card (u/the-id card) {:public_uuid uuid})))
+ (t2/update! :model/Card :id (u/the-id card) {:public_uuid uuid})))
(testing "GET /api/public/card/:uuid/params/:param-key/values"
(is (= {:values [["African"] ["American"] ["Asian"]]
:has_more_values false}
@@ -2078,7 +2078,7 @@
(is (= "Not found."
(client/client :get 404 (dashcard-url dash card dashcard))))))
(testing "if the Card has been archived."
- (t2/update! :model/Card (u/the-id card) {:archived true})
+ (t2/update! :model/Card :id (u/the-id card) {:archived true})
(is (= "Not found."
(client/client :get 404 (dashcard-url dash card dashcard)))))))))))))
@@ -2456,7 +2456,7 @@
[user-kw dashboard-id]
(binding [api/*current-user-id* (mt/user->id user-kw)]
(:last_used_param_values
- (t2/hydrate (t2/select-one :model/Dashboard dashboard-id) :last_used_param_values))))
+ (t2/hydrate (t2/select-one :model/Dashboard :id dashboard-id) :last_used_param_values))))
(deftest dashcard-tile-query-does-not-save-last-used-parameters-test
(testing "GET api/public/tiles/dashboard/:uuid/dashcard/:dashcard-id/card/:card-id/:zoom/:x/:y"
@@ -2499,7 +2499,7 @@
:lonField (tiles.api-test/encoded-lon-field-ref)))]
(testing "sanity: the tile renders while the Card is live"
(is (= 200 (tile-status))))
- (t2/update! :model/Card card-id {:archived true})
+ (t2/update! :model/Card :id card-id {:archived true})
(testing "and 404s once it is archived"
(is (= 404 (tile-status)))))))))))
@@ -2587,7 +2587,7 @@
:model/DashboardCard unselected-dashcard {:dashboard_id (:id dashboard)
:card_id (:id unselected-card)}
:model/DashboardCard empty-dashcard {:dashboard_id (:id dashboard) :card_id (:id empty-card)}]
- (t2/delete! :model/Timeline (:id missing))
+ (t2/delete! :model/Timeline :id (:id missing))
(perms/revoke-collection-permissions! (perms-group/all-users) collection)
(let [token (jwt/sign {:resource {:dashboard (:id dashboard)} :params {}} secret)
expected {(:id first-dashcard) [(:id first-event)]
@@ -2653,9 +2653,9 @@
(mt/user-http-request :rasta :put 200 card-path {:display "table"}))
(testing "changing display cannot reveal an inaccessible timeline"
(mt/user-http-request :rasta :put 403 card-path {:display "line"})
- (is (= :table (t2/select-one-fn :display :model/Card (:id card))))
+ (is (= :table (t2/select-one-fn :display :model/Card :id (:id card))))
(is (= (:visualization_settings card)
- (t2/select-one-fn :visualization_settings :model/Card (:id card))))
+ (t2/select-one-fn :visualization_settings :model/Card :id (:id card))))
(doseq [path paths]
(is (= {(:id dashcard) []} (dashboard-event-ids (mt/client :get 200 path))))))
(testing "timeline readers can restore a supported display"
@@ -2694,7 +2694,7 @@
:model/DashboardCard dashcard {:dashboard_id (:id dashboard)
:action_id action-id
:card_id model-id}]
- (t2/update! :model/Card model-id
+ (t2/update! :model/Card :id model-id
{:visualization_settings {:timeline.selected_timeline_ids [(:id timeline)]}})
(is (= {(:id dashcard) []} (dashboard-event-ids (public-dashboard dashboard)))))))))
@@ -2744,4 +2744,4 @@
(is (= 401 (:status (if body
(mt/client-full-response method 401 path body)
(mt/client-full-response method 401 path)))))))
- (is (= (:name event) (t2/select-one-fn :name :model/TimelineEvent (:id event)))))))
+ (is (= (:name event) (t2/select-one-fn :name :model/TimelineEvent :id (:id event)))))))
diff --git a/test/metabase/pulse/api/alert_test.clj b/test/metabase/pulse/api/alert_test.clj
index e3fb51d9974..6291bff4be5 100644
--- a/test/metabase/pulse/api/alert_test.clj
+++ b/test/metabase/pulse/api/alert_test.clj
@@ -167,7 +167,7 @@
{:type :notification-recipient/user
:user_id (mt/user->id :lucky)}]}]}]
(mt/user-http-request user :delete status (format "alert/%d/subscription" noti-id))
- (thunk (models.notification/hydrate-notification (t2/select-one :model/Notification noti-id)))))
+ (thunk (models.notification/hydrate-notification (t2/select-one :model/Notification :id noti-id)))))
email-recipients (fn [notification]
(->> notification :handlers (m/find-first #(= :channel/email (:channel_type %))) :recipients))]
(testing "creator can unsubscribe themselves"
diff --git a/test/metabase/pulse/api/pulse_test.clj b/test/metabase/pulse/api/pulse_test.clj
index 642803e4dea..2047484eac7 100644
--- a/test/metabase/pulse/api/pulse_test.clj
+++ b/test/metabase/pulse/api/pulse_test.clj
@@ -647,7 +647,7 @@
(t2/select-one-fn :collection_position :model/Pulse :id (u/the-id pulse)))))
(testing "...and unset (unpin) it as well?"
(pulse-test/with-pulse-in-collection! [_ collection pulse]
- (t2/update! :model/Pulse (u/the-id pulse) {:collection_position 1})
+ (t2/update! :model/Pulse :id (u/the-id pulse) {:collection_position 1})
(perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection)
(mt/user-http-request :rasta :put 200 (str "pulse/" (u/the-id pulse))
{:collection_position nil})
@@ -660,7 +660,7 @@
(is (= nil
(t2/select-one-fn :collection_position :model/Pulse :id (u/the-id pulse))))
(testing "shouldn't be able to unset (unpin) a Pulse"
- (t2/update! :model/Pulse (u/the-id pulse) {:collection_position 1})
+ (t2/update! :model/Pulse :id (u/the-id pulse) {:collection_position 1})
(mt/user-http-request :rasta :put 403 (str "pulse/" (u/the-id pulse))
{:collection_position nil})
(is (= 1
@@ -679,7 +679,7 @@
(testing "Can we unarchive a Pulse?"
(pulse-test/with-pulse-in-collection! [_ collection pulse]
(perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection)
- (t2/update! :model/Pulse (u/the-id pulse) {:archived true})
+ (t2/update! :model/Pulse :id (u/the-id pulse) {:archived true})
(mt/user-http-request :rasta :put 200 (str "pulse/" (u/the-id pulse))
{:archived false})
(is (= false
diff --git a/test/metabase/pulse/dashboard_subscription_test.clj b/test/metabase/pulse/dashboard_subscription_test.clj
index a8de6b95b3b..28b345bb8d0 100644
--- a/test/metabase/pulse/dashboard_subscription_test.clj
+++ b/test/metabase/pulse/dashboard_subscription_test.clj
@@ -117,7 +117,7 @@
:channel/slack)
(pulse.test-util/with-captured-channel-send-messages!
(mt/with-temporary-setting-values [site-url "https://testmb.com"]
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))))))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))))))
(thunk []
(if fixture
(fixture {:dashboard-id dashboard-id,
@@ -970,7 +970,7 @@
[:model/Dashboard dashboard-id]
[:model/Collection collection-id]
[:model/Card model-id]]]
- (t2/update! model id {:name (format "New %s name" (name model))}))
+ (t2/update! model :id id {:name (format "New %s name" (name model))}))
(is (=? [{:text (format "### [New Collection name](%s/collection/%d)\nLinked collection desc" site-url collection-id)}
{:text (format "### [New Database name](%s/browse/%d)\nLinked database desc" site-url database-id)}
{:text (format "### [Linked table dname](%s/question?db=%d&table=%d)\nLinked table desc" site-url database-id table-id)}
@@ -1021,7 +1021,7 @@
[:model/Dashboard dashboard-id]
[:model/Collection collection-id]
[:model/Card model-id]]]
- (t2/update! model id {:name (format "New %s name" (name model))}))
+ (t2/update! model :id id {:name (format "New %s name" (name model))}))
(is (=? [{:text (format "### [New Collection name](%s/collection/%d)\nLinked collection desc" site-url collection-id)}
{:text (format "### [New Database name](%s/browse/%d)\nLinked database desc" site-url database-id)}
{:text (format "### [Linked table dname](%s/question?db=%d&table=%d)\nLinked table desc" site-url database-id table-id)}
@@ -1317,7 +1317,7 @@
:pulse_channel_id pc-id}]
(is (= "<h1>dashboard description</h1>"
(->> (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))
:channel/email first :message first :content
(re-find #"<h1>dashboard description</h1>")))))))
@@ -1340,7 +1340,7 @@
:model/PulseChannel {pc-id :id} {:pulse_id pulse-id}
:model/PulseChannelRecipient _ {:user_id (pulse.test-util/rasta-id)
:pulse_channel_id pc-id}]
- (let [pulse (t2/select-one :model/Pulse pulse-id)
+ (let [pulse (t2/select-one :model/Pulse :id pulse-id)
has-link? (fn [pulse]
(->> (pulse.test-util/with-captured-channel-send-messages!
(pulse.send/send-pulse! pulse))
@@ -1462,7 +1462,7 @@
;; icon
pulse.test-util/png-attachment]})
(-> (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))
:channel/email
first
(mt/summarize-multipart-single-email (re-pattern error-msg)))))))))
@@ -1496,7 +1496,7 @@
;; active card result
pulse.test-util/png-attachment]})
(-> (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))
:channel/email
first
(mt/summarize-multipart-single-email #"My Precious Card" #"Archived Card")))))))
@@ -1519,7 +1519,7 @@
:creator_id (mt/user->id :rasta)
:dashboard dashboard-id
:channel-type :email}]
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))
(is (empty? (.listFiles ^java.io.File @@#'notification.temp-storage/temp-dir)))))))
(deftest dashboard-with-rows-saved-to-disk-test
@@ -1548,7 +1548,7 @@
:model/PulseChannelRecipient _ {:user_id (pulse.test-util/rasta-id)
:pulse_channel_id pc-id}]
(let [pulse-results (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))]
(is (= (rasta-dashsub-message
{:message [{"Aviary KPIs" true}
pulse.test-util/png-attachment]})
@@ -1577,7 +1577,7 @@
:model/PulseChannelRecipient _ {:user_id (pulse.test-util/rasta-id)
:pulse_channel_id pc-id}]
(let [pulse-results (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))]
(is (= (rasta-dashsub-message
{:message [{"Aviary KPIs" true
"Dashboard content available in attached files" true}
@@ -1625,7 +1625,7 @@
:pulse_channel_id pc-id}]
(let [executed (do-with-executed-card-ids
#(pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))]
(is (= [attached-id] @executed)))))
(testing "attachment-only + include_pdf still executes every card, since the PDF renders the whole dashboard"
(mt/with-temp [:model/PulseChannel {pc-id :id} {:pulse_id pulse-id
@@ -1636,7 +1636,7 @@
:pulse_channel_id pc-id}]
(let [executed (do-with-executed-card-ids
#(pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))]
(is (= #{attached-id other-id} (set @executed))))))
(testing "a slack channel executes every card"
(mt/with-temp [:model/PulseChannel _ {:pulse_id pulse-id
@@ -1644,7 +1644,7 @@
:details {:channel "#general"}}]
(let [executed (do-with-executed-card-ids
#(pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))]
(is (= #{attached-id other-id} (set @executed))))))))
(deftest dashboard-sub-body-only-cards-use-display-limit-test
@@ -1676,7 +1676,7 @@
(u/prog1 (orig dashcard parameters opts)
(swap! row-counts assoc (:card_id dashcard) (-> <> :result :row_count))))]
(pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))
(is (< 2000 (get @row-counts attached-id)) "attached card runs to the attachment limit")
(is (= 2000 (get @row-counts body-only-id)) "body-only card gets the interactive display limit")))))
@@ -1741,7 +1741,7 @@
:model/PulseChannelRecipient _ {:user_id (pulse.test-util/rasta-id)
:pulse_channel_id pc-id}]
(let [pulse-results (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))]
(testing "renderer is called with the subscription's dashboard id and resolved parameters"
(is (= dashboard-id (:dashboard-id @render-args)))
(is (= [] (:parameters @render-args))))
@@ -1777,7 +1777,7 @@
:model/PulseChannelRecipient _ {:user_id (pulse.test-util/rasta-id)
:pulse_channel_id pc-id}]
(let [pulse-results (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))]
(is (false? @called?))
(is (= (rasta-dashsub-message
{:message [{"Aviary KPIs" true}
@@ -1806,7 +1806,7 @@
:model/PulseChannelRecipient _ {:user_id (pulse.test-util/rasta-id)
:pulse_channel_id pc-id}]
(-> (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))
:channel/email
first)))
@@ -1848,7 +1848,7 @@
(.getBytes "%PDF-1.4 stub" "UTF-8"))]
(pulse.test-util/slack-test-setup!
(let [results (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))
msg (first (:channel/slack results))]
(testing "renderer is called with the subscription's dashboard id"
(is (= dashboard-id (:dashboard-id @render-args))))
@@ -1874,7 +1874,7 @@
:details {:channel "#general"}}]
(pulse.test-util/slack-test-setup!
(let [results (pulse.test-util/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))
msg (first (:channel/slack results))]
(is (nil? (:pdf msg)))
(is (some #(= "image" (:type %)) (:blocks msg)))))))))
diff --git a/test/metabase/pulse/models/pulse_channel_test.clj b/test/metabase/pulse/models/pulse_channel_test.clj
index 40f313d2423..76b4ead110c 100644
--- a/test/metabase/pulse/models/pulse_channel_test.clj
+++ b/test/metabase/pulse/models/pulse_channel_test.clj
@@ -399,18 +399,18 @@
(is (= #{(pulse->trigger-info pulse-id daily-at-6pm [pc-id])}
(send-pulse-triggers pulse-id))))
(testing "updating the schedule of a trigger will remove it from the existing trigger and create a new one"
- (t2/update! :model/PulseChannel pc-id daily-at-7pm)
+ (t2/update! :model/PulseChannel :id pc-id daily-at-7pm)
(is (=? #{(pulse->trigger-info pulse-id daily-at-7pm [pc-id])}
(send-pulse-triggers pulse-id))))
(testing "disable PC will delete its trigger"
- (t2/update! :model/PulseChannel pc-id {:enabled false})
+ (t2/update! :model/PulseChannel :id pc-id {:enabled false})
(is (empty? (send-pulse-triggers pulse-id))))
(testing "reenable PC will add its trigger"
- (t2/update! :model/PulseChannel pc-id {:enabled true})
+ (t2/update! :model/PulseChannel :id pc-id {:enabled true})
(is (=? #{(pulse->trigger-info pulse-id daily-at-7pm [pc-id])}
(send-pulse-triggers pulse-id))))
(testing "remove the trigger if PC is deleted"
- (t2/delete! :model/PulseChannel pc-id)
+ (t2/delete! :model/PulseChannel :id pc-id)
(is (empty? (send-pulse-triggers pulse-id)))))))
(deftest e2e-multiple-pcs-test
@@ -428,7 +428,7 @@
daily-at-6pm)]
(is (=? #{(pulse->trigger-info pulse-id daily-at-6pm [pc-id-1 pc-id-2])}
(send-pulse-triggers pulse-id)))
- (t2/delete! :model/PulseChannel pc-id-2)
+ (t2/delete! :model/PulseChannel :id pc-id-2)
(testing "deleting channel-2 should remove the id, but keep the existing trigger"
(is (=? #{(pulse->trigger-info pulse-id daily-at-6pm [pc-id-1])}
(send-pulse-triggers pulse-id))))))
@@ -439,11 +439,11 @@
(is (=? #{(pulse->trigger-info pulse-id daily-at-6pm [pc-id-1 pc-id-2])}
(send-pulse-triggers pulse-id)))
(testing "change schedule of a trigger will remove it from the existing trigger and create a new one"
- (t2/update! :model/PulseChannel pc-id-2 daily-at-7pm)
+ (t2/update! :model/PulseChannel :id pc-id-2 daily-at-7pm)
(is (=? #{(pulse->trigger-info pulse-id daily-at-6pm [pc-id-1])
(pulse->trigger-info pulse-id daily-at-7pm [pc-id-2])}
(send-pulse-triggers pulse-id))))
(testing "change it back to the original schedule will remove the trigger and update channel-ids of the existing one"
- (t2/update! :model/PulseChannel pc-id-2 daily-at-6pm)
+ (t2/update! :model/PulseChannel :id pc-id-2 daily-at-6pm)
(is (=? #{(pulse->trigger-info pulse-id daily-at-6pm [pc-id-1 pc-id-2])}
(send-pulse-triggers pulse-id)))))))))
diff --git a/test/metabase/pulse/models/pulse_test.clj b/test/metabase/pulse/models/pulse_test.clj
index 9fd92231561..ea640204238 100644
--- a/test/metabase/pulse/models/pulse_test.clj
+++ b/test/metabase/pulse/models/pulse_test.clj
@@ -292,9 +292,9 @@
:model/Dashboard {dashboard-id :id} {}
:model/Pulse {pulse-id :id} {:dashboard_id dashboard-id :collection_id collection-id}]
(is (thrown-with-msg? Exception #"collection ID of a dashboard subscription cannot be directly modified"
- (t2/update! :model/Pulse pulse-id {:collection_id (inc collection-id)})))
+ (t2/update! :model/Pulse :id pulse-id {:collection_id (inc collection-id)})))
(is (thrown-with-msg? Exception #"dashboard ID of a dashboard subscription cannot be modified"
- (t2/update! :model/Pulse pulse-id {:dashboard_id (inc dashboard-id)}))))))
+ (t2/update! :model/Pulse :id pulse-id {:dashboard_id (inc dashboard-id)}))))))
(deftest no-archived-cards-test
(testing "make sure fetching a Pulse doesn't return any archived cards"
@@ -322,7 +322,7 @@
(do-with-objects
(fn [{:keys [archived? user-id]}]
(testing "make the User inactive"
- (is (pos? (t2/update! :model/User user-id {:is_active false}))))
+ (is (pos? (t2/update! :model/User :id user-id {:is_active false}))))
(testing "Pulse should be archived"
(is (archived?))))))
(testing "multiple subscribers"
@@ -334,10 +334,10 @@
:model/PulseChannelRecipient _ {:pulse_channel_id pulse-channel-id :user_id user-2-id}]
(is (not (archived?)))
(testing "User 1 becomes inactive: Pulse should not be archived yet (because User 2 is still a recipient)"
- (is (pos? (t2/update! :model/User user-id {:is_active false})))
+ (is (pos? (t2/update! :model/User :id user-id {:is_active false})))
(is (not (archived?))))
(testing "User 2 becomes inactive: Pulse should now be archived because it has no more recipients"
- (is (t2/update! :model/User user-2-id {:is_active false}))
+ (is (t2/update! :model/User :id user-2-id {:is_active false}))
(is (archived?))
(testing "PulseChannel & PulseChannelRecipient rows should have been archived as well."
(is (not (t2/exists? :model/PulseChannel :id pulse-channel-id)))
@@ -350,7 +350,7 @@
:model/PulseChannel {channel-2-id :id} {:pulse_id pulse-id}
:model/PulseChannelRecipient _ {:pulse_channel_id channel-2-id :user_id user-2-id}]
(testing "make User 1 inactive"
- (is (t2/update! :model/User user-id {:is_active false})))
+ (is (t2/update! :model/User :id user-id {:is_active false})))
(testing "Pulse should not be archived"
(is (not (archived?))))))))
(testing "still sent to a Slack channel"
@@ -360,16 +360,16 @@
:details {:channel "#general"}
:pulse_id pulse-id}]
(testing "make the User inactive"
- (is (pos? (t2/update! :model/User user-id {:is_active false}))))
+ (is (pos? (t2/update! :model/User :id user-id {:is_active false}))))
(testing "Pulse should not be archived"
(is (not (archived?))))))))
(testing "still sent to email addresses\n"
(testing "emails on the same channel as deleted User\n"
(do-with-objects
(fn [{:keys [archived? user-id pulse-channel-id]}]
- (t2/update! :model/PulseChannel pulse-channel-id {:details {:emails ["[email protected]"]}})
+ (t2/update! :model/PulseChannel :id pulse-channel-id {:details {:emails ["[email protected]"]}})
(testing "make the User inactive"
- (is (pos? (t2/update! :model/User user-id {:is_active false}))))
+ (is (pos? (t2/update! :model/User :id user-id {:is_active false}))))
(testing "Pulse should not be archived"
(is (not (archived?)))))))
(testing "emails on a different channel\n"
@@ -379,7 +379,7 @@
:details {:emails ["[email protected]"]}
:pulse_id pulse-id}]
(testing "make the User inactive"
- (is (pos? (t2/update! :model/User user-id {:is_active false}))))
+ (is (pos? (t2/update! :model/User :id user-id {:is_active false}))))
(testing "Pulse should not be archived"
(is (not (archived?))))))))))))
@@ -392,17 +392,17 @@
(is (= #{(pulse-channel-test/pulse->trigger-info pulse-id pulse-channel-test/daily-at-6pm [pc-id])}
(pulse-channel-test/send-pulse-triggers pulse-id)))
(testing "archived pulse will disable pulse channels and remove triggers"
- (t2/update! :model/Pulse pulse-id {:archived true})
- (is (false? (t2/select-one-fn :enabled :model/PulseChannel pc-id)))
+ (t2/update! :model/Pulse :id pulse-id {:archived true})
+ (is (false? (t2/select-one-fn :enabled :model/PulseChannel :id pc-id)))
(is (empty? (pulse-channel-test/send-pulse-triggers pulse-id))))
(testing "re-enabled pulse will re-enable pulse channels and add triggers"
- (t2/update! :model/Pulse pulse-id {:archived false})
- (is (true? (t2/select-one-fn :enabled :model/PulseChannel pc-id)))
+ (t2/update! :model/Pulse :id pulse-id {:archived false})
+ (is (true? (t2/select-one-fn :enabled :model/PulseChannel :id pc-id)))
(is (= #{(pulse-channel-test/pulse->trigger-info pulse-id pulse-channel-test/daily-at-6pm [pc-id])}
(pulse-channel-test/send-pulse-triggers pulse-id))))
(testing "delete pulse will remove pulse channels and triggers"
- (t2/delete! :model/Pulse pulse-id)
- (is (false? (t2/exists? :model/PulseChannel pc-id)))
+ (t2/delete! :model/Pulse :id pulse-id)
+ (is (false? (t2/exists? :model/PulseChannel :id pc-id)))
(is (empty? (pulse-channel-test/send-pulse-triggers pulse-id)))))))
;;; +----------------------------------------------------------------------------------------------------------------+
@@ -445,7 +445,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"A Pulse can only go in Collections in the \"default\"(?: or :[a-z\-]+)+ namespace."
- (t2/update! :model/Pulse card-id {:collection_id collection-id})))))))
+ (t2/update! :model/Pulse :id card-id {:collection_id collection-id})))))))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Dashboard Subscription Collections Permissions Tests |
diff --git a/test/metabase/pulse/send_test.clj b/test/metabase/pulse/send_test.clj
index f9f64a39918..f6ec112ae42 100644
--- a/test/metabase/pulse/send_test.clj
+++ b/test/metabase/pulse/send_test.clj
@@ -166,7 +166,7 @@
(pulse.test-util/with-captured-channel-send-messages!
(mt/with-temporary-setting-values [site-url "https://testmb.com"]
(notification.tu/with-javascript-visualization-stub
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))))))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))))))
(thunk []
(if fixture
(fixture {:card-id card-id, :pulse-id pulse-id} thunk*)
@@ -224,12 +224,12 @@
:http
(fn [{:keys [card-id pulse-id]} [request]]
- (let [pulse (t2/select-one :model/Pulse pulse-id)
- card (t2/select-one :model/Card card-id)]
+ (let [pulse (t2/select-one :model/Pulse :id pulse-id)
+ card (t2/select-one :model/Card :id card-id)]
(is (=? {:body {:type "alert"
:alert_id pulse-id
:alert_creator_id (mt/malli=? int?)
- :alert_creator_name (t2/select-one-fn :common_name :model/User (:creator_id pulse))
+ :alert_creator_name (t2/select-one-fn :common_name :model/User :id (:creator_id pulse))
:data {:type "question"
:question_id card-id
:question_name (:name card)
@@ -645,7 +645,7 @@
(pulse.test-util/with-captured-channel-send-messages!
(is (thrown-with-msg? clojure.lang.ExceptionInfo
#"Failed to deliver to channel/slack$"
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id)))))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id)))))
count)))))))))
(deftest failure-on-several-channels-names-each-channel-test
@@ -667,7 +667,7 @@
(with-redefs [channel/render-notification (fn [channel-type & _]
(throw (ex-info (str (name channel-type) " failed") {})))]
(let [e (is (thrown? clojure.lang.ExceptionInfo
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))]
;; the channels come in the pulse's channel order, which the test does not fix
(is (re-matches #"Failed to deliver to (channel/email, channel/slack|channel/slack, channel/email)"
(ex-message e)))
@@ -695,7 +695,7 @@
(mt/with-dynamic-fn-redefs [notification.send/send-notification-async!
(fn [notification]
(#'notification.send/put-notification! queue notification))]
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id) :async? true))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id) :async? true))
(is (= #{:channel/email :channel/slack}
(set (for [notification (repeatedly #(#'notification.send/take-notification-with-timeout! queue 0))
:while notification]
@@ -719,7 +719,7 @@
:channel_id channel-id}]
(with-redefs [channel/render-notification (fn [& _] (throw (ex-info "http failed" {})))]
(let [e (is (thrown? clojure.lang.ExceptionInfo
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))]
(is (= (str "Failed to deliver to channel/http " channel-id) (ex-message e)))
(is (=? {:failed-handlers [{:channel_type :channel/http
:channel_id channel-id}]}
@@ -749,7 +749,7 @@
:model/PulseChannel _ {:pulse_id pulse-id
:channel_type "http"
:channel_id (:id channel)}]
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))
(is (=? {:body {:alert_creator_id (mt/user->id :rasta)
:alert_creator_name "Rasta Toucan"
:alert_id pulse-id
@@ -792,7 +792,7 @@
(mt/with-fake-inbox
(let [results (pulse.test-util/with-captured-channel-send-messages!
(mt/with-temporary-setting-values [site-url "https://testmb.com"]
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))]
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))]
(is (seq (:channel/email results)))))))))))
(deftest send-skip-alert-test
diff --git a/test/metabase/pulse/task/send_pulses_test.clj b/test/metabase/pulse/task/send_pulses_test.clj
index 976a5d909e6..25b64bf3f1d 100644
--- a/test/metabase/pulse/task/send_pulses_test.clj
+++ b/test/metabase/pulse/task/send_pulses_test.clj
@@ -131,7 +131,7 @@
(testing "only send to enabled channels that has recipients"
(is (= #{pc} @sent-channel-ids)))
(testing "channels that has no recipients are deleted"
- (is (false? (t2/exists? :model/PulseChannel pc-no-recipient)))))))))
+ (is (false? (t2/exists? :model/PulseChannel :id pc-no-recipient)))))))))
(deftest send-pulse!*-skips-archived-dashboard-test
(testing "a trigger firing for a trashed Dashboard sends nothing and records no task run"
@@ -148,12 +148,12 @@
;; the Notification send paths
(let [task-runs #(t2/select-pks-set :model/TaskRun :entity_type :dashboard :entity_id dash-id)]
(try
- (t2/update! :model/Dashboard dash-id {:archived true})
+ (t2/update! :model/Dashboard :id dash-id {:archived true})
(#'task.send-pulses/send-pulse!* pulse-id #{pc-id})
(is (= #{} @sent-channel-ids))
(is (empty? (task-runs)))
(testing "once the Dashboard is restored, the same fire sends and records a task run"
- (t2/update! :model/Dashboard dash-id {:archived false})
+ (t2/update! :model/Dashboard :id dash-id {:archived false})
(#'task.send-pulses/send-pulse!* pulse-id #{pc-id})
(is (= #{pc-id} @sent-channel-ids))
(is (= 1 (count (task-runs)))))
diff --git a/test/metabase/queries/models/card_test.clj b/test/metabase/queries/models/card_test.clj
index 9d1baadccff..8be23fdcb1c 100644
--- a/test/metabase/queries/models/card_test.clj
+++ b/test/metabase/queries/models/card_test.clj
@@ -130,8 +130,8 @@
(testing "before update"
(is (= {:name "some name", :database_id (mt/id)}
(into {} (t2/select-one [:model/Card :name :database_id] :id id)))))
- (t2/update! :model/Card id {:name "another name"
- :dataset_query (dummy-dataset-query (mt/id))})
+ (t2/update! :model/Card :id id {:name "another name"
+ :dataset_query (dummy-dataset-query (mt/id))})
(testing "after update"
(is (= {:name "another name" :database_id (mt/id)}
(into {} (t2/select-one [:model/Card :name :database_id] :id id)))))))
@@ -231,7 +231,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"A Card can only go in Collections in the \"default\"(?: or :[a-z\-]+)+ namespace."
- (t2/update! :model/Card card-id {:collection_id collection-id})))))))
+ (t2/update! :model/Card :id card-id {:collection_id collection-id})))))))
(deftest ^:parallel normalize-result-metadata-test
(testing "Should normalize result metadata keys when fetching a Card from the DB"
@@ -249,7 +249,7 @@
"updating" (fn [changes f]
(mt/with-temp [:model/Card {card-id :id} {:dataset_query (mt/mbql-query checkins)
:result_metadata (qp.preprocess/query->expected-cols (mt/mbql-query checkins))}]
- (t2/update! :model/Card card-id changes)
+ (t2/update! :model/Card :id card-id changes)
(f (t2/select-one-fn :result_metadata :model/Card :id card-id))))}]
(testing (format "When %s a Card\n" creating-or-updating)
(testing "If result_metadata is empty, we should attempt to populate it"
@@ -488,7 +488,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Invalid Field Filter: Field \d+ \"VENUES\"\.\"NAME\" belongs to Database \d+ \"test-data \(h2\)\", but the query is against Database \d+ \"daily-bird-counts \(h2\)\""
- (t2/update! :model/Card card-id bad-card-data))))))))
+ (t2/update! :model/Card :id card-id bad-card-data))))))))
(deftest ^:parallel validate-parameters-test
(testing "Should validate Card :parameters when"
@@ -508,9 +508,9 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Invalid output:.*:parameters"
- (t2/update! :model/Card id {:parameters [{:id 100}]})))
- (is (pos? (t2/update! :model/Card id {:parameters [{:id "new-valid-id"
- :type "id"}]})))))))
+ (t2/update! :model/Card :id id {:parameters [{:id 100}]})))
+ (is (pos? (t2/update! :model/Card :id id {:parameters [{:id "new-valid-id"
+ :type "id"}]})))))))
(deftest normalize-parameters-test
(testing ":parameters should get normalized when coming out of the DB"
@@ -541,9 +541,9 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Invalid output:.*:parameter_mappings"
- (t2/update! :model/Card id {:parameter_mappings [{:parameter_id 100}]})))
- (is (pos? (t2/update! :model/Card id {:parameter_mappings [{:parameter_id "new-valid-id"
- :target [:field 1000 nil]}]})))))))
+ (t2/update! :model/Card :id id {:parameter_mappings [{:parameter_id 100}]})))
+ (is (pos? (t2/update! :model/Card :id id {:parameter_mappings [{:parameter_id "new-valid-id"
+ :target [:field 1000 nil]}]})))))))
(deftest ^:parallel normalize-parameter-mappings-test
(testing ":parameter_mappings should get normalized when coming out of the DB"
@@ -572,9 +572,9 @@
:parameter_id "_CATEGORY_NAME_"}]
(t2/select :model/ParameterCard :parameterized_object_type "card" :parameterized_object_id card-id)))
(testing "update values_source_config.card_id will update ParameterCard"
- (t2/update! :model/Card card-id {:parameters [(merge default-params
- {:values_source_type "card"
- :values_source_config {:card_id source-card-id-2}})]})
+ (t2/update! :model/Card :id card-id {:parameters [(merge default-params
+ {:values_source_type "card"
+ :values_source_config {:card_id source-card-id-2}})]})
(is (=? [{:card_id source-card-id-2
:parameterized_object_type :card
:parameterized_object_id card-id
@@ -622,7 +622,7 @@
:values_source_type "card"
:values_source_config {:card_id source-card-id}}]}]
(mt/with-dynamic-fn-redefs [parameter-card/upsert-or-delete-from-parameters! (fn [& _] (throw (ex-info "Should not be called" {})))]
- (t2/update! :model/Card card-id-1 {:name "new name"})))))
+ (t2/update! :model/Card :id card-id-1 {:name "new name"})))))
(deftest cleanup-parameter-on-card-changes-test
(mt/dataset test-data
@@ -657,7 +657,7 @@
(t2/select :model/ParameterCard :card_id source-card-id {:order-by [[:parameter_id :asc]]})))
;; update card with removing the products.category
(testing "on update result_metadata"
- (t2/update! :model/Card source-card-id
+ (t2/update! :model/Card :id source-card-id
(mt/card-with-source-metadata-for-query
(mt/mbql-query products {:fields [(mt/$ids $products.title)]
:limit 5})))
@@ -681,7 +681,7 @@
:value_field (mt/$ids $products.title)}}]
(t2/select-one-fn :parameters :model/Card :id (:id card)))))))
(testing "on archive card"
- (t2/update! :model/Card source-card-id {:archived true})
+ (t2/update! :model/Card :id source-card-id {:archived true})
(testing "ParameterCard for card is removed"
(is (=? [] (t2/select :model/ParameterCard :card_id source-card-id))))
(testing "update the dashboard parameter and remove values_config of card"
@@ -717,11 +717,11 @@
:values_source_config {:card_id source-card-id
:value_field [:field "Categories__NAME" {:base-type "type/Text"}]}}]}]
(testing "saving the source card with different columns that still include the value_field keeps the parameter config"
- (t2/update! :model/Card source-card-id (mt/card-with-source-metadata-for-query source-query-2))
+ (t2/update! :model/Card :id source-card-id (mt/card-with-source-metadata-for-query source-query-2))
(is (= param-card-params
(t2/select-one-fn :parameters :model/Card :id param-card-id))))
(testing "removing the join from the source card removes the parameter config"
- (t2/update! :model/Card source-card-id (mt/card-with-source-metadata-for-query venues-query))
+ (t2/update! :model/Card :id source-card-id (mt/card-with-source-metadata-for-query venues-query))
(is (= [{:name "Category name",
:slug "category_name",
:id "category_name_param",
@@ -809,7 +809,7 @@
"Updates the model Card with `model-id` through [[card/update-card!]], as the API does."
[model-id changes]
(mt/with-test-user :crowberto
- (card/update-card! {:card-before-update (t2/select-one :model/Card model-id)
+ (card/update-card! {:card-before-update (t2/select-one :model/Card :id model-id)
:card-updates changes})))
(defn- filtered-venues-query
@@ -875,13 +875,13 @@
(testing "an inserted action takes its model's collection"
(is (= coll-1 (action-collection))))
(testing "moving the model moves its actions"
- (t2/update! :model/Card model-id {:collection_id coll-2})
+ (t2/update! :model/Card :id model-id {:collection_id coll-2})
(is (= coll-2 (action-collection)))
- (t2/update! :model/Card model-id {:collection_id nil})
+ (t2/update! :model/Card :id model-id {:collection_id nil})
(is (nil? (action-collection))))
(testing "an action can't be attached to another model"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"An action's model can't be changed"
- (t2/update! :model/Action action-id {:model_id other-id})))
+ (t2/update! :model/Action :id action-id {:model_id other-id})))
(is (nil? (action-collection))))))))
(deftest model-changes-outside-update-card-publish-no-action-events-test
@@ -889,15 +889,15 @@
(testing "a model becoming a question"
(do-with-model-actions!
(fn [{:keys [model-id]}]
- (is (= #{} (action-events-during! #(t2/update! :model/Card model-id {:type :question})))))))
+ (is (= #{} (action-events-during! #(t2/update! :model/Card :id model-id {:type :question})))))))
(testing "a model query that no longer supports implicit actions"
(do-with-model-actions!
(fn [{:keys [model-id]}]
- (is (= #{} (action-events-during! #(t2/update! :model/Card model-id {:dataset_query (filtered-venues-query)})))))))
+ (is (= #{} (action-events-during! #(t2/update! :model/Card :id model-id {:dataset_query (filtered-venues-query)})))))))
(testing "a deleted model"
(do-with-model-actions!
(fn [{:keys [model-id]}]
- (is (= #{} (action-events-during! #(t2/delete! :model/Card model-id)))))))))
+ (is (= #{} (action-events-during! #(t2/delete! :model/Card :id model-id)))))))))
(deftest ^:parallel extract-result-metadata-non-model-test
(testing "non-model Card extraction drops :result_metadata entirely"
@@ -965,7 +965,7 @@
(deftest serdes-load-legacy-query-integer-literals-test
(testing "a Card loaded from a legacy-MBQL export keeps integer literals in comparisons and runs"
- (let [db-name (t2/select-one-fn :name :model/Database (mt/id))
+ (let [db-name (t2/select-one-fn :name :model/Database :id (mt/id))
price-id (mt/id :venues :price)]
(mt/with-temp [:model/Card {card-id :id} {:dataset_query (mt/mbql-query venues)}]
(let [extracted (serdes/extract-one "Card" nil (t2/select-one :model/Card :id card-id))
@@ -999,7 +999,7 @@
(deftest upgrade-to-v2-db-test-2
(testing ":visualization_settings v. 1 should be upgraded to v. 2 and persisted on update"
(mt/with-temp [:model/Card {card-id :id} {:visualization_settings {:pie.show_legend true}}]
- (t2/update! :model/Card card-id {:name "Favorite Toucan Foods"})
+ (t2/update! :model/Card :id card-id {:name "Favorite Toucan Foods"})
(is (= {:version 2
:pie.show_legend true
:pie.percent_visibility "inside"}
@@ -1425,7 +1425,7 @@
:model/Card {b-id :id} {:name "Metric B", :type :metric, :dataset_query (metric-query a-id)}]
;; close the cycle with a raw update -- the card API rejects cyclic saves, so this is the non-API path
;; (serdes, remote sync, pre-check data) by which a cycle actually reaches the DB
- (t2/update! :model/Card a-id {:dataset_query (metric-query b-id)})
+ (t2/update! :model/Card :id a-id {:dataset_query (metric-query b-id)})
(f a-id b-id))))))
(deftest query-description-metric-reference-cycle-test
@@ -1459,7 +1459,7 @@
(testing "an update touching no schema-governed column leaves the vintage alone"
(mt/with-temp [:model/Card {card-id :id} {}]
(age-card! card-id 20)
- (t2/update! :model/Card card-id {:name "Updated Name"})
+ (t2/update! :model/Card :id card-id {:name "Updated Name"})
(is (= "Updated Name" (t2/select-one-fn :name :model/Card :id card-id))
"the update itself is persisted")
(is (= 20 (stored-card-schema card-id))
@@ -1469,7 +1469,7 @@
(testing "an update touching a schema-governed column migrates the group and stamps the version"
(mt/with-temp [:model/Card {card-id :id} {}]
(age-card! card-id 20)
- (t2/update! :model/Card card-id {:dataset_query (mt/mbql-query venues)})
+ (t2/update! :model/Card :id card-id {:dataset_query (mt/mbql-query venues)})
(is (= card/current-card-schema-version (stored-card-schema card-id))
(str "the bump must reach the database. t2/update! diffs changes against a baseline SELECT; if "
"the after-select schema upgrade runs on that baseline it already reads as current, the "
@@ -1480,7 +1480,7 @@
(mt/with-temp [:model/Collection {coll-id :id} {}
:model/Dashboard {dash-id :id} {:collection_id coll-id}
:model/Card {card-id :id} {}]
- (t2/update! :model/Card card-id {:dashboard_id dash-id})
+ (t2/update! :model/Card :id card-id {:dashboard_id dash-id})
(is (= coll-id
(t2/select-one-fn :collection_id :model/Card :id card-id))))))
@@ -1492,7 +1492,7 @@
:type :query
:query {:source-table (mt/id :venues)
:filter [:= [:field-id (mt/id :venues :name)] "Test"]}}]
- (t2/update! :model/Card card-id {:dataset_query unnormalized-query})
+ (t2/update! :model/Card :id card-id {:dataset_query unnormalized-query})
;; Verify the query was normalized (field-id -> field)
(let [updated-query (t2/select-one-fn :dataset_query :model/Card :id card-id)]
(is (=? [:= {} [:field {} (mt/id :venues :name)] "Test"]
@@ -1502,7 +1502,7 @@
(testing "populate-query-fields is called"
(mt/with-temp [:model/Card {card-id :id} {}]
(let [new-query (mt/mbql-query venues)]
- (t2/update! :model/Card card-id {:dataset_query new-query})
+ (t2/update! :model/Card :id card-id {:dataset_query new-query})
(let [updated-card (t2/select-one :model/Card :id card-id)]
(is (= (mt/id) (:database_id updated-card)))
(is (= (mt/id :venues) (:table_id updated-card)))
@@ -1518,11 +1518,11 @@
:type :query
:query {:source-table (str "card__" model-id)}}}]
(testing "source_card_id is cleared when converting to native SQL"
- (t2/update! :model/Card question-id
+ (t2/update! :model/Card :id question-id
{:dataset_query {:database (mt/id)
:type :native
:native {:query "SELECT * FROM venues"}}})
- (is (nil? (:source_card_id (t2/select-one :model/Card question-id)))))))
+ (is (nil? (:source_card_id (t2/select-one :model/Card :id question-id)))))))
(testing "deleting a model should not cascade delete questions that were converted to native SQL"
(mt/with-temp [:model/Card {model-id :id} {:name "Test Model"
:type :model
@@ -1531,28 +1531,28 @@
:dataset_query {:database (mt/id)
:type :query
:query {:source-table (str "card__" model-id)}}}]
- (t2/update! :model/Card question-id
+ (t2/update! :model/Card :id question-id
{:dataset_query {:database (mt/id)
:type :native
:native {:query "SELECT * FROM venues"}}})
- (t2/delete! :model/Card model-id)
+ (t2/delete! :model/Card :id model-id)
(testing "model should be deleted"
- (is (not (t2/exists? :model/Card model-id))))
+ (is (not (t2/exists? :model/Card :id model-id))))
(testing "converted question should survive"
- (is (t2/exists? :model/Card question-id))))))
+ (is (t2/exists? :model/Card :id question-id))))))
(deftest table-id-cleared-on-conversion-to-native-test
(testing "table_id should be set to nil when a question is converted to native SQL"
(mt/with-temp [:model/Card {card-id :id} {:dataset_query (mt/mbql-query venues)}]
(is (= (mt/id :venues) (t2/select-one-fn :table_id :model/Card :id card-id)))
- (t2/update! :model/Card card-id
+ (t2/update! :model/Card :id card-id
{:dataset_query (mt/native-query {:query "SELECT * FROM venues"})})
(is (nil? (t2/select-one-fn :table_id :model/Card :id card-id)))))
(testing "table_id should be set to nil when the source becomes a native model with no table"
(mt/with-temp [:model/Card {model-id :id} {:type :model
:dataset_query (mt/native-query {:query "SELECT 1"})}
:model/Card {card-id :id} {:dataset_query (mt/mbql-query venues)}]
- (t2/update! :model/Card card-id
+ (t2/update! :model/Card :id card-id
{:dataset_query {:database (mt/id)
:type :query
:query {:source-table (str "card__" model-id)}}})
@@ -1568,7 +1568,7 @@
(is (= (mt/id :venues) (t2/select-one-fn :table_id :model/Card :id card-id)))
;; hard-delete the source card so the table can no longer be derived from the query
(t2/delete! :model/Card :id model-id)
- (t2/update! :model/Card card-id {:name "Renamed, query untouched"})
+ (t2/update! :model/Card :id card-id {:name "Renamed, query untouched"})
(is (= (mt/id :venues) (t2/select-one-fn :table_id :model/Card :id card-id))))))
(deftest assert-no-source-card-id-for-native-query-test
@@ -1584,7 +1584,7 @@
(deftest before-update-embedding-timestamp-test
(testing "maybe-populate-initially-published-at is called"
(mt/with-temp [:model/Card {card-id :id} {:enable_embedding false}]
- (t2/update! :model/Card card-id {:enable_embedding true})
+ (t2/update! :model/Card :id card-id {:enable_embedding true})
(let [updated-card (t2/select-one :model/Card :id card-id)]
(is (some? (:initially_published_at updated-card)))))))
@@ -1592,8 +1592,8 @@
(testing "verified-result-metadata? flag is removed from final changes"
(mt/with-temp [:model/Card {card-id :id} {:dataset_query (mt/mbql-query venues)}]
;; This should not cause an error even though verified-result-metadata? is not a valid column
- (t2/update! :model/Card card-id {:name "Updated"
- :verified-result-metadata? true})
+ (t2/update! :model/Card :id card-id {:name "Updated"
+ :verified-result-metadata? true})
(is (= "Updated" (t2/select-one-fn :name :model/Card :id card-id))))))
(deftest create-card-remote-synced-collection-non-remote-synced-deps-test
@@ -1866,7 +1866,7 @@
(testing "a created card stores the remapped columns of a run"
(is (= 2 (count (filter :remapped_from (:result_metadata card))))))
(finally
- (t2/delete! :model/Card (:id card))))))))
+ (t2/delete! :model/Card :id (:id card))))))))
(deftest create-native-model-external-remap-query-test
(testing "External remapping (FK) should work when querying through a native SQL model (#35842)"
@@ -2012,7 +2012,7 @@
:model/Card {card-id :id} {:dataset_query (mt/mbql-query venues)
:metabot_conversation_id convo-id
:metabot_chart_id "chart-1"}]
- (t2/update! :model/Card card-id changes)
+ (t2/update! :model/Card :id card-id changes)
(is (= {:metabot_conversation_id nil :metabot_chart_id nil}
(t2/select-one [:model/Card :metabot_conversation_id :metabot_chart_id]
:id card-id)))))))
@@ -2022,7 +2022,7 @@
:model/Card {card-id :id} {:dataset_query (mt/mbql-query venues)
:metabot_conversation_id convo-id
:metabot_chart_id "chart-1"}]
- (t2/update! :model/Card card-id {:name "Renamed" :collection_id coll-id})
+ (t2/update! :model/Card :id card-id {:name "Renamed" :collection_id coll-id})
(is (= {:metabot_conversation_id convo-id :metabot_chart_id "chart-1"}
(t2/select-one [:model/Card :metabot_conversation_id :metabot_chart_id]
:id card-id))))))
@@ -2064,7 +2064,7 @@
(t2/query-one {:update :report_card
:set {:card_schema 23, :dimensions nil, :dimension_mappings nil}
:where [:= :id card-id]})
- (t2/update! :model/Card card-id {:dataset_query (mt/mbql-query categories {:aggregation [[:count]]})})
+ (t2/update! :model/Card :id card-id {:dataset_query (mt/mbql-query categories {:aggregation [[:count]]})})
(is (= #{(mt/id :categories)}
(into #{} (map :table-id) (t2/select-one-fn :dimension_mappings :model/Card :id card-id)))))))
@@ -2122,8 +2122,8 @@
(mt/with-temp [:model/Card card {:display :line :visualization_settings before}]
(mt/with-test-user :rasta
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"You don't have permissions"
- (t2/update! :model/Card (:id card) {:visualization_settings after}))))
- (is (= before (t2/select-one-fn :visualization_settings :model/Card (:id card)))))))))
+ (t2/update! :model/Card :id (:id card) {:visualization_settings after}))))
+ (is (= before (t2/select-one-fn :visualization_settings :model/Card :id (:id card)))))))))
(deftest card-timeline-visibility-on-a-display-without-events-test
(testing "a display that cannot draw events shows nothing, so its visibility settings need no timeline access"
@@ -2135,11 +2135,11 @@
(perms/revoke-collection-permissions! (perms-group/all-users) collection)
(mt/with-test-user :rasta
(let [settings {:timeline.selected_timeline_ids [(:id timeline)] :timeline_events.enabled true}]
- (t2/update! :model/Card (:id card) {:visualization_settings settings})
- (is (= settings (t2/select-one-fn :visualization_settings :model/Card (:id card)))))
+ (t2/update! :model/Card :id (:id card) {:visualization_settings settings})
+ (is (= settings (t2/select-one-fn :visualization_settings :model/Card :id (:id card)))))
(testing "switching to a display that draws them is still checked"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"You don't have permissions"
- (t2/update! :model/Card (:id card) {:display :line}))))))))
+ (t2/update! :model/Card :id (:id card) {:display :line}))))))))
(deftest partially-readable-card-timeline-selection-test
(testing "on a card that also selects a timeline the user cannot read"
@@ -2158,11 +2158,11 @@
:timeline.excluded_timeline_event_ids []}
overrides))
;; no bound user, so this restores the starting point without a permission check
- restore! #(t2/update! :model/Card (:id card) {:visualization_settings (settings)})
+ restore! #(t2/update! :model/Card :id (:id card) {:visualization_settings (settings)})
update-settings! (fn [settings]
(mt/with-test-user :rasta
- (t2/update! :model/Card (:id card) {:visualization_settings settings}))
- (t2/select-one-fn :visualization_settings :model/Card (:id card)))]
+ (t2/update! :model/Card :id (:id card) {:visualization_settings settings}))
+ (t2/select-one-fn :visualization_settings :model/Card :id (:id card)))]
(testing "an event of the readable timeline can be hidden and shown again"
(restore!)
(let [hidden (settings :timeline.excluded_timeline_event_ids [(:id readable-event)])]
@@ -2174,7 +2174,7 @@
(is (= hidden (update-settings! hidden)))
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"You don't have permissions"
(update-settings! (settings))))
- (is (= hidden (t2/select-one-fn :visualization_settings :model/Card (:id card))))))
+ (is (= hidden (t2/select-one-fn :visualization_settings :model/Card :id (:id card))))))
(testing "the readable timeline can be deselected and selected again"
(restore!)
(let [deselected (settings :timeline.selected_timeline_ids [(:id private-timeline)])]
@@ -2196,11 +2196,11 @@
(mt/with-test-user :rasta
(testing "unrelated visualization edits preserve inaccessible saved selections"
(let [settings (assoc (:visualization_settings card) :graph.show_values true)]
- (t2/update! :model/Card (:id card) {:visualization_settings settings})
- (is (= settings (t2/select-one-fn :visualization_settings :model/Card (:id card)))))
+ (t2/update! :model/Card :id (:id card) {:visualization_settings settings})
+ (is (= settings (t2/select-one-fn :visualization_settings :model/Card :id (:id card)))))
(testing "an explicit empty selection can hide all events"
- (t2/update! :model/Card (:id card) {:visualization_settings {:timeline.selected_timeline_ids []}})
- (is (= [] (get-in (t2/select-one :model/Card (:id card))
+ (t2/update! :model/Card :id (:id card) {:visualization_settings {:timeline.selected_timeline_ids []}})
+ (is (= [] (get-in (t2/select-one :model/Card :id (:id card))
[:visualization_settings :timeline.selected_timeline_ids]))))))))
(deftest card-timeline-selection-validation-test
@@ -2210,10 +2210,10 @@
(testing (pr-str invalid-ids)
(let [settings {:timeline.selected_timeline_ids invalid-ids}]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Selected timeline IDs must be"
- (t2/update! :model/Card (:id card) {:visualization_settings settings}))))
+ (t2/update! :model/Card :id (:id card) {:visualization_settings settings}))))
(let [settings {:timeline.excluded_timeline_event_ids invalid-ids}]
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Excluded timeline event IDs must be"
- (t2/update! :model/Card (:id card) {:visualization_settings settings})))))))))
+ (t2/update! :model/Card :id (:id card) {:visualization_settings settings})))))))))
(deftest card-timeline-malformed-saved-selection-test
(testing "a malformed selection saved before it was validated can still be repaired"
@@ -2222,11 +2222,11 @@
:visualization_settings {:timeline.selected_timeline_ids 7}}]
(doseq [repaired [[(:id timeline)] []]]
;; no bound user, so each case starts from the malformed value again
- (t2/update! :model/Card (:id card) {:visualization_settings {:timeline.selected_timeline_ids 7}})
+ (t2/update! :model/Card :id (:id card) {:visualization_settings {:timeline.selected_timeline_ids 7}})
(mt/with-test-user :rasta
- (t2/update! :model/Card (:id card) {:visualization_settings {:timeline.selected_timeline_ids repaired}}))
+ (t2/update! :model/Card :id (:id card) {:visualization_settings {:timeline.selected_timeline_ids repaired}}))
(is (= repaired
- (get-in (t2/select-one :model/Card (:id card))
+ (get-in (t2/select-one :model/Card :id (:id card))
[:visualization_settings :timeline.selected_timeline_ids])))))))
(deftest card-timeline-malformed-saved-exclusions-test
@@ -2236,28 +2236,28 @@
:visualization_settings {:timeline.selected_timeline_ids [(:id timeline)]
:timeline.excluded_timeline_event_ids 5}}]
(mt/with-test-user :rasta
- (t2/update! :model/Card (:id card)
+ (t2/update! :model/Card :id (:id card)
{:visualization_settings {:timeline.selected_timeline_ids [(:id timeline)]
:timeline.excluded_timeline_event_ids []}})
- (is (= [] (get-in (t2/select-one :model/Card (:id card))
+ (is (= [] (get-in (t2/select-one :model/Card :id (:id card))
[:visualization_settings :timeline.excluded_timeline_event_ids])))))))
(deftest card-timeline-selection-deleted-timeline-test
(testing "a selection pointing at a deleted timeline still saves, so the card is not stuck"
(mt/with-temp [:model/Timeline timeline {}
:model/Card card {:visualization_settings {:timeline.selected_timeline_ids [(:id timeline)]}}]
- (t2/delete! :model/Timeline (:id timeline))
+ (t2/delete! :model/Timeline :id (:id timeline))
(mt/with-test-user :rasta
- (t2/update! :model/Card (:id card) {:display :line})
- (is (= :line (t2/select-one-fn :display :model/Card (:id card))))))))
+ (t2/update! :model/Card :id (:id card) {:display :line})
+ (is (= :line (t2/select-one-fn :display :model/Card :id (:id card))))))))
(deftest card-timeline-selection-without-user-context-test
(mt/with-temp [:model/Timeline timeline {}]
- (t2/delete! :model/Timeline (:id timeline))
+ (t2/delete! :model/Timeline :id (:id timeline))
(mt/with-current-user nil
(mt/with-temp [:model/Card card {:visualization_settings {:timeline.selected_timeline_ids [(:id timeline)]}}]
- (t2/update! :model/Card (:id card) {:visualization_settings {:timeline.selected_timeline_ids []}})
- (is (= [] (get-in (t2/select-one :model/Card (:id card))
+ (t2/update! :model/Card :id (:id card) {:visualization_settings {:timeline.selected_timeline_ids []}})
+ (is (= [] (get-in (t2/select-one :model/Card :id (:id card))
[:visualization_settings :timeline.selected_timeline_ids])))))))
(deftest skip-dimension-backfill-skips-only-upgrade-24-test
@@ -2283,9 +2283,9 @@
:where [:= :id card-id]}))
"abandoned-ident")))
(testing "without the flag the backfill runs"
- (is (seq (:dimensions (t2/select-one :model/Card card-id)))))
+ (is (seq (:dimensions (t2/select-one :model/Card :id card-id)))))
(binding [card-schema/*skip-dimension-backfill?* true]
- (let [card (t2/select-one :model/Card card-id)]
+ (let [card (t2/select-one :model/Card :id card-id)]
(testing "the expensive 24 backfill is skipped"
(is (nil? (:dimensions card)))
(is (nil? (:dimension_mappings card))))
diff --git a/test/metabase/queries/models/parameter_card_test.clj b/test/metabase/queries/models/parameter_card_test.clj
index d09482a1cc2..98bcd262483 100644
--- a/test/metabase/queries/models/parameter_card_test.clj
+++ b/test/metabase/queries/models/parameter_card_test.clj
@@ -204,4 +204,4 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"invalid parameterized_object_type"
- (t2/update! :model/ParameterCard pc-id {:parameterized_object_type "invalid"})))))))
+ (t2/update! :model/ParameterCard :id pc-id {:parameterized_object_type "invalid"})))))))
diff --git a/test/metabase/queries_rest/api/card_test.clj b/test/metabase/queries_rest/api/card_test.clj
index 3e2e503d0be..d9b966a7057 100644
--- a/test/metabase/queries_rest/api/card_test.clj
+++ b/test/metabase/queries_rest/api/card_test.clj
@@ -151,7 +151,7 @@
(doseq [card-or-id (if (sequential? card-or-cards-or-ids)
card-or-cards-or-ids
[card-or-cards-or-ids])]
- (t2/update! :model/Card (u/the-id card-or-id) {:collection_id (u/the-id collection)}))
+ (t2/update! :model/Card :id (u/the-id card-or-id) {:collection_id (u/the-id collection)}))
;; now use `grant-perms-fn!` to grant appropriate perms
(grant-perms-fn! (perms-group/all-users) collection)
;; call (f)
@@ -325,7 +325,7 @@
(is (= "CREATED_AT" (-> dashboard-result mt/cols first :name)))
(is (= 1 (count (mt/cols collection-result))))
(is (= 1 (count (mt/rows collection-result))))))
- (t2/update! :model/Card metric-id {:dimensions [(assoc dimension :default true)]})
+ (t2/update! :model/Card :id metric-id {:dimensions [(assoc dimension :default true)]})
(doseq [query-path [path (format "card/pivot/%d/query" metric-id)]]
(let [result (mt/user-http-request :crowberto :post 202 query-path {:dashboard_id dashboard-id})]
(is (= "PRODUCT_ID" (-> result mt/cols first :name)))
@@ -335,9 +335,9 @@
(is (= "PRODUCT_ID" (-> result mt/cols first :name)))
(is (= stored-metadata
(t2/select-one-fn :result_metadata :model/Card :id metric-id))))
- (t2/update! :model/Card metric-id {:dimensions [(assoc dimension
- :default true
- :status :status/orphaned)]})
+ (t2/update! :model/Card :id metric-id {:dimensions [(assoc dimension
+ :default true
+ :status :status/orphaned)]})
(testing "an orphaned default keeps the saved dashboard breakout and makes collection previews scalar"
(let [dashboard-result (mt/user-http-request :crowberto :post 202 path
{:dashboard_id dashboard-id})
@@ -2383,7 +2383,7 @@
:name "Another new name"
:dataset_query {:lib/type "mbql/query"
:stages [{:source-table (mt/id :checkins)}]}}
- (update-card! :rasta 200 {:name "Another new name", :dataset_query (t2/select-one-fn :dataset_query :model/Card card-id)})))))))))))
+ (update-card! :rasta 200 {:name "Another new name", :dataset_query (t2/select-one-fn :dataset_query :model/Card :id card-id)})))))))))))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Card updates that impact alerts |
@@ -2405,7 +2405,7 @@
:notification-card {:disable_links (boolean disable-links?)}}]
(when deleted?
(let [[email] (notification.tu/with-mock-inbox-email!
- (f (->> notification :payload :card_id (t2/select-one :model/Card))))]
+ (f (t2/select-one :model/Card :id (-> notification :payload :card_id))))]
:subject "One of your alerts has stopped working"
:body [{(str expected-email-re) (not should-re-not-match?)}]}
@@ -2536,7 +2536,7 @@
:details {:value "[email protected]"}}]}]}]
(mt/with-temporary-setting-values [site-url "https://metabase.com"]
(mt/user-http-request :rasta :put 200 (str "card/" (->> notification :payload :card_id)) {:display display})
- (is (t2/exists? :model/Notification (:id notification))
+ (is (t2/exists? :model/Notification :id (:id notification))
"Alert should not have been deleted"))))))))
;;; +----------------------------------------------------------------------------------------------------------------+
@@ -3097,7 +3097,7 @@
(is (= "You don't have permissions to do that."
(mt/user-http-request :rasta :put 403 (str "card/" (:id card))
{:visualization_settings {:timeline.selected_timeline_ids [(:id timeline)]}})))
- (is (not (contains? (t2/select-one-fn :visualization_settings :model/Card (:id card))
+ (is (not (contains? (t2/select-one-fn :visualization_settings :model/Card :id (:id card))
:timeline.selected_timeline_ids))))))
(deftest card-timeline-moved-to-private-collection-test
@@ -3111,7 +3111,7 @@
:visualization_settings {:timeline.selected_timeline_ids [(:id readable) (:id moved)]
:timeline.excluded_timeline_event_ids []}}]
(perms/revoke-collection-permissions! (perms-group/all-users) restricted)
- (t2/update! :model/Timeline (:id moved) {:collection_id (:id restricted)})
+ (t2/update! :model/Timeline :id (:id moved) {:collection_id (:id restricted)})
(testing "an event of the timeline the editor can still read can be hidden"
(let [settings {:timeline.selected_timeline_ids [(:id readable) (:id moved)]
:timeline.excluded_timeline_event_ids [(:id readable-event)]}]
@@ -3210,7 +3210,7 @@
(is (= "You don't have permissions to do that."
(mt/user-http-request :rasta :put 403 (str "card/" (:id source-card))
{:dashboard_id (:id dashboard)})))
- (is (nil? (t2/select-one-fn :dashboard_id :model/Card (:id source-card)))))
+ (is (nil? (t2/select-one-fn :dashboard_id :model/Card :id (:id source-card)))))
(testing "a user who can read the timeline can move the card into the public dashboard"
(is (= (:id dashboard)
(:dashboard_id (mt/user-http-request :crowberto :put 200 (str "card/" (:id source-card))
@@ -3230,7 +3230,7 @@
(is (= "You don't have permissions to do that."
(mt/user-http-request :rasta :put 403 (str "card/" card-id) {:dashboard_id dash-id})))
(is (=? {:archived true, :dashboard_id nil}
- (t2/select-one :model/Card card-id)))
+ (t2/select-one :model/Card :id card-id)))
(is (empty? (t2/select :model/DashboardCard :dashboard_id dash-id)))
(testing "a user who can read the timeline can still move it"
(is (=? {:archived false, :dashboard_id dash-id}
@@ -3762,7 +3762,7 @@
(let [metadata (t2/select-one-fn :result_metadata :model/Card :id card-id)
;; simulate updating metadat with user changed stuff
user-edited (add-preserved metadata)]
- (t2/update! :model/Card card-id {:result_metadata user-edited})
+ (t2/update! :model/Card :id card-id {:result_metadata user-edited})
(testing "Saved metadata preserves user edits"
(is (= (map only-user-edits user-edited)
(map only-user-edits (t2/select-one-fn :result_metadata :model/Card :id card-id)))))
@@ -4093,7 +4093,7 @@
;; a saved native Card carries `result_metadata`, which is what lets the value field be found on it; run
;; the wrapper as an admin to populate it, as saving the Card would
(when (= wrapper-query-type :native)
- (t2/update! :model/Card wrapper-card-id
+ (t2/update! :model/Card :id wrapper-card-id
{:result_metadata (mt/with-test-user :crowberto
(-> (qp/process-query (nested-card-wrapper-query :native nested-card-id))
(get-in [:data :results_metadata :columns])))}))
@@ -4187,7 +4187,7 @@
(testing "Old style, inferred parameters from native template-tags"
(with-card-param-values-fixtures [{:keys [param-keys field-filter-card]}]
;; e2e tests and some older cards don't have an explicit parameter and infer them from the native template tags
- (t2/update! :model/Card (:id field-filter-card) {:parameters []})
+ (t2/update! :model/Card :id (:id field-filter-card) {:parameters []})
(testing "GET /api/card/:card-id/params/:param-key/values for field-filter based params"
(testing "without search query"
(let [response (mt/user-http-request :crowberto :get 200
@@ -4263,7 +4263,7 @@
:slug "ID"}]}]
(testing "Get values for field-filter based params for Fields that have a Field -> Field remapping\n"
(is (= :type/Name
- (t2/select-one-fn :semantic_type :model/Field (mt/id :venues :name)))
+ (t2/select-one-fn :semantic_type :model/Field :id (mt/id :venues :name)))
"venues.name has semantic_type=type/Name, so it will be searched")
(testing "without search query"
(mt/let-url [url (param-values-url card param-key)]
@@ -4399,9 +4399,9 @@
:alias "SomeAlias"}]}})]
(is (nil? (:based_on_upload (request card'))))))
(testing "\nIf the table is not based on uploads, based_on_upload should be nil"
- (t2/update! :model/Table table-id {:is_upload false})
+ (t2/update! :model/Table :id table-id {:is_upload false})
(is (nil? (:based_on_upload (request card))))
- (t2/update! :model/Table table-id {:is_upload true}))
+ (t2/update! :model/Table :id table-id {:is_upload true}))
(testing "\nIf the user doesn't have data perms for the database, based_on_upload should be nil"
(mt/with-temp-copy-of-db
(mt/with-no-data-perms-for-all-users!
@@ -4414,7 +4414,7 @@
:dataset_query (mt/native-query {:query "select 1"}))]
(is (nil? (:based_on_upload (request card'))))))
(testing "\nIf uploads are disabled on all databases, based_on_upload should be nil"
- (t2/update! :model/Database other-db-id {:uploads_enabled false})
+ (t2/update! :model/Database :id other-db-id {:uploads_enabled false})
(is (nil? (:based_on_upload (request card))))))))))))
(deftest based-on-upload-test
@@ -4812,12 +4812,12 @@
:model/Card {other-card-id :id} {}]
(testing "We can update with `archived=true` or `archived=false`"
(is (mt/user-http-request :crowberto :put 200 (str "card/" card-id) {:archived true}))
- (is (t2/select-one-fn :archived :model/Card card-id))
+ (is (t2/select-one-fn :archived :model/Card :id card-id))
(is (mt/user-http-request :crowberto :put 200 (str "card/" card-id) {:archived false}))
- (is (not (t2/select-one-fn :archived :model/Card card-id))))
+ (is (not (t2/select-one-fn :archived :model/Card :id card-id))))
(testing "we can update the name"
(is (mt/user-http-request :crowberto :put 200 (str "card/" card-id) {:name "foo"}))
- (is (= "foo" (t2/select-one-fn :name :model/Card card-id))))
+ (is (= "foo" (t2/select-one-fn :name :model/Card :id card-id))))
(testing "We can update with `dashboard_id` for a normal card."
(is (mt/user-http-request :crowberto :put 200 (str "card/" other-card-id) {:dashboard_id dash-id}))
(is (= dash-id (t2/select-one-fn :dashboard_id :model/Card :id other-card-id))))
@@ -4911,7 +4911,7 @@
:dashboard_id nil}
(mt/user-http-request :rasta :put 200 (str "card/" card-id) {:collection_id coll-id
:dashboard_id nil})))
- (is (= coll-id (t2/select-one-fn :collection_id :model/Card card-id)))
+ (is (= coll-id (t2/select-one-fn :collection_id :model/Card :id card-id)))
(is (t2/exists? :model/DashboardCard :dashboard_id dash-id :card_id card-id)))))
(deftest move-question-to-dashboard-can-choose-tab-test
@@ -4985,7 +4985,7 @@
(mt/user-http-request :rasta :put 200 (str "card/" card-id "?delete_old_dashcards=true")
{:collection_id coll-id
:dashboard_id nil})))
- (is (= coll-id (t2/select-one-fn :collection_id :model/Card card-id)))
+ (is (= coll-id (t2/select-one-fn :collection_id :model/Card :id card-id)))
(is (not (t2/exists? :model/DashboardCard :dashboard_id dash-id :card_id card-id))))))
(deftest move-question-to-existing-dashboard-test
@@ -5222,7 +5222,7 @@
:moderation_status "verified"}
(-> (mt/user-http-request :rasta :get 200 (str "card/" card-id))
:dashboard)))
- (t2/delete! :model/ModerationReview mr-id)
+ (t2/delete! :model/ModerationReview :id mr-id)
(is (= {:name "My Dashboard"
:id dash-id
:moderation_status nil}
@@ -5393,7 +5393,7 @@
:type :native
:native {:query "SELECT * FROM products"}}}]
;; Update snippet to reference card (creates snippet → card)
- (t2/update! :model/NativeQuerySnippet (:id snippet)
+ (t2/update! :model/NativeQuerySnippet :id (:id snippet)
{:content (str "WHERE id IN ({{#" (:id card) "}})")
:template_tags {(str "card-" (:id card)) {:type :card
:card-id (:id card)
@@ -5441,7 +5441,7 @@
:name (str "#" (:id card-1))
:display-name "Card 1"}}}}}]
;; Update snippet-2 to reference card-2 (creates snippet-2 → card-2 → card-1 → snippet-1)
- (t2/update! :model/NativeQuerySnippet (:id snippet-2)
+ (t2/update! :model/NativeQuerySnippet :id (:id snippet-2)
{:content (str "AND id IN ({{#" (:id card-2) "}})")
:template_tags {(str "card-" (:id card-2)) {:type :card
:card-id (:id card-2)
@@ -5485,7 +5485,7 @@
:snippet-name "snippet-1"
:name "snippet:snippet-1"
:display-name "Snippet 1"}}}]
- (t2/update! :model/NativeQuerySnippet (:id snippet-1)
+ (t2/update! :model/NativeQuerySnippet :id (:id snippet-1)
{:content "WHERE category = 'Electronics' {{snippet: snippet-2}}"})
;; Now try to create a NEW card that references snippet-1 (which has a cycle with snippet-2)
;; This should fail even though the card doesn't exist yet
@@ -5907,13 +5907,13 @@
(mt/with-temp [:model/Card {card-id :id} {:dataset_query query-with-default}]
;; First, run the card with the default value so result_metadata gets populated server-side.
(mt/user-http-request :rasta :post 202 (format "card/%d/query" card-id))
- (let [metadata-before (t2/select-one-fn :result_metadata :model/Card card-id)]
+ (let [metadata-before (t2/select-one-fn :result_metadata :model/Card :id card-id)]
(is (seq metadata-before)
"baseline: a run with the default value should populate result_metadata")
;; Now edit the SQL and remove the default — the recompute at save time can't run the query
(mt/user-http-request :crowberto :put 200 (format "card/%d" card-id)
{:dataset_query query-without-default})
- (let [metadata-after (t2/select-one-fn :result_metadata :model/Card card-id)]
+ (let [metadata-after (t2/select-one-fn :result_metadata :model/Card :id card-id)]
(is (= (map :name metadata-before)
(map :name metadata-after))
"result_metadata should be preserved across SQL edits when the recompute cannot run")))))))
diff --git a/test/metabase/query_processor/api_test.clj b/test/metabase/query_processor/api_test.clj
index 334046121c1..da083e92ac6 100644
--- a/test/metabase/query_processor/api_test.clj
+++ b/test/metabase/query_processor/api_test.clj
@@ -1220,7 +1220,7 @@
(mt/with-temp [:model/User {user-id :id} {:email "[email protected]"}
:model/Collection collection {}]
;; Publish the venues table into this collection
- (t2/update! :model/Table (mt/id :venues) {:is_published true :collection_id (u/the-id collection)})
+ (t2/update! :model/Table :id (mt/id :venues) {:is_published true :collection_id (u/the-id collection)})
(let [all-users (perms/all-users-group)]
;; Set database-level permissions first to establish baseline
(perms/set-database-permission! all-users (mt/id) :perms/view-data :unrestricted)
diff --git a/test/metabase/query_processor/dashboard_test.clj b/test/metabase/query_processor/dashboard_test.clj
index e3700b233ad..a938bffc23f 100644
--- a/test/metabase/query_processor/dashboard_test.clj
+++ b/test/metabase/query_processor/dashboard_test.clj
@@ -57,7 +57,7 @@
(:dimensions metric))]
(is (some? dimension) (str "Missing metric dimension " display-name))
(when dimension
- (t2/update! :model/Card metric-id {:dimensions dimensions}))))
+ (t2/update! :model/Card :id metric-id {:dimensions dimensions}))))
(defn- default-metric-dimension [metric]
(let [provider (lib-metric/metadata-provider)]
@@ -202,7 +202,7 @@
dimensions (mapv #(cond-> %
(:default %) (dissoc :sources))
(:dimensions metric))]
- (t2/update! :model/Card metric-id {:dimensions dimensions}))
+ (t2/update! :model/Card :id metric-id {:dimensions dimensions}))
(testing "missing dimension sources are derived from the mapping"
(let [metric (t2/select-one :model/Card :id metric-id)
dimension (mt/as-admin (default-metric-dimension metric))]
@@ -219,7 +219,7 @@
(:default %)
(assoc :sources [{:type :field, :field-id (mt/id :orders :tax)}]))
(:dimensions metric))]
- (t2/update! :model/Card metric-id {:dimensions dimensions}))
+ (t2/update! :model/Card :id metric-id {:dimensions dimensions}))
(testing "a curated default hidden from the current user is ignored"
(mt/with-temp-vals-in-db :model/Field (mt/id :orders :product_id) {:visibility_type :sensitive}
(mt/with-test-user :rasta
@@ -255,7 +255,7 @@
dimensions (mapv #(cond-> %
(:default %) (assoc :status :status/orphaned))
(:dimensions metric))]
- (t2/update! :model/Card metric-id {:dimensions dimensions}))
+ (t2/update! :model/Card :id metric-id {:dimensions dimensions}))
(testing "an orphaned curated default falls back to the saved breakout"
(let [result (run-query-for-dashcard dashboard-id metric-id dashcard-id)]
(is (= "CREATED_AT" (-> result mt/cols first :name))))))))))
@@ -626,7 +626,7 @@
:template-tags {}})}
:model/DashboardCard {dashcard-id :id} {:card_id card-id
:dashboard_id dashboard-id}]
- (let [original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard dashboard-id)]
+ (let [original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard :id dashboard-id)]
(mt/with-temporary-setting-values [synchronous-batch-updates true]
(run-query-for-dashcard dashboard-id card-id dashcard-id)
(is (not= original-last-viewed-at (t2/select-one-fn :last_viewed_at :model/Dashboard :id dashboard-id)))))))))
diff --git a/test/metabase/query_processor/implicit_joins_test.clj b/test/metabase/query_processor/implicit_joins_test.clj
index f7f7118590e..9be57e66cfe 100644
--- a/test/metabase/query_processor/implicit_joins_test.clj
+++ b/test/metabase/query_processor/implicit_joins_test.clj
@@ -258,8 +258,8 @@
query (lib/query mp table)
fk-field (mt/id :long_col_name :fk)
id-2-field (mt/id :long_col_name_2 :foo_abcdefg_abcdefg_abcdefg_abcdefg_abcdefg_abcdefg_abcdefg_abc)]
- (t2/update! :model/Field fk-field {:semantic_type :type/FK
- :fk_target_field_id id-2-field})
+ (t2/update! :model/Field :id fk-field {:semantic_type :type/FK
+ :fk_target_field_id id-2-field})
(testing "Implicit join with long column name should use actual DB column name as source alias (#67002)"
(let [breakoutable-cols (lib/breakoutable-columns query)
;; Use case-insensitive matching because H2 stores column names in uppercase
diff --git a/test/metabase/query_processor/middleware/results_metadata_test.clj b/test/metabase/query_processor/middleware/results_metadata_test.clj
index 929fa81d3f3..79f3d6373ed 100644
--- a/test/metabase/query_processor/middleware/results_metadata_test.clj
+++ b/test/metabase/query_processor/middleware/results_metadata_test.clj
@@ -539,14 +539,14 @@
:result_metadata nil}]
(let [run-with-filter!
(fn [product-id]
- (t2/update! :model/Card card-id
+ (t2/update! :model/Card :id card-id
{:dataset_query (mt/mbql-query orders
{:aggregation [[:count] [:sum $total]]
:breakout [$product_id]
:filter [:= $product_id product-id]})})
(mt/as-admin
(qp/process-query-for-card
- (t2/select-one :model/Card card-id) :api
+ (t2/select-one :model/Card :id card-id) :api
:make-run (constantly
(fn [query info]
(qp/process-query (assoc query :info info))))))
@@ -624,11 +624,11 @@
(query-processor.db/set-card-result-metadata! card-id baseline)
(mt/as-admin
(qp/process-query-for-card
- (t2/select-one :model/Card card-id) :api
+ (t2/select-one :model/Card :id card-id) :api
:parameters [{:id "_pid_" :type :number :target [:variable [:template-tag "pid"]] :value "50"}]
:make-run (constantly
(fn [query info]
(qp/process-query (assoc query :info info))))))
- (let [after (t2/select-one-fn :result_metadata :model/Card card-id)]
+ (let [after (t2/select-one-fn :result_metadata :model/Card :id card-id)]
(is (= #{"product_id" "cnt"} (into #{} (map (comp u/lower-case-en :name)) after))
"parameter-independent schema change should persist despite the parameter skip")))))
diff --git a/test/metabase/query_processor/middleware/update_used_cards_test.clj b/test/metabase/query_processor/middleware/update_used_cards_test.clj
index c2354cbce1e..700254c611e 100644
--- a/test/metabase/query_processor/middleware/update_used_cards_test.clj
+++ b/test/metabase/query_processor/middleware/update_used_cards_test.clj
@@ -29,18 +29,18 @@
(defn- card-last-used-at
[card-id]
- (t2/select-one-fn :last_used_at :model/Card card-id))
+ (t2/select-one-fn :last_used_at :model/Card :id card-id))
(defn- card-updated-at
[card-id]
- (t2/select-one-fn :updated_at :model/Card card-id))
+ (t2/select-one-fn :updated_at :model/Card :id card-id))
(defn do-test!
"Check if `last_used_at` of `card-id` is nil, then execute `f`, then check that `last_used_at` is non nil."
[card-id thunk]
(assert (fn? thunk))
- (t2/update! (t2/table-name :model/Card) card-id {:last_used_at #t "2025-05-16T12:40:00-07:00"
- :updated_at #t "2025-05-16T12:40:00-07:00"})
+ (t2/update! (t2/table-name :model/Card) :id card-id {:last_used_at #t "2025-05-16T12:40:00-07:00"
+ :updated_at #t "2025-05-16T12:40:00-07:00"})
(let [original-last-used-at (card-last-used-at card-id)
original-updated-at (card-updated-at card-id)]
(mt/with-temporary-setting-values [synchronous-batch-updates true]
@@ -102,7 +102,7 @@
(#'qp.update-used-cards/update-used-cards!* [{:id card-id-1 :timestamp two-hours-ago}
{:id card-id-1 :timestamp one-hour-ago}])
(is (= one-hour-ago
- (-> (t2/select-one-fn :last_used_at :model/Card card-id-1)
+ (-> (t2/select-one-fn :last_used_at :model/Card :id card-id-1)
t/offset-date-time
(.withNano 0))))))
(testing "if the existing last_used_at is greater than the updating values, do not override it"
@@ -110,7 +110,7 @@
[:model/Card {card-id-2 :id} {:last_used_at now}]
(#'qp.update-used-cards/update-used-cards!* [{:id card-id-2 :timestamp one-hour-ago}])
(is (= now
- (-> (t2/select-one-fn :last_used_at :model/Card card-id-2)
+ (-> (t2/select-one-fn :last_used_at :model/Card :id card-id-2)
t/offset-date-time
(.withNano 0))))))
(testing "if metabase is in read only mode still sets the last_used_at timestamp"
@@ -119,6 +119,6 @@
(mt/with-temporary-setting-values [read-only-mode true]
(#'qp.update-used-cards/update-used-cards!* [{:id card-id-1 :timestamp now}])
(is (= now
- (-> (t2/select-one-fn :last_used_at :model/Card card-id-1)
+ (-> (t2/select-one-fn :last_used_at :model/Card :id card-id-1)
t/offset-date-time
(.withNano 0)))))))))
diff --git a/test/metabase/query_processor/persistence_test.clj b/test/metabase/query_processor/persistence_test.clj
index ebdfaf58453..d80fc734351 100644
--- a/test/metabase/query_processor/persistence_test.clj
+++ b/test/metabase/query_processor/persistence_test.clj
@@ -105,7 +105,7 @@
;; card result_metadata is persisted in legacy shape
#_{:clj-kondo/ignore [:deprecated-var]}
(qp.metadata/legacy-result-metadata nil))]
- (t2/update! :model/Card id {:result_metadata metadata})))]
+ (t2/update! :model/Card :id id {:result_metadata metadata})))]
;; 4 seconds is long but redshift can be a little slow
(when (= ::timed-out (mt/wait-for-result updater 4000 ::timed-out))
(throw (ex-info "Query metadata not set in time for querying against model"
diff --git a/test/metabase/revisions/api_test.clj b/test/metabase/revisions/api_test.clj
index 2c0f0b1a476..88901a2dc5d 100644
--- a/test/metabase/revisions/api_test.clj
+++ b/test/metabase/revisions/api_test.clj
@@ -86,7 +86,7 @@
(mt/with-temp [:model/Card {:keys [id] :as card} {:name "A card"}]
(create-card-revision! (:id card) true :rasta)
(doseq [i (range (inc revision/max-revisions))]
- (t2/update! :model/Card (:id card) {:name (format "New name %d" i)})
+ (t2/update! :model/Card :id (:id card) {:name (format "New name %d" i)})
(create-card-revision! (:id card) false :rasta))
(is (= ["renamed this Card from \"New name 14\" to \"New name 15\"."
"renamed this Card from \"New name 13\" to \"New name 14\"."
@@ -161,7 +161,7 @@
:type "native"
:native {:query "SELECT 2 --comment"}}}}]
(create-transform-revision! transform-id true :crowberto)
- (t2/update! :model/Transform transform-id
+ (t2/update! :model/Transform :id transform-id
{:source {:type "query"
:query {:database y-db-id
:type "native"
@@ -718,7 +718,7 @@
:model/Card {card-id :id} {}]
(update-dashcards! dash-id [card-id dq-id])
(update-dashcards! dash-id [])
- (t2/update! :model/Card dq-id {:dashboard_id other-dash-id})
+ (t2/update! :model/Card :id dq-id {:dashboard_id other-dash-id})
(revert-dashboard-api! dash-id (:id (second (dashboard-revisions-api dash-id))))
(is (= #{card-id} (t2/select-fn-set :card_id :model/DashboardCard :dashboard_id dash-id)))
(is (= 1 (t2/count :model/DashboardCard :dashboard_id dash-id)))))))
@@ -731,7 +731,7 @@
:model/Card {card-id :id} {}]
(update-dashcards! dash-id [card-id dq-id])
;; make it a non-DQ before removing it, otherwise it will be auto-archived
- (t2/update! :model/Card dq-id {:dashboard_id nil})
+ (t2/update! :model/Card :id dq-id {:dashboard_id nil})
(update-dashcards! dash-id [])
(revert-dashboard-api! dash-id (:id (second (dashboard-revisions-api dash-id))))
(is (= #{dq-id card-id} (t2/select-fn-set :card_id :model/DashboardCard :dashboard_id dash-id)))
@@ -746,7 +746,7 @@
:model/Card {card-id :id} {}]
(update-dashcards! dash-id [card-id dq-id])
(update-dashcards! dash-id [])
- (t2/update! :model/Card card-id {:dashboard_id other-dash-id})
+ (t2/update! :model/Card :id card-id {:dashboard_id other-dash-id})
(revert-dashboard-api! dash-id (:id (second (dashboard-revisions-api dash-id))))
(is (= 1 (t2/count :model/DashboardCard :dashboard_id dash-id)))
(is (= #{dq-id} (t2/select-fn-set :card_id :model/DashboardCard :dashboard_id dash-id)))))))
@@ -770,7 +770,7 @@
:breakout [!month.orders.created_at]}})}]
(update-dashcards! dash-id [dq-id])
;; turn it into a model outside the DQ
- (t2/update! :model/Card dq-id {:dashboard_id nil :type :model})
+ (t2/update! :model/Card :id dq-id {:dashboard_id nil :type :model})
;; remove it from the dashboard
(update-dashcards! dash-id [])
(revert-dashboard-api! dash-id (:id (second (dashboard-revisions-api dash-id))))
@@ -1017,7 +1017,7 @@
(testing "Reverting a Card through the API works"
(mt/with-temp [:model/Card {card-id :id} {:name "revert test"}]
(create-card-revision! card-id true :crowberto)
- (t2/update! :model/Card card-id {:description "hi"})
+ (t2/update! :model/Card :id card-id {:description "hi"})
(create-card-revision! card-id false :crowberto)
(let [[_ {prev-id :id}] (revision/revisions :model/Card card-id)]
(is (=? {:description "reverted to an earlier version."}
@@ -1071,7 +1071,7 @@
(let [original-metadata (t2/select-one-fn :result_metadata :model/Card :id card-id)
original-names (map :display_name original-metadata)]
(create-card-revision! card-id true :crowberto)
- (t2/update! :model/Card card-id
+ (t2/update! :model/Card :id card-id
{:result_metadata (mapv #(assoc % :display_name "EDITED") original-metadata)
:visualization_settings {:some_setting true}})
(create-card-revision! card-id false :crowberto)
@@ -1136,7 +1136,7 @@
(perms/revoke-collection-permissions! (perms-group/all-users) restricted)
(create-dashboard-revision! public-id true :crowberto)
;; the card stays on the dashboard, but as a visualizer dashcard its events are no longer shown
- (t2/update! :model/DashboardCard dashcard-id
+ (t2/update! :model/DashboardCard :id dashcard-id
{:visualization_settings {:visualization {:display "line" :columnValuesMapping {} :settings {}}}})
(create-dashboard-revision! public-id false :crowberto)
(let [[_ {revision-id :id}] (revision/revisions :model/Dashboard public-id)]
diff --git a/test/metabase/revisions/events_test.clj b/test/metabase/revisions/events_test.clj
index 4cc512c15a4..31a7181d41e 100644
--- a/test/metabase/revisions/events_test.clj
+++ b/test/metabase/revisions/events_test.clj
@@ -174,7 +174,7 @@
(mt/with-temp [:model/Dashboard {dashboard-id :id, :as dashboard} {}
:model/Card {card-id :id} (card-properties)
:model/DashboardCard dashcard {:card_id card-id, :dashboard_id dashboard-id}]
- (t2/update! :model/DashboardCard (:id dashcard) {:size_x 3})
+ (t2/update! :model/DashboardCard :id (:id dashcard) {:size_x 3})
(events/publish-event! :event/dashboard-update {:object dashboard :user-id (mt/user->id :crowberto)})
(is (= {:model "Dashboard"
:model_id dashboard-id
@@ -227,7 +227,7 @@
:model/DashboardTab {dashtab-id :id} {:name "First tab"
:position 0
:dashboard_id dashboard-id}]
- (t2/update! :model/DashboardTab dashtab-id {:name "New name"})
+ (t2/update! :model/DashboardTab :id dashtab-id {:name "New name"})
(events/publish-event! :event/dashboard-update {:object dashboard :user-id (mt/user->id :rasta)})
(is (= {:model "Dashboard"
:model_id dashboard-id
@@ -250,7 +250,7 @@
:model/DashboardTab {dashtab-id :id} {:name "First tab"
:position 0
:dashboard_id dashboard-id}]
- (t2/delete! :model/DashboardTab dashtab-id)
+ (t2/delete! :model/DashboardTab :id dashtab-id)
(events/publish-event! :event/dashboard-update {:object dashboard :user-id (mt/user->id :rasta)})
(is (= {:model "Dashboard"
:model_id dashboard-id
diff --git a/test/metabase/revisions/impl/card_test.clj b/test/metabase/revisions/impl/card_test.clj
index 2de23dc2c5c..00a065758d9 100644
--- a/test/metabase/revisions/impl/card_test.clj
+++ b/test/metabase/revisions/impl/card_test.clj
@@ -141,7 +141,7 @@
;; we'll automatically delete old revisions if we have more than [[revision/max-revisions]]
;; revisions for an instance, so let's clear everything to make it easier to test
(t2/delete! :model/Revision :model "Card" :model_id (:id card))
- (t2/update! :model/Card (:id card) changes)
+ (t2/update! :model/Card :id (:id card) changes)
(create-card-revision! (:id card) false)
(testing (format "we should track when %s changes" col)
(is (= 1 (t2/count :model/Revision :model "Card" :model_id (:id card)))))
@@ -178,7 +178,7 @@
[:model/Card card card-info]
(let [before (select-keys card [:result_metadata])
changes (update before :result_metadata drop-last)]
- (t2/update! :model/Card (:id card) changes)
+ (t2/update! :model/Card :id (:id card) changes)
(create-card-revision! (:id card) false)
(testing "we should track when :result_metadata changes on model"
(is (= 1 (t2/count :model/Revision :model "Card" :model_id (:id card)))))
diff --git a/test/metabase/revisions/impl/dashboard_test.clj b/test/metabase/revisions/impl/dashboard_test.clj
index 2007bf48f18..bc6ec897334 100644
--- a/test/metabase/revisions/impl/dashboard_test.clj
+++ b/test/metabase/revisions/impl/dashboard_test.clj
@@ -265,7 +265,7 @@
changes {col (update-col col (get dashboard col))}]
(clean-revisions-for-dashboard (:id dashboard))
;; do the update
- (t2/update! :model/Dashboard (:id dashboard) changes)
+ (t2/update! :model/Dashboard :id (:id dashboard) changes)
(create-dashboard-revision! (:id dashboard) false)
(testing (format "we should track when %s changes" col)
(is (= 2 (t2/count :model/Revision :model "Dashboard" :model_id (:id dashboard)))))
@@ -312,7 +312,7 @@
(doseq [col columns]
(clean-revisions-for-dashboard (:id dashboard))
;; do the update
- (t2/update! :model/DashboardCard (:id dashcard) {col (update-col col (get dashcard col))})
+ (t2/update! :model/DashboardCard :id (:id dashcard) {col (update-col col (get dashcard col))})
(create-dashboard-revision! (:id dashboard) false)
(testing (format "we should track when %s changes" col)
(is (= 2 (t2/count :model/Revision :model "Dashboard" :model_id (:id dashboard)))))))))))
@@ -337,7 +337,7 @@
(doseq [col columns]
(clean-revisions-for-dashboard (:id dashboard))
;; do the update
- (t2/update! :model/DashboardTab (:id dashtab) {col (update-col col (get dashtab col))})
+ (t2/update! :model/DashboardTab :id (:id dashtab) {col (update-col col (get dashtab col))})
(create-dashboard-revision! (:id dashboard) false)
(testing (format "we should track when %s changes" col)
(is (= 2 (t2/count :model/Revision :model "Dashboard" :model_id (:id dashboard)))))))))))
@@ -396,7 +396,7 @@
(update serialized-dashboard :cards check-ids))))
(testing "delete the dashcard and modify the dash attributes"
(dashboard-card/delete-dashboard-cards! [(:id dashboard-card)])
- (t2/update! :model/Dashboard dashboard-id
+ (t2/update! :model/Dashboard :id dashboard-id
{:name "Revert Test"
:auto_apply_filters false
:description "something"})
@@ -505,7 +505,7 @@
:dashboard_id dashboard-id}])]
(create-dashboard-revision! dashboard-id false)
;; 2. update a tab name
- (t2/update! :model/DashboardTab tab-1-id {:name "Tab 1 with new name"})
+ (t2/update! :model/DashboardTab :id tab-1-id {:name "Tab 1 with new name"})
(create-dashboard-revision! dashboard-id false)
;; check to make sure we have everything setup before testing
(is (=? [{:id tab-1-id :name "Tab 1 with new name" :position 0}
@@ -531,8 +531,8 @@
:dashboard_id dashboard-id}])]
(create-dashboard-revision! dashboard-id false)
;; 2. delete the 1st tab and re-position the second tab
- (t2/delete! :model/DashboardTab tab-1-id)
- (t2/update! :model/DashboardTab tab-2-id {:position 0})
+ (t2/delete! :model/DashboardTab :id tab-1-id)
+ (t2/update! :model/DashboardTab :id tab-2-id {:position 0})
(create-dashboard-revision! dashboard-id false)
;; check to make sure we have everything setup before testing
(is (=? [{:id tab-2-id :name "Tab 2" :position 0}]
@@ -593,10 +593,10 @@
:col 0
:size_x 4
:size_y 4}])
- (t2/delete! :model/DashboardCard card-2-tab-1)
- (t2/update! :model/DashboardCard card-1-tab-1 {:row 10 :col 10})
+ (t2/delete! :model/DashboardCard :id card-2-tab-1)
+ (t2/update! :model/DashboardCard :id card-1-tab-1 {:row 10 :col 10})
;; 2.b: delete tab 2
- (t2/delete! :model/DashboardTab tab-2-id)
+ (t2/delete! :model/DashboardTab :id tab-2-id)
;; 2.c: create a new tab with 1 card
(let [new-tab-id (t2/insert-returning-pks! :model/DashboardTab {:name "Tab 3"
:position 1
@@ -615,7 +615,7 @@
(testing "and position of first card is (0,0)"
(is (=? {:row 0
:col 0}
- (t2/select-one :model/DashboardCard card-1-tab-1)))))
+ (t2/select-one :model/DashboardCard :id card-1-tab-1)))))
(testing "tab \"Tab 2\" is restored"
(let [new-tab-2 (t2/select-one :model/DashboardTab :dashboard_id dashboard-id :name "Tab 2")]
(is (= 1 (:position new-tab-2)))
@@ -665,7 +665,7 @@
;; 2. delete all the dashcards
(t2/delete! :model/DashboardCard :dashboard_id dashboard-id)
(create-dashboard-revision! dashboard-id false)
- (t2/delete! :model/Card will-be-deleted-card)
+ (t2/delete! :model/Card :id will-be-deleted-card)
(t2/update! :model/Card :id will-be-archived-card {:archived true})
(testing "revert should not include archived or deleted card ids (#34884)"
(revert-to-previous-revision! :model/Dashboard dashboard-id 2)
@@ -685,7 +685,7 @@
;; 0. create initial dashboard revision
(create-dashboard-revision! dashboard-id true)
;; 1. add two parameters - one with a card that will be deleted, one with a card that stays
- (t2/update! :model/Dashboard dashboard-id
+ (t2/update! :model/Dashboard :id dashboard-id
{:parameters [{:id "deleted-source"
:name "Filter with deleted source"
:slug "deleted_source"
@@ -706,10 +706,10 @@
:type "category"}]})
(create-dashboard-revision! dashboard-id false)
;; 2. remove the parameters (simulating user changing the filter settings)
- (t2/update! :model/Dashboard dashboard-id {:parameters []})
+ (t2/update! :model/Dashboard :id dashboard-id {:parameters []})
(create-dashboard-revision! dashboard-id false)
;; 3. delete one card and archive another scenario - here we just delete
- (t2/delete! :model/Card value-source-card)
+ (t2/delete! :model/Card :id value-source-card)
;; 4. revert to the revision that had parameters referencing the now-deleted card
(revert-to-previous-revision! :model/Dashboard dashboard-id 2)
(let [reverted-params (:parameters (t2/select-one :model/Dashboard :id dashboard-id))]
@@ -737,7 +737,7 @@
;; 0. create initial dashboard revision
(create-dashboard-revision! dashboard-id true)
;; 1. add a parameter with a card source
- (t2/update! :model/Dashboard dashboard-id
+ (t2/update! :model/Dashboard :id dashboard-id
{:parameters [{:id "archived-source"
:name "Filter with archived source"
:slug "archived_source"
@@ -747,10 +747,10 @@
:value_field [:field 1 nil]}}]})
(create-dashboard-revision! dashboard-id false)
;; 2. remove the parameters
- (t2/update! :model/Dashboard dashboard-id {:parameters []})
+ (t2/update! :model/Dashboard :id dashboard-id {:parameters []})
(create-dashboard-revision! dashboard-id false)
;; 3. archive the card
- (t2/update! :model/Card will-be-archived-card {:archived true})
+ (t2/update! :model/Card :id will-be-archived-card {:archived true})
;; 4. revert to the revision that had parameters referencing the now-archived card
(revert-to-previous-revision! :model/Dashboard dashboard-id 2)
(let [reverted-params (:parameters (t2/select-one :model/Dashboard :id dashboard-id))]
diff --git a/test/metabase/revisions/impl/document_integration_test.clj b/test/metabase/revisions/impl/document_integration_test.clj
index ad3d5f82714..d9cb5aaac48 100644
--- a/test/metabase/revisions/impl/document_integration_test.clj
+++ b/test/metabase/revisions/impl/document_integration_test.clj
@@ -92,7 +92,7 @@
(is (=? @rasta-revision-info (:user revision)))
(is (= config/mb-version-string (:metabase_version revision))))))
(testing "Multiple revisions are returned in correct order"
- (t2/update! :model/Document doc-id {:name "Updated Document"})
+ (t2/update! :model/Document :id doc-id {:name "Updated Document"})
(create-document-revision! doc-id false :rasta)
(let [revisions (get-document-revisions doc-id)]
(is (= 2 (count revisions)))
@@ -109,8 +109,8 @@
:creator_id (mt/user->id :rasta)}]
(create-document-revision! doc-id true :rasta)
(testing "Document can be updated and reverted"
- (t2/update! :model/Document doc-id {:name "Updated Document"
- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]}})
+ (t2/update! :model/Document :id doc-id {:name "Updated Document"
+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]}})
(create-document-revision! doc-id false :rasta)
(let [revisions (revision/revisions :model/Document doc-id)
[_ {original-revision-id :id}] revisions]
@@ -143,7 +143,7 @@
:document {:type "doc" :content []}
:creator_id (mt/user->id :crowberto)}]
(create-document-revision! (:id document) true :crowberto)
- (t2/update! :model/Document (:id document) {:name "Updated Private Document"})
+ (t2/update! :model/Document :id (:id document) {:name "Updated Private Document"})
(create-document-revision! (:id document) false :crowberto)
(let [document-id (u/the-id document)
[_ {prev-rev-id :id}] (revision/revisions :model/Document document-id)]
@@ -176,7 +176,7 @@
(is (every? #(contains? % :is_creation) revisions-response))
(is (every? #(contains? % :description) revisions-response))))
(testing "Document reversion integrates with OSS revert endpoint"
- (t2/update! :model/Document doc-id {:name "Modified Document"})
+ (t2/update! :model/Document :id doc-id {:name "Modified Document"})
(create-document-revision! doc-id false :rasta)
(let [[_ {original-rev-id :id}] (revision/revisions :model/Document doc-id)
revert-response (mt/user-http-request :rasta :post "revision/revert"
@@ -222,7 +222,7 @@
:creator_id (mt/user->id :rasta)}]
(create-document-revision! doc-id true :rasta)
(testing "Name change produces correct diff and description"
- (t2/update! :model/Document doc-id {:name "Updated Title"})
+ (t2/update! :model/Document :id doc-id {:name "Updated Title"})
(create-document-revision! doc-id false :rasta)
(let [revisions (get-document-revisions doc-id)
update-revision (first revisions)]
@@ -230,7 +230,7 @@
(is (= "Updated Title" (get-in update-revision [:diff :after :name])))
(is (str/includes? (:description update-revision) "renamed"))))
(testing "Content change produces diff"
- (t2/update! :model/Document doc-id {:document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "New content"}]}]}})
+ (t2/update! :model/Document :id doc-id {:document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "New content"}]}]}})
(create-document-revision! doc-id false :rasta)
(let [revisions (get-document-revisions doc-id)
content-revision (first revisions)]
diff --git a/test/metabase/revisions/impl/document_test.clj b/test/metabase/revisions/impl/document_test.clj
index e0663af8b79..427c649eae9 100644
--- a/test/metabase/revisions/impl/document_test.clj
+++ b/test/metabase/revisions/impl/document_test.clj
@@ -70,8 +70,8 @@
:document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Original content"}]}]}
:creator_id (mt/user->id :crowberto)}]
(let [original-serialized (revision/serialize-instance :model/Document doc-id document)
- _ (t2/update! :model/Document doc-id {:name "Updated Document"
- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]}})
+ _ (t2/update! :model/Document :id doc-id {:name "Updated Document"
+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]}})
updated-document (t2/select-one :model/Document :id doc-id)]
(testing "document was updated"
(is (= "Updated Document" (:name updated-document)))
diff --git a/test/metabase/revisions/impl/exploration_test.clj b/test/metabase/revisions/impl/exploration_test.clj
index 6546527c221..bcb7bb3cbed 100644
--- a/test/metabase/revisions/impl/exploration_test.clj
+++ b/test/metabase/revisions/impl/exploration_test.clj
@@ -42,7 +42,7 @@
(events/publish-event! :event/exploration-create
{:object (t2/select-one :model/Exploration :id expl-id)
:user-id (mt/user->id :crowberto)})
- (t2/update! :model/Exploration expl-id {:name "renamed"})
+ (t2/update! :model/Exploration :id expl-id {:name "renamed"})
(events/publish-event! :event/exploration-update
{:object (t2/select-one :model/Exploration :id expl-id)
:user-id (mt/user->id :rasta)})
@@ -75,7 +75,7 @@
(let [first-rev-id (t2/select-one-pk :model/Revision
:model "Exploration" :model_id expl-id
{:order-by [[:id :asc]]})]
- (t2/update! :model/Exploration expl-id {:name "renamed" :description "later"})
+ (t2/update! :model/Exploration :id expl-id {:name "renamed" :description "later"})
(events/publish-event! :event/exploration-update
{:object (t2/select-one :model/Exploration :id expl-id)
:user-id (mt/user->id :crowberto)})
diff --git a/test/metabase/revisions/models/revision_test.clj b/test/metabase/revisions/models/revision_test.clj
index 972fd5f1e43..bca98812c5d 100644
--- a/test/metabase/revisions/models/revision_test.clj
+++ b/test/metabase/revisions/models/revision_test.clj
@@ -192,9 +192,9 @@
:model_id card-id
:object {}
:most_recent false}))]
- (t2/update! (t2/table-name :model/Revision) (:id revision) {:most_recent true})
+ (t2/update! (t2/table-name :model/Revision) :id (:id revision) {:most_recent true})
(is (= (:timestamp revision)
- (t2/select-one-fn :timestamp :model/Revision (:id revision)))))))
+ (t2/select-one-fn :timestamp :model/Revision :id (:id revision)))))))
(deftest sorting-test
(testing "Test that revisions are sorted in reverse chronological order"
@@ -264,7 +264,7 @@
{:entity :model/Dashboard
:id dash-id
:user-id (mt/user->id :rasta)
- :object (t2/select-one :model/Dashboard dash-id)}))]
+ :object (t2/select-one :model/Dashboard :id dash-id)}))]
(testing "first revision should be recorded"
(push-revision)
(is (= 1 (count (revision/revisions :model/Dashboard dash-id)))))
@@ -289,7 +289,7 @@
{:entity :model/Card
:id card-id
:user-id (mt/user->id :rasta)
- :object (t2/select-one :model/Card card-id)}))]
+ :object (t2/select-one :model/Card :id card-id)}))]
(testing "first revision should be recorded"
(push-revision)
(is (= 1 (count (revision/revisions :model/Card card-id)))))
@@ -304,7 +304,7 @@
;; Excluding it from `serialize-instance` would also equalize the comparison, but then
;; `revert-to-revision! :model/Card` would fall back to `starting-card-schema-version` and
;; silently downgrade the card on every revert.
- (let [card (t2/select-one :model/Card card-id)]
+ (let [card (t2/select-one :model/Card :id card-id)]
(is (= (:card_schema card)
(:card_schema (revision/serialize-instance :model/Card card-id card))))
(is (> (:card_schema card) queries/starting-card-schema-version)
diff --git a/test/metabase/search/api_test.clj b/test/metabase/search/api_test.clj
index e865d039825..51152963247 100644
--- a/test/metabase/search/api_test.clj
+++ b/test/metabase/search/api_test.clj
@@ -1222,7 +1222,7 @@
(is (= nil (search-for-pulses pulse))))
(testing "Even as a dashboard subscription, the pulse is not found."
(mt/with-temp [:model/Dashboard dashboard {}]
- (t2/update! :model/Pulse (:id pulse) {:dashboard_id (:id dashboard)})
+ (t2/update! :model/Pulse :id (:id pulse) {:dashboard_id (:id dashboard)})
(is (= nil (search-for-pulses pulse))))))))))
(deftest filter-by-creator-test
@@ -2253,7 +2253,7 @@
:model/PermissionsGroupMembership _ {:group_id group-id :user_id (mt/user->id :rasta)}]
(mt/with-no-data-perms-for-all-users!
(perms/set-database-permission! group-id db-id :perms/view-data :unrestricted)
- (perms/set-table-permission! group-id (t2/select-one :model/Table table-id) :perms/create-queries :query-builder)
+ (perms/set-table-permission! group-id (t2/select-one :model/Table :id table-id) :perms/create-queries :query-builder)
(is (=? [{:name "test measure" :model "measure"}]
(binding [*search-request-results-database-id* db-id]
(search-request-data :rasta :q "test measure"))))))))
@@ -2267,13 +2267,13 @@
(is (=? [{:name measure-name :model "measure"}]
(search-request-data :crowberto :q measure-name))))
(testing "after archiving, measure disappears from default results"
- (t2/update! :model/Measure measure-id {:archived true})
+ (t2/update! :model/Measure :id measure-id {:archived true})
(is (= [] (search-request-data :crowberto :q measure-name))))
(testing "archived measure appears in archived=true results"
(is (=? [{:name measure-name :model "measure" :archived true}]
(search-request-data :crowberto :q measure-name :archived "true"))))
(testing "after unarchiving, measure returns to default results"
- (t2/update! :model/Measure measure-id {:archived false})
+ (t2/update! :model/Measure :id measure-id {:archived false})
(is (=? [{:name measure-name :model "measure"}]
(search-request-data :crowberto :q measure-name))))))))
diff --git a/test/metabase/search/appdb/index_test.clj b/test/metabase/search/appdb/index_test.clj
index 65798504d2e..676ce94a1f6 100644
--- a/test/metabase/search/appdb/index_test.clj
+++ b/test/metabase/search/appdb/index_test.clj
@@ -108,11 +108,11 @@
legacy-input #(-> (t2/select-one [index-table :legacy_input] :model "table" :model_id (str table-id))
:legacy_input
json/decode+kw)
- db-id (t2/select-one-fn :db_id :model/Table table-id)
+ db-id (t2/select-one-fn :db_id :model/Table :id table-id)
db-name-fn (comp :database_name legacy-input)
alternate-name (str (random-uuid))]
(is (= "Indexed Database" (db-name-fn)))
- (t2/update! :model/Database db-id {:name alternate-name})
+ (t2/update! :model/Database :id db-id {:name alternate-name})
(is (= alternate-name (db-name-fn)))))))
(deftest partial-word-test
@@ -486,10 +486,10 @@
:collection_id coll-id})]
(fetch "indexed-entity" :name (:name miv)))))
(testing "Changing values syncs the index"
- (t2/update! :model/Card (:id model) (update model :dataset_query (fn [query]
- (let [products-id (lib.metadata/field query (mt/id :products :id))]
- (-> query
- (lib/filter (lib/!= products-id (:model_pk miv))))))))
+ (t2/update! :model/Card :id (:id model) (update model :dataset_query (fn [query]
+ (let [products-id (lib.metadata/field query (mt/id :products :id))]
+ (-> query
+ (lib/filter (lib/!= products-id (:model_pk miv))))))))
(model-index/add-values! model-index)
(let [miv2 (t2/select-one :model/ModelIndexValue :model_index_id (:id model-index))]
(is (=? [(index-entity
diff --git a/test/metabase/search/appdb/metrics_test.clj b/test/metabase/search/appdb/metrics_test.clj
index 6dab89d588a..be724a38aba 100644
--- a/test/metabase/search/appdb/metrics_test.clj
+++ b/test/metabase/search/appdb/metrics_test.clj
@@ -20,7 +20,7 @@
(search.tu/with-temp-index-table
(binding [search.ingestion/*force-sync* true]
(mt/dataset test-data
- (mt/with-temp [:model/User {} (when-not (t2/exists? :model/User 1) {:id 1})
+ (mt/with-temp [:model/User {} (when-not (t2/exists? :model/User :id 1) {:id 1})
:model/Collection {col-id :id} {:name "Collection"}
:model/Card {} {:name "Customer Satisfaction" :collection_id col-id}
:model/Card {} {:name "Projected Revenue" :collection_id col-id}]
@@ -37,7 +37,7 @@
(search.tu/with-temp-index-table
(binding [search.ingestion/*force-sync* true]
(mt/dataset test-data
- (mt/with-temp [:model/User {} (when-not (t2/exists? :model/User 1) {:id 1})
+ (mt/with-temp [:model/User {} (when-not (t2/exists? :model/User :id 1) {:id 1})
:model/Collection {col-id :id} {:name "Collection"}
:model/Card {} {:name "Quarterly Forecast" :collection_id col-id}]
;; a full (not in-place) reindex populates a pending table, then activates it
diff --git a/test/metabase/search/appdb/scoring_test.clj b/test/metabase/search/appdb/scoring_test.clj
index cc0bf8a7a37..2ac9adf7da5 100644
--- a/test/metabase/search/appdb/scoring_test.clj
+++ b/test/metabase/search/appdb/scoring_test.clj
@@ -419,7 +419,7 @@
(do (t2/insert! :model/TableUserSettings
{:table_id table-id :is_published true :collection_id (:id data)})
(curated))
- (do (t2/update! :model/TableUserSettings table-id {:is_published false :collection_id nil})
+ (do (t2/update! :model/TableUserSettings :table_id table-id {:is_published false :collection_id nil})
(curated))]))))))))
(deftest ^:parallel data-layer-test
diff --git a/test/metabase/search/ingestion_test.clj b/test/metabase/search/ingestion_test.clj
index aa58a2d658c..8e793b628e0 100644
--- a/test/metabase/search/ingestion_test.clj
+++ b/test/metabase/search/ingestion_test.clj
@@ -147,7 +147,7 @@
:type :metric
:dataset_query (metric-query a-id)}]
;; close the cycle A -> B -> A; nothing rejects reference cycles at write time
- (t2/update! :model/Card a-id {:dataset_query (metric-query b-id)})
+ (t2/update! :model/Card :id a-id {:dataset_query (metric-query b-id)})
(let [result (#'search.ingestion/execute-all-function-attrs
(search.spec/spec "card")
{:dataset_query (json/encode (metric-query a-id))
diff --git a/test/metabase/search/task/search_index_test.clj b/test/metabase/search/task/search_index_test.clj
index 3d19f74a059..2cec2b6b676 100644
--- a/test/metabase/search/task/search_index_test.clj
+++ b/test/metabase/search/task/search_index_test.clj
@@ -34,7 +34,7 @@
(let [initial-size (index-size)
table-name (search.index/active-table)]
(is (pos? initial-size))
- (t2/delete! table-name (t2/select-one-pk table-name))
+ (t2/delete! table-name :id (t2/select-one-pk table-name))
(is (= (dec initial-size) (index-size)))
(testing "It can cycle the index gracefully"
(is (search/reindex! {:async? false}))
diff --git a/test/metabase/segments/models/segment_test.clj b/test/metabase/segments/models/segment_test.clj
index b32a13343e5..34311d92072 100644
--- a/test/metabase/segments/models/segment_test.clj
+++ b/test/metabase/segments/models/segment_test.clj
@@ -69,21 +69,21 @@
(is (thrown-with-msg?
Exception
#"You cannot update the creator_id of a Segment"
- (t2/update! :model/Segment id {:creator_id (mt/user->id :crowberto)}))))
+ (t2/update! :model/Segment :id id {:creator_id (mt/user->id :crowberto)}))))
(testing "you shouldn't be able to set it to `nil` either"
(is (thrown-with-msg?
Exception
#"You cannot update the creator_id of a Segment"
- (t2/update! :model/Segment id {:creator_id nil}))))
+ (t2/update! :model/Segment :id id {:creator_id nil}))))
(testing "calling `update!` with a value that is the same as the current value shouldn't throw an Exception"
(is (= 0
- (t2/update! :model/Segment id {:creator_id (mt/user->id :rasta)})))))))
+ (t2/update! :model/Segment :id id {:creator_id (mt/user->id :rasta)})))))))
(deftest definition-description-missing-definition-test
(testing "Do not hydrate definition description if definition is nil"
(mt/with-temp [:model/Segment {id :id} {:name "Segment"
:table_id (mt/id :users)}]
- (is (nil? (-> (t2/select-one :model/Segment id)
+ (is (nil? (-> (t2/select-one :model/Segment :id id)
(t2/hydrate :definition_description)
:definition_description))))))
@@ -124,7 +124,7 @@
:set {:definition (json/encode {:filter
[:= [:wheat-field Integer/MAX_VALUE nil] 4]})}
:where [:= :id id]})
- (is (nil? (-> (t2/select-one :model/Segment id)
+ (is (nil? (-> (t2/select-one :model/Segment :id id)
(t2/hydrate :definition_description)
:definition_description))))))
@@ -153,7 +153,7 @@
(is (thrown-with-msg?
Exception
#"does not exist"
- (t2/update! :model/Segment segment-id {:definition {:filter [:segment 99999]}})))))
+ (t2/update! :model/Segment :id segment-id {:definition {:filter [:segment 99999]}})))))
(testing "Updating a segment to reference itself should fail"
(mt/with-temp [:model/Segment {segment-id :id} {:name "Segment"
:table_id (mt/id :venues)
@@ -161,7 +161,7 @@
(is (thrown-with-msg?
Exception
#"[Cc]ycle"
- (t2/update! :model/Segment segment-id {:definition {:filter [:segment segment-id]}})))))
+ (t2/update! :model/Segment :id segment-id {:definition {:filter [:segment segment-id]}})))))
(testing "Updating a segment to create an indirect cycle should fail"
(mt/with-temp [:model/Segment {segment-1-id :id} {:name "Segment 1"
:table_id (mt/id :venues)
@@ -172,7 +172,7 @@
(is (thrown-with-msg?
Exception
#"[Cc]ycle"
- (t2/update! :model/Segment segment-1-id {:definition {:filter [:segment segment-2-id]}}))))))
+ (t2/update! :model/Segment :id segment-1-id {:definition {:filter [:segment segment-2-id]}}))))))
;;; ------------------------------------------------ Permission Tests ------------------------------------------------
diff --git a/test/metabase/server/middleware/session_oauth_test.clj b/test/metabase/server/middleware/session_oauth_test.clj
index 3d674871cda..6d313516541 100644
--- a/test/metabase/server/middleware/session_oauth_test.clj
+++ b/test/metabase/server/middleware/session_oauth_test.clj
@@ -264,10 +264,10 @@
(save-access-token! token user-id client-id [oauth-server/full-access-scope] (in-one-hour))
(testing "authenticates before deactivation"
(is (= user-id (:metabase-user-id (merge-current-user-info (bearer-request token))))))
- (t2/update! :model/User user-id {:is_active false})
+ (t2/update! :model/User :id user-id {:is_active false})
(testing "after deactivation the token no longer authenticates"
(is (nil? (:metabase-user-id (merge-current-user-info (bearer-request token))))))
- (t2/update! :model/User user-id {:is_active true})
+ (t2/update! :model/User :id user-id {:is_active true})
(testing "after reactivation the same token STILL does not authenticate"
(is (nil? (:metabase-user-id (merge-current-user-info (bearer-request token))))))))))))
diff --git a/test/metabase/server/middleware/session_test.clj b/test/metabase/server/middleware/session_test.clj
index 2669e8d2d0c..f11033a9496 100644
--- a/test/metabase/server/middleware/session_test.clj
+++ b/test/metabase/server/middleware/session_test.clj
@@ -50,10 +50,10 @@
:created_at :%now})
(testing "session authenticates while the user is active"
(is (some? (#'mw.session/current-user-info-for-session session-key nil))))
- (t2/update! :model/User user-id {:is_active false})
+ (t2/update! :model/User :id user-id {:is_active false})
(testing "after deactivation the session no longer authenticates"
(is (nil? (#'mw.session/current-user-info-for-session session-key nil))))
- (t2/update! :model/User user-id {:is_active true})
+ (t2/update! :model/User :id user-id {:is_active true})
(testing "after reactivation the same session STILL does not authenticate"
(is (nil? (#'mw.session/current-user-info-for-session session-key nil))))))))
@@ -362,10 +362,10 @@
(testing "authenticates while its synthetic user is active"
(is (authed?)))
(testing "deactivating the creator does NOT revoke the key — creator_id is attribution only"
- (t2/update! :model/User creator-id {:is_active false})
+ (t2/update! :model/User :id creator-id {:is_active false})
(is (authed?)))
(testing "deactivating the key's own synthetic user DOES revoke it"
- (t2/update! :model/User synthetic-id {:is_active false})
+ (t2/update! :model/User :id synthetic-id {:is_active false})
(is (not (authed?))))))))
(deftest ^:parallel current-user-info-for-api-key-test-2
diff --git a/test/metabase/session/api_test.clj b/test/metabase/session/api_test.clj
index b73e39a62b1..b31de8833bd 100644
--- a/test/metabase/session/api_test.clj
+++ b/test/metabase/session/api_test.clj
@@ -522,7 +522,7 @@
(let [password {:old "password"
:new "whateverUP12!!"}]
(mt/with-temp [:model/User {:keys [id]} {}]
- (t2/update! :model/User id {:last_login :%now})
+ (t2/update! :model/User :id id {:last_login :%now})
(let [token (auth-identity/create-password-reset! id)
reset-token (auth-identity/reset-token-hash id)]
(mt/client :post 200 "session/reset_password" {:token token
@@ -553,7 +553,7 @@
(let [uid (mt/user->id :rasta)
token (auth-identity/create-password-reset! uid)
ai (t2/select-one :model/AuthIdentity :user_id uid :provider "emailed-secret-password-reset")]
- (t2/update! :model/AuthIdentity (:id ai)
+ (t2/update! :model/AuthIdentity :id (:id ai)
{:credentials (assoc (:credentials ai) :expires_at (java.time.Instant/ofEpochMilli 0))})
(is (=? {:errors {:password "Invalid reset token"}}
(mt/client :post 400 "session/reset_password" {:token token
@@ -604,7 +604,7 @@
"the new session is attributed to an auth identity")
(is (= password-identity-id (:auth_identity_id (first sessions)))
"the new session is attributed to the password identity the reset just wrote")
- (is (some? (t2/select-one-fn :last_used_at :model/AuthIdentity password-identity-id))
+ (is (some? (t2/select-one-fn :last_used_at :model/AuthIdentity :id password-identity-id))
"completing the reset counts as a use of the password identity")
(is (nil? (t2/select-one :model/AuthIdentity :user_id (:id user) :provider "emailed-secret-password-reset"))
"the consumed reset identity is still deleted"))))))
@@ -647,7 +647,7 @@
(let [uid (mt/user->id :rasta)
token (auth-identity/create-password-reset! uid)
ai (t2/select-one :model/AuthIdentity :user_id uid :provider "emailed-secret-password-reset")]
- (t2/update! :model/AuthIdentity (:id ai)
+ (t2/update! :model/AuthIdentity :id (:id ai)
{:credentials (assoc (:credentials ai) :expires_at (java.time.Instant/ofEpochMilli 0))})
(is (= {:valid false}
(mt/client :get 200 "session/password_reset_token_valid", :token token)))))))
@@ -863,7 +863,7 @@
(mt/client :post 200 "session/google_auth" {:token "foo"})))
(is (=? {:first_name "test"
:last_name "user"}
- (t2/select-one :model/User user-id))))
+ (t2/select-one :model/User :id user-id))))
(testing "with throttling disabled"
(with-redefs [api.session/throttling-disabled? true]
(is (malli= SessionResponse
@@ -999,7 +999,7 @@
(deftest no-password-no-login-test
(testing "A user with no password should not be able to do password-based login"
(mt/with-temp [:model/User user]
- (t2/update! :model/User (u/the-id user) {:password nil, :password_salt nil})
+ (t2/update! :model/User :id (u/the-id user) {:password nil, :password_salt nil})
(let [device-info {:device_id "Cam's Computer"
:device_description "The computer where Cam wrote this test"
:embedded false
diff --git a/test/metabase/session/events/revoke_on_deactivation_test.clj b/test/metabase/session/events/revoke_on_deactivation_test.clj
index 24c4ab2dc9f..dd8c24fb747 100644
--- a/test/metabase/session/events/revoke_on_deactivation_test.clj
+++ b/test/metabase/session/events/revoke_on_deactivation_test.clj
@@ -42,9 +42,9 @@
(let [session-id (insert-session! user-id)]
(is (nil? (:ended_at (t2/select-one :model/Session :id session-id)))
"session is live while the user is active")
- (t2/update! :model/User user-id {:is_active false})
+ (t2/update! :model/User :id user-id {:is_active false})
(is (= {:end_reason "user-deactivated", :ended_by_user_id nil, :key_hashed nil} (ending session-id))
"deactivation outside a request ends the session with no actor")
- (t2/update! :model/User user-id {:is_active true})
+ (t2/update! :model/User :id user-id {:is_active true})
(is (= {:end_reason "user-deactivated", :ended_by_user_id nil, :key_hashed nil} (ending session-id))
"reactivation does not revive the pre-deactivation session")))))
diff --git a/test/metabase/session/models/session_test.clj b/test/metabase/session/models/session_test.clj
index 92165df89d0..8b4c1ebb2f1 100644
--- a/test/metabase/session/models/session_test.clj
+++ b/test/metabase/session/models/session_test.clj
@@ -207,12 +207,12 @@
{:last_active_at (t/instant)}
{:ended_at (t/instant), :expires_at (t/instant)}]]
(is (thrown-with-msg? RuntimeException #"You cannot update a Session"
- (t2/update! :model/Session session-id changes)))))
+ (t2/update! :model/Session :id session-id changes)))))
(testing "recording an ending is allowed"
- (is (= 1 (t2/update! :model/Session session-id {:ended_at (t/instant)
- :end_reason "admin"
- :ended_by_user_id (mt/user->id :crowberto)
- :key_hashed nil}))))
+ (is (= 1 (t2/update! :model/Session :id session-id {:ended_at (t/instant)
+ :end_reason "admin"
+ :ended_by_user_id (mt/user->id :crowberto)
+ :key_hashed nil}))))
(testing "an ending is final: nothing an ending writes can be changed once it is recorded"
(doseq [changes [{:ended_at nil}
{:ended_at (t/instant)}
@@ -220,4 +220,4 @@
{:ended_by_user_id (mt/user->id :rasta)}
{:key_hashed (session/hash-session-key (session/generate-session-key))}]]
(is (thrown-with-msg? RuntimeException #"You cannot change a Session that has ended"
- (t2/update! :model/Session session-id changes)))))))))
+ (t2/update! :model/Session :id session-id changes)))))))))
diff --git a/test/metabase/session/task/session_cleanup_test.clj b/test/metabase/session/task/session_cleanup_test.clj
index b05fe8ef25d..c4269015fb5 100644
--- a/test/metabase/session/task/session_cleanup_test.clj
+++ b/test/metabase/session/task/session_cleanup_test.clj
@@ -64,7 +64,7 @@
;; also past max age, to show which reason wins
old-session (insert-session! user-id :created_at (t/minus (t/local-date-time) (t/days 400)))]
;; the raw table: the model's before-update would end the sessions itself, which is not what this test is about
- (t2/update! (t2/table-name :model/User) user-id {:is_active false})
+ (t2/update! (t2/table-name :model/User) :id user-id {:is_active false})
(sweep!)
(testing "a deactivated user's session is recorded as user-deactivated"
(is (= {:reason "user-deactivated", :ended? true, :key-cleared? true} (ending session-id))))
diff --git a/test/metabase/setup/core_test.clj b/test/metabase/setup/core_test.clj
index d51567b9c69..9fc53f57060 100644
--- a/test/metabase/setup/core_test.clj
+++ b/test/metabase/setup/core_test.clj
@@ -92,13 +92,13 @@
(mt/with-sample-h2-app-db!
(is (= 1
(appearance/example-dashboard-id)))
- (t2/update! :model/Dashboard 1 {:archived true})
+ (t2/update! :model/Dashboard :id 1 {:archived true})
(is (nil? (appearance/example-dashboard-id))))))
(deftest sample-content-permissions-test
(mt/with-sample-h2-app-db!
(let [dashboard (t2/select-one :model/Dashboard :creator_id config/internal-mb-user-id)
- collection (t2/select-one :model/Collection (:collection_id dashboard))
+ collection (t2/select-one :model/Collection :id (:collection_id dashboard))
card (t2/select-one :model/Card :creator_id config/internal-mb-user-id)]
(testing "Rasta (as a member of 'All Users') should have sufficient privileges to edit the example content"
(mt/with-current-user (mt/user->id :rasta)
diff --git a/test/metabase/slackbot/uploads_test.clj b/test/metabase/slackbot/uploads_test.clj
index 79c808a5cb6..b6de4d051bf 100644
--- a/test/metabase/slackbot/uploads_test.clj
+++ b/test/metabase/slackbot/uploads_test.clj
@@ -467,7 +467,7 @@
(mt/test-driver :h2
(mt/with-empty-db
(mt/with-discard-model-updates! [:model/Database]
- (t2/update! :model/Database (mt/id) {:uploads_enabled true})
+ (t2/update! :model/Database :id (mt/id) {:uploads_enabled true})
(mt/with-current-user (mt/user->id :crowberto)
(mt/with-dynamic-fn-redefs
[slackbot.client/download-file-stream (fn [_client _url]
@@ -476,7 +476,7 @@
:error #"I couldn't upload malformed\.csv: Column count in data .*"}
(#'slackbot.uploads/upload-file!
test-client
- {:db (t2/select-one :model/Database (mt/id))
+ {:db (t2/select-one :model/Database :id (mt/id))
:schema-name (sql.tx/session-schema :h2)
:table-prefix "slackbot_"}
{:name "malformed.csv", :filetype "csv", :url_private "https://example.com/x.csv", :size 100}))))))))))
diff --git a/test/metabase/sync/field_values_test.clj b/test/metabase/sync/field_values_test.clj
index 2b6c8cad9ef..70580c4ed61 100644
--- a/test/metabase/sync/field_values_test.clj
+++ b/test/metabase/sync/field_values_test.clj
@@ -40,7 +40,7 @@
(testing "Test that when we delete FieldValues syncing the Table again will cause them to be re-created"
(testing "Check that we have expected field values to start with"
;; Manually activate Field values since they are not created during sync (#53387)
- (field-values/get-or-create-full-field-values! (t2/select-one :model/Field (mt/id :venues :price)))
+ (field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :venues :price)))
;; Reset them to values that should get updated during sync
(t2/update! :model/FieldValues :field_id (mt/id :venues :price) {:values [10 20 30 40]})
;; sync to make sure the field values are filled
@@ -56,7 +56,7 @@
(sync-database-counts! "update-field-values" (data/db)))))
(testing "Now re-sync the table and make sure they're back"
;; Manually activate Field values since they are not created during sync (#53387)
- (field-values/get-or-create-full-field-values! (t2/select-one :model/Field (mt/id :venues :price)))
+ (field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :venues :price)))
;; Reset them to values that should get updated during sync
(t2/update! :model/FieldValues :field_id (mt/id :venues :price) {:values [10 20 30 40]})
(sync/sync-table! (t2/select-one :model/Table :id (mt/id :venues)))
@@ -71,7 +71,7 @@
(is (= [1 2 3 4]
(venues-price-field-values))))
(testing "Update the FieldValues, remove one of the values that should be there"
- (t2/update! :model/FieldValues (t2/select-one-pk :model/FieldValues :field_id (mt/id :venues :price) :type :full) {:values [1 2 3]})
+ (t2/update! :model/FieldValues :id (t2/select-one-pk :model/FieldValues :field_id (mt/id :venues :price) :type :full) {:values [1 2 3]})
(is (= [1 2 3]
(venues-price-field-values))))
(testing "Now re-sync the table and validate the field values updated"
@@ -85,7 +85,7 @@
(testing "sync refreshes a table's FieldValues until a user hides it through PUT /api/table/:id"
(data/with-temp-copy-of-db
(letfn [(field-values-after-sync! []
- (field-values/get-or-create-full-field-values! (t2/select-one :model/Field (mt/id :venues :price)))
+ (field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :venues :price)))
(t2/update! :model/FieldValues :field_id (mt/id :venues :price) :type :full {:values [10 20 30 40]})
(sync/update-field-values! (:id (data/db)))
(venues-price-field-values))]
@@ -98,7 +98,7 @@
(testing "Test that syncing will skip updating inactive FieldValues"
(mt/with-full-data-perms-for-all-users!
(t2/update! :model/FieldValues
- (t2/select-one-pk :model/FieldValues :field_id (mt/id :venues :price) :type :full)
+ :id (t2/select-one-pk :model/FieldValues :field_id (mt/id :venues :price) :type :full)
{:last_used_at (t/minus (t/offset-date-time) (t/days 20))
:values [1 2 3]})
(is (= (repeat 2 {:errors 0, :created 0, :updated 0, :deleted 0})
@@ -111,7 +111,7 @@
(t/minus (t/offset-date-time) (t/hours 2))))
(testing "Field is syncing after usage"
(t2/update! :model/FieldValues
- (t2/select-one-pk :model/FieldValues :field_id (mt/id :venues :price) :type :full)
+ :id (t2/select-one-pk :model/FieldValues :field_id (mt/id :venues :price) :type :full)
{:values [1 2 3]})
(is (= (repeat 2 {:errors 0, :created 0, :updated 1, :deleted 0})
(sync-database-counts! "update-field-values" (data/db))))
@@ -119,7 +119,7 @@
(mt/user-http-request :rasta :get 200 (format "field/%d/values" (mt/id :venues :price)))))))
(testing "If only advanced fields have been used recently, still sync"
(t2/update! :model/FieldValues
- (t2/select-one-pk :model/FieldValues :field_id (mt/id :venues :price) :type :full)
+ :id (t2/select-one-pk :model/FieldValues :field_id (mt/id :venues :price) :type :full)
{:last_used_at (t/minus (t/offset-date-time) (t/days 20))
:values [1 2 3]})
(t2/insert! :model/FieldValues {:field_id (mt/id :venues :price)
@@ -194,7 +194,7 @@
;; insert 50 rows & sync
(one-off-dbs/insert-rows-and-sync! (one-off-dbs/range-str 50))
;; Manually activate Field values since they are not created during sync (#53387)
- (field-values/get-or-create-full-field-values! (t2/select-one :model/Field (mt/id :blueberries_consumed :str)))
+ (field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :blueberries_consumed :str)))
(testing "has_field_values should be auto-list"
(is (= :auto-list
(t2/select-one-fn :has_field_values :model/Field :id (mt/id :blueberries_consumed :str)))))
@@ -225,7 +225,7 @@
;; insert 50 rows & sync
(one-off-dbs/insert-rows-and-sync! [(str/join (repeat 50 "A"))])
;; Manually activate Field values since they are not created during sync (#53387)
- (field-values/get-or-create-full-field-values! (t2/select-one :model/Field (mt/id :blueberries_consumed :str)))
+ (field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :blueberries_consumed :str)))
(testing "has_field_values should be auto-list"
(is (= :auto-list
(t2/select-one-fn :has_field_values :model/Field :id (mt/id :blueberries_consumed :str)))))
@@ -255,8 +255,8 @@
(one-off-dbs/insert-rows-and-sync! (one-off-dbs/range-str 50))
;; change has_field_values to list
;; Manually activate Field values since they are not created during sync (#53387)
- (field-values/get-or-create-full-field-values! (t2/select-one :model/Field (mt/id :blueberries_consumed :str)))
- (t2/update! :model/Field (mt/id :blueberries_consumed :str) {:has_field_values "list"})
+ (field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :blueberries_consumed :str)))
+ (t2/update! :model/Field :id (mt/id :blueberries_consumed :str) {:has_field_values "list"})
(testing "has_more_values should initially be false"
(is (= false
(t2/select-one-fn :has_more_values :model/FieldValues :field_id (mt/id :blueberries_consumed :str)))))
@@ -287,9 +287,9 @@
;; insert a row with values contain 50 chars
(one-off-dbs/insert-rows-and-sync! [(str/join (repeat 50 "A"))])
;; Manually activate Field values since they are not created during sync (#53387)
- (field-values/get-or-create-full-field-values! (t2/select-one :model/Field (mt/id :blueberries_consumed :str)))
+ (field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :blueberries_consumed :str)))
;; change has_field_values to list
- (t2/update! :model/Field (mt/id :blueberries_consumed :str) {:has_field_values "list"})
+ (t2/update! :model/Field :id (mt/id :blueberries_consumed :str) {:has_field_values "list"})
(testing "has_more_values should initially be false"
(is (= false
(t2/select-one-fn :has_more_values :model/FieldValues :field_id (mt/id :blueberries_consumed :str)))))
@@ -312,7 +312,7 @@
;; insert 50 rows & sync
(one-off-dbs/insert-rows-and-sync! [(str/join (repeat 50 "A"))])
;; Manually activate Field values since they are not created during sync (#53387)
- (field-values/get-or-create-full-field-values! (t2/select-one :model/Field (mt/id :blueberries_consumed :str)))
+ (field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :blueberries_consumed :str)))
;; we throw ConnectException, which is a non-recoverable exception. Mock the SQL-path fetcher
;; (run-distinct-batch) since that's what the H2 sync path will call.
(mt/with-dynamic-fn-redefs [distinct-batch/run-distinct-batch (fn [& _] (throw (java.net.ConnectException.)))]
diff --git a/test/metabase/sync/sync_metadata/comments_test.clj b/test/metabase/sync/sync_metadata/comments_test.clj
index eb53dac7c16..a1ce14290b9 100644
--- a/test/metabase/sync/sync_metadata/comments_test.clj
+++ b/test/metabase/sync/sync_metadata/comments_test.clj
@@ -58,7 +58,7 @@
(mt/dataset update-desc
(mt/with-temp-copy-of-db
(let [field-id (mt/id "update_desc" "updated_desc")]
- (t2/update! :model/Field field-id {:description nil})
+ (t2/update! :model/Field :id field-id {:description nil})
(field-user-settings/upsert-user-settings {:id field-id} {:description "updated description"})
(sync/sync-table! (t2/select-one :model/Table :id (mt/id "update_desc")))
(is (= #{{:name (mt/format-name "id"), :description nil}
diff --git a/test/metabase/sync/sync_metadata/dbms_version_test.clj b/test/metabase/sync/sync_metadata/dbms_version_test.clj
index 1b0de85b413..acdfb6fb122 100644
--- a/test/metabase/sync/sync_metadata/dbms_version_test.clj
+++ b/test/metabase/sync/sync_metadata/dbms_version_test.clj
@@ -23,7 +23,7 @@
(mt/dataset test-data
(let [db (mt/db)
version-on-load (db-dbms-version db)
- _ (t2/update! :model/Database (u/the-id db) {:dbms_version nil})
+ _ (t2/update! :model/Database :id (u/the-id db) {:dbms_version nil})
db (t2/select-one :model/Database :id (u/the-id db))
version-after-update (db-dbms-version db)
_ (sync-dbms-ver/sync-dbms-version! (driver.u/lib-database (:id db)))]
diff --git a/test/metabase/sync/sync_metadata/default_schema_test.clj b/test/metabase/sync/sync_metadata/default_schema_test.clj
index adfe9ceeb23..2756e8b14ce 100644
--- a/test/metabase/sync/sync_metadata/default_schema_test.clj
+++ b/test/metabase/sync/sync_metadata/default_schema_test.clj
@@ -9,7 +9,7 @@
(mt/test-driver :h2
(mt/dataset test-data
(let [database (mt/db)]
- (t2/update! :model/Database (:id database) {:default_schema nil})
+ (t2/update! :model/Database :id (:id database) {:default_schema nil})
(let [{:keys [step-info task-history]}
(sync.util-test/sync-database! "sync-default-schema" (assoc database :default_schema nil))]
(testing "the sync step reports the discovered schema"
@@ -19,4 +19,4 @@
(:task_details task-history))))
(testing "the discovered schema is persisted on the Database"
(is (= "PUBLIC"
- (t2/select-one-fn :default_schema :model/Database (:id database))))))))))
+ (t2/select-one-fn :default_schema :model/Database :id (:id database))))))))))
diff --git a/test/metabase/sync/sync_metadata/fields/sync_instances_test.clj b/test/metabase/sync/sync_metadata/fields/sync_instances_test.clj
index 744040bac8f..1835520b4a9 100644
--- a/test/metabase/sync/sync_metadata/fields/sync_instances_test.clj
+++ b/test/metabase/sync/sync_metadata/fields/sync_instances_test.clj
@@ -83,7 +83,7 @@
toucan-field-id (u/the-id (t2/select-one-pk :model/Field :table_id transactions-table-id, :name "toucan"))
details-field-id (u/the-id (t2/select-one-pk :model/Field :table_id transactions-table-id, :name "details", :parent_id toucan-field-id))
age-field-id (u/the-id (t2/select-one-pk :model/Field :table_id transactions-table-id, :name "age", :parent_id details-field-id))]
- (t2/update! :model/Field age-field-id {:active false})
+ (t2/update! :model/Field :id age-field-id {:active false})
;; now sync again.
(sync-metadata/sync-db-metadata! (:id db))
;; field should be reactivated
@@ -100,7 +100,7 @@
toucan-field-id (u/the-id (t2/select-one-pk :model/Field :table_id transactions-table-id, :name "toucan"))
details-field-id (u/the-id (t2/select-one-pk :model/Field :table_id transactions-table-id, :name "details", :parent_id toucan-field-id))
age-field-id (u/the-id (t2/select-one-pk :model/Field :table_id transactions-table-id, :name "age", :parent_id details-field-id))]
- (t2/update! :model/Field details-field-id {:active false})
+ (t2/update! :model/Field :id details-field-id {:active false})
;; now sync again.
(sync-metadata/sync-db-metadata! (:id db))
;; field should be reactivated
diff --git a/test/metabase/sync/sync_metadata/fields/sync_metadata_test.clj b/test/metabase/sync/sync_metadata/fields/sync_metadata_test.clj
index 1f6707a37c6..e9f5a494919 100644
--- a/test/metabase/sync/sync_metadata/fields/sync_metadata_test.clj
+++ b/test/metabase/sync/sync_metadata/fields/sync_metadata_test.clj
@@ -23,7 +23,7 @@
(seq db-settings) (assoc :settings db-settings))
:model/Table table (assoc table :db_id (u/the-id db))]
(let [update-operations (atom [])]
- (mt/with-dynamic-fn-redefs [t2/update! (fn [model id updates]
+ (mt/with-dynamic-fn-redefs [t2/update! (fn [model _pk-column id updates]
(swap! update-operations conj [(name model) id updates])
(count updates))]
(#'sync-metadata/update-field-metadata-if-needed!
@@ -333,8 +333,8 @@
:base-type :type/Text}]
(try
- (sync/sync-table! (t2/select-one :model/Table (mt/id :table)))
- (let [original-field (t2/select-one :model/Field (mt/id :table :field))]
+ (sync/sync-table! (t2/select-one :model/Table :id (mt/id :table)))
+ (let [original-field (t2/select-one :model/Field :id (mt/id :table :field))]
(testing "sanity check: the original state"
(is (=? {:semantic_type :type/Email
:fingerprint (mt/malli=? :map)
@@ -351,8 +351,8 @@
"ALTER TABLE \"TABLE\" ADD COLUMN \"FIELD\" INTEGER;"
"INSERT INTO \"TABLE\"(field) VALUES(1);"]]
(next.jdbc/execute! conn [sql]))))
- (sync/sync-table! (t2/select-one :model/Table (mt/id :table)))
- (let [new-field (t2/select-one :model/Field (mt/id :table :field))]
+ (sync/sync-table! (t2/select-one :model/Table :id (mt/id :table)))
+ (let [new-field (t2/select-one :model/Field :id (mt/id :table :field))]
(testing "updated field is re-fingerprinted and analyzed"
(is (=? {:semantic_type nil
:fingerprint (mt/malli=? :map)
@@ -361,7 +361,7 @@
new-field))
(is (not= (:fingerprint original-field) (:fingerprint new-field))))))
(finally
- (t2/delete! :model/Database (mt/id))))))))
+ (t2/delete! :model/Database :id (mt/id))))))))
(deftest untyped-field-getting-its-base-type-keeps-user-settings-test
(testing "A Field that never had a real base type, like one serdes synthesized for a stub database, keeps its user settings"
@@ -396,7 +396,7 @@
[["100"] ["200"] ["300"]]]]
(try
(sync/sync-database! (mt/id))
- (let [original-field (t2/select-one :model/Field (mt/id :my_table :text_column))]
+ (let [original-field (t2/select-one :model/Field :id (mt/id :my_table :text_column))]
(testing "sanity check: original column is text"
(is (=? {:base_type :type/Text
:effective_type :type/Text}
@@ -415,7 +415,7 @@
"INSERT INTO \"MY_TABLE\"(text_column) VALUES(100.00),(200.00),(300.00);"]]
(next.jdbc/execute! conn [sql]))))
(sync/sync-database! (mt/id))
- (let [new-field (t2/select-one :model/Field (mt/id :my_table :text_column))]
+ (let [new-field (t2/select-one :model/Field :id (mt/id :my_table :text_column))]
(testing "after sync, base_type and effective_type both reflect the new numeric column
and stale coercion/semantic type are cleared"
(is (=? {:id (:id original-field)
@@ -431,7 +431,7 @@
(fn [conn]
(doseq [sql ["DROP TABLE \"MY_TABLE\";"]]
(next.jdbc/execute! conn [sql]))))
- (t2/delete! :model/Table (:table_id original-field))
+ (t2/delete! :model/Table :id (:table_id original-field))
(t2/delete! :model/Field :table_id (:table_id original-field))
(sql-jdbc.execute/do-with-connection-with-options
:h2
@@ -461,7 +461,7 @@
:semantic_type nil}
new-field)))))
(finally
- (t2/delete! :model/Database (mt/id)))))))
+ (t2/delete! :model/Database :id (mt/id)))))))
(deftest sync-self-heals-effective-type-drift-test
(testing "GHY-3388: when a field is in the broken state (effective_type ≠ base_type with no
@@ -535,7 +535,7 @@
:base-type :type/Text}]
(try
- (sync/sync-table! (t2/select-one :model/Table (mt/id :table)))
+ (sync/sync-table! (t2/select-one :model/Table :id (mt/id :table)))
(let [field-id (mt/id :table :field)]
(mt/user-http-request :crowberto :put 200 (format "field/%d" field-id) {:data_sensitivity "PII"})
(sql-jdbc.execute/do-with-connection-with-options
@@ -547,7 +547,7 @@
"ALTER TABLE \"TABLE\" ADD COLUMN \"FIELD\" INTEGER;"
"INSERT INTO \"TABLE\"(field) VALUES(1);"]]
(next.jdbc/execute! conn [sql]))))
- (sync/sync-table! (t2/select-one :model/Table (mt/id :table)))
+ (sync/sync-table! (t2/select-one :model/Table :id (mt/id :table)))
(is (=? {:base_type :type/Integer
:effective_type :type/Integer
:data_sensitivity nil}
@@ -556,4 +556,4 @@
:data_sensitivity :PII}
(t2/select-one :model/FieldUserSettings :field_id field-id))))
(finally
- (t2/delete! :model/Database (mt/id)))))))
+ (t2/delete! :model/Database :id (mt/id)))))))
diff --git a/test/metabase/sync/sync_metadata/fields_test.clj b/test/metabase/sync/sync_metadata/fields_test.clj
index e6f214f1453..3d477d6d465 100644
--- a/test/metabase/sync/sync_metadata/fields_test.clj
+++ b/test/metabase/sync/sync_metadata/fields_test.clj
@@ -141,8 +141,8 @@
:table_id [:in tables]))
field-to-drop (t2/select-one :model/Field :name "example_name" :table_id [:in tables])
field-to-update (get-field-to-update)]
- (t2/update! :model/Field (u/the-id field-to-update) {:semantic_type :type/FK
- :fk_target_field_id (u/the-id field-to-drop)})
+ (t2/update! :model/Field :id (u/the-id field-to-update) {:semantic_type :type/FK
+ :fk_target_field_id (u/the-id field-to-drop)})
;; get the field before sync
(let [field-before-sync (get-field-to-update)]
;; ok cool! now delete one of those columns...
@@ -228,7 +228,7 @@
:semantic_type :type/PK}
(get-pk-details))))
(testing "Clear out the semantic type"
- (t2/update! :model/Field (mt/id :venues :id) {:semantic_type nil})
+ (t2/update! :model/Field :id (mt/id :venues :id) {:semantic_type nil})
(is (= {:database_is_pk true
:semantic_type nil}
(get-pk-details))))
@@ -238,12 +238,12 @@
:semantic_type :type/PK}
(get-pk-details))))
(testing "sync-table! should *not* change the semantic type of fields that are marked with a different type"
- (t2/update! :model/Field (mt/id :venues :id) {:semantic_type :type/Latitude})
+ (t2/update! :model/Field :id (mt/id :venues :id) {:semantic_type :type/Latitude})
(is (= {:database_is_pk true
:semantic_type :type/Latitude}
(get-pk-details))))
(testing "Make sure that sync-table runs set-table-pks-if-needed!"
- (t2/update! :model/Field (mt/id :venues :id) {:semantic_type nil})
+ (t2/update! :model/Field :id (mt/id :venues :id) {:semantic_type nil})
(sync/sync-table! (t2/select-one :model/Table :id (mt/id :venues)))
(is (= {:database_is_pk true
:semantic_type :type/PK}
@@ -277,7 +277,7 @@
[]]]
(let [db (mt/db)
db-spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
- get-fk #(t2/select-one :model/Field (mt/id :country :continent_id))]
+ get-fk #(t2/select-one :model/Field :id (mt/id :country :continent_id))]
;; 1. add FK relationship in the database targeting continent_1
(jdbc/execute! db-spec "ALTER TABLE country ADD CONSTRAINT country_continent_id_fkey FOREIGN KEY (continent_id) REFERENCES continent_1(id);")
(sync/sync-database! (:id db) {:scan :schema})
@@ -319,7 +319,7 @@
:semantic-type :type/FK
:fk-target-exists? true}
(state))))
- (t2/update! :model/Field (mt/id :checkins :user_id) {:semantic_type nil, :fk_target_field_id nil})
+ (t2/update! :model/Field :id (mt/id :checkins :user_id) {:semantic_type nil, :fk_target_field_id nil})
(testing "after"
(is (= {:step-info {:total-fks 6, :updated-fks 1, :total-failed 0}
:task-details {:total-fks 6, :updated-fks 1, :total-failed 0}
@@ -479,7 +479,7 @@
(mapv :visibility_type)
frequencies)))
;; remove cruft column directive:
- (t2/update! :model/Database (u/the-id db) {:settings {:auto-cruft-columns []}})
+ (t2/update! :model/Database :id (u/the-id db) {:settings {:auto-cruft-columns []}})
(sync-metadata/sync-db-metadata! (:id db))
(is (= {:details-only 12}
(->> (db->fields db)
@@ -496,8 +496,8 @@
:preview_display true}
details-field)
"before auto-cruft: field has default visibility and preview_display")
- (t2/update! :model/Database (u/the-id db) {:settings {:auto-cruft-columns ["details"]}})
- (sync-metadata/sync-db-metadata! (:id (t2/select-one :model/Database (u/the-id db))))
+ (t2/update! :model/Database :id (u/the-id db) {:settings {:auto-cruft-columns ["details"]}})
+ (sync-metadata/sync-db-metadata! (:id (t2/select-one :model/Database :id (u/the-id db))))
(is (=? {:visibility_type :details-only
:preview_display false}
(t2/select-one :model/Field :id (:id details-field)))
@@ -643,7 +643,7 @@
(is (nil? (field)))
(is (= :PII (mirror))))
(testing "a bare update to the Field only changes the classifier's own value"
- (t2/update! :model/Field field-id {:data_sensitivity :SEC_KEY})
+ (t2/update! :model/Field :id field-id {:data_sensitivity :SEC_KEY})
(is (= :SEC_KEY (field)))
(is (= :PII (mirror))))))))
@@ -693,7 +693,7 @@
(is (=? {:active true, :data_sensitivity nil} (field)))
(is (= :PHI (mirror)))))
(finally
- (t2/delete! :model/Database (mt/id)))))))
+ (t2/delete! :model/Database :id (mt/id)))))))
(deftest per-table-field-sync-failure-levels-test
(testing "a failure syncing one table's fields is logged by kind (GHY-4945, GHY-4946)"
diff --git a/test/metabase/sync/sync_metadata/indexes_test.clj b/test/metabase/sync/sync_metadata/indexes_test.clj
index 2a4f3b32554..12f7df0b4f2 100644
--- a/test/metabase/sync/sync_metadata/indexes_test.clj
+++ b/test/metabase/sync/sync_metadata/indexes_test.clj
@@ -20,8 +20,8 @@
[{:field-name "indexed" :indexed? true :base-type :type/Integer}
{:field-name "not-indexed" :indexed? false :base-type :type/Integer}]
[[1 2]]]])
- (is (true? (t2/select-one-fn :database_indexed :model/Field (mt/id :table :indexed))))
- (is (not= true (t2/select-one-fn :database_indexed :model/Field (mt/id :table :not-indexed)))))))
+ (is (true? (t2/select-one-fn :database_indexed :model/Field :id (mt/id :table :indexed))))
+ (is (not= true (t2/select-one-fn :database_indexed :model/Field :id (mt/id :table :not-indexed)))))))
(deftest sync-composite-indexed-columns-test
(mt/test-drivers
@@ -34,8 +34,8 @@
(jdbc/execute! (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
(sql.tx/create-index-sql driver/*driver* "table" ["first" "second"]))
(sync/sync-database! (mt/id))
- (is (true? (t2/select-one-fn :database_indexed :model/Field (mt/id :table :first))))
- (is (not= true (t2/select-one-fn :database_indexed :model/Field (mt/id :table :second))))))))
+ (is (true? (t2/select-one-fn :database_indexed :model/Field :id (mt/id :table :first))))
+ (is (not= true (t2/select-one-fn :database_indexed :model/Field :id (mt/id :table :second))))))))
(driver/register! ::not-support-index-test :abstract? true)
diff --git a/test/metabase/sync/sync_metadata/sync_timezone_test.clj b/test/metabase/sync/sync_metadata/sync_timezone_test.clj
index 78a64c78183..9f092f947f8 100644
--- a/test/metabase/sync/sync_metadata/sync_timezone_test.clj
+++ b/test/metabase/sync/sync_metadata/sync_timezone_test.clj
@@ -50,7 +50,7 @@
(try
(let [db (mt/db)
tz-on-load (db-timezone db)
- _ (t2/update! :model/Database (:id db) {:timezone nil})
+ _ (t2/update! :model/Database :id (:id db) {:timezone nil})
tz-after-update (db-timezone db)
;; It looks like we can get some stale timezone information depending on which thread is used for querying the
;; database in sync. Clearing the connection pool to ensure we get the most updated TZ data
@@ -72,7 +72,7 @@
(is (java.time.ZoneId/of (db-timezone db)))))
(finally
;; Make sure to reset the timezone to UTC in case the test failed
- (t2/update! :model/Database (:id (mt/db)) {:timezone "UTC"})))))))
+ (t2/update! :model/Database :id (:id (mt/db)) {:timezone "UTC"})))))))
(deftest sync-timezone-mysql-test
(mt/test-driver :mysql
@@ -90,6 +90,6 @@
(is (= {:timezone-id "+08:00"}
(sync.util-test/only-step-keys step-info)))
(is (= "+08:00"
- (t2/select-one-fn :timezone :model/Database (:id database)))))
+ (t2/select-one-fn :timezone :model/Database :id (:id database)))))
(finally
(jdbc/execute! spec [(str "SET GLOBAL time_zone = '" global-time-zone "';")])))))))))
diff --git a/test/metabase/sync/sync_metadata/tables_test.clj b/test/metabase/sync/sync_metadata/tables_test.clj
index 25850d456f0..89f41f6d54c 100644
--- a/test/metabase/sync/sync_metadata/tables_test.clj
+++ b/test/metabase/sync/sync_metadata/tables_test.clj
@@ -73,7 +73,7 @@
(let [dbdef (mt/dataset-definition "sync-retired-table"
[["user" [{:field-name "name" :base-type :type/Text}] [["Ngoc"]]]])]
(mt/dataset dbdef
- (t2/update! :model/Table (mt/id :user) {:active false})
+ (t2/update! :model/Table :id (mt/id :user) {:active false})
;; table description is changed
(jdbc/execute! (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
[(sql.tx/standalone-table-comment-sql
@@ -83,7 +83,7 @@
(sync/sync-database! (mt/id) {:scan :schema})
(is (=? {:active true
:description "added comment"}
- (t2/select-one :model/Table (mt/id :user))))))))
+ (t2/select-one :model/Table :id (mt/id :user))))))))
(deftest sync-estimated-row-count-test
(mt/test-driver :postgres
@@ -98,7 +98,7 @@
(next.jdbc/execute! conn ["VACUUM;"])))
(sync/sync-database! (mt/id) {:scan :schema})
(is (= 100
- (t2/select-one-fn :estimated_row_count :model/Table (mt/id :venues))))))))
+ (t2/select-one-fn :estimated_row_count :model/Table :id (mt/id :venues))))))))
(defmacro ^:private run-twice
"Run body twice. In this case, we are checking that creating and updating syncs the tables correctly w.r.t.
@@ -195,15 +195,15 @@
:active true}]
(#'sync-tables/archive-tables! (driver.u/lib-database (:id db)))
(testing "Old deactivated table is archived with suffix"
- (let [archived-table (t2/select-one :model/Table (:id table-1))]
+ (let [archived-table (t2/select-one :model/Table :id (:id table-1))]
(is (some? (:archived_at archived-table)))
(is (str/starts-with? (:name archived-table) "old_table__mbarchiv__"))))
(testing "Recently deactivated table is not archived"
- (let [recent-table (t2/select-one :model/Table (:id table-2))]
+ (let [recent-table (t2/select-one :model/Table :id (:id table-2))]
(is (nil? (:archived_at recent-table)))
(is (= "recent_table" (:name recent-table)))))
(testing "Active table is not affected"
- (let [active-table (t2/select-one :model/Table (:id table-3))]
+ (let [active-table (t2/select-one :model/Table :id (:id table-3))]
(is (nil? (:archived_at active-table)))
(is (= "active_table" (:name active-table)))
(is (true? (:active active-table))))))))
@@ -223,11 +223,11 @@
:deactivated_at (t/minus (t/offset-date-time) (t/days 30))}]
(#'sync-tables/archive-tables! (driver.u/lib-database (:id db)))
(testing "Transform target table is not archived or renamed"
- (let [table (t2/select-one :model/Table (:id provisional))]
+ (let [table (t2/select-one :model/Table :id (:id provisional))]
(is (nil? (:archived_at table)))
(is (= "transform_output" (:name table)))))
(testing "Normal table is archived as usual"
- (let [table (t2/select-one :model/Table (:id normal))]
+ (let [table (t2/select-one :model/Table :id (:id normal))]
(is (some? (:archived_at table)))
(is (str/starts-with? (:name table) "old_table__mbarchiv__")))))))
@@ -242,7 +242,7 @@
(let [original-name (:name table)
original-archived-at (:archived_at table)]
(#'sync-tables/archive-tables! (driver.u/lib-database (:id db)))
- (let [updated-table (t2/select-one :model/Table (:id table))]
+ (let [updated-table (t2/select-one :model/Table :id (:id table))]
(is (= original-name (:name updated-table)))
(is (= original-archived-at (:archived_at updated-table))))))))
@@ -253,16 +253,16 @@
:db_id (u/the-id db)
:active true}]
(testing "Initially active table has no deactivated_at"
- (is (nil? (:deactivated_at (t2/select-one :model/Table (:id table))))))
+ (is (nil? (:deactivated_at (t2/select-one :model/Table :id (:id table))))))
(testing "Setting active to false sets deactivated_at"
- (t2/update! :model/Table (:id table) {:active false})
- (let [updated-table (t2/select-one :model/Table (:id table))]
+ (t2/update! :model/Table :id (:id table) {:active false})
+ (let [updated-table (t2/select-one :model/Table :id (:id table))]
(is (some? (:deactivated_at updated-table)))
(is (false? (:active updated-table)))))
(testing "Reactivating table clears deactivated_at and archived_at"
- (t2/update! :model/Table (:id table) {:archived_at (t/offset-date-time)})
- (t2/update! :model/Table (:id table) {:active true})
- (let [reactivated-table (t2/select-one :model/Table (:id table))]
+ (t2/update! :model/Table :id (:id table) {:archived_at (t/offset-date-time)})
+ (t2/update! :model/Table :id (:id table) {:active true})
+ (let [reactivated-table (t2/select-one :model/Table :id (:id table))]
(is (nil? (:deactivated_at reactivated-table)))
(is (nil? (:archived_at reactivated-table)))
(is (true? (:active reactivated-table))))))))
@@ -276,7 +276,7 @@
:deactivated_at (t/minus (t/offset-date-time) (t/days 20))}]
(#'sync-tables/archive-tables! (driver.u/lib-database (:id db)))
(testing "the original table was archived and renamed"
- (let [archived-table (t2/select-one :model/Table (:id original-table))]
+ (let [archived-table (t2/select-one :model/Table :id (:id original-table))]
(is (some? (:archived_at archived-table)))
(is (str/starts-with? (:name archived-table) "sensitive_table__mbarchiv__"))))
(mt/with-temp [:model/Table new-table {:name "sensitive_table"
@@ -302,16 +302,16 @@
(let [select-cols (into [:model/Table :id :name :schema :data_authority] @#'sync-tables/keys-to-update)]
(#'sync-tables/update-table-metadata-if-needed!
{:name "computed_table" :schema nil :is_writable true}
- (t2/select-one select-cols (:id computed-table))
+ (t2/select-one select-cols :id (:id computed-table))
(driver.u/lib-database (:id db)))
(#'sync-tables/update-table-metadata-if-needed!
{:name "normal_table" :schema nil :is_writable true}
- (t2/select-one select-cols (:id normal-table))
+ (t2/select-one select-cols :id (:id normal-table))
(driver.u/lib-database (:id db))))
(testing "computed table should remain non-writable"
- (is (false? (t2/select-one-fn :is_writable :model/Table (:id computed-table)))))
+ (is (false? (t2/select-one-fn :is_writable :model/Table :id (:id computed-table)))))
(testing "normal table should be updated to writable"
- (is (true? (t2/select-one-fn :is_writable :model/Table (:id normal-table))))))))
+ (is (true? (t2/select-one-fn :is_writable :model/Table :id (:id normal-table))))))))
(deftest no-spurious-update-when-metadata-unchanged-test
(testing (str "update-table-metadata-if-needed! should not issue an UPDATE (which would bump updated_at) "
@@ -335,23 +335,23 @@
:database_require_filter nil
:estimated_row_count 100
:is_writable false}
- initial-updated-at (t2/select-one-fn :updated_at :model/Table (:id tbl))]
+ initial-updated-at (t2/select-one-fn :updated_at :model/Table :id (:id tbl))]
(testing "no-op sync does not bump updated_at"
(#'sync-tables/update-table-metadata-if-needed!
matching-metadata
- (t2/select-one select-cols (:id tbl))
+ (t2/select-one select-cols :id (:id tbl))
(driver.u/lib-database (:id db)))
(is (= initial-updated-at
- (t2/select-one-fn :updated_at :model/Table (:id tbl)))))
+ (t2/select-one-fn :updated_at :model/Table :id (:id tbl)))))
(testing "a real change still bumps updated_at"
(#'sync-tables/update-table-metadata-if-needed!
(assoc matching-metadata :estimated_row_count 999)
- (t2/select-one select-cols (:id tbl))
+ (t2/select-one select-cols :id (:id tbl))
(driver.u/lib-database (:id db)))
(is (not= initial-updated-at
- (t2/select-one-fn :updated_at :model/Table (:id tbl))))
+ (t2/select-one-fn :updated_at :model/Table :id (:id tbl))))
(is (= 999
- (t2/select-one-fn :estimated_row_count :model/Table (:id tbl)))))))))
+ (t2/select-one-fn :estimated_row_count :model/Table :id (:id tbl)))))))))
(deftest create-or-reactivate-tables-deterministic-id-order-test
(testing "new tables are inserted sorted by [schema name] so auto-increment ids are assigned deterministically"
@@ -384,7 +384,7 @@
:active false
:data_authority :computed}]
(sync-tables/create-or-reactivate-table! (driver.u/lib-database (:id sample-db)) {:name "existing_sample_table"})
- (let [updated-table (t2/select-one :model/Table (:id existing-table))]
+ (let [updated-table (t2/select-one :model/Table :id (:id existing-table))]
(is (= :ingested (:data_authority updated-table)))
(is (:active updated-table)))))))))
diff --git a/test/metabase/sync/sync_metadata_test.clj b/test/metabase/sync/sync_metadata_test.clj
index 11cac76a1dd..cf58791e1c2 100644
--- a/test/metabase/sync/sync_metadata_test.clj
+++ b/test/metabase/sync/sync_metadata_test.clj
@@ -47,17 +47,17 @@
(is (thrown? Throwable
(#'sync-metadata/sync-db-metadata!* (driver.u/lib-database (:id db))))))
(is (= "aborted"
- (t2/select-one-fn :initial_sync_status :model/Database (:id db))))
+ (t2/select-one-fn :initial_sync_status :model/Database :id (:id db))))
(testing "and the message of the error is recorded as the cause (GHY-3856)"
(is (= "boom"
- (t2/select-one-fn :initial_sync_error :model/Database (:id db)))))))))
+ (t2/select-one-fn :initial_sync_error :model/Database :id (:id db)))))))))
(deftest field-sync-failure-aborts-initial-sync-test
(testing "When an essential sync step fails non-transiently mid-initial-sync (e.g. MariaDB <10.2 whose"
(testing "information_schema lacks generation_expression, so describe-fields throws, GHY-3943),"
(testing "the initial sync status is marked aborted instead of falsely reporting \"complete\""
(mt/with-temp-copy-of-db
- (t2/update! :model/Database (mt/id) {:initial_sync_status "incomplete"})
+ (t2/update! :model/Database :id (mt/id) {:initial_sync_status "incomplete"})
(mt/with-dynamic-fn-redefs [fetch-metadata/fields-metadata
(fn [& _]
(throw (doto (java.sql.SQLSyntaxErrorException.
@@ -65,16 +65,16 @@
(.setStackTrace (into-array StackTraceElement [])))))]
(#'sync-metadata/sync-db-metadata!* (driver.u/lib-database (mt/id))))
(is (= "aborted"
- (t2/select-one-fn :initial_sync_status :model/Database (mt/id))))
+ (t2/select-one-fn :initial_sync_status :model/Database :id (mt/id))))
(testing "and the step's own error message is recorded as the cause, not a schema-validation error (GHY-3856)"
(is (= "Unknown column 'generation_expression' in 'field list'"
- (t2/select-one-fn :initial_sync_error :model/Database (mt/id))))))))))
+ (t2/select-one-fn :initial_sync_error :model/Database :id (mt/id))))))))))
(deftest completed-sync-clears-initial-sync-error-test
(testing "GHY-3856: a sync that completes after an aborted one clears the recorded cause, so the UI shows no stale error"
(mt/with-temp-copy-of-db
- (t2/update! :model/Database (mt/id) {:initial_sync_status "aborted"
- :initial_sync_error "boom"})
+ (t2/update! :model/Database :id (mt/id) {:initial_sync_status "aborted"
+ :initial_sync_error "boom"})
(#'sync-metadata/sync-db-metadata!* (driver.u/lib-database (mt/id)))
(is (= {:initial_sync_status "complete", :initial_sync_error nil}
(t2/select-one [:model/Database :initial_sync_status :initial_sync_error] :id (mt/id)))))))
diff --git a/test/metabase/sync/sync_test.clj b/test/metabase/sync/sync_test.clj
index 507752f3957..62c20d99c34 100644
--- a/test/metabase/sync/sync_test.clj
+++ b/test/metabase/sync/sync_test.clj
@@ -325,13 +325,13 @@
(testing "New values come in after sync"
(binding [*execute-response* (fn [_query respond] (respond {:cols [{:name "field"}]}
(partition-all 1 ["d" "e" "f"])))]
- (sync/sync-database! (:id (t2/select-one :model/Database (u/the-id db)))))
+ (sync/sync-database! (:id (t2/select-one :model/Database :id (u/the-id db)))))
(is (=? {:f {:name "title" :has_field_values :auto-list}
:fv {:values ["d" "e" "f"] :has_more_values false}}
(query-field-and-values))))
(testing "After setting to search it should stay search and sync removes field-values"
- (t2/update! :model/Field (:id field) {:has_field_values "search"})
- (sync/sync-database! (:id (t2/select-one :model/Database (u/the-id db))))
+ (t2/update! :model/Field :id (:id field) {:has_field_values "search"})
+ (sync/sync-database! (:id (t2/select-one :model/Database :id (u/the-id db))))
(get-or-create-vals ["x" "y" "z"])
(is (=? {:f {:name "title" :has_field_values :search}
:fv nil}
@@ -362,7 +362,7 @@
(is (= ["metadata" "analyze"]
(map :name (sync/sync-database! (:id db))))))
(testing "a later sync of the Database, with its initial sync complete, runs it"
- (let [synced-db (t2/select-one :model/Database (u/the-id db))]
+ (let [synced-db (t2/select-one :model/Database :id (u/the-id db))]
(is (= "complete" (:initial_sync_status synced-db)))
(is (= ["metadata" "analyze" "field-values"]
(map :name (sync/sync-database! (:id synced-db)))))))))))
diff --git a/test/metabase/sync/task/sync_databases_test.clj b/test/metabase/sync/task/sync_databases_test.clj
index a73ea144bc8..0476c6a8367 100644
--- a/test/metabase/sync/task/sync_databases_test.clj
+++ b/test/metabase/sync/task/sync_databases_test.clj
@@ -120,7 +120,7 @@
(testing "Check that changing the schedule column(s) for a DB properly updates the scheduled tasks"
(with-scheduler-setup!
(mt/with-temp [:model/Database database {:details {:let-user-control-scheduling true}}]
- (t2/update! :model/Database (u/the-id database)
+ (t2/update! :model/Database :id (u/the-id database)
{:metadata_sync_schedule "0 15 10 ? * MON-FRI" ; 10:15 AM every weekday
:cache_field_values_schedule "0 11 11 11 11 ?"}) ; Every November 11th at 11:11 AM
(is (= [(assoc-in sync-job [:triggers 0 :cron-schedule] "0 15 10 ? * MON-FRI")
@@ -131,7 +131,7 @@
(testing "Check that changing one schedule doesn't affect the other"
(with-scheduler-setup!
(mt/with-temp [:model/Database database {:details {:let-user-control-scheduling true}}]
- (t2/update! :model/Database (u/the-id database)
+ (t2/update! :model/Database :id (u/the-id database)
{:cache_field_values_schedule "0 15 10 ? * MON-FRI"})
(is (= [sync-job
(assoc-in fv-job [:triggers 0 :cron-schedule] "0 15 10 ? * MON-FRI")]
@@ -140,7 +140,7 @@
(deftest schedule-changes-only-expected-test-2
(with-scheduler-setup!
(mt/with-temp [:model/Database database {:details {:let-user-control-scheduling true}}]
- (t2/update! :model/Database (u/the-id database)
+ (t2/update! :model/Database :id (u/the-id database)
{:metadata_sync_schedule "0 15 10 ? * MON-FRI"})
(is (= [(assoc-in sync-job [:triggers 0 :cron-schedule] "0 15 10 ? * MON-FRI")
fv-job]
@@ -379,8 +379,8 @@
(mt/with-temp [:model/Database db {:metadata_sync_schedule sync-default
:cache_field_values_schedule fv-default
:details {:let-user-control-scheduling true}}]
- (t2/update! :model/Database (u/the-id db) {:details (assoc (:details db)
- :let-user-control-scheduling true)})
+ (t2/update! :model/Database :id (u/the-id db) {:details (assoc (:details db)
+ :let-user-control-scheduling true)})
(let [before (t2/select-one :model/Database :id (u/the-id db))]
(#'task.sync-databases/randomize-db-schedules-if-needed!)
(let [after (t2/select-one :model/Database :id (u/the-id db))]
diff --git a/test/metabase/sync/util_test.clj b/test/metabase/sync/util_test.clj
index f0961e3e8cb..7b1213f01b1 100644
--- a/test/metabase/sync/util_test.clj
+++ b/test/metabase/sync/util_test.clj
@@ -290,33 +290,33 @@
(deftest initial-sync-status-test
(mt/dataset test-data
(testing "If `initial-sync-status` on a DB is `incomplete`, it is marked as `complete` when sync-metadata has finished"
- (let [_ (t2/update! :model/Database (mt/id) {:initial_sync_status "incomplete"})
+ (let [_ (t2/update! :model/Database :id (mt/id) {:initial_sync_status "incomplete"})
db (t2/select-one :model/Database :id (mt/id))]
(sync/sync-database! (:id db))
(is (= "complete" (t2/select-one-fn :initial_sync_status :model/Database :id (:id db))))))
(testing "If `initial-sync-status` on a DB is `complete`, it remains `complete` when sync is run again"
- (let [_ (t2/update! :model/Database (mt/id) {:initial_sync_status "complete"})
+ (let [_ (t2/update! :model/Database :id (mt/id) {:initial_sync_status "complete"})
db (t2/select-one :model/Database :id (mt/id))]
(sync/sync-database! (:id db))
(is (= "complete" (t2/select-one-fn :initial_sync_status :model/Database :id (:id db))))))
(testing "If `initial-sync-status` on a table is `incomplete`, it is marked as `complete` after the sync-fks step
has finished"
(let [table-id (t2/select-one-fn :id :model/Table :db_id (mt/id) :active true)
- _ (t2/update! :model/Table table-id {:initial_sync_status "incomplete"})
+ _ (t2/update! :model/Table :id table-id {:initial_sync_status "incomplete"})
_table (t2/select-one :model/Table :id table-id)]
(sync/sync-database! (mt/id))
(is (= "complete" (t2/select-one-fn :initial_sync_status :model/Table :id table-id)))))
(testing "Database and table syncs are marked as complete even if the initial scan is :schema only"
- (let [_ (t2/update! :model/Database (mt/id) {:initial_sync_status "incomplete"})
+ (let [_ (t2/update! :model/Database :id (mt/id) {:initial_sync_status "incomplete"})
db (t2/select-one :model/Database :id (mt/id))
table-id (t2/select-one-fn :id :model/Table :db_id (mt/id) :active true)
- _ (t2/update! :model/Table table-id {:initial_sync_status "incomplete"})
+ _ (t2/update! :model/Table :id table-id {:initial_sync_status "incomplete"})
_table (t2/select-one :model/Table :id table-id)]
(sync/sync-database! (:id db) {:scan :schema})
(is (= "complete" (t2/select-one-fn :initial_sync_status :model/Database :id (:id db))))
(is (= "complete" (t2/select-one-fn :initial_sync_status :model/Table :id table-id)))))
(testing "If a non-recoverable error occurs during sync, `initial-sync-status` on the database is set to `aborted`"
- (let [_ (t2/update! :model/Database (mt/id) {:initial_sync_status "incomplete"})
+ (let [_ (t2/update! :model/Database :id (mt/id) {:initial_sync_status "incomplete"})
db (t2/select-one :model/Database :id (mt/id))]
(mt/with-dynamic-fn-redefs [sync-metadata/make-sync-steps (fn [_]
[(sync-util/create-sync-step
@@ -328,8 +328,8 @@
(is (= "Connection refused" (t2/select-one-fn :initial_sync_error :model/Database :id (:id db))))))))
(testing "If `initial-sync-status` is `aborted` for a database, it is set to `complete` the next time sync finishes
without error"
- (let [_ (t2/update! :model/Database (mt/id) {:initial_sync_status "complete"
- :initial_sync_error nil})
+ (let [_ (t2/update! :model/Database :id (mt/id) {:initial_sync_status "complete"
+ :initial_sync_error nil})
db (t2/select-one :model/Database :id (mt/id))]
(sync/sync-database! (:id db))
(is (= "complete" (t2/select-one-fn :initial_sync_status :model/Database :id (:id db))))))))
@@ -342,8 +342,8 @@
(let [[active-table inactive-table] (t2/select :model/Table :db_id (mt/id) :active true)
get-active-table #(t2/select-one :model/Table :id (:id active-table))
get-inactive-table #(t2/select-one :model/Table :id (:id inactive-table))]
- (t2/update! :model/Table (:id active-table) {:initial_sync_status "complete" :active true})
- (t2/update! :model/Table (:id inactive-table) {:initial_sync_status "complete" :active false})
+ (t2/update! :model/Table :id (:id active-table) {:initial_sync_status "complete" :active true})
+ (t2/update! :model/Table :id (:id inactive-table) {:initial_sync_status "complete" :active false})
(let [syncing-chan (a/chan)
completed-chan (a/chan)]
(let [sync-fields! (mt/original-fn #'sync-fields/sync-fields!)]
diff --git a/test/metabase/task_history/models/task_run_test.clj b/test/metabase/task_history/models/task_run_test.clj
index ccea363ee1f..02ecc013482 100644
--- a/test/metabase/task_history/models/task_run_test.clj
+++ b/test/metabase/task_history/models/task_run_test.clj
@@ -344,7 +344,7 @@
:pulse_channel_id pc-id}]
(notification.tu/with-javascript-visualization-stub
(pulse.tu/with-captured-channel-send-messages!
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))
(let [run (t2/select-one :model/TaskRun :entity_type :dashboard :entity_id dash-id)]
(is (some? run) "task run was created")
(is (= :subscription (:run_type run)))
@@ -372,7 +372,7 @@
(throw (ex-info "second channel failed" {}))))
channel/send! (constantly nil)]
(is (thrown? clojure.lang.ExceptionInfo
- (pulse.send/send-pulse! (t2/select-one :model/Pulse pulse-id))))))
+ (pulse.send/send-pulse! (t2/select-one :model/Pulse :id pulse-id))))))
(let [run (t2/select-one :model/TaskRun :entity_type :dashboard :entity_id dash-id)]
(is (= {:success 1 :failed 1}
(frequencies (t2/select-fn-vec :status :model/TaskHistory :run_id (:id run) :task "notification-send"))))
diff --git a/test/metabase/test/data/impl.clj b/test/metabase/test/data/impl.clj
index 2800a0877ce..d932e351aae 100644
--- a/test/metabase/test/data/impl.clj
+++ b/test/metabase/test/data/impl.clj
@@ -310,7 +310,7 @@
:let [new-parent-id (get old-id->new-id old-parent-id)]
:when (and new-parent-id
(not= new-parent-id old-parent-id))]
- (t2/update! :model/Field new-id {:parent_id new-parent-id})))
+ (t2/update! :model/Field :id new-id {:parent_id new-parent-id})))
;; now copy the FieldValues as well. Only the full ones: an advanced FieldValues is looked up by a hash that
;; includes the id of the field it was cached for, so a copy of one can never be found again, and only turns
;; up in whatever a test counts.
@@ -358,7 +358,7 @@
:source-table.active
:target-table.active
[:not= :source-field.fk_target_field_id nil]]})]
- (t2/update! :model/Field (the-field-id (the-table-id new-db-id source-table) source-field)
+ (t2/update! :model/Field :id (the-field-id (the-table-id new-db-id source-table) source-field)
{:fk_target_field_id (the-field-id (the-table-id new-db-id target-table) target-field)})))
(defn- copy-db-tables-and-fields! [old-db-id new-db-id]
diff --git a/test/metabase/test/data/impl/get_or_create.clj b/test/metabase/test/data/impl/get_or_create.clj
index 9bb470ee239..66670ec349a 100644
--- a/test/metabase/test/data/impl/get_or_create.clj
+++ b/test/metabase/test/data/impl/get_or_create.clj
@@ -104,7 +104,7 @@
(doseq [property [:visibility-type :semantic-type]]
(when-let [v (get field-definition property)]
(log/debugf "SET %s %s.%s -> %s" property table-name field-name v)
- (t2/update! :model/Field (:id @field) {(keyword (str/replace (name property) #"-" "_")) (u/qualified-name v)})))
+ (t2/update! :model/Field :id (:id @field) {(keyword (str/replace (name property) #"-" "_")) (u/qualified-name v)})))
;; effective-type and coercion-strategy must be set atomically — the GHY-3388 model
;; invariant requires effective_type=base_type when coercion_strategy is nil, so a
;; sequence that sets effective_type alone first would be reverted before
@@ -116,7 +116,7 @@
coerce (assoc :coercion_strategy (u/qualified-name coerce)))]
(when (seq upd)
(log/debugf "SET effective-type/coercion-strategy %s.%s -> %s" table-name field-name upd)
- (t2/update! :model/Field (:id @field) upd))))))))
+ (t2/update! :model/Field :id (:id @field) upd))))))))
(def ^:private create-database-timeout-ms
"Max amount of time to wait for driver text extensions to create a DB and load test data."
@@ -259,7 +259,7 @@
:table_id (:id table)
:%lower.name (u/lower-case-en field-name))]
(when (and source-field target-pk-field)
- (t2/update! :model/Field (:id source-field)
+ (t2/update! :model/Field :id (:id source-field)
{:fk_target_field_id (:id target-pk-field)})))))
;; ---------------------- Main Entry Point ----------------------
@@ -502,7 +502,7 @@
(load-dataset-data-if-needed! driver dbdef)
;; update the `created_at` timestamp for the test data so the next call to `get-or-create-database!` doesn't
;; need to go thru this again.
- (t2/update! :model/Database (u/the-id existing-database) {:created_at (t/offset-date-time)})))
+ (t2/update! :model/Database :id (u/the-id existing-database) {:created_at (t/offset-date-time)})))
(finally
(.. lock writeLock unlock))))))
diff --git a/test/metabase/test/util.clj b/test/metabase/test/util.clj
index e30e89a9060..f18ac746ea0 100644
--- a/test/metabase/test/util.clj
+++ b/test/metabase/test/util.clj
@@ -800,7 +800,7 @@
(format "%s %d not found." (name model) (u/the-id object-or-id)))
column->temp-value (maybe-merge-original-values model original-column->value column->temp-value)]
(try
- (t2/update! model (u/the-id object-or-id) column->temp-value)
+ (t2/update! model :id (u/the-id object-or-id) column->temp-value)
(f)
(finally
(t2/query-one
@@ -1252,7 +1252,7 @@
(finally
(methodical/remove-aux-method-with-unique-key! #'t2.before-update/before-update :before model method-unique-key)
(doseq [[id original-val] @pk->original]
- (t2/update! model id original-val)))))
+ (t2/update! model :id id original-val)))))
(with-discard-model-updates! (rest models)
(thunk))))
@@ -1273,23 +1273,23 @@
(let [count-aux-method-before (set (methodical/aux-methods t2.before-update/before-update :model/Card :before))]
(testing "with single model"
(with-discard-model-updates! [:model/Card]
- (t2/update! :model/Card card-id {:name "New Card name"})
+ (t2/update! :model/Card :id card-id {:name "New Card name"})
(testing "the changes takes affect inside the macro"
- (is (= "New Card name" (t2/select-one-fn :name :model/Card card-id)))))
+ (is (= "New Card name" (t2/select-one-fn :name :model/Card :id card-id)))))
(testing "outside macro, the changes should be reverted"
- (is (= card (t2/select-one :model/Card card-id)))))
+ (is (= card (t2/select-one :model/Card :id card-id)))))
(testing "with multiple models"
(with-discard-model-updates! [:model/Card :model/Dashboard]
(testing "the changes takes affect inside the macro"
- (t2/update! :model/Card card-id {:name "New Card name"})
- (is (= "New Card name" (t2/select-one-fn :name :model/Card card-id)))
- (t2/update! :model/Dashboard dash-id {:name "New Dashboard name"})
- (is (= "New Dashboard name" (t2/select-one-fn :name :model/Dashboard dash-id)))))
+ (t2/update! :model/Card :id card-id {:name "New Card name"})
+ (is (= "New Card name" (t2/select-one-fn :name :model/Card :id card-id)))
+ (t2/update! :model/Dashboard :id dash-id {:name "New Dashboard name"})
+ (is (= "New Dashboard name" (t2/select-one-fn :name :model/Dashboard :id dash-id)))))
(testing "outside macro, the changes should be reverted"
(is (= (dissoc card :updated_at)
- (dissoc (t2/select-one :model/Card card-id) :updated_at)))
+ (dissoc (t2/select-one :model/Card :id card-id) :updated_at)))
(is (= (dissoc dash :updated_at)
- (dissoc (t2/select-one :model/Dashboard dash-id) :updated_at)))))
+ (dissoc (t2/select-one :model/Dashboard :id dash-id) :updated_at)))))
(testing "make sure that we cleaned up the aux methods after"
(is (= count-aux-method-before
(set (methodical/aux-methods t2.before-update/before-update :model/Card :before))))))))
diff --git a/test/metabase/test/util/misc.clj b/test/metabase/test/util/misc.clj
index 735c04163f3..2ffc742abe7 100644
--- a/test/metabase/test/util/misc.clj
+++ b/test/metabase/test/util/misc.clj
@@ -47,7 +47,7 @@
(try
(thunk temp-admin)
(finally
- (t2/delete! :model/User (:id temp-admin))
+ (t2/delete! :model/User :id (:id temp-admin))
(when (seq existing-admin-ids)
(t2/update! (t2/table-name :model/User) {:id [:in existing-admin-ids]} {:is_superuser true}))
(perms/add-users-to-groups! (for [{:keys [user_id group_id is_group_manager]} existing-admin-memberships]
diff --git a/test/metabase/timeline/models/timeline_event_test.clj b/test/metabase/timeline/models/timeline_event_test.clj
index 47ee55464f9..e8d39190d2e 100644
--- a/test/metabase/timeline/models/timeline_event_test.clj
+++ b/test/metabase/timeline/models/timeline_event_test.clj
@@ -35,6 +35,6 @@
:model/TimelineEvent a {:timeline_id (u/the-id tl-a) :icon "balloons"}
:model/TimelineEvent b {:timeline_id (u/the-id tl-b) :icon "cake"}]
(is (= timeline-event/default-icon
- (t2/select-one-fn :icon :model/TimelineEvent (u/the-id a))))
+ (t2/select-one-fn :icon :model/TimelineEvent :id (u/the-id a))))
(is (= "cake"
- (t2/select-one-fn :icon :model/TimelineEvent (u/the-id b)))))))
+ (t2/select-one-fn :icon :model/TimelineEvent :id (u/the-id b)))))))
diff --git a/test/metabase/timeline/models/timeline_test.clj b/test/metabase/timeline/models/timeline_test.clj
index f56ed5c5660..ffb21519886 100644
--- a/test/metabase/timeline/models/timeline_test.clj
+++ b/test/metabase/timeline/models/timeline_test.clj
@@ -41,9 +41,9 @@
(mt/with-temp [:model/Timeline a {:icon "balloons"}
:model/Timeline b {:icon "cake"}]
(is (= timeline-event/default-icon
- (t2/select-one-fn :icon :model/Timeline (u/the-id a))))
+ (t2/select-one-fn :icon :model/Timeline :id (u/the-id a))))
(is (= "cake"
- (t2/select-one-fn :icon :model/Timeline (u/the-id b)))))))
+ (t2/select-one-fn :icon :model/Timeline :id (u/the-id b)))))))
(deftest hydrate-timeline-test
(mt/with-temp [:model/Timeline tl {:name "tl-a"}
diff --git a/test/metabase/transforms/execute_test.clj b/test/metabase/transforms/execute_test.clj
index 6bf29fa1e41..2d3016bfe08 100644
--- a/test/metabase/transforms/execute_test.clj
+++ b/test/metabase/transforms/execute_test.clj
@@ -43,14 +43,14 @@
(mt/test-drivers (mt/normal-drivers-with-feature :transforms/table)
(mt/dataset transforms-dataset/transforms-test
(let [target-type "table"
- schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [{table1-name :name :as target1} {:type target-type
:schema schema
:name "g_products"}
{table2-name :name :as target2} {:type target-type
:schema schema
:name "gizmo_products"}]
- (let [table-name (t2/select-one-fn :name :model/Table (mt/id :transforms_products))
+ (let [table-name (t2/select-one-fn :name :model/Table :id (mt/id :transforms_products))
t1-query (make-query table-name "category" lib/starts-with "G")]
(mt/with-temp [:model/Transform t1 {:name "transform1"
:source {:type :query
@@ -80,7 +80,7 @@
(mt/test-drivers (mt/normal-driver-select {:+features [:transforms/table :left-join]})
(mt/dataset transforms-dataset/transforms-test
(let [target-type "table"
- schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [no-limit-table {:type target-type
:schema schema
:name "widgets_daily_no_limit"}
@@ -213,7 +213,7 @@
(lib/order-by products-id :asc))]
(testing "user without create schema permissions should be able to create tables in existing schema"
(with-transform-cleanup! [target-table {:type "table"
- :schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))
+ :schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))
:name "widget_products"}]
(mt/with-temp [:model/Transform transform {:name "transform"
:source {:type :query
@@ -253,7 +253,7 @@
(mt/test-drivers (mt/normal-driver-select {:+features [:transforms/table]})
(mt/with-premium-features #{:database-routing}
(with-transform-cleanup! [target-table {:type :table
- :schema (t2/select-one-fn :schema :model/Table (mt/id :products))
+ :schema (t2/select-one-fn :schema :model/Table :id (mt/id :products))
:name "products"}]
(let [mp (mt/metadata-provider)
products (lib.metadata/table mp (mt/id :products))
@@ -412,7 +412,7 @@
(mt/test-drivers (mt/normal-driver-select {:+features [:transforms/table]})
(mt/with-premium-features #{:database-routing}
(with-transform-cleanup! [target-table {:type :table
- :schema (t2/select-one-fn :schema :model/Table (mt/id :products))
+ :schema (t2/select-one-fn :schema :model/Table :id (mt/id :products))
:name "products"}]
(let [mp (mt/metadata-provider)
products (lib.metadata/table mp (mt/id :products))
@@ -445,7 +445,7 @@
password (:password details)
readonly-user (u/lower-case-en (mt/random-name))
spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
- schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))
+ schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))
make-widget-query
(fn [mp]
(let [transforms-products (lib.metadata/table mp (mt/id :transforms_products))
@@ -517,10 +517,10 @@
(mt/dataset transforms-dataset/transforms-test
(let [db-id (mt/id)
transform-cache-key [db-id :transform]
- schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))
+ schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))
old-write-details (:write_data_details (mt/db))]
(when-not old-write-details
- (t2/update! :model/Database db-id {:write_data_details (:details (mt/db))}))
+ (t2/update! :model/Database :id db-id {:write_data_details (:details (mt/db))}))
(try
(sql-jdbc.conn/invalidate-pool-for-db! (mt/id))
(testing "transform pool does not exist before transform execution"
@@ -542,7 +542,7 @@
(testing "transform pool is created during transform execution"
(is (contains? @@#'sql-jdbc.conn/pool-cache-key->connection-pool transform-cache-key))))))
(finally
- (t2/update! :model/Database db-id {:write_data_details old-write-details})
+ (t2/update! :model/Database :id db-id {:write_data_details old-write-details})
(sql-jdbc.conn/invalidate-pool-for-db! (mt/id))))))))))
(deftest transform-run-refreshes-target-stats-test
@@ -551,8 +551,8 @@
;; The ANALYZE effect is observable on Postgres (Redshift inherits the same impl); assert it here.
(mt/test-driver :postgres
(mt/dataset transforms-dataset/transforms-test
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))
- source-name (t2/select-one-fn :name :model/Table (mt/id :transforms_products))
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))
+ source-name (t2/select-one-fn :name :model/Table :id (mt/id :transforms_products))
admin-spec (sql-jdbc.conn/db->pooled-connection-spec (lib.metadata/database (mt/metadata-provider)))
;; A table has one pg_statistic row per analyzed column; a never-analyzed CTAS table has none.
analyzed-column-count
diff --git a/test/metabase/transforms/index_test.clj b/test/metabase/transforms/index_test.clj
index e6b2af4c880..96585e5dbc9 100644
--- a/test/metabase/transforms/index_test.clj
+++ b/test/metabase/transforms/index_test.clj
@@ -27,7 +27,7 @@
[]
{:type :query
:query (query-test-util/make-query
- {:source-table (t2/select-one-fn :name :model/Table (mt/id :transforms_products))})})
+ {:source-table (t2/select-one-fn :name :model/Table :id (mt/id :transforms_products))})})
(defn- python-source
"A Python transform source that returns `transforms_products` unchanged (built via `create-table!`)."
@@ -51,7 +51,7 @@
"Run a transform (source from the 0-arg `make-source`) with the driver's `:indexes` persisted as its index requests,
then assert `:physical-indexes` reads `:expected` from the catalog. Runs twice to check they survive a rebuild."
[{:keys [indexes expected physical-indexes]} make-source]
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [{table-name :name :as target}
{:type "table"
:schema schema
@@ -94,7 +94,7 @@
(mt/test-drivers (index-util/index-test-drivers)
(mt/dataset transforms-dataset/transforms-test
(let [{:keys [indexes]} (index-util/driver-cases driver/*driver*)
- schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [{table-name :name :as target}
{:type "table" :schema schema :name "idx_verify_products" :database (mt/id)}]
(mt/with-temp [:model/Transform {tid :id :as transform} {:name "index-verify-transform"
@@ -121,7 +121,7 @@
(is (some? test-case) (index-util/missing-case-message driver/*driver*))
(when test-case
(let [bogus (index-util/bogus-indexes (:indexes test-case))
- schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [target {:type "table"
:schema schema
:name "idx_fail_products"
@@ -149,7 +149,7 @@
(is (some? test-case) (index-util/missing-case-message driver/*driver*))
(when test-case
(let [db (mt/db)
- schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [{table-name :name :as target}
{:type "table"
:schema schema
@@ -264,15 +264,15 @@
:delete-pending [{:id kept-id}]
:delete-row [{:id dropped-id}]})
(testing "succeeded: status set, stale error cleared, execution stamped"
- (is (= :succeeded (t2/select-one-fn :status :model/TableIndex succeeded-id)))
- (is (nil? (t2/select-one-fn :error_message :model/TableIndex succeeded-id)))
- (is (some? (t2/select-one-fn :last_executed_at :model/TableIndex succeeded-id))))
+ (is (= :succeeded (t2/select-one-fn :status :model/TableIndex :id succeeded-id)))
+ (is (nil? (t2/select-one-fn :error_message :model/TableIndex :id succeeded-id)))
+ (is (some? (t2/select-one-fn :last_executed_at :model/TableIndex :id succeeded-id))))
(testing "failed: status set with the not-found message"
- (is (= :failed (t2/select-one-fn :status :model/TableIndex failed-id)))
- (is (re-find #"not.*found" (t2/select-one-fn :error_message :model/TableIndex failed-id))))
+ (is (= :failed (t2/select-one-fn :status :model/TableIndex :id failed-id)))
+ (is (re-find #"not.*found" (t2/select-one-fn :error_message :model/TableIndex :id failed-id))))
(testing "a still-present delete-pending row is kept and stamped"
- (is (= :delete-pending (t2/select-one-fn :status :model/TableIndex kept-id)))
- (is (some? (t2/select-one-fn :last_executed_at :model/TableIndex kept-id))))
+ (is (= :delete-pending (t2/select-one-fn :status :model/TableIndex :id kept-id)))
+ (is (some? (t2/select-one-fn :last_executed_at :model/TableIndex :id kept-id))))
(testing "a vanished delete-pending row is removed, freeing its (transform, name) for re-create"
(is (not (t2/exists? :model/TableIndex :id dropped-id)))
(is (some? (t2/insert-returning-pk! :model/TableIndex
@@ -296,8 +296,8 @@
(is (thrown? Throwable
(#'transforms-base.u/apply-standalone-indexes!
{:lib/type :metadata/database :engine :postgres :id (mt/id)} (assoc (:target transform) :transform-id tid))))
- (is (= :failed (t2/select-one-fn :status :model/TableIndex idx-id)))
- (is (re-find #"ddl boom" (t2/select-one-fn :error_message :model/TableIndex idx-id)))))))
+ (is (= :failed (t2/select-one-fn :status :model/TableIndex :id idx-id)))
+ (is (re-find #"ddl boom" (t2/select-one-fn :error_message :model/TableIndex :id idx-id)))))))
(def ^:private access-denied-message
"A ClickHouse privilege error, as Cloud Storage's shared ClickHouse raises it for a tenant reading `system`."
@@ -322,9 +322,9 @@
:source {:type "query"}
:target {:database (mt/id) :type "table" :schema "public" :name "t"}}))
(testing "the running request is failed, with the driver message trimmed of its version tail"
- (is (= :failed (t2/select-one-fn :status :model/TableIndex running-id)))
+ (is (= :failed (t2/select-one-fn :status :model/TableIndex :id running-id)))
(is (= (str "Couldn't read the table's indexes to verify this one: "
(reconcile/driver-error-message (:engine (mt/db)) (ex-info access-denied-message {})))
- (t2/select-one-fn :error_message :model/TableIndex running-id))))
+ (t2/select-one-fn :error_message :model/TableIndex :id running-id))))
(testing "a request this run never started is left for the next one"
- (is (= :create-pending (t2/select-one-fn :status :model/TableIndex pending-id)))))))
+ (is (= :create-pending (t2/select-one-fn :status :model/TableIndex :id pending-id)))))))
diff --git a/test/metabase/transforms/jobs_test.clj b/test/metabase/transforms/jobs_test.clj
index 337c8a2802f..7a69494834a 100644
--- a/test/metabase/transforms/jobs_test.clj
+++ b/test/metabase/transforms/jobs_test.clj
@@ -276,7 +276,7 @@
(mt/with-fake-inbox
(notification.seed/seed-notification!)
(let [mp (mt/metadata-provider)
- table (t2/select-one :model/Table (mt/id :transforms_products))
+ table (t2/select-one :model/Table :id (mt/id :transforms_products))
;; generate sql for different dbs
sql (-> (lib/query mp (lib.metadata/table mp (mt/id :transforms_products)))
(lib/with-fields [(lib.metadata/field mp (mt/id :transforms_products :name))])
@@ -343,7 +343,7 @@
:model/TransformJobRun]
(notification.seed/seed-notification!)
(let [mp (mt/metadata-provider)
- table (t2/select-one :model/Table (mt/id :transforms_products))
+ table (t2/select-one :model/Table :id (mt/id :transforms_products))
;; generate sql for different dbs
sql (-> (lib/query mp (lib.metadata/table mp (mt/id :transforms_products)))
(lib/with-fields [(lib.metadata/field mp (mt/id :transforms_products :name))])
@@ -440,7 +440,7 @@
:model/TransformJobRun]
(notification.seed/seed-notification!)
(let [mp (mt/metadata-provider)
- table (t2/select-one :model/Table (mt/id :transforms_products))
+ table (t2/select-one :model/Table :id (mt/id :transforms_products))
;; generate sql for different dbs
sql (-> (lib/query mp (lib.metadata/table mp (mt/id :transforms_products)))
(lib/with-fields [(lib.metadata/field mp (mt/id :transforms_products :name))])
@@ -546,7 +546,7 @@
(mt/test-drivers (mt/normal-drivers-with-feature :transforms/table)
(mt/dataset transforms-dataset/transforms-test
(let [mp (mt/metadata-provider)
- table (t2/select-one :model/Table (mt/id :transforms_products))
+ table (t2/select-one :model/Table :id (mt/id :transforms_products))
sql (-> (lib/query mp (lib.metadata/table mp (mt/id :transforms_products)))
(lib/with-fields [(lib.metadata/field mp (mt/id :transforms_products :name))])
(lib/limit 10)
diff --git a/test/metabase/transforms/models/transform_job_test.clj b/test/metabase/transforms/models/transform_job_test.clj
index 996ed9f2523..0eb6e6e0bbf 100644
--- a/test/metabase/transforms/models/transform_job_test.clj
+++ b/test/metabase/transforms/models/transform_job_test.clj
@@ -34,9 +34,9 @@
:schedule "* 0 0 0 0"
:built_in_type type}]
(is (= (str (:name translations))
- (str (:name (t2/select-one :model/TransformJob (:id job))))))
+ (str (:name (t2/select-one :model/TransformJob :id (:id job))))))
(is (= (str (:description translations))
- (str (:description (t2/select-one :model/TransformJob (:id job)))))))))
+ (str (:description (t2/select-one :model/TransformJob :id (:id job)))))))))
(deftest initial-jobs-translated-on-update
(testing "Setting name still translates description"
@@ -49,9 +49,9 @@
(t2/update! :model/TransformJob :id (:id job)
{:name "default2"})
(is (= "default2"
- (str (:name (t2/select-one :model/TransformJob (:id job))))))
+ (str (:name (t2/select-one :model/TransformJob :id (:id job))))))
(is (= (str (:description translations))
- (str (:description (t2/select-one :model/TransformJob (:id job)))))))))
+ (str (:description (t2/select-one :model/TransformJob :id (:id job)))))))))
(testing "Setting description still translates name"
(doseq [[type translations] values]
(mt/with-temp [:model/TransformJob job
@@ -62,9 +62,9 @@
(t2/update! :model/TransformJob :id (:id job)
{:description "default description 2"})
(is (= "default description 2"
- (str (:description (t2/select-one :model/TransformJob (:id job))))))
+ (str (:description (t2/select-one :model/TransformJob :id (:id job))))))
(is (= (str (:name translations))
- (str (:name (t2/select-one :model/TransformJob (:id job)))))))))
+ (str (:name (t2/select-one :model/TransformJob :id (:id job)))))))))
(testing "Setting schedule translates description and name"
(doseq [[type translations] values]
(mt/with-temp [:model/TransformJob job
@@ -75,9 +75,9 @@
(t2/update! :model/TransformJob :id (:id job)
{:schedule "0 0 0 0 0"})
(is (= (str (:description translations))
- (str (:description (t2/select-one :model/TransformJob (:id job))))))
+ (str (:description (t2/select-one :model/TransformJob :id (:id job))))))
(is (= (str (:name translations))
- (str (:name (t2/select-one :model/TransformJob (:id job))))))))))
+ (str (:name (t2/select-one :model/TransformJob :id (:id job))))))))))
(deftest data-analyst-job-access-follows-the-advanced-permissions-feature-test
(testing "a data analyst reads, writes and creates transform jobs only while advanced-permissions is available"
diff --git a/test/metabase/transforms/models/transform_tag_test.clj b/test/metabase/transforms/models/transform_tag_test.clj
index 693603b382c..384f1ecac54 100644
--- a/test/metabase/transforms/models/transform_tag_test.clj
+++ b/test/metabase/transforms/models/transform_tag_test.clj
@@ -17,7 +17,7 @@
["monthly" (i18n/trs "monthly")]]]
(mt/with-temp [:model/TransformTag tag {:name "default" :built_in_type type}]
(is (= name
- (str (:name (t2/select-one :model/TransformTag (:id tag)))))))))
+ (str (:name (t2/select-one :model/TransformTag :id (:id tag)))))))))
(deftest initial-tags-translated-on-update
(doseq [type ["hourly" "daily" "weekly" "monthly"]]
@@ -25,15 +25,15 @@
(t2/update! :model/TransformTag :id (:id tag)
{:name "default2"})
(is (= "default2"
- (:name (t2/select-one :model/TransformTag (:id tag)))))
- (is (nil? (t2/select-one-fn :built_in_type :model/TransformTag (:id tag)))))))
+ (:name (t2/select-one :model/TransformTag :id (:id tag)))))
+ (is (nil? (t2/select-one-fn :built_in_type :model/TransformTag :id (:id tag)))))))
(deftest initial-tags-kept-on-noop-update-test
(testing "An update that only touches the timestamp leaves a tag built in"
(doseq [type ["hourly" "daily" "weekly" "monthly"]]
(mt/with-temp [:model/TransformTag tag {:name "default" :built_in_type type}]
(t2/update! :model/TransformTag :id (:id tag) {:updated_at (mi/now)})
- (is (= type (t2/select-one-fn :built_in_type :model/TransformTag (:id tag))))))))
+ (is (= type (t2/select-one-fn :built_in_type :model/TransformTag :id (:id tag))))))))
(deftest data-analyst-tag-access-follows-the-advanced-permissions-feature-test
(testing "a data analyst reads, writes and creates transform tags only while advanced-permissions is available"
diff --git a/test/metabase/transforms/models/transform_test.clj b/test/metabase/transforms/models/transform_test.clj
index 7f2aff0125b..94fe86d41c1 100644
--- a/test/metabase/transforms/models/transform_test.clj
+++ b/test/metabase/transforms/models/transform_test.clj
@@ -39,11 +39,11 @@
:source {:type "python"
:body "print(\"hello\")"}}]
(is (nil? (:source_database_id transform)))
- (t2/update! :model/Transform (:id transform) {:source {:type "query"
- :query {:database (mt/id)
- :type "native"
- :native {:query "SELECT 1"}}}})
- (is (= (mt/id) (t2/select-one-fn :source_database_id :model/Transform (:id transform)))))))
+ (t2/update! :model/Transform :id (:id transform) {:source {:type "query"
+ :query {:database (mt/id)
+ :type "native"
+ :native {:query "SELECT 1"}}}})
+ (is (= (mt/id) (t2/select-one-fn :source_database_id :model/Transform :id (:id transform)))))))
(deftest source-database-deletion-sets-null-test
(testing "deleting a database referenced by a transform nulls the transform's source_database_id (ON DELETE SET NULL)"
@@ -55,10 +55,10 @@
:type "native"
:native {:query "SELECT 1"}}}}]
(is (= db-id (:source_database_id transform)))
- (t2/delete! :model/Database db-id)
- (is (nil? (t2/select-one-fn :source_database_id :model/Transform (:id transform))))
+ (t2/delete! :model/Database :id db-id)
+ (is (nil? (t2/select-one-fn :source_database_id :model/Transform :id (:id transform))))
;; transform itself still exists
- (is (some? (t2/select-one :model/Transform (:id transform)))))))
+ (is (some? (t2/select-one :model/Transform :id (:id transform)))))))
(defn- temp-transform-with-index! [thunk]
(mt/with-temp [:model/Transform {transform-id :id}
@@ -76,20 +76,20 @@
(testing "editing the source query (output schema may change) marks the transform's managed indexes for revalidation"
(temp-transform-with-index!
(fn [transform-id index-id]
- (t2/update! :model/Transform transform-id
+ (t2/update! :model/Transform :id transform-id
{:source {:type "query" :query (query-test-util/make-query :source-table "checkins")}})
- (is (= :update-pending (t2/select-one-fn :status :model/TableIndex index-id))))))
+ (is (= :update-pending (t2/select-one-fn :status :model/TableIndex :id index-id))))))
(testing "retargeting to a different table marks the transform's managed indexes for revalidation"
(temp-transform-with-index!
(fn [transform-id index-id]
- (t2/update! :model/Transform transform-id
+ (t2/update! :model/Transform :id transform-id
{:target {:database (mt/id) :type "table" :schema "public" :name (mt/random-name)}})
- (is (= :update-pending (t2/select-one-fn :status :model/TableIndex index-id))))))
+ (is (= :update-pending (t2/select-one-fn :status :model/TableIndex :id index-id))))))
(testing "an unrelated edit (renaming the transform) leaves the indexes alone"
(temp-transform-with-index!
(fn [transform-id index-id]
- (t2/update! :model/Transform transform-id {:name "renamed"})
- (is (= :succeeded (t2/select-one-fn :status :model/TableIndex index-id)))))))
+ (t2/update! :model/Transform :id transform-id {:name "renamed"})
+ (is (= :succeeded (t2/select-one-fn :status :model/TableIndex :id index-id)))))))
(deftest can-read-write-on-orphaned-transform-test
(testing "superusers can read/write a transform whose source database has been deleted, data analysts cannot"
@@ -101,8 +101,8 @@
:query {:database db-id
:type "native"
:native {:query "SELECT 1"}}}}]
- (t2/delete! :model/Database db-id)
- (let [reloaded (t2/select-one :model/Transform (:id transform))]
+ (t2/delete! :model/Database :id db-id)
+ (let [reloaded (t2/select-one :model/Transform :id (:id transform))]
(is (nil? (:source_database_id reloaded)))
(mt/with-current-user (mt/user->id :crowberto)
(is (mi/can-read? reloaded))
@@ -129,8 +129,8 @@
:source {:type "query"
:query (lib/query (mt/metadata-provider)
(lib.metadata/table (mt/metadata-provider) (mt/id :orders)))}}]
- (let [native (t2/select-one :model/Transform (:id native-transform))
- mbql (t2/select-one :model/Transform (:id mbql-transform))]
+ (let [native (t2/select-one :model/Transform :id (:id native-transform))
+ mbql (t2/select-one :model/Transform :id (:id mbql-transform))]
(mt/with-data-analyst-role! (mt/user->id :rasta)
(mt/with-restored-data-perms!
;; Remove native access granted to All Users by default so the user's only path to native would be
@@ -162,8 +162,8 @@
:query {:database db-id
:type :native
:native {:query "SELECT 1"}}}}]
- (t2/delete! :model/Database db-id)
- (let [reloaded (t2/select-one :model/Transform (:id transform))
+ (t2/delete! :model/Database :id db-id)
+ (let [reloaded (t2/select-one :model/Transform :id (:id transform))
{:keys [status error]} (transforms-base.query/run-query-transform! reloaded nil)]
(is (= :failed status))
(is (re-find #"Source database for this transform has been deleted"
@@ -182,21 +182,21 @@
(mt/with-temp [:model/Transform {transform-id :id} {:name "Test Transform" :source source}]
(is (some #(= :event/create-transform (first %)) @events-published))
(reset! events-published [])
- (t2/update! :model/Transform transform-id {:name "Updated Name"})
+ (t2/update! :model/Transform :id transform-id {:name "Updated Name"})
(is (some #(= :event/update-transform (first %)) @events-published))
(reset! events-published [])
- (t2/delete! :model/Transform transform-id)
+ (t2/delete! :model/Transform :id transform-id)
(is (some #(= :event/delete-transform (first %)) @events-published))))
(reset! events-published [])
(testing "events are suppressed during deserialization"
(binding [mi/*deserializing?* true]
(mt/with-temp [:model/Transform {transform-id :id} {:name "Deserialized Transform" :source source}]
- (t2/update! :model/Transform transform-id {:name "Deserialized Update"})
- (t2/delete! :model/Transform transform-id)))
+ (t2/update! :model/Transform :id transform-id {:name "Deserialized Update"})
+ (t2/delete! :model/Transform :id transform-id)))
(is (empty? @events-published)))))))
(defn- stored-deps [transform-id]
- (t2/select-one-fn :table_dependencies :model/Transform transform-id))
+ (t2/select-one-fn :table_dependencies :model/Transform :id transform-id))
(deftest table-dependencies-cache-test
(testing "table_dependencies is not computed on insert — it is filled lazily on the first read"
@@ -215,9 +215,9 @@
:type "query"
:query {:source-table (mt/id :orders)}}}}]
;; seed a cached value (as the lazy read path would)
- (t2/update! :model/Transform id {:table_dependencies [{:table (mt/id :orders)}]})
+ (t2/update! :model/Transform :id id {:table_dependencies [{:table (mt/id :orders)}]})
(is (= [{:table (mt/id :orders)}] (stored-deps id)))
- (t2/update! :model/Transform id
+ (t2/update! :model/Transform :id id
{:source {:type "query"
:query {:database (mt/id)
:type "query"
@@ -338,7 +338,7 @@
:is_active true
:run_method "manual"
:last_heartbeat (t/offset-date-time)}]
- (let [last-run (:last_run (t2/hydrate (t2/select-one :model/Transform transform-id) :last_run))]
+ (let [last-run (:last_run (t2/hydrate (t2/select-one :model/Transform :id transform-id) :last_run))]
(is (=? {:id run-id, :transform_id transform-id} last-run))
(is (not (contains? last-run :last_heartbeat)))))))
@@ -367,7 +367,7 @@
:type :card
:card-id card-id}}}}}}]
(mt/with-non-admin-groups-no-collection-perms collection
- (let [stored (t2/select-one :model/Transform (:id transform))
+ (let [stored (t2/select-one :model/Transform :id (:id transform))
body (into {} stored)]
(mt/with-data-analyst-role! (mt/user->id :rasta)
(mt/with-restored-data-perms!
@@ -395,7 +395,7 @@
:source {:type "query"
:query (lib/query (mt/metadata-provider)
(lib.metadata/table (mt/metadata-provider) (mt/id :orders)))}}]
- (let [stored (t2/select-one :model/Transform (:id transform))]
+ (let [stored (t2/select-one :model/Transform :id (:id transform))]
(mt/with-data-analyst-role! (mt/user->id :rasta)
(mt/with-restored-data-perms!
(data-perms/set-database-permission! group-id (mt/id) :perms/view-data :unrestricted)
diff --git a/test/metabase/transforms/models_test.clj b/test/metabase/transforms/models_test.clj
index 317d8d3bf7d..562a8ca5733 100644
--- a/test/metabase/transforms/models_test.clj
+++ b/test/metabase/transforms/models_test.clj
@@ -183,8 +183,8 @@
:schema nil
:name "test_table_null_schema"
:db_id db-id}}]
- (t2/update! :model/Transform (:id transform1) {:target_table_id table-with-schema-id})
- (t2/update! :model/Transform (:id transform2) {:target_table_id table-null-schema-id})
+ (t2/update! :model/Transform :id (:id transform1) {:target_table_id table-with-schema-id})
+ (t2/update! :model/Transform :id (:id transform2) {:target_table_id table-null-schema-id})
(let [transform1 (t2/select-one :model/Transform :id (:id transform1))
transform2 (t2/select-one :model/Transform :id (:id transform2))]
(testing "Hydrates table with non-NULL schema"
@@ -329,10 +329,10 @@
:db_id db-id}
:last_checkpoint_value "42"}]
(testing "checkpoint is present before update"
- (let [t (t2/select-one :model/Transform transform-id)]
+ (let [t (t2/select-one :model/Transform :id transform-id)]
(is (= "42" (:last_checkpoint_value t)))))
(testing "changing checkpoint-filter-field-id resets checkpoint"
- (t2/update! :model/Transform transform-id
+ (t2/update! :model/Transform :id transform-id
{:source {:type "query"
:query {:database db-id
:type "native"
@@ -340,13 +340,13 @@
:template-tags {}}}
:source-incremental-strategy {:type "checkpoint"
:checkpoint-filter-field-id 200}}})
- (let [t (t2/select-one :model/Transform transform-id)]
+ (let [t (t2/select-one :model/Transform :id transform-id)]
(is (nil? (:last_checkpoint_value t)))))
(testing "updating without changing checkpoint-filter-field-id preserves checkpoint"
;; Set checkpoint again
- (t2/update! :model/Transform transform-id
+ (t2/update! :model/Transform :id transform-id
{:last_checkpoint_value "99"})
- (t2/update! :model/Transform transform-id
+ (t2/update! :model/Transform :id transform-id
{:source {:type "query"
:query {:database db-id
:type "native"
@@ -354,7 +354,7 @@
:template-tags {}}}
:source-incremental-strategy {:type "checkpoint"
:checkpoint-filter-field-id 200}}})
- (let [t (t2/select-one :model/Transform transform-id)]
+ (let [t (t2/select-one :model/Transform :id transform-id)]
(is (= "99" (:last_checkpoint_value t)))))))))
(deftest lookback-round-trips-with-keyword-keys-test
@@ -375,7 +375,7 @@
:name "test_lookback"
:db_id db-id}}]
(is (= {:value 4 :unit "day"}
- (get-in (t2/select-one :model/Transform transform-id)
+ (get-in (t2/select-one :model/Transform :id transform-id)
[:source :source-incremental-strategy :lookback])))))))
(deftest start-run-stores-job-run-id-test
diff --git a/test/metabase/transforms/test_util.clj b/test/metabase/transforms/test_util.clj
index ce4cf54069c..fe31a980e5a 100644
--- a/test/metabase/transforms/test_util.clj
+++ b/test/metabase/transforms/test_util.clj
@@ -147,7 +147,7 @@
[table-name]
(let [pk (or (try (mt/id (keyword table-name)) (catch Exception _ nil))
(if-let [schema (when-let [products-id (try (mt/id :transforms_products) (catch Exception _ nil))]
- (t2/select-one-fn :schema :model/Table products-id))]
+ (t2/select-one-fn :schema :model/Table :id products-id))]
(t2/select-one-pk :model/Table :db_id (mt/id) :schema schema :name table-name)
(t2/select-one-pk :model/Table :db_id (mt/id) :name table-name)))]
(->>
@@ -265,7 +265,7 @@
"Get the schema from the products table in the test dataset.
This is needed for databases like BigQuery that require a schema/dataset."
[]
- (t2/select-one-fn :schema :model/Table (mt/id :transforms_products)))
+ (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products)))
(defn default-schema-or-public
"Returns the driver's default schema (e.g., 'dbo' for SQL Server) or 'public' as fallback.
diff --git a/test/metabase/transforms/util_test.clj b/test/metabase/transforms/util_test.clj
index bcd9c985738..7278ef21f77 100644
--- a/test/metabase/transforms/util_test.clj
+++ b/test/metabase/transforms/util_test.clj
@@ -447,7 +447,7 @@
driver/table-exists? (constantly false)]
(transforms-base.u/activate-table-and-mark-computed! (driver.u/lib-database (:id db)) target)
(is (some? @synced-table))
- (let [table (t2/select-one :model/Table (:id @synced-table))]
+ (let [table (t2/select-one :model/Table :id (:id @synced-table))]
(is (= :computed (:data_authority table)))
(is (false? (:is_writable table))
"Computed transform tables should have is_writable=false")))))))
@@ -485,7 +485,7 @@
(with-redefs [transforms-base.i/execute-base! (constantly {:status :succeeded})]
(mt/with-dynamic-fn-redefs
[transforms-base.u/sync-target! (fn [_target _database]
- (t2/select-one :model/Table table-id))
+ (t2/select-one :model/Table :id table-id))
transforms.u/run-cancelable-transform! (fn [_run-id _transform _driver _details run-fn & _opts]
(run-fn (a/promise-chan) nil))]
(transforms.execute/execute! transform {:run-method :manual})
@@ -799,7 +799,7 @@
(= "PUBLIC" (:schema table)))]
(transforms-base.u/activate-table-and-mark-computed! (driver.u/lib-database (:id db)) target)
(is (some? @synced-table))
- (let [table (t2/select-one :model/Table (:id @synced-table))]
+ (let [table (t2/select-one :model/Table :id (:id @synced-table))]
(is (= "PUBLIC" (:schema table))
"Table schema should be updated to the driver's default schema"))))))
(testing "activate-table-and-mark-computed! leaves nil schema when physical table has no default schema"
@@ -823,6 +823,6 @@
driver/table-exists? (constantly false)]
(transforms-base.u/activate-table-and-mark-computed! (driver.u/lib-database (:id db)) target)
(is (some? @synced-table))
- (let [table (t2/select-one :model/Table (:id @synced-table))]
+ (let [table (t2/select-one :model/Table :id (:id @synced-table))]
(is (nil? (:schema table))
"Table schema should remain nil when physical table isn't in default schema")))))))
diff --git a/test/metabase/transforms_base/ordering_test.clj b/test/metabase/transforms_base/ordering_test.clj
index f10570af996..5d7b54b37ee 100644
--- a/test/metabase/transforms_base/ordering_test.clj
+++ b/test/metabase/transforms_base/ordering_test.clj
@@ -88,7 +88,7 @@
LIMIT 100"}}
"orders_transform_products_transform")]
(is (= #{{:transform t1} {:transform t2}}
- (transform-deps-for-db (t2/select-one :model/Transform t4))))
+ (transform-deps-for-db (t2/select-one :model/Transform :id t4))))
(is (= {t1 #{}
t2 #{}
t3 #{t1}
@@ -117,7 +117,7 @@
(transforms.execute/execute! transform1 {:run-method :manual})
(let [table1 (t2/select-one-pk :model/Table :name "checkins_transform")]
(is (= #{{:table table1} {:transform t2}}
- (transform-deps-for-db (t2/select-one :model/Transform t3)))))
+ (transform-deps-for-db (t2/select-one :model/Transform :id t3)))))
(is (= {t1 #{}
t2 #{}
t3 #{t1 t2}}
@@ -150,7 +150,7 @@
LIMIT 100" dataset dataset)}}
"venues_transform_2" dataset)]
(is (= #{{:table table1} {:transform t2}}
- (transform-deps-for-db (t2/select-one :model/Transform t3))))
+ (transform-deps-for-db (t2/select-one :model/Transform :id t3))))
(is (= {t1 #{}
t2 #{}
t3 #{t1 t2}}
@@ -450,11 +450,11 @@
:type "query"
:query {:source-table (mt/id :orders)}})]
;; simulate a row created before the column existed
- (t2/update! (t2/table-name :model/Transform) id {:table_dependencies nil})
+ (t2/update! (t2/table-name :model/Transform) :id id {:table_dependencies nil})
(mt/with-metadata-provider (mt/id)
(let [all (t2/select [:model/Transform :id :target :target_table_id :created_at :table_dependencies])
{:keys [uncached]} (ordering/transform-ordering #{id} all)]
(is (contains? uncached id))
(ordering/persist-table-dependencies! uncached)
(is (= [{:table (mt/id :orders)}]
- (t2/select-one-fn :table_dependencies :model/Transform id)))))))))
+ (t2/select-one-fn :table_dependencies :model/Transform :id id)))))))))
diff --git a/test/metabase/transforms_rest/api/transform_runs_test.clj b/test/metabase/transforms_rest/api/transform_runs_test.clj
index 861313a538f..9f8c0b957ed 100644
--- a/test/metabase/transforms_rest/api/transform_runs_test.clj
+++ b/test/metabase/transforms_rest/api/transform_runs_test.clj
@@ -262,12 +262,12 @@
:model/TransformRun {run-id :id} {:transform_id transform-id
:transform_name "Hidden Transform"}]
;; deleting the source database makes the transform unreadable to data analysts
- (t2/delete! :model/Database db-id)
+ (t2/delete! :model/Database :id db-id)
(testing "a data analyst who cannot read the transform gets a 403"
(mt/user-http-request :lucky :get 403 (str "transform/run/" run-id)))
(testing "a superuser still reads the run"
(is (= run-id (:id (mt/user-http-request :crowberto :get 200 (str "transform/run/" run-id))))))
(testing "an orphaned run (transform deleted, transform_id nulled) is superuser-only"
- (t2/delete! :model/Transform transform-id)
+ (t2/delete! :model/Transform :id transform-id)
(mt/user-http-request :lucky :get 403 (str "transform/run/" run-id))
(is (= run-id (:id (mt/user-http-request :crowberto :get 200 (str "transform/run/" run-id)))))))))))
diff --git a/test/metabase/transforms_rest/api/transform_test.clj b/test/metabase/transforms_rest/api/transform_test.clj
index e6155e452ec..b4fb4068435 100644
--- a/test/metabase/transforms_rest/api/transform_test.clj
+++ b/test/metabase/transforms_rest/api/transform_test.clj
@@ -63,7 +63,7 @@
"Create a query filtering products by category, using shared utility.
Returns a legacy MBQL query structure for API compatibility."
[category]
- (let [table-name (t2/select-one-fn :name :model/Table (mt/id :transforms_products))]
+ (let [table-name (t2/select-one-fn :name :model/Table :id (mt/id :transforms_products))]
(query-test-util/make-query
{:source-table table-name
:source-column "category"
@@ -100,7 +100,7 @@
:name table-name}})
transform-id (:id response)
user-id (mt/user->id user)
- creator-id (t2/select-one-fn :creator_id :model/Transform transform-id)]
+ creator-id (t2/select-one-fn :creator_id :model/Transform :id transform-id)]
(testing "Response includes creator_id"
(is (= user-id (:creator_id response))))
(testing "Database record has creator_id set correctly"
@@ -915,7 +915,7 @@
(mt/dataset transforms-dataset/transforms-test
(with-transform-db-perms!
(with-transforms-api-users! [user]
- (let [schema (t2/select-one-fn :schema :model/Table (mt/id :transforms_products))]
+ (let [schema (t2/select-one-fn :schema :model/Table :id (mt/id :transforms_products))]
(with-transform-cleanup! [{table1-name :name :as target1} {:type "table"
:schema schema
:name "gadget_products"}
@@ -1292,7 +1292,7 @@
(let [response (mt/user-http-request :crowberto action 200 url req)
transform-id (:id response)
;; Read the updated transform from the DB for accurate comparison
- transform (-> (t2/select-one :model/Transform transform-id)
+ transform (-> (t2/select-one :model/Transform :id transform-id)
(t2/hydrate :transform_tag_ids))]
(is (= exp-revisions (t2/count :model/Revision :model "Transform"
:model_id transform-id)))
@@ -2141,7 +2141,7 @@
(let [mp (mt/metadata-provider)
category-col (lib.metadata/field mp (mt/id :transforms_products :category))
[source-schema source-table-name] (t2/select-one-fn (juxt :schema :name) :model/Table
- (mt/id :transforms_products))
+ :id (mt/id :transforms_products))
;; Qualify the FROM clause with its schema so that drivers which require the WHERE clause's
;; field-filter substitution (a fully qualified `schema.table.column` reference) to agree with
;; the table expression named in FROM (e.g. ClickHouse) can resolve the query. An unqualified
@@ -2195,8 +2195,8 @@
(with-transform-db-perms!
(with-transforms-api-users! [user]
(let [schema (get-test-schema)
- existing-table-name (t2/select-one-fn :name :model/Table (mt/id :transforms_products))
- other-existing-name (t2/select-one-fn :name :model/Table (mt/id :transforms_orders))]
+ existing-table-name (t2/select-one-fn :name :model/Table :id (mt/id :transforms_products))
+ other-existing-name (t2/select-one-fn :name :model/Table :id (mt/id :transforms_orders))]
(testing "POST /api/transform"
(mt/user-http-request user :post 409 "transform"
{:name "Colliding Transform"
@@ -2245,7 +2245,7 @@
query (lib/native-query mp "select 1")]
(mt/with-temp [:model/Transform transform {:source {:type "query" :query query}
:target {:type "table" :name (mt/random-name)}}]
- (t2/delete! :model/Database (:id db))
+ (t2/delete! :model/Database :id (:id db))
(is (=? {:id (:id transform)}
(mt/user-http-request :crowberto :get 200 (str "transform/" (:id transform)))))))))))
diff --git a/test/metabase/upload/api_test.clj b/test/metabase/upload/api_test.clj
index f82984cf163..4ec6dde56f0 100644
--- a/test/metabase/upload/api_test.clj
+++ b/test/metabase/upload/api_test.clj
@@ -30,7 +30,7 @@
(mt/test-driver :h2
(mt/with-empty-db
(testing "Happy path"
- (t2/update! :model/Database (mt/id) {:uploads_enabled true :uploads_schema_name "PUBLIC" :uploads_table_prefix nil})
+ (t2/update! :model/Database :id (mt/id) {:uploads_enabled true :uploads_schema_name "PUBLIC" :uploads_table_prefix nil})
(let [{:keys [status body]} (upload-example-csv-via-api!)]
(is (= 200
status))
diff --git a/test/metabase/upload/db_test.clj b/test/metabase/upload/db_test.clj
index 2b956a51f46..b3f960edea0 100644
--- a/test/metabase/upload/db_test.clj
+++ b/test/metabase/upload/db_test.clj
@@ -12,7 +12,7 @@
(mt/with-discard-model-updates! [:model/Database]
(testing "returns the uploads-enabled database"
(t2/update! :model/Database :uploads_enabled true {:uploads_enabled false})
- (t2/update! :model/Database (mt/id) {:uploads_enabled true})
+ (t2/update! :model/Database :id (mt/id) {:uploads_enabled true})
(is (= (mt/id)
(:id (upload.db/current-database)))))
(testing "returns nil when uploads are disabled"
diff --git a/test/metabase/upload/impl_test.clj b/test/metabase/upload/impl_test.clj
index 9e9e0068c7a..ef23b8c318c 100644
--- a/test/metabase/upload/impl_test.clj
+++ b/test/metabase/upload/impl_test.clj
@@ -125,10 +125,10 @@
schema-name (or (some->> schema-name (ddl.i/format-name driver/*driver*))
(sql.tx/session-schema driver/*driver*))
table (sync-tables/create-or-reactivate-table! (driver.u/lib-database (:id database)) {:name table-name :schema schema-name})]
- (t2/update! :model/Table (:id table) {:is_upload true})
+ (t2/update! :model/Table :id (:id table) {:is_upload true})
(binding [upload/*auxiliary-sync-steps* :synchronous]
(#'upload/scan-and-sync-table! table))
- (t2/select-one :model/Table (:id table))))
+ (t2/select-one :model/Table :id (:id table))))
(defn- tmp-file [prefix extension]
(doto (File/createTempFile prefix extension)
@@ -305,7 +305,7 @@
;; usually we don't care about analyze or field values for tests, so skip by default for speed
auxiliary-sync-steps :never}}]
(let [schema (sql.tx/session-schema driver/*driver*)
- db (t2/select-one :model/Database (mt/id))]
+ db (t2/select-one :model/Database :id (mt/id))]
(binding [upload/*auxiliary-sync-steps* auxiliary-sync-steps]
(:table (#'upload/create-from-csv-and-sync! {:db db
:file file
@@ -346,14 +346,14 @@
{:pre [(keyword? driver/*driver*)]}
(mt/with-discard-model-updates! [:model/Database]
(t2/update! :model/Database :uploads_enabled true {:uploads_enabled false})
- (t2/update! :model/Database db-id {:uploads_enabled uploads-enabled})
+ (t2/update! :model/Database :id db-id {:uploads_enabled uploads-enabled})
(mt/with-current-user user-id
(let [file (or file (csv-file-with
["id, name"
"1, Luke Skywalker"
"2, Darth Vader"]
csv-file-prefix))
- db (t2/select-one :model/Database db-id)
+ db (t2/select-one :model/Database :id db-id)
schema-name (if (contains? options :schema-name)
(ddl.i/format-name driver/*driver* (:schema-name options))
(sql.tx/session-schema driver/*driver*))
@@ -388,8 +388,8 @@
"Set uploads_enabled to true the current database, and as an admin user, run the thunk"
[thunk]
(mt/with-discard-model-updates! [:model/Database]
- (t2/update! :model/Database (mt/id) {:uploads_enabled true
- :uploads_schema_name (sql.tx/session-schema driver/*driver*)})
+ (t2/update! :model/Database :id (mt/id) {:uploads_enabled true
+ :uploads_schema_name (sql.tx/session-schema driver/*driver*)})
(mt/with-current-user (mt/user->id :crowberto)
(thunk))))
@@ -421,7 +421,7 @@
(t2/select-one :model/Card :table_id (:id table)))
(defn- card->table [card]
- (t2/select-one :model/Table (:table_id card)))
+ (t2/select-one :model/Table :id (:table_id card)))
(defmacro with-upload-table!
"Execute `body` with a table created by evaluating the expression `create-table-expr`. `create-table-expr` must
@@ -607,7 +607,7 @@
(sort-by :database_position)
(map (juxt (comp u/lower-case-en :name) identity))))))
(testing "Check that table can be written via data-editing"
- (is (true? (t2/select-one-fn :is_writable [:model/Table :is_writable] (:id table)))))
+ (is (true? (t2/select-one-fn :is_writable [:model/Table :is_writable] :id (:id table)))))
(testing "Check the data was uploaded into the table"
(is (= 2
(count (rows-for-table table)))))))))))
@@ -1162,8 +1162,8 @@
db-id (u/the-id db)
original-sync-values (select-keys db [:is_on_demand :is_full_sync])
schema-name (sql.tx/session-schema driver/*driver*)
- _ (t2/update! :model/Database db-id {:is_on_demand false
- :is_full_sync false})]
+ _ (t2/update! :model/Database :id db-id {:is_on_demand false
+ :is_full_sync false})]
(try
(testing "Happy path with schema, and without table-prefix"
(do-with-uploaded-example-csv!
@@ -1186,12 +1186,12 @@
new-table)
"A new table is created")
(is (= "complete"
- (:initial_sync_status (t2/select-one :model/Table (:id new-table))))
+ (:initial_sync_status (t2/select-one :model/Table :id (:id new-table))))
"The table is synced and marked as complete")
(is (t2/exists? :model/Field :table_id (:id new-table) :%lower.name "name" :semantic_type :type/Name)
"The sync actually runs")))))
(finally
- (t2/update! :model/Database db-id original-sync-values))))))
+ (t2/update! :model/Database :id db-id original-sync-values))))))
(deftest create-csv-upload!-table-prefix-test
(mt/test-drivers (mt/normal-drivers-with-feature :uploads)
@@ -1400,10 +1400,10 @@
schema-filter-prop (find-schema-filters-prop driver)
filter-type-prop (keyword (str (:name schema-filter-prop) "-type"))
patterns-type-prop (keyword (str (:name schema-filter-prop) "-patterns"))]
- (t2/update! :model/Database (mt/id) {:details (-> (mt/db)
- :details
- (assoc filter-type-prop "exclusion"
- patterns-type-prop "public"))})
+ (t2/update! :model/Database :id (mt/id) {:details (-> (mt/db)
+ :details
+ (assoc filter-type-prop "exclusion"
+ patterns-type-prop "public"))})
(testing "Upload should fail if table can't be found after sync, for example because of schema filters"
(try (do-with-uploaded-example-csv!
{:schema-name "public"}
@@ -1517,7 +1517,7 @@
(let [new-table (when (nil? table-id)
(create-upload-table!))
table-id (or table-id (:id new-table))]
- (t2/update! :model/Table table-id {:is_upload is-upload})
+ (t2/update! :model/Table :id table-id {:is_upload is-upload})
(try (update-csv! action {:table-id table-id, :file file})
(finally
;; Drop the table in the testdb if a new one was created.
@@ -1945,7 +1945,7 @@
csv-rows ["name, age" "Luke Skywalker, 57"]
file (csv-file-with csv-rows)
other-id (mt/id :venues)
- other-table (t2/select-one :model/Table other-id)
+ other-table (t2/select-one :model/Table :id other-id)
mp (lib-be/application-database-metadata-provider (:db_id table))]
(mt/with-temp [:model/Card {question-id :id} {:table_id table-id, :dataset_query (mbql mp table)}
:model/Card {model-id :id} {:table_id table-id, :type :model, :dataset_query (mbql mp table)}
@@ -2660,7 +2660,7 @@
;; Block access to the table in the other schema
(data-perms/set-table-permission! pg blocked-table :perms/view-data :blocked)
(data-perms/set-table-permission! pg blocked-table :perms/create-queries :no)
- (let [db (t2/select-one :model/Database db-id)]
+ (let [db (t2/select-one :model/Database :id db-id)]
(mt/with-current-user (mt/user->id :rasta)
(testing "can upload to the upload schema"
(is (true? (upload/can-create-upload? db "upload_schema"))))
diff --git a/test/metabase/users/models/user_test.clj b/test/metabase/users/models/user_test.clj
index 195d765dcd1..c2f979d4878 100644
--- a/test/metabase/users/models/user_test.clj
+++ b/test/metabase/users/models/user_test.clj
@@ -111,7 +111,7 @@
to `f`, then let `mt/with-temp` clean them up."
[f]
(mt/with-temp [:model/User admin {:is_superuser true, :email "[email protected]"}]
- (t2/update! :model/User (:id admin) {:last_login :%now})
+ (t2/update! :model/User :id (:id admin) {:last_login :%now})
(f admin)))
(deftest new-user-invite-email-test
@@ -174,8 +174,8 @@
(mt/with-temporary-raw-setting-values [send-new-sso-user-admin-email? "true"]
(mt/with-temp [:model/User admin-1 {:is_superuser true, :email "[email protected]"}
:model/User admin-2 {:is_superuser true, :email "[email protected]"}]
- (t2/update! :model/User (:id admin-1) {:last_login :%now})
- (t2/update! :model/User (:id admin-2) {:last_login :%now})
+ (t2/update! :model/User :id (:id admin-1) {:last_login :%now})
+ (t2/update! :model/User :id (:id admin-2) {:last_login :%now})
(is (= {(:email admin-1) ["<New User> created a Metabase account"]
(:email admin-2) ["<New User> created a Metabase account"]}
(-> (invite-user-accept-and-check-inboxes! :sso-auth? true)
@@ -397,14 +397,14 @@
(testing "updating a User"
(mt/with-temp [:model/User {user-id :id} {:locale "en_US"}]
(testing "valid locale"
- (t2/update! :model/User user-id {:locale "en_GB"})
+ (t2/update! :model/User :id user-id {:locale "en_GB"})
(is (= "en_GB"
(t2/select-one-fn :locale :model/User :id user-id))))
(testing "invalid locale"
(is (thrown-with-msg?
Throwable
#"Assert failed: Invalid locale: \"en_XX\""
- (t2/update! :model/User user-id {:locale "en_XX"}))))))))
+ (t2/update! :model/User :id user-id {:locale "en_XX"}))))))))
(deftest normalize-locale-test
(testing "`:locale` should be normalized"
@@ -413,7 +413,7 @@
(is (= "en_US"
(t2/select-one-fn :locale :model/User :id user-id))))
(testing "updating a User"
- (t2/update! :model/User user-id {:locale "en-GB"})
+ (t2/update! :model/User :id user-id {:locale "en-GB"})
(is (= "en_GB"
(t2/select-one-fn :locale :model/User :id user-id)))))))
@@ -428,10 +428,10 @@
(testing "Sanity check: subscription should exist"
(is (subscription-exists?)))
(testing "user is updated but not archived: don't delete the subscription"
- (is (pos? (t2/update! :model/User user-id {:is_active true :first_name "New name"})))
+ (is (pos? (t2/update! :model/User :id user-id {:is_active true :first_name "New name"})))
(is (subscription-exists?)))
(testing "archive the user"
- (is (pos? (t2/update! :model/User user-id {:is_active false}))))
+ (is (pos? (t2/update! :model/User :id user-id {:is_active false}))))
(testing "subscription should no longer exist"
(is (not (subscription-exists?))))))))
@@ -462,18 +462,18 @@
:last_name "Smith"
:email "[email protected]"}]
(is (= "John Smith"
- (:common_name (t2/select-one [:model/User :first_name :last_name] (:id user)))))
+ (:common_name (t2/select-one [:model/User :first_name :last_name] :id (:id user)))))
(is (= "John Smith"
- (:common_name (t2/select-one :model/User (:id user)))))
- (is (nil? (:common_name (t2/select-one [:model/User :first_name :email] (:id user)))))
- (is (nil? (:common_name (t2/select-one [:model/User :email] (:id user)))))))
+ (:common_name (t2/select-one :model/User :id (:id user)))))
+ (is (nil? (:common_name (t2/select-one [:model/User :first_name :email] :id (:id user)))))
+ (is (nil? (:common_name (t2/select-one [:model/User :email] :id (:id user)))))))
(testing "common_name should be present if first_name and last_name are selected but nil and email is also selected"
(mt/with-temp [:model/User user {:first_name nil
:last_name nil
:email "[email protected]"}]
- (:common_name (t2/select-one [:model/User :email :first_name :last_name] (:id user)))))
- (is (nil? (:common_name (t2/select-one [:model/User :first_name :last_name] (:id user))))))))
+ (:common_name (t2/select-one [:model/User :email :first_name :last_name] :id (:id user)))))
+ (is (nil? (:common_name (t2/select-one [:model/User :first_name :last_name] :id (:id user))))))))
(deftest block-sso-provisioning-if-instance-not-set-up
(testing "SSO users should not be created if an admin user has not already been created (metabase-private#201)"
@@ -493,11 +493,11 @@
(testing "deactivated_at is set when a user is deactivated and unset when reactivated (#51728)"
(mt/with-temp [:model/User {user-id :id :as user} {}]
(is (nil? (:deactivated_at user)))
- (t2/update! :model/User user-id {:is_active false})
- (let [deactivated-at (t2/select-one-fn :deactivated_at :model/User user-id)]
+ (t2/update! :model/User :id user-id {:is_active false})
+ (let [deactivated-at (t2/select-one-fn :deactivated_at :model/User :id user-id)]
(is (instance? java.time.OffsetDateTime deactivated-at)))
- (t2/update! :model/User user-id {:is_active true})
- (let [deactivated-at (t2/select-one-fn :deactivated_at :model/User user-id)]
+ (t2/update! :model/User :id user-id {:is_active true})
+ (let [deactivated-at (t2/select-one-fn :deactivated_at :model/User :id user-id)]
(is (nil? deactivated-at))))))
(deftest add-attributes-merges-login-and-jwt-attributes-test
diff --git a/test/metabase/users_rest/api_test.clj b/test/metabase/users_rest/api_test.clj
index 65317a73e07..7dbdb23554e 100644
--- a/test/metabase/users_rest/api_test.clj
+++ b/test/metabase/users_rest/api_test.clj
@@ -1789,7 +1789,7 @@
(mt/with-temporary-setting-values [google-auth-client-id "pretend-client-id.apps.googleusercontent.com"
google-auth-enabled true]
(mt/with-temp [:model/User user {:sso_source :google}]
- (t2/update! :model/User (u/the-id user)
+ (t2/update! :model/User :id (u/the-id user)
{:is_active false})
(mt/with-temporary-setting-values [google-auth-enabled false]
(mt/user-http-request :crowberto :put 200 (format "user/%s/reactivate" (u/the-id user)))
@@ -1925,7 +1925,7 @@
(testing "old_password is checked against the password AuthIdentity, like login, not the legacy core_user columns"
(mt/with-temp [:model/User user {:is_superuser false}]
(auth-identity/set-password! (:id user) "def")
- (t2/update! (t2/table-name :model/User) (:id user) {:password "not-a-bcrypt-hash", :password_salt "stale"})
+ (t2/update! (t2/table-name :model/User) :id (:id user) {:password "not-a-bcrypt-hash", :password_salt "stale"})
(is (=? {:success true}
(mt/client {:username (:email user), :password "def"}
:put 200 (format "user/%d/password" (:id user))
diff --git a/test/metabase/util/embed_test.clj b/test/metabase/util/embed_test.clj
index c8897070713..32da99b1d93 100644
--- a/test/metabase/util/embed_test.clj
+++ b/test/metabase/util/embed_test.clj
@@ -18,19 +18,19 @@
(testing "should populate `initially_published_at` when a Card's enable_embedding is changed to true"
(mt/with-temp [model card {:enable_embedding false}]
(is (nil? (:initially_published_at card)))
- (t2/update! model (u/the-id card) {:enable_embedding true})
+ (t2/update! model :id (u/the-id card) {:enable_embedding true})
(is (some? (t2/select-one-fn :initially_published_at model :id (u/the-id card))))))
(testing "should keep `initially_published_at` value when a Card's enable_embedding is changed to false"
(mt/with-temp [model card {:enable_embedding true :initially_published_at now}]
(is (some? (:initially_published_at card)))
- (t2/update! model (u/the-id card) {:enable_embedding false})
+ (t2/update! model :id (u/the-id card) {:enable_embedding false})
(is (= (t/offset-date-time now) (t2/select-one-fn :initially_published_at model :id (u/the-id card))))))
(testing "should keep `initially_published_at` value when `enable_embedding` is already set to true"
(mt/with-temp [model card {:enable_embedding true :initially_published_at now}]
- (t2/update! model (u/the-id card) {:enable_embedding true})
+ (t2/update! model :id (u/the-id card) {:enable_embedding true})
(is (= (t/offset-date-time now) (t2/select-one-fn :initially_published_at model :id (u/the-id card))))))
(testing "should keep `initially_published_at` value when `enable_embedding` is already set to false"
(mt/with-temp [model card {:enable_embedding false}]
(is (nil? (:initially_published_at card)))
- (t2/update! model (u/the-id card) {:enable_embedding false})
+ (t2/update! model :id (u/the-id card) {:enable_embedding false})
(is (nil? (t2/select-one-fn :initially_published_at model :id (u/the-id card)))))))))
diff --git a/test/metabase/util/honey_sql_2_test.clj b/test/metabase/util/honey_sql_2_test.clj
index dab30b108cb..e809b9c9954 100644
--- a/test/metabase/util/honey_sql_2_test.clj
+++ b/test/metabase/util/honey_sql_2_test.clj
@@ -8,6 +8,16 @@
[metabase.test :as mt]
[metabase.util.honey-sql-2 :as h2x]))
+(deftest ^:parallel assert-map-or-nil!-test
+ (testing "a map or nil passes through unchanged"
+ (is (= {:where [:= :id 1]} (h2x/assert-map-or-nil! {:where [:= :id 1]})))
+ (is (nil? (h2x/assert-map-or-nil! nil))))
+ (testing "anything else, such as a string or a number, throws"
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Expected a Honey SQL map"
+ (h2x/assert-map-or-nil! "DELETE FROM core_user")))
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Expected a Honey SQL map"
+ (h2x/assert-map-or-nil! 1)))))
+
(deftest ^:parallel inline-Ratio-test
(testing ":inline behavior for clojure.lang.Ratio should make sense (#28354)"
(is (= ["SELECT 4 / (1.0 / 3.0) AS x"]
diff --git a/test/metabase/view_log/events/view_log_test.clj b/test/metabase/view_log/events/view_log_test.clj
index 7a3df72afee..a5d2a6a5d72 100644
--- a/test/metabase/view_log/events/view_log_test.clj
+++ b/test/metabase/view_log/events/view_log_test.clj
@@ -148,7 +148,7 @@
(#'events.view-log/update-dashboard-last-viewed-at!* [{:id dashboard-id-1 :timestamp one-hour-ago}
{:id dashboard-id-1 :timestamp two-hours-ago}])
(is (= one-hour-ago
- (-> (t2/select-one-fn :last_viewed_at :model/Dashboard dashboard-id-1)
+ (-> (t2/select-one-fn :last_viewed_at :model/Dashboard :id dashboard-id-1)
t/offset-date-time
(.withNano 0))))))
(testing "if the existing last_viewed_at is greater than the updating values, do not override it"
@@ -156,7 +156,7 @@
[:model/Dashboard {dashboard-id-2 :id} {:last_viewed_at now}]
(#'events.view-log/update-dashboard-last-viewed-at!* [{:id dashboard-id-2 :timestamp one-hour-ago}])
(is (= now
- (-> (t2/select-one-fn :last_viewed_at :model/Dashboard dashboard-id-2)
+ (-> (t2/select-one-fn :last_viewed_at :model/Dashboard :id dashboard-id-2)
t/offset-date-time
(.withNano 0))))))))
@@ -212,9 +212,9 @@
(is (= 0 (:view_count card))
"view_count should be 0 before the event is published")
(events/publish-event! :event/card-read {:object-id (:id card) :user-id (u/the-id user) :context :question})
- (is (= 1 (t2/select-one-fn :view_count :model/Card (:id card))))
+ (is (= 1 (t2/select-one-fn :view_count :model/Card :id (:id card))))
(events/publish-event! :event/card-read {:object-id (:id card) :user-id (u/the-id user) :context :question})
- (is (= 2 (t2/select-one-fn :view_count :model/Card (:id card)))))))))
+ (is (= 2 (t2/select-one-fn :view_count :model/Card :id (:id card)))))))))
(deftest card-query-model-view-count-test
(mt/test-helpers-set-global-values!
@@ -225,9 +225,9 @@
(is (= 0 (:view_count model))
"view_count should be 0 before the event is published")
(events/publish-event! :event/card-query {:card-id (u/id model) :user-id (u/id user) :context :ad-hoc})
- (is (= 1 (t2/select-one-fn :view_count :model/Card (u/id model))))
+ (is (= 1 (t2/select-one-fn :view_count :model/Card :id (u/id model))))
(events/publish-event! :event/card-query {:card-id (u/id model) :user-id (u/id user) :context :ad-hoc})
- (is (= 2 (t2/select-one-fn :view_count :model/Card (u/id model)))))))))
+ (is (= 2 (t2/select-one-fn :view_count :model/Card :id (u/id model)))))))))
(deftest dashboard-read-view-count-test
(mt/test-helpers-set-global-values!
@@ -241,11 +241,11 @@
(is (= 0 (:view_count dashboard) (:view_count card))
"view_count should be 0 before the event is published")
(events/publish-event! :event/dashboard-read {:object-id (:id dashboard) :user-id (u/the-id user)})
- (is (= 1 (t2/select-one-fn :view_count :model/Dashboard (:id dashboard))))
- (is (= 0 (t2/select-one-fn :view_count :model/Card (:id card)))
+ (is (= 1 (t2/select-one-fn :view_count :model/Dashboard :id (:id dashboard))))
+ (is (= 0 (t2/select-one-fn :view_count :model/Card :id (:id card)))
"view_count for cards on the dashboard should not be incremented")
(events/publish-event! :event/dashboard-read {:object-id (:id dashboard) :user-id (u/the-id user)})
- (is (= 2 (t2/select-one-fn :view_count :model/Dashboard (:id dashboard))))))))))
+ (is (= 2 (t2/select-one-fn :view_count :model/Dashboard :id (:id dashboard))))))))))
(deftest table-read-view-count-test
(mt/test-helpers-set-global-values!
@@ -256,10 +256,10 @@
(is (= 0 (:view_count table))
"view_count should be 0 before the event is published")
(events/publish-event! :event/table-read {:object table :user-id (u/the-id user)})
- (is (= 1 (t2/select-one-fn :view_count :model/Table (:id table)))
+ (is (= 1 (t2/select-one-fn :view_count :model/Table :id (:id table)))
"view_count should be incremented")
(events/publish-event! :event/table-read {:object table :user-id (u/the-id user)})
- (is (= 2 (t2/select-one-fn :view_count :model/Table (:id table)))
+ (is (= 2 (t2/select-one-fn :view_count :model/Table :id (:id table)))
"view_count should be incremented"))))))
(deftest oversized-row-does-not-destroy-batch-test
@@ -315,12 +315,12 @@
(is (= 2 ;; one for update card, one for table
@call-count)
"and groups db calls by frequency")
- (is (= 1 (t2/select-one-fn :view_count :model/Table table-id))
+ (is (= 1 (t2/select-one-fn :view_count :model/Table :id table-id))
"view_count for table-id should be 1")
- (is (= 2 (t2/select-one-fn :view_count :model/Card card-1-id))
+ (is (= 2 (t2/select-one-fn :view_count :model/Card :id card-1-id))
"view_count for card-1 should be 2")
(is (= 4 ;; 2 old + 2 new
- (t2/select-one-fn :view_count :model/Card card-2-id))
+ (t2/select-one-fn :view_count :model/Card :id card-2-id))
"view_count for card-2 should be 2")))))
;;; ---------------------------------------- API tests begin -----------------------------------------
diff --git a/test/metabase/warehouse_schema/models/field_test.clj b/test/metabase/warehouse_schema/models/field_test.clj
index fd24e3fbeea..7daa7ccf6c3 100644
--- a/test/metabase/warehouse_schema/models/field_test.clj
+++ b/test/metabase/warehouse_schema/models/field_test.clj
@@ -73,11 +73,11 @@
(data-perms/set-database-permission! pg db-id :perms/view-data :blocked)
(data-perms/set-database-permission! pg db-id :perms/create-queries :no)
(mt/with-test-user :rasta
- (is (not (mi/can-read? (t2/select-one :model/Field field-id)))))
+ (is (not (mi/can-read? (t2/select-one :model/Field :id field-id)))))
;; Grant view-data permission - field should still not be readable
(data-perms/set-table-permission! pg table-id :perms/view-data :unrestricted)
(mt/with-test-user :rasta
- (is (false? (boolean (mi/can-read? (t2/select-one :model/Field field-id)))))))))
+ (is (false? (boolean (mi/can-read? (t2/select-one :model/Field :id field-id)))))))))
(deftest field-can-read?-delegates-to-parent-table-allowed-test
(testing "Field can-read? delegates to parent table"
@@ -91,12 +91,12 @@
(data-perms/set-database-permission! pg db-id :perms/view-data :blocked)
(data-perms/set-database-permission! pg db-id :perms/create-queries :no)
(mt/with-test-user :rasta
- (is (not (mi/can-read? (t2/select-one :model/Field field-id)))))
+ (is (not (mi/can-read? (t2/select-one :model/Field :id field-id)))))
;; Grant view-data permission - now field should be readable
(data-perms/set-table-permission! pg table-id :perms/view-data :unrestricted)
(data-perms/set-table-permission! pg table-id :perms/create-queries :query-builder)
(mt/with-test-user :rasta
- (is (true? (mi/can-read? (t2/select-one :model/Field field-id))))))))
+ (is (true? (mi/can-read? (t2/select-one :model/Field :id field-id))))))))
(deftest field-can-query?-delegates-to-parent-table-test
(testing "Field can-query? delegates to parent table"
@@ -112,7 +112,7 @@
(data-perms/set-table-permission! pg table-id :perms/view-data :unrestricted)
(data-perms/set-table-permission! pg table-id :perms/create-queries :query-builder)
(mt/with-test-user :rasta
- (is (true? (mi/can-query? (t2/select-one :model/Field field-id))))))))
+ (is (true? (mi/can-query? (t2/select-one :model/Field :id field-id))))))))
;;; ---------------------------------- effective_type invariant guard tests -----------------------------------
;;; GHY-3388: a Field with coercion_strategy=nil and effective_type ≠ base_type is internally
@@ -149,8 +149,8 @@
:name "broken_on_update"
:base_type :type/Number
:effective_type :type/Number}]
- (t2/update! :model/Field field-id {:effective_type :type/Text
- :coercion_strategy nil})
+ (t2/update! :model/Field :id field-id {:effective_type :type/Text
+ :coercion_strategy nil})
(is (=? {:base_type :type/Number
:effective_type :type/Number}
(t2/select-one :model/Field :id field-id))))))
@@ -164,8 +164,8 @@
:name "with_coercion"
:base_type :type/Text
:effective_type :type/Text}]
- (t2/update! :model/Field field-id {:effective_type :type/Number
- :coercion_strategy :Coercion/String->Number})
+ (t2/update! :model/Field :id field-id {:effective_type :type/Number
+ :coercion_strategy :Coercion/String->Number})
(is (=? {:base_type :type/Text
:effective_type :type/Number
:coercion_strategy :Coercion/String->Number}
@@ -182,7 +182,7 @@
:effective_type :type/Number
:coercion_strategy :Coercion/String->Number}]
;; user clears the coercion but doesn't reset effective_type — guard catches this
- (t2/update! :model/Field field-id {:coercion_strategy nil})
+ (t2/update! :model/Field :id field-id {:coercion_strategy nil})
(is (=? {:base_type :type/Text
:effective_type :type/Text
:coercion_strategy nil}
@@ -241,7 +241,7 @@
:effective_type :type/Number
:position 0
:database_position 0}))]
- (t2/update! :model/Field id {:effective_type :type/Text})
+ (t2/update! :model/Field :id id {:effective_type :type/Text})
id))]
["t2/update! clears coercion_strategy but leaves effective_type stale"
(fn [table-id]
@@ -256,7 +256,7 @@
:coercion_strategy :Coercion/String->Number
:position 0
:database_position 0}))]
- (t2/update! :model/Field id {:coercion_strategy nil})
+ (t2/update! :model/Field :id id {:coercion_strategy nil})
id))]
["t2/update! changes base_type but leaves effective_type stale"
(fn [table-id]
@@ -270,7 +270,7 @@
:effective_type :type/Text
:position 0
:database_position 0}))]
- (t2/update! :model/Field id {:base_type :type/Number})
+ (t2/update! :model/Field :id id {:base_type :type/Number})
id))]
["t2/update! sets both effective_type AND coercion_strategy=nil to mismatched values"
(fn [table-id]
@@ -284,8 +284,8 @@
:effective_type :type/Number
:position 0
:database_position 0}))]
- (t2/update! :model/Field id {:effective_type :type/Text
- :coercion_strategy nil})
+ (t2/update! :model/Field :id id {:effective_type :type/Text
+ :coercion_strategy nil})
id))]]]
(testing label
(mt/with-temp [:model/Database {db-id :id} {}
@@ -313,7 +313,7 @@
(testing "a bare update to the Field is written as given and stays hidden behind the user label"
(mt/with-temp [:model/Field {field-id :id :as field} {:data_sensitivity :PII}]
(field-user-settings/upsert-user-settings field {:data_sensitivity :PUBLIC})
- (t2/update! :model/Field field-id {:data_sensitivity :PHI})
+ (t2/update! :model/Field :id field-id {:data_sensitivity :PHI})
(is (= :PHI (t2/select-one-fn :data_sensitivity :model/Field :id field-id)))
(is (= :PUBLIC (:data_sensitivity (warehouse-schema.db/field field-id))))))
(testing "upsert-user-settings with a nil value clears a previously set label on the mirror"
@@ -341,10 +341,10 @@
(warehouse-schema.db/field edited-id)))
(is (=? {:id plain-id :display_name "Plain"} (warehouse-schema.db/field plain-id))))
(testing "a flag left false means the sync value shows, even next to a user value"
- (t2/update! :model/FieldUserSettings edited-id {:description_set false})
+ (t2/update! :model/FieldUserSettings :field_id edited-id {:description_set false})
(is (= "sync description" (:description (warehouse-schema.db/field edited-id)))))
(testing "coercion_strategy follows the user's effective_type, so a cleared coercion shows as cleared"
- (t2/update! :model/Field edited-id {:effective_type :type/Number :coercion_strategy :Coercion/String->Number})
+ (t2/update! :model/Field :id edited-id {:effective_type :type/Number :coercion_strategy :Coercion/String->Number})
(field-user-settings/upsert-user-settings edited {:effective_type :type/Text :coercion_strategy nil})
(is (=? {:effective_type :type/Text :coercion_strategy nil} (warehouse-schema.db/field edited-id)))
(field-user-settings/unset-user-settings! edited [:effective_type :coercion_strategy])
@@ -404,6 +404,6 @@
(mt/with-temp [:model/Field {target-id :id} {}
:model/Field {source-id :id :as source} {:semantic_type :type/Category}]
(field-user-settings/upsert-user-settings source {:semantic_type :type/FK :fk_target_field_id target-id})
- (t2/update! :model/Field target-id {:active false})
+ (t2/update! :model/Field :id target-id {:active false})
(is (nil? (t2/select-one :model/FieldUserSettings :field_id source-id)))
(is (= :type/Category (:semantic_type (warehouse-schema.db/field source-id)))))))
diff --git a/test/metabase/warehouse_schema/models/field_values_test.clj b/test/metabase/warehouse_schema/models/field_values_test.clj
index 8f9031d1e75..0ce00e52930 100644
--- a/test/metabase/warehouse_schema/models/field_values_test.clj
+++ b/test/metabase/warehouse_schema/models/field_values_test.clj
@@ -174,7 +174,7 @@
(defn distinct-field-values
[id]
- (field-values/distinct-values (t2/select-one :model/Field id)))
+ (field-values/distinct-values (t2/select-one :model/Field :id id)))
(deftest distinct-values-test
(testing "Correctly get distinct field values for text fields"
@@ -200,7 +200,7 @@
(select-keys [:values :human_readable_values])))
(defn- sync-and-find-values! [db field-values-id]
- (sync/sync-database! (:id (t2/select-one :model/Database (u/the-id db))))
+ (sync/sync-database! (:id (t2/select-one :model/Database :id (u/the-id db))))
(find-values field-values-id))
(deftest implicit-deduplication-test
@@ -463,7 +463,7 @@
_ (field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id field-id))
field-values-id (t2/select-one-fn :id :model/FieldValues :field_id field-id)]
;; Add in human readable values for remapping
- (is (t2/update! :model/FieldValues field-values-id {:human_readable_values ["a" "b" "c"]}))
+ (is (t2/update! :model/FieldValues :id 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]
@@ -500,7 +500,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Invalid human-readable-values"
- (t2/update! :model/FieldValues id {:human_readable_values {"1" "A", "2", "B"}})))))))
+ (t2/update! :model/FieldValues :id id {:human_readable_values {"1" "A", "2", "B"}})))))))
(deftest rescanned-human-readable-values-test
(testing "Make sure FieldValues are calculated and saved correctly when remapping is in place (#13235)"
@@ -567,7 +567,7 @@
[full-id {:type :sandbox, :hash_key "random-hash"}]]]
(is (thrown-with-msg? ExceptionInfo
#"Can't update field_id, type, or hash_key for a FieldValues."
- (t2/update! :model/FieldValues id update-map)))))
+ (t2/update! :model/FieldValues :id id update-map)))))
(testing "The model hooks permits mention of the existing values"
(doseq [[id update-map] [[full-id {:field_id (mt/id :venues :id)}]
[sandbox-id {:type :sandbox}]
@@ -576,7 +576,7 @@
[full-id {:hash_key nil}]
[full-id {:type :full, :hash_key nil}]
[sandbox-id {:type :sandbox, :hash_key "random-hash"}]]]
- (is (some? (t2/update! :model/FieldValues id update-map)))))))
+ (is (some? (t2/update! :model/FieldValues :id id update-map)))))))
(deftest insert-full-field-values-should-remove-all-cached-field-values
(doseq [explicitly-full? [false true]]
@@ -592,7 +592,7 @@
:model/FieldValues sandbox-fv {:field_id (mt/id :venues :id)
:type :sandbox
:hash_key "random-hash"}]
- (t2/update! :model/FieldValues (:id fv) {:values [1 2 3]})
+ (t2/update! :model/FieldValues :id (:id fv) {:values [1 2 3]})
(is (not (t2/exists? :model/FieldValues :id (:id sandbox-fv))))))
(deftest update-full-field-without-values-should-remove-not-all-cached-field-values
@@ -601,7 +601,7 @@
:model/FieldValues sandbox-fv {:field_id (mt/id :venues :id)
:type :sandbox
:hash_key "random-hash"}]
- (t2/update! :model/FieldValues (:id fv) {:updated_at (t/zoned-date-time)})
+ (t2/update! :model/FieldValues :id (:id fv) {:updated_at (t/zoned-date-time)})
(is (t2/exists? :model/FieldValues :id (:id sandbox-fv)))))
(deftest select-coherence-test
diff --git a/test/metabase/warehouse_schema/models/table_test.clj b/test/metabase/warehouse_schema/models/table_test.clj
index d323f850812..27a43833694 100644
--- a/test/metabase/warehouse_schema/models/table_test.clj
+++ b/test/metabase/warehouse_schema/models/table_test.clj
@@ -147,7 +147,7 @@
(data-perms/set-table-permission! (perms-group/all-users) table-id-1 :perms/download-results :one-million-rows)
(data-perms/set-table-permission! (perms-group/all-users) table-id-1 :perms/manage-table-metadata :yes)
(is (true? (t2/exists? :model/DataPermissions :table_id table-id-1)))
- (t2/delete! :model/Table table-id-1)
+ (t2/delete! :model/Table :id table-id-1)
(testing "Table-level permissions are deleted when we delete the table"
(is (false? (t2/exists? :model/DataPermissions :table_id table-id-1))))))
@@ -158,7 +158,7 @@
(field-values/get-or-create-full-field-values! (t2/select-one :model/Field :id (mt/id :venues :name)))
(is (=? {(mt/id :venues :price) (mt/malli=? [:sequential {:min 1} :any])
(mt/id :venues :name) (mt/malli=? [:sequential {:min 1} :any])}
- (-> (t2/select-one :model/Table (mt/id :venues))
+ (-> (t2/select-one :model/Table :id (mt/id :venues))
(t2/hydrate :field_values)
:field_values)))
(testing "batched hydration of several tables"
@@ -173,7 +173,7 @@
(deftest pk-field-hydration-test
(is (= (mt/id :venues :id)
- (-> (t2/select-one :model/Table (mt/id :venues))
+ (-> (t2/select-one :model/Table :id (mt/id :venues))
(t2/hydrate :pk_field)
:pk_field))))
@@ -495,30 +495,30 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Cannot change data_source from metabase-transform"
- (t2/update! :model/Table table-id {:data_source :transform}))))
+ (t2/update! :model/Table :id table-id {:data_source :transform}))))
(testing "to nil"
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Cannot change data_source from metabase-transform"
- (t2/update! :model/Table table-id {:data_source nil}))))))
+ (t2/update! :model/Table :id table-id {:data_source nil}))))))
(testing "Cannot change data_source to metabase-transform"
(mt/with-temp [:model/Table {table-id :id} {:data_source :ingested}]
(testing "from another value"
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Cannot set data_source to metabase-transform"
- (t2/update! :model/Table table-id {:data_source :metabase-transform}))))
+ (t2/update! :model/Table :id table-id {:data_source :metabase-transform}))))
(testing "but can change to other non-metabase-transform values"
- (is (some? (t2/update! :model/Table table-id {:data_source :ingested})))
+ (is (some? (t2/update! :model/Table :id table-id {:data_source :ingested})))
(is (= :ingested (t2/select-one-fn :data_source :model/Table :id table-id))))
(testing "can also change it to nil"
- (is (some? (t2/update! :model/Table table-id {:data_source nil})))
+ (is (some? (t2/update! :model/Table :id table-id {:data_source nil})))
(is (nil? (t2/select-one-fn :data_source :model/Table :id table-id))))))
(testing "data_source guard is relaxed for nil -> metabase-transform during deserialization (GDGT-2445)"
(testing "can set data_source to metabase-transform on an existing synced table"
(mt/with-temp [:model/Table {table-id :id} {:data_source nil}]
(binding [mi/*deserializing?* true]
- (is (some? (t2/update! :model/Table table-id {:data_source :metabase-transform}))))
+ (is (some? (t2/update! :model/Table :id table-id {:data_source :metabase-transform}))))
(is (= :metabase-transform (t2/select-one-fn :data_source :model/Table :id table-id)))))
(testing "reverse direction stays blocked even during deserialization"
(mt/with-temp [:model/Table {table-id :id} {:data_source :metabase-transform}]
@@ -526,7 +526,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Cannot change data_source from metabase-transform"
- (t2/update! :model/Table table-id {:data_source nil}))))))))
+ (t2/update! :model/Table :id table-id {:data_source nil}))))))))
(deftest is-published-and-collection-id-test
(testing "is_published defaults to false"
@@ -596,7 +596,7 @@
(data-perms/set-database-permission! pg db-id :perms/create-queries :query-builder)
(data-perms/set-table-permission! pg table-id :perms/view-data :unrestricted)
(mt/with-test-user :rasta
- (is (true? (mi/can-read? (t2/select-one :model/Table table-id))))))))
+ (is (true? (mi/can-read? (t2/select-one :model/Table :id table-id))))))))
(deftest table-can-read?-with-view-data-permission-test
(testing "User with view-data and create-queries permission can read table"
@@ -609,7 +609,7 @@
(data-perms/set-database-permission! pg db-id :perms/create-queries :no)
(data-perms/set-table-permission! pg table-id :perms/view-data :unrestricted)
(mt/with-test-user :rasta
- (is (false? (boolean (mi/can-read? (t2/select-one :model/Table table-id)))))))))
+ (is (false? (boolean (mi/can-read? (t2/select-one :model/Table :id table-id)))))))))
(deftest table-can-read?-with-manage-table-metadata-permission-test
(testing "User with manage-table-metadata permission can read table"
@@ -622,7 +622,7 @@
(data-perms/set-database-permission! pg db-id :perms/create-queries :no)
(data-perms/set-table-permission! pg table-id :perms/manage-table-metadata :yes)
(mt/with-test-user :rasta
- (is (true? (mi/can-read? (t2/select-one :model/Table table-id))))))))
+ (is (true? (mi/can-read? (t2/select-one :model/Table :id table-id))))))))
(deftest table-can-read?-without-permissions-test
(testing "User with neither permission cannot read table"
@@ -634,7 +634,7 @@
(data-perms/set-database-permission! pg db-id :perms/view-data :blocked)
(data-perms/set-database-permission! pg db-id :perms/create-queries :no)
(mt/with-test-user :rasta
- (is (false? (mi/can-read? (t2/select-one :model/Table table-id))))))))
+ (is (false? (mi/can-read? (t2/select-one :model/Table :id table-id))))))))
;;; ---------------------------------------- can-query? permission tests ----------------------------------------
@@ -650,11 +650,11 @@
;; Only view-data - not enough
(data-perms/set-table-permission! pg table-id :perms/view-data :unrestricted)
(mt/with-test-user :rasta
- (is (false? (mi/can-query? (t2/select-one :model/Table table-id)))))
+ (is (false? (mi/can-query? (t2/select-one :model/Table :id table-id)))))
;; Add create-queries - now can query
(data-perms/set-table-permission! pg table-id :perms/create-queries :query-builder)
(mt/with-test-user :rasta
- (is (true? (mi/can-query? (t2/select-one :model/Table table-id))))))))
+ (is (true? (mi/can-query? (t2/select-one :model/Table :id table-id))))))))
(deftest table-can-query?-manage-table-metadata-does-not-grant-query-access-test
(testing "manage-table-metadata alone does NOT grant query access"
@@ -667,7 +667,7 @@
(data-perms/set-database-permission! pg db-id :perms/create-queries :no)
(data-perms/set-table-permission! pg table-id :perms/manage-table-metadata :yes)
(mt/with-test-user :rasta
- (is (false? (mi/can-query? (t2/select-one :model/Table table-id))))))))
+ (is (false? (mi/can-query? (t2/select-one :model/Table :id table-id))))))))
;;; ---------------------------------------- can_query hydration test ----------------------------------------
diff --git a/test/metabase/warehouse_schema/models/table_user_settings_test.clj b/test/metabase/warehouse_schema/models/table_user_settings_test.clj
index 6f5ff7e47f9..0766d9fafda 100644
--- a/test/metabase/warehouse_schema/models/table_user_settings_test.clj
+++ b/test/metabase/warehouse_schema/models/table_user_settings_test.clj
@@ -25,7 +25,7 @@
(is (=? {:id table-id :display_name "User Name" :description nil :entity_type :entity/GenericTable}
(user-table table-id))))
(testing "a flag left false means the sync value shows again"
- (t2/update! :model/TableUserSettings table-id {:description_set false})
+ (t2/update! :model/TableUserSettings :table_id table-id {:description_set false})
(is (= "sync description" (:description (user-table table-id))))))))
(deftest not-null-columns-need-no-flag-test
@@ -75,21 +75,21 @@
(testing "a written column carries its _set flag, on insert and on update"
(t2/insert! :model/FieldUserSettings {:field_id field-id :description "d"})
(is (true? (t2/select-one-fn :description_set :model/FieldUserSettings :field_id field-id)))
- (t2/update! :model/FieldUserSettings field-id {:semantic_type :type/Category})
+ (t2/update! :model/FieldUserSettings :field_id field-id {:semantic_type :type/Category})
(is (true? (t2/select-one-fn :semantic_type_set :model/FieldUserSettings :field_id field-id))))
(testing "a flag the writer set itself is left alone, which is how a value is taken back"
(t2/insert! :model/TableUserSettings {:table_id table-id :display_name "n" :description "d"})
- (t2/update! :model/TableUserSettings table-id {:description nil :description_set false})
+ (t2/update! :model/TableUserSettings :table_id table-id {:description nil :description_set false})
(is (false? (t2/select-one-fn :description_set :model/TableUserSettings :table_id table-id))))
(testing "both halves of the visibility choice move together"
- (t2/update! :model/TableUserSettings table-id {:visibility_type :hidden})
+ (t2/update! :model/TableUserSettings :table_id table-id {:visibility_type :hidden})
(is (=? {:visibility_type :hidden :data_layer :hidden
:visibility_type_set true :data_layer_set true}
(t2/select-one :model/TableUserSettings :table_id table-id))))
(testing "a change a user may not make is refused whoever writes it"
- (t2/update! :model/TableUserSettings table-id {:data_authority :authoritative})
+ (t2/update! :model/TableUserSettings :table_id table-id {:data_authority :authoritative})
(is (thrown-with-msg? Exception #"Cannot set data_authority back to unconfigured"
- (t2/update! :model/TableUserSettings table-id
+ (t2/update! :model/TableUserSettings :table_id table-id
{:data_authority :unconfigured})))))))
(deftest custom-order-fields-test
diff --git a/test/metabase/warehouse_schema_rest/api/field_test.clj b/test/metabase/warehouse_schema_rest/api/field_test.clj
index 886ad8c6cea..f9c1484d6af 100644
--- a/test/metabase/warehouse_schema_rest/api/field_test.clj
+++ b/test/metabase/warehouse_schema_rest/api/field_test.clj
@@ -363,7 +363,7 @@
(testing "PUT /api/field/:id clearing semantic_type on a sync-detected FK hides the target without touching sync data"
(mt/with-temp [:model/Field {target-id :id} {}
:model/Field {field-id :id} {}]
- (t2/update! :model/Field field-id {:semantic_type :type/FK :fk_target_field_id target-id})
+ (t2/update! :model/Field :id field-id {:semantic_type :type/FK :fk_target_field_id target-id})
(testing "before the user's edit, GET shows the sync-detected FK"
(is (=? {:semantic_type "type/FK"
:fk_target_field_id target-id
@@ -405,8 +405,8 @@
(mt/with-temp-copy-of-db
;; clear out existing human_readable_values in case they're set
(when-let [id (field-values-id :venues :price)]
- (t2/update! :model/FieldValues id {:human_readable_values nil}))
- (t2/update! :model/Field (mt/id :venues :price) {:has_field_values "list"})
+ (t2/update! :model/FieldValues :id id {:human_readable_values nil}))
+ (t2/update! :model/Field :id (mt/id :venues :price) {:has_field_values "list"})
;; now update the values via the API
(is (= {:values [[1] [2] [3] [4]], :field_id (mt/id :venues :price), :has_more_values false}
(mt/user-http-request :crowberto :get 200 (format "field/%d/values" (mt/id :venues :price)))))))
@@ -1027,7 +1027,7 @@
(deftest field-values-requires-query-permission-test
(testing "GET /api/field/:id/values requires query permission (view-data + create-queries)"
(mt/with-temp-copy-of-db
- (t2/update! :model/Field (mt/id :venues :price) {:has_field_values "list"})
+ (t2/update! :model/Field :id (mt/id :venues :price) {:has_field_values "list"})
(testing "User with only view-data permission (no create-queries) cannot access field values"
(mt/with-no-data-perms-for-all-users!
(is (= "You don't have permissions to do that."
diff --git a/test/metabase/warehouse_schema_rest/api/table_test.clj b/test/metabase/warehouse_schema_rest/api/table_test.clj
index 4cd0a5d0116..4f9f6adc59e 100644
--- a/test/metabase/warehouse_schema_rest/api/table_test.clj
+++ b/test/metabase/warehouse_schema_rest/api/table_test.clj
@@ -574,7 +574,7 @@
(testing "PUT /api/table/:id"
(testing "Table should get synced when it gets unhidden"
(mt/with-temp [:model/Database db {:details (:details (mt/db))}
- :model/Table table (-> (t2/select-one :model/Table (mt/id :venues))
+ :model/Table table (-> (t2/select-one :model/Table :id (mt/id :venues))
(dissoc :id :entity_id)
(assoc :db_id (:id db)))]
(let [called (atom 0)
@@ -1527,7 +1527,7 @@
[]]]
(let [db (mt/db)
db-spec (sql-jdbc.conn/db->pooled-connection-spec (driver.u/ensure-lib-database db))
- get-fk-target #(t2/select-one-fn :fk_target_field_id :model/Field (mt/id :country :continent_id))]
+ get-fk-target #(t2/select-one-fn :fk_target_field_id :model/Field :id (mt/id :country :continent_id))]
;; 1. add FK relationship in the database targeting continent_1
(jdbc/execute! db-spec "ALTER TABLE country ADD CONSTRAINT country_continent_id_fkey FOREIGN KEY (continent_id) REFERENCES continent(id);")
(sync/sync-database! (:id db) {:scan :schema})
diff --git a/test/metabase/warehouses/models/database_test.clj b/test/metabase/warehouses/models/database_test.clj
index 73142de3c0b..dcf7cb95091 100644
--- a/test/metabase/warehouses/models/database_test.clj
+++ b/test/metabase/warehouses/models/database_test.clj
@@ -68,7 +68,7 @@
(deftest cleanup-permissions-after-delete-db-test
(mt/with-temp [:model/Database {db-id :id} {}]
(is (true? (t2/exists? :model/DataPermissions :db_id db-id)))
- (t2/delete! :model/Database db-id)
+ (t2/delete! :model/Database :id db-id)
(testing "All permissions are deleted when we delete the database"
(is (false? (t2/exists? :model/DataPermissions :db_id db-id))))))
@@ -308,13 +308,13 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"The database does not support actions."
- (t2/update! :model/Database (:id database) {:settings {:database-enable-actions true}})))))
+ (t2/update! :model/Database :id (:id database) {:settings {:database-enable-actions true}})))))
(testing "Updating the engine when database-enable-actions is true should fail if the engine doesn't support actions"
(mt/with-temp [:model/Database database {:engine :h2 :settings {:database-enable-actions true}}]
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"The database does not support actions."
- (t2/update! :model/Database (:id database) {:engine :sqlite})))))))
+ (t2/update! :model/Database :id (:id database) {:engine :sqlite})))))))
(deftest ^:parallel sensitive-data-redacted-test
(let [encode-decode (comp json/decode json/encode)
@@ -457,7 +457,7 @@
(is (= (:details db)
(database/maybe-test-and-migrate-details! db)))
(is (= (:details db)
- (t2/select-one-fn :details :model/Database (:id db)))
+ (t2/select-one-fn :details :model/Database :id (:id db)))
(str [(:id db) "query"]))))))))
(deftest maybe-test-and-migrate-details!-password-test
@@ -475,7 +475,7 @@
:password "secret"}
(database/maybe-test-and-migrate-details! db)))
(is (= {:password "secret"}
- (t2/select-one-fn :details :model/Database (:id db))))))))))
+ (t2/select-one-fn :details :model/Database :id (:id db))))))))))
(deftest maybe-test-and-migrate-details!-keystore-test
(mt/with-driver
@@ -491,7 +491,7 @@
(is (= {:keystore-id (get-in db [:details :keystore-id])}
(database/maybe-test-and-migrate-details! db)))
(is (= {:keystore-id (get-in db [:details :keystore-id])}
- (t2/select-one-fn :details :model/Database (:id db))))))))))
+ (t2/select-one-fn :details :model/Database :id (:id db))))))))))
(deftest secrets-in-details-test
(mt/with-driver :secret-test-driver
@@ -504,8 +504,8 @@
:created_at (t/instant)
:updated_at (t/instant)
:details json-details}]
- (is (= json-details (t2/select-one-fn :details database-table db-id)))
- (is (= {:host "localhost" :keystore-id secret-id} (t2/select-one-fn :details :model/Database db-id)))
+ (is (= json-details (t2/select-one-fn :details database-table :id db-id)))
+ (is (= {:host "localhost" :keystore-id secret-id} (t2/select-one-fn :details :model/Database :id db-id)))
(is (= {:host "localhost" :keystore-id secret-id :keystore-options "uploaded" :keystore-value secret/protected-password}
(:details (mt/user-http-request :crowberto :get 200 (format "database/%d" db-id))))
"API request")))))
@@ -517,8 +517,8 @@
:created_at (t/instant)
:updated_at (t/instant)
:details json-details}]
- (is (= json-details (t2/select-one-fn :details database-table db-id)))
- (is (= {:host "localhost"} (t2/select-one-fn :details :model/Database db-id)))
+ (is (= json-details (t2/select-one-fn :details database-table :id db-id)))
+ (is (= {:host "localhost"} (t2/select-one-fn :details :model/Database :id db-id)))
(is (= {:host "localhost"}
(:details (mt/user-http-request :crowberto :get 200 (format "database/%d" db-id))))
"API request"))))))
@@ -530,25 +530,25 @@
(let [db-id (:id db)
secret-id (get-in db [:details :keystore-id])
expected {:keystore-id secret-id}]
- (is (= expected (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) db-id)))
+ (is (= expected (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) :id db-id)))
(is (=? {:value (u/string-to-bytes "secret") :source :uploaded :version 1}
(secret/latest-for-id secret-id)))
- (t2/update! :model/Database db-id {:details {:keystore-path "secret-path"}})
- (is (= expected (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) db-id)))
+ (t2/update! :model/Database :id db-id {:details {:keystore-path "secret-path"}})
+ (is (= expected (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) :id db-id)))
(is (=? {:value (u/string-to-bytes "secret-path") :source :file-path :version 2}
(secret/latest-for-id secret-id)))
- (t2/update! :model/Database db-id {:details {:keystore-path "ignore-path" :keystore-value "prefer-value"}})
- (is (= expected (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) db-id)))
+ (t2/update! :model/Database :id db-id {:details {:keystore-path "ignore-path" :keystore-value "prefer-value"}})
+ (is (= expected (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) :id db-id)))
(is (=? {:value (u/string-to-bytes "prefer-value") :source :uploaded :version 3}
(secret/latest-for-id secret-id)))
- (t2/update! :model/Database db-id {:details {:keystore-options "local"
- :keystore-path "prefer-path"
- :keystore-value "ignore-value"}})
- (is (= expected (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) db-id)))
+ (t2/update! :model/Database :id db-id {:details {:keystore-options "local"
+ :keystore-path "prefer-path"
+ :keystore-value "ignore-value"}})
+ (is (= expected (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) :id db-id)))
(is (=? {:value (u/string-to-bytes "prefer-path") :source :file-path :version 4}
(secret/latest-for-id secret-id)))
- (t2/update! :model/Database db-id {:details {:keystore-value nil}})
- (is (= {} (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) db-id)))
+ (t2/update! :model/Database :id db-id {:details {:keystore-value nil}})
+ (is (= {} (t2/select-one-fn (comp json/decode+kw :details) (t2/table-name :model/Database) :id db-id)))
(is (=? nil
(secret/latest-for-id secret-id))))))
@@ -576,7 +576,7 @@
:keystore-path "local.key"
:keystore-options "local")}))))
(is (=? (=?/malli host-and-keystore-id)
- (json/decode (:details (t2/select-one db-table db-id)) keyword))
+ (json/decode (:details (t2/select-one db-table :id db-id)) keyword))
"Database value")
(is (=? (=?/malli expected-path-response)
(:details (mt/user-http-request :crowberto :get 200 (format "database/%d" db-id))))
@@ -591,7 +591,7 @@
:keystore-value secret-key
:keystore-options "uploaded")}))))
(is (=? (=?/malli host-and-keystore-id)
- (json/decode (:details (t2/select-one db-table db-id)) keyword))
+ (json/decode (:details (t2/select-one db-table :id db-id)) keyword))
"Database value")
(is (=? (=?/malli (conj host-and-keystore-id
[:keystore-value [:enum secret/protected-password]]
@@ -689,7 +689,7 @@
:version 1
:value "new-password"})
(testing " updating the value works as expected"
- (t2/update! :model/Database id {:details (assoc details :password-path "/path/to/my/password-file")})
+ (t2/update! :model/Database :id id {:details (assoc details :password-path "/path/to/my/password-file")})
(check-db-fn (t2/select-one :model/Database :id id) {:kind :password
:source :file-path
:version 2
@@ -710,7 +710,7 @@
(let [db-id (:id db)
raw-write-details (t2/select-one-fn
(comp json/decode+kw :write_data_details)
- (t2/table-name :model/Database) db-id)]
+ (t2/table-name :model/Database) :id db-id)]
(testing "keystore-value replaced with keystore-id"
(is (contains? raw-write-details :keystore-id))
(is (not (contains? raw-write-details :keystore-value))))
@@ -725,10 +725,10 @@
:name "Secret Test"
:details {:host "localhost"}}]
(let [db-id (:id db)]
- (t2/update! :model/Database db-id {:write_data_details {:keystore-value "write-secret"}})
+ (t2/update! :model/Database :id db-id {:write_data_details {:keystore-value "write-secret"}})
(let [raw-write-details (t2/select-one-fn
(comp json/decode+kw :write_data_details)
- (t2/table-name :model/Database) db-id)]
+ (t2/table-name :model/Database) :id db-id)]
(testing "keystore-value replaced with keystore-id"
(is (contains? raw-write-details :keystore-id))
(is (not (contains? raw-write-details :keystore-value))))
@@ -777,7 +777,7 @@
:details (json/encode {:host "localhost"})
:write_data_details (json/encode {:keystore-value "should-be-cleaned"
:keystore-id 999})}]
- (let [db (t2/select-one :model/Database db-id)]
+ (let [db (t2/select-one :model/Database :id db-id)]
(testing "keystore-value cleaned from write_data_details"
(is (not (contains? (:write_data_details db) :keystore-value)))))))))
@@ -787,7 +787,7 @@
:name "Auth Provider Test"
:details {:auth-provider "aws-iam"}
:write_data_details {:auth-provider "aws-iam"}}]
- (let [db (t2/select-one :model/Database (:id db))]
+ (let [db (t2/select-one :model/Database :id (:id db))]
(testing ":details :auth-provider is keywordized"
(is (keyword? (get-in db [:details :auth-provider]))))
(testing ":write_data_details :auth-provider is keywordized"
@@ -813,7 +813,7 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"private or internal network address"
- (t2/update! :model/Database (:id db) {:engine (u/qualified-name ::alternate-details-driver)}))))))
+ (t2/update! :model/Database :id (:id db) {:engine (u/qualified-name ::alternate-details-driver)}))))))
(deftest overlay-details-are-validated-the-way-they-are-resolved-test
;; `:write_data_details` is merged onto `:details` by
@@ -823,12 +823,12 @@
(mt/with-temp [:model/Database db {:engine (u/qualified-name ::host-details-driver)
:details {:host "8.8.8.8"}}]
(testing "an overlay carrying only credentials inherits the host it will be merged with"
- (is (pos? (t2/update! :model/Database (:id db) {:write_data_details {:user "hummingbird"}}))))
+ (is (pos? (t2/update! :model/Database :id (:id db) {:write_data_details {:user "hummingbird"}}))))
(testing "an overlay that repoints the connection at an internal address is refused"
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"private or internal network address"
- (t2/update! :model/Database (:id db) {:write_data_details {:host "127.0.0.1" :user "hummingbird"}})))))))
+ (t2/update! :model/Database :id (:id db) {:write_data_details {:host "127.0.0.1" :user "hummingbird"}})))))))
(deftest disallowed-connection-parameters-are-refused-on-save-test
;; like the network policy, enforced on the model so serialization import and config-file provisioning -- which
@@ -844,24 +844,24 @@
(mt/with-temp [:model/Database db {:engine :postgres :details {:host "db.example.com"}}]
(is (thrown-with-msg?
clojure.lang.ExceptionInfo #"dangerous"
- (t2/update! :model/Database (:id db) {:details {:host "db.example.com" :sslfactory "a.b.C"}})))))
+ (t2/update! :model/Database :id (:id db) {:details {:host "db.example.com" :sslfactory "a.b.C"}})))))
(testing "a database whose driver isn't registered (e.g. an uninstalled plugin) can still be saved"
(mt/with-temp [:model/Database db {:engine "not-a-registered-driver" :details {:host "db.example.com"}}]
- (t2/update! :model/Database (:id db) {:details {:host "db2.example.com"}})
+ (t2/update! :model/Database :id (:id db) {:details {:host "db2.example.com"}})
(is (=? {:details {:host "db2.example.com"}}
- (t2/select-one :model/Database (:id db)))))))
+ (t2/select-one :model/Database :id (:id db)))))))
(deftest empty-details-are-not-subject-to-the-network-policy-test
(mt/with-temp-env-var-value! [mb-warehouse-allowed-networks "external-only"]
(testing "a database with empty details can be created"
(mt/with-temp [:model/Database db {:engine :h2, :details {}}]
(testing "and its engine changed, the way installing analytics flips the audit db's"
- (is (pos? (t2/update! :model/Database (:id db) {:engine "postgres"}))))
+ (is (pos? (t2/update! :model/Database :id (:id db) {:engine "postgres"}))))
(testing "but giving it an internal address is refused"
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"private or internal network address"
- (t2/update! :model/Database (:id db) {:details {:host "127.0.0.1"}}))))))))
+ (t2/update! :model/Database :id (:id db) {:details {:host "127.0.0.1"}}))))))))
(deftest attached-dwh-relaxes-the-network-policy-test
(mt/with-temp-env-var-value! [mb-warehouse-allowed-networks "external-only"]
@@ -873,7 +873,7 @@
:is_attached_dwh true
:details {:host "10.224.7.141"}}]
(testing "and updated"
- (is (pos? (t2/update! :model/Database (:id db) {:details {:host "10.224.7.142"}})))))))
+ (is (pos? (t2/update! :model/Database :id (:id db) {:details {:host "10.224.7.142"}})))))))
(testing "loopback and link-local stay blocked even for the attached DWH"
(doseq [host ["127.0.0.1" "169.254.169.254"]]
(is (thrown-with-msg?
@@ -1250,8 +1250,8 @@
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"router_database_id"
- (t2/update! :model/Database normal-id {:router_database_id router-id})))))
+ (t2/update! :model/Database :id normal-id {:router_database_id router-id})))))
(testing "a no-op update that does not touch router_database_id is allowed (destination can still be edited)"
(mt/with-temp [:model/Database {router-id :id} {}
:model/Database {dest-id :id} {:router_database_id router-id}]
- (is (t2/update! :model/Database dest-id {:name "renamed-destination"})))))
+ (is (t2/update! :model/Database :id dest-id {:name "renamed-destination"})))))
diff --git a/test/metabase/warehouses_rest/api_test.clj b/test/metabase/warehouses_rest/api_test.clj
index 101af719777..693a8d11b8c 100644
--- a/test/metabase/warehouses_rest/api_test.clj
+++ b/test/metabase/warehouses_rest/api_test.clj
@@ -419,7 +419,7 @@
{:name (mt/random-name)
:engine (u/qualified-name ::test-driver)
:details {:db "my_db"}}))
- db (t2/select-one :model/Database (:id resp))]
+ db (t2/select-one :model/Database :id (:id resp))]
(is (malli= [:merge
(into [:map] (m/map-vals (fn [v] [:= {} v]) (mt/object-defaults :model/Database)))
[:map
@@ -795,7 +795,7 @@
(is (= {:message "H2 is not supported as a data warehouse"}
(update! db {:engine :h2})))
(is (= :postgres
- (t2/select-one-fn :engine :model/Database (u/the-id db))))))
+ (t2/select-one-fn :engine :model/Database :id (u/the-id db))))))
(mt/with-temp [:model/Database db {:name (mt/random-name)
:details (:details (mt/db))
:engine :h2}]
@@ -803,7 +803,7 @@
(is (= {:message "H2 is not supported as a data warehouse"}
(update! db {:details {:db "mem:test-data;USER=GUEST;PASSWORD=guest;WHATEVER=true"}})))
(is (= (:details db)
- (t2/select-one-fn :details :model/Database (u/the-id db)))))))))
+ (t2/select-one-fn :details :model/Database :id (u/the-id db)))))))))
(deftest enable-model-actions-with-user-controlled-scheduling-test
(testing "Should be able to enable/disable actions for a database with user-controlled scheduling (metabase#30699)"
@@ -1116,7 +1116,7 @@
(deftest autocomplete-suggestions-honors-user-set-semantic-type-and-visibility-test
(testing "GET /api/database/:id/autocomplete_suggestions honors the user's semantic_type/visibility_type"
(let [field-id (mt/id :venues :price)
- base-type (t2/select-one-fn :base_type :model/Field field-id)
+ base-type (t2/select-one-fn :base_type :model/Field :id field-id)
venues-row (fn [] (first (filter (fn [[_ desc]] (str/starts-with? desc "VENUES "))
(mt/user-http-request :rasta :get 200
(format "database/%d/autocomplete_suggestions" (mt/id))
@@ -1656,7 +1656,7 @@
:cache_field_values schedule-map-for-last-friday-at-11pm}
:is_on_demand false
:is_full_sync false})
- db (t2/select-one :model/Database (:id resp))]
+ db (t2/select-one :model/Database :id (:id resp))]
(is (= (u.cron/schedule-map->cron-string schedule-map-for-weekly)
(:metadata_sync_schedule db)))
(is (nil? (:cache_field_values_schedule db)))
@@ -1677,7 +1677,7 @@
:cache_field_values schedule-map-for-last-friday-at-11pm}
:is_on_demand true
:is_full_sync false})
- db (t2/select-one :model/Database (:id resp))]
+ db (t2/select-one :model/Database :id (:id resp))]
(is (= (u.cron/schedule-map->cron-string schedule-map-for-weekly)
(:metadata_sync_schedule db)))
(is (nil? (:cache_field_values_schedule db)))
@@ -1709,7 +1709,7 @@
:is_on_demand false})
(is (= (task.sync-databases-test/all-db-sync-triggers-name db)
(task.sync-databases-test/query-all-db-sync-triggers-name db)))
- (let [db (t2/select-one :model/Database (:id db))]
+ (let [db (t2/select-one :model/Database :id (:id db))]
(is (= (u.cron/schedule-map->cron-string schedule-map-for-weekly)
(:metadata_sync_schedule db)))
(is (= (u.cron/schedule-map->cron-string schedule-map-for-last-friday-at-11pm)
@@ -1723,7 +1723,7 @@
:is_on_demand false})
(is (= #{(sync-and-analyze-trigger-name db)}
(task.sync-databases-test/query-all-db-sync-triggers-name db)))
- (let [db (t2/select-one :model/Database (:id db))]
+ (let [db (t2/select-one :model/Database :id (:id db))]
(is (= (u.cron/schedule-map->cron-string schedule-map-for-weekly)
(:metadata_sync_schedule db)))
(is (nil? (:cache_field_values_schedule db)))))
@@ -1736,7 +1736,7 @@
:is_on_demand false})
(is (= (task.sync-databases-test/all-db-sync-triggers-name db)
(task.sync-databases-test/query-all-db-sync-triggers-name db)))
- (let [db (t2/select-one :model/Database (:id db))]
+ (let [db (t2/select-one :model/Database :id (:id db))]
;; make sure the new schedule is randomized, not from the payload
(is (not= (-> schedule-map-for-weekly u.cron/schedule-map->cron-string)
(:metadata_sync_schedule db)))
@@ -1763,7 +1763,7 @@
:is_on_demand false})
(is (= #{(sync-and-analyze-trigger-name db)}
(task.sync-databases-test/query-all-db-sync-triggers-name db)))
- (let [db (t2/select-one :model/Database (:id db))]
+ (let [db (t2/select-one :model/Database :id (:id db))]
(is (= (u.cron/schedule-map->cron-string schedule-map-for-weekly)
(:metadata_sync_schedule db)))
(is (nil? (:cache_field_values_schedule db)))))))))
@@ -1782,7 +1782,7 @@
:is_on_demand true})
(is (= #{(sync-and-analyze-trigger-name db)}
(task.sync-databases-test/query-all-db-sync-triggers-name db)))
- (let [db (t2/select-one :model/Database (:id db))]
+ (let [db (t2/select-one :model/Database :id (:id db))]
(is (= (u.cron/schedule-map->cron-string schedule-map-for-weekly)
(:metadata_sync_schedule db)))
(is (nil? (:cache_field_values_schedule db)))))))))
@@ -2021,16 +2021,16 @@
:model/Table table {:db_id (u/the-id db) :initial_sync_status "incomplete"}]
(mt/user-http-request :crowberto :post 200 (format "database/%d/dismiss_spinner" (u/the-id db)))
(testing "dismissed db spinner"
- (is (= "complete" (t2/select-one-fn :initial_sync_status :model/Database (:id db)))))
+ (is (= "complete" (t2/select-one-fn :initial_sync_status :model/Database :id (:id db)))))
(testing "dismissed table spinner"
- (is (= "complete" (t2/select-one-fn :initial_sync_status :model/Table (:id table))))))))
+ (is (= "complete" (t2/select-one-fn :initial_sync_status :model/Table :id (:id table))))))))
(deftest dismiss-spinner-test-2
(testing "can we dissmiss the spinner if db has no tables? (#30837)"
(mt/with-temp [:model/Database db {:engine "h2", :details (:details (mt/db)) :initial_sync_status "incomplete"}]
(mt/user-http-request :crowberto :post 200 (format "database/%d/dismiss_spinner" (u/the-id db)))
(testing "dismissed db spinner"
- (is (= "complete" (t2/select-one-fn :initial_sync_status :model/Database (:id db))))))))
+ (is (= "complete" (t2/select-one-fn :initial_sync_status :model/Database :id (:id db))))))))
(deftest ^:parallel non-admins-cant-trigger-sync
(testing "Non-admins should not be allowed to trigger sync"
diff --git a/test/metabase/xrays/api/automagic_dashboards_test.clj b/test/metabase/xrays/api/automagic_dashboards_test.clj
index 7e1ef03b426..bd48e8615f2 100644
--- a/test/metabase/xrays/api/automagic_dashboards_test.clj
+++ b/test/metabase/xrays/api/automagic_dashboards_test.clj
@@ -452,7 +452,7 @@
:pk-ref id-field-ref
:value-ref title-field-ref}]
;; need user metadata edits to find linked tables to an otherwise opaque native query
- (t2/update! :model/Card (:id model)
+ (t2/update! :model/Card :id (:id model)
{:result_metadata (annotating results-meta id-field-ref
#(assoc % :id id-field-id))})
(assert (= (-> (t2/select-one-fn :result_metadata :model/Card
diff --git a/test/metabase/xrays/automagic_dashboards/core_test.clj b/test/metabase/xrays/automagic_dashboards/core_test.clj
index 9c4f0a3dfae..6859cf02e34 100644
--- a/test/metabase/xrays/automagic_dashboards/core_test.clj
+++ b/test/metabase/xrays/automagic_dashboards/core_test.clj
@@ -176,7 +176,7 @@
:aggregation [[:count]]}})})
{:keys [entity source]} (#'magic/->root query)]
(is (= entity query))
- (is (= source (t2/select-one :model/Table (mt/id :orders)))))))))
+ (is (= source (t2/select-one :model/Table :id (mt/id :orders)))))))))
(defn- mbql5-segment-definition
"Create an MBQL5 segment definition"
@@ -194,7 +194,7 @@
:definition (mbql5-segment-definition (mt/id :venues) (mt/id :venues :price) 10)}]
(let [{:keys [entity source]} (#'magic/->root segment)]
(is (= entity segment))
- (is (= source (t2/select-one :model/Table (mt/id :venues)))))))))
+ (is (= source (t2/select-one :model/Table :id (mt/id :venues)))))))))
;;; ------------------- `automagic-analysis` -------------------
@@ -1219,7 +1219,7 @@
(mt/dataset test-data
(testing ""
(testing "A table with a more specific entity-type will match to more specific binding definitions."
- (let [table (t2/select-one :model/Table (mt/id :people))
+ (let [table (t2/select-one :model/Table :id (mt/id :people))
{{:keys [entity_type]} :source :as root} (#'magic/->root table)
base-context (#'magic/make-base-context root)
dimensions [{"Loc" {:field_type [:type/Location], :score 60}}
@@ -1288,7 +1288,7 @@
(testing "Ensure we have examples to understand the shape returned from bind-dimensions"
(mt/dataset test-data
(testing "Clearly demonstrate the mechanism of full dimension binding"
- (let [table (t2/select-one :model/Table (mt/id :people))
+ (let [table (t2/select-one :model/Table :id (mt/id :people))
{{:keys [entity_type]} :source :as root} (#'magic/->root table)
base-context (#'magic/make-base-context root)
dimensions [{"Loc" {:field_type [:type/Location], :score 60}}
@@ -1478,7 +1478,7 @@
:source-table $$products}]
:aggregation [[:avg $tax]]
:breakout [&Products.products.title]}))
- right (t2/select-one :model/Table (mt/id :orders))
+ right (t2/select-one :model/Table :id (mt/id :orders))
cell-query [:= [:field (mt/id :products :title)
{:base-type :type/Text :join-alias "Products"}]
"Intelligent Granite Hat"]
@@ -1528,7 +1528,7 @@
:breakout [[:expression "TestColumn"]
[:field (mt/id :orders :created_at)
{:temporal-unit :month}]]}})
- right (t2/select-one :model/Table (mt/id :orders))
+ right (t2/select-one :model/Table :id (mt/id :orders))
cell-query [:and
[:= [:expression "TestColumn"] 2]
[:= [:field (mt/id :orders :created_at)
diff --git a/test/metabase/xrays/automagic_dashboards/interesting_test.clj b/test/metabase/xrays/automagic_dashboards/interesting_test.clj
index 5b4e1b824e5..e43698430bc 100644
--- a/test/metabase/xrays/automagic_dashboards/interesting_test.clj
+++ b/test/metabase/xrays/automagic_dashboards/interesting_test.clj
@@ -511,7 +511,7 @@
(remove (fn [dimension] (= "Lat" (ffirst dimension))) dimensions))}
candidate-bindings)))))))
(testing "A table with a more specific entity-type will match to more specific binding definitions."
- (let [table (t2/select-one :model/Table (mt/id :people))
+ (let [table (t2/select-one :model/Table :id (mt/id :people))
{{:keys [entity_type]} :source :as root} (#'magic/->root table)
base-context (#'magic/make-base-context root)
dimensions [{"Loc" {:field_type [:type/Location], :score 60}}