The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Avoid joins of remote_sync_object with actual tables (#67042)
Nathan Voxland1d8b669f6234
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/events.cljindex 71c58cb7b6d..aaf67aab587 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj@@ -23,6 +23,35 @@(boolean(collections/remote-synced-collection? collection_id)))+(defmulti ^:private remote-sync-model-details+ "Returns a map of relevant fields for the model."+ {:arglists '([model-type model-id])}+ (fn [model-type _model-id] model-type))++(defmethod remote-sync-model-details "Card"+ [_model-type model-id]+ (t2/select-one [:model/Card :name :collection_id :display] :id model-id))++(defmethod remote-sync-model-details "Dashboard"+ [_model-type model-id]+ (t2/select-one [:model/Dashboard :name :collection_id] :id model-id))++(defmethod remote-sync-model-details "Document"+ [_model-type model-id]+ (t2/select-one [:model/Document :name :collection_id] :id model-id))++(defmethod remote-sync-model-details "NativeQuerySnippet"+ [_model-type model-id]+ (t2/select-one [:model/NativeQuerySnippet :name :id] :id model-id))++(defmethod remote-sync-model-details "Timeline"+ [_model-type model-id]+ (t2/select-one [:model/Timeline :name :collection_id] :id model-id))++(defmethod remote-sync-model-details "Collection"+ [_model-type model-id]+ (t2/select-one [:model/Collection :name [:id :collection_id]] :id model-id))+(defn- create-or-update-remote-sync-object-entry!"Creates or updates a remote sync object entry for a model change. Takes a model-type (type of model: 'Card','Dashboard', 'Document', 'Collection'), a model-id (ID of the affected model), a status (status of the sync:@@ -32,21 +61,35 @@(let [existing (t2/select-one :model/RemoteSyncObject :model_type model-type :model_id model-id)](cond(not existing)- (t2/insert! :model/RemoteSyncObject- {:model_type model-type- :model_id model-id- :status status- :status_changed_at (t/offset-date-time)})+ (let [model-details (remote-sync-model-details model-type model-id)]+ (t2/insert! :model/RemoteSyncObject+ {:model_type model-type+ :model_id model-id+ :model_name (:name model-details)+ :model_collection_id (:collection_id model-details)+ :model_display (some-> model-details :display name)+ :status status+ :status_changed_at (t/offset-date-time)}));; If the entity was created and then removed/deleted before sync, just delete the entry from tracking(and (= "create" (:status existing)) (contains? #{"removed" "delete"} status))(t2/delete! :model/RemoteSyncObject (:id existing))- ;; If the entry was created, the status should remain create until synced- (not (= "create" (:status existing)))+ ;; Just update the status, object doesn't exist to update other info+ (= "delete" (:status existing))(t2/update! :model/RemoteSyncObject (:id existing){:status status- :status_changed_at (t/offset-date-time)}))))+ :status_changed_at (t/offset-date-time)})++ ;; If the entry was created, the status should remain create until synced+ (not (= "create" (:status existing)))+ (let [model (remote-sync-model-details model-type model-id)]+ (t2/update! :model/RemoteSyncObject (:id existing)+ {:status status+ :status_changed_at (t/offset-date-time)+ :model_name (:name model)+ :model_collection_id (:collection_id model)+ :model_display (some-> model :display name)})))));; Model change tracking event handlersdiff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.cljindex 2b5a036196c..47bcbf25ea7 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj@@ -27,6 +27,15 @@[](t2/select-pks-vec :model/Collection :is_remote_synced true))+(defn- model-fields-for-sync+ "Returns the fields to select for a given model type when syncing."+ [model-name]+ (case model-name+ "Card" [:id :name :collection_id :display]+ "NativeQuerySnippet" [:id :name]+ "Collection" [:id :name [:id :collection_id]]+ [:id :name :collection_id]))+(defn- sync-objects!"Populates the remote-sync-object table with imported entities. Deletes all existing RemoteSyncObject records andinserts new ones for each imported entity, marking them as 'synced' with the given timestamp.@@ -37,10 +46,15 @@(t2/delete! :model/RemoteSyncObject)(let [inserts (->> imported-entities-by-model(mapcat (fn [[model entity-ids]]- (t2/select [(keyword "model" model) :id] :entity_id [:in entity-ids])))- (map (fn [{:keys [id] :as model}]- {:model_type (name (t2/model model))+ (let [fields (model-fields-for-sync model)+ model-kw (keyword "model" model)]+ (t2/select (into [model-kw] fields) :entity_id [:in entity-ids]))))+ (map (fn [{:keys [id name collection_id display] :as model}]+ {:model_type (clojure.core/name (t2/model model)):model_id id+ :model_name name+ :model_collection_id collection_id+ :model_display (some-> display clojure.core/name):status "synced":status_changed_at timestamp})))](t2/insert! :model/RemoteSyncObject inserts)))diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_object.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_object.cljindex b60a1912e21..ea1e0a0262b 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_object.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_object.clj@@ -1,5 +1,6 @@(ns metabase-enterprise.remote-sync.models.remote-sync-object(:require+ [clojure.set :as set][methodical.core :as methodical][toucan2.core :as t2]))@@ -9,96 +10,6 @@(derive :model/RemoteSyncObject :metabase/model)-(def ^:private synced-models- {:collection "Collection" :report_card "Card" :document "Document" :report_dashboard "Dashboard" :native_query_snippet "NativeQuerySnippet" :timeline "Timeline"})--(def ^:private items-select- {:collection [:collection.id- :collection.name- :collection.created_at- :collection.authority_level- [:collection.id :collection_id]- [nil :display]- [nil :query_type]- [nil :description]- [nil :updated_at]- [[:inline "collection"] :model]- [:rs_obj.status :sync_status]]- :report_card [:report_card.id- :report_card.name- :report_card.created_at- [nil :authority_level]- :report_card.collection_id- :report_card.display- :report_card.query_type- :report_card.description- :report_card.updated_at- [[:inline "card"] :model]- [:rs_obj.status :sync_status]]- :document [:document.id- :document.name- :document.created_at- [nil :authority_level]- :document.collection_id- [nil :display]- [nil :query_type]- [nil :description]- :document.updated_at- [[:inline "document"] :model]- [:rs_obj.status :sync_status]]- :report_dashboard [:report_dashboard.id- :report_dashboard.name- :report_dashboard.created_at- [nil :authority_level]- :report_dashboard.collection_id- [nil :display]- [nil :query_type]- :report_dashboard.description- :report_dashboard.updated_at- [[:inline "dashboard"] :model]- [:rs_obj.status :sync_status]]- :native_query_snippet [:native_query_snippet.id- :native_query_snippet.name- :native_query_snippet.created_at- [nil :authority_level]- :native_query_snippet.collection_id- [nil :display]- [nil :query_type]- [nil :description]- :native_query_snippet.updated_at- [[:inline "snippet"] :model]- [:rs_obj.status :sync_status]]- :timeline [:timeline.id- :timeline.name- :timeline.created_at- [nil :authority_level]- :timeline.collection_id- [nil :display]- [nil :query_type]- :timeline.description- :timeline.updated_at- [[:inline "timeline"] :model]- [:rs_obj.status :sync_status]]})--(defn- build-dirty-union-all- "Builds a HoneySQL select statement that returns dirty children of a collection.-- Takes a map of model-type to HoneySQL select clause configurations.-- Returns a HoneySQL union-all query that counts dirty objects across all synced model types."- [select-options]- (let [queries (mapv (fn [[table entity-type]]- (let [id-col (keyword (str (name table) ".id"))]- {:select (select-options table)- :from [table]- :inner-join [[:remote_sync_object :rs_obj]- [:and- [:= :rs_obj.model_id id-col]- [:= :rs_obj.model_type [:inline entity-type]]]]- :where [:not= :status "synced"]}))- synced-models)]- {:union-all queries}))-(defn dirty-global?"Checks if any collection has changes since the last sync.@@ -112,4 +23,13 @@Returns a sequence of model maps that have changed since the last remote sync, including details about theircurrent state and sync status."[]- (t2/query (build-dirty-union-all items-select)))+ (->> (t2/select :model/RemoteSyncObject :status [:not= "synced"])+ (map #(-> %+ (dissoc :id)+ (set/rename-keys {:model_id :id+ :model_name :name+ :model_type :model+ :model_collection_id :collection_id+ :model_display :display+ :status :sync_status})))+ (into [])))diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.cljindex 1c3d672af10..7898540c730 100644--- a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj@@ -149,6 +149,8 @@remote-sync-branch "main"](t2/insert! :model/RemoteSyncObject {:model_type "Card":model_id 1+ :model_name "Test Card"+ :model_collection_id 1:status "updated":status_changed_at (java.time.OffsetDateTime/now)})(with-redefs [source/source-from-settings (constantly mock-main)]@@ -382,6 +384,8 @@:name "Test Card"}:model/RemoteSyncObject _ {:model_type "Card":model_id (:id card)+ :model_name "Test Card"+ :model_collection_id (:id remote-col):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](is (= {:is_dirty true}@@ -421,16 +425,22 @@:name "Card 2"}:model/Dashboard dashboard {:collection_id (:id remote-col1):name "Dashboard 1"}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card1)+ :model_name "Card 1"+ :model_collection_id (:id remote-col1):status "pending":status_changed_at (java.time.OffsetDateTime/now)}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card2)+ :model_name "Card 2"+ :model_collection_id (:id remote-col2):status "pending":status_changed_at (java.time.OffsetDateTime/now)}- :model/RemoteSyncObject _ {:model_type "Dashboard"+ :model/RemoteSyncObject _ {:model_type "dashboard":model_id (:id dashboard)+ :model_name "Dashboard 1"+ :model_collection_id (:id remote-col1):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](let [response (mt/user-http-request :crowberto :get 200 "ee/remote-sync/dirty")@@ -453,7 +463,9 @@:location (str "/" (:id remote-col) "/")}:model/Card nested-card {:collection_id (:id nested-col):name "Nested Card"}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card"+ :model_name "Nested Card"+ :model_collection_id (:id nested-col):model_id (:id nested-card):status "pending":status_changed_at (java.time.OffsetDateTime/now)}]@@ -473,6 +485,8 @@:name "Test Card"}:model/RemoteSyncObject _ {:model_type "Card":model_id (:id card)+ :model_name "Test Card"+ :model_collection_id (:id remote-col):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](let [response (mt/user-http-request :crowberto :get 200 "ee/remote-sync/dirty")@@ -751,6 +765,8 @@remote-sync-type :read-write](mt/with-temp [:model/RemoteSyncObject remote-sync {:model_type "Card":model_id 1+ :model_name "Test Card"+ :model_collection_id 1:status "updated":status_changed_at (java.time.OffsetDateTime/now)}](with-redefs [source/source-from-settings (constantly mock-source)diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.cljindex 34b38b410d5..b2406b5b0f4 100644--- a/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj@@ -514,27 +514,29 @@(testing "create-remote-sync-object-entry! creates new entry when none exists"(mt/with-current-user (mt/user->id :rasta)(t2/delete! :model/RemoteSyncObject)- (#'lib.events/create-or-update-remote-sync-object-entry! "Card" 123 "create" 456)- (let [entries (t2/select :model/RemoteSyncObject)]- (is (= 1 (count entries)))- (is (=? {:model_type "Card"- :model_id 123- :status "create"}- (first entries)))))))+ (let [existing-card-id (t2/select-one-fn :id [:model/Card :id])]+ (#'lib.events/create-or-update-remote-sync-object-entry! "Card" existing-card-id "create" 456)+ (let [entries (t2/select :model/RemoteSyncObject)]+ (is (= 1 (count entries)))+ (is (=? {:model_type "Card"+ :model_id existing-card-id+ :status "create"}+ (first entries))))))))(deftest create-remote-sync-object-entry-updates-existing-entry-test(testing "create-remote-sync-object-entry! updates existing entry when one exists"(mt/with-current-user (mt/user->id :rasta)(t2/delete! :model/RemoteSyncObject)- (let [clock-t1 (t/mock-clock (t/instant "2024-01-01T10:00:00Z") (t/zone-id "UTC"))]+ (let [clock-t1 (t/mock-clock (t/instant "2024-01-01T10:00:00Z") (t/zone-id "UTC"))+ existing-dashboard-id (t2/select-one-fn :id [:model/Dashboard :id])](t/with-clock clock-t1- (#'lib.events/create-or-update-remote-sync-object-entry! "Dashboard" 789 "update"))- (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Dashboard" :model_id 789)+ (#'lib.events/create-or-update-remote-sync-object-entry! "Dashboard" existing-dashboard-id "update"))+ (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Dashboard" :model_id existing-dashboard-id)initial-time (:status_changed_at initial-entry)clock-t2 (t/mock-clock (t/instant "2024-01-01T11:00:00Z") (t/zone-id "UTC"))](t/with-clock clock-t2- (#'lib.events/create-or-update-remote-sync-object-entry! "Dashboard" 789 "synced"))- (let [entries (t2/select :model/RemoteSyncObject :model_type "Dashboard" :model_id 789)]+ (#'lib.events/create-or-update-remote-sync-object-entry! "Dashboard" existing-dashboard-id "synced"))+ (let [entries (t2/select :model/RemoteSyncObject :model_type "Dashboard" :model_id existing-dashboard-id)](is (= 1 (count entries)))(let [update-entry (first entries)](is (= (:id initial-entry) (:id update-entry)))@@ -545,14 +547,15 @@(testing "create-remote-sync-object-entry! does not update entry when status is 'create'"(mt/with-current-user (mt/user->id :rasta)(t2/delete! :model/RemoteSyncObject)- (let [clock-t1 (t/mock-clock (t/instant "2024-01-01T10:00:00Z") (t/zone-id "UTC"))]+ (let [clock-t1 (t/mock-clock (t/instant "2024-01-01T10:00:00Z") (t/zone-id "UTC"))+ existing-dashboard-id (t2/select-one-fn :id [:model/Dashboard :id])](t/with-clock clock-t1- (#'lib.events/create-or-update-remote-sync-object-entry! "Dashboard" 789 "create"))- (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Dashboard" :model_id 789)+ (#'lib.events/create-or-update-remote-sync-object-entry! "Dashboard" existing-dashboard-id "create"))+ (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Dashboard" :model_id existing-dashboard-id)clock-t2 (t/mock-clock (t/instant "2024-01-01T11:00:00Z") (t/zone-id "UTC"))](t/with-clock clock-t2- (#'lib.events/create-or-update-remote-sync-object-entry! "Dashboard" 789 "synced"))- (let [entries (t2/select :model/RemoteSyncObject :model_type "Dashboard" :model_id 789)]+ (#'lib.events/create-or-update-remote-sync-object-entry! "Dashboard" existing-dashboard-id "synced"))+ (let [entries (t2/select :model/RemoteSyncObject :model_type "Dashboard" :model_id existing-dashboard-id)](is (= 1 (count entries)))(let [update-entry (first entries)](is (= (:id initial-entry) (:id update-entry)))@@ -563,13 +566,14 @@(testing "create-remote-sync-object-entry! uses current user when user-id not specified"(mt/with-current-user (mt/user->id :rasta)(t2/delete! :model/RemoteSyncObject)- (#'lib.events/create-or-update-remote-sync-object-entry! "Collection" 999 "create")- (let [entries (t2/select :model/RemoteSyncObject)]- (is (= 1 (count entries)))- (is (=? {:model_type "Collection"- :model_id 999- :status "create"}- (first entries)))))))+ (let [existing-collection-id (t2/select-one-fn :id [:model/Collection :id])]+ (#'lib.events/create-or-update-remote-sync-object-entry! "Collection" existing-collection-id "create")+ (let [entries (t2/select :model/RemoteSyncObject)]+ (is (= 1 (count entries)))+ (is (=? {:model_type "Collection"+ :model_id existing-collection-id+ :status "create"}+ (first entries))))))))(deftest existing-card-moved-out-of-remote-synced-collection-test(testing "existing card moved out of remote-synced collection is marked as removed"@@ -855,3 +859,30 @@:user-id (mt/user->id :rasta)})(let [entries (t2/select :model/RemoteSyncObject)](is (= 0 (count entries)))))))++(deftest soft-delete-then-hard-delete-preserves-dirty-status-test+ (testing "doc that is soft-deleted then hard-deleted should maintain dirty status"+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}+ :model/Document doc {:name "Test Doc"+ :collection_id (:id remote-sync-collection)}]+ (t2/delete! :model/RemoteSyncObject)++ ;; Trash the doc+ (t2/update! :model/Document (: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))+ (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+ ;; so the collection remains dirty+ (let [hard-delete-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id doc))]+ (is (= "delete" (:status hard-delete-entry)))+ (is (not (nil? hard-delete-entry)))))))diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.cljindex 8b133bc0cfd..a6fd0b95814 100644--- a/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj@@ -300,9 +300,9 @@(mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection" :is_remote_synced true :entity_id "test-collection-1xxxx" :location "/"}:model/Card {card-id :id} {:name "Test Card" :collection_id coll-id :entity_id "test-card-1xxxxxxxxxx"}](t2/insert! :model/RemoteSyncObject- [{:model_type "Collection" :model_id coll-id :status "created" :status_changed_at (t/offset-date-time)}- {:model_type "Card" :model_id card-id :status "updated" :status_changed_at (t/offset-date-time)}- {:model_type "Card" :model_id 999 :status "deleted" :status_changed_at (t/offset-date-time)}])+ [{:model_type "Collection" :model_id coll-id :model_name "Test Collection" :status "created" :status_changed_at (t/offset-date-time)}+ {:model_type "Card" :model_id card-id :model_name "Test Card" :status "updated" :status_changed_at (t/offset-date-time)}+ {:model_type "Card" :model_id 999 :model_name "Test Card2" :status "deleted" :status_changed_at (t/offset-date-time)}])(is (= 3 (t2/count :model/RemoteSyncObject)))(let [test-files {"main" {"collections/test-collection-1xxxx-_/test-collection-1xxxx.yaml"(test-helpers/generate-collection-yaml "test-collection-1xxxx" "Test Collection")@@ -329,9 +329,9 @@:model/Card {card-id :id} {:name "Test Card" :collection_id coll-id :entity_id "test-card-1xxxxxxxxxx"}:model/Dashboard {dash-id :id} {:name "Test Dashboard" :collection_id coll-id :entity_id "test-dashboard-1xxxxx"}](t2/insert! :model/RemoteSyncObject- [{:model_type "Collection" :model_id coll-id :status "updated" :status_changed_at (t/offset-date-time)}- {:model_type "Card" :model_id card-id :status "created" :status_changed_at (t/offset-date-time)}- {:model_type "Dashboard" :model_id dash-id :status "removed" :status_changed_at (t/offset-date-time)}])+ [{:model_type "Collection" :model_id coll-id :model_name "Test Collection" :status "updated" :status_changed_at (t/offset-date-time)}+ {:model_type "Card" :model_id card-id :model_name "Test Card" :status "created" :status_changed_at (t/offset-date-time)}+ {:model_type "Dashboard" :model_id dash-id :model_name "Test Dashboard" :status "removed" :status_changed_at (t/offset-date-time)}])(is (= "updated" (:status (t2/select-one :model/RemoteSyncObject :model_type "Collection" :model_id coll-id))))(is (= "created" (:status (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id card-id))))(is (= "removed" (:status (t2/select-one :model/RemoteSyncObject :model_type "Dashboard" :model_id dash-id))))@@ -362,8 +362,8 @@:entity_id "removed-collection-xx":location "/"}](t2/insert! :model/RemoteSyncObject- [{:model_type "Collection" :model_id active-coll-id :status "synced" :status_changed_at (t/offset-date-time)}- {:model_type "Collection" :model_id removed-coll-id :status "removed" :status_changed_at (t/offset-date-time)}])+ [{:model_type "Collection" :model_id active-coll-id :model_name "Active Collection" :status "synced" :status_changed_at (t/offset-date-time)}+ {:model_type "Collection" :model_id removed-coll-id :model_name "Removed Collection" :status "removed" :status_changed_at (t/offset-date-time)}])(let [initial-files {"main" {"collections/active-collection-xxx_active_collection/active-collection-xxx.yaml"(test-helpers/generate-collection-yaml "active-collection-xxx" "Active Collection")"collections/active-collection-xxx_active_collection/cards/active-card.yaml"@@ -397,8 +397,8 @@:entity_id "nested-removed-collxx":location (format "/%d/" parent-coll-id)}](t2/insert! :model/RemoteSyncObject- [{:model_type "Collection" :model_id parent-coll-id :status "synced" :status_changed_at (t/offset-date-time)}- {:model_type "Collection" :model_id nested-coll-id :status "removed" :status_changed_at (t/offset-date-time)}])+ [{:model_type "Collection" :model_id parent-coll-id :model_name "Parent Collection" :status "synced" :status_changed_at (t/offset-date-time)}+ {:model_type "Collection" :model_id nested-coll-id :model_name "Nested Collection" :status "removed" :status_changed_at (t/offset-date-time)}])(let [initial-files {"main" {"collections/parent-collection-xx_parent_collection/parent-collection-xx.yaml"(test-helpers/generate-collection-yaml "parent-collection-xx" "Parent Collection")"collections/parent-collection-xx_parent_collection/nested-removed-collxx_nested_removed_collection/nested-removed-collxx.yaml"@@ -435,9 +435,9 @@:entity_id "removed-coll-2xxxxxxx" ;; 21 chars:location "/"}](t2/insert! :model/RemoteSyncObject- [{:model_type "Collection" :model_id active-coll-id :status "synced" :status_changed_at (t/offset-date-time)}- {:model_type "Collection" :model_id removed-coll-1-id :status "removed" :status_changed_at (t/offset-date-time)}- {:model_type "Collection" :model_id removed-coll-2-id :status "removed" :status_changed_at (t/offset-date-time)}])+ [{:model_type "Collection" :model_id active-coll-id :model_name "Active Collection" :status "synced" :status_changed_at (t/offset-date-time)}+ {:model_type "Collection" :model_id removed-coll-1-id :model_name "Removed Col 1" :status "removed" :status_changed_at (t/offset-date-time)}+ {:model_type "Collection" :model_id removed-coll-2-id :model_name "Removed Col 2" :status "removed" :status_changed_at (t/offset-date-time)}])(let [initial-files {"main" {"collections/removed-coll-1xxxxxxx_removed_collection_1/removed-coll-1xxxxxxx.yaml"(test-helpers/generate-collection-yaml "removed-coll-1xxxxxxx" "Removed Collection 1")"collections/removed-coll-1xxxxxxx_removed_collection_1/cards/card-1.yaml"diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/models/remote_sync_object_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/models/remote_sync_object_test.cljindex a9b31741a16..a8d1bf7a0bf 100644--- a/enterprise/backend/test/metabase_enterprise/remote_sync/models/remote_sync_object_test.clj+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/models/remote_sync_object_test.clj@@ -31,8 +31,9 @@:creator_id (mt/user->id :rasta):display "table":dataset_query (mt/native-query {:query "SELECT 1"})}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card)+ :model_name (:name card):status "synced":status_changed_at (java.time.OffsetDateTime/now)}](is (false? (rs-object/dirty-global?))))))@@ -47,8 +48,9 @@:creator_id (mt/user->id :rasta):display "table":dataset_query (mt/native-query {:query "SELECT 1"})}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card)+ :model_name (:name card):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](is (true? (rs-object/dirty-global?))))))@@ -63,8 +65,9 @@:creator_id (mt/user->id :rasta):display "table":dataset_query (mt/native-query {:query "SELECT 1"})}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card)+ :model_name (:name card):status "error":status_changed_at (java.time.OffsetDateTime/now)}](is (true? (rs-object/dirty-global?))))))@@ -84,12 +87,14 @@:creator_id (mt/user->id :rasta):display "table":dataset_query (mt/native-query {:query "SELECT 1"})}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card1)+ :model_name (:name card1):status "synced":status_changed_at (java.time.OffsetDateTime/now)}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card2)+ :model_name (:name card2):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](is (true? (rs-object/dirty-global?))))))@@ -112,8 +117,9 @@:creator_id (mt/user->id :rasta):display "table":dataset_query (mt/native-query {:query "SELECT 1"})}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card)+ :model_name (:name card):status "synced":status_changed_at (java.time.OffsetDateTime/now)}](is (empty? (rs-object/dirty-for-global))))))@@ -128,8 +134,9 @@:creator_id (mt/user->id :rasta):display "table":dataset_query (mt/native-query {:query "SELECT 1"})}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card)+ :model_name (:name card):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](let [dirty-items (rs-object/dirty-for-global)]@@ -153,12 +160,14 @@:model/Dashboard dashboard {:name "Test Dashboard":collection_id (:id collection):creator_id (mt/user->id :rasta)}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card)+ :model_name (:name card):status "pending":status_changed_at (java.time.OffsetDateTime/now)}- :model/RemoteSyncObject _ {:model_type "Dashboard"+ :model/RemoteSyncObject _ {:model_type "dashboard":model_id (:id dashboard)+ :model_name (:name dashboard):status "error":status_changed_at (java.time.OffsetDateTime/now)}](let [dirty-items (rs-object/dirty-for-global)@@ -174,8 +183,9 @@(mt/with-temp[:model/Collection collection {:name "Test Collection":location "/"}- :model/RemoteSyncObject _ {:model_type "Collection"+ :model/RemoteSyncObject _ {:model_type "collection":model_id (:id collection)+ :model_name (:name collection):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](let [dirty-items (rs-object/dirty-for-global)]@@ -200,12 +210,14 @@:creator_id (mt/user->id :rasta):display "table":dataset_query (mt/native-query {:query "SELECT 1"})}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card1)+ :model_name (:name card1):status "synced":status_changed_at (java.time.OffsetDateTime/now)}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card2)+ :model_name (:name card2):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](let [dirty-items (rs-object/dirty-for-global)@@ -223,8 +235,9 @@:collection_id (:id snip-collection):creator_id (mt/user->id :rasta):content "SELECT * FROM table"}- :model/RemoteSyncObject _ {:model_type "NativeQuerySnippet"+ :model/RemoteSyncObject _ {:model_type "snippet":model_id (:id snippet)+ :model_name (:name snippet):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](let [dirty-items (rs-object/dirty-for-global)]@@ -242,8 +255,9 @@:model/Document document {:name "Test Document":collection_id (:id collection):creator_id (mt/user->id :rasta)}- :model/RemoteSyncObject _ {:model_type "Document"+ :model/RemoteSyncObject _ {:model_type "document":model_id (:id document)+ :model_name (:name document):status "error":status_changed_at (java.time.OffsetDateTime/now)}](let [dirty-items (rs-object/dirty-for-global)]@@ -277,24 +291,29 @@:collection_id (:id snip-collection):creator_id (mt/user->id :rasta):content "SELECT * FROM table"}- :model/RemoteSyncObject _ {:model_type "Collection"+ :model/RemoteSyncObject _ {:model_type "collection":model_id (:id collection)+ :model_name (:name collection):status "pending":status_changed_at (java.time.OffsetDateTime/now)}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card)+ :model_name (:name card):status "pending":status_changed_at (java.time.OffsetDateTime/now)}- :model/RemoteSyncObject _ {:model_type "Dashboard"+ :model/RemoteSyncObject _ {:model_type "dashboard":model_id (:id dashboard)+ :model_name (:name dashboard):status "pending":status_changed_at (java.time.OffsetDateTime/now)}- :model/RemoteSyncObject _ {:model_type "Document"+ :model/RemoteSyncObject _ {:model_type "document":model_id (:id document)+ :model_name (:name document):status "pending":status_changed_at (java.time.OffsetDateTime/now)}- :model/RemoteSyncObject _ {:model_type "NativeQuerySnippet"+ :model/RemoteSyncObject _ {:model_type "snippet":model_id (:id snippet)+ :model_name (:name snippet):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](let [dirty-items (rs-object/dirty-for-global)@@ -321,8 +340,9 @@:creator_id (mt/user->id :rasta):display "table":dataset_query (mt/native-query {:query "SELECT 1"})}- :model/RemoteSyncObject _ {:model_type "Card"+ :model/RemoteSyncObject _ {:model_type "card":model_id (:id card)+ :model_name (:name card):status "pending":status_changed_at (java.time.OffsetDateTime/now)}](is (true? (rs-object/dirty-global?)))diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/test-utils.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/test-utils.tsindex ffd4bb23373..fda4ed83444 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/test-utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/test-utils.ts@@ -58,9 +58,6 @@ export const createMockDirtyEntity = (): RemoteSyncEntity => ({id: 1,name: "Test Card",- description: null,- created_at: "2024-01-01T00:00:00Z",- updated_at: null,model: "card",sync_status: "update",collection_id: 1,diff --git a/frontend/src/metabase-types/api/mocks/remote-sync.ts b/frontend/src/metabase-types/api/mocks/remote-sync.tsindex 349434f9f96..3b1995dee3d 100644--- a/frontend/src/metabase-types/api/mocks/remote-sync.ts+++ b/frontend/src/metabase-types/api/mocks/remote-sync.ts@@ -5,9 +5,6 @@ export const createMockRemoteSyncEntity = (): RemoteSyncEntity => ({id: 1,name: "My Question",- description: null,- created_at: "2015-01-01T20:10:30.200",- updated_at: "2015-01-01T20:10:30.200",model: "card",sync_status: "update",...opts,diff --git a/frontend/src/metabase-types/api/remote-sync.ts b/frontend/src/metabase-types/api/remote-sync.tsindex 0af0e17429b..a915c246c80 100644--- a/frontend/src/metabase-types/api/remote-sync.ts+++ b/frontend/src/metabase-types/api/remote-sync.ts@@ -21,15 +21,10 @@ export type RemoteSyncEntityStatus =export type RemoteSyncEntity = {id: number;name: string;- description: string | null;- created_at: string;- updated_at: string | null;model: RemoteSyncEntityModel;collection_id?: number;display?: CardDisplayType;- query_type?: string;sync_status: RemoteSyncEntityStatus;- authority_level?: string | null;};export type RemoteSyncChangesResponse = {diff --git a/resources/migrations/057_update_migrations.yaml b/resources/migrations/057_update_migrations.yamlindex 046ddf8e5d9..7eeb547f0cb 100644--- a/resources/migrations/057_update_migrations.yaml+++ b/resources/migrations/057_update_migrations.yaml@@ -2604,6 +2604,89 @@ databaseChangeLog:path: instance_analytics_views/content/v5/h2-content.sqlrelativeToChangelogFile: true+ - changeSet:+ id: v57.2025-12-08T19:05:23+ author: nvoxland+ comment: Add remote_sync_object.model_name+ changes:+ - addColumn:+ tableName: remote_sync_object+ columns:+ - column:+ name: model_name+ type: varchar(255)+ remarks: Copy of the name from the object being sync'ed++ - changeSet:+ id: v57.2025-12-08T19:05:24+ author: nvoxland+ comment: Add remote_sync_object.model_collection_id+ changes:+ # No foreign key because the referenced collection may be deleted+ - addColumn:+ tableName: remote_sync_object+ columns:+ - column:+ name: model_collection_id+ type: int+ remarks: Copy of the collection from the object being sync'ed++ - changeSet:+ id: v57.2025-12-08T19:05:25+ author: nvoxland+ comment: Add remote_sync_object.model_display+ changes:+ - addColumn:+ tableName: remote_sync_object+ columns:+ - column:+ name: model_display+ type: varchar(50)+ remarks: Copy of the display field from the object being sync'ed++ - changeSet:+ id: v57.2025-12-08T19:05:26+ author: nvoxland+ comment: Update in-flight remote_sync_objects+ changes:+ - sql:+ splitStatements: true+ sql: |+ update remote_sync_object set model_name = (select name from collection where id = remote_sync_object.model_id) where model_type = 'Collection';+ update remote_sync_object set model_collection_id = (select id from collection where id = remote_sync_object.model_id) where model_type = 'Collection';++ update remote_sync_object set model_name = (select name from report_card where id = remote_sync_object.model_id) where model_type = 'Card';+ update remote_sync_object set model_collection_id = (select collection_id from report_card where id = remote_sync_object.model_id) where model_type = 'Card';+ update remote_sync_object set model_display = (select display from report_card where id = remote_sync_object.model_id) where model_type = 'Card';++ update remote_sync_object set model_name = (select name from document where id = remote_sync_object.model_id) where model_type = 'Document';+ update remote_sync_object set model_collection_id = (select collection_id from document where id = remote_sync_object.model_id) where model_type = 'Document';++ update remote_sync_object set model_name = (select name from report_dashboard where id = remote_sync_object.model_id) where model_type = 'Dashboard';+ update remote_sync_object set model_collection_id = (select collection_id from report_dashboard where id = remote_sync_object.model_id) where model_type = 'Dashboard';++ update remote_sync_object set model_name = (select name from native_query_snippet where id = remote_sync_object.model_id) where model_type = 'NativeQuerySnippet';+ update remote_sync_object set model_collection_id = (select collection_id from native_query_snippet where id = remote_sync_object.model_id) where model_type = 'NativeQuerySnippet';++ update remote_sync_object set model_name = (select name from timeline where id = remote_sync_object.model_id) where model_type = 'Timeline';+ update remote_sync_object set model_collection_id = (select collection_id from timeline where id = remote_sync_object.model_id) where model_type = 'Timeline';++ update remote_sync_object set model_name='DELETED' where model_name is null;+ rollback: ## Changes will get rolled back when columns are rolled back+++ - changeSet:+ id: v57.2025-12-08T19:05:27+ author: nvoxland+ comment: Mark remote_sync_objects.model_name as not null+ changes:+ - addNotNullConstraint:+ tableName: remote_sync_object+ columnName: model_name+ columnDataType: varchar(255)+++- changeSet:id: v57.2025-12-09T12:45:01author: dpsutton