diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index 8d087a329cd6f6e19ceec5e15525e5b9f7deee71..dc2016d70d90b48b0df8d563f27787522f6d4d6e 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -149,6 +149,7 @@ toucan.db/delete! {:message "Use t2/delete! instead of toucan.db/delete!"} toucan.db/insert! {:message "Use t2/insert-returning-instances! instead of toucan.db/insert!"} toucan.db/update! {:message "Use t2/update! instead of toucan.db/update!"} + toucan.db/update-where! {:message "Use t2/update! instead of toucan.db/update-where!"} toucan.db/query {:message "Use mdb.query/query instead of toucan.db/query"} toucan.db/count {:message "Use t2/count instead of toucan.db/count"} toucan.db/exists? {:message "Use t2/exists? instead of toucan.db/exists?"} diff --git a/enterprise/backend/src/metabase_enterprise/audit_app/api/user.clj b/enterprise/backend/src/metabase_enterprise/audit_app/api/user.clj index 46bf7f7faf6fe33eec26537dd4a823c97778bc8f..5e31dcf052c815a024b79627e3e6dc54ca175b33 100644 --- a/enterprise/backend/src/metabase_enterprise/audit_app/api/user.clj +++ b/enterprise/backend/src/metabase_enterprise/audit_app/api/user.clj @@ -6,7 +6,6 @@ [metabase.api.user :as api.user] [metabase.models.pulse :refer [Pulse]] [metabase.models.pulse-channel-recipient :refer [PulseChannelRecipient]] - [toucan.db :as db] [toucan2.core :as t2])) #_{:clj-kondo/ignore [:deprecated-var]} @@ -19,7 +18,7 @@ ;; Alerts/DashboardSubscriptions (t2/delete! PulseChannelRecipient :user_id id) ;; archive anything they created. - (db/update-where! Pulse {:creator_id id, :archived false} :archived true) + (t2/update! Pulse {:creator_id id, :archived false} {:archived true}) api/generic-204-no-content) (api/define-routes) diff --git a/enterprise/backend/test/metabase_enterprise/advanced_permissions/api/group_manager_test.clj b/enterprise/backend/test/metabase_enterprise/advanced_permissions/api/group_manager_test.clj index fa95fbbe1ec00237e72978e11839ae0437a8286f..eca5b3173e53407f3e058fb745aa3493e17fa0ed 100644 --- a/enterprise/backend/test/metabase_enterprise/advanced_permissions/api/group_manager_test.clj +++ b/enterprise/backend/test/metabase_enterprise/advanced_permissions/api/group_manager_test.clj @@ -10,7 +10,6 @@ [metabase.public-settings.premium-features-test :as premium-features-test] [metabase.test :as mt] [metabase.util :as u] - [toucan.db :as db] [toucan2.core :as t2])) (deftest permissions-group-apis-test @@ -38,9 +37,9 @@ [PermissionsGroup [{group-id :id} {:name "Test delete group"}] PermissionsGroupMembership [_ {:group_id group-id, :user_id user-id}]] (when group-manager? - (db/update-where! PermissionsGroupMembership {:user_id user-id - :group_id group-id} - :is_group_manager true)) + (t2/update! PermissionsGroupMembership {:user_id user-id + :group_id group-id} + {:is_group_manager true})) (mt/user-http-request user :delete status (format "permissions/group/%d" group-id))))))] @@ -69,9 +68,9 @@ (delete-group :crowberto 204 false)) (testing "succeed if users access group that they are manager of" - (db/update-where! PermissionsGroupMembership {:user_id (:id user) - :group_id (:id group)} - :is_group_manager true) + (t2/update! PermissionsGroupMembership {:user_id (:id user) + :group_id (:id group)} + {:is_group_manager true}) (testing "non-admin user can only view groups that are manager of" (is (= #{(:id group)} (set (map :id (get-groups user 200)))))) @@ -169,9 +168,9 @@ [group-2 {:name "New Group 2"} user-2 [group-2]] (testing "succeed if users access group that they are manager of" - (db/update-where! PermissionsGroupMembership {:user_id (:id user-2) - :group_id (:id group-2)} - :is_group_manager true) + (t2/update! PermissionsGroupMembership {:user_id (:id user-2) + :group_id (:id group-2)} + {:is_group_manager true}) (get-membership user-2 200) (add-membership user-2 200 group-2 false) (update-membership user-2 200 group-2 false) @@ -191,9 +190,9 @@ (testing "if advanced-permissions is enabled, " (premium-features-test/with-premium-features #{:advanced-permissions} (testing "succeed if users access group that they are manager of," - (db/update-where! PermissionsGroupMembership {:user_id (:id user) - :group_id (:id group)} - :is_group_manager true) + (t2/update! PermissionsGroupMembership {:user_id (:id user) + :group_id (:id group)} + {:is_group_manager true}) (testing "can set is_group_manager=true" (add-membership :crowberto 200 group true) (add-membership user 200 group true)) @@ -235,9 +234,9 @@ (get-users user 403) (get-users :crowberto 200)) (testing "succeed if users is a group manager and returns additional fields" - (db/update-where! PermissionsGroupMembership {:user_id (:id user) - :group_id (:id group)} - :is_group_manager true) + (t2/update! PermissionsGroupMembership {:user_id (:id user) + :group_id (:id group)} + {:is_group_manager true}) (is (subset? (set user/group-manager-visible-columns) (-> (:data (get-users user 200)) first @@ -291,9 +290,9 @@ (get-user :crowberto 200)) (testing "succeed if users is a group manager and returns additional fields" - (db/update-where! PermissionsGroupMembership {:user_id (:id user) - :group_id (:id group)} - :is_group_manager true) + (t2/update! PermissionsGroupMembership {:user_id (:id user) + :group_id (:id group)} + {:is_group_manager true}) (is (= [{:id (:id (perms-group/all-users)) :is_group_manager false}] (:user_group_memberships (get-user user 200))))))))))) @@ -349,9 +348,9 @@ (testing "if `advanced-permissions` is enabled" (premium-features-test/with-premium-features #{:advanced-permissions} (testing "Group Managers" - (db/update-where! PermissionsGroupMembership {:user_id (:id user) - :group_id (:id group)} - :is_group_manager true) + (t2/update! PermissionsGroupMembership {:user_id (:id user) + :group_id (:id group)} + {:is_group_manager true}) (testing "Can't edit users' info" (let [current-user-first-name (t2/select-one-fn :first_name User :id (:id user))] diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj index 1ac5c9092bca9bb570078bfdec7c8d564264a496..c80d320817007d0b17cdf7eaac6749b758f46d24 100644 --- a/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj +++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj @@ -15,7 +15,6 @@ [metabase.util :as u] [metabase.util.schema :as su] [schema.core :as s] - [toucan.db :as db] [toucan2.core :as t2])) (defn- db-graph-keypath [group] @@ -142,14 +141,14 @@ (defn- fake-persist-card! [card] (let [persisted-info (persisted-info/turn-on-model! (mt/user->id :rasta) card)] - (db/update-where! PersistedInfo {:card_id (u/the-id card)} - :definition (json/encode - (persisted-info/metadata->definition - (:result_metadata card) - (:table_name persisted-info))) - :active true - :state "persisted" - :query_hash (persisted-info/query-hash (:dataset_query card))))) + (t2/update! PersistedInfo {:card_id (u/the-id card)} + {:definition (json/encode + (persisted-info/metadata->definition + (:result_metadata card) + (:table_name persisted-info))) + :active true + :state "persisted" + :query_hash (persisted-info/query-hash (:dataset_query card))}))) (deftest persistence-and-permissions (mt/with-model-cleanup [PersistedInfo] diff --git a/enterprise/backend/test/metabase_enterprise/sso/integrations/saml_test.clj b/enterprise/backend/test/metabase_enterprise/sso/integrations/saml_test.clj index 3e3f524f56f70774fed4f01d4ad292b321422aca..f49f835d2b743187aa74d59a2f0cae3a7941014f 100644 --- a/enterprise/backend/test/metabase_enterprise/sso/integrations/saml_test.clj +++ b/enterprise/backend/test/metabase_enterprise/sso/integrations/saml_test.clj @@ -20,7 +20,6 @@ [ring.util.codec :as codec] [saml20-clj.core :as saml] [saml20-clj.encode-decode :as encode-decode] - [toucan.db :as db] [toucan2.core :as t2]) (:import (java.net URL) @@ -142,8 +141,8 @@ (try (f) (finally - (u/ignore-exceptions (do (db/update-where! User {} :login_attributes nil) - (db/update-where! User {:email "rasta@metabase.com"} :first_name "Rasta" :last_name "Toucan" :sso_source nil)))))) + (u/ignore-exceptions (do (t2/update! User {} {:login_attributes nil}) + (t2/update! User {:email "rasta@metabase.com"} {:first_name "Rasta" :last_name "Toucan" :sso_source nil})))))) (defmacro ^:private with-saml-default-setup [& body] `(with-valid-premium-features-token diff --git a/src/metabase/api/card.clj b/src/metabase/api/card.clj index 46021b86d2043876c63370c87944e4e017fbbf4a..453e80d32945977f8198c114cbd0d2d470e5cc1c 100644 --- a/src/metabase/api/card.clj +++ b/src/metabase/api/card.clj @@ -53,7 +53,6 @@ [metabase.util.malli.schema :as ms] [metabase.util.schema :as su] [schema.core :as s] - [toucan.db :as db] [toucan.hydrate :refer [hydrate]] [toucan2.core :as t2]) (:import @@ -697,7 +696,8 @@ saved later when it is ready." (api/reconcile-position-for-collection! collection_id collection_position nil) ;; Now we can update the card with the new collection and a new calculated position ;; that appended to the end - (t2/update! Card (u/the-id card) + (t2/update! Card + (u/the-id card) {:collection_position idx :collection_id new-collection-id-or-nil})) ;; These are reversed because of the classic issue when removing an item from array. If we remove an @@ -738,8 +738,9 @@ saved later when it is ready." (when-let [cards-without-position (seq (for [card cards :when (not (:collection_position card))] (u/the-id card)))] - (db/update-where! Card {:id [:in (set cards-without-position)]} - :collection_id new-collection-id-or-nil)))))) + (t2/update! (t2/table-name Card) + {:id [:in (set cards-without-position)]} + {:collection_id new-collection-id-or-nil})))))) #_{:clj-kondo/ignore [:deprecated-var]} (api/defendpoint-schema POST "/collections" diff --git a/src/metabase/api/common.clj b/src/metabase/api/common.clj index 4ea2e31aa50464a62de6d8f3f32400fbc310ad36..497cc622e95063f539b58df42e23da3f56413751 100644 --- a/src/metabase/api/common.clj +++ b/src/metabase/api/common.clj @@ -24,7 +24,6 @@ [metabase.util.log :as log] [metabase.util.schema :as su] [schema.core :as schema] - [toucan.db :as db] [toucan2.core :as t2])) (declare check-403 check-404) @@ -543,9 +542,9 @@ new-position :- (schema/maybe su/IntGreaterThanZero)] (let [update-fn! (fn [plus-or-minus position-update-clause] (doseq [model '[Card Dashboard Pulse]] - (db/update-where! model {:collection_id collection-id - :collection_position position-update-clause} - :collection_position [plus-or-minus :collection_position 1])))] + (t2/update! model {:collection_id collection-id + :collection_position position-update-clause} + {:collection_position [plus-or-minus :collection_position 1]})))] (when (not= new-position old-position) (cond (and (nil? new-position) diff --git a/src/metabase/api/database.clj b/src/metabase/api/database.clj index 9a2f124790e5de7656cc75dfe6d3ca8ce7c5a80e..81e4be808594a6bbabc23ea328d2d781f9cd7956 100644 --- a/src/metabase/api/database.clj +++ b/src/metabase/api/database.clj @@ -997,7 +997,7 @@ tables (map api/write-check (:tables (first (add-tables [db]))))] (sync-util/set-initial-database-sync-complete! db) ;; avoid n+1 - (db/update-where! Table {:id [:in (map :id tables)]} :initial_sync_status "complete")) + (t2/update! Table {:id [:in (map :id tables)]} {:initial_sync_status "complete"})) {:status :ok}) ;; TODO - do we also want an endpoint to manually trigger analysis. Or separate ones for classification/fingerprinting? diff --git a/src/metabase/api/timeline.clj b/src/metabase/api/timeline.clj index 64a5391e38673efdbc544ed1f5d783176d9b6222..1f9e6216b64fb8920a8ada8dc0d110c37bc60f32 100644 --- a/src/metabase/api/timeline.clj +++ b/src/metabase/api/timeline.clj @@ -12,7 +12,6 @@ [metabase.util.date-2 :as u.date] [metabase.util.schema :as su] [schema.core :as s] - [toucan.db :as db] [toucan.hydrate :refer [hydrate]] [toucan2.core :as t2])) @@ -99,7 +98,7 @@ :present #{:description :icon :collection_id :default :archived} :non-nil #{:name})) (when (and (some? archived) (not= current-archived archived)) - (db/update-where! TimelineEvent {:timeline_id id} :archived archived)) + (t2/update! TimelineEvent {:timeline_id id} {:archived archived})) (hydrate (t2/select-one Timeline :id id) :creator [:collection :can_write]))) #_{:clj-kondo/ignore [:deprecated-var]} diff --git a/src/metabase/models/collection.clj b/src/metabase/models/collection.clj index 96434df055deb133935336dea574022a4f90ead5..ec52e27e50791c107eac18d16263b715e87e64c4 100644 --- a/src/metabase/models/collection.clj +++ b/src/metabase/models/collection.clj @@ -626,13 +626,14 @@ (let [affected-collection-ids (cons (u/the-id collection) (collection->descendant-ids collection, :archived false))] (t2/with-transaction [_conn] - (db/update-where! Collection {:id [:in affected-collection-ids] - :archived false} - :archived true) + (t2/update! (t2/table-name Collection) + {:id [:in affected-collection-ids] + :archived false} + {:archived true}) (doseq [model '[Card Dashboard NativeQuerySnippet Pulse]] - (db/update-where! model {:collection_id [:in affected-collection-ids] - :archived false} - :archived true))))) + (t2/update! model {:collection_id [:in affected-collection-ids] + :archived false} + {:archived true}))))) (s/defn ^:private unarchive-collection! "Unarchive a Collection and its descendant Collections and their Cards, Dashboards, and Pulses." @@ -640,13 +641,14 @@ (let [affected-collection-ids (cons (u/the-id collection) (collection->descendant-ids collection, :archived true))] (t2/with-transaction [_conn] - (db/update-where! Collection {:id [:in affected-collection-ids] - :archived true} - :archived false) + (t2/update! (t2/table-name Collection) + {:id [:in affected-collection-ids] + :archived true} + {:archived false}) (doseq [model '[Card Dashboard NativeQuerySnippet Pulse]] - (db/update-where! model {:collection_id [:in affected-collection-ids] - :archived true} - :archived false))))) + (t2/update! model {:collection_id [:in affected-collection-ids] + :archived true} + {:archived false}))))) ;;; +----------------------------------------------------------------------------------------------------------------+ @@ -798,10 +800,10 @@ This needs to be done recursively for all descendants as well." [collection :- (mi/InstanceOf Collection)] (t2/query-one {:delete-from :permissions - :where [:in :object (for [collection (cons collection (descendants collection)) - path-fn [perms/collection-read-path - perms/collection-readwrite-path]] - (path-fn collection))]})) + :where [:in :object (for [collection (cons collection (descendants collection)) + path-fn [perms/collection-read-path + perms/collection-readwrite-path]] + (path-fn collection))]})) (defn- update-perms-when-moving-across-personal-boundry! "If a Collection is moving 'across the boundry' and will become a descendant of a Personal Collection, or will cease @@ -859,7 +861,7 @@ (update-perms-when-moving-across-personal-boundry! collection-before-updates collection-updates)) ;; (5) make sure hex color is valid (when (api/column-will-change? :color collection-before-updates collection-updates) - (assert-valid-hex-color color)) + (assert-valid-hex-color color)) ;; OK, AT THIS POINT THE CHANGES ARE VALIDATED. NOW START ISSUING UPDATES ;; (1) archive or unarchive as appropriate (maybe-archive-or-unarchive! collection-before-updates collection-updates) @@ -887,9 +889,9 @@ (throw (Exception. (tru "You cannot delete a Personal Collection!"))))) ;; Delete permissions records for this Collection (t2/query-one {:delete-from :permissions - :where [:or - [:= :object (perms/collection-readwrite-path collection)] - [:= :object (perms/collection-read-path collection)]]})) + :where [:or + [:= :object (perms/collection-readwrite-path collection)] + [:= :object (perms/collection-read-path collection)]]})) ;;; -------------------------------------------------- IModel Impl --------------------------------------------------- diff --git a/src/metabase/models/dashboard.clj b/src/metabase/models/dashboard.clj index 84dac81f2c17a1b5db367e90597a3e8dbf3bc1e7..b1514828585d7bcc45c35d6ed670d8cd3607d6b9 100644 --- a/src/metabase/models/dashboard.clj +++ b/src/metabase/models/dashboard.clj @@ -31,7 +31,6 @@ [metabase.util.log :as log] [metabase.util.schema :as su] [schema.core :as s] - [toucan.db :as db] [toucan.hydrate :refer [hydrate]] [toucan.models :as models] [toucan2.core :as t2])) @@ -136,9 +135,9 @@ :position position})] (t2/with-transaction [_conn] (binding [pulse/*allow-moving-dashboard-subscriptions* true] - (db/update-where! Pulse {:dashboard_id dashboard-id} - :name (:name dashboard) - :collection_id (:collection_id dashboard)) + (t2/update! Pulse {:dashboard_id dashboard-id} + {:name (:name dashboard) + :collection_id (:collection_id dashboard)}) (pulse-card/bulk-create! new-pulse-cards))))))) (defn- post-update diff --git a/src/metabase/models/moderation_review.clj b/src/metabase/models/moderation_review.clj index ef4bf59ed3e795b6f3782116bbadf8d69cb52ec4..573dfe69ca47fd7495e63ff7803509de278af8b7 100644 --- a/src/metabase/models/moderation_review.clj +++ b/src/metabase/models/moderation_review.clj @@ -8,7 +8,6 @@ [metabase.moderation :as moderation] [metabase.util.schema :as su] [schema.core :as s] - [toucan.db :as db] [toucan.models :as models] [toucan2.core :as t2])) @@ -73,7 +72,7 @@ (s/optional-key :text) (s/maybe s/Str)}] (t2/with-transaction [_conn] (delete-extra-reviews! (:moderated_item_id params) (:moderated_item_type params)) - (db/update-where! ModerationReview {:moderated_item_id (:moderated_item_id params) - :moderated_item_type (:moderated_item_type params)} - :most_recent false) + (t2/update! ModerationReview {:moderated_item_id (:moderated_item_id params) + :moderated_item_type (:moderated_item_type params)} + {:most_recent false}) (first (t2/insert-returning-instances! ModerationReview (assoc params :most_recent true))))) diff --git a/src/metabase/models/parameter_card.clj b/src/metabase/models/parameter_card.clj index 1c24c1a4ae37234d985e0bd48ac06d59f0e4a555..147ed89ed6c9643d433696d7fbb524926ff80d53 100644 --- a/src/metabase/models/parameter_card.clj +++ b/src/metabase/models/parameter_card.clj @@ -5,7 +5,6 @@ [metabase.util.i18n :refer [tru]] [metabase.util.malli :as mu] [metabase.util.malli.schema :as ms] - [toucan.db :as db] [toucan.models :as models] [toucan2.core :as t2])) @@ -30,7 +29,8 @@ (defn- pre-update [pc] (u/prog1 pc - (validate-parameterized-object-type pc))) + (when (:parameterized_object_type pc) + (validate-parameterized-object-type pc)))) (mi/define-methods ParameterCard @@ -60,7 +60,7 @@ conditions {:parameterized_object_id parameterized-object-id :parameterized_object_type parameterized-object-type :parameter_id id}] - (or (db/update-where! ParameterCard conditions :card_id card-id) + (or (pos? (t2/update! ParameterCard conditions {:card_id card-id})) (t2/insert! ParameterCard (merge conditions {:card_id card-id})))))) (mu/defn upsert-or-delete-from-parameters! diff --git a/src/metabase/models/persisted_info.clj b/src/metabase/models/persisted_info.clj index 29cfe2cb7f07b45dd325754053e0951bdcd33010..3fceaf6940b313fa6d6e5269cf38817086448dba 100644 --- a/src/metabase/models/persisted_info.clj +++ b/src/metabase/models/persisted_info.clj @@ -91,7 +91,7 @@ ([conditions-map] (mark-for-pruning! conditions-map "deletable")) ([conditions-map state] - (db/update-where! PersistedInfo conditions-map :active false, :state state, :state_change_at :%now))) + (t2/update! PersistedInfo conditions-map {:active false, :state state, :state_change_at :%now}))) (defn- create-row "Marks PersistedInfo as `creating`, these will at some point be persisted by the PersistRefresh task." diff --git a/src/metabase/models/query.clj b/src/metabase/models/query.clj index 9a6d60e7471fdf38ab1568a50e6928ea3496a081..3e07bf17297c0fa84a9234f56e6e395a57377fb5 100644 --- a/src/metabase/models/query.clj +++ b/src/metabase/models/query.clj @@ -7,7 +7,6 @@ [metabase.mbql.normalize :as mbql.normalize] [metabase.models.interface :as mi] [metabase.util.honey-sql-2 :as h2x] - [toucan.db :as db] [toucan.models :as models] [toucan2.core :as t2])) @@ -49,15 +48,15 @@ (or ;; if it DOES NOT have a query (yet) set that. In 0.31.0 we added the query.query column, and it gets set for all ;; new entries, so at some point in the future we can take this out, and save a DB call. - (db/update-where! Query + (pos? (t2/update! Query {:query_hash query-hash, :query nil} - :query (json/generate-string query) - :average_execution_time avg-execution-time) + {:query (json/generate-string query) + :average_execution_time avg-execution-time})) ;; if query is already set then just update average_execution_time. (We're doing this separate call to avoid ;; updating query on every single UPDATE) - (db/update-where! Query + (pos? (t2/update! Query {:query_hash query-hash} - :average_execution_time avg-execution-time)))) + {:average_execution_time avg-execution-time}))))) (defn- record-new-query-entry! "Record a query and its execution time for a `query` with `query-hash` that's not already present in the DB. diff --git a/src/metabase/models/secret.clj b/src/metabase/models/secret.clj index 658320358f40e03a5aa73b2582c4a1a7b8820cde..289e7a55d404caba4cce3606830b9cf47456ca32 100644 --- a/src/metabase/models/secret.clj +++ b/src/metabase/models/secret.clj @@ -13,7 +13,6 @@ [metabase.util.i18n :refer [tru]] [metabase.util.log :as log] [methodical.core :as methodical] - [toucan.db :as db] [toucan.models :as models] [toucan2.core :as t2]) (:import @@ -243,8 +242,8 @@ latest-version (when existing-id (latest-for-id existing-id))] (if latest-version (if (= (select-keys latest-version bump-version-keys) [kind src value]) - (db/update-where! Secret {:id existing-id :version (:version latest-version)} - :name nm) + (pos? (t2/update! Secret {:id existing-id :version (:version latest-version)} + {:name nm})) (insert-new (u/the-id latest-version) (inc (:version latest-version)))) (insert-new nil 1)))) diff --git a/src/metabase/models/setting/cache.clj b/src/metabase/models/setting/cache.clj index e3f96d453e800ea79a8b4d31e536253087db9704..6213556d0011570f74c8f738de1cc58ed0d60339 100644 --- a/src/metabase/models/setting/cache.clj +++ b/src/metabase/models/setting/cache.clj @@ -9,7 +9,6 @@ [metabase.util.honey-sql-2 :as h2x] [metabase.util.i18n :refer [trs]] [metabase.util.log :as log] - [toucan.db :as db] [toucan2.core :as t2]) (:import (java.util.concurrent.locks ReentrantLock))) @@ -76,8 +75,8 @@ ;; for MySQL, cast(current_timestamp AS char); for H2 & Postgres, cast(current_timestamp AS text) (let [current-timestamp-as-string-honeysql (h2x/cast (if (= (mdb.connection/db-type) :mysql) :char :text) [:raw "current_timestamp"])] - ;; attempt to UPDATE the existing row. If no row exists, `update-where!` will return false... - (or (db/update-where! 'Setting {:key settings-last-updated-key} :value current-timestamp-as-string-honeysql) + ;; attempt to UPDATE the existing row. If no row exists, `t2/update!` will return 0... + (or (pos? (t2/update! :setting {:key settings-last-updated-key} {:value current-timestamp-as-string-honeysql})) ;; ...at which point we will try to INSERT a new row. Note that it is entirely possible two instances can both ;; try to INSERT it at the same time; one instance would fail because it would violate the PK constraint on ;; `key`, and throw a SQLException. As long as one instance updates the value, we are fine, so we can go ahead diff --git a/src/metabase/query_processor/middleware/cache_backend/db.clj b/src/metabase/query_processor/middleware/cache_backend/db.clj index a005b7b034145aa245aeed1203b049ac1553d668..27a87affa5575ef919d76a1c63868c4ff85922e9 100644 --- a/src/metabase/query_processor/middleware/cache_backend/db.clj +++ b/src/metabase/query_processor/middleware/cache_backend/db.clj @@ -88,9 +88,9 @@ [^bytes query-hash ^bytes results] (log/debug (trs "Caching results for query with hash {0}." (pr-str (i/short-hex-hash query-hash)))) (try - (or (db/update-where! QueryCache {:query_hash query-hash} - :updated_at (t/offset-date-time) - :results results) + (or (pos? (t2/update! QueryCache {:query_hash query-hash} + {:updated_at (t/offset-date-time) + :results results})) (first (t2/insert-returning-instances! QueryCache :updated_at (t/offset-date-time) :query_hash query-hash diff --git a/src/metabase/sync/analyze.clj b/src/metabase/sync/analyze.clj index 44233ce73da8db5c554eb1e2493a20a575debace..db6ee5bcf3e3b12b92e821c7a5b951395bb61284 100644 --- a/src/metabase/sync/analyze.clj +++ b/src/metabase/sync/analyze.clj @@ -13,7 +13,7 @@ [metabase.util.i18n :refer [trs]] [metabase.util.log :as log] [schema.core :as s] - [toucan.db :as db])) + [toucan2.core :as t2])) ;; How does analysis decide which Fields should get analyzed? ;; @@ -57,10 +57,10 @@ [tables :- [i/TableInstance]] (when-let [ids (seq (map u/the-id tables))] ;; The WHERE portion of this query should match up with that of `classify/fields-to-classify` - (db/update-where! Field {:table_id [:in ids] - :fingerprint_version i/latest-fingerprint-version - :last_analyzed nil} - :last_analyzed :%now))) + (t2/update! Field {:table_id [:in ids] + :fingerprint_version i/latest-fingerprint-version + :last_analyzed nil} + {:last_analyzed :%now}))) (s/defn ^:private update-fields-last-analyzed! "Update the `last_analyzed` date for all the recently re-fingerprinted/re-classified Fields in TABLE." diff --git a/src/metabase/sync/sync_metadata/fields/sync_instances.clj b/src/metabase/sync/sync_metadata/fields/sync_instances.clj index 4011127a5d36c0d1616f76fa9951728bb0ab861a..837e553780200374687f265f503fafe008201381 100644 --- a/src/metabase/sync/sync_metadata/fields/sync_instances.clj +++ b/src/metabase/sync/sync_metadata/fields/sync_instances.clj @@ -81,8 +81,8 @@ (let [fields-to-reactivate (matching-inactive-fields table new-field-metadatas parent-id)] ;; if the fields already exist but were just marked inactive then reäctivate them (when (seq fields-to-reactivate) - (db/update-where! Field {:id [:in (map u/the-id fields-to-reactivate)]} - :active true)) + (t2/update! Field {:id [:in (map u/the-id fields-to-reactivate)]} + {:active true})) (let [reactivated? (comp (set (map common/canonical-name fields-to-reactivate)) common/canonical-name) ;; If we reactivated the fields, no need to insert them; insert new rows for any that weren't reactivated diff --git a/src/metabase/sync/sync_metadata/metabase_metadata.clj b/src/metabase/sync/sync_metadata/metabase_metadata.clj index ac4439a862941bebabdb6d7328f695ab8bf6a942..5952a4bf694dda5f6de53ef3eb49e75799d84eaa 100644 --- a/src/metabase/sync/sync_metadata/metabase_metadata.clj +++ b/src/metabase/sync/sync_metadata/metabase_metadata.clj @@ -19,7 +19,6 @@ [metabase.util.log :as log] [metabase.util.schema :as su] [schema.core :as s] - [toucan.db :as db] [toucan2.core :as t2])) (def ^:private KeypathComponents @@ -44,19 +43,19 @@ "Set a property for a Field or Table in DATABASE. Returns `true` if a property was successfully set." [database :- i/DatabaseInstance, {:keys [table-name field-name k]} :- KeypathComponents, value] (boolean - ;; ignore legacy entries that try to set field_type since it's no longer part of Field - (when-not (= k :field_type) - ;; fetch the corresponding Table, then set the Table or Field property - (if table-name - (when-let [table-id (t2/select-one-pk Table - ;; TODO: this needs to support schemas - :db_id (u/the-id database) - :name table-name - :active true)] - (if field-name - (db/update-where! Field {:name field-name, :table_id table-id} k value) - (t2/update! Table table-id {k value}))) - (t2/update! Database (u/the-id database) {k value}))))) + ;; ignore legacy entries that try to set field_type since it's no longer part of Field + (when-not (= k :field_type) + ;; fetch the corresponding Table, then set the Table or Field property + (if table-name + (when-let [table-id (t2/select-one-pk Table + ;; TODO: this needs to support schemas + :db_id (u/the-id database) + :name table-name + :active true)] + (if field-name + (pos? (t2/update! Field {:name field-name, :table_id table-id} {k value})) + (pos? (t2/update! Table table-id {k value})))) + (pos? (t2/update! Database (u/the-id database) {k value})))))) (s/defn ^:private sync-metabase-metadata-table! "Databases may include a table named `_metabase_metadata` (case-insentive) which includes descriptions or other diff --git a/src/metabase/sync/sync_metadata/tables.clj b/src/metabase/sync/sync_metadata/tables.clj index 99fc07cf56ed9d8023abad325aa37ecb67e8b620..3a9e5efe7d3643114ac75ba516c5a4cc3f1fab53 100644 --- a/src/metabase/sync/sync_metadata/tables.clj +++ b/src/metabase/sync/sync_metadata/tables.clj @@ -17,7 +17,6 @@ [metabase.util.i18n :refer [trs]] [metabase.util.log :as log] [schema.core :as s] - [toucan.db :as db] [toucan2.core :as t2])) ;;; ------------------------------------------------ "Crufty" Tables ------------------------------------------------- @@ -136,11 +135,11 @@ (for [table old-tables] (sync-util/name-for-logging (mi/instance Table table)))) (doseq [{schema :schema, table-name :name, :as _table} old-tables] - (db/update-where! Table {:db_id (u/the-id database) - :schema schema - :name table-name - :active true} - :active false))) + (t2/update! Table {:db_id (u/the-id database) + :schema schema + :name table-name + :active true} + {:active false}))) (s/defn ^:private update-table-description! @@ -151,11 +150,11 @@ (sync-util/name-for-logging (mi/instance Table table)))) (doseq [{schema :schema, table-name :name, description :description} changed-tables] (when-not (str/blank? description) - (db/update-where! Table {:db_id (u/the-id database) - :schema schema - :name table-name - :description nil} - :description description)))) + (t2/update! Table {:db_id (u/the-id database) + :schema schema + :name table-name + :description nil} + {:description description})))) (s/defn ^:private table-set :- #{i/DatabaseMetadataTable} diff --git a/test/metabase/analytics/snowplow_test.clj b/test/metabase/analytics/snowplow_test.clj index 06fb550e85111e98485607daf8d83e026ed3b72d..031734a4dc11fe7998b3c4f3da3a060e8f049221 100644 --- a/test/metabase/analytics/snowplow_test.clj +++ b/test/metabase/analytics/snowplow_test.clj @@ -10,7 +10,6 @@ [metabase.test.fixtures :as fixtures] [metabase.util :as u] [metabase.util.date-2 :as u.date] - [toucan.db :as db] [toucan2.core :as t2]) (:import (java.util LinkedHashMap))) @@ -189,4 +188,4 @@ instance-creation))))) (finally (when original-value - (db/update-where! Setting {:key "instance-creation"} :value original-value)))))) + (t2/update! Setting {:key "instance-creation"} {:value original-value})))))) diff --git a/test/metabase/api/collection_test.clj b/test/metabase/api/collection_test.clj index c2c45787e61b6c6acbd293660ec0de2dc4207251..de4feb9ec60431610bdddc3278228b7bef5b0a73 100644 --- a/test/metabase/api/collection_test.clj +++ b/test/metabase/api/collection_test.clj @@ -35,7 +35,6 @@ [metabase.util :as u] [metabase.util.schema :as su] [schema.core :as s] - [toucan.db :as db] [toucan2.core :as t2] [toucan2.tools.with-temp :as t2.with-temp]) (:import @@ -601,7 +600,7 @@ (mt/with-temp Collection [collection {:name "Art Collection"}] (perms/grant-collection-read-permissions! (perms-group/all-users) collection) (with-some-children-of-collection collection - (db/update-where! Dashboard {:collection_id (u/the-id collection)} :archived true) + (t2/update! Dashboard {:collection_id (u/the-id collection)} {:archived true}) (is (= [(default-item {:name "Dine & Dashboard", :description nil, :model "dashboard", :entity_id true})] (mt/boolean-ids-and-timestamps (:data (mt/user-http-request :rasta :get 200 (str "collection/" (u/the-id collection) "/items?archived=true"))))))))) @@ -625,8 +624,8 @@ ;; need different timestamps and Revision has a pre-update to throw as they aren't editable (t2/query-one {:update :revision ;; in the past - :set {:timestamp (.minusHours (ZonedDateTime/now (ZoneId/of "UTC")) 24)} - :where [:= :id (:id _revision1)]}) + :set {:timestamp (.minusHours (ZonedDateTime/now (ZoneId/of "UTC")) 24)} + :where [:= :id (:id _revision1)]}) (testing "Results include last edited information from the `Revision` table" (is (= [{:name "AA"} {:name "Card with history 1", @@ -719,14 +718,14 @@ (letfn [(at-year [year] (ZonedDateTime/of year 1 1 0 0 0 0 (ZoneId/of "UTC")))] (t2/query-one {:update :revision ;; in the past - :set {:timestamp (at-year 2015)} - :where [:in :id (map :id [card-revision1 dash-revision1])]}) + :set {:timestamp (at-year 2015)} + :where [:in :id (map :id [card-revision1 dash-revision1])]}) ;; mark the later revisions with the user with name "pass". Note important that its the later revision by ;; id. Query assumes increasing timestamps with ids (t2/query-one {:update :revision - :set {:timestamp (at-year 2021) - :user_id passuser-id} - :where [:in :id (map :id [card-revision2 dash-revision2])]})) + :set {:timestamp (at-year 2021) + :user_id passuser-id} + :where [:in :id (map :id [card-revision2 dash-revision2])]})) (is (= ["pass" "pass"] (->> (mt/user-http-request :rasta :get 200 (str "collection/" collection-id "/items?models=dashboard&models=card")) :data diff --git a/test/metabase/api/dashboard_test.clj b/test/metabase/api/dashboard_test.clj index 998f0ff802083599111cd14f779145288b96cfd2..248818f1db9c67e8586355729c186ceed34a4cbf 100644 --- a/test/metabase/api/dashboard_test.clj +++ b/test/metabase/api/dashboard_test.clj @@ -48,7 +48,6 @@ [metabase.util :as u] [ring.util.codec :as codec] [schema.core :as s] - [toucan.db :as db] [toucan2.core :as t2] [toucan2.protocols :as t2.protocols] [toucan2.tools.with-temp :as t2.with-temp]) @@ -2084,10 +2083,10 @@ (let [metadata (-> (qp/process-query (:dataset_query native-card)) :data :results_metadata :columns)] (is (seq metadata) "Did not get metadata") - (db/update-where! 'Card {:id model-id} - :result_metadata (json/generate-string - (assoc-in metadata [0 :id] - (mt/id :products :category))))) + (t2/update! 'Card {:id model-id} + {:result_metadata (json/generate-string + (assoc-in metadata [0 :id] + (mt/id :products :category)))})) ;; ...so instead we create a question on top of this model (note that ;; metadata must be present on the model) and use the question on the ;; dashboard. diff --git a/test/metabase/cmd/rotate_encryption_key_test.clj b/test/metabase/cmd/rotate_encryption_key_test.clj index 5e20388c849d7357e205a76eca1c25fe3fb72897..7b52b8ff17060671d3c55d966664ff82d7a901b2 100644 --- a/test/metabase/cmd/rotate_encryption_key_test.clj +++ b/test/metabase/cmd/rotate_encryption_key_test.clj @@ -20,7 +20,6 @@ [metabase.util.encryption-test :as encryption-test] [metabase.util.i18n :as i18n] [methodical.core :as methodical] - [toucan.db :as db] [toucan.models :as models] [toucan2.core :as t2]) (:import @@ -171,7 +170,7 @@ (testing "rotate-encryption-key! to nil decrypts the encrypted keys" (t2/update! Database 1 {:details "{\"db\":\"/tmp/test.db\"}"}) - (db/update-where! Database {:name "k3"} :details "{\"db\":\"/tmp/test.db\"}") + (t2/update! 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)) (is (= "unencrypted value" (raw-value "nocrypt"))) diff --git a/test/metabase/models/params/chain_filter_test.clj b/test/metabase/models/params/chain_filter_test.clj index 1e2efb5fa5e2d7e631b285c461c25aafbbead931..655aec311433ce46f34fabc08287b41ba5df69fb 100644 --- a/test/metabase/models/params/chain_filter_test.clj +++ b/test/metabase/models/params/chain_filter_test.clj @@ -499,20 +499,20 @@ (is (= 1 (t2/count FieldValues :field_id field-id :type "linked-filter")))) (testing "should search for the values of linked-filter FieldValues" - (db/update-where! FieldValues {:field_id field-id - :type "linked-filter"} - :values (json/generate-string ["Good" "Bad"]) - ;; HACK: currently this is hardcoded to true for linked-filter - ;; in [[params.field-values/fetch-advanced-field-values]] - ;; we want this to false to test this case - :has_more_values false) + (t2/update! FieldValues {:field_id field-id + :type "linked-filter"} + {:values (json/generate-string ["Good" "Bad"]) + ;; HACK: currently this is hardcoded to true for linked-filter + ;; in [[params.field-values/fetch-advanced-field-values]] + ;; we want this to false to test this case + :has_more_values false}) (is (= {:values ["Good"] :has_more_values false} (chain-filter-search categories.name {venues.price 4} "o"))) (testing "Shouldn't use cached FieldValues if has_more_values=true" - (db/update-where! FieldValues {:field_id field-id - :type "linked-filter"} - :has_more_values true) + (t2/update! FieldValues {:field_id field-id + :type "linked-filter"} + {:has_more_values true}) (is (= {:values ["Steakhouse"] :has_more_values false} (chain-filter-search categories.name {venues.price 4} "o")))))))))) diff --git a/test/metabase/models/setting/cache_test.clj b/test/metabase/models/setting/cache_test.clj index 204ee76335bf04db5a6f5ef89ad562004b8e945b..276ccad5e24a614d134dffa3b35ba68e3da9a5a5 100644 --- a/test/metabase/models/setting/cache_test.clj +++ b/test/metabase/models/setting/cache_test.clj @@ -8,7 +8,6 @@ [metabase.public-settings :as public-settings] [metabase.test :as mt] [metabase.test.fixtures :as fixtures] - [toucan.db :as db] [toucan2.core :as t2])) (set! *warn-on-reflection* true) @@ -27,17 +26,17 @@ "Simulate a different instance updating the value of `settings-last-updated` in the DB by updating its value without updating our locally cached value.." [] - (db/update-where! Setting {:key setting.cache/settings-last-updated-key} - :value [:raw (case (mdb/db-type) - ;; make it one second in the future so we don't end up getting an exact match when we try to test - ;; to see if things update below - :h2 "cast(dateadd('second', 1, current_timestamp) AS text)" - :mysql "cast((current_timestamp + interval 1 second) AS char)" - :postgres "cast((current_timestamp + interval '1 second') AS text)")])) + (t2/update! Setting {:key setting.cache/settings-last-updated-key} + {:value [:raw (case (mdb/db-type) + ;; make it one second in the future so we don't end up getting an exact match when we try to test + ;; to see if things update below + :h2 "cast(dateadd('second', 1, current_timestamp) AS text)" + :mysql "cast((current_timestamp + interval 1 second) AS char)" + :postgres "cast((current_timestamp + interval '1 second') AS text)")]})) (defn- simulate-another-instance-updating-setting! [setting-name new-value] (if new-value - (db/update-where! Setting {:key (name setting-name)} :value new-value) + (t2/update! Setting {:key (name setting-name)} {:value new-value}) (t2/delete! (t2/table-name Setting) {:key (name setting-name)})) (update-settings-last-updated-value-in-db!)) diff --git a/test/metabase/models/setting_test.clj b/test/metabase/models/setting_test.clj index 918617ebc90611e09535a1a7cd4bd338fe60bd24..1d73dbbf5b598f00af9f0a59bbc60158f49925a4 100644 --- a/test/metabase/models/setting_test.clj +++ b/test/metabase/models/setting_test.clj @@ -15,7 +15,6 @@ [metabase.util.encryption-test :as encryption-test] [metabase.util.i18n :as i18n :refer [deferred-tru]] [schema.core :as s] - [toucan.db :as db] [toucan2.core :as t2])) (use-fixtures :once (fixtures/initialize :db)) @@ -535,8 +534,8 @@ (testing "make sure that fetching the Setting always fetches the latest value from the DB" (uncached-setting! "ABCDEF") - (db/update-where! Setting {:key "uncached-setting"} - :value "123456") + (t2/update! Setting {:key "uncached-setting"} + {:value "123456"}) (is (= "123456" (uncached-setting)))) diff --git a/test/metabase/server/middleware/auth_test.clj b/test/metabase/server/middleware/auth_test.clj index b3f56f471fd9a0a7a5c116e920f46c3e8335cf45..e72d48374b3befab425c1056336cee252f9b592c 100644 --- a/test/metabase/server/middleware/auth_test.clj +++ b/test/metabase/server/middleware/auth_test.clj @@ -10,7 +10,6 @@ [metabase.test.data.users :as test.users] [metabase.test.fixtures :as fixtures] [ring.mock.request :as ring.mock] - [toucan.db :as db] [toucan2.core :as t2]) (:import (java.util UUID))) @@ -63,8 +62,8 @@ (try (t2/insert! Session {:id session-id :user_id (test.users/user->id :rasta)}) - (db/update-where! Session {:id session-id} - :created_at (t/instant 0)) + (t2/update! (t2/table-name Session) {:id session-id} + {:created_at (t/instant 0)}) (is (= mw.util/response-unauthentic (auth-enforced-handler (request-with-session-id session-id)))) (finally (t2/delete! Session :id session-id))))) diff --git a/test/metabase/server/middleware/session_test.clj b/test/metabase/server/middleware/session_test.clj index 5d43fc4648f2029bcf479d927f1ff3c76342fbab..b3412851415c79d2ee81fca525a9c27f47cd9022 100644 --- a/test/metabase/server/middleware/session_test.clj +++ b/test/metabase/server/middleware/session_test.clj @@ -19,7 +19,6 @@ [metabase.test :as mt] [metabase.util.i18n :as i18n] [ring.mock.request :as ring.mock] - [toucan.db :as db] [toucan2.core :as t2]) (:import (clojure.lang ExceptionInfo) @@ -251,8 +250,8 @@ (mt/with-user-in-groups [group-1 {:name "New Group 1"} group-2 {:name "New Group 2"} user [group-1 group-2]] - (db/update-where! PermissionsGroupMembership {:user_id (:id user), :group_id (:id group-2)} - :is_group_manager true) + (t2/update! PermissionsGroupMembership {:user_id (:id user), :group_id (:id group-2)} + {:is_group_manager true}) (t2/insert! Session {:id (str test-uuid) :user_id (:id user)}) (testing "is `false` if advanced-permisison is disabled" diff --git a/test/metabase/sync/analyze_test.clj b/test/metabase/sync/analyze_test.clj index 3cfdc17a86533f60293ea4b92977a6657eb38f85..86053681c0925da04a74a11c0c3dc9cd6e868d11 100644 --- a/test/metabase/sync/analyze_test.clj +++ b/test/metabase/sync/analyze_test.clj @@ -19,7 +19,6 @@ [metabase.test.data :as data] [metabase.test.sync :as test.sync :refer [sync-survives-crash?]] [metabase.util :as u] - [toucan.db :as db] [toucan.util.test :as tt] [toucan2.core :as t2])) @@ -27,10 +26,10 @@ (testing "Check that Fields do *not* get analyzed if they're not newly created and fingerprint version is current" (data/with-temp-copy-of-db ;; mark all the Fields as analyzed with so they won't be subject to analysis - (db/update-where! Field {:table_id (data/id :venues)} - :last_analyzed #t "2017-08-01T00:00" - :semantic_type nil - :fingerprint_version Short/MAX_VALUE) + (t2/update! Field {:table_id (data/id :venues)} + {:last_analyzed #t "2017-08-01T00:00" + :semantic_type nil + :fingerprint_version Short/MAX_VALUE}) ;; the type of the value that comes back may differ a bit between different application DBs (let [analysis-date (t2/select-one-fn :last_analyzed Field :table_id (data/id :venues))] ;; ok, NOW run the analysis process diff --git a/test/metabase/sync/sync_metadata/comments_test.clj b/test/metabase/sync/sync_metadata/comments_test.clj index 0e834f75dbf77538be19f177001cb62af3414dea..726537681cfff3b3f65c976436b9fdf72cccb937 100644 --- a/test/metabase/sync/sync_metadata/comments_test.clj +++ b/test/metabase/sync/sync_metadata/comments_test.clj @@ -10,7 +10,6 @@ [metabase.test :as mt] [metabase.test.data.interface :as tx] [metabase.util :as u] - [toucan.db :as db] [toucan2.core :as t2])) (defn- db->fields [db] @@ -44,7 +43,7 @@ (mt/dataset update-desc (mt/with-temp-copy-of-db ;; change the description in metabase while the source table comment remains the same - (db/update-where! Field {:id (mt/id "update_desc" "updated_desc")}, :description "updated description") + (t2/update! Field {:id (mt/id "update_desc" "updated_desc")}, {:description "updated description"}) ;; now sync the DB again, this should NOT overwrite the manually updated description (sync/sync-table! (t2/select-one Table :id (mt/id "update_desc"))) (is (= #{{:name (mt/format-name "id"), :description nil} @@ -103,10 +102,10 @@ (mt/dataset (basic-table "table_with_updated_desc" "table comment") (mt/with-temp-copy-of-db ;; change the description in metabase while the source table comment remains the same - (db/update-where! Table {:id (mt/id "table_with_updated_desc")}, :description "updated table description") + (t2/update! Table {:id (mt/id "table_with_updated_desc")} {:description "updated table description"}) ;; now sync the DB again, this should NOT overwrite the manually updated description (sync-tables/sync-tables-and-database! (mt/db)) - (is (= #{{:name (mt/format-name "table_with_updated_desc"), :description "updated table description"}} + (is (= #{{:name (mt/format-name "table_with_updated_desc") :description "updated table description"}} (db->tables (mt/db))))))))) (deftest sync-existing-table-comment-test diff --git a/test/metabase/sync/sync_metadata/sync_database_type_test.clj b/test/metabase/sync/sync_metadata/sync_database_type_test.clj index efafda5c957d90440c49559d9710a48715f75c72..f1af3275a78c45fa3bc11161611dddcef72f67e9 100644 --- a/test/metabase/sync/sync_metadata/sync_database_type_test.clj +++ b/test/metabase/sync/sync_metadata/sync_database_type_test.clj @@ -7,7 +7,6 @@ [metabase.sync.util-test :as sync.util-test] [metabase.test :as mt] [metabase.util :as u] - [toucan.db :as db] [toucan2.core :as t2])) (deftest update-database-type-test @@ -17,7 +16,7 @@ (let [venues-table (t2/select-one Table :db_id (u/the-id db), :display_name "Venues")] ;; ok, now give all the Fields `?` as their `database_type`. (This is what the DB migration does for existing ;; Fields) - (db/update-where! Field {:table_id (u/the-id venues-table)}, :database_type "?") + (t2/update! Field {:table_id (u/the-id venues-table)}, {:database_type "?"}) ;; now sync the DB again (let [{:keys [step-info task-history]} (sync.util-test/sync-database! "sync-fields" db)] (is (= {:total-fields 16, :updated-fields 6} @@ -40,7 +39,7 @@ (let [{new-step-info :step-info, new-task-history :task-history} (sync.util-test/sync-database! "sync-fields" db) venues-table (t2/select-one Table :db_id (u/the-id db), :display_name "Venues")] ;; ok, now give all the Fields `:type/*` as their `base_type` - (db/update-where! Field {:table_id (u/the-id venues-table)}, :base_type "type/*") + (t2/update! Field {:table_id (u/the-id venues-table)}, {:base_type "type/*"}) ;; now sync the DB again (let [{after-step-info :step-info, after-task-history :task-history} (sync.util-test/sync-database! "sync-fields" db)] (is (= {:updated-fields 16, :total-fields 16} diff --git a/test/metabase/test.clj b/test/metabase/test.clj index 379c818d7112c3b1393f979674909824eb56eaff..b681934beabcaa3f5b57ce90f29d304586cd9251 100644 --- a/test/metabase/test.clj +++ b/test/metabase/test.clj @@ -312,7 +312,7 @@ _ (t2/delete! (t2/table-name PermissionsGroupMembership) :group_id (:id (perms-group/admin))) existing-admin-ids (t2/select-pks-set User :is_superuser true) _ (when (seq existing-admin-ids) - (db/update-where! User {:id [:in existing-admin-ids]} :is_superuser false)) + (t2/update! (t2/table-name User) {:id [:in existing-admin-ids]} {:is_superuser false})) temp-admin (first (t2/insert-returning-instances! User (merge (with-temp-defaults User) attributes {:is_superuser true}))) @@ -322,7 +322,7 @@ (finally (t2/delete! User primary-key (primary-key temp-admin)) (when (seq existing-admin-ids) - (db/update-where! User {:id [:in existing-admin-ids]} :is_superuser true)) + (t2/update! (t2/table-name User) {:id [:in existing-admin-ids]} {:is_superuser true})) (db/insert-many! PermissionsGroupMembership existing-admin-memberships))))) (defmacro with-single-admin-user