Skip to content

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

fix: clean up style issues in new remote-sync code (#68753)

Edward Pagetef4136d69e10
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/source/git.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/source/git.clj
index 729f1edad61..e3e3352671e 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/source/git.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/source/git.clj
@@ -232,7 +232,8 @@
Takes a git-source map containing a :git Git instance.
- Returns the default branch name as a string (without 'refs/heads/' prefix), or nil if no default branch is found."
+ Returns the default branch name as a string (without 'refs/heads/' prefix).
+ Throws ExceptionInfo if no default branch is found."
[{:keys [^Git git] :as git-source}]
;; Query the remote directly to get HEAD - lsRemote returns symbolic refs
(let [refs (call-remote-command (.lsRemote git) git-source)
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj
index d4a1e8bdaea..8cb0095046d 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj
@@ -32,7 +32,9 @@
- :model-type - String name for RemoteSyncObject model_type column
- :model-key - Toucan2 model keyword (e.g., :model/Card)
- :identity - Identity strategy: :entity-id, :path, or :hybrid
- - :path-keys - For path-based: vector of path components [:database :schema :table :field]
+ - :path-keys - For :path or :hybrid identity: vector of path components [:database :schema :table :field]
+ - :parent-model - For :parent-table eligibility: the parent model key to check eligibility against
+ (e.g., :model/Table for Field, Segment, Measure)
- :delete-after - Optional vector of model keys that must be deleted AFTER this model.
Used to handle FK constraints during import cleanup. For example, if Card
has :delete-after [:model/Collection], Card will be deleted before Collection.
@@ -50,9 +52,16 @@
:hydrate-query - Optional custom query for joins (overrides select-fields)
:field-mappings - Map of RemoteSyncObject column -> source field or [field transform-fn]
- :removal - Removal/cleanup configuration:
- :statuses - Set of statuses to check for removal (e.g., #{\"removed\" \"delete\"})
- :scope-key - Optional key for scoping deletions (e.g., :collection_id, :id).
- If nil, deletions are global (by entity_id only).
+ :statuses - Set of statuses to check for removal (e.g., #{\"removed\" \"delete\"})
+ :scope-key - Optional key for scoping deletions (e.g., :collection_id, :id).
+ If nil, deletions are global (by entity_id only).
+ :conditions - Optional map of extra conditions for filtering removals
+ (e.g., {:built_in_type nil} to protect built-in items)
+ - :export-scope - Export scope for query-export-roots:
+ :root-collections - Query root-level remote-synced + namespace collections (Collection)
+ :root-only - Query root instances with collection_id = nil (Transform)
+ :all - Query all instances (TransformTag, PythonLibrary, NativeQuerySnippet)
+ nil/:derived - No root query; derived from other models via serdes/descendants
- :enabled? - true, or setting keyword (e.g., :remote-sync-transforms, :library-synced).
When :library-synced, uses the library-is-remote-synced? setting."
{:model/Card
@@ -617,7 +626,7 @@
;;; ---------------------------------------------- Spec Field Accessors ------------------------------------------------
-(defn select-fields-for-sync
+(defn fields-for-sync
"Returns the fields to select for a model during sync operations.
Falls back to default if not specified in spec."
[model-type-str]
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj
index 5ed4a09ab0a..4a76b5dfd41 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj
@@ -229,20 +229,20 @@
;; The actual paths are tested in impl_test.clj integration tests which verify
;; the full export/import cycle with real database entities.
-;;; --------------------------------------------- Select Fields for Sync Tests -----------------------------------------
+;;; --------------------------------------------- Fields for Sync Tests -----------------------------------------------
-(deftest select-fields-for-sync-test
- (testing "select-fields-for-sync returns spec fields"
+(deftest fields-for-sync-test
+ (testing "fields-for-sync returns spec fields"
(is (= [:name :collection_id :display]
- (spec/select-fields-for-sync "Card")))
+ (spec/fields-for-sync "Card")))
(is (= [:name :collection_id]
- (spec/select-fields-for-sync "Dashboard")))
+ (spec/fields-for-sync "Dashboard")))
(is (= [:name :collection_id]
- (spec/select-fields-for-sync "NativeQuerySnippet"))))
+ (spec/fields-for-sync "NativeQuerySnippet"))))
- (testing "select-fields-for-sync returns default for unknown type"
+ (testing "fields-for-sync returns default for unknown type"
(is (= [:id :name :collection_id]
- (spec/select-fields-for-sync "UnknownModel")))))
+ (spec/fields-for-sync "UnknownModel")))))
;;; --------------------------------------------- Export Scope Tests -------------------------------------------------
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/test_helpers.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/test_helpers.clj
index 23d071af0f8..ef3604fe310 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/test_helpers.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/test_helpers.clj
@@ -556,16 +556,9 @@ serdes/meta:
(str/replace (u/lower-case-en name) #"\s+" "_")))
(defn generate-measure-yaml
- "Generates YAML content for a measure.
-
- Args:
- measure-name: The name of the measure.
- table-name: The name of the table containing this measure.
- db-name: The name of the database containing this measure.
- agg-field-name: The name of the field to use in the aggregation clause.
-
- Returns:
- A string containing the YAML representation of the measure."
+ "Generates YAML content for a measure with the given `measure-name`, `table-name`, and `db-name`.
+ Optional keyword args include `:schema`, `:description`, `:entity-id`, and `:agg-field-name`
+ for the aggregation field. Returns a string containing the YAML representation of the measure."
[measure-name table-name db-name & {:keys [schema description entity-id agg-field-name]
:or {description "Test measure"
agg-field-name "Some Field"}}]
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-has-library-dirty-changes.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-has-library-dirty-changes.ts
index 223e9c3f6dc..d0e2777bd9e 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-has-library-dirty-changes.ts
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-has-library-dirty-changes.ts
@@ -4,10 +4,13 @@ import { useListCollectionsTreeQuery } from "metabase/api";
import { isLibraryCollection } from "metabase/collections/utils";
import { getAllDescendantIds } from "metabase/common/components/tree/utils";
import { buildCollectionTree } from "metabase/entities/collections";
+import type { CollectionId } from "metabase-types/api";
import { useGitSyncVisible } from "./use-git-sync-visible";
import { useRemoteSyncDirtyState } from "./use-remote-sync-dirty-state";
+const isNumericId = (id: CollectionId): id is number => typeof id === "number";
+
export function useHasLibraryDirtyChanges(): boolean {
const { isVisible: isGitSyncVisible } = useGitSyncVisible();
const { dirty, hasDirtyInCollectionTree, isDirty, hasRemovedItems } =
@@ -42,9 +45,7 @@ export function useHasLibraryDirtyChanges(): boolean {
const snippetsTree = buildCollectionTree(snippetsCollections);
const snippetsCollectionIds = getAllDescendantIds(snippetsTree);
const numericSnippetCollectionIds = new Set(
- [...snippetsCollectionIds].filter(
- (id): id is number => typeof id === "number",
- ),
+ [...snippetsCollectionIds].filter(isNumericId),
);
const hasSnippetDirtyChanges = dirty.some((entity) => {
@@ -75,11 +76,7 @@ export function useHasLibraryDirtyChanges(): boolean {
const libraryCollectionIds = getAllDescendantIds(libraryTree);
// Filter to only numeric IDs for the dirty check
- const numericIds = new Set(
- [...libraryCollectionIds].filter(
- (id): id is number => typeof id === "number",
- ),
- );
+ const numericIds = new Set([...libraryCollectionIds].filter(isNumericId));
return hasDirtyInCollectionTree(numericIds);
}, [
diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx
index 999168f0d73..e3072ac4db4 100644
--- a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx
+++ b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx
@@ -40,7 +40,6 @@ export const SearchInputContainer = styled.div<{
}
return css`
background-color: var(--mb-color-background-primary);
-
&:hover {
background-color: var(--mb-color-background-secondary);
}