Skip to content

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

No special Synced Collection on remote sync setup (#68499)

John Swansond950e7048297
diff --git a/e2e/support/helpers/e2e-remote-sync-helpers.ts b/e2e/support/helpers/e2e-remote-sync-helpers.ts
index 138e08bf0ff..91c209a0cdc 100644
--- a/e2e/support/helpers/e2e-remote-sync-helpers.ts
+++ b/e2e/support/helpers/e2e-remote-sync-helpers.ts
@@ -45,12 +45,14 @@ export const commitToRepo = (
export function configureGit(
syncType: "read-write" | "read-only",
syncUrl = LOCAL_GIT_PATH + "/.git",
+ collections?: Record<number, boolean>,
) {
cy.request("PUT", "/api/ee/remote-sync/settings", {
"remote-sync-branch": "main",
"remote-sync-type": syncType,
"remote-sync-url": syncUrl,
"remote-sync-enabled": true,
+ ...(collections && { collections }),
});
}
@@ -71,6 +73,21 @@ export function configureGitAndPullChanges(
}
}
+// Setup remote sync with a new synced collection in one step
+export function configureGitWithNewSyncedCollection(
+ syncType: "read-write" | "read-only",
+ collectionName = "Test Synced Collection",
+ syncUrl = LOCAL_GIT_PATH + "/.git",
+) {
+ return cy
+ .request("POST", "/api/collection", { name: collectionName })
+ .then((response) => {
+ const collection = response.body;
+ configureGit(syncType, syncUrl, { [collection.id]: true });
+ return cy.wrap(collection);
+ });
+}
+
// Prepare the local git repo and initializing with an empty commit
export function setupGitSync() {
cy.exec("rm -rf " + LOCAL_GIT_PATH);
@@ -153,7 +170,10 @@ export const updateRemoteQuestion = (
});
};
-export const moveCollectionItemToSyncedCollection = (name: string) => {
+export const moveCollectionItemToSyncedCollection = (
+ name: string,
+ targetCollection = "Synced Collection",
+) => {
navigationSidebar()
.findByRole("treeitem", { name: /Our analytics/ })
.click();
@@ -163,21 +183,24 @@ export const moveCollectionItemToSyncedCollection = (name: string) => {
entityPickerModal().within(() => {
cy.findAllByRole("tab", { name: /Browse|Collections/ }).click();
- entityPickerModalItem(1, "Synced Collection").click();
+ entityPickerModalItem(1, targetCollection).click();
cy.button("Move").click();
});
getSyncStatusIndicators().should("have.length", 1);
navigationSidebar()
- .findByRole("treeitem", { name: /Synced Collection/ })
+ .findByRole("treeitem", { name: new RegExp(targetCollection) })
.click();
collectionTable().findByText(name).should("exist");
};
-export const goToSyncedCollection = (opts?: Partial<Cypress.ClickOptions>) =>
+export const goToSyncedCollection = (
+ collectionName = "Synced Collection",
+ opts?: Partial<Cypress.ClickOptions>,
+) =>
navigationSidebar()
- .findByRole("treeitem", { name: /Synced Collection/ })
+ .findByRole("treeitem", { name: new RegExp(collectionName) })
.click(opts);
// Git sync controls are now in the app bar, not the sidebar
diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
index 29058af25b2..025bd176d66 100644
--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
@@ -26,8 +26,9 @@ describe("Remote Sync", () => {
describe("read-write Mode", () => {
it("can push and pull changes", () => {
- H.configureGitAndPullChanges("read-write");
- H.wrapSyncedCollection();
+ H.configureGitWithNewSyncedCollection("read-write").as(
+ "syncedCollection",
+ );
const UPDATED_REMOTE_QUESTION_NAME = "Updated Question Name";
cy.get("@syncedCollection").then((syncedCollection) => {
@@ -46,7 +47,7 @@ describe("Remote Sync", () => {
// Ensure that status icon is present
H.getSyncStatusIndicators().should("have.length.greaterThan", 0);
H.navigationSidebar()
- .findByRole("link", { name: /Synced Collection/ })
+ .findByRole("link", { name: /Test Synced Collection/ })
.click();
H.collectionTable().findByText(REMOTE_QUESTION_NAME).should("exist");
@@ -64,7 +65,7 @@ describe("Remote Sync", () => {
});
H.navigationSidebar()
- .findByRole("link", { name: /Synced Collection/ })
+ .findByRole("link", { name: /Test Synced Collection/ })
.findByTestId("remote-sync-status")
.should("not.exist");
@@ -92,8 +93,9 @@ describe("Remote Sync", () => {
});
it("should not allow you to move content to the Synced Collection that references non Synced Collection items", () => {
- H.configureGitAndPullChanges("read-write");
- H.wrapSyncedCollection();
+ H.configureGitWithNewSyncedCollection("read-write").as(
+ "syncedCollection",
+ );
cy.intercept("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`).as(
"updateDashboard",
);
@@ -107,7 +109,7 @@ describe("Remote Sync", () => {
H.entityPickerModal().within(() => {
H.entityPickerModalTab("Collections").click();
- H.entityPickerModalItem(1, "Synced Collection").click();
+ H.entityPickerModalItem(1, "Test Synced Collection").click();
cy.button("Move").click();
});
@@ -124,7 +126,7 @@ describe("Remote Sync", () => {
H.entityPickerModal().within(() => {
H.entityPickerModalTab("Browse").click();
- H.entityPickerModalItem(1, "Synced Collection").click();
+ H.entityPickerModalItem(1, "Test Synced Collection").click();
cy.button("Move").click();
});
@@ -236,8 +238,9 @@ describe("Remote Sync", () => {
};
it("should allow you to create new branches and switch between them", () => {
- H.configureGitAndPullChanges("read-write");
- H.wrapSyncedCollection();
+ H.configureGitWithNewSyncedCollection("read-write").as(
+ "syncedCollection",
+ );
const NEW_BRANCH_1 = `new-branch-${Date.now()}`;
const NEW_BRANCH_2 = `new-branch-${Date.now() + 1}`;
@@ -245,24 +248,30 @@ describe("Remote Sync", () => {
cy.visit("/collection/root");
H.navigationSidebar()
- .findByRole("treeitem", { name: /Synced Collection/ })
+ .findByRole("treeitem", { name: /Test Synced Collection/ })
.click();
- // Synced Synced Collection starts empty
+ // Test Synced Collection starts empty
H.collectionTable().should("not.exist");
cy.findByTestId("collection-empty-state").should("exist");
createNewBranch(NEW_BRANCH_1);
- // Move something into Synced Collection for the new branch
- H.moveCollectionItemToSyncedCollection("Orders, Count");
+ // Move something into synced collection for the new branch
+ H.moveCollectionItemToSyncedCollection(
+ "Orders, Count",
+ "Test Synced Collection",
+ );
pushUpdates();
// Go back to the main branch
createNewBranch(NEW_BRANCH_2);
- H.moveCollectionItemToSyncedCollection("Orders Model");
+ H.moveCollectionItemToSyncedCollection(
+ "Orders Model",
+ "Test Synced Collection",
+ );
H.collectionTable().findByText("Orders, Count").should("exist");
H.collectionTable().findByText("Orders Model").should("exist");
@@ -282,24 +291,29 @@ describe("Remote Sync", () => {
});
it("should show a popup when trying to switch branches with unsynced changes", () => {
- H.configureGitAndPullChanges("read-write");
+ H.configureGitWithNewSyncedCollection("read-write").as(
+ "syncedCollection",
+ );
const NEW_BRANCH = `new-branch-${Date.now()}`;
cy.visit("/collection/root");
H.navigationSidebar()
- .findByRole("treeitem", { name: /Synced Collection/ })
+ .findByRole("treeitem", { name: /Test Synced Collection/ })
.click();
- // Synced Synced Collection starts empty
+ // Test Synced Collection starts empty
H.collectionTable().should("not.exist");
cy.findByTestId("collection-empty-state").should("exist");
createNewBranch(NEW_BRANCH);
- // Move something into Synced Collection for the new branch
- H.moveCollectionItemToSyncedCollection("Orders, Count");
+ // Move something into synced collection for the new branch
+ H.moveCollectionItemToSyncedCollection(
+ "Orders, Count",
+ "Test Synced Collection",
+ );
// Attempt to go back to main
switchToExistingBranch("main");
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj
index 422587830b8..4fdbb040381 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj
@@ -182,9 +182,7 @@
(remote-sync.task/update-progress! task-id 0.8)
(t2/with-transaction [_conn]
(remove-unsynced! (spec/all-syncable-collection-ids) imported-entities-by-model)
- (sync-objects! sync-timestamp imported-entities-by-model table-paths field-paths)
- (when (and (nil? (collection/remote-synced-collection)) (= :read-write (settings/remote-sync-type)))
- (collection/create-remote-synced-collection!)))
+ (sync-objects! sync-timestamp imported-entities-by-model table-paths field-paths))
(remote-sync.task/update-progress! task-id 0.95)
(remote-sync.task/set-version!
task-id
diff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.clj
index 8b2c2b190c1..ec3380ec934 100644
--- a/src/metabase/collections/models/collection.clj
+++ b/src/metabase/collections/models/collection.clj
@@ -162,15 +162,6 @@
[]
(t2/select-one :model/Collection :is_remote_synced true :location "/"))
-(defn create-remote-synced-collection!
- "Create the remote-synced-collection"
- []
- (when-not (nil? (remote-synced-collection))
- (throw (ex-info "Remote-synced collection already exists" {})))
- (t2/insert-returning-instance! :model/Collection {:name "Synced Collection"
- :is_remote_synced true
- :location "/"}))
-
(defonce ^:dynamic ^:private *clearing-remote-sync* false)
(defn clear-remote-synced-collection!