Skip to content

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

Mark an existing Library synced when saving remote sync settings (#85813)

Alexander Polyankinbd1d685b4582
diff --git a/e2e/test/scenarios/data-studio/data-model/datamodel-data-studio.cy.spec.ts b/e2e/test/scenarios/data-studio/data-model/datamodel-data-studio.cy.spec.ts
index 9f96d6d9f04..d8e6eb3ba56 100644
--- a/e2e/test/scenarios/data-studio/data-model/datamodel-data-studio.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/data-model/datamodel-data-studio.cy.spec.ts
@@ -810,7 +810,12 @@ describe("scenarios > data studio > datamodel", () => {
H.createLibrary();
H.copySyncedLibraryFixture();
H.commitToRepo();
- H.configureGitAndPullChanges("read-write");
+ H.configureGit("read-write");
+ cy.request("POST", "/api/ee/remote-sync/import", {
+ expected_branch: "main",
+ force: true,
+ });
+ H.pollForTask({ taskName: "import" });
H.publishTables({ table_ids: [ORDERS_ID, PRODUCTS_ID] });
cy.request("POST", "/api/ee/remote-sync/export", { branch: "main" });
H.pollForTask({ taskName: "export" });
diff --git a/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj b/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj
index 47969331f24..363c07449da 100644
--- a/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/advanced_config/db.clj
@@ -76,7 +76,7 @@
(mu/defn database
"The Database with `database-id`, or nil."
[database-id :- ::lib.schema.id/database]
- (t2/select-one :model/Database database-id))
+ (t2/select-one :model/Database :id [:auto/param database-id]))
(mu/defn insert-database!
"Insert `database` and return the new instance."
diff --git a/enterprise/backend/src/metabase_enterprise/data_studio/db.clj b/enterprise/backend/src/metabase_enterprise/data_studio/db.clj
index 93d7f9829ab..0175e7c6d78 100644
--- a/enterprise/backend/src/metabase_enterprise/data_studio/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/data_studio/db.clj
@@ -89,7 +89,7 @@
(mu/defn collection
"The Collection with `collection-id`, or nil."
[collection-id :- ::lib.schema.id/collection]
- (t2/select-one :model/Collection collection-id))
+ (t2/select-one :model/Collection :id [:auto/param collection-id]))
(mu/defn latest-table-publishing-event
"The most recent publish or unpublish AuditLog event for `table-id`, or nil."
@@ -103,7 +103,7 @@
(mu/defn user-name-and-email
"The id, first name, last name, and email of the User with `user-id`, or nil."
[user-id :- ::lib.schema.id/user]
- (t2/select-one [:model/User :id :first_name :last_name :email] user-id))
+ (t2/select-one [:model/User :id :first_name :last_name :email] :id [:auto/param user-id]))
(mu/defn publish-tables!
"Publish the Tables with `table-ids` into the Collection with `collection-id`, returning the number updated."
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj
index ba4be3da383..0c1c7d5b0db 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj
@@ -16,6 +16,7 @@
[metabase.api.common :as api]
[metabase.api.macros :as api.macros]
[metabase.api.routes.common :refer [+auth]]
+ [metabase.collections.core :as collections]
[metabase.events.core :as events]
[metabase.settings.core :as setting]
[metabase.util.log :as log]
@@ -251,11 +252,22 @@
(throw (ex-info (impl/source-error-message e)
{:status-code 400} e))))))
+(defn- with-library-synced
+ "Adds the Library to `settings` collections as synced when they leave read-write sync on and custom collections are off."
+ [settings]
+ (let [library (collections/library-collection)]
+ (cond-> settings
+ (and library
+ (not (settings/remote-sync-custom-collections-enabled))
+ (= :read-write (get settings :remote-sync-type (settings/remote-sync-type)))
+ (not (str/blank? (get settings :remote-sync-url (settings/remote-sync-url)))))
+ (assoc-in [:collections (:id library)] true))))
+
(api.macros/defendpoint :put "/settings" :- remote-sync.schema/SettingsUpdateResponse
"Update Remote Sync related settings. You must be a superuser to do this."
[_route-params
_query-params
- {:keys [remote-sync-type collections] :as settings}
+ {:keys [remote-sync-type] :as settings}
:- [:map {:closed true}
[:remote-sync-url {:optional true} [:maybe :string]]
[:remote-sync-token {:optional true} [:maybe :string]]
@@ -283,7 +295,8 @@
(api/check-400 (not (and (remote-sync.object/dirty?) (= :read-only remote-sync-type)))
"There are unsaved changes in the Remote Sync collection which will be overwritten switching to read-only mode.")
;; Filter out no-op collection changes before checking read-only mode or running bulk-set
- (let [collections (when (seq collections)
+ (let [{:keys [collections] :as settings} (with-library-synced settings)
+ collections (when (seq collections)
(let [current-states (into {}
(map (juxt :id :is_remote_synced))
(remote-sync.db/collection-sync-states (keys collections)))]
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj
index c789f59b50c..49688a9c85c 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj
@@ -759,7 +759,7 @@
(mu/defn task
"The RemoteSyncTask with `task-id`, or nil."
[task-id :- ms/PositiveInt]
- (t2/select-one :model/RemoteSyncTask task-id))
+ (t2/select-one :model/RemoteSyncTask :id [:auto/param task-id]))
(mu/defn lock-task
"The RemoteSyncTask with `task-id`, locked for update, or nil."
diff --git a/enterprise/backend/src/metabase_enterprise/stale/db.clj b/enterprise/backend/src/metabase_enterprise/stale/db.clj
index 416f03a9020..17d0f1159dd 100644
--- a/enterprise/backend/src/metabase_enterprise/stale/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/stale/db.clj
@@ -10,7 +10,7 @@
(mu/defn collection
"The Collection with `collection-id`, or nil."
[collection-id :- ::lib.schema.id/collection]
- (t2/select-one :model/Collection collection-id))
+ (t2/select-one :model/Collection :id [:auto/param collection-id]))
(mu/defn collections-by-id
"A map of ID to Collection for `collection-ids`."
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 74156f519dc..08209b8d21a 100644
--- a/enterprise/backend/src/metabase_enterprise/support_access_grants/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/support_access_grants/db.clj
@@ -78,7 +78,7 @@
(mu/defn user
"The User with `user-id`, or nil."
[user-id :- ::lib.schema.id/user]
- (t2/select-one :model/User user-id))
+ (t2/select-one :model/User :id [:auto/param user-id]))
(mu/defn user-by-email
"The User with `email`, or nil."
diff --git a/enterprise/backend/src/metabase_enterprise/transforms_python/db.clj b/enterprise/backend/src/metabase_enterprise/transforms_python/db.clj
index 7b3220bf549..0e8ae858e6c 100644
--- a/enterprise/backend/src/metabase_enterprise/transforms_python/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/db.clj
@@ -22,7 +22,7 @@
(mu/defn database-engine
"The engine of the Database with `database-id`."
[database-id :- ::lib.schema.id/database]
- (t2/select-one-fn :engine :model/Database database-id))
+ (t2/select-one-fn :engine :model/Database :id [:auto/param database-id]))
(mu/defn update-run-message!
"Set the message of the TransformRun with `run-id`."
@@ -33,7 +33,7 @@
(mu/defn python-library
"The PythonLibrary with `library-id`, or nil."
[library-id :- ms/PositiveInt]
- (t2/select-one :model/PythonLibrary library-id))
+ (t2/select-one :model/PythonLibrary :id [:auto/param library-id]))
(mu/defn python-library-by-path
"The PythonLibrary at `path`, or nil."
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
index 482418b4430..041c79792f7 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
@@ -16,6 +16,7 @@
[metabase-enterprise.remote-sync.source.protocol :as source.p]
[metabase-enterprise.remote-sync.spec :as spec]
[metabase-enterprise.remote-sync.test-helpers :as test-helpers]
+ [metabase.collections.test-utils :as collections.tu]
[metabase.driver.settings :as driver.settings]
[metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.settings.core :as setting]
@@ -2292,6 +2293,68 @@
:collections {coll-id true}})
(is (false? (:is_remote_synced (t2/select-one :model/Collection :id coll-id)))))))))
+(defn- do-with-setup-redefs! [thunk]
+ (mt/with-dynamic-fn-redefs [settings/check-git-settings! (constantly nil)
+ source/source-from-settings (constantly (test-helpers/create-mock-source))]
+ (mt/with-temporary-setting-values [remote-sync-url nil
+ remote-sync-branch nil
+ remote-sync-type :read-only]
+ (collections.tu/with-library-not-synced
+ (collections.tu/with-library [{:keys [library data metrics]}]
+ (thunk (mapv :id [library data metrics])))))))
+
+(defn- synced-states [collection-ids]
+ (t2/select-fn-vec :is_remote_synced :model/Collection :id [:in collection-ids] {:order-by [:id]}))
+
+(deftest settings-syncs-existing-library-test
+ (testing "ENG-14338: setting up read-write sync marks an existing Library synced, and existing transforms are tracked"
+ (mt/with-temporary-setting-values [remote-sync-custom-collections-enabled false]
+ (mt/with-temp [:model/Transform {transform-id :id} {:name "Existing Transform"}]
+ (do-with-setup-redefs!
+ (fn [library-ids]
+ (mt/user-http-request :crowberto :put 200 "ee/remote-sync/settings"
+ {:remote-sync-url "https://github.com/test/repo.git"
+ :remote-sync-branch "main"
+ :remote-sync-type :read-write
+ :remote-sync-transforms true})
+ (is (= [true true true] (synced-states library-ids)))
+ (is (contains? (dirty-ids "transform") transform-id))))))))
+
+(deftest settings-syncs-library-when-asked-not-to-test
+ (testing "Without custom collections the Library is synced even when the request leaves it unsynced"
+ (mt/with-temporary-setting-values [remote-sync-custom-collections-enabled false]
+ (do-with-setup-redefs!
+ (fn [[library-id :as library-ids]]
+ (mt/user-http-request :crowberto :put 200 "ee/remote-sync/settings"
+ {:remote-sync-url "https://github.com/test/repo.git"
+ :remote-sync-branch "main"
+ :remote-sync-type :read-write
+ :collections {library-id false}})
+ (is (= [true true true] (synced-states library-ids))))))))
+
+(deftest settings-leaves-library-with-custom-collections-test
+ (testing "With custom collections the Library stays unsynced unless the request syncs it"
+ (mt/with-temporary-setting-values [remote-sync-custom-collections-enabled true]
+ (do-with-setup-redefs!
+ (fn [library-ids]
+ (mt/user-http-request :crowberto :put 200 "ee/remote-sync/settings"
+ {:remote-sync-url "https://github.com/test/repo.git"
+ :remote-sync-branch "main"
+ :remote-sync-type :read-write})
+ (is (= [false false false] (synced-states library-ids))))))))
+
+(deftest settings-disable-leaves-library-untracked-test
+ (testing "Disabling read-write sync doesn't mark the Library synced or track it on the way out"
+ (mt/with-temporary-setting-values [remote-sync-custom-collections-enabled false
+ remote-sync-url "https://github.com/test/repo.git"
+ remote-sync-branch "main"
+ remote-sync-type :read-write]
+ (collections.tu/with-library-not-synced
+ (collections.tu/with-library [{:keys [library]}]
+ (mt/user-http-request :crowberto :put 200 "ee/remote-sync/settings" {:remote-sync-url ""})
+ (is (false? (t2/select-one-fn :is_remote_synced :model/Collection :id (:id library))))
+ (is (not (t2/exists? :model/RemoteSyncObject :model_type "Collection" :model_id (:id library)))))))))
+
;; ---------- API-level guard sweep --------------------------------------------------------------
;;
;; Boundary tests verifying that every mutating remote-sync HTTP endpoint surfaces the guard's
diff --git a/src/metabase/actions/db.clj b/src/metabase/actions/db.clj
index 5fc811f89af..d2b873d33a6 100644
--- a/src/metabase/actions/db.clj
+++ b/src/metabase/actions/db.clj
@@ -125,7 +125,7 @@
(mu/defn dashcard-dashboard-id
"The `:dashboard_id` of the DashboardCard with `dashcard-id`, or nil."
[dashcard-id :- ::lib.schema.id/dashcard]
- (t2/select-one-fn :dashboard_id [:model/DashboardCard :dashboard_id] dashcard-id))
+ (t2/select-one-fn :dashboard_id [:model/DashboardCard :dashboard_id] :id [:auto/param dashcard-id]))
(mu/defn dashcard-action-id
"The Action id of the DashboardCard with `dashcard-id`, or nil."
@@ -260,7 +260,7 @@
(mu/defn dashboard-collection-id
"The Collection id of the Dashboard with `dashboard-id`, or nil."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one-fn :collection_id [:model/Dashboard :collection_id] dashboard-id))
+ (t2/select-one-fn :collection_id [:model/Dashboard :collection_id] :id [:auto/param dashboard-id]))
(mu/defn destination-database-exists-for-router?
"Whether the Database with `database-id` has routing destinations."
diff --git a/src/metabase/agent_api/db.clj b/src/metabase/agent_api/db.clj
index 6447b3f6c78..201ab7a3851 100644
--- a/src/metabase/agent_api/db.clj
+++ b/src/metabase/agent_api/db.clj
@@ -13,7 +13,7 @@
"The id, name, location, owner, namespace, and archival of the Collection with `collection-id`, or nil."
[collection-id :- ::lib.schema.id/collection]
(t2/select-one [:model/Collection :id :name :location :personal_owner_id :namespace :archived_directly]
- collection-id))
+ :id [:auto/param collection-id]))
(mu/defn card
"The Card with `card-id`, or nil."
diff --git a/src/metabase/api_keys/db.clj b/src/metabase/api_keys/db.clj
index 7ca92657153..01b7e97f5e1 100644
--- a/src/metabase/api_keys/db.clj
+++ b/src/metabase/api_keys/db.clj
@@ -31,7 +31,7 @@
(mu/defn api-key
"The ApiKey with `id`, or nil."
[id :- ms/PositiveInt]
- (t2/select-one :model/ApiKey id))
+ (t2/select-one :model/ApiKey :id [:auto/param id]))
(def ^:private ApiKeyWithGroupId
"An ApiKey instance possibly carrying the `::api-keys/group-id` the before-update hook consumes."
diff --git a/src/metabase/auth_identity/db.clj b/src/metabase/auth_identity/db.clj
index 31e41f0742a..5f4a1762f11 100644
--- a/src/metabase/auth_identity/db.clj
+++ b/src/metabase/auth_identity/db.clj
@@ -85,7 +85,7 @@
(mu/defn user
"The User with `user-id`, or nil."
[user-id :- ::lib.schema.id/user]
- (t2/select-one :model/User user-id))
+ (t2/select-one :model/User :id [:auto/param user-id]))
(mu/defn user-by-email
"The User whose email matches `email` case-insensitively, or nil."
diff --git a/src/metabase/cache/db.clj b/src/metabase/cache/db.clj
index 254e135a71b..7c95a71be0a 100644
--- a/src/metabase/cache/db.clj
+++ b/src/metabase/cache/db.clj
@@ -39,7 +39,7 @@
(mu/defn cache-config
"The CacheConfig with primary key `pk`, or nil."
[pk :- ms/PositiveInt]
- (t2/select-one :model/CacheConfig pk))
+ (t2/select-one :model/CacheConfig :id [:auto/param pk]))
(mu/defn root-ttl-cache-config
"The root TTL CacheConfig, or nil."
diff --git a/src/metabase/channel/db.clj b/src/metabase/channel/db.clj
index 8c8483ec742..26a61ac6f79 100644
--- a/src/metabase/channel/db.clj
+++ b/src/metabase/channel/db.clj
@@ -36,7 +36,7 @@
(mu/defn channel
"The Channel with `id`, or nil."
[id :- ms/PositiveInt]
- (t2/select-one :model/Channel id))
+ (t2/select-one :model/Channel :id [:auto/param id]))
(mu/defn update-channel!
"Apply `changes` to the Channel with `id`, returning the number updated."
diff --git a/src/metabase/dashboards_rest/db.clj b/src/metabase/dashboards_rest/db.clj
index 934285235d5..bb282a4e35c 100644
--- a/src/metabase/dashboards_rest/db.clj
+++ b/src/metabase/dashboards_rest/db.clj
@@ -29,12 +29,12 @@
(mu/defn dashboard-parameters
"The id and parameters of the Dashboard with `dashboard-id`, or nil."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one [:model/Dashboard :id :parameters] dashboard-id))
+ (t2/select-one [:model/Dashboard :id :parameters] :id [:auto/param dashboard-id]))
(mu/defn dashboard-name-columns
"The name, description, and creator of the Dashboard with `dashboard-id`, or nil."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one [:model/Dashboard :name :description :creator_id] dashboard-id))
+ (t2/select-one [:model/Dashboard :name :description :creator_id] :id [:auto/param dashboard-id]))
(mu/defn dashboard-public-uuid
"The public uuid of the Dashboard with `dashboard-id`, or nil."
@@ -181,7 +181,7 @@
(mu/defn dashcard
"The DashboardCard with `dashcard-id`, or nil."
[dashcard-id :- ::lib.schema.id/dashcard]
- (t2/select-one :model/DashboardCard dashcard-id))
+ (t2/select-one :model/DashboardCard :id [:auto/param dashcard-id]))
(mu/defn dashcard-in-dashboard
"The DashboardCard with `dashcard-id` on the Dashboard with `dashboard-id`, or nil."
@@ -209,7 +209,7 @@
(mu/defn user-name-and-email
"The name and email of the User with `user-id`, or nil."
[user-id :- ::lib.schema.id/user]
- (t2/select-one [:model/User :first_name :last_name :email] user-id))
+ (t2/select-one [:model/User :first_name :last_name :email] :id [:auto/param user-id]))
(mu/defn user-names-and-emails
"The names and emails of the Users with `user-ids`."
diff --git a/src/metabase/data_studio/db.clj b/src/metabase/data_studio/db.clj
index ce2fb0773bb..1c3847a88bf 100644
--- a/src/metabase/data_studio/db.clj
+++ b/src/metabase/data_studio/db.clj
@@ -73,7 +73,7 @@
(mu/defn database
"The Database with `database-id`, or nil."
[database-id :- ::lib.schema.id/database]
- (t2/select-one :model/Database database-id))
+ (t2/select-one :model/Database :id [:auto/param database-id]))
(mu/defn databases
"The Databases with `database-ids`."
diff --git a/src/metabase/documents/db.clj b/src/metabase/documents/db.clj
index 33ee94e5ba7..d62ac9048f3 100644
--- a/src/metabase/documents/db.clj
+++ b/src/metabase/documents/db.clj
@@ -91,7 +91,7 @@
(mu/defn card
"The Card with `card-id`, or nil."
[card-id :- ::lib.schema.id/card]
- (t2/select-one :model/Card card-id))
+ (t2/select-one :model/Card :id [:auto/param card-id]))
(mu/defn cards-not-in-document
"The Cards with `card-ids` that do not belong to the Document with `document-id`."
diff --git a/src/metabase/embedding_rest/db.clj b/src/metabase/embedding_rest/db.clj
index ae541b48b93..4ad74534b1d 100644
--- a/src/metabase/embedding_rest/db.clj
+++ b/src/metabase/embedding_rest/db.clj
@@ -12,7 +12,7 @@
(mu/defn card
"The Card with `card-id`, or nil."
[card-id :- ::lib.schema.id/card]
- (t2/select-one :model/Card card-id))
+ (t2/select-one :model/Card :id [:auto/param card-id]))
(mu/defn active-card
"The non-archived Card with `card-id`, or nil. A trashed Card keeps its DashboardCard rows, so the dashcard routes
@@ -33,7 +33,7 @@
(mu/defn dashboard
"The Dashboard with `dashboard-id`, or nil."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one :model/Dashboard dashboard-id))
+ (t2/select-one :model/Dashboard :id [:auto/param dashboard-id]))
(mu/defn dashboard-embedding-params
"The embedding parameters of the Dashboard with `dashboard-id`, or nil."
@@ -48,7 +48,7 @@
(mu/defn dashcard
"The DashboardCard with `dashcard-id`, or nil."
[dashcard-id :- ::lib.schema.id/dashcard]
- (t2/select-one :model/DashboardCard dashcard-id))
+ (t2/select-one :model/DashboardCard :id [:auto/param dashcard-id]))
(mu/defn embedding-themes
"The id, entity id, name, settings, default flag, and timestamps of every EmbeddingTheme, oldest first."
diff --git a/src/metabase/lib_metric/db.clj b/src/metabase/lib_metric/db.clj
index 77198906115..adbdea8eaf7 100644
--- a/src/metabase/lib_metric/db.clj
+++ b/src/metabase/lib_metric/db.clj
@@ -18,7 +18,7 @@
(mu/defn card-table-and-database-id
"The `:table_id` and `:database_id` of the Card with `card-id`, or nil."
[card-id :- ::lib.schema.id/card]
- (t2/select-one [:model/Card :table_id :database_id] card-id))
+ (t2/select-one [:model/Card :table_id :database_id] :id [:auto/param card-id]))
(mu/defn table-database-id
"The Database id of the Table with `table-id`, or nil."
diff --git a/src/metabase/metabot/db.clj b/src/metabase/metabot/db.clj
index 36602b8164f..25b1fdcfeec 100644
--- a/src/metabase/metabot/db.clj
+++ b/src/metabase/metabot/db.clj
@@ -421,7 +421,7 @@
(mu/defn database-summary
"The ID, name, description, and engine of the Database with `database-id`."
[database-id :- ::lib.schema.id/database]
- (t2/select-one [:model/Database :id :name :description :engine] database-id))
+ (t2/select-one [:model/Database :id :name :description :engine] :id [:auto/param database-id]))
(mu/defn database-with-columns
"The `columns` of the Database with `database-id`."
@@ -949,12 +949,12 @@
(mu/defn dashboard
"The Dashboard with `dashboard-id`, or nil."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one :model/Dashboard dashboard-id))
+ (t2/select-one :model/Dashboard :id [:auto/param dashboard-id]))
(mu/defn dashboard-summary
"The ID, description, name, Collection ID, and parameters of the Dashboard with `dashboard-id`, or nil."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one [:model/Dashboard :id :description :name :collection_id :parameters] dashboard-id))
+ (t2/select-one [:model/Dashboard :id :description :name :collection_id :parameters] :id [:auto/param dashboard-id]))
(mu/defn dashboard-name
"The name of the Dashboard with `dashboard-id`."
@@ -1054,7 +1054,7 @@
"The ID, email, and names of the User with `user-id`, or nil if `user-id` is nil or matches no User."
[user-id :- [:maybe ::lib.schema.id/user]]
(when user-id
- (t2/select-one [:model/User :id :email :first_name :last_name] user-id)))
+ (t2/select-one [:model/User :id :email :first_name :last_name] :id [:auto/param user-id])))
(mu/defn user-summaries-by-id
"A map of ID to the ID, email, and names of the Users with `user-ids`."
diff --git a/src/metabase/notification/db.clj b/src/metabase/notification/db.clj
index 8a6c311044a..5ed2aaa1956 100644
--- a/src/metabase/notification/db.clj
+++ b/src/metabase/notification/db.clj
@@ -85,7 +85,7 @@
(mu/defn notification
"The Notification with `notification-id`, or nil."
[notification-id :- ms/PositiveInt]
- (t2/select-one :model/Notification notification-id))
+ (t2/select-one :model/Notification :id [:auto/param notification-id]))
(mu/defn notification-by-internal-id
"The seeded Notification with `internal-id`, or nil."
@@ -258,7 +258,7 @@
(mu/defn subscription
"The NotificationSubscription with `subscription-id`, or nil."
[subscription-id :- ms/PositiveInt]
- (t2/select-one :model/NotificationSubscription subscription-id))
+ (t2/select-one :model/NotificationSubscription :id [:auto/param subscription-id]))
(mu/defn subscriptions-for-notifications
"The NotificationSubscriptions of the Notifications with `notification-ids` (nil entries are ignored)."
@@ -379,7 +379,7 @@
(mu/defn channel-template-channel-type
"The `:channel_type` of the ChannelTemplate with `template-id`."
[template-id :- ms/PositiveInt]
- (t2/select-one-fn :channel_type [:model/ChannelTemplate :channel_type] template-id))
+ (t2/select-one-fn :channel_type [:model/ChannelTemplate :channel_type] :id [:auto/param template-id]))
(mu/defn insert-channel-template!
"Insert `template` and return its ID."
@@ -678,7 +678,7 @@
(mu/defn card
"The Card with `card-id`, or nil."
[card-id :- [:maybe ::lib.schema.id/card]]
- (t2/select-one :model/Card card-id))
+ (t2/select-one :model/Card :id [:auto/param card-id]))
(mu/defn unarchived-card
"The Card with `card-id` if it is not archived, or nil."
@@ -688,17 +688,17 @@
(mu/defn card-name
"The name of the Card with `card-id`."
[card-id :- ::lib.schema.id/card]
- (t2/select-one-fn :name :model/Card card-id))
+ (t2/select-one-fn :name :model/Card :id [:auto/param card-id]))
(mu/defn dashboard
"The Dashboard with `dashboard-id`, or nil."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one :model/Dashboard dashboard-id))
+ (t2/select-one :model/Dashboard :id [:auto/param dashboard-id]))
(mu/defn dashboard-name
"The name of the Dashboard with `dashboard-id`."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one-fn :name :model/Dashboard dashboard-id))
+ (t2/select-one-fn :name :model/Dashboard :id [:auto/param dashboard-id]))
(mu/defn dashboard-tabs
"The DashboardTabs of the Dashboard with `dashboard-id`."
@@ -718,13 +718,13 @@
(mu/defn user-email
"The email of the User with `user-id`."
[user-id :- ::lib.schema.id/user]
- (t2/select-one-fn :email [:model/User :email] user-id))
+ (t2/select-one-fn :email [:model/User :email] :id [:auto/param user-id]))
(mu/defn user-summary
"The ID, names, email, and derived common name of the User with `user-id`, or nil (also for a nil `user-id`, e.g.
a system-created notification without a creator)."
[user-id :- [:maybe ::lib.schema.id/user]]
- (t2/select-one [:model/User :id :first_name :last_name :email] user-id))
+ (t2/select-one [:model/User :id :first_name :last_name :email] :id [:auto/param user-id]))
(mu/defn active-users-by-id
"A map of ID to active User for `user-ids`."
diff --git a/src/metabase/pulse/db.clj b/src/metabase/pulse/db.clj
index a9962a86cb6..9fd32f7a9e2 100644
--- a/src/metabase/pulse/db.clj
+++ b/src/metabase/pulse/db.clj
@@ -12,7 +12,7 @@
(mu/defn card
"The Card with `card-id`, or nil."
[card-id :- ::lib.schema.id/card]
- (t2/select-one :model/Card card-id))
+ (t2/select-one :model/Card :id [:auto/param card-id]))
(mu/defn card-query
"The query of the Card with `card-id`, or nil."
@@ -23,7 +23,7 @@
(t2/select-one-fn :dataset_query
[:model/Card :id :dataset_query :card_schema :type :entity_id
:result_metadata :dimensions :dimension_mappings]
- card-id))
+ :id [:auto/param card-id]))
(mu/defn dashboard
"The Dashboard with `dashboard-id`, or nil. `dashboard-id` may be nil (e.g. a legacy Pulse with no Dashboard), in
@@ -413,7 +413,7 @@
(defn user-name-and-email
"The first name, last name, and email of the User with `user-id`, or nil."
[user-id]
- (t2/select-one [:model/User :first_name :last_name :email] user-id))
+ (t2/select-one [:model/User :first_name :last_name :email] :id [:auto/param user-id]))
(defn users-names-and-emails
"The first names, last names, and emails of the Users with `user-ids`."
@@ -433,12 +433,12 @@
(defn dashboard-parameters
"The id and parameters of the Dashboard with `dashboard-id`, or nil."
[dashboard-id]
- (t2/select-one [:model/Dashboard :id :parameters] dashboard-id))
+ (t2/select-one [:model/Dashboard :id :parameters] :id [:auto/param dashboard-id]))
(defn dashboard-name-description-creator
"The name, description, and creator id of the Dashboard with `dashboard-id`, or nil."
[dashboard-id]
- (t2/select-one [:model/Dashboard :name :description :creator_id] dashboard-id))
+ (t2/select-one [:model/Dashboard :name :description :creator_id] :id [:auto/param dashboard-id]))
(defn unarchived-pulses-for-dashboard
"The unarchived Pulses of the Dashboard with `dashboard-id`, in id order."
diff --git a/src/metabase/queries_rest/db.clj b/src/metabase/queries_rest/db.clj
index 2a1ece7bcff..d669861f632 100644
--- a/src/metabase/queries_rest/db.clj
+++ b/src/metabase/queries_rest/db.clj
@@ -135,7 +135,7 @@
(mu/defn dashboard-collection-id
"The Collection id of the Dashboard with `dashboard-id`, or nil."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one-fn :collection_id [:model/Dashboard :collection_id] dashboard-id))
+ (t2/select-one-fn :collection_id [:model/Dashboard :collection_id] :id [:auto/param dashboard-id]))
(mu/defn update-card!
"Apply `changes` to the Card with `card-id`."
diff --git a/src/metabase/sample_data/db.clj b/src/metabase/sample_data/db.clj
index 34ee97ba284..83ff0d373b8 100644
--- a/src/metabase/sample_data/db.clj
+++ b/src/metabase/sample_data/db.clj
@@ -26,7 +26,7 @@
(mu/defn database
"The Database with `database-id`, or nil."
[database-id :- ::lib.schema.id/database]
- (t2/select-one :model/Database database-id))
+ (t2/select-one :model/Database :id [:auto/param database-id]))
(mu/defn set-sample-database-details!
"Set the `details` of the sample Database, returning the ids of the updated rows."
diff --git a/src/metabase/tiles/db.clj b/src/metabase/tiles/db.clj
index 7edb716fab7..a242b0947d0 100644
--- a/src/metabase/tiles/db.clj
+++ b/src/metabase/tiles/db.clj
@@ -9,14 +9,14 @@
(mu/defn card
"The Card with `card-id`, or nil."
[card-id :- ::lib.schema.id/card]
- (t2/select-one :model/Card card-id))
+ (t2/select-one :model/Card :id [:auto/param card-id]))
(mu/defn dashboard
"The Dashboard with `dashboard-id`, or nil."
[dashboard-id :- ::lib.schema.id/dashboard]
- (t2/select-one :model/Dashboard dashboard-id))
+ (t2/select-one :model/Dashboard :id [:auto/param dashboard-id]))
(mu/defn dashcard
"The DashboardCard with `dashcard-id`, or nil."
[dashcard-id :- ::lib.schema.id/dashcard]
- (t2/select-one :model/DashboardCard dashcard-id))
+ (t2/select-one :model/DashboardCard :id [:auto/param dashcard-id]))
diff --git a/src/metabase/transforms/db.clj b/src/metabase/transforms/db.clj
index 346830ad93a..faa312b97c6 100644
--- a/src/metabase/transforms/db.clj
+++ b/src/metabase/transforms/db.clj
@@ -67,7 +67,7 @@
(mu/defn transform-last-checkpoint-value
"The last checkpoint value of the Transform with `transform-id`."
[transform-id :- ::lib.schema.id/transform]
- (t2/select-one-fn :last_checkpoint_value [:model/Transform :last_checkpoint_value] transform-id))
+ (t2/select-one-fn :last_checkpoint_value [:model/Transform :last_checkpoint_value] :id [:auto/param transform-id]))
(mu/defn transform-collection-id
"The Collection ID of the Transform with `transform-id`."
@@ -825,7 +825,7 @@
(mu/defn database
"The Database with `database-id`, or nil."
[database-id :- ::lib.schema.id/database]
- (t2/select-one :model/Database database-id))
+ (t2/select-one :model/Database :id [:auto/param database-id]))
(mu/defn table
"The Table with `table-id`, or nil."
diff --git a/src/metabase/transforms_base/db.clj b/src/metabase/transforms_base/db.clj
index 666c89d7460..0c0e75db93e 100644
--- a/src/metabase/transforms_base/db.clj
+++ b/src/metabase/transforms_base/db.clj
@@ -23,7 +23,7 @@
(mu/defn transform
"The Transform with `transform-id`, or nil."
[transform-id :- ::lib.schema.id/transform]
- (t2/select-one :model/Transform transform-id))
+ (t2/select-one :model/Transform :id [:auto/param transform-id]))
(mu/defn update-transform!
"Apply `changes` to the Transform with `transform-id`."
diff --git a/src/metabase/upload/db.clj b/src/metabase/upload/db.clj
index f75c9546f32..7e4542603ef 100644
--- a/src/metabase/upload/db.clj
+++ b/src/metabase/upload/db.clj
@@ -25,7 +25,7 @@
(mu/defn database-is-attached-dwh?
"Whether the Database with `database-id` is an attached data warehouse."
[database-id :- ::lib.schema.id/database]
- (t2/select-one-fn :is_attached_dwh :model/Database database-id))
+ (t2/select-one-fn :is_attached_dwh :model/Database :id [:auto/param database-id]))
(mu/defn disable-uploads-for-all-databases!
"Disable uploads on every Database that has them enabled."
diff --git a/src/metabase/warehouse_schema_rest/db.clj b/src/metabase/warehouse_schema_rest/db.clj
index 54ad7f7f778..67818121665 100644
--- a/src/metabase/warehouse_schema_rest/db.clj
+++ b/src/metabase/warehouse_schema_rest/db.clj
@@ -138,7 +138,7 @@
(mu/defn database
"The Database with `database-id`, or nil."
[database-id :- ::lib.schema.id/database]
- (t2/select-one :model/Database database-id))
+ (t2/select-one :model/Database :id [:auto/param database-id]))
(mu/defn non-destination-database
"The Database with `database-id` if it is not a routing destination, or nil."
diff --git a/src/metabase/xrays/db.clj b/src/metabase/xrays/db.clj
index cb37a87f8bc..a3fa39b8637 100644
--- a/src/metabase/xrays/db.clj
+++ b/src/metabase/xrays/db.clj
@@ -273,4 +273,4 @@
(mu/defn model-index
"The ModelIndex with `model-index-id`, or nil."
[model-index-id :- ms/PositiveInt]
- (t2/select-one :model/ModelIndex model-index-id))
+ (t2/select-one :model/ModelIndex :id [:auto/param model-index-id]))