Skip to content

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

Remove unused code (#73023)

Alexander Polyankinb23bc51a1df9
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.edn
index 920b68cd18e..ce90ad13e67 100644
--- a/.clj-kondo/config/modules/config.edn
+++ b/.clj-kondo/config/modules/config.edn
@@ -569,8 +569,7 @@
:model/Table
:model/Timeline
:model/Transform
- :model/User
- :model/Workspace}}
+ :model/User}}
collections-rest
{:team "UX West"
@@ -794,7 +793,6 @@
metabase.driver.common.parameters
metabase.driver.common.parameters.parse
metabase.driver.connection
- metabase.driver.connection.workspaces
metabase.driver.ddl.interface
metabase.driver.h2
metabase.driver.impl
@@ -2241,8 +2239,7 @@
util
warehouse-schema}
:friends #{models
- enterprise/transforms-python
- enterprise/workspaces}
+ enterprise/transforms-python}
:model-exports #{:model/Transform
:model/TransformJob
:model/TransformJobTransformTag
@@ -2276,8 +2273,7 @@
util
warehouse-schema}
:friends #{transforms
- enterprise/transforms-python
- enterprise/workspaces}}
+ enterprise/transforms-python}}
transforms-inspector
{:team "Gadget"
@@ -2299,8 +2295,7 @@
:model/TransformJob
:model/TransformJobTransformTag
:model/TransformRun
- :model/TransformTag
- :model/WorkspaceMergeTransform}}
+ :model/TransformTag}}
types
{:team "Querying Platform"
@@ -2561,10 +2556,6 @@
:model/Field
:model/Table}}
- workspaces
- {:team "Metabot"
- :uses #{util}}
-
xrays
{:team "Graphy"
:api #{metabase.xrays.api
@@ -2898,7 +2889,6 @@
transforms
transforms-base
util}
- :model-exports #{:model/Dependency}
:model-imports #{:model/Card
:model/Collection
:model/Dashboard
@@ -3325,8 +3315,7 @@
{:team "Graphy"
:api #{metabase-enterprise.transforms-python.api
metabase-enterprise.transforms-python.core
- metabase-enterprise.transforms-python.init
- metabase-enterprise.transforms-python.python-runner}
+ metabase-enterprise.transforms-python.init}
:uses #{analytics
api
app-db
@@ -3360,37 +3349,8 @@
enterprise/workspaces
{:team "Metabot"
- :api #{metabase-enterprise.workspaces.api
- metabase-enterprise.workspaces.init}
- :model-exports #{:model/Workspace :model/WorkspaceMergeTransform}
- :uses #{api
- api-scope
- app-db
- config
- database-routing
- driver
- events
- lib
- lib-be
- models
- premium-features
- queries
- ;; NOTE: we will remove this once we get "pure transforms" module.
- query-processor
- request
- settings
- sql-tools
- transforms
- transforms-base
- util
- warehouse-schema
- enterprise/transforms-python}
- :model-imports #{:model/Collection
- :model/Database
- :model/Dependency
- :model/Field
- :model/Table
- :model/Transform}}
+ :api #{}
+ :uses #{premium-features}}
enterprise/writable-connection
{:team "Graphy"
diff --git a/e2e/support/helpers/e2e-codemirror-helpers.ts b/e2e/support/helpers/e2e-codemirror-helpers.ts
index ffcfc814001..1166b350f1d 100644
--- a/e2e/support/helpers/e2e-codemirror-helpers.ts
+++ b/e2e/support/helpers/e2e-codemirror-helpers.ts
@@ -16,8 +16,6 @@ export function codeMirrorHelpers<T extends object>(testId: string, extra: T) {
helpers.get().should("be.visible").click("right", {
/**
* We want to click on the right, because we want the caret to be positioned at the end of the editor.
- * Transform editor in workspaces (data studio) has a resize handle at the right of the editor,
- * which causes this click("right") to fail.
* Alternative approach with pressing End key for moving the caret to the end made
* repro for (metabase#49882-2, metabase#15892) fail in CI every time.
* Hence force: true.
diff --git a/e2e/support/helpers/e2e-data-studio-helpers.ts b/e2e/support/helpers/e2e-data-studio-helpers.ts
index 07a5ca15559..ee1d2e247de 100644
--- a/e2e/support/helpers/e2e-data-studio-helpers.ts
+++ b/e2e/support/helpers/e2e-data-studio-helpers.ts
@@ -24,26 +24,8 @@ export const DataStudio = {
list: () => cy.findByTestId("transforms-list"),
saveChangesButton: () => DataStudio.Transforms.queryEditor().button("Save"),
editTransform: () => cy.findByRole("button", { name: "Edit" }),
- editDefinitionButton: () =>
- cy.get(
- '[data-testid="edit-definition-button"], [data-testid="transform-edit-menu-button"]',
- ),
- getEditDefinitionLink: () => {
- // When workspaces are available, "Edit definition" is inside the "Edit" menu
- // When workspaces are not available, "Edit definition" is a direct link
- return DataStudio.Transforms.editDefinitionButton()
- .first()
- .then(($el) => {
- if ($el.attr("data-testid") === "edit-definition-button") {
- return cy.wrap($el);
- } else {
- cy.wrap($el).click();
- return popover().findByRole("menuitem", {
- name: /Edit definition/,
- });
- }
- });
- },
+ editDefinitionButton: () => cy.findByTestId("edit-definition-button"),
+ getEditDefinitionLink: () => DataStudio.Transforms.editDefinitionButton(),
clickEditDefinition: () => {
DataStudio.Transforms.getEditDefinitionLink().click();
},
diff --git a/e2e/support/helpers/e2e-workspaces-helpers.ts b/e2e/support/helpers/e2e-workspaces-helpers.ts
deleted file mode 100644
index 722243252dc..00000000000
--- a/e2e/support/helpers/e2e-workspaces-helpers.ts
+++ /dev/null
@@ -1,149 +0,0 @@
-import type { WorkspaceId } from "metabase-types/api";
-
-export const Workspaces = {
- visit: (id: WorkspaceId) => {
- return cy.visit(`/data-studio/workspace/${id}`);
- },
-
- visitDataStudio() {
- return cy.visit("/data-studio");
- },
-
- visitWorkspaces() {
- return cy.visit("/data-studio/workspaces");
- },
-
- visitTransformListPage() {
- return cy.visit("/data-studio/transforms");
- },
-
- getWorkspacesPage() {
- return cy.findByTestId("workspaces-page");
- },
-
- getWorkspacePage() {
- return cy.findByTestId("workspace-page");
- },
-
- getWorkspaceContent() {
- return cy.findByTestId("workspace-content");
- },
-
- getWorkspaceTabs() {
- return cy.findByTestId("workspace-tabs");
- },
-
- getWorkspaceSidebar() {
- return cy.findByTestId("workspace-sidebar");
- },
-
- openSetupTab() {
- this.getWorkspaceContent().findByRole("tab", { name: "Setup" }).click();
- },
-
- openCodeTab() {
- this.getWorkspaceSidebar().findByRole("tab", { name: "Code" }).click();
- },
-
- openDataTab() {
- this.getWorkspaceSidebar().findByRole("tab", { name: "Data" }).click();
- },
-
- openGraphTab() {
- this.getWorkspaceContent().findByRole("tab", { name: "Graph" }).click();
- },
-
- getWorkspacesSection() {
- return cy.findByTestId("workspaces-section");
- },
-
- getWorkspaceItem(name: string) {
- return this.getWorkspacesSection().find(`a[name="${name}"]`);
- },
-
- getWorkspaceItemStatus(name: string) {
- return this.getWorkspaceItem(name).findByTestId("workspace-status");
- },
-
- getWorkspaceItemActions(name: string) {
- return this.getWorkspaceItem(name).findByLabelText("More actions");
- },
-
- getWorkspaceNameInput() {
- return cy.findByPlaceholderText("Workspace name");
- },
-
- getRunAllTransformsButton() {
- return cy.findByTestId("run-all-button");
- },
-
- getMergeWorkspaceButton() {
- return cy.findByRole("button", { name: /Merge/ });
- },
-
- getMergeCommitInput() {
- return cy.findByPlaceholderText(
- "Describe the changes you made in this workspace...",
- );
- },
-
- getWorkspaceDatabaseSelect() {
- return cy.findByPlaceholderText("Select a database");
- },
-
- getTransformTabHeader() {
- return cy.findByTestId("transform-tab-header");
- },
-
- getTransformTargetButton() {
- return this.getTransformTabHeader().findByRole("button", {
- name: /Change target/,
- });
- },
-
- getRunTransformButton() {
- return this.getTransformTabHeader().findByTestId("run-button", {
- timeout: 10_000,
- });
- },
-
- getRunStatus() {
- return cy.findByTestId("run-status");
- },
-
- getSaveTransformButton() {
- return this.getTransformTabHeader().findByRole("button", { name: /Save/ });
- },
-
- getWorkspaceTransforms() {
- return cy.findByTestId("workspace-transforms");
- },
-
- getMainlandTransforms() {
- return cy.findByTestId("mainland-transforms", { timeout: 10_000 });
- },
-
- getNewWorkspaceButton() {
- return cy.findByRole("button", { name: /New workspace/ });
- },
-
- getNewWorkspaceNameInput() {
- return cy.findByPlaceholderText("Enter workspace name");
- },
-
- getNewWorkspaceDatabaseInput() {
- return cy.findByPlaceholderText("Select a database");
- },
-
- getTransformStatusDot(name: string | RegExp) {
- return cy.findByText(name).parent().findByTestId("status-dot");
- },
-
- getTransformTargetDiff() {
- return cy.findByTestId("transform-target-diff");
- },
-
- getSourceTablesDiff() {
- return cy.findByTestId("source-tables-diff");
- },
-};
diff --git a/e2e/support/helpers/index.ts b/e2e/support/helpers/index.ts
index 6a6e1b64400..fb1a7a1cd77 100644
--- a/e2e/support/helpers/index.ts
+++ b/e2e/support/helpers/index.ts
@@ -62,5 +62,4 @@ export * from "./e2e-upload-helpers";
export * from "./e2e-users-helpers";
export * from "./e2e-visual-tests-helpers";
export * from "./e2e-viz-settings-helpers";
-export * from "./e2e-workspaces-helpers";
export * from "./embedding-sdk-helpers/constants";
diff --git a/e2e/support/timings.json b/e2e/support/timings.json
index 858267b62bb..6cd8aaf2a7e 100644
--- a/e2e/support/timings.json
+++ b/e2e/support/timings.json
@@ -700,14 +700,6 @@
"spec": "../test/scenarios/data-studio/transforms/transforms.cy.spec.ts",
"duration": 488066
},
- {
- "spec": "../test/scenarios/data-studio/workspaces-metabot.cy.spec.ts",
- "duration": 63
- },
- {
- "spec": "../test/scenarios/data-studio/workspaces.cy.spec.ts",
- "duration": 262450
- },
{
"spec": "../test/scenarios/dependencies/dependency-broken-list.cy.spec.ts",
"duration": 60514
diff --git a/e2e/test/scenarios/admin/database-routing/database-routing-admin.cy.spec.ts b/e2e/test/scenarios/admin/database-routing/database-routing-admin.cy.spec.ts
index 1c22c4c227a..75ef4c71371 100644
--- a/e2e/test/scenarios/admin/database-routing/database-routing-admin.cy.spec.ts
+++ b/e2e/test/scenarios/admin/database-routing/database-routing-admin.cy.spec.ts
@@ -532,43 +532,6 @@ describe("admin > database > database routing", () => {
});
});
- describe("workspaces", () => {
- it("should not be possible to workspaces routing when database routing is are enabled", () => {
- configureDbRoutingViaAPI({
- router_database_id: WRITABLE_DB_ID,
- user_attribute: "role",
- });
-
- visitDatabaseAdminPage(WRITABLE_DB_ID);
-
- workspacesSection().within(() => {
- cy.findByLabelText("Enable workspaces").should("be.disabled");
- cy.findByText(
- "Workspaces can't be enabled when database routing is enabled.",
- )
- .scrollIntoView()
- .should("be.visible");
- });
- });
-
- it("should not be possible to enable database routing when workspaces are enabled", () => {
- visitDatabaseAdminPage(WRITABLE_DB_ID);
-
- workspacesSection()
- .findByLabelText("Enable workspaces")
- .click({ force: true });
-
- dbRoutingSection().within(() => {
- cy.findByLabelText("Enable database routing").should("be.disabled");
- cy.findByText(
- "Database routing can't be enabled when workspaces are enabled.",
- )
- .scrollIntoView()
- .should("be.visible");
- });
- });
- });
-
describe("Table editing", () => {
it("should not be possible to enable table editing when database routing is enabled", () => {
configureDbRoutingViaAPI({
@@ -720,10 +683,6 @@ function enableGlobalModelPersistence() {
cy.findByLabelText("Disabled").click();
}
-function workspacesSection() {
- return cy.findByTestId("database-workspaces-section");
-}
-
function tableEditingSection() {
return cy.findByTestId("database-table-editing-section");
}
diff --git a/e2e/test/scenarios/admin/databases.cy.spec.js b/e2e/test/scenarios/admin/databases.cy.spec.js
index bec1089c8c9..1e161156f88 100644
--- a/e2e/test/scenarios/admin/databases.cy.spec.js
+++ b/e2e/test/scenarios/admin/databases.cy.spec.js
@@ -40,110 +40,6 @@ describe(
},
);
-describe(
- "admin > database > external databases > workspaces",
- { tags: ["@external"] },
- () => {
- beforeEach(() => {
- cy.intercept("POST", "/api/database/*/permission/workspace/check").as(
- "checkPermissions",
- );
- });
-
- [
- { dbName: "Writable Postgres12", snapshot: "postgres-writable" },
- { dbName: "Writable MySQL8", snapshot: "mysql-writable" },
- ].forEach(({ dbName, snapshot }) => {
- it(`should allow to enable and disable workspaces in ${snapshot} database`, () => {
- H.restore(snapshot);
- cy.signInAsAdmin();
- H.activateToken("pro-self-hosted");
- H.addPostgresDatabase("Test DB");
-
- visitDatabase(WRITABLE_DB_ID);
-
- cy.findByLabelText("Enable workspaces").should("not.be.checked");
- cy.findByLabelText("Enable workspaces").parent().click();
-
- cy.wait("@checkPermissions");
- cy.findByLabelText("Enable workspaces").should("be.checked");
-
- cy.findByLabelText("Settings").click();
- H.popover().findByText("Data studio").click();
- H.Workspaces.getNewWorkspaceButton().click();
- cy.findByPlaceholderText("Select a database").click();
- H.popover().within(() => {
- cy.findByText(dbName).should("be.visible");
- cy.findByText("Test DB").should("not.exist");
- });
-
- cy.go(-2);
- cy.findByLabelText("Enable workspaces").should("be.checked");
- cy.findByLabelText("Enable workspaces").parent().click();
- cy.findByLabelText("Enable workspaces").should("not.be.checked");
-
- cy.go(2);
- cy.findByPlaceholderText("No database supports workspaces").should(
- "be.visible",
- );
- });
- });
-
- it("should not show workspaces setting for unsupported mysql database", () => {
- H.restore();
- cy.signInAsAdmin();
- H.activateToken("pro-self-hosted");
-
- visitDatabase(WRITABLE_DB_ID);
-
- cy.findByLabelText("Enable workspaces").should("not.exist");
- cy.findByRole("heading", { name: "Not found." }).should("exist");
- });
-
- it("should not allow to enable workspaces for a db user that cannot create users/schemas", () => {
- H.restore("postgres-writable");
- cy.signInAsAdmin();
- H.activateToken("pro-self-hosted");
-
- // Create a limited postgres user without CREATE USER/SCHEMA permissions
- const limitedUser = "limited_user";
- const limitedPassword = "limited_pass";
-
- H.queryWritableDB(`
- DROP USER IF EXISTS ${limitedUser};
- CREATE USER ${limitedUser} WITH PASSWORD '${limitedPassword}';
- `);
-
- // Update the existing database connection to use the limited user
- cy.request("PUT", `/api/database/${WRITABLE_DB_ID}`, {
- details: {
- host: "localhost",
- port: QA_POSTGRES_PORT,
- dbname: "writable_db",
- user: limitedUser,
- password: limitedPassword,
- },
- });
-
- visitDatabase(WRITABLE_DB_ID);
-
- cy.findByLabelText("Enable workspaces").should("not.be.checked");
- cy.findByLabelText("Enable workspaces").parent().click();
-
- cy.wait("@checkPermissions");
-
- cy.findByTestId("database-workspaces-section").should(
- "contain.text",
- "Failed to initialize workspace isolation",
- );
- cy.findByLabelText("Enable workspaces").should("not.be.checked");
-
- // Cleanup: just drop the postgres user, H.restore() resets the DB connection
- H.queryWritableDB(`DROP USER IF EXISTS ${limitedUser};`);
- });
- },
-);
-
describe("admin > database > add", () => {
function toggleFieldWithDisplayName(displayName) {
cy.findByLabelText(new RegExp(displayName)).click({ force: true });
diff --git a/e2e/test/scenarios/data-studio/workspaces-metabot.cy.spec.ts b/e2e/test/scenarios/data-studio/workspaces-metabot.cy.spec.ts
deleted file mode 100644
index 8aafc25ffb0..00000000000
--- a/e2e/test/scenarios/data-studio/workspaces-metabot.cy.spec.ts
+++ /dev/null
@@ -1,433 +0,0 @@
-import { WRITABLE_DB_ID } from "e2e/support/cypress_data";
-
-const { H } = cy;
-const { Workspaces } = H;
-
-const SOURCE_TABLE = "Animals";
-
-// temporarily disabled, should be enabled in upcoming iteration
-describe.skip("scenarios > data studio > workspaces > metabot", () => {
- beforeEach(() => {
- H.restore("postgres-writable");
- H.resetTestTable({ type: "postgres", table: "many_schemas" });
- H.resetSnowplow();
- cy.signInAsAdmin();
- H.activateToken("pro-self-hosted");
- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: SOURCE_TABLE });
-
- cy.request("PUT", "/api/permissions/graph", {
- groups: {
- "1": {
- "1": { download: { schemas: "full" }, "view-data": "unrestricted" },
- "2": {
- "view-data": "unrestricted",
- download: { schemas: "full" },
- "create-queries": "query-builder-and-native",
- },
- },
- },
- revision: 1,
- sandboxes: [],
- impersonations: [],
- });
-
- cy.intercept("POST", "/api/ee/workspace").as("createWorkspace");
- cy.intercept("POST", "/api/metabot/agent-streaming").as("agentReq");
- });
-
- it("should be able to create a transform via metabot in workspace", () => {
- Workspaces.visitWorkspaces();
-
- cy.log("Create a new workspace");
- Workspaces.getNewWorkspaceButton().click();
- cy.wait("@createWorkspace");
-
- cy.log("Open the Agent Chat tab");
- cy.findByRole("tab", { name: "Agent Chat" }).click();
-
- cy.log("Verify metabot chat is visible");
- cy.findByTestId("metabot-chat").should("be.visible");
-
- cy.log("Send a message to metabot asking to create a transform");
- H.mockMetabotResponse({
- body: createMockTransformSuggestionResponse(
- "I'll create a SQL transform that selects all animals for you.",
- createMockNativeTransformJSON(
- null,
- WRITABLE_DB_ID,
- 'SELECT * FROM "Schema A"."Animals"',
- ),
- ),
- });
- H.sendMetabotMessage("Create a SQL transform that selects all animals");
-
- cy.log("Verify the suggestion appears in the chat");
- cy.findByTestId("metabot-chat-suggestion").should("be.visible");
- cy.findByTestId("metabot-chat-suggestion").should(
- "contain",
- 'SELECT * FROM "Schema A"."Animals"',
- );
-
- cy.log("Apply the suggestion to create the transform");
- cy.findByTestId("metabot-chat-suggestion")
- .findByRole("button", { name: /create/i })
- .click();
-
- cy.log("Verify transform tab is opened with the suggested code");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("New transform", [
- "Setup",
- "Agent Chat",
- "Graph",
- "New transform",
- ]);
- });
- H.NativeEditor.get().should("contain", "SELECT * FROM");
-
- cy.log("Verify the transform appears in the workspace transforms list");
- Workspaces.getWorkspaceTransforms()
- .findByText("New transform")
- .should("be.visible");
-
- cy.log("Accept the suggested transform");
- cy.findByTestId("accept-proposed-changes-button").click();
-
- cy.log("Run preview to verify the transform works");
- cy.findByTestId("run-button").click();
-
- cy.log("Verify preview tab opens with results");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("Preview (New transform)", [
- "Setup",
- "Agent Chat",
- "Graph",
- "New transform",
- "Preview (New transform)",
- ]);
- });
- H.assertTableData({
- columns: ["name", "score"],
- firstRows: [
- ["Duck", "10"],
- ["Horse", "20"],
- ["Cow", "30"],
- ],
- });
-
- cy.log("Save the transform with a name and target table");
- cy.findByRole("tab", { name: "New transform" }).click();
- Workspaces.getSaveTransformButton().click();
-
- const transformName = "My transform";
- H.modal().within(() => {
- cy.findByLabelText(/Name/).clear().type(transformName);
- cy.findByLabelText(/Table name/)
- .clear()
- .type("animals_transform");
- cy.findByLabelText("Schema").click();
- cy.document()
- .findByRole("option", { name: /Schema A/ })
- .click();
- cy.findByRole("button", { name: /Save/ }).click();
- });
- verifyAndCloseToast("Transform saved successfully");
-
- cy.log("Verify the saved transform appears in workspace transforms list");
- Workspaces.getWorkspaceTransforms()
- .findByText(transformName)
- .should("be.visible");
-
- cy.log("Run the transform to materialize the output table");
- Workspaces.getRunTransformButton().click();
- Workspaces.getRunTransformButton().should("have.text", "Ran successfully");
-
- cy.log("Verify the target table appears in the Data tab");
- Workspaces.openDataTab();
- Workspaces.getWorkspaceSidebar()
- .findByText("Schema A.animals_transform")
- .should("be.visible");
- });
-
- it("should be able to reject a metabot suggestion and keep the editor empty", () => {
- Workspaces.visitWorkspaces();
-
- cy.log("Create a new workspace");
- Workspaces.getNewWorkspaceButton().click();
- cy.wait("@createWorkspace");
-
- cy.log("Open the Agent Chat tab");
- cy.findByRole("tab", { name: "Agent Chat" }).click();
-
- cy.log("Verify metabot chat is visible");
- cy.findByTestId("metabot-chat").should("be.visible");
-
- cy.log("Send a message to metabot asking to create a transform");
- H.mockMetabotResponse({
- body: createMockTransformSuggestionResponse(
- "I'll create a SQL transform that selects all animals for you.",
- createMockNativeTransformJSON(
- null,
- WRITABLE_DB_ID,
- 'SELECT * FROM "Schema A"."Animals"',
- ),
- ),
- });
- H.sendMetabotMessage("Create a SQL transform that selects all animals");
-
- cy.log("Verify the suggestion appears in the chat");
- cy.findByTestId("metabot-chat-suggestion").should("be.visible");
-
- cy.log("Apply the suggestion to create the transform");
- cy.findByTestId("metabot-chat-suggestion")
- .findByRole("button", { name: /create/i })
- .click();
-
- cy.log("Verify transform tab is opened with the suggested code");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("New transform", [
- "Setup",
- "Agent Chat",
- "Graph",
- "New transform",
- ]);
- });
- H.NativeEditor.get().should("contain", "SELECT * FROM");
-
- cy.log("Reject the suggested transform");
- cy.findByTestId("reject-proposed-changes-button").click();
-
- cy.log("Verify the editor is now empty after rejection");
- H.NativeEditor.value().should("be.empty");
-
- cy.log("Verify accept/reject buttons are no longer visible");
- cy.findByTestId("accept-proposed-changes-button").should("not.exist");
- cy.findByTestId("reject-proposed-changes-button").should("not.exist");
-
- cy.log("Verify save button is disabled since editor is empty");
- Workspaces.getSaveTransformButton().should("be.disabled");
-
- cy.log("Verify the transform still appears in workspace list as unsaved");
- Workspaces.getWorkspaceTransforms()
- .findByText("New transform")
- .should("be.visible");
- });
-
- it(
- "should be able to create a Python transform via metabot in workspace",
- { tags: ["@python"] },
- () => {
- Workspaces.visitWorkspaces();
-
- cy.log("Create a new workspace");
- Workspaces.getNewWorkspaceButton().click();
- cy.wait("@createWorkspace");
-
- cy.log("Open the Agent Chat tab");
- cy.findByRole("tab", { name: "Agent Chat" }).click();
-
- cy.log("Verify metabot chat is visible");
- cy.findByTestId("metabot-chat").should("be.visible");
-
- cy.log("Send a message to metabot asking to create a Python transform");
- H.mockMetabotResponse({
- body: createMockTransformSuggestionResponse(
- "I'll create a Python transform that returns a simple DataFrame.",
- createMockPythonTransformJSON(
- null,
- WRITABLE_DB_ID,
- {},
- "import pandas as pd\\n\\ndef transform():\\n return pd.DataFrame({'message': ['Hello from Python!']})",
- ),
- ),
- });
- H.sendMetabotMessage("Create a Python transform that returns a greeting");
-
- cy.log("Verify the suggestion appears in the chat");
- cy.findByTestId("metabot-chat-suggestion").should("be.visible");
- cy.findByTestId("metabot-chat-suggestion").should(
- "contain",
- "Hello from Python!",
- );
-
- cy.log("Apply the suggestion to create the transform");
- cy.findByTestId("metabot-chat-suggestion")
- .findByRole("button", { name: /create/i })
- .click();
-
- cy.log("Verify transform tab is opened with the suggested code");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("New transform", [
- "Setup",
- "Agent Chat",
- "Graph",
- "New transform",
- ]);
- });
- H.PythonEditor.get().should("contain", "Hello from Python!");
-
- cy.log("Verify the transform appears in the workspace transforms list");
- Workspaces.getWorkspaceTransforms()
- .findByText("New transform")
- .should("be.visible");
-
- cy.log("Accept the suggested transform");
- cy.findByTestId("accept-proposed-changes-button").click();
-
- cy.log("Run preview to verify the transform works");
- cy.findByTestId("run-button").click();
-
- cy.log("Verify preview tab opens with results");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("Preview (New transform)", [
- "Setup",
- "Agent Chat",
- "Graph",
- "New transform",
- "Preview (New transform)",
- ]);
- });
- H.assertTableData({
- columns: ["message"],
- firstRows: [["Hello from Python!"]],
- });
-
- cy.log("Save the transform with a name and target table");
- cy.findByRole("tab", { name: "New transform" }).click();
- Workspaces.getSaveTransformButton().click();
-
- const transformName = "My Python transform";
- H.modal().within(() => {
- cy.findByLabelText(/Name/).clear().type(transformName);
- cy.findByLabelText(/Table name/)
- .clear()
- .type("python_transform");
- cy.findByLabelText("Schema").click();
- cy.document()
- .findByRole("option", { name: /Schema A/ })
- .click();
- cy.findByRole("button", { name: /Save/ }).click();
- });
- verifyAndCloseToast("Transform saved successfully");
-
- cy.log("Verify the saved transform appears in workspace transforms list");
- Workspaces.getWorkspaceTransforms()
- .findByText(transformName)
- .should("be.visible");
-
- cy.log("Run the transform to materialize the output table");
- Workspaces.getRunTransformButton().click();
- Workspaces.getRunTransformButton().should(
- "have.text",
- "Ran successfully",
- );
-
- cy.log("Verify the target table appears in the Data tab");
- Workspaces.openDataTab();
- Workspaces.getWorkspaceSidebar()
- .findByText("Schema A.python_transform")
- .should("be.visible");
- },
- );
-
- it(
- "should be able to reject a Python metabot suggestion and keep the editor with default template",
- { tags: ["@python"] },
- () => {
- Workspaces.visitWorkspaces();
-
- cy.log("Create a new workspace");
- Workspaces.getNewWorkspaceButton().click();
- cy.wait("@createWorkspace");
-
- cy.log("Open the Agent Chat tab");
- cy.findByRole("tab", { name: "Agent Chat" }).click();
-
- cy.log("Verify metabot chat is visible");
- cy.findByTestId("metabot-chat").should("be.visible");
-
- cy.log("Send a message to metabot asking to create a Python transform");
- H.mockMetabotResponse({
- body: createMockTransformSuggestionResponse(
- "I'll create a Python transform that returns a simple DataFrame.",
- createMockPythonTransformJSON(
- null,
- WRITABLE_DB_ID,
- {},
- "import pandas as pd\\n\\ndef transform():\\n return pd.DataFrame({'message': ['Hello from Python!']})",
- ),
- ),
- });
- H.sendMetabotMessage("Create a Python transform that returns a greeting");
-
- cy.log("Verify the suggestion appears in the chat");
- cy.findByTestId("metabot-chat-suggestion").should("be.visible");
-
- cy.log("Apply the suggestion to create the transform");
- cy.findByTestId("metabot-chat-suggestion")
- .findByRole("button", { name: /create/i })
- .click();
-
- cy.log("Verify transform tab is opened with the suggested code");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("New transform", [
- "Setup",
- "Agent Chat",
- "Graph",
- "New transform",
- ]);
- });
- H.PythonEditor.get().should("contain", "Hello from Python!");
-
- cy.log("Reject the suggested transform");
- cy.findByTestId("reject-proposed-changes-button").click();
-
- cy.log(
- "Verify the editor has default Python template after rejection (not the suggestion)",
- );
- H.PythonEditor.get().should("not.contain", "Hello from Python!");
- H.PythonEditor.get().should("contain", "Your transformation function");
-
- cy.log("Verify accept/reject buttons are no longer visible");
- cy.findByTestId("accept-proposed-changes-button").should("not.exist");
- cy.findByTestId("reject-proposed-changes-button").should("not.exist");
-
- cy.log("Verify the transform still appears in workspace list as unsaved");
- Workspaces.getWorkspaceTransforms()
- .findByText("New transform")
- .should("be.visible");
- },
- );
-});
-
-function createMockNativeTransformJSON(
- id: number | null,
- databaseId: number,
- sql: string,
-) {
- const escapedSql = sql.replace(/"/g, '\\"');
- return `{"id":${id},"name":"New transform","entity_id":null,"description":"","source":{"type":"query","query":{"database":${databaseId},"type":"native","native":{"query":"${escapedSql}","template-tags":{}}}},"target":{"type":"table","name":""},"created_at":null,"updated_at":null}`;
-}
-
-function createMockPythonTransformJSON(
- id: number | null,
- databaseId: number,
- sourceTables: { [tableName: string]: number },
- body: string,
-) {
- return `{"id":${id},"name":"New transform","entity_id":null,"description":"","source":{"type":"python","source-database":${databaseId},"source-tables":${JSON.stringify(sourceTables)},"body":"${body}"},"target":{"type":"table","name":""},"created_at":null,"updated_at":null}`;
-}
-
-function createMockTransformSuggestionResponse(
- text: string,
- transformJSON: string,
-) {
- return `0:"${text}"
-2:{"type":"transform_suggestion","version":1,"value":${transformJSON}}
-2:{"type":"state","version":1,"value":{}}
-d:{"finishReason":"stop","usage":{}}`;
-}
-
-function verifyAndCloseToast(message: string) {
- H.undoToast().should("contain.text", message);
- H.undoToast().icon("close").click();
-}
diff --git a/e2e/test/scenarios/data-studio/workspaces.cy.spec.ts b/e2e/test/scenarios/data-studio/workspaces.cy.spec.ts
deleted file mode 100644
index c51bce8a418..00000000000
--- a/e2e/test/scenarios/data-studio/workspaces.cy.spec.ts
+++ /dev/null
@@ -1,2662 +0,0 @@
-import dedent from "ts-dedent";
-
-import { WRITABLE_DB_ID } from "e2e/support/cypress_data";
-import { NativeEditor } from "e2e/support/helpers";
-import type {
- DatabaseId,
- PythonTransformTableAliases,
- TransformId,
- TransformTagId,
- WorkspaceRunResponse,
-} from "metabase-types/api";
-
-const { H } = cy;
-const { DataStudio, Workspaces } = H;
-const { Transforms } = DataStudio;
-
-const SOURCE_TABLE = "Animals";
-const TARGET_TABLE_MBQL = "transform_table_1";
-const TARGET_TABLE_SQL = "transform_table_2";
-const TARGET_TABLE_PYTHON = "transform_table_3";
-const TARGET_SCHEMA = "Schema A";
-
-const COLOR_TEXT = "rgba(7, 23, 34, 0.84)";
-const COLOR_SUCCESS = "rgb(104, 151, 53)";
-const COLOR_DANGER = "rgb(227, 89, 94)";
-
-describe("scenarios > data studio > workspaces", () => {
- beforeEach(() => {
- H.restore("postgres-writable");
- H.resetTestTable({ type: "postgres", table: "many_schemas" });
- H.resetSnowplow();
- cy.signInAsAdmin();
- H.activateToken("pro-self-hosted");
- H.updateSetting("transforms-enabled", true);
- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: SOURCE_TABLE });
-
- // TODO (Stas 2025-12-31) -- Is this correct way to grant querying permissions?
- cy.request("PUT", "/api/permissions/graph", {
- groups: {
- "1": {
- "1": { download: { schemas: "full" }, "view-data": "unrestricted" },
- "2": {
- "view-data": "unrestricted",
- download: { schemas: "full" },
- "create-queries": "query-builder-and-native",
- },
- },
- },
- revision: 1,
- sandboxes: [],
- impersonations: [],
- });
-
- enableWorkspacesInDb(WRITABLE_DB_ID);
-
- cy.intercept("POST", "/api/ee/workspace").as("createWorkspace");
- cy.intercept("POST", "/api/ee/workspace/*/transform/*/run").as(
- "runTransform",
- );
- cy.intercept("POST", "/api/ee/workspace/*/run").as("runTransforms");
- cy.intercept("POST", "/api/dataset").as("dataset");
- });
-
- describe("should be able to create, navigate, archive, unarchive, rename, and delete workspaces", () => {
- it("creates, navigates, archives, renames and deletes workspaces", () => {
- Workspaces.visitWorkspaces();
- Workspaces.getWorkspacesPage()
- .findByText("No active workspaces")
- .should("be.visible");
-
- cy.log("Properly shows empty state.");
- Workspaces.getWorkspacesSection()
- .findByText("No workspaces yet")
- .should("be.visible");
-
- createWorkspace();
- registerWorkspaceAliasName("workspaceNameA");
-
- cy.log("Navigates to available workspace page.");
- Workspaces.visitWorkspaces();
- cy.location("pathname").should("match", /data-studio\/workspaces\/\d+/);
-
- cy.log("Shows workspace name");
- cy.get("@workspaceNameA").then((workspaceName) => {
- Workspaces.getWorkspaceNameInput().should("have.value", workspaceName);
- });
- Workspaces.getMergeWorkspaceButton().should("be.disabled");
-
- Workspaces.getWorkspaceContent().within(() => {
- cy.log("Starts on setup tab, and has only 2 tabs");
- H.tabsShouldBe("Setup", ["Setup", "Graph"]);
-
- cy.log("shows workspace db");
- Workspaces.getWorkspaceDatabaseSelect()
- .should("have.value", "Writable Postgres12")
- .should("be.enabled");
-
- cy.log("Doesn't show workspace setup logs");
- cy.findByText("Setting up the workspace").should("not.exist");
- });
-
- Workspaces.getWorkspaceSidebar().within(() => {
- cy.log("starts on Code tab, and has only 2 tabs");
- H.tabsShouldBe("Code", ["Code", "Data"]);
-
- cy.log("shows transforms lists");
- cy.findByText("Workspace is empty").should("be.visible");
- cy.findByText("No available transforms").should("be.visible");
- });
-
- createWorkspace();
- registerWorkspaceAliasName("workspaceNameB");
- cy.get<string>("@workspaceNameB").then((workspaceNameB) => {
- Workspaces.getWorkspaceNameInput().should("have.value", workspaceNameB);
-
- cy.get<string>("@workspaceNameA").then((workspaceNameA) => {
- Workspaces.getWorkspacesSection().within(() => {
- cy.findByText(workspaceNameB).should("be.visible");
- cy.findByText(workspaceNameA).should("be.visible").click();
- });
-
- cy.log("can archive a workspace");
- Workspaces.getWorkspaceItemStatus(workspaceNameA).should(
- "contain.text",
- "Ready",
- );
- Workspaces.getWorkspaceItemActions(workspaceNameA).click();
- H.popover().findByText("Delete").should("not.exist");
- H.popover().findByText("Archive").click();
- verifyAndCloseToast("Workspace archived successfully");
- cy.log("Updates setup logs (GDGT-1583)");
- Workspaces.getWorkspaceContent()
- .findByText("Workspace is archived")
- .should("be.visible");
-
- cy.log("shows archived workspaces and their status");
- Workspaces.getWorkspaceItem(workspaceNameA).should(
- "contain.text",
- "Archived",
- );
-
- cy.log("can delete a workspace");
- Workspaces.getWorkspaceItemActions(workspaceNameA).click();
- H.popover().findByText("Delete").click();
- H.modal().findByText("Delete").click();
- verifyAndCloseToast("Workspace deleted successfully");
- Workspaces.getWorkspaceItem(workspaceNameA).should("not.exist");
-
- cy.location("pathname").should(
- "match",
- /data-studio\/workspaces\/\d+/,
- );
- Workspaces.getWorkspaceNameInput().should(
- "have.value",
- workspaceNameB,
- );
-
- Workspaces.getWorkspaceNameInput()
- .clear()
- .type("Renamed workspace")
- .blur();
- verifyAndCloseToast("Workspace renamed successfully");
- Workspaces.getWorkspaceItem("Renamed workspace").should("be.visible");
- });
- });
- });
-
- it("shows unsaved changes warning", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- H.NativeEditor.type(" LIMIT 2");
-
- cy.log("try to navigate away with unsaved changes - cancel navigation");
- DataStudio.nav().findByText("Glossary").click();
- H.modal().findByText("Discard your changes?").should("be.visible");
- H.modal().button("Cancel").click();
-
- Workspaces.getSaveTransformButton().click();
- Workspaces.getSaveTransformButton().should("be.disabled");
-
- cy.log("try to navigate away without unsaved changes");
- DataStudio.nav().findByText("Glossary").click();
- H.modal().should("not.exist");
- cy.location("pathname").should("eq", "/data-studio/glossary");
- cy.go("back");
-
- Workspaces.getWorkspaceTransforms().findByText("SQL transform").click();
- H.NativeEditor.type(";");
-
- cy.log("try to navigate away with unsaved changes - discard changes");
- DataStudio.nav().findByText("Glossary").click();
- H.modal().findByText("Discard your changes?").should("be.visible");
- H.modal().button("Discard changes").click();
- H.modal().should("not.exist");
- cy.location("pathname").should("eq", "/data-studio/glossary");
- });
-
- it("preserves workspace tabs state", () => {
- const sourceTable = `${TARGET_SCHEMA}.${SOURCE_TABLE}`;
- createTransforms();
- Workspaces.visitWorkspaces();
- cy.log("Create workspace, open transform tab");
- createWorkspace();
- registerWorkspaceAliasName("workspaceA");
-
- cy.log("Open the transform tab");
- Workspaces.getWorkspaceSidebar()
- .findByText("SQL transform")
- .should("be.visible")
- .click();
-
- H.NativeEditor.type(" LIMIT 2");
- Workspaces.getSaveTransformButton().click();
-
- cy.log("Create a second workspace");
- createWorkspace();
- registerWorkspaceAliasName("workspaceB");
-
- cy.log("Second workspace should start with default tabs");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("Setup", ["Setup", "Graph"]);
- });
-
- cy.log("Navigate back to first workspace");
- cy.get<string>("@workspaceA").then((workspaceNameA) => {
- Workspaces.getWorkspacesSection()
- .findByText(workspaceNameA)
- .should("be.visible")
- .click();
-
- cy.log("First workspace should preserve its tabs state");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe(sourceTable, ["Setup", "Graph", "SQL transform"]);
- });
-
- H.NativeEditor.value().should("contain", "LIMIT 2");
- });
- });
-
- it("archives and unarchives populated workspace (GDGT-1583)", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
- registerWorkspaceAliasName("workspaceA");
-
- cy.get<string>("@workspaceA").then((workspaceName) => {
- cy.log("Add a transform to the workspace");
- Workspaces.getWorkspaceSidebar()
- .findByText("SQL transform")
- .should("be.visible")
- .click();
-
- H.NativeEditor.type(" LIMIT 2");
- Workspaces.getSaveTransformButton().click();
-
- cy.log("Archive the workspace");
- Workspaces.openSetupTab();
- Workspaces.getWorkspaceItemActions(workspaceName).click();
- H.popover().findByText("Archive").click();
- verifyAndCloseToast("Workspace archived successfully");
- cy.log("Updates setup logs (GDGT-1583)");
- Workspaces.getWorkspaceContent()
- .findByText(/Workspace is archived/)
- .should("be.visible");
- Workspaces.getWorkspaceItem(workspaceName).should(
- "contain.text",
- "Archived",
- );
-
- cy.log("Block UI for archived workspace");
- Workspaces.getMergeWorkspaceButton().should("be.disabled");
- Workspaces.getWorkspaceDatabaseSelect().should("be.disabled");
-
- Workspaces.getWorkspaceTransforms().findByText("SQL transform").click();
- Workspaces.getRunTransformButton().should("be.disabled");
- Workspaces.getSaveTransformButton().should("be.disabled");
- Workspaces.getTransformTargetButton().should("be.disabled");
- Workspaces.getWorkspaceTransforms()
- .findByText("SQL transform")
- .realHover();
- Workspaces.getWorkspaceTransforms()
- .findByLabelText("More actions")
- .should("not.exist");
- H.NativeEditor.get().should("have.attr", "aria-readonly", "true");
-
- cy.log("Unarchive the workspace");
- Workspaces.openSetupTab();
- Workspaces.getWorkspaceItemActions(workspaceName).click();
- H.popover().findByText("Restore").click();
- verifyAndCloseToast("Workspace restored successfully");
- cy.log("Updates setup logs (GDGT-1583)");
- Workspaces.getWorkspaceContent()
- .findByText("Workspace ready!")
- .should("be.visible");
- Workspaces.getWorkspaceItemStatus(workspaceName).should(
- "contain.text",
- "Ready",
- );
- Workspaces.getWorkspaceTransforms()
- .findByText("SQL transform")
- .realHover();
- Workspaces.getWorkspaceTransforms()
- .findByLabelText("More actions")
- .should("be.visible");
- });
- });
-
- it("should be able to check out existing SQL transform into a new workspace from the transform page", () => {
- cy.log("Prepare available transforms: MBQL, Python, SQL");
- const sourceTable = `${TARGET_SCHEMA}.${SOURCE_TABLE}`;
- const targetTableSql = `${TARGET_SCHEMA}.${TARGET_TABLE_SQL}`;
- createTransforms({ visit: true });
-
- cy.log("Create a workspace, open transform page in it");
- cy.findByRole("button", { name: /Edit/ }).click();
- H.popover().within(() => {
- cy.findByText("No workspaces yet").should("be.visible");
- cy.findByText("New workspace").should("be.visible").click();
- });
- registerWorkspaceAliasName("workspaceA");
-
- cy.location("pathname").should("match", /data-studio\/workspaces\/\d+/);
- cy.get("@workspaceA").then((workspaceName) => {
- Workspaces.getWorkspaceNameInput().should("have.value", workspaceName);
- });
-
- cy.log("No transforms are checked out yet");
- Workspaces.getWorkspacePage()
- .findByText("Workspace is empty")
- .should("be.visible");
- Workspaces.getMainlandTransforms()
- .findByText("Python transform")
- .should("be.visible");
- Workspaces.getMainlandTransforms()
- .findByText("MBQL transform")
- .should("be.visible")
- .realHover();
- H.tooltip()
- .findByText(
- "Transforms based on the query builder cannot be edited in a workspace.",
- )
- .should("be.visible");
- Workspaces.getMainlandTransforms()
- .findByText("SQL transform")
- .should("be.visible")
- .click();
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("SQL transform", ["Setup", "Graph", "SQL transform"]);
- });
- cy.log("UI Controls are hidden/disabled until changes are made");
- Workspaces.getMergeWorkspaceButton().should("be.disabled");
- Workspaces.getTransformTargetButton().should("not.exist");
- Workspaces.getRunTransformButton().should("not.exist");
- Workspaces.getSaveTransformButton().should("be.enabled");
-
- H.NativeEditor.type(" LIMIT 2");
-
- cy.log("UI Controls are enabled after changes");
- Workspaces.getMergeWorkspaceButton().should("be.disabled");
- Workspaces.getTransformTargetButton().should("not.exist");
- Workspaces.getRunTransformButton().should("not.exist");
- Workspaces.getSaveTransformButton().should("be.enabled").click();
-
- cy.log(
- "Merge/Run controls are enabled after transform is saved to a workspace",
- );
- Workspaces.getMergeWorkspaceButton().should("be.enabled");
- Workspaces.getSaveTransformButton().should("be.disabled");
- Workspaces.getRunTransformButton().should("be.enabled").click();
-
- Workspaces.getWorkspaceSidebar().within(() => {
- cy.findByRole("tab", { name: "Data" }).click();
- cy.findByLabelText(sourceTable).should("be.visible").click();
- });
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe(sourceTable, [
- "Setup",
- "Graph",
- "SQL transform",
- sourceTable,
- ]);
- H.assertTableData({
- columns: ["Name", "Score"],
- firstRows: [
- ["Duck", "10"],
- ["Horse", "20"],
- ["Cow", "30"],
- ],
- });
- });
-
- cy.findByLabelText(targetTableSql).should("be.visible").click();
- cy.wait("@dataset");
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe(targetTableSql, [
- "Setup",
- "Graph",
- "SQL transform",
- sourceTable,
- targetTableSql,
- ]);
- H.assertTableData({
- columns: ["Name", "Score"],
- firstRows: [
- ["Duck", "10"],
- ["Horse", "20"],
- ],
- });
- cy.findByText("Cow").should("not.exist");
- cy.findByText("30").should("not.exist");
- });
-
- Workspaces.getMergeWorkspaceButton().click();
- Workspaces.getMergeCommitInput().type("Merge transform");
- H.modal().within(() => {
- cy.log("All quality checks should be passed");
- cy.findByText("Quality Checks").should("exist");
- cy.findByText("External dependencies").should("exist");
- cy.findByText("Internal dependencies").should("exist");
- cy.findByText("Structural issues").should("exist");
- cy.findByText("Unused outputs").should("exist");
- cy.findByText("1 transform will be merged").should("exist");
-
- cy.log("Transform diffs are displayed");
- cy.findByText("Modified transforms").should("exist");
- cy.findByTestId("transform-list-item")
- .should("contain.text", "SQL transform")
- .should("be.visible")
- .should(($el) => {
- expect($el.text()).to.include("SQL transform");
- expect($el.text()).to.match(/\+1\b/);
- expect($el.text()).to.match(/-1\b/);
- })
- .click();
- cy.contains(
- '[class*="cm-deletedLine"]',
- 'SELECT * FROM "Schema A"."Animals"',
- );
- cy.contains(
- '[class*="cm-insertedLine"]',
- 'SELECT * FROM "Schema A"."Animals" LIMIT 2',
- );
-
- cy.findByRole("button", { name: /Merge/ }).click();
- });
- verifyAndCloseToast("merged successfully");
-
- Transforms.list()
- .findByRole("row", { name: /SQL transform/ })
- .click();
- H.NativeEditor.value().should(
- "eq",
- 'SELECT * FROM "Schema A"."Animals" LIMIT 2',
- );
- Transforms.runTab().click();
- runTransformAndWaitForSuccessOnTransformsPage();
- Transforms.settingsTab().click();
- getTableLink().should("contain.text", TARGET_TABLE_SQL).click();
-
- H.assertTableData({
- columns: ["Name", "Score"],
- firstRows: [
- ["Duck", "10"],
- ["Horse", "20"],
- ],
- });
- H.tableInteractiveBody().findByText("Cow").should("not.exist");
- H.tableInteractiveBody().findByText("30").should("not.exist");
- });
- });
-
- describe("should show tabs UI correctly", () => {
- it("should allow closing tabs with close button, selects fallback tab", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("Setup", ["Setup", "Graph"]);
- });
-
- cy.log("Open transform tabs");
- Workspaces.getMainlandTransforms().findByText("Python transform").click();
-
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("SQL transform", [
- "Setup",
- "Graph",
- "Python transform",
- "SQL transform",
- ]);
- });
-
- cy.log("Reorder and close tabs");
- Workspaces.getWorkspaceContent().within(() => {
- cy.findAllByRole("tab").eq(3).as("sqlTransformTab");
- H.moveDnDKitElementByAlias("@sqlTransformTab", {
- horizontal: -150,
- });
- cy.wait(100);
- cy.findAllByRole("tab")
- .eq(0)
- .findByLabelText("close icon")
- .should("not.exist");
- cy.findAllByRole("tab")
- .eq(1)
- .findByLabelText("close icon")
- .should("not.exist");
- cy.findAllByRole("tab")
- .eq(2)
- .findByLabelText("close icon")
- .should("exist");
- cy.findAllByRole("tab")
- .eq(3)
- .findByLabelText("close icon")
- .should("exist")
- .click();
- });
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("SQL transform", ["Setup", "Graph", "SQL transform"]);
- });
- });
-
- it("closes relevant tabs after ws transform is removed", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- H.NativeEditor.type(" LIMIT 2");
- Workspaces.getSaveTransformButton().click();
- runTransformAndWaitForSuccess();
-
- cy.log("Open the transform table tab");
- Workspaces.openDataTab();
- Workspaces.getWorkspaceSidebar()
- .findByText(`${TARGET_SCHEMA}.${TARGET_TABLE_SQL}`)
- .should("be.visible")
- .click();
-
- cy.log("Verify both tabs are open");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe(TARGET_TABLE_SQL, [
- "Setup",
- "Graph",
- "SQL transform",
- "transform_table",
- ]);
- });
-
- Workspaces.openCodeTab();
-
- cy.log("Remove the transform from the workspace");
- Workspaces.getWorkspaceTransforms()
- .findByText("SQL transform")
- .realHover();
- Workspaces.getWorkspaceTransforms()
- .findByLabelText("More actions")
- .click();
- H.popover().findByText("Remove").click();
- verifyAndCloseToast("Transform removed from the workspace");
-
- cy.log("Verify both transform tab and table tab have been closed");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("Setup", ["Setup", "Graph"]);
- });
- });
- });
-
- describe("setup tab", () => {
- it("should allow to change database before transforms are added", () => {
- H.addPostgresDatabase("Test DB", undefined, undefined, "testDbId");
- cy.get<DatabaseId>("@testDbId").then((testDbId) => {
- enableWorkspacesInDb(testDbId);
- });
-
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Database dropdown should be enabled initially");
- Workspaces.getWorkspaceDatabaseSelect()
- .should("have.value", "Test DB")
- .click();
- H.popover()
- .findByRole("option", { name: "Sample Database" })
- .should("not.exist");
- H.popover().findByRole("option", { name: "Writable Postgres12" }).click();
-
- cy.log("Verify database was changed");
- verifyAndCloseToast("Successfully updated workspace database");
- Workspaces.getWorkspaceDatabaseSelect().should(
- "have.value",
- "Writable Postgres12",
- );
- });
-
- it("should lock database dropdown when workspace has been initialized, shows setup log", () => {
- // @flaky
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Add WS transform to lock DB selection");
- Workspaces.getMainlandTransforms()
- .findByText("SQL transform")
- .should("be.visible")
- .click();
- Workspaces.getWorkspaceContent().within(() => {
- H.NativeEditor.type(" LIMIT 2");
- Workspaces.getSaveTransformButton().click();
-
- cy.findByRole("tab", { name: "Setup" }).click();
-
- cy.log("Database dropdown should be disabled after adding transforms");
- Workspaces.getWorkspaceDatabaseSelect()
- .should("be.disabled")
- .should("have.value", "Writable Postgres12");
-
- cy.log("Setup log should be visible");
- cy.findByText(/Setting up the workspace/).should("be.visible");
- });
- });
-
- it("should disable workspace actions while workspace is in pending status", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Mock /log endpoint to return pending status");
- cy.log("Add transform to workspace");
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- H.NativeEditor.type(" LIMIT 2");
-
- cy.intercept("GET", "/api/ee/workspace/*/log", {
- body: {
- workspace_id: 1,
- status: "pending",
- updated_at: null,
- last_completed_at: null,
- logs: [
- {
- id: 1,
- task: "workspace-setup",
- description: "Setting up workspace",
- status: "started",
- message: null,
- },
- ],
- },
- }).as("getWorkspaceLog");
-
- Workspaces.getSaveTransformButton().click();
-
- cy.log("Verify merge button is disabled");
- Workspaces.getMergeWorkspaceButton().should("be.disabled");
-
- cy.log("Verify transform actions menu is disabled");
- Workspaces.getWorkspaceTransforms()
- .findByText("SQL transform")
- .parent()
- .findByLabelText("More actions")
- .should("not.exist");
-
- cy.log(
- "Switch to Data tab and verify clicking uninitialized output table does not run transform",
- );
- Workspaces.openDataTab();
- cy.intercept("POST", "/api/ee/workspace/*/transform/*/run").as(
- "runTransformRequest",
- );
- cy.findByTestId("workspace-sidebar")
- .findByLabelText(/transform_table_2/)
- .click();
- cy.get("@runTransformRequest.all").should("have.length", 0);
- });
- });
-
- describe("graph tab", () => {
- it(
- "should display multiple transforms and their connections",
- { tags: ["@python"] },
- () => {
- H.setPythonRunnerSettings();
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- Workspaces.getSaveTransformButton().click();
- Workspaces.getWorkspaceTransforms()
- .findByText("SQL transform")
- .should("be.visible");
-
- Workspaces.getMainlandTransforms()
- .findByText("Python transform")
- .click();
- Workspaces.getSaveTransformButton().click();
- Workspaces.getWorkspaceTransforms()
- .findByText("Python transform")
- .should("be.visible");
-
- Workspaces.getRunAllTransformsButton().click();
- H.popover().findByText("Run all transforms").click();
- verifyAndCloseToast("Transforms ran successfully");
-
- Workspaces.openGraphTab();
-
- // Verify nodes
- H.DependencyGraph.graph().should("be.visible");
- H.DependencyGraph.graph()
- .findByLabelText("SQL transform")
- .should("be.visible");
- H.DependencyGraph.graph()
- .findByLabelText("Python transform")
- .should("be.visible");
- H.DependencyGraph.graph()
- .findByLabelText(TARGET_TABLE_SQL)
- .should("be.visible");
- H.DependencyGraph.graph()
- .findByLabelText(TARGET_TABLE_PYTHON)
- .should("be.visible");
-
- // Verify edges: input tables -> transforms -> output tables
- // To simplify test logic, we just check that all edges are present.
- // In total there should be 4 edges:
- // - Animals -> SQL transform
- // - Animals -> Python transform
- // - SQL transform -> target table
- // - Python transform -> target table
- H.DependencyGraph.graph()
- .findAllByLabelText(/Edge from.*workspace-transform.*to.*Animals/)
- .should("have.length", 2);
- H.DependencyGraph.graph()
- .findAllByLabelText(/Edge from.*target.*to.*workspace-transform/)
- .should("have.length", 2);
- },
- );
-
- it("should allow clicking on graph nodes to see details", () => {
- // @flaky
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- Workspaces.getSaveTransformButton().click();
- runTransformAndWaitForSuccess();
-
- Workspaces.openGraphTab();
-
- H.DependencyGraph.graph().findByLabelText(SOURCE_TABLE).click();
- H.DependencyGraph.graph()
- .findByLabelText(SOURCE_TABLE)
- .should("have.attr", "aria-selected", "true");
-
- cy.log("Verify info panel shows fields for input table");
- cy.findByTestId("graph-info-panel").within(() => {
- cy.findByText("2 fields").should("be.visible");
- cy.findByText("Name").should("be.visible");
- cy.findByText("Score").should("be.visible");
- cy.findByLabelText("Close").click();
- });
-
- H.DependencyGraph.graph().findByLabelText("SQL transform").click();
- H.DependencyGraph.graph()
- .findByLabelText("SQL transform")
- .should("have.attr", "aria-selected", "true");
-
- cy.log("Verify info panel shows transform link");
- cy.findByTestId("graph-info-panel").within(() => {
- cy.findByLabelText("View this workspace transform").should(
- "be.visible",
- );
- });
-
- cy.log("Click transform link and verify navigation to transform tab");
- cy.findByTestId("graph-info-panel")
- .findByLabelText("View this workspace transform")
- .click();
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("SQL transform", ["Setup", "Graph", "SQL transform"]);
- });
- });
- });
-
- describe("code tab", () => {
- it("should check out transform into the workspace and remove it", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Open mainland transform");
- Workspaces.getMainlandTransforms()
- .findByText("SQL transform")
- .should("be.visible")
- .click();
-
- cy.log("Make changes to the transform");
- Workspaces.getWorkspaceContent().within(() => {
- H.NativeEditor.type(" LIMIT 2");
- });
-
- cy.log(
- "Check that transform has yellow dot change indicator after editing",
- );
- Workspaces.getMainlandTransforms().within(() => {
- Workspaces.getTransformStatusDot("SQL transform").should("be.visible");
- });
-
- cy.log("Save the transform to add it to workspace");
- Workspaces.getSaveTransformButton().click();
- cy.log("Save button should be disabled after saving");
- Workspaces.getSaveTransformButton().should("be.disabled");
-
- cy.log("Transform should be removed from available list after saving");
- Workspaces.getMainlandTransforms()
- .findByText("SQL transform")
- .should("not.exist");
-
- cy.log("Transform should appear in workspace transforms list");
- Workspaces.getWorkspaceTransforms()
- .findByText("SQL transform")
- .should("be.visible");
-
- cy.log("Make additional changes to the saved transform");
- Workspaces.getWorkspaceContent().within(() => {
- H.NativeEditor.type(";");
- });
-
- cy.log("Check that transform has yellow dot status again");
- Workspaces.getWorkspaceTransforms().within(() => {
- Workspaces.getTransformStatusDot("SQL transform").should("be.visible");
- });
-
- cy.log("Save it again");
- cy.log(
- "Add delay to API response to verify button is disabled immediately on click",
- );
- cy.intercept(
- { method: "PUT", url: "/api/ee/workspace/*/transform/*" },
- (req) => {
- req.on("response", (res) => {
- res.setDelay(500);
- });
- },
- ).as("updateTransformSlow");
-
- Workspaces.getWorkspaceContent().within(() => {
- Workspaces.getSaveTransformButton().click();
- cy.log("Save button should show loading state immediately after click");
- Workspaces.getSaveTransformButton().should("have.attr", "data-loading");
- });
- cy.log("Wait for save to complete");
- cy.wait("@updateTransformSlow");
- cy.log(
- "Save button should be disabled after save completes (no changes)",
- );
- Workspaces.getSaveTransformButton().should("be.disabled");
-
- cy.log("Check that yellow dot doesn't exist anymore after saving");
- Workspaces.getWorkspaceTransforms().within(() => {
- Workspaces.getTransformStatusDot("SQL transform").should("not.exist");
- });
-
- cy.log("Remove transform from the workspace through ellipsis menu");
- Workspaces.getWorkspaceTransforms()
- .findByText("SQL transform")
- .realHover();
- Workspaces.getWorkspaceTransforms()
- .findByLabelText("More actions")
- .click();
- H.popover()
- .findByRole("menuitem", { name: /Remove/ })
- .click();
-
- cy.log("Check that it's not present in workspace transforms list");
- Workspaces.getWorkspaceTransforms()
- .findByText("SQL transform")
- .should("not.exist");
-
- cy.log("Check that it's displayed back in available transforms list");
- Workspaces.getMainlandTransforms()
- .findByText("SQL transform")
- .should("be.visible");
- });
- });
-
- describe("transform tab", () => {
- it("should create new transform - SQL", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Click Add Transform button");
- Workspaces.getWorkspaceSidebar().findByLabelText("Add transform").click();
-
- cy.log("Check that SQL and Python options are provided");
- H.popover()
- .findByRole("menuitem", { name: /Python Script/ })
- .should("be.visible");
- H.popover()
- .findByRole("menuitem", { name: /SQL Transform/ })
- .should("be.visible")
- .click();
-
- cy.log("Check that it opens new empty tab");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("New transform", ["Setup", "Graph", "New transform"]);
- H.NativeEditor.value().should("be.empty");
- Workspaces.getSaveTransformButton().should("be.disabled");
- });
-
- cy.log(
- "Check that 'New transform' is added to workspace transforms list",
- );
- Workspaces.getWorkspaceTransforms()
- .findByText("New transform")
- .should("be.visible");
-
- cy.log("Type a query in the editor");
- Workspaces.getWorkspaceContent().within(() => {
- H.NativeEditor.paste("SELECT * FROM many_schemas.animals");
- });
-
- cy.log("Open transform settings");
- Workspaces.getSaveTransformButton().click();
-
- cy.log(
- "Check that table name gets automatically populated based on transform name",
- );
- H.modal().within(() => {
- cy.findByText("Incremental transformation").should("not.exist");
- cy.findByLabelText(/Table name/).should("have.value", "new_transform");
- cy.findByDisplayValue("new_transform").clear().type("test_table");
-
- cy.findByLabelText("Schema").click();
- cy.document()
- .findByRole("option", { name: /Schema B/ })
- .click();
-
- cy.findByRole("button", { name: /Save/ }).click();
- });
- verifyAndCloseToast("Transform saved successfully");
-
- cy.log("Verify transform is saved with new name");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("New transform", ["Setup", "Graph", "New transform"]);
- });
-
- cy.log(
- "Check transform appears in workspace transforms list with correct name",
- );
- Workspaces.getWorkspaceTransforms()
- .findByText("New transform")
- .should("be.visible");
-
- Workspaces.openDataTab();
- Workspaces.getWorkspaceSidebar()
- .findByText("Schema B.test_table")
- .should("be.visible");
-
- Workspaces.getTransformTargetButton().click();
- H.modal().within(() => {
- cy.findByLabelText("Schema").should("have.value", "Schema B");
- cy.findByLabelText("New table name")
- .should("have.value", "test_table")
- .clear()
- .type("new_table");
- cy.findByRole("button", { name: /Change target/ }).click();
- });
- verifyAndCloseToast("Transform target updated");
-
- Workspaces.getWorkspaceSidebar()
- .findByText("Schema B.new_table")
- .should("be.visible");
-
- Workspaces.openCodeTab();
- Workspaces.getWorkspaceTransforms().within(() => {
- Workspaces.getTransformStatusDot("New transform").should("not.exist");
- });
- });
-
- it("should create new transform - Python", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Click Add Transform button");
- Workspaces.getWorkspaceSidebar().findByLabelText("Add transform").click();
-
- cy.log("Check that Python and SQL options are provided");
- H.popover()
- .findByRole("menuitem", { name: /SQL Transform/ })
- .should("be.visible");
- H.popover()
- .findByRole("menuitem", { name: /Python Script/ })
- .should("be.visible")
- .click();
-
- cy.log("Check that it opens new empty tab");
- Workspaces.getWorkspaceTabs().within(() => {
- H.tabsShouldBe("New transform", ["Setup", "Graph", "New transform"]);
- });
- H.PythonEditor.value().should("not.be.empty");
-
- cy.log(
- "Check that 'New transform' is added to workspace transforms list",
- );
- Workspaces.getWorkspaceTransforms()
- .findByText("New transform")
- .should("be.visible");
-
- cy.log("Type a query in the editor");
- Workspaces.getWorkspaceContent().within(() => {
- H.PythonEditor.clear().paste(TEST_PYTHON_TRANSFORM);
-
- cy.findByTestId("python-data-picker")
- .findByText("Select a table…")
- .click();
- });
-
- H.entityPickerModal().within(() => {
- cy.findByText("Schema A").click();
- cy.findByText("Animals").click();
- });
-
- cy.log("Open transform settings");
- Workspaces.getSaveTransformButton().click();
-
- cy.log(
- "Check that table name gets automatically populated based on transform name",
- );
- H.modal().within(() => {
- cy.findByText("Incremental transformation").should("not.exist");
- cy.findByLabelText(/Table name/).should("have.value", "new_transform");
- cy.findByDisplayValue("new_transform").clear().type("test_table");
-
- cy.findByLabelText("Schema").click();
- cy.document()
- .findByRole("option", { name: /Schema B/ })
- .click();
-
- cy.findByRole("button", { name: /Save/ }).click();
- });
- verifyAndCloseToast("Transform saved successfully");
-
- cy.log("Verify transform is saved with new name");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("New transform", ["Setup", "Graph", "New transform"]);
- });
-
- cy.log(
- "Check transform appears in workspace transforms list with correct name",
- );
- Workspaces.getWorkspaceTransforms()
- .findByText("New transform")
- .should("be.visible");
-
- Workspaces.openDataTab();
- Workspaces.getWorkspaceSidebar().within(() => {
- cy.findByText("Schema B.test_table").should("be.visible");
- cy.findByText("Schema A.Animals").should("be.visible");
- });
-
- cy.findByTestId("python-data-picker").findByText("Animals").click();
-
- H.entityPickerModal().within(() => {
- cy.findByText("Schema B").click();
- cy.findByText("Animals").click();
- });
-
- Workspaces.getSaveTransformButton().click();
-
- Workspaces.openDataTab();
- Workspaces.getWorkspaceSidebar()
- .findByText("Schema B.Animals")
- .should("be.visible");
-
- Workspaces.getTransformTargetButton().click();
- H.modal().within(() => {
- cy.findByLabelText("Schema").should("have.value", "Schema B");
- cy.findByLabelText("New table name")
- .should("have.value", "test_table")
- .clear()
- .type("new_table");
- cy.findByRole("button", { name: /Change target/ }).click();
- });
- verifyAndCloseToast("Transform target updated");
-
- Workspaces.getWorkspaceSidebar()
- .findByText("Schema B.new_table")
- .should("be.visible");
-
- Workspaces.openCodeTab();
- Workspaces.getWorkspaceTransforms().within(() => {
- Workspaces.getTransformStatusDot("New transform").should("not.exist");
- });
- });
-
- it("should validate target name", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Add existing transform");
- Workspaces.getMainlandTransforms()
- .findByText("SQL transform")
- .should("be.visible")
- .click();
-
- cy.log("Make changes to the transform");
- Workspaces.getWorkspaceContent().within(() => {
- H.NativeEditor.type(" LIMIT 2");
- });
- Workspaces.getSaveTransformButton().click();
-
- cy.log("Create new transform");
- Workspaces.getWorkspaceSidebar().findByLabelText("Add transform").click();
-
- H.popover()
- .findByRole("menuitem", { name: /SQL Transform/ })
- .click();
-
- Workspaces.getWorkspaceContent().within(() => {
- H.NativeEditor.paste("any text");
- });
- Workspaces.getSaveTransformButton().click();
-
- H.modal().within(() => {
- cy.findByDisplayValue("new_transform").clear();
- cy.findByText("Target table name is required").should("be.visible");
- cy.realType(TARGET_TABLE_SQL);
- cy.findByText(
- "Another transform in this workspace already targets that table",
- ).should("be.visible");
- cy.realType("1");
- cy.findByText(
- "Another transform in this workspace already targets that table",
- ).should("not.exist");
- });
- });
- });
-
- describe("data tab", () => {
- it("should list input and output tables", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
-
- H.NativeEditor.type(" LIMIT 1;");
- Workspaces.getSaveTransformButton().click();
-
- cy.log("Close saved transform tab");
- Workspaces.getWorkspaceContent().within(() => {
- cy.findByRole("tab", { name: "SQL transform" })
- .findByLabelText("close icon")
- .click();
- });
-
- Workspaces.openDataTab();
- Workspaces.getWorkspaceSidebar()
- .findByText(`${TARGET_SCHEMA}.${SOURCE_TABLE}`)
- .should("be.visible");
- Workspaces.getWorkspaceSidebar()
- .findByText(`${TARGET_SCHEMA}.${TARGET_TABLE_SQL}`)
- .as("outputTable")
- .should("be.visible")
- .realHover();
- cy.root()
- .findByText("Run transform to see the results")
- .should("be.visible");
-
- cy.get("@outputTable").realHover().click();
-
- Workspaces.getWorkspaceContent().within(() => {
- cy.findByText("Loading...").should("be.visible");
- H.assertTableData({
- columns: ["Name", "Score"],
- firstRows: [["Duck", "10"]],
- });
- });
-
- Workspaces.getWorkspaceTabs().within(() => {
- H.tabsShouldBe(`${TARGET_SCHEMA}.${TARGET_TABLE_SQL}`, [
- "Setup",
- "Graph",
- `${TARGET_SCHEMA}.${TARGET_TABLE_SQL}`,
- ]);
- });
-
- Workspaces.getWorkspaceSidebar()
- .findByLabelText(`${TARGET_SCHEMA}.${TARGET_TABLE_SQL}`)
- .findByLabelText("Open transform")
- .as("transformLink")
- .realHover();
- cy.root().findByText("Open transform").should("be.visible");
- cy.get("@transformLink").click();
-
- Workspaces.getWorkspaceTabs().within(() => {
- H.tabsShouldBe("SQL transform", [
- "Setup",
- "Graph",
- `${TARGET_SCHEMA}.${TARGET_TABLE_SQL}`,
- "SQL transform",
- ]);
- });
- });
- });
-
- describe("run transform", () => {
- it("should run and fail transform runs", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Run transform");
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
-
- H.NativeEditor.type(" LIMIT");
- Workspaces.getSaveTransformButton().click();
-
- Workspaces.getWorkspaceContent().findByText(
- "This transform hasn't been run before.",
- );
-
- Workspaces.getRunTransformButton().click();
-
- H.undoToast().findByText(/Transform run failed/);
-
- H.NativeEditor.type(" 1;");
- Workspaces.getSaveTransformButton().click();
- Workspaces.getRunTransformButton().click();
-
- Workspaces.getWorkspaceContent().findByText("Ran successfully");
- Workspaces.getWorkspaceContent().findByText(
- "Last ran a few seconds ago successfully.",
- );
-
- H.NativeEditor.type("{backspace}{backspace}");
- Workspaces.getSaveTransformButton().click();
- Workspaces.getRunTransformButton().click();
-
- H.undoToast().findByText(/Transform run failed/);
- });
-
- it("should show ad-hoc results", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Run ad-hoc query");
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
-
- H.NativeEditor.type(" LIMIT 1;");
- Workspaces.getSaveTransformButton().click();
- cy.log("open preview");
- cy.findByLabelText("Get Answer").click();
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("Preview (SQL transform)", [
- "Setup",
- "Graph",
- "SQL transform",
- "Preview (SQL transform)",
- ]);
- cy.findByText("Preview (SQL transform)").click();
- // TODO (Stas 2025-12-30) -- Is it expected that ad-hoc cols have lowercase names?
- H.assertTableData({
- columns: ["name", "score"],
- firstRows: [["Duck", "10"]],
- });
- });
- });
-
- it("should open preview on Cmd+Enter when no unsaved changes, and not when there are changes", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Open SQL transform and save");
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- H.NativeEditor.type(" LIMIT 1;");
- Workspaces.getSaveTransformButton().click();
-
- cy.log("Cmd+Enter opens preview when transform is saved");
- H.NativeEditor.focus();
- cy.realPress([
- Cypress.platform === "darwin" ? "Meta" : "Control",
- "Enter",
- ]);
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("Preview (SQL transform)", [
- "Setup",
- "Graph",
- "SQL transform",
- "Preview (SQL transform)",
- ]);
- });
-
- cy.log("Close preview tab");
- Workspaces.getWorkspaceContent().within(() => {
- cy.findByRole("tab", { name: "Preview (SQL transform)" })
- .icon("close")
- .click();
- });
-
- cy.log("Go back to SQL transform tab and make a change");
- Workspaces.getWorkspaceContent()
- .findByRole("tab", { name: "SQL transform" })
- .click();
- H.NativeEditor.type(" ");
-
- cy.log("Cmd+Enter does not open preview when there are unsaved changes");
- cy.realPress([
- Cypress.platform === "darwin" ? "Meta" : "Control",
- "Enter",
- ]);
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("SQL transform", ["Setup", "Graph", "SQL transform"]);
- });
- });
-
- it("should not show Python transform preview section in workspace", () => {
- H.setPythonRunnerSettings();
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Open Python transform in workspace");
- Workspaces.getMainlandTransforms().findByText("Python transform").click();
-
- cy.log("Inline preview section (Results/Output) should not be displayed");
- cy.findByTestId("python-results").should("not.exist");
-
- cy.log("Python editor should fill available height (no white box)");
-
- const MIN_EDITOR_HEIGHT = 535; // assumes that no notification banner is showing
- cy.findByTestId("python-editor").should(($editor) => {
- const height = $editor.height();
- expect(height).to.be.at.least(
- MIN_EDITOR_HEIGHT,
- `Editor height should be at least ${MIN_EDITOR_HEIGHT}px, got ${height}`,
- );
- });
- });
-
- it(
- "should show ad-hoc results for Python transform",
- { tags: ["@python"] },
- () => {
- H.setPythonRunnerSettings();
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Run ad-hoc Python query");
- Workspaces.getMainlandTransforms()
- .findByText("Python transform")
- .click();
-
- Workspaces.getSaveTransformButton().click();
- cy.findByLabelText("Get Answer").click();
-
- Workspaces.getWorkspaceTabs().within(() => {
- H.tabsShouldBe("Preview (Python transform)", [
- "Setup",
- "Graph",
- "Python transform",
- "Preview (Python transform)",
- ]);
- cy.findByText("Preview (Python transform)").click();
- });
- H.assertTableData({
- columns: ["foo"],
- firstRows: [["42"]],
- });
- },
- );
-
- it("should show ad-hoc error for SQL transform", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Run invalid ad-hoc SQL query");
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
-
- H.NativeEditor.type(" INVALID SYNTAX");
- Workspaces.getSaveTransformButton().click();
- cy.findByLabelText("Get Answer").click();
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("Preview (SQL transform)", [
- "Setup",
- "Graph",
- "SQL transform",
- "Preview (SQL transform)",
- ]);
- cy.findByText("Preview (SQL transform)").click();
- cy.findByText(/Error loading data/i).should("be.visible");
- });
- });
-
- it(
- "should show ad-hoc error for Python transform",
- { tags: ["@python"] },
- () => {
- H.setPythonRunnerSettings();
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Run invalid ad-hoc Python query");
- Workspaces.getMainlandTransforms()
- .findByText("Python transform")
- .click();
-
- H.PythonEditor.clear().paste("invalid python syntax !!!");
- Workspaces.getSaveTransformButton().click();
- cy.findByLabelText("Get Answer").click();
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("Preview (Python transform)", [
- "Setup",
- "Graph",
- "Python transform",
- "Preview (Python transform)",
- "Results",
- "Output",
- ]);
- cy.findByText("Preview (Python transform)").click();
- cy.findByText(/Transform preview failed/i).should("be.visible");
- });
- },
- );
- });
-
- describe("run all transforms", () => {
- it("should run all transforms", { tags: ["@python"] }, () => {
- H.setPythonRunnerSettings();
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- Workspaces.getRunAllTransformsButton().should("be.disabled");
-
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- cy.log("Verify native editor is loaded");
- H.NativeEditor.get().should("contain.text", "SELECT");
- Workspaces.getSaveTransformButton().click();
- cy.log("Verify sql transform is saved to the workspace");
- Workspaces.getWorkspaceTransforms().should(
- "contain.text",
- "SQL transform",
- );
-
- Workspaces.getMainlandTransforms().findByText("Python transform").click();
- cy.log("Verify Python editor is loaded");
- H.PythonEditor.get().should("contain.text", "import");
- Workspaces.getSaveTransformButton().click();
- cy.log("Verify python transform is saved to the workspace");
- Workspaces.getWorkspaceTransforms().should(
- "contain.text",
- "Python transform",
- );
-
- Workspaces.getRunAllTransformsButton().should("be.enabled").click();
-
- H.popover().within(() => {
- cy.findByText("Run stale transforms").should("be.visible");
- cy.findByText("Run all transforms").should("be.visible").click();
- });
-
- Workspaces.getRunAllTransformsButton().should(
- "not.have.attr",
- "data-loading",
- );
- verifyAndCloseToast("Transforms ran successfully");
-
- Workspaces.getWorkspaceContent()
- .findByText("Last ran a few seconds ago successfully.")
- .should("be.visible");
-
- cy.findByRole("tab", { name: "SQL transform" }).click();
-
- Workspaces.getWorkspaceContent()
- .findByText("Last ran a few seconds ago successfully.")
- .should("be.visible");
-
- Workspaces.openDataTab();
- Workspaces.getWorkspaceSidebar()
- .findByText(`${TARGET_SCHEMA}.${TARGET_TABLE_SQL}`)
- .realHover();
- H.tooltip().should("not.exist");
-
- Workspaces.getWorkspaceSidebar()
- .findByText(`${TARGET_SCHEMA}.${TARGET_TABLE_PYTHON}`)
- .realHover();
- H.tooltip().should("not.exist");
- });
-
- it("should run all stale transforms", { tags: ["@python"] }, () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- Workspaces.openCodeTab();
-
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- Workspaces.getSaveTransformButton().click();
-
- Workspaces.getMainlandTransforms().findByText("Python transform").click();
- Workspaces.getSaveTransformButton().click();
-
- Workspaces.getRunTransformButton().click();
- Workspaces.getWorkspaceContent()
- .findByText("Last ran a few seconds ago successfully.")
- .should("be.visible");
-
- Workspaces.openDataTab();
- Workspaces.getWorkspaceSidebar()
- .findByText(`${TARGET_SCHEMA}.${TARGET_TABLE_PYTHON}`)
- .realHover();
- H.tooltip().should("not.exist");
-
- Workspaces.getRunAllTransformsButton().should("be.enabled").click();
-
- H.popover().within(() => {
- cy.findByText("Run all transforms").should("be.visible");
- cy.findByText("Run stale transforms").should("be.visible").click();
- });
-
- Workspaces.getRunAllTransformsButton().should(
- "have.attr",
- "data-loading",
- "true",
- );
- cy.wait<WorkspaceRunResponse, WorkspaceRunResponse>(
- "@runTransforms",
- ).then(({ response }) => {
- cy.log("only 1 stale transform has been executed");
- expect(response?.body.succeeded).to.be.an("array").with.length(1);
- });
- Workspaces.getRunAllTransformsButton().should(
- "not.have.attr",
- "data-loading",
- );
- verifyAndCloseToast("Transforms ran successfully");
-
- cy.findByRole("tab", { name: "SQL transform" }).click();
-
- Workspaces.getWorkspaceContent()
- .findByText("Last ran a few seconds ago successfully.")
- .should("be.visible");
-
- Workspaces.getWorkspaceSidebar()
- .findByText(`${TARGET_SCHEMA}.${TARGET_TABLE_SQL}`)
- .realHover();
- H.tooltip().should("not.exist");
- });
- });
-
- describe("check out transform into a workspace", () => {
- it("should check out transform into a new workspace from the transform page", () => {
- cy.log("Create 2 workspaces, add transform to the second one");
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
- registerWorkspaceAliasName("workspaceA");
- createWorkspace();
- registerWorkspaceAliasName("workspaceB");
-
- Workspaces.getMainlandTransforms().within(() => {
- cy.findByText("SQL transform").should("be.visible");
- // intentionally not chaining the click since it makes the test flaky
- cy.findByText("SQL transform").click();
- });
-
- Workspaces.getWorkspaceContent().within(() => {
- H.NativeEditor.type(" LIMIT 2");
- });
- Workspaces.getSaveTransformButton().click();
-
- cy.log(
- "Check that all workspaces are available and sorted by checked status",
- );
- cy.visit("/data-studio/transforms");
- Transforms.list()
- .findByRole("row", { name: /SQL transform/ })
- .click();
-
- cy.findByRole("button", { name: /Edit/ }).click();
-
- cy.get<string>("@workspaceA").then((workspaceA) => {
- cy.get<string>("@workspaceB").then((workspaceB) => {
- H.popover().within(() => {
- cy.findAllByRole("menuitem").eq(0).contains("Edit definition");
- cy.findAllByRole("menuitem").eq(1).contains("New workspace");
- cy.findAllByRole("menuitem").eq(2).contains(workspaceB);
- cy.log("Check that edit redirects to correct workspace");
- cy.findAllByRole("menuitem").eq(3).contains(workspaceA).click();
- });
- });
- });
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("SQL transform", ["Setup", "Graph", "SQL transform"]);
- });
- Workspaces.getWorkspaceTransforms()
- .findByText("SQL transform")
- .should("not.exist");
- });
-
- it("should open checked out transform in existing workspace from the transform page", () => {
- // @flaky
- cy.log("Create 2 workspaces, add transform to the second one");
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
- registerWorkspaceAliasName("workspaceA");
- createWorkspace();
- registerWorkspaceAliasName("workspaceB");
-
- Workspaces.getMainlandTransforms()
- .findByText("SQL transform")
- .should("be.visible")
- .click();
-
- Workspaces.getWorkspaceContent().within(() => {
- H.NativeEditor.type(" LIMIT 2");
- });
- Workspaces.getSaveTransformButton().click();
-
- cy.visit("/data-studio/transforms");
- Transforms.list()
- .findByRole("row", { name: /SQL transform/ })
- .click();
-
- cy.findByRole("button", { name: /Edit/ }).click();
- cy.get<string>("@workspaceA").then((workspaceA) => {
- cy.get<string>("@workspaceB").then((workspaceB) => {
- H.popover().within(() => {
- cy.findAllByRole("menuitem").eq(1).contains("New workspace");
- cy.findAllByRole("menuitem").eq(3).contains(workspaceA);
- cy.log("Edit transform in a workspace where it's been checked out");
- cy.findAllByRole("menuitem").eq(2).contains(workspaceB).click();
- });
- });
- });
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("SQL transform", ["Setup", "Graph", "SQL transform"]);
- });
- H.NativeEditor.value().should("contain", " LIMIT 2");
- Workspaces.getWorkspaceTransforms().findByText("SQL transform").click();
- cy.log(
- "Tabs state should stay the same, because this transform is already checked and its tab should be opened after redirect",
- );
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("SQL transform", ["Setup", "Graph", "SQL transform"]);
- });
- });
-
- it("should not allow to checkout transform if checkout_disabled is received", () => {
- cy.intercept("GET", "/api/ee/workspace/checkout*").as(
- "checkoutWorkspace",
- );
-
- H.createModelFromTableName({
- tableName: "Animals",
- modelName: "Animals",
- idAlias: "modelId",
- });
-
- cy.log("Create transform via UI with model reference");
- Workspaces.visitTransformListPage();
- cy.button("Create a transform").click();
- H.popover().findByText("SQL query").click();
- H.popover().findByText("Writable Postgres12").click();
-
- cy.get("@modelId").then((modelId) => {
- H.NativeEditor.type(`SELECT * FROM {{#${modelId}-animals}} as t;`);
- });
-
- H.DataStudio.Transforms.saveChangesButton().click();
-
- H.modal().within(() => {
- cy.findByLabelText("Name").clear().type("Model Reference Transform");
- cy.findByLabelText("Table name").clear().type("model_ref_transform");
- cy.button("Save").click();
- });
-
- cy.log("Verify edit transform in a workspace button is disabled");
- cy.findByRole("button", { name: /Edit/ }).click();
- cy.wait("@checkoutWorkspace");
- H.popover()
- .findByRole("menuitem", { name: /New workspace/ })
- .should("be.disabled")
- .trigger("mouseenter", { force: true }); // in CI realHover() does not work with disabled elements
- H.tooltip().should(
- "contain.text",
- "Transforms referencing other questions cannot be edited in a workspace.",
- );
-
- cy.log("Edit transform to remove model reference");
- H.popover().findByText("Edit definition").click();
- H.NativeEditor.type(
- '{selectall}SELECT * FROM "Schema A"."Animals" as t;',
- );
- Transforms.saveChangesButton().click();
-
- cy.log("Verify Edit transform button is now enabled");
- cy.findByRole("button", { name: /Edit/ }).should("be.enabled");
- });
-
- // unskip once GDGT-1564 is unblocked
- it.skip("should not allow workspace checkout when workspaces are disabled on DB (blocked by backend)", () => {
- createSqlTransform({
- sourceQuery: `SELECT * FROM "${TARGET_SCHEMA}"."${SOURCE_TABLE}"`,
- visitTransform: false,
- });
-
- cy.log("Disable workspaces on the database");
- cy.request("PUT", `/api/database/${WRITABLE_DB_ID}`, {
- settings: { "database-enable-workspaces": false },
- });
-
- cy.get<TransformId>("@transformId").then((transformId) => {
- H.visitTransform(transformId);
- });
-
- H.DataStudio.Transforms.editDefinitionButton().click();
-
- cy.log("Verify workspace checkout is disabled");
- // The backend should return checkout_disabled with a reason like "database-workspaces-disabled"
- // Frontend maps this to a user-friendly message via getCheckoutDisabledMessage()
- H.popover().contains("New workspace").should("be.disabled");
- H.popover().contains("New workspace").realHover();
- // TODO (Uladzimir 2026-01-30) -- update tooltip text once backend is done
- H.tooltip().should("contain.text", "cannot be edited in a workspace");
- });
- });
-
- describe("merge workspace", () => {
- it("shows target table diff and input tables diff", () => {
- H.getTableId({
- name: "Animals",
- databaseId: WRITABLE_DB_ID,
- schema: "Schema A",
- }).then((id1) => {
- H.getTableId({
- name: "Animals",
- databaseId: WRITABLE_DB_ID,
- schema: "Schema B",
- }).then((id2) => {
- createPythonTransform({
- body: TEST_PYTHON_TRANSFORM,
- sourceTables: [
- {
- alias: "foo",
- table_id: id1,
- database_id: WRITABLE_DB_ID,
- schema: "Schema A",
- },
- {
- alias: "bar",
- table_id: id2,
- database_id: WRITABLE_DB_ID,
- schema: "Schema B",
- },
- ],
- visitTransform: true,
- });
- });
- });
-
- cy.findByRole("button", { name: /Edit/ }).click();
- H.popover().findByText("New workspace").click();
-
- cy.location("pathname").should("match", /data-studio\/workspaces\/\d+/);
-
- cy.log("rename 1st table's name");
- cy.findAllByLabelText("Reset alias to default")
- .should("have.length", 2)
- .eq(0)
- .click();
-
- cy.log("change 2nd table");
- cy.findByTestId("python-data-picker")
- .findAllByText("Animals")
- .should("have.length", 2)
- .eq(1)
- .click();
- H.entityPickerModal().within(() => {
- cy.findByText("Schema C").click();
- cy.findByText("Animals").click();
- });
-
- cy.log("add 3rd table");
- cy.button(/Add a table/).click();
- cy.findByTestId("python-data-picker")
- .findByText("Select a table…")
- .click();
- H.entityPickerModal().within(() => {
- cy.findByText("Schema D").click();
- cy.findByText("Animals").click();
- });
-
- Workspaces.getSaveTransformButton().click();
-
- cy.log("change target table");
- cy.button(/Change target/).click();
- H.modal().within(() => {
- cy.findByLabelText("New table name").clear().type("epic_table");
- cy.button("Change target").click();
- });
- verifyAndCloseToast("Transform target updated");
-
- cy.button("Merge").click();
- H.modal().within(() => {
- cy.findByText("Python transform").click();
-
- Workspaces.getTransformTargetDiff().within(() => {
- cy.findByText("Transform target").should("be.visible");
- verifyNormalText("Schema A");
- verifyRemovedText("transform_table_3");
- verifyAddedText("epic_table");
- });
-
- Workspaces.getSourceTablesDiff().within(() => {
- cy.findByText("Source tables").should("be.visible");
-
- cy.log("1st table");
- verifyRemovedText("foo");
- verifyAddedText("animals");
- verifyNormalText("Schema A");
- cy.findAllByText("Animals")
- .should("have.length", 3)
- .eq(0)
- .should("have.css", "text-decoration-line", "none")
- .and("have.css", "color", COLOR_TEXT);
-
- cy.log("2nd table");
- verifyNormalText("bar");
- verifyRemovedText("Schema B");
- verifyAddedText("Schema C");
- cy.findAllByText("Animals")
- .should("have.length", 3)
- .eq(1)
- .should("have.css", "text-decoration-line", "none")
- .and("have.css", "color", COLOR_TEXT);
-
- cy.log("3rd table");
- verifyAddedText("animals_1");
- verifyAddedText("Schema D");
- cy.findAllByText("Animals")
- .should("have.length", 3)
- .eq(2)
- .should("have.css", "text-decoration-line", "none")
- .and("have.css", "color", COLOR_SUCCESS);
- });
- });
-
- cy.realPress("Escape");
-
- cy.findAllByLabelText("Remove this table")
- .should("have.length", 3)
- .last()
- .click();
- cy.findAllByLabelText("Remove this table")
- .should("have.length", 2)
- .last()
- .click();
- Workspaces.getSaveTransformButton().click();
-
- cy.button("Merge").click();
- H.modal().within(() => {
- cy.findByText("Python transform").click();
-
- Workspaces.getSourceTablesDiff().within(() => {
- cy.findByText("Source tables").should("be.visible");
-
- cy.log("2nd table - removed");
- verifyRemovedText("bar");
- verifyRemovedText("Schema B");
- cy.findAllByText("Animals")
- .should("have.length", 2)
- .eq(1)
- .should("have.css", "text-decoration-line", "line-through")
- .and("have.css", "color", COLOR_DANGER);
- });
- });
- });
-
- it(
- "should be able to check out existing Python transform with multiple input tables into a new workspace",
- { tags: ["@python"] },
- () => {
- H.setPythonRunnerSettings();
- cy.log("Create Python transform with 2 input tables");
- H.getTableId({
- name: "Animals",
- databaseId: WRITABLE_DB_ID,
- schema: "Schema A",
- }).then((id1) => {
- H.getTableId({
- name: "Animals",
- databaseId: WRITABLE_DB_ID,
- schema: "Schema B",
- }).then((id2) => {
- createPythonTransform({
- body: TEST_PYTHON_TRANSFORM_MULTI_TABLE,
- sourceTables: [
- {
- alias: "animals_a",
- table_id: id1,
- database_id: WRITABLE_DB_ID,
- schema: "Schema A",
- },
- {
- alias: "animals_b",
- table_id: id2,
- database_id: WRITABLE_DB_ID,
- schema: "Schema B",
- },
- ],
- visitTransform: true,
- });
- });
- });
-
- cy.log("Create a workspace and check out the transform");
- cy.findByRole("button", { name: /Edit/ }).click();
- H.popover().findByText("New workspace").click();
-
- cy.location("pathname").should("match", /data-studio\/workspaces\/\d+/);
-
- cy.log("Update the Python transform code");
- H.PythonEditor.clear().paste(TEST_PYTHON_TRANSFORM_MULTI_TABLE_UPDATED);
- Workspaces.getSaveTransformButton().click();
-
- cy.log("Run the transform");
- Workspaces.getRunTransformButton().click();
- Workspaces.getRunTransformButton().should(
- "have.text",
- "Ran successfully",
- );
-
- cy.log("Merge the workspace");
- Workspaces.getMergeWorkspaceButton().click();
- Workspaces.getMergeCommitInput().type("Merge Python transform");
- H.modal().within(() => {
- cy.findByText("1 transform will be merged").should("exist");
- cy.findByRole("button", { name: /Merge/ }).click();
- });
- verifyAndCloseToast("merged successfully");
-
- cy.log("Verify the merged transform runs correctly");
- Transforms.list()
- .findByRole("row", { name: /Python transform/ })
- .click();
- Transforms.runTab().click();
- runTransformAndWaitForSuccessOnTransformsPage();
- Transforms.settingsTab().click();
- getTableLink().should("contain.text", TARGET_TABLE_PYTHON).click();
-
- H.assertTableData({
- columns: ["Name", "Total Score"],
- firstRows: [
- ["Duck", "20"],
- ["Horse", "40"],
- ["Cow", "60"],
- ],
- });
- },
- );
-
- it(
- "should be able to create new SQL and Python transforms in a workspace and merge them to global list",
- { tags: ["@python"] },
- () => {
- H.setPythonRunnerSettings();
- cy.log("Create a new workspace");
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Create a new SQL transform");
- Workspaces.getWorkspaceSidebar()
- .findByLabelText("Add transform")
- .click();
- H.popover()
- .findByRole("menuitem", { name: /SQL Transform/ })
- .click();
-
- H.NativeEditor.type(
- 'SELECT * FROM "Schema A"."Animals" WHERE name = \'Duck\';',
- );
- Workspaces.getSaveTransformButton().click();
- H.modal().within(() => {
- cy.findByLabelText(/Table name/)
- .clear()
- .type("sql_table");
- cy.findByLabelText("Schema").click();
- cy.document()
- .findByRole("option", { name: /Schema A/ })
- .click();
- cy.findByRole("button", { name: /Save/ }).click();
- });
- verifyAndCloseToast("Transform saved successfully");
-
- cy.log("Create a new Python transform with 2 input tables");
- Workspaces.getWorkspaceSidebar()
- .findByLabelText("Add transform")
- .click();
- H.popover()
- .findByRole("menuitem", { name: /Python Script/ })
- .click();
-
- H.PythonEditor.clear().paste(TEST_PYTHON_TRANSFORM_MULTI_TABLE);
- Workspaces.getWorkspaceContent().within(() => {
- cy.findByTestId("python-data-picker")
- .findAllByText("Select a table…")
- .first()
- .click();
- });
- H.entityPickerModal().within(() => {
- cy.findByText("Schema A").click();
- cy.findByText("Animals").click();
- });
- Workspaces.getWorkspaceContent().within(() => {
- cy.button(/Add a table/).click();
- cy.findByTestId("python-data-picker")
- .findByText("Select a table…")
- .click();
- });
- H.entityPickerModal().within(() => {
- cy.findByText("Schema B").click();
- cy.findByText("Animals").click();
- });
-
- Workspaces.getSaveTransformButton().click();
- H.modal().within(() => {
- cy.findByLabelText(/Table name/)
- .clear()
- .type("python_table");
- cy.findByLabelText("Schema").click();
- cy.document()
- .findByRole("option", { name: /Schema A/ })
- .click();
- cy.findByRole("button", { name: /Save/ }).click();
- });
- verifyAndCloseToast("Transform saved successfully");
-
- cy.log("Merge the workspace");
- Workspaces.getMergeWorkspaceButton().click();
- Workspaces.getMergeCommitInput().type("Merge new transforms");
- H.modal().within(() => {
- cy.findByText("2 transforms will be merged").should("exist");
- cy.findByRole("button", { name: /Merge/ }).click();
- });
- verifyAndCloseToast("merged successfully");
-
- cy.log("Verify both transforms appear in global transforms list");
- Transforms.list()
- .findByRole("row", { name: /sql_table/ })
- .should("exist");
- Transforms.list()
- .findByRole("row", { name: /python_table/ })
- .should("exist");
-
- cy.log("Run SQL transform and verify results");
- Transforms.list()
- .findByRole("row", { name: /sql_table/ })
- .click();
- Transforms.runTab().click();
- runTransformAndWaitForSuccessOnTransformsPage();
- Transforms.settingsTab().click();
- getTableLink().should("contain.text", "sql_table").click();
-
- H.assertTableData({
- columns: ["Name", "Score"],
- firstRows: [["Duck", "10"]],
- });
-
- cy.log("Run Python transform and verify results");
- Workspaces.visitTransformListPage();
- Transforms.list()
- .findByRole("row", { name: /python_table/ })
- .click();
- Transforms.runTab().click();
- runTransformAndWaitForSuccessOnTransformsPage();
- Transforms.settingsTab().click();
- getTableLink().should("contain.text", "python_table").click();
-
- H.assertTableData({
- columns: ["Name", "Total Score"],
- firstRows: [["test", "0"]],
- });
- },
- );
-
- it("should preserve changed target table after merging workspace", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Check out existing SQL transform");
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- Workspaces.getSaveTransformButton().click();
-
- cy.log("Change target table settings");
- Workspaces.getTransformTargetButton().click();
- H.modal().within(() => {
- cy.findByLabelText("Schema").should("have.value", "Schema A");
- cy.findByLabelText("New table name").clear().type("renamed_table");
- cy.findByRole("button", { name: /Change target/ }).click();
- });
- verifyAndCloseToast("Transform target updated");
-
- cy.log("Merge the workspace");
- Workspaces.getMergeWorkspaceButton().click();
- Workspaces.getMergeCommitInput().type("Rename target table");
- H.modal().within(() => {
- cy.findByText("1 transform will be merged").should("exist");
-
- cy.log("Verify target table diff is displayed");
- cy.findByText("SQL transform").click();
- Workspaces.getTransformTargetDiff().within(() => {
- verifyRemovedText("transform_table_2");
- verifyAddedText("renamed_table");
- });
-
- cy.findByRole("button", { name: /Merge/ }).click();
- });
- verifyAndCloseToast("merged successfully");
-
- cy.log("Verify target table is updated in global transform");
- Transforms.list()
- .findByRole("row", { name: /SQL transform/ })
- .click();
- Transforms.settingsTab().click();
- getTableLink({ isActive: false }).should("contain.text", "renamed_table");
- });
-
- it("should merge a chain of 3 dependent transforms created in workspace", () => {
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Create Transform 1: Base transform selecting from Animals");
- Workspaces.getWorkspaceSidebar().findByLabelText("Add transform").click();
- H.popover()
- .findByRole("menuitem", { name: /SQL Transform/ })
- .click();
-
- H.NativeEditor.type('SELECT name, score FROM "Schema A"."Animals";');
- Workspaces.getSaveTransformButton().click();
- H.modal().within(() => {
- cy.findByLabelText(/Table name/)
- .clear()
- .type("chain_step_1");
- cy.findByLabelText("Schema").click();
- cy.document()
- .findByRole("option", { name: /Schema A/ })
- .click();
- cy.findByRole("button", { name: /Save/ }).click();
- });
- verifyAndCloseToast("Transform saved successfully");
-
- cy.log("Run Transform 1 to create the output table");
- Workspaces.getRunTransformButton().click();
- Workspaces.getRunTransformButton().should(
- "have.text",
- "Ran successfully",
- );
-
- cy.log("Create Transform 2: Depends on Transform 1");
- Workspaces.getWorkspaceSidebar().findByLabelText("Add transform").click();
- H.popover()
- .findByRole("menuitem", { name: /SQL Transform/ })
- .click();
-
- H.NativeEditor.type(
- 'SELECT name, score * 2 as score FROM "Schema A"."chain_step_1";',
- );
- Workspaces.getSaveTransformButton().click();
- H.modal().within(() => {
- cy.findByLabelText(/Table name/)
- .clear()
- .type("chain_step_2");
- cy.findByLabelText("Schema").click();
- cy.document()
- .findByRole("option", { name: /Schema A/ })
- .click();
- cy.findByRole("button", { name: /Save/ }).click();
- });
- verifyAndCloseToast("Transform saved successfully");
-
- cy.log("Run Transform 2");
- Workspaces.getRunTransformButton().click();
- Workspaces.getRunTransformButton().should(
- "have.text",
- "Ran successfully",
- );
-
- cy.log("Create Transform 3: Depends on Transform 2");
- Workspaces.getWorkspaceSidebar().findByLabelText("Add transform").click();
- H.popover()
- .findByRole("menuitem", { name: /SQL Transform/ })
- .click();
-
- H.NativeEditor.type(
- 'SELECT name, score * 2 as score FROM "Schema A"."chain_step_2";',
- );
- Workspaces.getSaveTransformButton().click();
- H.modal().within(() => {
- cy.findByLabelText(/Table name/)
- .clear()
- .type("chain_step_3");
- cy.findByLabelText("Schema").click();
- cy.document()
- .findByRole("option", { name: /Schema A/ })
- .click();
- cy.findByRole("button", { name: /Save/ }).click();
- });
- verifyAndCloseToast("Transform saved successfully");
-
- cy.log("Run Transform 3");
- Workspaces.getRunTransformButton().click();
- Workspaces.getRunTransformButton().should(
- "have.text",
- "Ran successfully",
- );
-
- cy.log("Merge the workspace with all 3 transforms");
- Workspaces.getMergeWorkspaceButton().click();
- Workspaces.getMergeCommitInput().type("Merge transform chain");
- H.modal().within(() => {
- cy.findByText("3 transforms will be merged").should("exist");
- cy.findByRole("button", { name: /Merge/ }).click();
- });
- verifyAndCloseToast("merged successfully");
-
- cy.log("Run chain_step_1 (first in chain)");
- Transforms.list()
- .findByRole("row", { name: /chain_step_1/ })
- .click();
- Transforms.runTab().click();
- runTransformAndWaitForSuccessOnTransformsPage();
-
- DataStudio.nav().findByRole("link", { name: "Transforms" }).click();
-
- cy.log("Run chain_step_2 (second in chain)");
- Transforms.list()
- .findByRole("row", { name: /chain_step_2/ })
- .click();
- Transforms.runTab().click();
- runTransformAndWaitForSuccessOnTransformsPage();
-
- DataStudio.nav().findByRole("link", { name: "Transforms" }).click();
-
- cy.log("Run chain_step_3 (final in chain) and verify results");
- Transforms.list()
- .findByRole("row", { name: /chain_step_3/ })
- .click();
- Transforms.runTab().click();
- runTransformAndWaitForSuccessOnTransformsPage();
- Transforms.settingsTab().click();
- getTableLink().should("contain.text", "chain_step_3").click();
-
- // Original scores: Duck=10, Horse=20, Cow=30
- // After 2 doublings (x2 x2 = x4): Duck=40, Horse=80, Cow=120
- H.assertTableData({
- columns: ["Name", "Score"],
- firstRows: [
- ["Duck", "40"],
- ["Horse", "80"],
- ["Cow", "120"],
- ],
- });
- });
- });
-
- describe("repros", () => {
- it("should not show error when editing a new transform in a workspace (GDGT-1445)", () => {
- Workspaces.visitTransformListPage();
- cy.findByLabelText("Create a transform").click();
- H.popover().findByText("SQL query").click();
- // to avoid flakiness on editor's focus
- cy.findByTestId("native-query-top-bar").should(
- "contain.text",
- "Writable Postgres12",
- );
- NativeEditor.type("select 1");
- cy.button("Save").click();
- cy.findByPlaceholderText("My Great Transform").type("My transform");
- H.modal().button("Save").click();
-
- cy.button(/Edit/).click();
- H.popover().findByText("New workspace").click();
- H.undoToast().should("not.exist");
- Workspaces.getWorkspaceTabs().within(() => {
- H.tabsShouldBe("My transform", ["Setup", "Graph", "My transform"]);
- });
- });
-
- it("should detect changes after closing and reopening a transform tab (GDGT-1535, GDGT-1551)", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Open transform and make edits");
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- H.NativeEditor.type(" LIMIT 2");
-
- cy.log("Save the transform to workspace");
- Workspaces.getSaveTransformButton().click();
- Workspaces.getSaveTransformButton().should("be.disabled");
-
- cy.log("Make additional edits");
- H.NativeEditor.type(";");
- Workspaces.getSaveTransformButton().should("be.enabled");
-
- cy.log("Close the transform tab");
- Workspaces.getWorkspaceContent().within(() => {
- cy.findByRole("tab", { name: "SQL transform" })
- .findByLabelText("close icon")
- .click();
- });
-
- cy.log("Reopen the transform tab by clicking in Code tab");
- Workspaces.getWorkspaceTransforms().findByText("SQL transform").click();
-
- cy.log("Verify Save button is enabled (changes should be detected)");
- Workspaces.getSaveTransformButton().should("be.enabled");
-
- cy.log("Verify the edited content is preserved");
- H.NativeEditor.value().should("contain", "LIMIT 2;");
-
- cy.log("Create a new unsaved transform in the workspace");
- Workspaces.getWorkspaceSidebar().findByLabelText("Add transform").click();
- H.popover()
- .findByRole("menuitem", { name: /SQL Transform/ })
- .click();
-
- cy.log("Verify the unsaved transform tab is opened");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("New transform", [
- "Setup",
- "Graph",
- "SQL transform",
- "New transform",
- ]);
- });
-
- cy.log("Close the unsaved transform tab");
- Workspaces.getWorkspaceContent().within(() => {
- cy.findByRole("tab", { name: "New transform" })
- .findByLabelText("close icon")
- .click();
- });
-
- cy.log("Reopen the unsaved transform tab by clicking in Code tab");
- Workspaces.getWorkspaceTransforms().findByText("New transform").click();
-
- cy.log("Verify the unsaved transform tab is reopened");
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("New transform", [
- "Setup",
- "Graph",
- "SQL transform",
- "New transform",
- ]);
- });
- });
-
- it("should show empty state after creating, archiving, and deleting a workspace", () => {
- Workspaces.visitWorkspaces();
-
- // Create a new workspace
- createWorkspace();
- registerWorkspaceAliasName("workspaceToDelete");
-
- // Archive the workspace immediately
- cy.get<string>("@workspaceToDelete").then((workspaceName) => {
- Workspaces.getWorkspaceItemActions(workspaceName).click();
- H.popover().findByText("Archive").click();
- verifyAndCloseToast("Workspace archived successfully");
-
- // Verify it's archived
- Workspaces.getWorkspaceItem(workspaceName).should(
- "contain.text",
- "Archived",
- );
-
- // Delete the archived workspace
- Workspaces.getWorkspaceItemActions(workspaceName).click();
- H.popover().findByText("Delete").click();
- H.modal().findByText("Delete").click();
- verifyAndCloseToast("Workspace deleted successfully");
-
- // Verify workspace is gone
- Workspaces.getWorkspaceItem(workspaceName).should("not.exist");
- });
-
- // Verify empty state is shown again
- Workspaces.getWorkspacesPage()
- .findByText("No active workspaces")
- .should("be.visible");
- Workspaces.getWorkspacesSection()
- .findByText("No workspaces yet")
- .should("be.visible");
- });
-
- it("should show correct run status when switching tabs (GDGT-1571)", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.log("Create first SQL transform that will succeed");
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
- H.NativeEditor.type(" LIMIT 1;");
- Workspaces.getSaveTransformButton().click();
-
- cy.log("Run the successful transform");
- Workspaces.getRunTransformButton().click();
- Workspaces.getRunTransformButton().should(
- "have.text",
- "Ran successfully",
- );
-
- cy.log("Create second SQL transform that will fail");
- Workspaces.getWorkspaceSidebar().findByLabelText("Add transform").click();
- H.popover()
- .findByRole("menuitem", { name: /SQL Transform/ })
- .click();
- H.NativeEditor.type("INVALID SQL QUERY");
- H.NativeEditor.rejectCompletion();
- Workspaces.getSaveTransformButton().click();
-
- H.modal().within(() => {
- cy.findByLabelText("Name").clear().type("Failing transform");
- cy.findByText("Save").click();
- });
-
- cy.log("Run the failing transform");
- Workspaces.getRunTransformButton().click();
- Workspaces.getRunTransformButton().should("have.text", "Run failed");
- Workspaces.getRunStatus().should("contain.text", "Last run failed");
-
- cy.log("Switch to the first transform tab");
- Workspaces.getWorkspaceContent().within(() => {
- cy.findByRole("tab", { name: "SQL transform" }).click();
- });
- Workspaces.getRunStatus().should(
- "have.text",
- "Last ran a few seconds ago successfully.",
- );
- });
-
- it("should immediately open transform tab and show a loading state (GDGT-1531)", () => {
- createTransforms();
- Workspaces.visitWorkspaces();
- createWorkspace();
-
- cy.intercept("GET", "/api/transform/*", (request) => {
- request.reply((response) => {
- response.setDelay(2000);
- response.send();
- });
- }).as("getTransform");
-
- cy.log("Create first SQL transform that will succeed");
- Workspaces.getMainlandTransforms().findByText("SQL transform").click();
-
- Workspaces.getWorkspaceContent().within(() => {
- H.tabsShouldBe("SQL transform", ["Setup", "Graph", "SQL transform"]);
- cy.findByTestId("loading-indicator").should("be.visible");
- });
-
- cy.wait("@getTransform");
- cy.findByTestId("loading-indicator").should("not.exist");
- });
- });
-});
-
-function enableWorkspacesInDb(id: DatabaseId) {
- cy.request("POST", `/api/database/${id}/permission/workspace/check`, {
- cached: false,
- });
- cy.request("PUT", `/api/database/${id}`, {
- settings: { "database-enable-workspaces": true },
- });
-}
-
-function createWorkspace() {
- Workspaces.getNewWorkspaceButton().click();
- cy.findByTestId("loading-indicator").should("not.exist");
-}
-
-const TEST_PYTHON_TRANSFORM = dedent`
- import pandas as pd
-
- def transform(foo):
- return pd.DataFrame([{"foo": 42 }])
-`;
-
-const TEST_PYTHON_TRANSFORM_MULTI_TABLE = dedent`
- import pandas as pd
-
- def transform(animals_a, animals_b):
- return pd.DataFrame([{"name": "test", "total_score": 0}])
-`;
-
-const TEST_PYTHON_TRANSFORM_MULTI_TABLE_UPDATED = dedent`
- import pandas as pd
-
- def transform(animals_a, animals_b):
- # Combine scores from both tables by name
- merged = animals_a.merge(animals_b, on="name", suffixes=("_a", "_b"))
- result = pd.DataFrame({
- "name": merged["name"],
- "total_score": merged["score_a"] + merged["score_b"]
- })
- return result
-`;
-
-function createTransforms({ visit }: { visit?: boolean } = { visit: false }) {
- createMbqlTransform({
- targetTable: TARGET_TABLE_MBQL,
- });
-
- H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then((id) => {
- createPythonTransform({
- body: TEST_PYTHON_TRANSFORM,
- sourceTables: [
- {
- alias: "foo",
- table_id: id,
- database_id: WRITABLE_DB_ID,
- schema: TARGET_SCHEMA,
- },
- ],
- });
- });
-
- createSqlTransform({
- sourceQuery: `SELECT * FROM "${TARGET_SCHEMA}"."${SOURCE_TABLE}"`,
- visitTransform: visit,
- });
-}
-
-function createMbqlTransform(
- opts: {
- sourceTable?: string;
- targetTable?: string;
- targetSchema?: string | null;
- tagIds?: TransformTagId[];
- name?: string;
- databaseId?: number;
- visitTransform?: boolean;
- } = {},
-) {
- return H.createMbqlTransform({
- sourceTable: SOURCE_TABLE,
- targetTable: TARGET_TABLE_MBQL,
- targetSchema: TARGET_SCHEMA,
- name: "MBQL transform",
- ...opts,
- });
-}
-
-function createSqlTransform(opts: {
- sourceQuery: string;
- targetTable?: string;
- targetSchema?: string;
- tagIds?: TransformTagId[];
- visitTransform?: boolean;
-}) {
- return H.createSqlTransform({
- targetTable: TARGET_TABLE_SQL,
- targetSchema: TARGET_SCHEMA,
- ...opts,
- });
-}
-
-function createPythonTransform(opts: {
- body: string;
- sourceTables: PythonTransformTableAliases;
- targetTable?: string;
- targetSchema?: string;
- tagIds?: TransformTagId[];
- visitTransform?: boolean;
-}) {
- return H.createPythonTransform({
- targetTable: TARGET_TABLE_PYTHON,
- targetSchema: TARGET_SCHEMA,
- ...opts,
- });
-}
-
-function getTableLink({ isActive = true }: { isActive?: boolean } = {}) {
- return cy
- .findByTestId("table-link")
- .should("have.attr", "aria-disabled", String(!isActive));
-}
-
-function runTransformAndWaitForSuccess() {
- Workspaces.getRunTransformButton().click();
- Workspaces.getRunTransformButton().should("have.text", "Ran successfully");
-}
-
-function runTransformAndWaitForSuccessOnTransformsPage() {
- getRunButton().click();
- getRunButton().should("have.text", "Ran successfully");
-}
-
-function getRunButton(options: { timeout?: number } = {}) {
- return cy.findAllByTestId("run-button").eq(0, options);
-}
-
-function verifyAndCloseToast(message: string) {
- H.undoToast().should("contain.text", message);
- H.undoToast().icon("close").click({ force: true });
-}
-
-function registerWorkspaceAliasName(name: string) {
- cy.wait("@createWorkspace").then((interception) => {
- const workspaceName = interception.response?.body?.name;
- // Backend returns randomized name.
- cy.wrap(workspaceName).as(name);
- });
-}
-
-function verifyNormalText(text: string) {
- cy.findByText(text)
- .should("have.css", "text-decoration-line", "none")
- .and("have.css", "color", COLOR_TEXT);
-}
-
-function verifyAddedText(text: string) {
- cy.findByText(text)
- .should("have.css", "text-decoration-line", "none")
- .and("have.css", "color", COLOR_SUCCESS);
-}
-
-function verifyRemovedText(text: string) {
- cy.findByText(text)
- .should("have.css", "text-decoration-line", "line-through")
- .and("have.css", "color", COLOR_DANGER);
-}
diff --git a/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj b/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj
index 3e1423f9ba9..6b7e5d7aea6 100644
--- a/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj
+++ b/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj
@@ -39,7 +39,6 @@
[metabase-enterprise.transforms-python.api]
[metabase-enterprise.transforms.api]
[metabase-enterprise.upload-management.api]
- [metabase-enterprise.workspaces.api]
[metabase.api.macros :as api.macros]
[metabase.api.util.handlers :as handlers]
[metabase.util.i18n :refer [deferred-tru]]))
@@ -70,8 +69,7 @@
:metabot-v3 (deferred-tru "Metabot")
:cloud-custom-smtp (deferred-tru "Custom SMTP")
:support-users (deferred-tru "Support Users")
- :transforms-python (deferred-tru "Transforms Python")
- :workspaces (deferred-tru "Workspaces")})
+ :transforms-python (deferred-tru "Transforms Python")})
(defn- premium-handler [handler required-feature]
(let [handler (cond-> handler
@@ -129,8 +127,7 @@
"/stale" (premium-handler metabase-enterprise.stale.api/routes :collection-cleanup)
"/support-access-grant" (premium-handler metabase-enterprise.support-access-grants.api/routes :support-users)
"/tenant" (premium-handler metabase-enterprise.tenants.api/routes :tenants)
- "/upload-management" (premium-handler metabase-enterprise.upload-management.api/routes :upload-management)
- "/workspace" (premium-handler metabase-enterprise.workspaces.api/routes :workspaces)})
+ "/upload-management" (premium-handler metabase-enterprise.upload-management.api/routes :upload-management)})
;;; ↑↑↑ KEEP THIS SORTED OR ELSE ↑↑↑
(def ^:private routes-map
diff --git a/enterprise/backend/src/metabase_enterprise/core/init.clj b/enterprise/backend/src/metabase_enterprise/core/init.clj
index 51a9f40dd5c..798fc2c6574 100644
--- a/enterprise/backend/src/metabase_enterprise/core/init.clj
+++ b/enterprise/backend/src/metabase_enterprise/core/init.clj
@@ -21,5 +21,4 @@
[metabase-enterprise.sso.init]
[metabase-enterprise.stale.init]
[metabase-enterprise.support-access-grants.init]
- [metabase-enterprise.transforms-python.init]
- [metabase-enterprise.workspaces.init]))
+ [metabase-enterprise.transforms-python.init]))
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj b/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj
index 56abd204bef..f04b4f2e55c 100644
--- a/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj
+++ b/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj
@@ -139,17 +139,4 @@
"User"
"UserKeyValue"
"UserParameterValue"
- "ViewLog"
- "Workspace"
- ;; TODO (lbrdnk 2025-12-17) -- I've added rest of the workspace models. I believe some of those will be available for
- ;; serialization, hence we should revisit this later in the project.
- "WorkspaceInput"
- "WorkspaceInputExternal"
- "WorkspaceInputTransform"
- "WorkspaceLog"
- "WorkspaceMerge"
- "WorkspaceMergeTransform"
- "WorkspaceGraph"
- "WorkspaceOutput"
- "WorkspaceOutputExternal"
- "WorkspaceTransform"])
+ "ViewLog"])
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/api.clj b/enterprise/backend/src/metabase_enterprise/workspaces/api.clj
deleted file mode 100644
index 89f98883867..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/api.clj
+++ /dev/null
@@ -1,722 +0,0 @@
-(ns metabase-enterprise.workspaces.api
- "`/api/ee/workspace/` routes"
- (:require
- [clojure.set :as set]
- [clojure.walk :as walk]
- [honey.sql.helpers :as sql.helpers]
- [metabase-enterprise.workspaces.api.common :as ws.api.common]
- [metabase-enterprise.workspaces.common :as ws.common]
- [metabase-enterprise.workspaces.isolation :as ws.isolation]
- [metabase-enterprise.workspaces.merge :as ws.merge]
- [metabase-enterprise.workspaces.models.workspace :as ws.model]
- [metabase-enterprise.workspaces.models.workspace-input-external]
- [metabase-enterprise.workspaces.models.workspace-log]
- [metabase-enterprise.workspaces.models.workspace-output-external]
- [metabase-enterprise.workspaces.types :as ws.t]
- [metabase.api.common :as api]
- [metabase.api.macros :as api.macros]
- [metabase.api.routes.common :refer [+auth]]
- [metabase.config.core :as config]
- [metabase.driver.util :as driver.u]
- [metabase.request.core :as request]
- [metabase.util :as u]
- [metabase.util.i18n :as i18n :refer [tru]]
- [metabase.util.malli.registry :as mr]
- [metabase.util.malli.schema :as ms]
- [toucan2.core :as t2]))
-
-(set! *warn-on-reflection* true)
-
-;;; --------------------------------------------------- Schemas -------------------------------------------------------
-
-(def ^:private WorkspaceStatus
- (into [:enum] ws.api.common/computed-statuses))
-
-(def ^:private Workspace
- [:map
- [:id ::ws.t/appdb-id]
- [:name :string]
- [:collection_id ::ws.t/appdb-id]
- [:database_id ::ws.t/appdb-id]
- [:status WorkspaceStatus]
- [:created_at ms/TemporalInstant]
- [:updated_at ms/TemporalInstant]])
-
-(def ^:private TransformSource ws.api.common/TransformSource)
-
-(def ^:private TransformTarget
- [:map {:closed true}
- [:database {:optional true} ::ws.t/appdb-id]
- [:type [:enum "table"]]
- [:schema {:optional true} [:maybe [:string {:min 1}]]]
- [:name [:string {:min 1}]]
- [:table_id {:optional true} [:maybe ::ws.t/appdb-id]]])
-
-(def ^:private InputTable
- [:map
- [:db_id ::ws.t/appdb-id]
- [:schema [:maybe :string]]
- [:table :string]
- [:table_id [:maybe ::ws.t/appdb-id]]])
-
-(def ^:private OutputTable
- [:map
- [:db_id ::ws.t/appdb-id]
- [:global [:map
- [:transform_id [:maybe ::ws.t/appdb-id]]
- [:schema [:maybe :string]]
- [:table :string]
- [:table_id [:maybe ::ws.t/appdb-id]]]]
- [:isolated [:map
- [:transform_id [:or ::ws.t/ref-id ::ws.t/appdb-id]]
- [:schema :string]
- [:table :string]
- [:table_id [:maybe ::ws.t/appdb-id]]]]])
-
-(def ^:private WorkspaceTransform
- [:map
- [:ref_id ::ws.t/ref-id]
- [:global_id [:maybe ::ws.t/appdb-id]]
- [:name :string]
- [:description [:maybe :string]]
- [:source :map]
- [:target :map]
- [:target_stale [:maybe :boolean]]
- [:workspace_id ::ws.t/appdb-id]
- [:creator_id [:maybe ::ws.t/appdb-id]]
- [:archived_at :any]
- [:created_at :any]
- [:updated_at :any]
- [:last_run_at :any]
- [:last_run_status [:maybe :string]]
- [:last_run_message [:maybe :string]]])
-
-(def ^:private WorkspaceTransformListing
- [:map {:closed true}
- [:ref_id ::ws.t/ref-id]
- [:global_id [:maybe ::ws.t/appdb-id]]
- [:name :string]
- [:source_type [:maybe :keyword]]
- [:creator_id [:maybe ::ws.t/appdb-id]]])
-
-(def ^:private ExternalTransform
- [:map
- [:id ::ws.t/appdb-id]
- [:name :string]
- [:source_type :keyword]
- [:checkout_disabled [:maybe :string]]])
-
-(def ^:private PendingInput
- [:map
- [:db_id ::ws.t/appdb-id]
- [:schema [:maybe :string]]
- [:table :string]])
-
-(def ^:private GraphNode
- [:map
- [:id [:or ::ws.t/appdb-id ::ws.t/ref-id]]
- [:type [:enum :input-table :external-transform :workspace-transform]]
- [:dependents_count [:map-of [:enum :input-table :external-transform :workspace-transform] ms/PositiveInt]]
- [:data :map]])
-
-(def ^:private GraphEdge
- [:map
- [:from_entity_id [:or ::ws.t/appdb-id ::ws.t/ref-id]]
- [:from_entity_type :string]
- [:to_entity_id [:or ::ws.t/appdb-id ::ws.t/ref-id]]
- [:to_entity_type :string]])
-
-(def ^:private GraphResult
- [:map
- [:nodes [:sequential GraphNode]]
- [:edges [:sequential GraphEdge]]])
-
-;;; --------------------------------------------------- Routes -------------------------------------------------------
-
-(def ^:private WorkspaceListing
- [:map {:closed true}
- [:id ::ws.t/appdb-id]
- [:database_id ::ws.t/appdb-id]
- [:name :string]
- [:status WorkspaceStatus]
- [:updated_at ms/TemporalInstant]])
-
-(api.macros/defendpoint :get "/" :- [:map {:closed true}
- [:items [:sequential WorkspaceListing]]
- [:limit [:maybe :int]]
- [:offset [:maybe :int]]]
- "Get a list of all workspaces"
- [_route-params
- _query-params]
- {:items (->> (t2/select [:model/Workspace :id :name :database_id :base_status :db_status :updated_at]
- (cond-> {:order-by [[:created_at :desc]]}
- (request/limit) (sql.helpers/limit (request/limit))
- (request/offset) (sql.helpers/offset (request/offset))))
- (mapv #(-> %
- (dissoc :base_status :db_status)
- (assoc :status (ws.model/computed-status %)))))
- :limit (request/limit)
- :offset (request/offset)})
-
-(api.macros/defendpoint :get "/:ws-id/table"
- :- [:map {:closed true}
- [:inputs [:sequential InputTable]]
- [:outputs [:sequential OutputTable]]]
- "Get workspace tables"
- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]
- _query-params]
- (ws.api.common/get-workspace-tables ws-id))
-
-(api.macros/defendpoint :get "/:ws-id" :- Workspace
- "Get a single workspace by ID"
- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]
- _query-params]
- (ws.api.common/get-workspace ws-id))
-
-(api.macros/defendpoint :get "/:ws-id/log"
- :- [:map
- [:workspace_id ms/PositiveInt]
- [:status WorkspaceStatus]
- [:updated_at :any]
- [:last_completed_at [:maybe :any]]
- [:logs [:sequential [:map
- [:id ms/PositiveInt]
- [:task :keyword]
- [:description ms/LocalizedString]
- [:started_at :any]
- [:updated_at :any]
- [:completed_at [:maybe :any]]
- [:status [:maybe :keyword]]
- [:message [:maybe :string]]]]]]
- "Get workspace creation status and recent log entries for polling during async setup"
- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]
- _query-params]
- (ws.api.common/get-workspace-log ws-id))
-
-(def ^:private CreateWorkspace
- [:map
- [:name {:optional true} [:string {:min 1}]]
- [:database_id {:optional true} ::ws.t/appdb-id]])
-
-(defn- first-supported-database-id
- "Return the ID of the first database that supports workspaces, or nil if none."
- []
- (:id
- (u/seek #(driver.u/supports? (:engine %) :workspace %)
- (t2/select :model/Database :is_audit false :is_sample false {:order-by [:name]}))))
-
-(api.macros/defendpoint :post "/" :- Workspace
- "Create a new workspace
-
- Potential payload:
- {:name \"a\" :database_id 2}}"
- [_route-params
- _query-params
- {:keys [database_id] :as body} :- CreateWorkspace]
- (when database_id
- (ws.api.common/check-transforms-enabled! database_id))
-
- ;; If no database_id provided, use first supported DB as provisional default (uninitialized workspace)
- (let [provisional? (not database_id)
- database-id (or database_id
- (api/check-400 (first-supported-database-id)
- (tru "No supported databases configured. Please add a database that supports workspaces.")))]
- (ws.api.common/ws->response (ws.common/create-workspace! api/*current-user-id*
- (assoc body
- :database_id database-id
- :provisional? provisional?)))))
-
-(defn- db-unsupported-reason [db]
- (when (not (driver.u/supports? (:engine db) :workspace db))
- "Database type not supported."))
-
-(api.macros/defendpoint :get "/enabled" :- [:map [:supported :boolean] [:reason {:optional true} :string]]
- "Test whether the current user can use Workspaces. Optionally takes a specific database.
- Factors include: driver support, database user privileges, metabase permissions."
- [_url-params
- {:keys [database-id]} :- [:map [:database-id {:optional true} ms/PositiveInt]]]
- (if-let [reason (when database-id
- (db-unsupported-reason (api/check-404 (t2/select-one :model/Database database-id))))]
- {:supported false, :reason reason}
- {:supported true}))
-
-(api.macros/defendpoint :get "/database" :- [:map
- [:databases
- [:sequential [:map
- [:id ms/PositiveInt]
- [:name :string]
- [:enabled :boolean]
- [:permissions_status {:optional true}
- [:map
- [:status :string]
- [:checked_at :string]
- [:error {:optional true} :string]]]]]]]
- "Get a list supported databases, and whether they're enabled and have required permissions."
- [_url-params
- _query-params]
- (let [databases (->> (t2/select [:model/Database :id :name :engine :settings :workspace_permissions_status]
- :is_audit false :is_sample false {:order-by [:name]})
- (filter #(driver.u/supports? (:engine %) :workspace %)))]
- {:databases (mapv (fn [{:keys [id name workspace_permissions_status settings]}]
- {:id id
- :name name
- :enabled (boolean (:database-enable-workspaces settings))
- :workspace_permissions_status (or workspace_permissions_status {:status "unknown"})})
- databases)}))
-
-(api.macros/defendpoint :put "/:ws-id" :- Workspace
- "Update simple workspace properties.
-
- Can set database_id only on uninitialized workspaces."
- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]
- _query-params
- {:keys [name database_id]} :- [:map {:closed true}
- [:name {:optional true} [:string {:min 1}]]
- [:database_id {:optional true} ::ws.t/appdb-id]]]
- (let [workspace (api/check-404 (t2/select-one :model/Workspace :id ws-id))
- _ (api/check-400 (not= :archived (:base_status workspace)) "Cannot update an archived workspace")
- data (cond-> {}
- database_id (-> (u/prog1
- (api/check-400 (= :uninitialized (:db_status workspace))
- "Can only set database_id on uninitialized workspace")
- (ws.api.common/check-transforms-enabled! database_id))
- (assoc :database_id database_id))
- name (assoc :name name))]
- (ws.api.common/ws->response
- (if (seq data)
- (do
- (t2/update! :model/Workspace ws-id data)
- (t2/select-one :model/Workspace :id ws-id))
- workspace))))
-
-(api.macros/defendpoint :post "/:ws-id/archive" :- Workspace
- "Archive a workspace. Deletes the isolated schema and tables, but preserves mirrored entities."
- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]
- _query-params
- _body-params]
- (ws.api.common/archive-workspace! ws-id))
-
-(api.macros/defendpoint :post "/:ws-id/unarchive" :- Workspace
- "Restore an archived workspace. Recreates the isolated schema and tables."
- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]
- _query-params
- _body-params]
- (let [ws (api/check-404 (t2/select-one :model/Workspace :id ws-id))]
- (api/check-400 (= :archived (:base_status ws)) "You cannot unarchive a workspace that is not archived")
- (ws.model/unarchive! ws)
- (-> (t2/select-one :model/Workspace :id ws-id)
- ws.api.common/ws->response)))
-
-(api.macros/defendpoint :delete "/:ws-id" :- [:map [:ok [:= true]]]
- "Delete a workspace and all its contents, including mirrored entities."
- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]
- _query-params]
- (let [ws (api/check-404 (t2/select-one :model/Workspace :id ws-id))]
- (api/check-400 (= :archived (:base_status ws)) "You cannot delete a workspace without first archiving it")
- (ws.model/delete! ws)
- {:ok true}))
-
-(api.macros/defendpoint :get "/:ws-id/external/transform" :- [:map [:transforms [:sequential ExternalTransform]]]
- "Get transforms that are external to the workspace, i.e. no matching workspace_transform row exists."
- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]
- {:keys [database-id]} :- [:map [:database-id {:optional true} ::ws.t/appdb-id]]]
- (ws.api.common/get-external-transforms ws-id database-id))
-
-(api.macros/defendpoint :post "/:ws-id/run"
- :- [:map
- [:succeeded [:sequential ::ws.t/ref-id]]
- [:failed [:sequential ::ws.t/ref-id]]
- [:not_run [:sequential ::ws.t/ref-id]]]
- "Execute all transforms in the workspace in dependency order.
- Returns which transforms succeeded, failed, and were not run."
- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]
- _query-params
- ;; Hmmm, I wonder why this isn't a boolean? T_T
- {:keys [stale_only]} :- [:map [:stale_only {:optional true} ::ws.t/flag]]]
- (ws.api.common/run-workspace! ws-id stale_only))
-
-(api.macros/defendpoint :get "/:ws-id/graph" :- GraphResult
- "Display the dependency graph between the Changeset and the (potentially external) entities that they depend on."
- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]
- _query-params]
- (ws.api.common/get-workspace-graph ws-id))
-
-;;; ---------------------------------------- Problems/Validation ----------------------------------------
-
-(api.macros/defendpoint :get "/:ws-id/problem" :- [:sequential ::ws.t/problem]
- "Detect problems in the workspace that would affect downstream transforms after merge.
-
- Returns a list of problems, each with:
- - category: the problem category (e.g. 'unused', 'internal-downstream', 'external-downstream')
- - problem: the specific problem (e.g. 'not-run', 'stale', 'removed-field')
- - severity: :error, :warning, or :info
- - block-merge: whether this problem prevents merging
- - data: extra information, shape depends on the problem type
-
- See `metabase-enterprise.workspaces.types/problem-types` for the full list."
- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]
- _query-params]
- (ws.api.common/get-workspace-problems ws-id))
-
-(api.macros/defendpoint :post "/:ws-id/transform/validate/target"
- :- [:map [:status :int] [:body [:or :string i18n/LocalizedString]]]
- "Validate the target table for a workspace transform"
- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]
- {:keys [transform-id]} :- [:map [:transform-id {:optional true} ::ws.t/ref-id]]
- {:keys [db_id target]} :- [:map
- [:db_id {:optional true} ::ws.t/appdb-id]
- [:target [:map
- [:database {:optional true} ::ws.t/appdb-id]
- [:type :string]
- [:schema [:maybe :string]]
- [:name :string]]]]]
- (ws.api.common/validate-target ws-id transform-id db_id target))
-
-(api.macros/defendpoint :post "/:ws-id/transform"
- :- WorkspaceTransform
- "Add another transform to the Changeset. This could be a fork of an existing global transform, or something new."
- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]
- _query-params
- body :- [:map #_{:closed true}
- [:name :string]
- [:description {:optional true} [:maybe :string]]
- [:source TransformSource]
- [:target TransformTarget]]]
- (ws.api.common/create-workspace-transform! ws-id body))
-
-(api.macros/defendpoint :get "/:ws-id/transform" :- [:map [:transforms [:sequential WorkspaceTransformListing]]]
- "Get all transforms in a workspace."
- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]]
- (ws.api.common/list-transforms ws-id))
-
-(api.macros/defendpoint :get "/:ws-id/transform/:tx-id" :- WorkspaceTransform
- "Get a specific transform in a workspace."
- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]]
- (ws.api.common/fetch-ws-transform ws-id tx-id))
-
-(api.macros/defendpoint :put "/:ws-id/transform/:tx-id" :- WorkspaceTransform
- "Update or create a transform in a workspace.
- If the transform exists, updates it. If it doesn't exist, creates a new transform with the provided ref_id.
- For creation, name, source, and target are required."
- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]
- _query-params
- body :- [:map
- [:name {:optional true} :string]
- [:description {:optional true} [:maybe :string]]
- [:source {:optional true} TransformSource]
- [:target {:optional true} TransformTarget]]]
- (ws.api.common/update-transform! ws-id tx-id body))
-
-(api.macros/defendpoint :post "/:ws-id/transform/:tx-id/archive" :- :nil
- "Mark the given transform to be archived when the workspace is merged.
- For provisional transforms we will skip even creating it in the first place."
- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]]
- (ws.api.common/archive-transform! ws-id tx-id))
-
-(api.macros/defendpoint :post "/:ws-id/transform/:tx-id/unarchive" :- :nil
- "Unmark the given transform for archival. This will recall the last definition it had within the workspace."
- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]]
- (ws.api.common/unarchive-transform! ws-id tx-id))
-
-(api.macros/defendpoint :delete "/:ws-id/transform/:tx-id" :- :nil
- "Discard a transform from the changeset.
- Equivalent to resetting a checked-out transform to its global definition, or deleting a provisional transform."
- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]]
- (ws.api.common/delete-transform! ws-id tx-id))
-
-(api.macros/defendpoint :post "/:ws-id/transform/:tx-id/run"
- :- ::ws.t/execution-result
- "Run a transform in a workspace.
-
- App DB changes are rolled back. Warehouse DB changes persist.
-
- When run_stale_ancestors is true, any stale ancestor transforms will be executed first
- in dependency order. If any ancestor fails, execution stops and remaining ancestors
- are marked as not_run. The target transform will not run if any ancestor failed."
- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]
- _query-params
- {:keys [run_stale_ancestors]} :- [:map [:run_stale_ancestors {:optional true} ::ws.t/flag]]]
- (ws.api.common/run-transform! ws-id tx-id run_stale_ancestors))
-
-(api.macros/defendpoint :post "/:ws-id/transform/:tx-id/dry-run"
- :- ::ws.t/query-result
- "Dry-run a transform in a workspace without persisting to the target table.
-
- Returns the first 2000 rows of transform output for preview purposes.
- Does not update last_run_at or create any database tables.
-
- When run_stale_ancestors is true, any stale ancestor transforms will be executed first
- in dependency order (these ARE persisted). If any ancestor fails, execution stops and
- the dry-run will not proceed."
- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]
- _query-params
- {:keys [run_stale_ancestors]} :- [:map [:run_stale_ancestors {:optional true} ::ws.t/flag]]]
- (ws.api.common/dry-run-transform! ws-id tx-id run_stale_ancestors))
-
-(api.macros/defendpoint :post "/:ws-id/query"
- :- ::ws.t/query-result
- "Execute an arbitrary SQL query in the workspace's isolated database context.
- Table references are remapped to isolated workspace tables.
- Returns the first 2000 rows of query results."
- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]
- _query-params
- {:keys [sql]} :- [:map [:sql [:string {:min 1}]]]]
- (ws.api.common/execute-query! ws-id sql))
-
-;;; ---------------------------------------- Input Grant Endpoints ----------------------------------------
-
-(api.macros/defendpoint :get "/:ws-id/input/pending"
- :- [:map [:inputs [:sequential PendingInput]]]
- "List all input tables that haven't been granted access yet, excluding tables shadowed by workspace outputs."
- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]]
- (ws.api.common/get-pending-inputs ws-id))
-
-(api.macros/defendpoint :post "/:ws-id/input/grant"
- :- [:map
- [:already_granted [:sequential [:map [:db_id ms/PositiveInt] [:schema [:maybe :string]] [:table :string]]]]
- [:newly_granted [:sequential [:map [:db_id ms/PositiveInt] [:schema [:maybe :string]] [:table :string]]]]]
- "Grant read access to input tables by table coordinates. Superuser only.
- Idempotent - returns which tables were already granted vs newly granted."
- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]
- _query-params
- {:keys [tables]} :- [:map [:tables [:sequential [:map
- [:db_id ms/PositiveInt]
- [:schema [:maybe :string]]
- [:table :string]]]]]]
- (let [workspace (api/check-404 (t2/select-one :model/Workspace ws-id))
- ;; Batch lookup: one query per (db_id, schema) group for efficiency
- input-lookup (into {}
- (for [[_ group] (group-by (juxt :db_id :schema) tables)
- :let [db-id (:db_id (first group))
- schema (:schema (first group))
- names (mapv :table group)]
- row (t2/select [:model/WorkspaceInput :id :db_id :schema :table :access_granted]
- :workspace_id ws-id
- :db_id db-id
- :schema schema
- :table [:in names])]
- [[(:db_id row) (:schema row) (:table row)] row]))
- all-inputs (mapv #(get input-lookup [(:db_id %) (:schema %) (:table %)]) tables)]
- (when (some nil? all-inputs)
- (api/check-400 false
- (str "The following tables do not have corresponding input rows: "
- (pr-str (keep (fn [[table input]] (when-not input table))
- (map vector tables all-inputs))))))
- (let [{already-granted true ungranted false} (group-by :access_granted all-inputs)]
- ;; Grant access to ungranted tables, grouped by db_id
- (when (seq ungranted)
- (doseq [[db-id inputs] (group-by :db_id ungranted)
- :let [database (t2/select-one :model/Database :id db-id)
- tables (mapv (fn [{:keys [schema table]}] {:schema schema :name table}) inputs)]]
- (ws.isolation/grant-read-access-to-tables! database workspace tables))
- (t2/update! :model/WorkspaceInput {:id [:in (map :id ungranted)]} {:access_granted true}))
- {:already_granted (mapv #(select-keys % [:db_id :schema :table]) already-granted)
- :newly_granted (mapv #(select-keys % [:db_id :schema :table]) ungranted)})))
-
-;;; ---------------------------------------- Checkout ----------------------------------------
-
-(def ^:private CheckoutTransformLegacy
- "Legacy format for workspace checkout transforms (DEPRECATED)."
- [:map
- [:id ::ws.t/ref-id]
- [:name :string]
- [:workspace [:map
- [:id ms/PositiveInt]
- [:name :string]]]])
-
-(def ^:private WorkspaceWithCheckout
- "Workspace with checkout status information."
- [:map
- [:id ::ws.t/appdb-id]
- [:name :string]
- [:status WorkspaceStatus]
- [:existing [:maybe [:map
- [:ref_id ::ws.t/ref-id]
- [:name :string]]]]])
-
-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-route-uses-kebab-case]}
-(api.macros/defendpoint :get "/checkout"
- :- [:map
- [:checkout_disabled [:maybe [:enum "mbql" "card-reference" "unknown-type"]]]
- [:workspaces [:sequential WorkspaceWithCheckout]]
- [:transforms [:sequential CheckoutTransformLegacy]]]
- "Get checkout status for a global transform.
-
- Returns:
- - checkout_disabled: Why this transform cannot be checked out (nil if allowed)
- - workspaces: All workspaces for this transform's database, with checkout status
- - transforms: (DEPRECATED) Use :workspaces instead"
- [_route-params
- {:keys [transform-id]} :- [:map {:closed true} [:transform-id ms/PositiveInt]]]
- (let [transform (api/check-404
- (t2/select-one [:model/Transform :id :target_db_id :source_type :source]
- :id transform-id))
- db-id (:target_db_id transform)
- workspaces (t2/select [:model/Workspace :id :name :base_status :db_status]
- :database_id db-id
- :base_status [:not= :archived]
- {:order-by [[:name :asc]]})
- checkouts (t2/select [:model/WorkspaceTransform :workspace_id :ref_id :name]
- :global_id transform-id)
- ws-id->checkouts (into {} (map (juxt :workspace_id identity) checkouts))
- id->workspace (into {} (map (juxt :id identity) workspaces))]
- {:checkout_disabled (ws.api.common/checkout-disabled-reason transform)
- :workspaces (for [{:keys [id name] :as ws} workspaces
- :let [checkout (get ws-id->checkouts id)]]
- {:id id
- :name name
- :status (ws.model/computed-status ws)
- :existing (when checkout
- {:ref_id (:ref_id checkout)
- :name (:name checkout)})})
- :transforms (for [{:keys [ref_id name workspace_id]} checkouts
- :let [ws (get id->workspace workspace_id)]
- :when ws]
- {:id ref_id
- :name name
- :workspace {:id (:id ws) :name (:name ws)}})}))
-
-;;; ---------------------------------------- Merge ----------------------------------------
-
-(api.macros/defendpoint :post "/:ws-id/merge"
- :- [:or
- [:map
- [:merged
- [:map
- [:transforms [:sequential
- [:map
- [:op [:enum :create :delete :update :noop]]
- [:global_id {:optional true} [:maybe ::ws.t/appdb-id]]
- [:ref_id ::ws.t/ref-id]]]]]]
- [:errors
- [:sequential
- [:map
- [:op [:enum :create :delete :update :noop]]
- [:global_id {:optional true} [:maybe ::ws.t/appdb-id]]
- [:ref_id ::ws.t/ref-id]]]]
- [:workspace [:map [:id ::ws.t/appdb-id] [:name :string]]]]
- ;; error message from check-404 or check-400
- :string]
- "This will:
- 1. Update original transforms with workspace versions
- 2. Archive the workspace and clean up isolated resources
- Returns a report of merged entities, or error in errors key.
-
- Request body may include:
- - commit-message: A description of what changes are being merged (optional, will be required in future)"
- [{:keys [ws-id] :as _query-params} :- [:map [:ws-id ::ws.t/appdb-id]]
- _query-params
- {:keys [commit-message]
- :or {commit-message "Placeholder for merge commit message. Should be required on FE"}} :- [:map
- [:commit-message {:optional true} [:string {:min 1}]]]]
- (let [ws (u/prog1 (t2/select-one :model/Workspace :id ws-id)
- (api/check-404 <>)
- (api/check-400 (not= :archived (:base_status <>)) "Cannot merge an archived workspace"))
- {:keys [merged
- errors]} (-> (ws.merge/merge-workspace! ws api/*current-user-id* commit-message)
- (update :errors
- (partial mapv #(-> %
- (update :error (fn [e] (.getMessage ^Throwable e)))
- (set/rename-keys {:error :message})))))]
- (u/prog1
- {:merged merged
- :errors errors
- :workspace {:id ws-id, :name (:name ws)}}
- (when-not (seq errors)
- (ws.model/archive! ws)))))
-
-(api.macros/defendpoint :post "/:ws-id/transform/:tx-id/merge"
- :- [:map
- [:op [:enum :create :delete :update :noop]]
- [:global_id [:maybe ::ws.t/appdb-id]]
- [:ref_id ::ws.t/ref-id]
- [:message {:optional true} :string]]
- "Merge single transform from workspace back to the core. If workspace transform is archived
- the corresponding core transform is deleted.
-
- Request body may include:
- - commit-message: A description of what changes are being merged (optional, will be required in future)"
- [{:keys [ws-id tx-id] :as _query-params} :- [:map
- [:ws-id ::ws.t/appdb-id]
- [:tx-id ::ws.t/ref-id]]
- _query-params
- {:keys [commit-message]
- :or {commit-message "Placeholder for merge commit message. Should be required on FE"}} :- [:map
- [:commit-message {:optional true} [:string {:min 1}]]]]
- (let [ws (api/check-404 (t2/select-one [:model/Workspace :id :name] :id ws-id))
- ws-transform (api/check-404 (t2/select-one :model/WorkspaceTransform :workspace_id ws-id :ref_id tx-id))
- ws-merge-id (t2/insert-returning-pk!
- :model/WorkspaceMerge
- {:workspace_id (:id ws)
- :workspace_name (:name ws)
- :commit_message commit-message
- :creator_id api/*current-user-id*})
- {:keys [error] :as result} (ws.merge/merge-transform! {:ws-transform ws-transform
- :workspace ws
- :workspace-merge-id ws-merge-id
- :merging-user-id api/*current-user-id*
- :commit-message commit-message})]
- (if error
- (throw (ex-info "Failed to merge transform."
- (-> result
- (dissoc :error)
- (assoc :status-code 500))
- error))
- result)))
-
-;;; ---------------------------------------- Test Resources ----------------------------------------
-
-(defn- shorthand-ref?
- "Check if string matches shorthand pattern like x1, t1, x23, etc."
- [s]
- (and (string? s) (boolean (re-matches #"[xt]\d+" s))))
-
-(defn- parse-magic-references
- "Recursively walk data structure converting shorthand refs to keywords."
- [x]
- (walk/postwalk
- (fn [v]
- (if (shorthand-ref? v)
- (keyword v)
- v))
- x))
-
-(when (or config/is-dev? config/is-test?)
- (mr/def ::dependency-graph
- "Map of shorthand symbols to lists of dependencies. The latter are all strings, and refs need to be detected."
- [:map-of :keyword [:sequential :string]])
-
- (mr/def ::test-resources-request
- "Request body for creating test resources."
- [:map
- [:database_id {:optional true} ::ws.t/appdb-id]
- [:global {:optional true} ::dependency-graph]
- [:workspace {:optional true} [:map
- [:name {:optional true} :string]
- [:checkouts {:optional true} [:sequential :keyword]]
- [:definitions {:optional true} ::dependency-graph]]]])
-
- (mr/def ::test-resources-response
- "Response from creating test resources."
- [:map
- [:workspace-id [:maybe :int]]
- [:global-map [:map-of [:or :keyword :string] :int]]
- [:workspace-map [:map-of :keyword :string]]])
-
- (api.macros/defendpoint :post "/test-resources" :- ::test-resources-response
- "Create test resources for workspace e2e tests. Only available in dev/test mode.
-
- Optionally accepts a database_id in the body; if not provided it will try to use the sample database."
- [_route-params
- _query-params
- {db-id :database_id :as body} :- ::test-resources-request]
- (if-let [create-fn (requiring-resolve 'metabase-enterprise.workspaces.test-util/create-resources!)]
- (create-fn (-> body
- (dissoc :database_id)
- (cond-> db-id (assoc :database-id db-id))
- parse-magic-references))
- (throw (ex-info "Workspace test utilities not available" {:status-code 501})))))
-
-(def ^{:arglists '([request respond raise])} routes
- "`/api/ee/workspace/` routes."
- (api.macros/ns-handler *ns* api/+check-superuser +auth))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/api/common.clj b/enterprise/backend/src/metabase_enterprise/workspaces/api/common.clj
deleted file mode 100644
index 8abdcc6a2aa..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/api/common.clj
+++ /dev/null
@@ -1,713 +0,0 @@
-(ns metabase-enterprise.workspaces.api.common
- "Shared schemas, validations, and handler logic for workspace API routes.
- Used by `workspaces.api` only currently, but may be shared with agent APIs in future."
- (:require
- [clojure.string :as str]
- [medley.core :as m]
- [metabase-enterprise.workspaces.common :as ws.common]
- [metabase-enterprise.workspaces.impl :as ws.impl]
- [metabase-enterprise.workspaces.models.workspace :as ws.model]
- [metabase-enterprise.workspaces.models.workspace-input-external]
- [metabase-enterprise.workspaces.models.workspace-log]
- [metabase-enterprise.workspaces.models.workspace-output-external]
- [metabase-enterprise.workspaces.types :as ws.t]
- [metabase-enterprise.workspaces.validation :as ws.validation]
- [metabase.api.common :as api]
- [metabase.database-routing.core :as database-routing]
- ^{:clj-kondo/ignore [:metabase/modules]}
- [metabase.driver.sql.normalize :as sql.normalize]
- [metabase.driver.util :as driver.u]
- [metabase.lib.core :as lib]
- [metabase.queries.schema :as queries.schema]
- [metabase.transforms-base.util :as transforms-base.u]
- [metabase.transforms.core :as transforms]
- [metabase.transforms.feature-gating :as transforms.gating]
- [metabase.transforms.util :as transforms.u]
- [metabase.util :as u]
- [metabase.util.i18n :refer [deferred-tru]]
- [metabase.util.malli.registry :as mr]
- [metabase.warehouse-schema.models.table :as table]
- [toucan2.core :as t2]))
-
-(set! *warn-on-reflection* true)
-
-;;; --------------------------------------------------- Schemas ------------------------------------------------------
-
-(def computed-statuses
- "All possible values returned by computed-status (computed from base_status, etc.)"
- #{:uninitialized :pending :ready :broken :archived})
-
-(def workspace-transform-alias
- "Alias map for workspace transform fields (e.g. :target_stale -> :definition_changed)."
- {:target_stale :definition_changed})
-
-(mr/def ::run-trigger
- [:enum "none" "global-schedule"])
-
-(def TransformSource
- "Schema for a transform source. Shared across APIs — this is a data model concern, not an API contract."
- [:multi {:dispatch transforms-base.u/keyword-type-dispatch}
- [:query
- [:map
- [:type [:= "query"]]
- [:query ::queries.schema/query]]]
- [:python
- [:map {:closed true}
- [:source-database {:optional true} :int]
- [:source-tables [:sequential ::transforms-base.u/source-table-entry]]
- [:type [:= "python"]]
- [:body :string]]]])
-
-(def ^:private WorkspaceTransform
- "Internal schema used by handler functions for column selection. Each API namespace maintains
- its own copy of this schema for response validation — keep them in sync."
- [:map
- [:ref_id ::ws.t/ref-id]
- [:global_id [:maybe ::ws.t/appdb-id]]
- [:name :string]
- [:description [:maybe :string]]
- [:source :map]
- [:target :map]
- [:target_stale [:maybe :boolean]]
- [:workspace_id ::ws.t/appdb-id]
- [:creator_id [:maybe ::ws.t/appdb-id]]
- [:archived_at :any]
- [:created_at :any]
- [:updated_at :any]
- [:last_run_at :any]
- [:last_run_status [:maybe :string]]
- [:last_run_message [:maybe :string]]])
-
-;;; ------------------------------------------------- Utilities ------------------------------------------------------
-
-(defn- flag-enabled?
- "Coerce a flag parameter (true, false, or 1) to boolean."
- [v]
- (boolean (#{1 true} v)))
-
-(defn ws->response
- "Transform a workspace record into an API response, computing the backwards-compatible status."
- [ws]
- (-> ws
- (select-keys [:id :name :collection_id :database_id :created_at :updated_at])
- (assoc :status (ws.model/computed-status ws))))
-
-(defn check-transforms-enabled!
- "Validates that the database supports transforms: exists, is not sample/audit, supports :transforms/table, and no DB routing."
- [db-id]
- (let [database (api/check-400 (t2/select-one :model/Database db-id)
- (deferred-tru "The target database cannot be found."))]
- (api/check (transforms.gating/any-transforms-enabled?)
- [402 (deferred-tru "Premium features required for transforms are not enabled.")])
- (api/check-400 (not (:is_sample database))
- (deferred-tru "Cannot run transforms on the sample database."))
- (api/check-400 (not (:is_audit database))
- (deferred-tru "Cannot run transforms on audit databases."))
- (api/check-400 (driver.u/supports? (:engine database) :transforms/table database)
- (deferred-tru "The database does not support the requested transform target type."))
- (api/check-400 (not (database-routing/db-routing-enabled? database))
- (deferred-tru "Transforms are not supported on databases with DB routing enabled."))))
-
-(defn checkout-disabled-reason
- "Returns reason why a transform cannot be checked out, or nil if checkout is allowed."
- [{:keys [source_type source]}]
- (case source_type
- :mbql "mbql"
- :native (when (seq (lib/template-tags-referenced-cards (:query source)))
- "card-reference")
- :python nil
- "unknown-type"))
-
-(def ^:private db+schema+table (juxt :database :schema :name))
-
-(defn internal-target-conflict?
- "Check whether the given table is the target of another transform within the workspace. Ignores global transforms.
- NOTE: This intentionally includes archived transforms in the conflict check. Excluding them would allow a new
- transform to target the same table, creating a catch-22 when unarchiving the original (it can't be edited until
- after unarchiving, but unarchiving would create a conflict). Revisit if product decides on a UX for this."
- [ws-id target & [tx-id]]
- (contains?
- (t2/select-fn-set (comp db+schema+table :target)
- [:model/WorkspaceTransform :target]
- :ref_id [:not= tx-id]
- :workspace_id ws-id)
- (db+schema+table target)))
-
-(defn check-inputs-granted!
- "Throws 400 if any input tables required by the transform have not been granted access."
- [ws-id tx-id]
- (let [ungranted (ws.impl/ungranted-inputs-for-transform ws-id tx-id)]
- (when (seq ungranted)
- (let [tables (mapv #(select-keys % [:db_id :schema :table]) ungranted)]
- (throw (ex-info (str "Transform cannot run: the following input tables have not been granted access: "
- (pr-str tables))
- {:status-code 400
- :ungranted-tables tables}))))))
-
-;;; ---------------------------------------- Schema-driven select-keys ----------------------------------------
-
-(defn- malli-map-keys [schema]
- (into [] (map first) (rest schema)))
-
-(defn select-malli-keys
- "Like select-keys, but with the arguments reversed, and taking the malli schema for the output map.
- Nothing smart - for example, it doesn't understand optional versus maybe."
- ([schema m]
- (select-keys m (malli-map-keys schema)))
- ([schema alias-map m]
- (merge (select-malli-keys schema m)
- (u/for-map [[to from] alias-map] [to (from m)]))))
-
-(defn select-model-malli-keys
- "Build the model-fields vector for a t2/select from a malli schema for the output row(s)"
- ([model schema]
- (into [model] (malli-map-keys schema)))
- ([model schema alias-map]
- (into [model]
- (map (fn [to] (if-let [from (to alias-map)] [from to] to)))
- (malli-map-keys schema))))
-
-;;; ---------------------------------------- Transform CRUD helpers ----------------------------------------
-
-(defn attach-isolated-target
- "Attaches the isolated (workspace-scoped) target table info to a workspace transform."
- [{:keys [workspace_id ref_id] :as ws-transform}]
- (let [{:keys [db_id isolated_schema isolated_table]}
- (t2/select-one :model/WorkspaceOutput :workspace_id workspace_id :ref_id ref_id)]
- (assoc ws-transform :target_isolated {:type "table"
- :database db_id
- :schema isolated_schema
- :name isolated_table})))
-
-;; Global transforms precalculate these in a toucan hook - maybe we should do that too? Let's review later.
-(defn map-source-type
- "Derives :source_type from the transform's :source and removes :source from the map."
- [ws-tx]
- (-> ws-tx
- (assoc :source_type (transforms/transform-source-type (:source ws-tx)))
- (dissoc :source)))
-
-(defn fetch-ws-transform
- "Fetches a single workspace transform by workspace-id and ref-id, with isolated target attached. 404s if not found."
- [ws-id tx-id]
- (-> (select-model-malli-keys :model/WorkspaceTransform WorkspaceTransform workspace-transform-alias)
- (t2/select-one :workspace_id ws-id :ref_id tx-id)
- api/check-404
- attach-isolated-target))
-
-(defn create-workspace-transform!
- "Shared logic for creating a new workspace transform.
- Validates the transform, checks constraints, and inserts it into the changeset.
- Returns the created transform with isolated target info attached.
-
- Options:
- - `:ref-id` - Optional custom ref_id for the transform (defaults to auto-generated)"
- [ws-id body & {:keys [ref-id]}]
- (doseq [field [:name :source :target]]
- (api/check-400 (get body field) (str (name field) " is required when creating a new transform")))
- ;; Check premium feature requirements
- (api/check (transforms.u/check-feature-enabled body)
- [402 (deferred-tru "Premium features required for this transform type are not enabled.")])
- (t2/with-transaction [_tx]
- (let [workspace (u/prog1 (api/check-404 (t2/select-one :model/Workspace :id ws-id))
- (api/check-400 (not= :archived (:base_status <>))
- "Cannot create transforms in an archived workspace"))
- global-id (:global_id body (:id body))
- ;; Verify transform source is allowed in workspaces (not MBQL, no card references, etc.)
- _ (let [source-type (transforms/transform-source-type (:source body))
- reason (checkout-disabled-reason {:source_type source-type :source (:source body)})]
- (api/check-400 (nil? reason)
- (case reason
- "mbql"
- (deferred-tru "MBQL transforms cannot be added to workspaces.")
- "card-reference"
- (deferred-tru "Transforms referencing questions cannot be added to workspaces.")
- (deferred-tru "This transform cannot be added to a workspace: {0}." reason))))
- ;; For uninitialized workspaces, preserve the target database from the request body
- ;; For initialized workspaces, ensure the target database matches the workspace database
- body (-> body (dissoc :global_id)
- (cond-> (not= :uninitialized (:db_status workspace))
- (update :target assoc :database (:database_id workspace))))
- ;; Check for internal target conflict AFTER adding database to target
- _ (api/check-400 (not (internal-target-conflict? ws-id (:target body)))
- (deferred-tru "Another transform in this workspace already targets that table"))
- ;; Eagerly create global target table row so it's immediately visible
- {:keys [database schema name]} (:target body)
- _ (when (and database name)
- (table/upsert-transform-target-table! database schema name))
- transform (ws.common/add-to-changeset! api/*current-user-id* workspace :transform global-id body
- :ref-id ref-id)]
- (-> (select-malli-keys WorkspaceTransform workspace-transform-alias transform)
- attach-isolated-target))))
-
-;;; ---------------------------------------- Pending inputs ----------------------------------------
-
-(defn pending-inputs
- "Pending (ungranted) inputs in a workspace, excluding tables shadowed by workspace outputs.
- Only includes inputs that are still referenced by at least one current transform version.
- Unlike query-ungranted-external-inputs, this includes tables that may not exist yet in metabase_table."
- [workspace-id]
- (t2/select [:model/WorkspaceInput :db_id :schema :table]
- {:where [:and
- [:= :workspace_input.workspace_id workspace-id]
- [:= :workspace_input.access_granted false]
- ;; Only include inputs referenced by a current transform version.
- [:exists {:select [1]
- :from [[:workspace_input_transform :wit]]
- :where [:and
- [:= :wit.workspace_input_id :workspace_input.id]
- [:= :wit.transform_version
- {:select [[:%max.transform_version]]
- :from [[:workspace_input_transform :wit2]]
- :where [:and
- [:= :wit2.workspace_id :wit.workspace_id]
- [:= :wit2.ref_id :wit.ref_id]]}]]}]
- ;; Ignore tables that will be shadowed by outputs of other transforms.
- [:not [:exists {:select [1]
- :from [[:workspace_output :wo]]
- :where [:and
- [:= :wo.workspace_id :workspace_input.workspace_id]
- [:= :wo.db_id :workspace_input.db_id]
- [:or
- [:and [:= :wo.global_schema nil] [:= :workspace_input.schema nil]]
- [:= :wo.global_schema :workspace_input.schema]]
- [:= :wo.global_table :workspace_input.table]]}]]
- [:not [:exists {:select [1]
- :from [[:workspace_output_external :woe]]
- :where [:and
- [:= :woe.workspace_id :workspace_input.workspace_id]
- [:= :woe.db_id :workspace_input.db_id]
- [:or
- [:and [:= :woe.global_schema nil] [:= :workspace_input.schema nil]]
- [:= :woe.global_schema :workspace_input.schema]]
- [:= :woe.global_table :workspace_input.table]]}]]]
- :order-by [:db_id :schema :table]}))
-
-;;; ---------------------------------------- Graph helpers ----------------------------------------
-
-(defn node-type
- "Returns the graph node type, mapping :table to :input-table."
- [node]
- (let [nt (:node-type node)]
- (case nt
- :table :input-table
- nt)))
-
-(defn node-id
- "Returns a unique string identifier for a graph node."
- [{:keys [node-type id]}]
- (case node-type
- :workspace-transform id
- :external-transform id
- :table (str (:db id) "-" (:schema id) "-" (:table id))))
-
-(defn table-ids-by-target
- "Batch lookup table IDs for transform targets.
- Returns {[db_id normalized_schema normalized_name] -> table-record}.
- Schema and table names are normalized per database driver to match how tables are stored in metabase_table."
- [db-id driver transforms]
- (when (seq transforms)
- (let [table-keys (into #{}
- (keep (fn [{:keys [target]}]
- (when (:database target)
- [db-id
- (sql.normalize/normalize-name driver (:schema target))
- (sql.normalize/normalize-name driver (:name target))])))
- transforms)
- with-schema (filter second table-keys)
- without-schema (keep (fn [[db-id schema table-name]]
- (when-not schema [db-id table-name]))
- table-keys)]
- (when (or (seq with-schema) (seq without-schema))
- (let [tables (t2/select [:model/Table :id :db_id :schema :name]
- {:where [:or
- (when (seq with-schema)
- [:in [:composite :db_id :schema :name] with-schema])
- (when (seq without-schema)
- [:and
- [:= :schema nil]
- [:in [:composite :db_id :name] without-schema]])]})]
- (m/index-by (juxt :db_id :schema :name) tables))))))
-
-(defn target->spec
- "Resolves a transform's target to a spec map with :db, :schema, :table, and :table_id."
- [driver table-id-map {:keys [target] :as tx}]
- (let [table-key [(:database target)
- (sql.normalize/normalize-name driver (:schema target))
- (sql.normalize/normalize-name driver (:name target))]
- table-id (:id (get table-id-map table-key))]
- (assoc tx :target {:db (:database target)
- :schema (:schema target)
- :table (:name target)
- :table_id table-id})))
-
-(defn fetch-transforms-for-graph
- "Batch fetch all transforms needed for the graph. Returns {:external {id -> tx}, :workspace {ref_id -> tx}}."
- [ws-id entities]
- (let [external-ids (into [] (keep #(when (= :external-transform (:node-type %)) (:id %))) entities)
- ref-ids (into [] (keep #(when (= :workspace-transform (:node-type %)) (:id %))) entities)
- external-txs (when (seq external-ids)
- (m/index-by :id (t2/select [:model/Transform :id :name :target] :id [:in external-ids])))
- workspace-txs (when (seq ref-ids)
- (m/index-by :ref_id (t2/select [:model/WorkspaceTransform :ref_id :name :target]
- :workspace_id ws-id :ref_id [:in ref-ids])))]
- {:external external-txs
- :workspace workspace-txs}))
-
-(defn node-data
- "Returns the data payload for a graph node, resolving targets to specs."
- [driver transforms-map table-id-map {:keys [node-type id]}]
- (case node-type
- :table id
- :external-transform (some->> (get-in transforms-map [:external id])
- (target->spec driver table-id-map))
- :workspace-transform (some->> (get-in transforms-map [:workspace id])
- (target->spec driver table-id-map))))
-
-;;; ---------------------------------------- Shared endpoint handlers ----------------------------------------
-;; These functions contain the handler logic for the workspace API (`workspaces/api.clj`).
-;; Each `defendpoint` becomes a thin wrapper that calls the corresponding function here.
-
-(def ^:private log-limit "Maximum number of recent workspace log items to show" 20)
-
-(defn get-pending-inputs
- "Handler body for GET /:ws-id/input/pending."
- [ws-id]
- (api/check-404 (t2/select-one :model/Workspace :id ws-id))
- {:inputs (pending-inputs ws-id)})
-
-(defn get-workspace
- "Handler body for GET /:ws-id."
- [ws-id]
- (-> (t2/select-one :model/Workspace :id ws-id) api/check-404 ws->response))
-
-(defn get-workspace-tables
- "Handler body for GET /:ws-id/table."
- [ws-id]
- (let [workspace (api/check-404 (t2/select-one :model/Workspace :id ws-id))
- ;; Trigger creation of the Workspace*External entries
- _ (ws.impl/get-or-calculate-graph! workspace)
- order-by {:order-by [:db_id :global_schema :global_table]}
- outputs (t2/select [:model/WorkspaceOutput
- :db_id :global_schema :global_table :global_table_id
- :isolated_schema :isolated_table :isolated_table_id :ref_id]
- :workspace_id ws-id order-by)
- external-outputs (t2/select [:model/WorkspaceOutputExternal
- :db_id :global_schema :global_table :global_table_id
- :isolated_schema :isolated_table :isolated_table_id :transform_id]
- :workspace_id ws-id order-by)
- all-outputs (concat outputs external-outputs)
- raw-inputs (distinct
- (t2/select [:model/WorkspaceInput :db_id :schema :table :table_id]
- :workspace_id ws-id {:order-by [:db_id :schema :table]}))
- external-inputs (distinct
- (t2/select [:model/WorkspaceInputExternal :db_id :schema :table :table_id]
- :workspace_id ws-id {:order-by [:db_id :schema :table]}))
- all-raw-inputs (concat raw-inputs external-inputs)
- ;; Some of our inputs may be shadowed by the outputs of other transforms. We only want external inputs.
- shadowed? (into #{} (map (juxt :db_id :global_schema :global_table)) all-outputs)
- inputs (remove (comp shadowed? (juxt :db_id :schema :table)) all-raw-inputs)
- ;; Build a map of [d s t] => id for every table that has been synced since the output row was written.
- fallback-map (merge
- (ws.impl/table-ids-fallbacks :global_schema :global_table :global_table_id all-outputs)
- (ws.impl/table-ids-fallbacks :isolated_schema :isolated_table :isolated_table_id all-outputs))
- table-ids (into (into #{} (keep :isolated_table_id) all-outputs) (vals fallback-map))
- active-table-ids (t2/select-fn-set :id [:model/Table :id] :id [:in table-ids] :active true)]
- {:inputs (sort-by (juxt :db_id :schema :table) inputs)
- :outputs (sort-by
- (juxt :db_id (comp (juxt :schema :table) :global))
- (concat
- ;; Workspace transform outputs
- (for [{:keys [ref_id db_id global_schema global_table global_table_id
- isolated_schema isolated_table isolated_table_id]} outputs
- :let [isolated_table_id (or isolated_table_id
- (get fallback-map [db_id isolated_schema isolated_table]))]]
- {:db_id db_id
- :global {:transform_id nil
- :schema global_schema
- :table global_table
- :table_id (or global_table_id (get fallback-map [db_id global_schema global_table]))}
- :isolated {:transform_id ref_id
- :schema isolated_schema
- :table isolated_table
- :table_id isolated_table_id
- :active (contains? active-table-ids isolated_table_id)}})
-
- ;; External transform outputs
- (for [{:keys [transform_id db_id global_schema global_table global_table_id
- isolated_schema isolated_table isolated_table_id]} external-outputs
- :let [isolated_table_id (or isolated_table_id
- (get fallback-map [db_id isolated_schema isolated_table]))]]
- {:db_id db_id
- :global {:transform_id transform_id
- :schema global_schema
- :table global_table
- :table_id (or global_table_id (get fallback-map [db_id global_schema global_table]))}
- :isolated {:transform_id transform_id
- :schema isolated_schema
- :table isolated_table
- :table_id isolated_table_id
- :active (contains? active-table-ids isolated_table_id)}})))}))
-
-(defn get-workspace-log
- "Handler body for GET /:ws-id/log."
- [ws-id]
- (let [workspace (api/check-404 (t2/select-one :model/Workspace :id ws-id))
- logs (t2/select [:model/WorkspaceLog
- :id :task :started_at :completed_at :status :message
- :updated_at]
- :workspace_id ws-id
- {:order-by [[:started_at :desc]]
- :limit log-limit})]
- {:workspace_id ws-id
- :status (ws.model/computed-status workspace)
- :logs logs
- :updated_at (->> (map :updated_at logs) sort reverse first)
- :last_completed_at (->> (seq (keep :completed_at logs)) sort reverse first)}))
-
-(defn get-workspace-graph
- "Handler body for GET /:ws-id/graph."
- [ws-id]
- (let [workspace (api/check-404 (t2/select-one :model/Workspace :id ws-id))
- db-id (:database_id workspace)
- driver (t2/select-one-fn :engine [:model/Database :engine] :id db-id)
- {:keys [inputs entities dependencies]} (ws.impl/get-or-calculate-graph! workspace)
- ;; Batch fetch all transforms and build table-id lookup map
- transforms-map (fetch-transforms-for-graph ws-id entities)
- all-transforms (concat (vals (:external transforms-map))
- (vals (:workspace transforms-map)))
- table-id-map (table-ids-by-target db-id driver all-transforms)
- ;; We may want to cache this inverted graph in the database JSON to avoid recalculating it each time.
- inverted (reduce
- (fn [inv [c parents]]
- (reduce (fn [inv p] (update inv p (fnil conj #{}) c)) inv parents))
- {}
- dependencies)
- dep-count #(frequencies (map node-type (get inverted %)))]
-
- {:nodes (concat (for [i inputs]
- {:type :input-table
- ;; Use an id that's independent of whether the table exists yet.
- :id (node-id {:id i, :node-type :table})
- :data i
- :dependents_count (dep-count {:node-type :table, :id i})})
- (for [e entities]
- {:type (node-type e)
- :id (:id e)
- :data (node-data driver transforms-map table-id-map e)
- :dependents_count (dep-count e)}))
- :edges (for [[child parents] dependencies, parent parents]
- {:to_entity_type (name (node-type parent))
- :to_entity_id (node-id parent)
- :from_entity_type (name (node-type child))
- :from_entity_id (node-id child)})}))
-
-(defn get-workspace-problems
- "Handler body for GET /:ws-id/problem."
- [ws-id]
- (let [workspace (api/check-404 (t2/select-one :model/Workspace :id ws-id))
- graph (ws.impl/get-or-calculate-graph! workspace)]
- (ws.validation/find-downstream-problems ws-id graph)))
-
-(defn get-external-transforms
- "Handler body for GET /:ws-id/external/transform."
- [ws-id database-id]
- (let [db-id (or database-id
- (:database_id (api/check-404 (t2/select-one [:model/Workspace :database_id] ws-id))))
- transforms (t2/select [:model/Transform :id :name :source_type :source]
- {:left-join [[:workspace_transform :wt]
- [:and
- [:= :transform.id :wt.global_id]
- [:= :wt.workspace_id ws-id]]]
- ;; NULL workspace_id means transform is not checked out into this workspace
- :where [:and
- [:= nil :wt.workspace_id]
- [:= :target_db_id db-id]]
- :order-by [[:id :asc]]})]
- {:transforms
- (into []
- (map #(-> %
- (dissoc :source)
- (assoc :checkout_disabled (checkout-disabled-reason %))))
- transforms)}))
-
-(defn list-transforms
- "Handler body for GET /:ws-id/transform."
- [ws-id]
- (api/check-404 (t2/select-one :model/Workspace :id ws-id))
- {:transforms (->> (t2/select [:model/WorkspaceTransform :ref_id :global_id :name :source :creator_id]
- :workspace_id ws-id {:order-by [:created_at]})
- (map map-source-type))})
-
-(defn archive-workspace!
- "Handler body for POST /:ws-id/archive."
- [ws-id]
- (let [ws (api/check-404 (t2/select-one :model/Workspace :id ws-id))]
- (api/check-400 (not= :archived (:base_status ws)) "You cannot archive an archived workspace")
- (ws.model/archive! ws)
- (-> (t2/select-one :model/Workspace :id ws-id) ws->response)))
-
-(defn archive-transform!
- "Handler body for POST /:ws-id/transform/:tx-id/archive."
- [ws-id tx-id]
- (api/check-404 (pos? (t2/update! :model/WorkspaceTransform
- {:workspace_id ws-id, :ref_id tx-id}
- {:archived_at [:now]})))
- ;; Increment graph version since transform is leaving the graph
- (ws.impl/increment-graph-version! ws-id)
- nil)
-
-(defn unarchive-transform!
- "Handler body for POST /:ws-id/transform/:tx-id/unarchive."
- [ws-id tx-id]
- (api/check-404 (pos? (t2/update! :model/WorkspaceTransform
- {:workspace_id ws-id, :ref_id tx-id}
- {:archived_at nil})))
- ;; Increment both versions - transform re-enters graph and needs re-analysis
- (ws.impl/increment-analysis-version! ws-id tx-id)
- ;; We could merge this with the initial WorkspaceTransform update to save a statement, but it adds complexity.
- (ws.impl/increment-graph-version! ws-id)
- nil)
-
-(defn validate-target
- "Handler body for POST /:ws-id/transform/validate/target."
- [ws-id transform-id db_id target]
- (let [workspace (api/check-404 (t2/select-one [:model/Workspace :database_id :db_status] ws-id))
- target (update target :database #(or % db_id))
- target-db-id (:database target)
- ;; For uninitialized workspaces we skip over checks for their db id
- ws-db-id (when (not= :uninitialized (:db_status workspace)) (:database_id workspace))]
- (cond
- (not= "table" (:type target))
- {:status 403 :body (deferred-tru "Unsupported target type")}
-
- (and target-db-id ws-db-id (not= target-db-id ws-db-id))
- {:status 403 :body (deferred-tru "Must target the workspace database")}
-
- (not (or target-db-id ws-db-id))
- {:status 403 :body (deferred-tru "Must target a database")}
-
- (when-let [schema (:schema target)] (driver.u/workspace-isolated-schema? schema))
- {:status 403 :body (deferred-tru "Must not target an isolated workspace schema")}
-
- ;; Within a workspace, we defer blocking on conflicts outside the workspace
- #_{:status 403 :body (deferred-tru "A table with that name already exists.")}
-
- ;; Consider deferring this validation until merge also.
- (internal-target-conflict? ws-id target transform-id)
- {:status 403 :body (deferred-tru "Another transform in this workspace already targets that table")}
-
- :else
- {:status 200 :body "OK"})))
-
-(defn run-workspace!
- "Handler body for POST /:ws-id/run."
- [ws-id stale_only]
- (let [workspace (t2/select-one :model/Workspace :id ws-id)
- _ (api/check-404 workspace)
- _ (api/check-400 (not= :archived (:base_status workspace)) "Cannot execute archived workspace")
- _ (check-transforms-enabled! (:database_id workspace))
- graph (ws.impl/get-or-calculate-graph! workspace)]
- (ws.impl/execute-workspace! workspace graph {:stale-only? (flag-enabled? stale_only)})))
-
-(defn run-transform!
- "Handler body for POST /:ws-id/transform/:tx-id/run."
- [ws-id tx-id run_stale_ancestors]
- (let [workspace (api/check-404 (t2/select-one :model/Workspace ws-id))
- transform (api/check-404 (t2/select-one :model/WorkspaceTransform :workspace_id ws-id :ref_id tx-id))
- _ (api/check-400 (not= :archived (:base_status workspace)) "Cannot execute archived workspace")
- _ (check-transforms-enabled! (:database_id workspace))
- _ (check-inputs-granted! ws-id tx-id)
- graph (ws.impl/get-or-calculate-graph! workspace)
- run-ancestors? (flag-enabled? run_stale_ancestors)
- ancestors-result (when run-ancestors?
- (ws.impl/run-stale-ancestors! workspace graph tx-id))
- failed-ancestors (:failed ancestors-result)
- transform-result (if (seq failed-ancestors)
- {:status :failed
- :message (str "Ancestor transform failed: "
- (str/join ", " failed-ancestors))
- :table (select-keys (:target transform) [:schema :name])}
- (ws.impl/run-transform! workspace graph transform))]
- (cond-> transform-result
- run-ancestors? (assoc :ancestors ancestors-result))))
-
-(defn dry-run-transform!
- "Handler body for POST /:ws-id/transform/:tx-id/dry-run."
- [ws-id tx-id run_stale_ancestors]
- (let [workspace (api/check-404 (t2/select-one :model/Workspace ws-id))
- transform (api/check-404 (t2/select-one :model/WorkspaceTransform :workspace_id ws-id :ref_id tx-id))
- _ (api/check-400 (not= :archived (:base_status workspace)) "Cannot execute archived workspace")
- _ (check-transforms-enabled! (:database_id workspace))
- _ (check-inputs-granted! ws-id tx-id)
- graph (ws.impl/get-or-calculate-graph! workspace)
- run-ancestors? (flag-enabled? run_stale_ancestors)
- ancestors-result (when run-ancestors?
- (ws.impl/run-stale-ancestors! workspace graph tx-id))
- failed-ancestors (:failed ancestors-result)
- dry-run-result (if (seq failed-ancestors)
- {:status :failed
- :message (str "Ancestor transform failed: "
- (str/join ", " failed-ancestors))}
- (ws.impl/dry-run-transform workspace graph transform))]
- (cond-> dry-run-result
- run-ancestors? (assoc :ancestors ancestors-result))))
-
-(defn execute-query!
- "Handler body for POST /:ws-id/query."
- [ws-id sql]
- (let [workspace (api/check-404 (t2/select-one :model/Workspace ws-id))
- _ (api/check-400 (not= :archived (:base_status workspace))
- "Cannot query archived workspace")
- _ (api/check-400 (not= :uninitialized (:db_status workspace))
- "Workspace is not initialized")
- _ (api/check-400 (some? (:database_details workspace))
- "Workspace is not ready for queries")
- _ (check-transforms-enabled! (:database_id workspace))
- graph (ws.impl/get-or-calculate-graph! workspace)]
- (ws.impl/execute-adhoc-query workspace graph sql)))
-
-(defn update-transform!
- "Handler body for PUT /:ws-id/transform/:tx-id."
- [ws-id tx-id body]
- ;; We use explicit check-then-branch rather than app-db/update-or-insert! because:
- ;; 1. WorkspaceTransform has a compound primary key which that helper doesn't support
- ;; 2. Update and insert have very different logic (update merges + increments versions,
- ;; insert requires full validation, workspace initialization, status transitions)
- (let [existing (t2/select-one :model/WorkspaceTransform :ref_id tx-id :workspace_id ws-id)]
- (if existing
- ;; UPDATE path
- (t2/with-transaction [_tx]
- (let [;; Merge only :database and :schema from existing target to preserve them when not explicitly provided.
- ;; Other fields are NOT merged, allowing them to be removed by omitting from the request.
- base (select-keys (:target existing) [:database :schema])
- merged-body (cond-> body
- (:target body) (update :target #(merge base %)))
- source-or-target-changed? (or (:source body) (:target body))]
- ;; If target is changing, check for conflicts with other transforms (excluding this one)
- (when (:target body)
- (api/check-400 (not (internal-target-conflict? ws-id (:target merged-body) tx-id))
- (deferred-tru "Another transform in this workspace already targets that table"))
- ;; Eagerly create global target table row so it's immediately visible
- (let [{:keys [database schema name]} (:target merged-body)]
- (when (and database name)
- (table/upsert-transform-target-table! database schema name))))
- (t2/update! :model/WorkspaceTransform {:workspace_id ws-id :ref_id tx-id} merged-body)
- ;; If source or target changed, increment versions for re-analysis
- (when source-or-target-changed?
- (ws.impl/increment-analysis-version! ws-id tx-id)
- ;; It's unfortunate that we are using an extra SQL statement for this, rather than doing it in the earlier
- ;; statement that set the [[body]]. Combining them would be tricky, as we still need the model transforms to
- ;; serialize the fields in the body, but the increment requires using an SQL expression.
- (ws.impl/increment-graph-version! ws-id)))
- (fetch-ws-transform ws-id tx-id))
- ;; INSERT path (upsert creates new transform)
- (create-workspace-transform! ws-id body :ref-id tx-id))))
-
-(defn delete-transform!
- "Handler body for DELETE /:ws-id/transform/:tx-id."
- [ws-id tx-id]
- (api/check-404 (pos? (t2/delete! :model/WorkspaceTransform :workspace_id ws-id :ref_id tx-id)))
- ;; Increment graph version since transform is potentially leaving the graph, or reverting to the global definition.
- (ws.impl/increment-graph-version! ws-id)
- nil)
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/common.clj b/enterprise/backend/src/metabase_enterprise/workspaces/common.clj
deleted file mode 100644
index f83ece95746..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/common.clj
+++ /dev/null
@@ -1,166 +0,0 @@
-(ns metabase-enterprise.workspaces.common
- (:require
- [clojure.string :as str]
- [metabase-enterprise.workspaces.isolation :as ws.isolation]
- [metabase-enterprise.workspaces.models.workspace-log :as ws.log]
- [metabase-enterprise.workspaces.util :as ws.u]
- [metabase.api.common :as api]
- [metabase.driver.util :as driver.u]
- [metabase.transforms-base.interface :as transforms-base.i]
- [metabase.util.log :as log]
- [metabase.util.quick-task :as quick-task]
- [toucan2.core :as t2]))
-
-(defn- extract-suffix-number
- "Extract the numeric suffix from a workspace name like 'Foo (3)', or nil if no valid suffix."
- [ws-name base-name]
- (when (= (str/replace ws-name #"\s*\(\d+\)$" "") base-name)
- (when-let [[_ n] (re-find #"\((\d+)\)$" ws-name)]
- (parse-long n))))
-
-(defn- generate-unique-workspace-name
- "Generate a unique workspace name by appending (N) if the name already exists.
-
- Strategy:
- 1. If the base name doesn't exist, use it as-is
- 2. If it exists, strip any existing (N) suffix and find the highest N among similar names
- 3. Return the base name with (N+1) appended
-
- Note: This function has a potential race condition between checking existence and insertion.
- Callers should handle unique constraint violations by retrying."
- [base-name]
- (when (str/blank? base-name)
- (throw (ex-info "Workspace name cannot be empty" {:status-code 400})))
- (if-not (t2/exists? :model/Workspace :name base-name)
- base-name
- (let [stripped-name (str/replace base-name #"\s*\(\d+\)$" "")
- existing (t2/select-fn-set :name :model/Workspace
- :name [:like (str stripped-name " (%)")])
- numbers (keep #(extract-suffix-number % stripped-name) existing)
- next-num (inc (apply max 0 numbers))]
- (str stripped-name " (" next-num ")"))))
-
-(defn- create-workspace-container!
- "Create the workspace and its related collection.
- Returns the workspace."
- [creator-id db-id workspace-name]
- (let [ws (t2/insert-returning-instance! :model/Workspace
- {:name workspace-name
- :creator_id creator-id
- :database_id db-id
- :base_status :empty
- :db_status :uninitialized})
- coll (t2/insert-returning-instance! :model/Collection
- {:name (format "Collection for Workspace %s" workspace-name)
- :namespace "workspace"
- :workspace_id (:id ws)})
- ws (assoc ws :collection_id (:id coll))]
- ;; Set the backlink from the workspace to the collection inside it.
- (t2/update! :model/Workspace (:id ws) {:collection_id (:id coll)})
- ws))
-
-(defn- unique-constraint-violation?
- "Check if an exception is due to a unique constraint violation."
- [e]
- (let [msg (str (ex-message e) (some-> (ex-cause e) ex-message))]
- (or (str/includes? msg "unique")
- (str/includes? msg "duplicate")
- (str/includes? msg "UNIQUE"))))
-
-(defn- run-workspace-setup!
- "Background job: runs isolation, grants. Updates db_status to :ready when done."
- [{ws-id :id :as workspace} database]
- (try
- (ws.log/track! ws-id :workspace-setup
- (let [isolation-details (ws.log/track! ws-id :database-isolation
- (ws.isolation/ensure-database-isolation! workspace database))]
- (t2/update! :model/Workspace ws-id (merge (select-keys isolation-details [:schema :database_details])
- {:db_status :ready}))))
- (catch Exception e
- (log/error e "Failed to setup workspace")
- (t2/update! :model/Workspace ws-id {:db_status :broken})
- (throw e))))
-
-(defn initialize-workspace!
- "Initialize an uninitialized workspace with the given database_id.
- Updates database_id (if different from provisional), sets schema, creates isolation resources async,
- and transitions db_status to :pending. Returns the updated workspace with schema set."
- [workspace database-id]
- (let [database (t2/select-one :model/Database database-id)
- schema (driver.u/workspace-isolation-namespace-name workspace)
- res (t2/update! :model/Workspace {:id (:id workspace)
- :db_status :uninitialized}
- {:database_id database-id
- :schema schema
- :db_status :pending})]
- (when (zero? res)
- (let [new-db-id (t2/select-one-fn :database_id :model/Workspace (:id workspace))]
- (when (not= database-id new-db-id)
- (throw (ex-info "Workspace has been initialized already with a different database"
- {:requested-db-id database-id
- :actual-db-id new-db-id})))))
- (let [ws (t2/select-one :model/Workspace (:id workspace))]
- ;; TODO (Chris 2026-02-02) -- Allow this to be fully async as part of BOT-746.
- (try
- @(quick-task/submit-task! #(run-workspace-setup! ws database))
- (catch Exception e
- (log/error e "Failed to initialize workspace")))
- ;; Querying again to get the database_details
- (t2/select-one :model/Workspace (:id workspace)))))
-
-(defn- create-uninitialized-workspace!
- "Create a workspace with a provisional database_id but no isolation resources.
- Retries on unique constraint violations for workspace name."
- [creator-id db-id ws-name max-retries]
- (loop [attempt 1]
- (let [unique-name (generate-unique-workspace-name ws-name)
- {:keys [retry
- workspace]} (try
- {:workspace (create-workspace-container! creator-id db-id unique-name)}
- (catch Exception e
- (if (and (< attempt max-retries) (unique-constraint-violation? e))
- {:retry true}
- (throw e))))]
- (if retry
- (recur (inc attempt))
- workspace))))
-
-(defn create-workspace!
- "Create workspace."
- [creator-id {ws-name-maybe :name
- db-id :database_id}]
- (let [ws-name (or ws-name-maybe (ws.u/generate-name))]
- (create-uninitialized-workspace! creator-id db-id ws-name 5)))
-
-(defn add-to-changeset!
- "Add the given transform to the workspace changeset.
- If workspace db_status is uninitialized, initializes it with the transform's target database.
- If workspace base_status is empty, transitions it to active.
-
- Options:
- - `:ref-id` - Optional custom ref_id (e.g., for upsert operations)."
- [creator-id workspace entity-type global-id body & {:keys [ref-id]}]
- (ws.u/assert-transform! entity-type)
- ;; Initialize workspace if uninitialized (outside transaction so async task can see committed data)
- (let [workspace (if (= :uninitialized (:db_status workspace))
- (let [target-db-id (transforms-base.i/target-db-id body)]
- (api/check-400 target-db-id "Transform must have a target database")
- (initialize-workspace! workspace target-db-id))
- workspace)]
- (t2/with-transaction [_]
- (let [workspace-id (:id workspace)
- workspace-db-id (:database_id workspace)
- body (assoc-in body [:target :database] workspace-db-id)
- transform (ws.u/insert-returning-ws-tx!
- (assoc (select-keys body [:name :description :source :target])
- :ref_id (or ref-id (ws.u/generate-ref-id))
- :creator_id creator-id
- :global_id global-id
- :workspace_id workspace-id))]
- (t2/update! :model/Workspace workspace-id
- ;; Increment graph_version since new transform = graph needs recalculation
- (cond-> {:graph_version [:+ :graph_version 1]}
- ;; Transition base_status from :empty to :active when first transform is added
- (= :empty (:base_status workspace))
- (assoc :base_status :active)))
- transform))))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/core.clj b/enterprise/backend/src/metabase_enterprise/workspaces/core.clj
deleted file mode 100644
index 3e3ddfb5b6f..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/core.clj
+++ /dev/null
@@ -1,11 +0,0 @@
-(ns metabase-enterprise.workspaces.core
- "API namespace for the `enterprise/workspaces` module."
- (:require
- [metabase-enterprise.workspaces.scope]
- [potemkin :as p]))
-
-(p/import-vars
- [metabase-enterprise.workspaces.scope
- agent-workspace-execute
- agent-workspace-read
- agent-workspace-write])
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/dag.clj b/enterprise/backend/src/metabase_enterprise/workspaces/dag.clj
deleted file mode 100644
index a4f3b7af690..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/dag.clj
+++ /dev/null
@@ -1,304 +0,0 @@
-(ns metabase-enterprise.workspaces.dag
- "Used to do graph computations with respect to dataflow within a workspace.
-
- This namespace should encapsulate all coupling to the [[metabase-enterprise.dependencies]] module, including through
- database artifacts.
-
- It is purely concerned with calculation, any side effects wanted as a result of the analysis should happen outside."
- (:require
- [metabase-enterprise.workspaces.util :as ws.u]
- [metabase.util :as u]
- [toucan2.core :as t2]
- [toucan2.realize :as t2.realize]))
-
-;; TODO (Chris 2025-12-15) -- Should we leverage data-authority table metadata to speed things up?
-
-(defn- table-id->coord [id]
- (t2/select-one [:model/Table :id :schema [:name :table] [:db_id :db]] id))
-
-(defn- target->coord [{:keys [database schema name] :as _target}]
- {:db database
- :schema schema
- :table name})
-
-(defn- global-parents
- "Dependencies analyzed by global hooks - may be incomplete. For example, excluding transforms that have not been run."
- [ws-id node-type id]
- ;; Note: from_entity_type is transformed to a keyword by the Dependency model
- (t2/select-fn-vec (fn [{id :to_entity_id entity-type :to_entity_type}]
- (case entity-type
- :card {:node-type :external-card, :id id}
- :table {:node-type :table, :id (table-id->coord id)}
- :transform {:node-type :external-transform, :id id}))
- [:model/Dependency :to_entity_type :to_entity_id]
- :from_entity_type node-type
- :from_entity_id id
- ;; Exclude transforms which are being overridden in the workspace.
- ;; Note: use string "transform" in SQL WHERE clause (db stores strings)
- {:where [:not [:and
- [:= "transform" :to_entity_type]
- [:exists {:select [1]
- :from [[:workspace_transform :wt]]
- :where [:and
- [:= :wt.workspace_id ws-id]
- [:= :wt.global_id :to_entity_id]]}]]]}))
-
-;; Workaround for change in how Dependencies table works (inlining of transform dependencies)
-(defn- global-tx-parents
- "Dependencies analyzed by global hooks - may be incomplete. For example, excluding transforms that have not been run."
- [id]
- ;; Note: from_entity_type is transformed to a keyword by the Dependency model
- (mapv
- (fn [{:keys [node-type id] :as node}]
- (if (= :external-transform node-type)
- {:node-type :table, :id (target->coord (t2/select-one-fn :target [:model/Transform :target] id))}
- node))
- (t2/select-fn-vec (fn [{id :to_entity_id entity-type :to_entity_type}]
- (case entity-type
- :card {:node-type :external-card, :id id}
- :table {:node-type :table, :id (table-id->coord id)}
- :transform {:node-type :external-transform, :id id}))
- [:model/Dependency :to_entity_type :to_entity_id]
- :from_entity_type "transform"
- :from_entity_id id)))
-
-(defn- ws-transform-parents [ws-id ref-id]
- ;; We assume there are no card dependencies yet
- ;; Get the latest version - which may have changed since we started this graph analysis (!!!)
- ;; Unfortunately, since each transform is versioned separately, it's not trivial to freeze to a snapshot.
- ;; NOTE: Perhaps this is a reason to snapshot these rows, or pre-query them all :thinking:
- ;;
- ;; After normalization (BOT-955), workspace_input no longer has ref_id/transform_version.
- ;; We JOIN through workspace_input_transform to find which inputs belong to this transform.
- (t2/select-fn-vec (fn [table-coord]
- {:node-type :table, :id (t2.realize/realize table-coord)})
- [:model/WorkspaceInput [:db_id :db] :schema :table [:table_id :id]]
- {:join [[:workspace_input_transform :wit]
- [:= :wit.workspace_input_id :workspace_input.id]]
- :where [:and
- [:= :wit.workspace_id ws-id]
- [:= :wit.ref_id ref-id]
- [:= :wit.transform_version
- {:select [[:%max.transform_version]]
- :from [:workspace_input_transform]
- :where [:and
- [:= :workspace_id ws-id]
- [:= :ref_id ref-id]]}]]}))
-
-(defn- table-producers [ws-id id-or-coord]
- ;; Work with either logical co-ords or an id
- (let [{:keys [db schema table id]} (if (map? id-or-coord) id-or-coord (table-id->coord id-or-coord))
- ;; Get the latest version - which may have changed since we started this graph analysis (!!!)
- ;; Unfortunately, since each transform is versioned separately, it's not trivial to freeze to a snapshot.
- ;; NOTE: Perhaps this is a reason to snapshot these rows, or pre-query them all :thinking:
- tx-ref-id (t2/select-one-fn :ref_id [:model/WorkspaceOutput :ref_id]
- {:where [:and
- [:= :workspace_id ws-id]
- [:or
- (when id
- [:= :global_table_id id])
- [:and
- [:= :db_id db]
- [:= :global_schema schema]
- [:= :global_table table]]]]
- :order-by [[:id :desc]]
- :limit 1})]
- (if tx-ref-id
- ;; If there is a workspace transform that targets this table, ignore any global transform that also targets it.
- [{:node-type :workspace-transform :id tx-ref-id}]
- (global-parents ws-id "table" id))))
-
-(defn- table? [{:keys [node-type]}] (= :table node-type))
-
-(defn- node-parents [ws-id {:keys [node-type id]}]
- (case node-type
- :workspace-transform (ws-transform-parents ws-id id)
- :external-transform (global-tx-parents id)
- :external-card (global-parents ws-id "card" id)
- :table (table-producers ws-id id)))
-
-(defn- node->allowed-parents
- [pred deps node]
- (if-not (pred node)
- [node]
- ;; Collapse to the things that *produce* node. If it is a root node, leave it in.
- (or (seq (mapcat (partial node->allowed-parents pred deps) (deps node)))
- [node])))
-
-(defn- collapse
- "Remove nodes that satisfy pred, in-lining their transitive dependencies instead."
- [pred deps]
- (u/for-map [[child parents] deps
- :when (not (pred child))]
- [child (mapcat (partial node->allowed-parents pred deps) parents)]))
-
-(defn- render-graph [entities parents deps & {:keys [table? table-sort unwrap-table]
- :or {table? table?
- table-sort (juxt :db :schema :table)
- unwrap-table :id}}]
- (let [table-nodes (filter table? entities)
- ;; Any table that has a parent in the subgraph is an output
- outputs (filter deps table-nodes)
- ;; Anything other parent table is an input
- inputs (->> entities (mapcat parents) (filter table?) (remove (set outputs)) distinct)
- entities (->> (ws.u/toposort-dfs deps) (remove table?))
- deps+input (reduce
- (fn [deps [c parents]]
- (if-not (deps c)
- deps
- (update deps c into parents)))
- deps
- parents)]
- {:inputs (sort-by table-sort (map unwrap-table inputs))
- :outputs (sort-by table-sort (map unwrap-table outputs))
- :entities entities
- ;; collapse tables out, directly connecting transforms? smaller graphs are easier for humans to read
- :dependencies (collapse table? deps+input)}))
-
-(defn- path-induced-subgraph*
- "Implementation for [[path-induced-subgraph]] that takes the lookup functions as arguments. Useful for testing."
- [init-nodes fns]
- (loop [members (set init-nodes)
- cache {}
- ;; Association list sets from nodes to their direct dependencies
- deps (u/for-map [node init-nodes] [node #{}])
- ;; Paths are vectors sorted from child to parent
- [path & paths] (for [node members] [node])]
- (if-not path
- ;; Finished walking all paths, render the result.
- (render-graph members cache deps fns)
- ;; Look-up from cache first
- (let [_ (when (some #(not= 1 (val %)) (frequencies path))
- (throw (ex-info "Cycle detected" {:path path})))
- head (peek path)
- parents-fn (:node-parents fns)
- parents (cache head (parents-fn head))
- cache (assoc cache head parents)
- continue (when parents (remove members parents))]
- (if (not= parents continue)
- ;; At least one parent is in the enclosed subgraph, so this entire path is as well.
- (let [add-dep (fn [deps [child parent]]
- (update deps child (fnil conj #{}) parent))
- ;; Break up the path into adjacent child-parent pairs.
- pairs (concat (partition 2 1 path)
- (map (fn [end] [(peek path) end]) (filter members parents)))
- ;; Since everything along this path will now be added to deps already, we can truncate the paths.
- next-paths (into paths (for [c continue] [(peek path) c]))]
- (recur (into members path) cache (reduce add-dep deps pairs) next-paths))
- ;; We have not reached another member of the enclosed subgraph yet, so keep extending.
- (recur members cache deps (into paths (for [c continue] (conj path c)))))))))
-
-;;;; Public API
-
-(defn reverse-graph
- "Reverse edge direction: child->parents becomes parent->children.
- Takes a dependency map and returns a map where each parent points to its children."
- [deps-map]
- (reduce (fn [m [child parents]]
- (reduce (fn [acc parent]
- (update acc parent (fnil conj []) child))
- m
- parents))
- {}
- deps-map))
-
-(defn bfs-reduce
- "BFS traversal from start node(s) through an edge map.
-
- edges-map - adjacency map from node to its neighbors
- starts - a collection of start nodes
-
- Options:
- - :include-start? - include start node(s) in result (default: false)
- - :rf - reducing function for collecting results (default: conj)
- - :init - initial value for the result accumulator (default: [])
-
- Returns the accumulated result in BFS order (no duplicates)."
- [edges-map starts & {:keys [include-start? rf init]
- :or {rf conj, init []}}]
- (let [init-set (set starts)
- get-children #(get edges-map % [])
- ;; Queue always starts with children of start nodes (excluding start nodes themselves)
- init-children (into [] (comp (mapcat get-children) (remove init-set)) starts)]
- (loop [queue init-children
- ;; Only mark start nodes as visited if we're including them in result
- ;; This allows routes between start nodes to be detected when include-start? is false
- visited (transient (if include-start? init-set #{}))
- result (if include-start? (reduce rf init starts) init)]
- (if (empty? queue)
- result
- (let [current (first queue)
- queue (subvec queue 1)]
- (if (visited current)
- (recur queue visited result)
- (let [children (get-children current)
- new-nodes (remove visited children)]
- (recur (into queue new-nodes)
- (conj! visited current)
- (rf result current)))))))))
-
-(defn path-induced-subgraph
- "Given a list of internal entities, compute the path-induced subgraph.
-
- Returns a map with:
- - :inputs - tables that the subgraph directly depends on, that are not themselves produced by the subgraph.
- ordered lexically by db+schema+table, to be stable across metabase instances, and visibly sorted.
- - :outputs - outputs of both the changeset transforms, and the external transforms enclosed by the changeset.
- both the external names, and the internal (isolated) names. sorted by the external names.
- point back to their relevant transform.
-
- - :entities - the full list of entities, both internal, and those that are enclosed. topo-sorted.
- - :dependencies - association list for the subgraph, with keys and values both in topological order"
- [ws-id internal-entities]
- (ws.u/assert-transforms! internal-entities)
- (if (empty? internal-entities)
- {:inputs []
- :outputs []
- :entities []
- :dependencies {}}
- (let [tx-nodes (for [{:keys [entity-type id]} internal-entities]
- (case entity-type
- :transform {:node-type :workspace-transform, :id id}))
- ->latest (fn [versioned-entities]
- (let [versions (u/group-by (juxt :node-type :id) versioned-entities)
- latest? (into #{}
- (map (fn [[entity versions]]
- (if (= 1 (count versions))
- (first versions)
- (assoc entity :version (transduce (map :version) max versions)))))
- versions)]
- (filter latest? versioned-entities)))
- outputs (when (seq tx-nodes)
- (->latest
- (t2/select-fn-vec (fn [row]
- {:node-type :table
- :id (t2.realize/realize row)
- :version (:version row)})
- ;; We use workspace_output.id (i.e. analysis write order) as a proxy for
- ;; the order in which the corresponding transforms were updated.
- [:model/WorkspaceOutput
- [:id :version]
- [:db_id :db]
- [:global_schema :schema]
- [:global_table :table]
- [:global_table_id :id]]
- :workspace_id ws-id
- :ref_id [:in (map :id tx-nodes)])))
- init-nodes (concat tx-nodes outputs)
- fns {:node-parents (partial node-parents ws-id)
- :table? table?}]
- (path-induced-subgraph* init-nodes fns))))
-
-;; source-table ---------> checked-out-transform
-;; \____external-transform__/
-;;
-;; should external-transform be enclosed? answer: no, because it won't become stale from changes in the workspace
-;;
-;; source-table ----> model ---> checked-out-transform
-;;
-;; this time we *need* the model to be serialized, because we need to read it in a fresh instance.
-;; it doesn't need to be remapped or "run" independently though, so does it make sense to call it enclosed?
-;;
-;; enclosed: between changeset only? or including the model in the example above?
-;; ancestors: as far back as you can go
-;;
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/dependencies.clj b/enterprise/backend/src/metabase_enterprise/workspaces/dependencies.clj
deleted file mode 100644
index 68fc1720471..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/dependencies.clj
+++ /dev/null
@@ -1,331 +0,0 @@
-(ns metabase-enterprise.workspaces.dependencies
- "Workspace-local dependency tracking.
-
- Unlike the global `dependency` table which links to `table_id` (requiring the table to exist),
- workspace dependencies use two tables that support logical references:
-
- - `workspace_input` - external tables transforms consume (may not exist yet)
- - `workspace_input_transform` - join table linking inputs to transforms (ref_id + transform_version)
- - `workspace_output` - tables transforms produce
-
- ## Example: Internal Dependency (Transform B depends on Transform A's output)
-
- Transform A produces `analytics.orders_summary`:
- ```
- {:ref_id \"happy-dolphin-a1b2\"
- :target {:database 1 :schema \"analytics\" :name \"orders_summary\"}}
- ```
-
- Transform B reads from `analytics.orders_summary`:
- ```
- {:ref_id \"brave-lion-g7h8\"
- :source {:type \"query\" :query \"SELECT * FROM analytics.orders_summary\"}
- :target {:database 1 :schema \"analytics\" :name \"orders_report\"}}
- ```
-
- After processing both transforms:
-
- workspace_output:
- | id | ref_id | schema | table |
- |-----|--------------------|-----------|----------------|
- | 101 | happy-dolphin-a1b2 | analytics | orders_summary |
- | 104 | brave-lion-g7h8 | analytics | orders_report |
-
- Transform B depends on Transform A's output - this is detected by matching table coordinates
- against workspace_output records during DAG traversal (no explicit edge storage needed).
-
- If Transform A also depended on an external table ORDERS:
-
- workspace_input:
- | id | schema | table | table_id |
- |-----|--------|--------|----------|
- | 201 | PUBLIC | ORDERS | 42 |
-
- workspace_input_transform:
- | workspace_input_id | ref_id | transform_version |
- |--------------------|--------------------|-------------------|
- | 201 | happy-dolphin-a1b2 | 1 |
-
- The join table links inputs to transforms, allowing multiple transforms to share a single input row."
- (:require
- [metabase-enterprise.workspaces.models.workspace-input]
- [metabase-enterprise.workspaces.models.workspace-input-transform]
- [metabase-enterprise.workspaces.models.workspace-output]
- [metabase-enterprise.workspaces.util :as ws.u]
- [metabase.app-db.core :as app-db]
- [metabase.driver :as driver]
- [metabase.driver.sql :as driver.sql]
- [metabase.lib.core :as lib]
- [metabase.lib.metadata :as lib.metadata]
- [metabase.util :as u]
- [metabase.util.log :as log]
- [metabase.util.malli :as mu]
- [metabase.util.malli.registry :as mr]
- [metabase.util.performance :as perf]
- [metabase.warehouse-schema.models.table :as table]
- [toucan2.core :as t2]))
-
-;;; ---------------------------------------- Schemas ----------------------------------------
-
-(mr/def ::table-ref
- "A logical reference to a table by schema and name. Includes table_id if the table exists."
- [:map
- [:db_id :int]
- [:schema [:maybe :string]]
- [:table :string]
- [:table_id {:optional true} [:maybe :int]]])
-
-(mr/def ::output-ref
- "A reference to an output table (transform target)."
- [:map
- [:db_id :int]
- [:schema [:maybe :string]]
- [:table :string]])
-
-(mr/def ::analysis
- "The result of analyzing an entity's dependencies."
- [:map
- [:output ::output-ref]
- [:inputs [:sequential ::table-ref]]])
-
-;;; ---------------------------------------- Batch table lookups ----------------------------------------
-
-(defn- batch-table-refs-from-ids
- "Look up table metadata for multiple table IDs in a single query.
- Returns a map of table-id -> {:db_id :schema :table :table_id}."
- [table-ids]
- (when (seq table-ids)
- (t2/select-fn->fn :id
- (fn [{:keys [id db_id schema name]}]
- {:db_id db_id
- :schema schema
- :table name
- :table_id id})
- [:model/Table :id :db_id :schema :name]
- :id [:in table-ids])))
-
-(defn- batch-lookup-table-ids
- "Look up table_ids for multiple logical table references in a single query.
- Uses the same matching logic as find-table-or-transform: if parsed schema is nil,
- it matches against the driver's default schema.
- Returns a map of [db_id search-schema table] -> table_id where search-schema
- is the schema used for lookup (defaulted if nil)."
- [driver db-id table-refs]
- (when (seq table-refs)
- (let [default-schema (driver.sql/default-schema driver)
- ;; Include default-schema in filter so nil refs can match that too
- nil-schema? (some (comp nil? :schema) table-refs)
- schemas-to-query (into #{} (map #(or (:schema %) default-schema)) table-refs)
- db-table-lookup (t2/select-fn->fn (juxt :schema :name) :id
- [:model/Table :id :schema :name]
- :db_id db-id
- :name [:in (map :table table-refs)]
- {:where (if nil-schema?
- [:or [:= :schema nil] [:in :schema schemas-to-query]]
- [:in :schema schemas-to-query])})]
- (into {}
- (keep (fn [{:keys [schema table]}]
- (let [table-id (or (get db-table-lookup [schema table])
- (when (nil? schema)
- (get db-table-lookup [default-schema table])))]
- (when table-id
- [[db-id schema table] table-id]))))
- table-refs))))
-
-(defn- output-from-target
- "Extract output table info from a transform's :target field."
- [{:keys [database schema name] :as _target}]
- {:db_id database
- :schema schema
- :table name})
-
-;;; ---------------------------------------- Input extraction ----------------------------------------
-
-(defn- inputs-from-mbql-query
- "Extract table refs from an MBQL query. Tables are looked up by ID in batch."
- [query]
- (let [table-ids (-> #{}
- (into (lib/all-source-table-ids query))
- (into (lib/all-implicitly-joined-table-ids query)))
- table-refs (batch-table-refs-from-ids table-ids)]
- (u/keepv table-refs table-ids)))
-
-(defn- inputs-from-native-query
- "Extract table refs from a native query. Uses driver/native-query-table-refs to get
- schema+table directly, then batch looks up table_ids for tables that exist.
- Uses the same default schema logic as find-table-or-transform."
- [query db-id]
- (let [driver (:engine (lib.metadata/database query))
- parsed-refs (driver/native-query-table-refs driver query)
- ;; Batch lookup existing table IDs (handles default schema logic)
- table-id-map (batch-lookup-table-ids driver db-id parsed-refs)]
- (perf/for [{:keys [schema table]} parsed-refs
- :let [table-id (get table-id-map [db-id schema table])]]
- (cond-> {:db_id db-id
- :schema schema
- :table table}
- table-id (assoc :table_id table-id)))))
-
-(defn- inputs-from-query
- "Extract table refs from a query (MBQL or native)."
- [query db-id]
- (if (lib/native-only-query? query)
- (inputs-from-native-query query db-id)
- (inputs-from-mbql-query query)))
-
-(defn- inputs-from-python-transform
- "Extract table refs from a python transform's source-tables vec.
- Entries with :database_id/:schema/:table just need a key rename;
- entries with only :table_id fall back to a batch lookup."
- [source-tables]
- (let [{full true, partial false} (group-by (fn [e] (boolean (:table e))) source-tables)
- renamed (mapv (fn [{:keys [database_id schema table]}]
- {:db_id database_id :schema schema :table table})
- full)
- looked (when (seq partial)
- (let [ids (into #{} (keep :table_id) partial)
- lookup (batch-table-refs-from-ids ids)]
- (u/keepv lookup (map :table_id partial))))]
- (into renamed looked)))
-
-(mu/defn analyze-entity :- ::analysis
- "Analyze a workspace entity to find its dependencies.
-
- Arguments:
- - entity-type: keyword, must be :transform (asserted)
- - entity: the workspace transform map with :source and :target
-
- Returns:
- {:output {:db_id int :schema string :table string}
- :inputs [{:db_id int :schema string :table string} ...]}"
- [entity-type :- :keyword
- entity :- :map]
- (ws.u/assert-transform! entity-type)
- (let [{{:keys [query source-tables], source-type :type} :source
- target :target} entity
- db-id (:database target)
- inputs (cond
- (= (keyword source-type) :query)
- (inputs-from-query query db-id)
-
- (= (keyword source-type) :python)
- (inputs-from-python-transform source-tables)
-
- :else
- (do (log/warnf "Don't know how to analyze deps of transform with source type '%s'" source-type)
- []))]
- {:output (output-from-target target)
- :inputs inputs}))
-
-;;; ---------------------------------------- Write helpers ----------------------------------------
-
-(defn- insert-workspace-output!
- "Insert a workspace_output record for the transform's target table with the given transform_version.
- Stores both global (original) and isolated (workspace-specific) table identifiers.
- With epochal versioning, we always insert new rows - cleanup of old versions happens separately.
- Silently ignores constraint violations from concurrent inserts."
- [workspace-id ref-id isolated-schema {:keys [db_id schema table]} transform-version]
- ;; 5 queries here: 2 × upsert-transform-target-table! (2 queries each) + 1 insert.
- ;; Worst case 9 on concurrent upsert conflicts.
- (let [isolated-table (ws.u/isolated-table-name schema table)
- global-table-id (table/upsert-transform-target-table! db_id schema table)
- isolated-table-id (table/upsert-transform-target-table! db_id isolated-schema isolated-table)]
- (ws.u/ignore-constraint-violation
- (t2/insert! :model/WorkspaceOutput
- {:workspace_id workspace-id
- :ref_id ref-id
- :transform_version transform-version
- :db_id db_id
- :global_schema schema
- :global_table table
- :global_table_id global-table-id
- :isolated_schema isolated-schema
- :isolated_table isolated-table
- :isolated_table_id isolated-table-id}))))
-
-(defn- normalize-input-schema
- "Normalize an input's schema: replace nil with the driver's default schema.
- This ensures consistent comparison with output schemas which are always explicit."
- [default-schema input]
- (update input :schema #(or % default-schema)))
-
-(defn- upsert-workspace-input!
- "Ensure a workspace_input row exists for the given table coordinate.
- Returns the workspace_input id (existing or newly created)."
- [workspace-id {:keys [db_id schema table table_id]}]
- (let [table_id (or table_id
- (t2/select-one-fn :id [:model/Table :id]
- :db_id db_id :schema schema :name table))]
- (app-db/update-or-insert!
- :model/WorkspaceInput
- {:workspace_id workspace-id
- :db_id db_id
- :schema schema
- :table table}
- (fn [existing]
- (cond-> {:workspace_id workspace-id
- :db_id db_id
- :schema schema
- :table table
- :table_id (:table_id existing)}
- table_id (assoc :table_id table_id))))))
-
-(defn- insert-workspace-inputs!
- "Insert a single workspace_input record per table, with a join entry per transform that uses that table."
- [workspace-id ref-id inputs transform-version]
- (when (seq inputs)
- ;; N+1 query here: we query once per input to handle race conditions. Native SQL upserts would be faster
- ;; but we don't have a driver-independent helper for that.
- (let [input-ids (mapv (partial upsert-workspace-input! workspace-id) inputs)]
- (ws.u/ignore-constraint-violation
- (t2/insert! :model/WorkspaceInputTransform
- (for [input-id input-ids]
- {:workspace_input_id input-id
- :workspace_id workspace-id
- :ref_id ref-id
- :transform_version transform-version})))))
- nil)
-
-(defn transform-output-exists-for-version?
- "Check if workspace_output exists for a transform at the given version or later."
- [ws-id ref-id transform-version]
- (t2/exists? :model/WorkspaceOutput
- :workspace_id ws-id
- :ref_id ref-id
- :transform_version [:>= transform-version]))
-
-(mu/defn write-entity-analysis! :- :nil
- "Persist dependency analysis for a workspace entity.
-
- Arguments:
- - workspace-id: int
- - isolated-schema: string, the workspace's isolated schema name
- - entity-type: keyword, must be :transform
- - ref-id: string, the workspace_transform.ref_id
- - analysis: result from analyze-entity
- - transform-version: long, the analysis_version to write (for epochal versioning)
-
- Side effects:
- - Inserts workspace_output for this transform (with both global and isolated identifiers)
- - Inserts workspace_input records for this transform's external dependencies
- - Old version cleanup happens separately in impl.clj"
- [workspace-id :- :int
- isolated-schema :- :string
- entity-type :- :keyword
- ref-id :- :string
- {:keys [output inputs]} :- ::analysis
- transform-version :- :int]
- (ws.u/assert-transform! entity-type)
- (t2/with-transaction [_conn]
- (when-not (transform-output-exists-for-version? workspace-id ref-id transform-version)
- (let [driver (t2/select-one-fn :engine [:model/Database :engine]
- :id [:in {:select [:database_id]
- :from [:workspace]
- :where [:= :id workspace-id]}])
- default-schema (driver.sql/default-schema driver)
- ;; Normalize external inputs so schemas are consistent
- normalized-inputs (map (partial normalize-input-schema default-schema) inputs)]
- ;; Insert inputs first, then output - output row acts as "commit marker" for version check
- (insert-workspace-inputs! workspace-id ref-id normalized-inputs transform-version)
- (insert-workspace-output! workspace-id ref-id isolated-schema output transform-version)
- nil))))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/events.clj b/enterprise/backend/src/metabase_enterprise/workspaces/events.clj
deleted file mode 100644
index 6ae60e5cb7c..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/events.clj
+++ /dev/null
@@ -1,33 +0,0 @@
-(ns metabase-enterprise.workspaces.events
- "Event handlers to increment workspace graph versions when global transforms change."
- (:require
- [metabase.events.core :as events]
- [metabase.util.log :as log]
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-;; When a global transform is created, updated, or deleted, increment graph_version for all workspaces.
-;; This is a conservative approach - we could be more selective by tracking which workspaces
-;; reference which transforms, but the complexity of doing so would be brittle.
-
-(defn- increment-all-workspace-graph-versions!
- "Increment graph_version for all workspaces, triggering graph recalculation."
- []
- (let [result (t2/query {:update :workspace
- :set {:graph_version [:+ :graph_version 1]}})]
- (when (pos? (:next.jdbc/update-count result 0))
- (log/debug "Incremented graph_version for all workspaces due to global transform change"))))
-
-;; These events are published by metabase.transforms-rest.api when transforms are
-;; created, updated, or deleted. We subscribe to increment graph versions.
-
-(derive ::workspace-staleness :metabase/event)
-(derive :event/transform-create ::workspace-staleness)
-(derive :event/transform-update ::workspace-staleness)
-(derive :event/transform-delete ::workspace-staleness)
-
-(methodical/defmethod events/publish-event! ::workspace-staleness
- [_ _event]
- ;; Increment graph_version for all workspaces when any global transform changes.
- ;; The graph will be recalculated lazily the next time we need it.
- (increment-all-workspace-graph-versions!))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/execute.clj b/enterprise/backend/src/metabase_enterprise/workspaces/execute.clj
deleted file mode 100644
index 993b8041c68..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/execute.clj
+++ /dev/null
@@ -1,192 +0,0 @@
-(ns metabase-enterprise.workspaces.execute
- "Executing transforms with optional reference re-mappings, without writing to AppDB.
-
- Uses transforms-base.core/execute! to run transforms in-memory. No Transform or TransformRun
- rows are created in AppDB. Warehouse DB changes (actual table data) persist in the isolated schema."
- (:require
- [clojure.string :as str]
- [metabase-enterprise.transforms-python.python-runner :as python-runner]
- [metabase.query-processor.core :as qp]
- [metabase.transforms-base.core :as transforms-base]
- [metabase.transforms-base.util :as transforms-base.u]
- [metabase.util.log :as log]
- [metabase.util.malli :as mu]))
-
-(set! *warn-on-reflection* true)
-
-(mu/defn- remap-python-source
- "Remap source-tables in a Python transform source to point to isolated tables."
- [table-mapping source :- [:map [:source-tables [:sequential ::transforms-base.u/source-table-entry]]]]
- (letfn [(remap [{:keys [database_id schema table table_id] :as entry}]
- (if-let [{:keys [id db-id] target-schema :schema target-table :table}
- (or (table-mapping entry)
- (some-> table_id table-mapping)
- (when table
- (table-mapping [database_id schema table])))]
- (cond-> entry
- id (assoc :table_id id)
- db-id (assoc :database_id db-id)
- target-schema (assoc :schema target-schema)
- target-table (assoc :table target-table))
- entry))]
- (update source :source-tables (fn [entries] (mapv remap entries)))))
-
-(defn- attach-table-remapping [table-mapping source]
- (let [tables (into {}
- (keep (fn [[[_ src-schema src-table] {tgt-schema :schema tgt-table :table}]]
- [{:schema src-schema :table src-table}
- {:schema tgt-schema :table tgt-table}]))
- ;; Keep only the named reference tuples that we will destructure, the table-id keys are irrelevant.
- (filter (comp vector? key) table-mapping))]
- (cond-> source
- (seq tables) (assoc-in [:query :middleware :workspace-remapping] {:tables tables}))))
-
-(defn- attach-table-field-remapping [_table-mapping _field-map source]
- (throw (ex-info "Remapping MBQL queries is not supported yet" {:source source})))
-
-(defn- remap-source [table-map field-map source-type source]
- (case source-type
- :mbql (attach-table-field-remapping table-map field-map source)
- :native (attach-table-remapping table-map source)
- :python (remap-python-source table-map source)))
-
-;; You might prefer a multi-method? I certainly would.
-
-(defn- remap-target [table-map target-fallback {d :database, s :schema, t :name :as target}]
- (if-let [replacement (or (table-map [d s t]) (target-fallback [d s t]))]
- ;; Always fallback to tables for re-mapped outputs, regardless of the type used in the original target.
- {:type (:type replacement "table")
- :database (:db-id replacement)
- :schema (:schema replacement)
- :name (:table replacement)}
- target))
-
-(def ^:private no-mapping {})
-
-(defn remapped-target
- "Extracts and applies remapping to a transform's target table reference.
-
- Used when needing to determine the isolated table location without running the full transform.
- Useful for error reporting and result construction.
-
- `remapping` is a map with:
- - `:tables` - map of table references to isolated table specs
- - `:target-fallback` - function to generate fallback mappings for unmapped targets
-
- Returns the remapped target as a map with `:type`, `:database`, `:schema`, and `:name`."
- [{:keys [target] :as _transform} remapping]
- (let [table-mapping (:tables remapping no-mapping)
- target-fallback (:target-fallback remapping no-mapping)]
- (remap-target table-mapping target-fallback target)))
-
-(def ^:private preview-row-limit
- "Maximum number of rows to return in dry-run/preview mode."
- 2000)
-
-(defn- dry-run-python
- "Run Python transform and return first 2000 rows without persisting.
- Returns a map with :status and :data (on success) or :message (on failure)."
- [{:keys [source]} remapping]
- (let [table-mapping (:tables remapping no-mapping)
- remapped-source (remap-python-source table-mapping source)
- resolved-source-tables (transforms-base.u/resolve-source-tables (:source-tables remapped-source))
- {:as result
- :keys [cols rows]} (python-runner/execute-and-read-output!
- {:code (:body remapped-source)
- :source-tables resolved-source-tables
- :row-limit preview-row-limit})]
- (if (= :succeeded (:status result))
- (let [flatrows (apply juxt (map (fn [c] (let [cname (:name c)] #(get % cname))) cols))]
- {:status :succeeded
- ;; return logs for debugging
- :logs (str/join "\n" (:logs result))
- :data {:cols cols
- :rows (mapv flatrows rows)}})
- {:status :failed
- :message (:message result)})))
-
-(defn- run-query
- "Remap source, execute query, and format as ::ws.t/query-result.
- Options: :row-limit (default 2000), :error-context (for logging).
- Returns {:status :succeeded :data {...} :running_time ...} or {:status :failed :message ...}."
- [source source-type remapping {:keys [row-limit error-context]
- :or {row-limit preview-row-limit}}]
- (try
- (let [table-mapping (:tables remapping no-mapping)
- field-mapping (:fields remapping no-mapping)
- remapped-source (remap-source table-mapping field-mapping source-type source)
- query (-> (:query remapped-source)
- (qp/userland-query)
- (assoc :constraints {:max-results row-limit
- :max-results-bare-rows row-limit}))
- result (qp/process-query query)
- data (:data result)]
- (if (= :completed (:status result))
- {:status :succeeded
- :data (select-keys data [:rows :cols :results_metadata])
- :running_time (:running_time result)
- :started_at (:started_at result)}
- {:status :failed
- :message (or (:error result) "Query execution failed")}))
- (catch Exception e
- (log/error e error-context)
- {:status :failed
- :message (ex-message e)})))
-
-(defn- dry-run-sql
- "Run SQL transform query and return first 2000 rows without persisting.
- Returns a ::ws.t/query-result map with data nested under :data to match /api/dataset format."
- [{:keys [source]} remapping]
- (run-query source (transforms-base.u/transform-source-type source) remapping
- {:error-context "Failed to run sql dry-run"}))
-
-(defn execute-adhoc-sql
- "Execute an arbitrary SQL query against a database and return up to row-limit rows (default 2000).
- Applies workspace table remapping so queries can reference global table names.
- Returns a ::ws.t/query-result map with data nested under :data."
- ([database-id sql remapping]
- (execute-adhoc-sql database-id sql remapping {}))
- ([database-id sql remapping opts]
- (let [source {:query {:database database-id
- :lib/type :mbql/query
- :stages [{:lib/type :mbql.stage/native
- :native sql}]}}]
- (run-query source :native remapping
- (merge {:error-context "Failed to execute adhoc SQL query"} opts)))))
-
-(defn run-transform-preview
- "Execute transform and return first 2000 rows without persisting.
- Returns a ::ws.t/query-result map with data nested under :data."
- [{:keys [source] :as transform} remapping]
- (let [s-type (transforms-base.u/transform-source-type source)]
- (case s-type
- (:native :mbql) (dry-run-sql transform remapping)
- :python (dry-run-python transform remapping))))
-
-(defn run-transform-with-remapping
- "Execute a given transform with the given table and field re-mappings.
-
- This is used by Workspaces to re-route the output of each transform to a non-production table, and
- to re-write their queries where these outputs transitively become inputs to other transforms.
-
- Returns an ::ws.t/execution-result map with status, timing, and table metadata.
-
- Uses transforms-base.core/execute! to run the transform in-memory without writing
- Transform or TransformRun rows to AppDB. The warehouse DB changes (actual table data)
- DO persist in the isolated schema."
- [{:keys [source target] :as transform} remapping]
- (let [s-type (transforms-base.u/transform-source-type source)
- table-mapping (:tables remapping no-mapping)
- target-fallback (:target-fallback remapping no-mapping)
- field-mapping (:fields remapping no-mapping)
- remapped-xf (-> (select-keys transform [:name :description])
- (assoc :source (remap-source table-mapping field-mapping s-type source)
- :target (remap-target table-mapping target-fallback target)))
- _ (assert (:target remapped-xf) "Target mapping must not be nil")
- start-time (java.time.Instant/now)
- result (transforms-base/execute! remapped-xf {:publish-events? false})]
- {:status (:status result)
- :start_time start-time
- :end_time (java.time.Instant/now)
- :message (or (:logs result) (some-> (:error result) ex-message))
- :table (select-keys (:target remapped-xf) [:name :schema])}))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/impl.clj b/enterprise/backend/src/metabase_enterprise/workspaces/impl.clj
deleted file mode 100644
index 2606b8d5e98..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/impl.clj
+++ /dev/null
@@ -1,944 +0,0 @@
-(ns metabase-enterprise.workspaces.impl
- "Glue code connecting workspace subsystems (dependencies, isolation)."
- (:require
- [clojure.set :as set]
- [clojure.string :as str]
- [metabase-enterprise.workspaces.dag :as ws.dag]
- [metabase-enterprise.workspaces.dependencies :as ws.deps]
- [metabase-enterprise.workspaces.execute :as ws.execute]
- [metabase-enterprise.workspaces.isolation :as ws.isolation]
- [metabase-enterprise.workspaces.util :as ws.u]
- [metabase.api.common :as api]
- [metabase.driver.sql :as driver.sql]
- [metabase.util :as u]
- [metabase.util.log :as log]
- [metabase.warehouse-schema.models.table :as table]
- [toucan2.core :as t2]))
-
-(defn- query-ungranted-external-inputs
- "Query for external inputs in a workspace that haven't been granted access yet.
- External inputs are tables that are not shadowed by any output tables.
- Returns seq of WorkspaceInput records where the table is active, and access_granted is false."
- [workspace-id]
- ;; It would be nice if we could optimize this join to use table_id, since we ignore tables that don't exist anyway.
- (t2/select :model/WorkspaceInput
- :workspace_id workspace-id
- {:where [:and
- [:= :workspace_input.access_granted false]
- ;; Ignore tables that will be shadowed by outputs of other transforms.
- [:not [:exists {:select [1]
- :from [[:workspace_output :wo]]
- :where [:and
- [:= :wo.workspace_id :workspace_input.workspace_id]
- [:= :wo.db_id :workspace_input.db_id]
- [:or
- [:and [:= :wo.global_schema nil] [:= :workspace_input.schema nil]]
- [:= :wo.global_schema :workspace_input.schema]]
- [:= :wo.global_table :workspace_input.table]]}]]
- [:not [:exists {:select [1]
- :from [[:workspace_output_external :woe]]
- :where [:and
- [:= :woe.workspace_id :workspace_input.workspace_id]
- [:= :woe.db_id :workspace_input.db_id]
- [:or
- [:and [:= :woe.global_schema nil] [:= :workspace_input.schema nil]]
- [:= :woe.global_schema :workspace_input.schema]]
- [:= :woe.global_table :workspace_input.table]]}]]
- ;; Ignore tables that don't currently exist.
- [:exists {:select [1]
- :from [[:metabase_table :t]]
- :where [:and
- [:= :active true]
- [:= :t.db_id :workspace_input.db_id]
- [:or
- [:and [:= :t.schema nil] [:= :workspace_input.schema nil]]
- [:= :t.schema :workspace_input.schema]]
- [:= :t.name :workspace_input.table]]}]]}))
-
-(defn- external-input->table
- [{:keys [schema table]}]
- {:schema schema
- :name table})
-
-(defn ungranted-inputs-for-transform
- "Return ungranted WorkspaceInput rows that are linked to the given transform (by ref-id).
- Uses the latest transform_version from workspace_input_transform."
- [ws-id ref-id]
- (t2/select [:model/WorkspaceInput :id :db_id :schema :table :table_id]
- {:join [[:workspace_input_transform :wit]
- [:= :wit.workspace_input_id :workspace_input.id]]
- :where [:and
- [:= :wit.workspace_id ws-id]
- [:= :wit.ref_id ref-id]
- [:= :workspace_input.access_granted false]
- [:= :wit.transform_version
- {:select [[:%max.transform_version]]
- :from [:workspace_input_transform]
- :where [:and
- [:= :workspace_id ws-id]
- [:= :ref_id ref-id]]}]]}))
-
-(defn sync-grant-accesses!
- "Grant read access to external input tables for a workspace that haven't been granted yet.
- External inputs are tables that are read by transforms but not produced by any transform in the workspace.
- This should be called after adding transforms to a workspace or when re-initializing workspace isolation
- (e.g., after unarchiving)."
- [{workspace-id :id :as workspace}]
- (let [ungranted-inputs (query-ungranted-external-inputs workspace-id)]
- (if-not (:database_details workspace)
- ;; TODO (Chris 2025-12-15) -- this should throw, but we're cautious about racing with initialization
- #_(throw (ex-info "No database details, unable to grant read only access to the service account." {}))
- (log/warn "No database details, unable to grant read only access to the service account.")
- (when (seq ungranted-inputs)
- (let [database (t2/select-one :model/Database :id (:database_id workspace))
- tables (mapv external-input->table ungranted-inputs)]
- (try
- (ws.isolation/grant-read-access-to-tables! database workspace tables)
- ;; Mark inputs as granted after successful grant
- (t2/update! :model/WorkspaceInput {:id [:in (map :id ungranted-inputs)]}
- {:access_granted true})
- (catch Exception e
- ;; Suppress errors for tables that don't exist (common in tests with fake tables)
- (when-not (some->> (ex-message e) (re-find #"(?i)(does not exist|not found|no such table)"))
- (log/warn e "Error granting RO table permissions")))))))))
-
-(defn grant-accesses-if-superuser!
- "Grant read access to external input tables if the current user is a superuser.
- Wrapper around sync-grant-accesses! that checks superuser permission."
- [workspace]
- (when api/*is-superuser?*
- (sync-grant-accesses! workspace)))
-
-(defn- batch-lookup-table-ids
- "Given a bounded list of tables, all within the same database, return an association list of [db schema table] => id"
- [db-id schema-key table-key table-refs]
- (when (seq table-refs)
- (t2/select-fn-vec (juxt (juxt (constantly db-id) :schema :name) :id)
- [:model/Table :id :schema :name]
- :db_id db-id
- {:where (into [:or] (for [tr table-refs]
- [:and
- [:= :schema (get tr schema-key)]
- [:= :name (get tr table-key)]]))})))
-
-(defn table-ids-fallbacks
- "Given a list of maps holding [db_id schema table], return a mapping from those tuples => table_id"
- ([table-refs]
- (table-ids-fallbacks :schema :name :id table-refs))
- ([schema-key table-key id-key table-refs]
- (when-let [table-refs (seq (remove id-key table-refs))]
- ;; These are ordered by db, so this will partition fine.
- (u/for-map [table-refs (partition-by :db_id table-refs)
- :let [db_id (:db_id (first table-refs))]
- ;; Guesstimating a number that prevents this query being too large.
- table-refs (partition-all 20 table-refs)
- map-entry (batch-lookup-table-ids db_id schema-key table-key table-refs)]
- map-entry))))
-
-(defn- add-table-mapping-entries
- "Add table mapping entries for a single table.
- Adds:
- - [db-id schema table] -> replacement (for qualified SQL references)
- - table-id -> replacement (for MBQL/Python, if table-id provided)
- - [db-id nil table] -> replacement (for unqualified SQL, if in-default-schema? is true)"
- [m {:keys [db-id schema table table-id replacement in-default-schema?]}]
- (cond-> m
- true (assoc [db-id schema table] replacement)
- table-id (assoc table-id replacement)
- in-default-schema? (assoc [db-id nil table] replacement)))
-
-(defn- build-remapping
- "Build table remapping from the analyzed input and output tables.
-
- Uses stored WorkspaceOutput, WorkspaceOutputExternal, WorkspaceInput, and WorkspaceInputExternal data.
-
- For OUTPUTS (isolated tables):
- Maps [db_id global_schema global_table] -> {:db-id :schema :table :id} for isolated tables.
- Also maps global_table_id -> same. This is more convenient and reliable for MBQL queries and Python transforms.
- Also maps [db_id nil global_table] for tables in the default schema, so unqualified SQL references work.
-
- For INPUTS (external tables read from source DB):
- Maps [db_id schema table] -> {:db-id :schema :table :id} to qualify references.
- This ensures \"SELECT * FROM orders\" becomes \"SELECT * FROM public.orders\" (or \"mydb.orders\" for MySQL).
-
- Output mappings take precedence over input mappings (merged last).
- This is used to remap queries, sources and targets to reflect the \"isolated\" tables used to seal the Workspace."
- [workspace _graph]
- (let [outputs (t2/select [:model/WorkspaceOutput
- :db_id :global_schema :global_table :global_table_id
- :isolated_schema :isolated_table :isolated_table_id]
- :workspace_id (:id workspace))
- external-outputs (t2/select [:model/WorkspaceOutputExternal
- :db_id :global_schema :global_table :global_table_id
- :isolated_schema :isolated_table :isolated_table_id]
- :workspace_id (:id workspace))
- all-outputs (concat outputs external-outputs)
- ;; Fetch input tables (external tables that transforms read from)
- inputs (t2/select [:model/WorkspaceInput :db_id :schema :table :table_id]
- :workspace_id (:id workspace))
- external-inputs (t2/select [:model/WorkspaceInputExternal :db_id :schema :table :table_id]
- :workspace_id (:id workspace))
- all-inputs (concat inputs external-inputs)
- ;; Get default schema for each database involved (both inputs and outputs).
- ;; For databases with schemas (PostgreSQL), this is the default schema (e.g., "public").
- ;; For databases without schemas (MySQL), we use the database name from connection details.
- db-ids (into #{} (map :db_id) (concat all-outputs all-inputs))
- databases (when (seq db-ids)
- (t2/select [:model/Database :id :engine :details] :id [:in db-ids]))
- db-id->default (u/index-by :id
- (fn [{:keys [engine details]}]
- (or (driver.sql/default-schema engine)
- ((some-fn :dbname :db) details)))
- databases)
- fallback-map (merge
- (table-ids-fallbacks :global_schema :global_table :global_table_id all-outputs)
- (table-ids-fallbacks :isolated_schema :isolated_table :isolated_table_id all-outputs))
- ;; Build output mappings (remap to isolated tables)
- output-map (reduce
- (fn [m {:keys [db_id global_schema global_table global_table_id
- isolated_schema isolated_table isolated_table_id]}]
- (add-table-mapping-entries m
- {:db-id db_id
- :schema global_schema
- :table global_table
- :table-id (or global_table_id
- (fallback-map [db_id global_schema global_table]))
- :replacement {:db-id db_id
- :schema isolated_schema
- :table isolated_table
- :id (or isolated_table_id
- (fallback-map [db_id isolated_schema isolated_table]))}
- :in-default-schema? (= global_schema (db-id->default db_id))}))
- {}
- all-outputs)
- ;; Build input mappings (qualify unqualified references to external tables).
- ;; For inputs, we only need to add a mapping for unqualified references (nil schema).
- ;; When the table already has an explicit schema, Macaw will preserve it as-is.
- input-map (reduce
- (fn [m {:keys [db_id schema table table_id]}]
- (let [default-schema (db-id->default db_id)]
- ;; Only add a mapping for unqualified references (nil schema).
- ;; When the table already has an explicit schema, Macaw preserves it.
- ;; Use unquoted schema here; remap-sql-source handles quoting for SQL.
- (cond-> m
- (and (nil? schema) (some? default-schema))
- (assoc [db_id nil table] {:db-id db_id
- :schema default-schema
- :table table
- :id table_id}))))
- {}
- all-inputs)
- ;; Merge with outputs taking precedence
- table-map (merge input-map output-map)]
- {:tables table-map
- ;; We never want to write to any global tables, so remap on-the-fly if we hit an un-mapped target.
- :target-fallback (fn [[d s t]]
- (log/warn "Missing remapping for" {:db d :schema s, :table t})
- {:db-id d, :schema (:schema workspace), :table (ws.u/isolated-table-name s t), :id nil})
- ;; We won't need the field-map until we support MBQL.
- :fields nil}))
-
-(defn- backfill-isolated-table-id!
- "Backfill workspace_output.isolated_table_id FK in the case where we just created the table for the first time."
- [ref-id]
- (when-let [table-id (:id (t2/query-one
- {:from [[:workspace_output :wo]]
- :join [[:metabase_table :t] [:and
- [:= :t.db_id :wo.db_id]
- [:= :t.schema :wo.isolated_schema]
- [:= :t.name :wo.isolated_table]]]
- :select [:t.id]
- :where [:and
- [:= :wo.ref_id ref-id]
- [:or [:= :wo.isolated_table_id nil] [:not= :t.id :wo.isolated_table_id]]]}))]
- (t2/update! :model/WorkspaceOutput {:ref_id ref-id} {:isolated_table_id table-id})))
-
-(defn- backfill-external-isolated-table-id!
- "Backfill workspace_output_external.isolated_table_id FK after running an enclosed external transform."
- [transform-id]
- (when-let [table-id (:id (t2/query-one
- {:from [[:workspace_output_external :woe]]
- :join [[:metabase_table :t] [:and
- [:= :t.db_id :woe.db_id]
- [:= :t.schema :woe.isolated_schema]
- [:= :t.name :woe.isolated_table]]]
- :select [:t.id]
- :where [:and
- [:= :woe.transform_id transform-id]
- [:or [:= :woe.isolated_table_id nil] [:not= :t.id :woe.isolated_table_id]]]}))]
- (t2/update! :model/WorkspaceOutputExternal {:transform_id transform-id} {:isolated_table_id table-id})))
-
-(defn- db-time
- "Returns the current timestamp from the database. Avoids timezone differences and clock skew with app server."
- []
- (:t (first (t2/query {:select [[:%now :t]]}))))
-
-(defn- node-type-id-xf
- "Create a transducer that filters nodes by type and extracts IDs."
- [node-type]
- (keep #(when (= node-type (:node-type %)) (:id %))))
-
-(defn- node-type-id-rf
- "Create a reducing function that filters nodes by type and extracts IDs."
- [node-type]
- ((node-type-id-xf node-type) conj))
-
-(defn- workspace-transform-ids
- "Extract ref-ids from nodes that are workspace transforms."
- [nodes]
- (into [] (node-type-id-xf :workspace-transform) nodes))
-
-(declare get-or-calculate-graph!)
-
-(defn upstream-nodes
- "Given a graph and a workspace transform ref-id, find all upstream nodes (all node types).
- Returns a set of {:node-type ... :id ...} maps (not including the starting node).
-
- Takes a graph with :dependencies map (child->parents) and traverses upstream."
- [graph ref-id]
- (when-let [deps-map (:dependencies graph)]
- (ws.dag/bfs-reduce deps-map [{:node-type :workspace-transform, :id ref-id}]
- :init #{}
- :rf (fn [acc entity]
- (conj acc (select-keys entity [:node-type :id]))))))
-
-(defn upstream-ids
- "Given a graph, filter node-type, and workspace transform ref-id, find upstream node IDs.
- Returns IDs of upstream nodes matching the filter-type (not including the starting node).
-
- Takes a graph with :dependencies map (child->parents) and traverses upstream."
- [graph filter-type ref-id]
- (when-let [deps-map (:dependencies graph)]
- (ws.dag/bfs-reduce deps-map [{:node-type :workspace-transform, :id ref-id}]
- :rf (node-type-id-rf filter-type))))
-
-(defn downstream-nodes
- "Given a graph and a workspace transform ref-id, find all downstream nodes (all node types).
- Returns a set of {:node-type ... :id ...} maps (not including the starting node).
-
- Takes a graph with :dependencies map (child->parents), reverses it for downstream traversal."
- [graph ref-id]
- (when-let [deps-map (:dependencies graph)]
- (let [forward-edges (ws.dag/reverse-graph deps-map)]
- (ws.dag/bfs-reduce forward-edges [{:node-type :workspace-transform, :id ref-id}]
- :init #{}
- :rf (fn [acc entity]
- (conj acc (select-keys entity [:node-type :id])))))))
-
-(defn downstream-ids
- "Given a graph, filter node-type, and workspace transform ref-id, find downstream node IDs.
- Returns IDs of downstream nodes matching the filter-type (not including the starting node).
-
- Takes a graph with :dependencies map (child->parents), reverses it for downstream traversal."
- [graph filter-type ref-id]
- (when-let [deps-map (:dependencies graph)]
- (let [forward-edges (ws.dag/reverse-graph deps-map)]
- (ws.dag/bfs-reduce forward-edges [{:node-type :workspace-transform, :id ref-id}]
- :rf (node-type-id-rf filter-type)))))
-
-(defn- any-internal-ancestor-stale?
- "Check if any in-workspace entity ancestor is stale.
- Returns true if any ancestor had its definition or input data changed since it last ran.
- Note: external transforms are not checked here, their staleness must be checked separately."
- [graph workspace ref-id]
- (when-let [ids (seq (upstream-ids graph :workspace-transform ref-id))]
- (t2/exists? :model/WorkspaceTransform
- :workspace_id (:id workspace)
- :ref_id [:in ids]
- {:where [:or
- [:= :definition_changed true]
- [:= :input_data_changed true]]})))
-
-(defn- mark-descendants-input-datastale!
- "Mark all transitive downstream workspace transforms as input_data_changed.
- Traverses the dependency graph downward from the given transform."
- [graph workspace ref-id]
- (when-let [ids (seq (downstream-ids graph :workspace-transform ref-id))]
- (t2/update! :model/WorkspaceTransform
- {:workspace_id (:id workspace)
- :ref_id [:in ids]}
- {:input_data_changed true})))
-
-(defn run-transform!
- "Execute the given workspace transform or enclosed external transform."
- ([workspace graph transform]
- (run-transform! workspace graph transform (build-remapping workspace graph)))
- ([workspace graph transform remapping]
- (let [ref-id (:ref_id transform)
- external-id (:id transform)
- start-time (db-time)
- result (try
- (ws.isolation/with-workspace-isolation
- workspace
- (ws.execute/run-transform-with-remapping transform remapping))
- (catch Exception e
- (log/errorf e "Failed to execute %s transform %s"
- (if ref-id "workspace" "external")
- (or ref-id external-id))
- {:status :failed
- :message (ex-message e)
- :start_time start-time
- :end_time (db-time)
- :table (select-keys (ws.execute/remapped-target transform remapping) [:schema :name])}))]
- ;; We don't currently keep any record of when enclosed transforms were run.
- (when ref-id
- (let [succeeded? (= :succeeded (:status result))
- pre-stale? (any-internal-ancestor-stale? graph workspace ref-id)]
- (t2/update! :model/WorkspaceTransform {:ref_id ref-id :workspace_id (:id workspace)}
- (cond-> {:last_run_at (:end_time result)
- :last_run_status (some-> (:status result) name)
- :last_run_message (:message result)}
- ;; On success, always clear definition_changed
- succeeded? (assoc :definition_changed false)
- ;; On success, clear input_data_changed only if no ancestors are stale
- (and succeeded? (not pre-stale?))
- (assoc :input_data_changed false)))
- ;; Always mark transitive downstream as stale when we run successfully
- ;; (their input data may have changed even if nothing was "stale")
- (when succeeded?
- (mark-descendants-input-datastale! graph workspace ref-id))))
- (when (= :succeeded (:status result))
- (if ref-id
- ;; Workspace transform
- (backfill-isolated-table-id! ref-id)
- ;; External transform (enclosed in workspace)
- (backfill-external-isolated-table-id! external-id)))
- result)))
-
-(defn dry-run-transform
- "Execute the given workspace transform without persisting to the target table.
- Returns the first 2000 rows of transform output for preview purposes."
- [workspace graph transform]
- (ws.isolation/with-workspace-isolation
- workspace
- (ws.execute/run-transform-preview transform (build-remapping workspace graph))))
-
-(defn execute-adhoc-query
- "Execute an arbitrary SQL query in the workspace's isolated database context.
- Applies workspace table remapping so queries can reference global table names.
- Options: :row-limit (default 2000).
- Returns a ::ws.t/query-result."
- [{db-id :database_id :as workspace} graph sql & {:as opts}]
- (ws.isolation/with-workspace-isolation
- workspace
- (ws.execute/execute-adhoc-sql db-id sql (build-remapping workspace graph) opts)))
-
-;;;; ---------------------------------------- External Transform Sync ----------------------------------------
-
-(defn- extract-external-transform-ids
- "Extract IDs of external transforms from graph entities."
- [entities]
- (into [] (comp (filter #(= :external-transform (:node-type %)))
- (map :id))
- entities))
-
-(defn- normalize-table-schema
- "Normalize a table's schema: replace nil with the driver's default schema.
- Takes a map of db_id -> default-schema for lookup."
- [db-id->default-schema {:keys [db_id schema] :as table}]
- (if (some? schema)
- table
- (assoc table :schema (get db-id->default-schema db_id))))
-
-;;;; ---------------------------------------- Epochal Versioning ----------------------------------------
-;; Two-level versioning for thread-safe graph calculation:
-;; - Transform level: analysis_version on workspace_transform, transform_version on workspace_input/workspace_output
-;; - Graph level: graph_version on workspace, workspace_graph, workspace_input_external, workspace_output_external
-
-(defn increment-graph-version!
- "Atomically increment graph_version for a workspace. Used to invalidate cached analysis."
- [workspace-id]
- (t2/update! :model/Workspace workspace-id {:graph_version [:+ :graph_version 1]}))
-
-(defn increment-analysis-version!
- "Atomically increment analysis_version for a transform. Used to invalidate cached analysis."
- [workspace-id ref-id]
- ;; definition_changed is also set by the WorkspaceTransform before-update hook when source/target changes,
- ;; but we set it here as well since this function is also called for unarchive (where source/target don't change).
- (t2/update! :model/WorkspaceTransform
- {:workspace_id workspace-id, :ref_id ref-id}
- {:analysis_version [:+ :analysis_version 1]
- :definition_changed true}))
-
-;;;; ---------------------------------------- Lazy Graph Calculation ----------------------------------------
-
-(defn- workspace-transforms
- "Return the entity values for the internal transforms."
- [ws-id]
- (t2/select-fn-vec (fn [{:keys [ref_id]}] {:entity-type :transform :id ref_id})
- [:model/WorkspaceTransform :ref_id]
- :workspace_id ws-id))
-
-(defn- calculate-graph
- "Calculate the dependency graph for a workspace.
- Returns the graph without caching - caller is responsible for caching."
- [ws-id]
- (ws.dag/path-induced-subgraph ws-id (workspace-transforms ws-id)))
-
-(defn- cleanup-old-transform-versions!
- "Delete obsolete analysis for a given workspace transform."
- [ws-id ref-id]
- (doseq [model [:model/WorkspaceOutput :model/WorkspaceInputTransform]]
- (t2/delete! model
- :workspace_id ws-id
- :ref_id ref-id
- ;; Use a subselect to avoid left over gunk from race conditions.
- {:where [:< :transform_version {:select [:analysis_version]
- :from [:workspace_transform]
- :where [:and
- [:= :workspace_id ws-id]
- [:= :ref_id ref-id]]}]})))
-
-(defn- cleanup-old-graph-versions!
- "Delete obsolete graph-level rows."
- [ws-id]
- (doseq [model [:model/WorkspaceGraph
- :model/WorkspaceInputExternal
- :model/WorkspaceOutputExternal]]
- (t2/delete! model
- :workspace_id ws-id
- ;; Use a subselect to avoid left over gunk from race conditions.
- {:where [:< :graph_version {:select [:graph_version]
- :from [:workspace]
- :where [:= :id ws-id]}]})))
-
-(defn- analyze-transform!
- "Analyze a transform and write its outputs/inputs with the given transform_version.
- Called when the transform's output doesn't exist for current analysis_version."
- [{ws-id :id, isolated-schema :schema :as _workspace}
- {:keys [ref_id analysis_version] :as transform}]
- (let [analysis (ws.deps/analyze-entity :transform transform)]
- (ws.deps/write-entity-analysis! ws-id isolated-schema :transform ref_id analysis analysis_version)
- (cleanup-old-transform-versions! ws-id ref_id)))
-
-(defn- analyze-stale-transforms!
- "Analyze transforms where workspace_output doesn't exist for current analysis_version.
- Skips transforms that haven't changed since last analysis.
- Returns true if any transforms were analyzed."
- [{ws-id :id, db-status :db_status :as workspace}]
- ;; Find transforms needing analysis: those without output at current analysis_version
- (let [stale-transforms (t2/select :model/WorkspaceTransform
- ;; Ordering is only for determinism in tests.
- {:order-by [:updated_at]
- :where [:and
- [:= :workspace_transform.workspace_id ws-id]
- [:not [:exists
- {:select [1]
- :from [[:workspace_output :wo]]
- :where [:and
- [:= :wo.workspace_id ws-id]
- [:= :wo.ref_id :workspace_transform.ref_id]
- [:= :wo.transform_version
- :workspace_transform.analysis_version]]}]]]})]
- ;; Analyze each stale transform
- (doseq [transform stale-transforms]
- (analyze-transform! workspace transform))
- ;; Grant any missing read access. Do this even if no transforms were stale, as we may have been unable to grant
- ;; some permissions previously (insufficient permissions, table didn't exist yet, etc.)
- (when (= :ready db-status)
- (grant-accesses-if-superuser! workspace))
- (boolean (seq stale-transforms))))
-
-(defn analyze-transform-if-stale!
- "Analyze a single transform if its workspace_output doesn't exist for current analysis_version.
- Used before running a transform to ensure grants are up-to-date."
- [{ws-id :id :as workspace} {:keys [ref_id analysis_version] :as transform}]
- (when-not (ws.deps/transform-output-exists-for-version? ws-id ref_id analysis_version)
- (analyze-transform! workspace transform)
- (grant-accesses-if-superuser! workspace)))
-
-(defn- insert-workspace-graph!
- "Insert a new graph for the given version. Silently ignores constraint violations
- from concurrent inserts (another process already inserted this version)."
- [ws-id graph-version graph]
- (when-not (t2/exists? :model/WorkspaceGraph
- :workspace_id ws-id
- :graph_version [:>= graph-version])
- (ws.u/ignore-constraint-violation
- (t2/insert! :model/WorkspaceGraph
- {:workspace_id ws-id
- :graph_version graph-version
- :graph graph}))))
-
-(defn- insert-external-outputs-for-version!
- "Sync workspace_output_external for a specific graph version.
- Creates new rows with graph_version set. Silently ignores constraint violations."
- [workspace-id isolated-schema entities graph-version]
- (when-not (t2/exists? :model/WorkspaceOutputExternal :workspace_id workspace-id :graph_version [:>= graph-version])
- (let [external-tx-ids (extract-external-transform-ids entities)]
- (when (seq external-tx-ids)
- ;; There are 4N + 3 queries for N transforms, we may want to optimize...
- ;; 1 exists
- ;; + 1 select
- ;; + N × 2 upsert-transform-target-table! (2 queries each)
- ;; + 1 batch insert
- ;; Worst case 8N + 3 on concurrent upsert conflicts.
- (let [transforms (t2/select [:model/Transform :id :target] :id [:in external-tx-ids])
- rows (for [{tx-id :id, {:keys [database schema name]} :target} transforms]
- (let [isolated-table (ws.u/isolated-table-name schema name)
- global-table-id (table/upsert-transform-target-table! database schema name)
- isolated-table-id (table/upsert-transform-target-table! database isolated-schema isolated-table)]
- {:workspace_id workspace-id
- :transform_id tx-id
- :graph_version graph-version
- :db_id database
- :global_schema schema
- :global_table name
- :global_table_id global-table-id
- :isolated_schema isolated-schema
- :isolated_table isolated-table
- :isolated_table_id isolated-table-id}))]
- (when (seq rows)
- (ws.u/ignore-constraint-violation
- (t2/insert! :model/WorkspaceOutputExternal rows))))))))
-
-(defn- insert-external-inputs-for-version!
- "Write `workspace_input_external` for a specific graph version, unless they (or a new version) already have been."
- [workspace-id entities graph-version]
- (when-not (t2/exists? :model/WorkspaceInputExternal :workspace_id workspace-id :graph_version [:>= graph-version])
- (let [external-tx-ids (extract-external-transform-ids entities)]
- (when (seq external-tx-ids)
- (let [input-tables (t2/select [:model/Dependency :to_entity_id]
- :from_entity_type :transform
- :from_entity_id [:in external-tx-ids]
- :to_entity_type :table)
- input-table-ids (into #{} (map :to_entity_id) input-tables)
- ;; Get workspace output table IDs (both workspace and external outputs)
- workspace-output-ids (t2/select-fn-set :global_table_id
- [:model/WorkspaceOutput :global_table_id]
- :workspace_id workspace-id
- {:where [:not= :global_table_id nil]})
- external-output-ids (t2/select-fn-set :global_table_id
- [:model/WorkspaceOutputExternal :global_table_id]
- :workspace_id workspace-id
- :graph_version graph-version
- {:where [:not= :global_table_id nil]})
- all-output-ids (set/union workspace-output-ids external-output-ids)
- external-input-ids (set/difference input-table-ids all-output-ids)]
- (when (seq external-input-ids)
- (let [tables (t2/select [:model/Table :id :db_id :schema :name] :id [:in external-input-ids])
- db-ids (into #{} (map :db_id) tables)
- db-id->default-schema (when (seq db-ids)
- (into {}
- (map (fn [{:keys [id engine]}]
- [id (driver.sql/default-schema engine)]))
- (t2/select [:model/Database :id :engine] :id [:in db-ids])))
- normalized-tables (map (partial normalize-table-schema db-id->default-schema) tables)]
- (when (seq normalized-tables)
- (ws.u/ignore-constraint-violation
- (t2/insert! :model/WorkspaceInputExternal
- (for [{:keys [id db_id schema name]} normalized-tables]
- {:workspace_id workspace-id
- :graph_version graph-version
- :db_id db_id
- :schema schema
- :table name
- :table_id id
- :access_granted false})))))))))))
-
-(defn- fully-persisted-graph
- "Fetch the latest graph for which all the related tables have all been populated, that meets a minimum version.
- Returns nil if no sufficiently recent graph, with all its derivatives persisted, exists.
- It uses a subselect to avoid races where the latest version could be superseded and deleted before we can fetch it."
- [ws-id min-version]
- (t2/select-one-fn :graph
- [:model/WorkspaceGraph :graph]
- :workspace_id ws-id
- :graph_version [:>= min-version]
- {:order-by [[:workspace_graph.graph_version :desc]]
- :limit 1}))
-
-(defn- graph-with-minimum-version
- "Fetch the latest graph (and its version) that meets a minimum version constraint."
- [ws-id min-version]
- (t2/select-one [:model/WorkspaceGraph :graph [:graph_version :version]]
- :workspace_id ws-id
- {:where [:>= :workspace_graph.graph_version min-version]
- :order-by [[:workspace_graph.graph_version :desc]]
- :limit 1}))
-
-(defn- calculate-and-persist-graph!
- "Return a graph for version > min-version.
-
- Non-blocking implementation that uses epochal steps to avoid co-ordination while providing workable consistency.
- If at any step we find results for a later version, we proceed to calculating (if necessary) that version.
- In the best case, we find complete results for the latest version and simply return them, without any computation.
-
- The analysis is computed in various stages, and written to the following tables in the given order:
-
- 1. workspace_input (per tx)
- 2. workspace_output (per tx, marks that we're done for that tx)
- 3. workspace_graph
- 4. workspace_input_external
- 5. workspace_output_external
-
- Returns the graph."
- [{ws-id :id, isolated-schema :schema :as workspace} min-version]
- ;; Analyze transforms that need it (transform-level versioning)
- ;; This writes workspace_input and workspace_output.
- (analyze-stale-transforms! workspace)
- ;; See if there's already a computed graph we can use, otherwise compute a new one.
- (let [{:keys [graph version]} (graph-with-minimum-version ws-id min-version)
- graph (or graph
- ;; Note that we can't freeze the versions of the transform's input and outputs, used to
- ;; calculate the graph, they don't use the same version numbering.
- ;; Instead, it will use the latest version across its various reads.
- ;; This means the graph is only eventually consistent - it doesn't have snapshot consistency
- ;; across the reads we make to the transforms. There are perverse cases where this can lead
- ;; to cycles or other data defects. Since such a graph will itself be stale, we will recover
- ;; from those defects on the next read.
- (u/prog1 (calculate-graph ws-id)
- (insert-workspace-graph! ws-id min-version <>)))
- version (or version min-version)
- ;; Write workspace_input_external if needed, bump version if we have been overtaken.
- _ (insert-external-inputs-for-version! ws-id (:entities graph) version)
- ;; Write workspace_output_external if needed, bump version if we have been overtaken.
- _ (insert-external-outputs-for-version! ws-id isolated-schema (:entities graph) version)]
- (log/debugf "Have graph for workspace %d at version %d (target was %d)" ws-id version min-version)
- ;; Discard any obsolete rows (including our own, if we've been overtaken)
- (cleanup-old-graph-versions! ws-id)
- ;; If there's an even more recent version in the database now, return that.
- ;; This decreases the chance of returning a graph with transient corruption.
- (or (graph-with-minimum-version ws-id (inc version)) graph)))
-
-(defn- fetch-staleness-map
- "Fetch staleness flags for workspace transforms from the database.
- Returns a map of ref-id -> {:definition_changed bool, :input_data_changed bool}.
- Only fetches rows where at least one flag is true; callers can rely on nil-punning
- for missing entries (missing = not stale)."
- [ws-id ref-ids]
- (when (seq ref-ids)
- (t2/select-fn->fn :ref_id #(select-keys % [:definition_changed :input_data_changed])
- :model/WorkspaceTransform
- :workspace_id ws-id
- :ref_id [:in ref-ids]
- {:where [:or
- [:= :definition_changed true]
- [:= :input_data_changed true]]})))
-
-(defn- workspace-transform? [entity]
- (= :workspace-transform (:node-type entity)))
-
-(defn- external-transform? [entity]
- (= :external-transform (:node-type entity)))
-
-(defn- transform? [entity]
- (#{:workspace-transform :external-transform} (:node-type entity)))
-
-(defn annotate-staleness
- "Annotate graph entities with transitive staleness given a staleness-map.
- An entity is stale if:
- - Its definition_changed is true (definition changed since last run), OR
- - Its input_data_changed is true (input data changed since last run), OR
- - Any of its ancestors are stale (transitively)
-
- Takes a graph and a staleness-map: {entity-id -> {:definition_changed bool, :input_data_changed bool}}
- Returns updated graph with :stale, :definition_changed, :input_data_changed on each transform entity.
-
- This propagates staleness down the graph using a BFS from all initially stale nodes.
- Both workspace transforms and external transforms are marked as stale so they can be
- executed in the correct toposorted order."
- [graph staleness-map]
- (let [locally-stale? (fn [entity]
- (let [staleness (get staleness-map (:id entity))]
- (or (:definition_changed staleness)
- (:input_data_changed staleness))))
- init-stale (filter (every-pred workspace-transform? locally-stale?)
- (:entities graph))
- forward-edges (some-> (:dependencies graph) ws.dag/reverse-graph)
- ;; BFS traverses through ALL nodes (including external transforms) to find all stale transforms
- all-reachable (if forward-edges
- (ws.dag/bfs-reduce forward-edges init-stale :include-start? true :init #{})
- (set init-stale))
- ;; Include both workspace and external transforms in the stale set
- all-stale (set (filter transform? all-reachable))
- annotate (fn [entity]
- (cond
- (workspace-transform? entity)
- (-> entity
- (merge (get staleness-map (:id entity)
- {:definition_changed false :input_data_changed false}))
- (assoc :stale (contains? all-stale entity)))
-
- (external-transform? entity)
- (assoc entity :stale (contains? all-stale entity))
-
- :else
- entity))]
- (update graph :entities #(mapv annotate %))))
-
-(defn with-staleness
- "Annotate graph entities with transitive staleness.
- Takes a workspace and a graph, fetches staleness from the database, and annotates the graph.
- Returns updated graph with :stale, :definition_changed, :input_data_changed on each workspace transform entity.
-
- Use `annotate-staleness` directly if you already have a staleness-map."
- [{ws-id :id} graph]
- (let [staleness-map (->> (:entities graph) workspace-transform-ids (fetch-staleness-map ws-id))]
- (annotate-staleness graph staleness-map)))
-
-(defn get-or-calculate-graph!
- "Return the dependency graph for a workspace.
- Uses cached graph if version matches, otherwise recalculates it.
- Thread-safe via epochal versioning.
- Also syncs workspace_output_external and workspace_input_external tables when recalculating.
-
- Use `with-staleness` to annotate the graph with transitive staleness."
- [{ws-id :id, graph-version :graph_version :as workspace}]
- (or (fully-persisted-graph ws-id graph-version)
- (calculate-and-persist-graph! workspace graph-version)))
-
-(defn- entities->transforms
- "Given a workspace-id and a sequence of graph entities, fetch the corresponding transform records.
- Returns transforms in the same order as the input entities."
- [ws-id entities]
- (let [type->ids (u/group-by :node-type :id entities)
- id->tx (merge
- {}
- (when-let [ids (seq (type->ids :external-transform))]
- (t2/select-fn->fn :id identity
- [:model/Transform :id :name :source :target]
- :id [:in ids]))
- (when-let [ref-ids (seq (type->ids :workspace-transform))]
- (t2/select-fn->fn :ref_id identity
- [:model/WorkspaceTransform :ref_id :name :source :target]
- :workspace_id ws-id
- :ref_id [:in ref-ids])))]
- (keep (comp id->tx :id) entities)))
-
-(defn- transforms-to-execute
- "Given a workspace, graph, and an optional filter, return the global and workspace definitions to run, in order."
- [{ws-id :id :as workspace} graph & {:keys [stale-only?]}]
- (let [graph (cond->> graph
- stale-only? (with-staleness workspace))
- entities (cond->> (:entities graph)
- stale-only? (filter :stale))]
- (entities->transforms ws-id entities)))
-
-(defn- id->str [ref-id-or-id]
- (if (string? ref-id-or-id)
- ref-id-or-id
- (str "global-id:" ref-id-or-id)))
-
-(defn- ungranted-transform-ref-ids
- "Return the set of workspace transform ref-ids that have at least one ungranted input
- at their current (max) transform version. str/trim is needed because ref_id is char(36)
- which pads with trailing spaces."
- [ws-id]
- (into #{}
- (map (comp str/trim :ref_id))
- (t2/query {:select-distinct [:wit.ref_id]
- :from [[:workspace_input_transform :wit]]
- :join [[:workspace_input :wi]
- [:= :wi.id :wit.workspace_input_id]]
- :where [:and
- [:= :wit.workspace_id ws-id]
- [:= :wi.access_granted false]
- [:= :wit.transform_version
- {:select [[:%max.transform_version]]
- :from [[:workspace_input_transform :wit2]]
- :where [:and
- [:= :wit2.workspace_id ws-id]
- [:= :wit2.ref_id :wit.ref_id]]}]]})))
-
-(defn- ungranted-external-transform-ids
- "Return the set of external transform IDs (integers) that have at least one ungranted external input.
- Joins workspace_input_external (ungranted tables) with the dependency table to find which
- external transforms depend on those tables."
- [ws-id]
- (into #{}
- (map :from_entity_id)
- (t2/query {:select-distinct [:d.from_entity_id]
- :from [[:workspace_input_external :wie]]
- :join [[:dependency :d]
- [:and
- [:= :d.to_entity_type "table"]
- [:= :d.to_entity_id :wie.table_id]
- [:= :d.from_entity_type "transform"]]]
- :where [:and
- [:= :wie.workspace_id ws-id]
- [:= :wie.access_granted false]
- [:not= :wie.table_id nil]]})))
-
-(defn execute-workspace!
- "Execute all the transforms within a given workspace.
- Skips transforms whose inputs have not been granted access."
- [workspace graph & {:keys [stale-only?] :or {stale-only? false}}]
- (let [ws-id (:id workspace)
- remapping (build-remapping workspace graph)
- ungranted-ref-ids (ungranted-transform-ref-ids ws-id)
- ungranted-external-tx-ids (ungranted-external-transform-ids ws-id)]
- (reduce
- (fn [acc {external-id :id ref-id :ref_id :as transform}]
- (let [node-type (if external-id :external-transform :workspace-transform)
- id-str (id->str (or external-id ref-id))]
- (if (or (and ref-id (contains? ungranted-ref-ids ref-id))
- (and external-id (contains? ungranted-external-tx-ids external-id)))
- (update acc :not_run conj id-str)
- (try
- (if (= :succeeded (:status (run-transform! workspace graph transform remapping)))
- (update acc :succeeded conj id-str)
- (update acc :failed conj id-str))
- (catch Exception e
- (log/error e "Failed to execute transform" {:workspace-id ws-id :node-type node-type :id id-str})
- (update acc :failed conj id-str))))))
- {:succeeded []
- :failed []
- :not_run []}
- (transforms-to-execute workspace graph {:stale-only? stale-only?}))))
-
-(defn- stale-ancestors-to-execute
- "Given a workspace, graph, and target ref-id, return the stale ancestor transforms to run, in dependency order.
- Only returns transforms that are both ancestors of the target AND stale.
- Includes both workspace transforms and external transforms in the ancestor chain."
- [{ws-id :id} graph ref-id]
- (let [ancestor-keys (upstream-nodes graph ref-id)
- ancestor? (fn [entity] (contains? ancestor-keys (select-keys entity [:node-type :id])))
- ancestor-entities (filter ancestor? (:entities graph))
- ;; Build a subgraph with only ancestor entities and their inter-dependencies
- ;; Dependencies map is keyed by entities (maps with :id), not by IDs directly
- ancestor-deps (into {}
- (keep (fn [[to-entity from-list]]
- (when (ancestor? to-entity)
- [to-entity (filterv ancestor? from-list)]))
- (:dependencies graph)))
- ancestor-graph {:entities ancestor-entities
- :dependencies ancestor-deps}
- ;; Only fetch staleness for ancestors, not the entire graph
- ancestor-ref-ids (workspace-transform-ids ancestor-entities)
- staleness-map (fetch-staleness-map ws-id ancestor-ref-ids)
- annotated-graph (annotate-staleness ancestor-graph staleness-map)
- stale-entities (filter :stale (:entities annotated-graph))]
- (entities->transforms ws-id stale-entities)))
-
-(defn run-stale-ancestors!
- "Run all stale ancestors of a given transform in dependency order.
- Stops on first failure, marking remaining transforms as not_run.
- Returns a map with :succeeded, :failed, and :not_run lists of ref-ids/transform-ids."
- [workspace graph ref-id]
- (let [ws-id (:id workspace)
- remapping (build-remapping workspace graph)]
- (reduce
- (fn [acc {external-id :id tx-ref-id :ref_id :as transform}]
- (let [node-type (if external-id :external-transform :workspace-transform)
- id-str (id->str (or external-id tx-ref-id))]
- (if (seq (:failed acc))
- ;; Skip execution if any previous transform failed
- (update acc :not_run conj id-str)
- (let [result (try
- (run-transform! workspace graph transform remapping)
- (catch Exception e
- {:status :failed
- :message (ex-message e)
- :error e}))]
- (if (= :succeeded (:status result))
- (update acc :succeeded conj id-str)
- (let [log-data {:workspace-id ws-id :node-type node-type :id id-str :result (dissoc result :error)}]
- (if-let [e (:error result)]
- (log/error e "Failed to execute ancestor transform" log-data)
- (log/error "Failed to execute ancestor transform" log-data))
- (update acc :failed conj id-str)))))))
- {:succeeded []
- :failed []
- :not_run []}
- (stale-ancestors-to-execute workspace graph ref-id))))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/init.clj b/enterprise/backend/src/metabase_enterprise/workspaces/init.clj
deleted file mode 100644
index 8df0afcb37b..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/init.clj
+++ /dev/null
@@ -1,10 +0,0 @@
-(ns metabase-enterprise.workspaces.init
- "Initialize workspace models. Driver workspace isolation methods are now
- defined directly in the driver files."
- (:require
- [metabase-enterprise.workspaces.events]
- [metabase-enterprise.workspaces.models.workspace]
- [metabase-enterprise.workspaces.models.workspace-graph]
- [metabase-enterprise.workspaces.models.workspace-transform]
- [metabase-enterprise.workspaces.scope]
- [metabase-enterprise.workspaces.settings]))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/isolation.clj b/enterprise/backend/src/metabase_enterprise/workspaces/isolation.clj
deleted file mode 100644
index 295415d2345..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/isolation.clj
+++ /dev/null
@@ -1,54 +0,0 @@
-(ns metabase-enterprise.workspaces.isolation
- "Workspace database isolation functions.
-
- The actual driver-specific implementations are now in the driver files:
- - metabase.driver.h2
- - metabase.driver.postgres
- - metabase.driver.redshift
- - metabase.driver.snowflake
- - metabase.driver.sqlserver
- - metabase.driver.clickhouse
- - metabase.driver.bigquery-cloud-sdk
-
- This namespace provides the public API for workspace isolation."
- (:require
- [metabase.driver :as driver]
- [metabase.driver.connection.workspaces :as driver.w]
- [metabase.driver.util :as driver.u]))
-
-;;;; Delegation to driver methods
-;; The actual multimethod implementations are now in the individual driver files.
-;; These functions dispatch through the driver multimethods.
-
-(defn grant-read-access-to-tables!
- "Grant read access to these tables.
- Delegates to driver/grant-workspace-read-access!"
- [database workspace tables]
- (driver/grant-workspace-read-access! (driver.u/database->driver database) database workspace tables))
-
-(defn destroy-workspace-isolation!
- "Destroy all database resources created for workspace isolation.
- This includes dropping tables, schemas/databases, users, roles, and logins.
- Fails fast on first error. Should be called when deleting a workspace.
- Delegates to driver/destroy-workspace-isolation!"
- [database workspace]
- (driver/destroy-workspace-isolation! (driver.u/database->driver database) database workspace))
-
-;;;; Public API
-
-(defn ensure-database-isolation!
- "Wrapper around the driver method, to make migrations easier in future."
- [workspace database]
- (driver/init-workspace-isolation! (driver.u/database->driver database) database workspace))
-
-(defn do-with-workspace-isolation
- "Impl of* with-workspace-isolation*."
- [workspace thunk]
- (driver.w/with-swapped-connection-details (:database_id workspace)
- (:database_details workspace)
- (thunk)))
-
-(defmacro with-workspace-isolation
- "Execute body with necessary isolation."
- [workspace & body]
- `(do-with-workspace-isolation ~workspace (fn [] ~@body)))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/merge.clj b/enterprise/backend/src/metabase_enterprise/workspaces/merge.clj
deleted file mode 100644
index 4630678bcf2..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/merge.clj
+++ /dev/null
@@ -1,128 +0,0 @@
-(ns metabase-enterprise.workspaces.merge
- "Update global entities based on the definitions within a workspace.
- All functions assumes that validation of the dependencies AFTER merge is done BEFORE calling any of these methods."
- (:require
- [metabase-enterprise.workspaces.models.workspace-merge]
- [metabase-enterprise.workspaces.models.workspace-merge-transform]
- [metabase-enterprise.workspaces.types :as ws.types]
- [metabase.transforms.core :as transforms.api]
- [metabase.util.malli :as mu]
- [toucan2.core :as t2])
- (:import (java.sql Connection)))
-
-(set! *warn-on-reflection* true)
-
-(defn- create-merge-transform-history!
- "Create a workspace_merge_transform record to track this merge operation.
- Does nothing for :noop operations (archived transforms that don't exist globally)
- or :delete operations (history would be CASCADE deleted with the transform anyway)."
- [op merge-map]
- (when (#{:create :update} op)
- (t2/insert! :model/WorkspaceMergeTransform merge-map)))
-
-(mu/defn merge-transform! :- [:map
- [:op [:enum :create :delete :noop :update]]
- [:ref_id ::ws.types/ref-id]
- [:global_id {:optional true} [:maybe ::ws.types/appdb-id]]
- [:error {:optional true} :any]]
- "Make the given transform in the Changeset public, i.e. create or update the relevant model/Transform entities.
- This should also clear it out from the Changset, as it no longer has any changes.
-
- Creates a WorkspaceMergeTransform history record.
- - :ws-transform - The workspace transform to merge
- - :workspace - The workspace map (must have :id and :name keys)
- - :workspace-merge-id - ID of parent WorkspaceMerge (caller must create this)
- - :merging-user-id - user performing the merge
- - :commit-message - description of the merge"
- [{:keys [ws-transform workspace workspace-merge-id merging-user-id commit-message]}]
- ;; Problems this may run into:
- ;; It will recalculate and validate the dag greedily as it inserts each items, and this might fail of temporary conflicts.
- ;; Some of these conflicts could be solved by ordering things smartly, but in the general case (e.g. reversing a
- ;; chain) this will not be possible - we would need to defer all validation and calculation, which is a bit scary.
- ;; Let's just focus on the happy path for now though, as this is a fundamental problem and unrelated to the design.
- (let [{:keys [global_id ref_id archived_at]} ws-transform
- {:keys [error] :as result}
- (cond (and global_id archived_at)
- (merge
- {:op :delete :global_id global_id :ref_id ref_id}
- (try
- (transforms.api/delete-transform! (t2/select-one :model/Transform :id global_id))
- nil
- (catch Throwable e
- {:error e})))
-
- global_id
- (merge
- {:op :update :global_id global_id :ref_id ref_id}
- (try
- (transforms.api/update-transform!
- global_id (select-keys ws-transform [:name :description :source :target]))
- nil
- (catch Throwable e
- {:error e})))
-
- archived_at
- {:op :noop :global_id nil :ref_id ref_id}
-
- :else
- (merge
- {:op :create :global_id nil :ref_id ref_id}
- (try
- {:global_id (:id (transforms.api/create-transform!
- (select-keys ws-transform [:name :description :source :target])
- (:creator_id ws-transform)))}
- (catch Throwable e
- {:error e}))))]
-
- (when-not error
- ;; See https://linear.app/metabase/issue/GDGT-1591/merging-a-workspace-removes-transforms-from-it
- ;; Keeping this stub as we may want to revisit it in the future.
- #_(t2/delete! :model/WorkspaceTransform :workspace_id (:id workspace) :ref_id ref_id)
- (create-merge-transform-history!
- (:op result)
- {:workspace_merge_id workspace-merge-id
- :workspace_id (:id workspace)
- :workspace_name (:name workspace)
- :transform_id (:global_id result)
- :commit_message commit-message
- :merging_user_id merging-user-id}))
-
- result))
-
-(defn merge-workspace!
- "Make all the transforms in the Changeset public, i.e. create or update the relevant model/Transform entities.
-
- - workspace: The workspace map (must have :id and :name keys)
- - merging-user-id: user performing the merge
- - commit-message: description of the merge"
- [workspace merging-user-id commit-message]
- ;; Perhaps we want to solve the N+1?
- ;; This will require reworking the lifecycle for validating and recalculating dependencies for the transforms.
- (t2/with-transaction [tx]
- (let [savepoint (.setSavepoint ^Connection tx)
- ws-merge-id (t2/insert-returning-pk!
- :model/WorkspaceMerge
- {:workspace_id (:id workspace)
- :workspace_name (:name workspace)
- :commit_message commit-message
- :creator_id merging-user-id})
- result (reduce
- (fn [acc ws-transform]
- (let [{:keys [error] :as result} (merge-transform! {:ws-transform ws-transform
- :workspace workspace
- :workspace-merge-id ws-merge-id
- :merging-user-id merging-user-id
- :commit-message commit-message})]
- (if error
- (reduced (-> acc
- (update :errors conj result)
- (assoc-in [:merged :transforms] [])))
- (update-in acc [:merged :transforms] conj result))))
- {:merged {:transforms []}
- :errors []}
- (t2/select :model/WorkspaceTransform :workspace_id (:id workspace)
- ;; Deterministic ordering; ref_id breaks created_at ties
- {:order-by [[:created_at :asc] [:ref_id :asc]]}))]
- (when (seq (:errors result))
- (.rollback ^Connection tx savepoint))
- result)))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace.clj
deleted file mode 100644
index b238bcbaab7..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace.clj
+++ /dev/null
@@ -1,105 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace
- (:require
- [metabase-enterprise.workspaces.impl :as ws.impl]
- [metabase-enterprise.workspaces.isolation :as ws.isolation]
- [metabase.models.interface :as mi]
- [metabase.util.log :as log]
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-;; NOTE: The `workspace` table still has an `execution_user` column in the DB. This was used by the service-user
-;; mechanism removed in c42c2ef1f20. It is no longer read or written by any code, but remains because the associated
-;; CoreUser rows may own dependent resources (e.g. transforms) that would cascade on delete.
-;; The `api_key_id` column and its associated API key rows were cleaned up in migration v60.2026-03-07.
-
-(methodical/defmethod t2/table-name :model/Workspace [_model] :workspace)
-
-(def ^:private base-statuses
- "Set of valid base_status values, representing the synchronous lifecycle."
- #{:empty :active :archived})
-
-(def ^:private db-statuses
- "Set of valid db_status values, representing the status of the data warehouse."
- #{:uninitialized :pending :ready :broken})
-
-(t2/deftransforms :model/Workspace
- {:database_details mi/transform-encrypted-json
- :base_status (mi/transform-validator mi/transform-keyword (partial mi/assert-enum base-statuses))
- :db_status (mi/transform-validator mi/transform-keyword (partial mi/assert-enum db-statuses))})
-
-(defn computed-status
- "Compute backwards-compatible status from base_status and db_status.
- Returns :archived if workspace is archived, otherwise returns db_status."
- [{:keys [base_status db_status]}]
- (case base_status
- :empty :uninitialized
- :archived :archived
- db_status))
-
-(doto :model/Workspace
- (derive :metabase/model)
- (derive :hook/timestamped?))
-
-(defn archive!
- "Archive a workspace. Destroys database isolation resources (best-effort), revokes access grants,
- sets base_status to :archived and db_status to :uninitialized.
- Cleanup failures are logged but don't block archiving - the workspace can be unarchived to retry cleanup,
- or deleted once the underlying permission issues are resolved."
- [{workspace-id :id :as workspace}]
- (let [database (t2/select-one :model/Database :id (:database_id workspace))
- ;; Best-effort cleanup - don't block archiving on cleanup failures
- ;; Only destroy isolation if workspace was initialized (not uninitialized db_status)
- cleaned? (when (not= :uninitialized (:db_status workspace))
- (try
- (ws.isolation/destroy-workspace-isolation! database workspace)
- true
- (catch Exception e
- (log/warnf e "Failed to cleanup isolation resources for workspace %s, proceeding with archive" workspace-id)
- false)))]
- ;; Mark all inputs as un-granted since the user *may* have been dropped (even if there were some failures)
- (t2/update! :model/WorkspaceInput {:workspace_id workspace-id}
- {:access_granted false})
- ;; Update workspace status and increment graph_version (will need recalculation on unarchive)
- (t2/update! :model/Workspace workspace-id
- {:base_status :archived
- :db_status (if cleaned? :uninitialized :broken)
- :graph_version [:+ :graph_version 1]})))
-
-(defn unarchive!
- "Unarchive a workspace. If workspace has transforms, re-initializes database isolation resources,
- re-grants read access to source tables, and sets base_status to :active with db_status :ready.
- If workspace is empty (no transforms), sets base_status to :empty and leaves db_status as :uninitialized."
- [workspace]
- (let [workspace-id (:id workspace)
- has-transforms? (t2/exists? :model/WorkspaceTransform :workspace_id workspace-id)]
- ;; Delete old graph data - will be recalculated
- (t2/delete! :model/WorkspaceGraph :workspace_id workspace-id)
- (if has-transforms?
- ;; Workspace has transforms - re-initialize database isolation
- (let [database (t2/select-one :model/Database (:database_id workspace))
- isolation-result (ws.isolation/ensure-database-isolation! workspace database)
- ;; Update workspace status and increment graph_version for recalculation
- _ (t2/update! :model/Workspace workspace-id
- (merge {:base_status :active
- :db_status :ready
- :graph_version [:+ :graph_version 1]}
- (select-keys isolation-result [:schema :database_details])))
- ;; Re-fetch workspace to get updated database_details and schema for granting permissions
- updated-ws (t2/select-one :model/Workspace workspace-id)]
- ;; Re-grant read access to source tables (inputs were marked un-granted during archive)
- (ws.impl/sync-grant-accesses! updated-ws))
- ;; Workspace is empty - just set to empty status
- (t2/update! :model/Workspace workspace-id {:base_status :empty}))))
-
-(defn delete!
- "Delete a workspace. Destroys database isolation resources and deletes the workspace."
- [workspace]
- ;; Only destroy isolation if workspace was initialized
- (when (not= :uninitialized (:db_status workspace))
- (when-let [database (t2/select-one :model/Database :id (:database_id workspace))]
- (try
- (ws.isolation/destroy-workspace-isolation! database workspace)
- (catch Exception _))
- (t2/update! :model/WorkspaceInput {:workspace_id (:id workspace)}
- {:access_granted false})))
- (t2/delete! :model/Workspace (:id workspace)))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_graph.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_graph.clj
deleted file mode 100644
index 7888cb25471..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_graph.clj
+++ /dev/null
@@ -1,50 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-graph
- "Model for cached workspace dependency graphs."
- (:require
- [metabase.models.interface :as mi]
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-(methodical/defmethod t2/table-name :model/WorkspaceGraph [_model] :workspace_graph)
-
-;; The graph structure contains :dependencies with map keys that need special handling.
-;; We use a custom transform that converts map keys to/from association lists.
-
-(defn- graph-out
- "Transform graph from DB (JSON string) to Clojure data.
- Converts :dependencies association list back to a map with proper keys."
- [graph-json]
- (when graph-json
- (let [graph (mi/json-out-with-keywordization graph-json)]
- (-> graph
- (update :dependencies (fn [assoc-list]
- (into {} (map (fn [[k vs]]
- [(update k :node-type keyword)
- (mapv #(update % :node-type keyword) vs)])
- assoc-list))))
- (update :entities (fn [entities]
- (mapv #(update % :node-type keyword) entities)))
- (update :inputs #(or % []))
- (update :outputs #(or % []))))))
-
-(defn- graph-in
- "Transform graph from Clojure data to DB (JSON string).
- Converts :dependencies map to association list since JSON can't have map keys."
- [graph]
- (when graph
- (-> graph
- (update :dependencies (fn [deps]
- (mapv (fn [[k vs]]
- [(select-keys k [:node-type :id])
- (mapv #(select-keys % [:node-type :id]) vs)])
- deps)))
- (update :entities (fn [entities]
- (mapv #(select-keys % [:node-type :id]) entities)))
- mi/json-in)))
-
-(t2/deftransforms :model/WorkspaceGraph
- {:graph {:in graph-in :out graph-out}})
-
-(doto :model/WorkspaceGraph
- (derive :metabase/model)
- (derive :hook/timestamped?))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_input.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_input.clj
deleted file mode 100644
index ca98507d05b..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_input.clj
+++ /dev/null
@@ -1,13 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-input
- "Model for WorkspaceInput - unique external tables that workspace transforms consume.
- Each row represents a unique (workspace_id, db_id, schema, table) tuple.
- The m2m relationship to transforms is in workspace_input_transform."
- (:require
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-(methodical/defmethod t2/table-name :model/WorkspaceInput [_model] :workspace_input)
-
-(doto :model/WorkspaceInput
- (derive :metabase/model)
- (derive :hook/timestamped?))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_input_external.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_input_external.clj
deleted file mode 100644
index 554e27e21ad..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_input_external.clj
+++ /dev/null
@@ -1,11 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-input-external
- "Model for WorkspaceInputExternal - external tables that enclosed external transforms consume."
- (:require
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-(methodical/defmethod t2/table-name :model/WorkspaceInputExternal [_model] :workspace_input_external)
-
-(doto :model/WorkspaceInputExternal
- (derive :metabase/model)
- (derive :hook/timestamped?))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_input_transform.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_input_transform.clj
deleted file mode 100644
index 594db8120fa..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_input_transform.clj
+++ /dev/null
@@ -1,15 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-input-transform
- "Model for WorkspaceInputTransform - join table linking workspace inputs to the transforms that depend on them.
- Each row associates a unique input table (in workspace_input) with a specific transform version."
- (:require
- [metabase.models.interface :as mi]
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-(methodical/defmethod t2/table-name :model/WorkspaceInputTransform [_model] :workspace_input_transform)
-
-(doto :model/WorkspaceInputTransform
- (derive :metabase/model))
-
-(t2/deftransforms :model/WorkspaceInputTransform
- {:ref_id mi/transform-trim})
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_log.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_log.clj
deleted file mode 100644
index 91980b7cce9..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_log.clj
+++ /dev/null
@@ -1,70 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-log
- (:require
- [java-time.api :as t]
- [metabase.models.interface :as mi]
- [metabase.util.i18n :refer [deferred-tru]]
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-(methodical/defmethod t2/table-name :model/WorkspaceLog [_model] :workspace_log)
-
-(doto :model/WorkspaceLog
- (derive :metabase/model)
- (derive :hook/timestamped?))
-
-(t2/deftransforms :model/WorkspaceLog
- {:task mi/transform-keyword
- :status mi/transform-keyword})
-
-(defn- task->description
- "Return a human-readable description for a workspace task."
- [task]
- (case task
- :workspace-setup (deferred-tru "Setting up the workspace")
- :database-isolation (deferred-tru "Provisioning database isolation")
- :mirror-entities (deferred-tru "Mirroring entities")
- :grant-read-access (deferred-tru "Granting permissions")
- (name task)))
-
-(t2/define-after-select :model/WorkspaceLog
- [{:keys [task] :as log}]
- (assoc log :description (task->description task)))
-
-(defn start!
- "Create a log entry for a workspace setup task. Returns the created log."
- [workspace-id task]
- (t2/insert-returning-instance! :model/WorkspaceLog
- {:workspace_id workspace-id
- :task task
- :started_at (t/offset-date-time)
- :status :started}))
-
-(defn- complete!
- [status log-id & [message]]
- (assert (#{:success :failure} status) "It can only be either success or failure")
- (let [data (cond-> {:completed_at (t/offset-date-time)
- :status status}
- message (assoc :message message))]
- (t2/update! :model/WorkspaceLog log-id data)))
-
-(defn success!
- "Task was completed successfully"
- [log-id & [message]]
- (complete! :success log-id message))
-
-(defn failure!
- "Task has failed"
- [log-id & [message]]
- (complete! :failure log-id message))
-
-(defmacro track!
- "Wrap body with automatic logging: starts a log entry, marks success on completion, failure on exception."
- [workspace-id task & body]
- `(let [log# (start! ~workspace-id ~task)]
- (try
- (let [result# (do ~@body)]
- (success! (:id log#))
- result#)
- (catch Exception e#
- (failure! (:id log#) (ex-message e#))
- (throw e#)))))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_merge.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_merge.clj
deleted file mode 100644
index ce3e0b34659..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_merge.clj
+++ /dev/null
@@ -1,14 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-merge
- "Model for WorkspaceMerge - tracks batch merge events with commit messages.
- Survives workspace deletion through inlined workspace_name."
- (:require
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-;;; -------------------------------------------------- Model Setup --------------------------------------------------
-
-(methodical/defmethod t2/table-name :model/WorkspaceMerge [_model] :workspace_merge)
-
-(doto :model/WorkspaceMerge
- (derive :metabase/model)
- (derive :hook/created-at-timestamped?))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_merge_transform.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_merge_transform.clj
deleted file mode 100644
index 8dfa06e1c42..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_merge_transform.clj
+++ /dev/null
@@ -1,15 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-merge-transform
- "Model for WorkspaceMergeTransform - tracks individual transform merges.
- Linked to WorkspaceMerge for batch merges, standalone for single-transform merges.
- Survives workspace deletion through inlined workspace_name."
- (:require
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-;;; -------------------------------------------------- Model Setup --------------------------------------------------
-
-(methodical/defmethod t2/table-name :model/WorkspaceMergeTransform [_model] :workspace_merge_transform)
-
-(doto :model/WorkspaceMergeTransform
- (derive :metabase/model)
- (derive :hook/created-at-timestamped?))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_output.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_output.clj
deleted file mode 100644
index 95f6f7433bd..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_output.clj
+++ /dev/null
@@ -1,15 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-output
- "Model for WorkspaceOutput - tables that workspace transforms produce."
- (:require
- [metabase.models.interface :as mi]
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-(methodical/defmethod t2/table-name :model/WorkspaceOutput [_model] :workspace_output)
-
-(doto :model/WorkspaceOutput
- (derive :metabase/model)
- (derive :hook/timestamped?))
-
-(t2/deftransforms :model/WorkspaceOutput
- {:ref_id mi/transform-trim})
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_output_external.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_output_external.clj
deleted file mode 100644
index 8c481e1e166..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_output_external.clj
+++ /dev/null
@@ -1,11 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-output-external
- "Model for WorkspaceOutputExternal - tables that enclosed external transforms produce."
- (:require
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-(methodical/defmethod t2/table-name :model/WorkspaceOutputExternal [_model] :workspace_output_external)
-
-(doto :model/WorkspaceOutputExternal
- (derive :metabase/model)
- (derive :hook/timestamped?))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_transform.clj b/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_transform.clj
deleted file mode 100644
index 2f8001c8564..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/models/workspace_transform.clj
+++ /dev/null
@@ -1,55 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-transform
- "Model for WorkspaceTransform - holds the changeset of transforms being created
- and edited within a workspace."
- (:require
- [clojure.string :as str]
- [metabase.models.interface :as mi]
- [metabase.transforms.models.transform :as transform]
- [methodical.core :as methodical]
- [toucan2.core :as t2]))
-
-(methodical/defmethod t2/table-name :model/WorkspaceTransform [_model] :workspace_transform)
-
-;; IMPORTANT: ref_id is NOT unique across workspaces - it corresponds to a Representation id and
-;; the same transform can be checked out into multiple workspaces. Always use BOTH workspace_id
-;; AND ref_id to identify a specific WorkspaceTransform record.
-;; Ordering matches the composite PK index in the database (workspace_id, ref_id),
-;; with workspace_id first to support looking up all transforms for a given workspace.
-(methodical/defmethod t2/primary-keys :model/WorkspaceTransform [_model] [:workspace_id :ref_id])
-
-(doto :model/WorkspaceTransform
- (derive :metabase/model)
- (derive :hook/timestamped?)
- (derive :hook/entity-id))
-
-(t2/deftransforms :model/WorkspaceTransform
- {:ref_id {:in identity :out str/trim}
- :source {:out transform/transform-source-out, :in transform/transform-source-in}
- :target mi/transform-json})
-
-(t2/define-before-insert :model/WorkspaceTransform
- [instance]
- ;; Ref id can not be added here due to mysql t2 bug
- (when-not (string? (not-empty (:ref_id instance)))
- (throw (ex-info "ref_id required for WorkspaceTransform insertion."
- {:instance instance})))
- instance)
-
-(t2/define-before-update :model/WorkspaceTransform
- [instance]
- ;; global_id is immutable - a transform's link to the global transform it was checked out from cannot change
- (when (contains? (t2/changes instance) :global_id)
- (let [original (t2/original instance)]
- (throw (ex-info "Cannot change global_id of an existing workspace transform."
- {:status-code 400
- :workspace_id (:workspace_id original)
- :ref_id (:ref_id original)
- :old_global_id (:global_id original)
- :new_global_id (:global_id instance)}))))
- ;; Mark the definition as changed when source or target is updated.
- ;; This is also set redundantly by [[metabase-enterprise.workspaces.impl/increment-analysis-version!]] in the API
- ;; layer, but having it here ensures correctness regardless of the code path used to update the transform.
- (cond-> instance
- (or (contains? (t2/changes instance) :source)
- (contains? (t2/changes instance) :target))
- (assoc :definition_changed true)))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/query_processor/middleware.clj b/enterprise/backend/src/metabase_enterprise/workspaces/query_processor/middleware.clj
index a1a18161410..6d68ccea4f4 100644
--- a/enterprise/backend/src/metabase_enterprise/workspaces/query_processor/middleware.clj
+++ b/enterprise/backend/src/metabase_enterprise/workspaces/query_processor/middleware.clj
@@ -1,41 +1,9 @@
(ns metabase-enterprise.workspaces.query-processor.middleware
- "QP preprocessing middleware that rewrites table references in native SQL queries for workspace transforms.
-
- When a query carries a `:workspace-remapping` key in its `:middleware` map (attached by workspace execute
- code), this middleware rewrites table names in the native SQL using [[sql-tools/replace-names]]."
(:require
- [metabase.driver :as driver]
- [metabase.driver.sql.util :as sql.u]
- [metabase.lib.schema :as lib.schema]
- [metabase.premium-features.core :refer [defenterprise]]
- [metabase.sql-tools.core :as sql-tools]
- [metabase.util :as u]))
-
-(set! *warn-on-reflection* true)
+ [metabase.premium-features.core :refer [defenterprise]]))
(defenterprise apply-workspace-remapping
- "Pre-processing middleware. Rewrites table references in native SQL queries for workspace transforms."
+ "Dummy implementation — the workspaces feature has been removed."
:feature :workspaces
- [{{remapping :workspace-remapping} :middleware :as query}]
- (cond
- ;; Not in a workspace that requires remapping, or no tables to remap.
- (or (not remapping) (empty? (:tables remapping)))
- query
-
- (not (lib.schema/native-only-query? query))
- (throw (ex-info "Workspace remapping is currently only supported for native queries"
- {:query query, :remapping remapping}))
-
- :else
- ;; Replacement identifiers must be quoted to preserve case — e.g., Snowflake uppercases
- ;; unquoted identifiers, so `mb__isolation_xxx` would become `MB__ISOLATION_XXX`.
- ;; TODO (2026-03-07): We pre-quote here with HoneySQL, but sql-tools/replace-names strips
- ;; and re-quotes using its own dialect convention. Consider adding a :force-quote? flag to
- ;; replace-names so it can handle quoting internally without this round-trip.
- (let [quote-id (fn [s] (if s (sql.u/quote-name driver/*driver* :table s) s))
- remapping (update remapping :tables update-vals #(update-vals % quote-id))]
- (u/update-in-if-exists query [:stages 0 :native]
- (fn [sql] (sql-tools/replace-names driver/*driver*
- sql
- remapping
- {:allow-unused? true}))))))
+ [query]
+ query)
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/scope.clj b/enterprise/backend/src/metabase_enterprise/workspaces/scope.clj
deleted file mode 100644
index 5db6bf96dfa..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/scope.clj
+++ /dev/null
@@ -1,14 +0,0 @@
-(ns metabase-enterprise.workspaces.scope
- "Scope declarations for the workspaces module."
- (:require
- [metabase.api-scope.core :as api-scope]
- [metabase.util.i18n :refer [deferred-tru]]))
-
-(api-scope/defscope agent-workspace-read "agent:workspace:read"
- (deferred-tru "Read workspace data"))
-
-(api-scope/defscope agent-workspace-write "agent:workspace:write"
- (deferred-tru "Write workspace data"))
-
-(api-scope/defscope agent-workspace-execute "agent:workspace:execute"
- (deferred-tru "Execute workspace queries"))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/settings.clj b/enterprise/backend/src/metabase_enterprise/workspaces/settings.clj
deleted file mode 100644
index 77b14fbd071..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/settings.clj
+++ /dev/null
@@ -1,25 +0,0 @@
-(ns metabase-enterprise.workspaces.settings
- (:require
- [metabase.settings.core :as setting]
- [metabase.util.i18n :refer [deferred-tru]]))
-
-(setting/defsetting database-enable-workspaces
- (deferred-tru "Whether the database has workspaces enabled")
- :default false
- :feature :workspaces
- :driver-feature :workspace
- :enabled-for-db? (fn [db]
- (setting/custom-disabled-reasons!
- (if-let [permission-status (:workspace_permissions_status db)]
- (when-let [error (:error permission-status)]
- [{:type :error
- :key :workspaces/permissions-missing
- ;; TODO (Ngoc 2026-01-20) -- localize error message - GDGT-1552
- :message error}])
- [{:type :error
- :key :workspaces/permissions-unchecked
- :message (deferred-tru "Workspace connection must be tested explicitly.")}])))
- :type :boolean
- :visibility :public
- :database-local :only
- :export? true)
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/types.clj b/enterprise/backend/src/metabase_enterprise/workspaces/types.clj
deleted file mode 100644
index d0a45228d7c..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/types.clj
+++ /dev/null
@@ -1,189 +0,0 @@
-(ns metabase-enterprise.workspaces.types
- (:require
- [metabase.util.malli.registry :as mr]
- [metabase.util.malli.schema :as ms]))
-
-(mr/def ::appdb-id ms/PositiveInt)
-
-(mr/def ::ref-id [:string {:min 1 :api/regex #".+"}])
-
-(mr/def ::flag
- "Boolean flag that accepts true, false, or 1 (for query param compatibility)."
- [:or [:= 1] :boolean])
-
-(def entity-types
- "The kinds of entities we can store within a Workspace."
- [{:name "Transform"
- :key :transform
- :group :transforms
- :model :model/Transform}])
-
-(mr/def ::entity-type (into [:enum] (map :key) entity-types))
-
-(mr/def ::entity-grouping (into [:enum] (map :group) entity-types))
-
-;; Map like {:transforms [1 2 3]}
-(mr/def ::entity-map
- [:map-of ::entity-grouping [:sequential ms/PositiveInt]])
-
-(mr/def ::ancestors-result
- "Result of running stale ancestor transforms."
- [:map
- [:succeeded [:sequential ::ref-id]]
- [:failed [:sequential ::ref-id]]
- [:not_run [:sequential ::ref-id]]])
-
-(mr/def ::execution-result
- [:map
- [:status [:enum :succeeded :failed]]
- [:start_time {:optional true} [:maybe some?]]
- [:end_time {:optional true} [:maybe some?]]
- [:message {:optional true} [:maybe :string]]
- [:table [:map
- [:name :string]
- [:schema {:optional true} [:maybe :string]]]]
- [:ancestors {:optional true} ::ancestors-result]])
-
-(mr/def ::query-result
- "Result of a query preview (dry-run or ad-hoc query).
- Data is nested under :data to match /api/dataset response format."
- [:map
- [:status [:enum :succeeded :failed]]
- [:message {:optional true} [:maybe :string]]
- [:running_time {:optional true} [:maybe :int]]
- [:started_at {:optional true} [:maybe :any]]
- [:data {:optional true}
- [:map
- [:rows {:optional true} [:sequential :any]]
- [:cols {:optional true} [:sequential :map]]
- [:results_metadata {:optional true} [:map
- [:columns {:optional true} [:sequential :map]]]]]]
- [:ancestors {:optional true} ::ancestors-result]])
-
-;;; ---------------------------------------- Graph/Problem Types ----------------------------------------
-
-;; Node types used in workspace graphs and problem detection
-(mr/def ::node-type [:enum :input-table :external-transform :workspace-transform])
-
-(mr/def ::table-coord
- "Logical reference to a table by database, schema, and name."
- [:map
- [:db_id ::appdb-id]
- [:schema [:maybe :string]]
- [:table :string]])
-
-(mr/def ::node-ref
- "Reference to a node in the graph or a related entity."
- [:map
- [:type ::node-type]
- [:id [:or ::appdb-id ::ref-id]]
- [:name {:optional true} :string]])
-
-;;; ---------------------------------------- Problem Types ----------------------------------------
-
-;; Problem type definitions with metadata for FE display and merge-blocking behavior
-;; See validation.clj docstring for full documentation table
-
-(def problem-types
- "All problem types with their metadata.
-
- Each entry has:
- - :description - human-readable explanation
- - :severity - :error, :warning, or :info
- - :block-merge - whether this problem should prevent merging
- - :static? - true if determinable from metadata alone, false if requires runtime info
-
- ## Categories
-
- Dependency-based (about output state) - prefix indicates who depends on the output:
- - unused-* : nothing depends on this output
- - internal-downstream-* : transforms within the workspace graph depend on this
- - external-downstream-* : transforms outside the workspace depend on this
-
- Structural (about graph shape) - prefix indicates scope of the issue:
- - internal-* : between workspace transforms only
- - external-* : involves global transforms (upstream or downstream)"
- {;; No dependents (informational)
- :unused/not-run {:description "Output hasn't been created yet, but nothing depends on it"
- :severity :info
- :block-merge false
- :static? true}
- :unused/stale {:description "Output is stale (needs re-run), but nothing depends on it"
- :severity :info
- :block-merge false
- :static? true}
- :unused/failed {:description "Transform failed on last run, but nothing depends on it"
- :severity :error
- :block-merge false
- :static? false}
-
- ;; Internal dependents (blocks workspace progress)
- :internal-downstream/not-run {:description "Output hasn't been created yet, other workspace transforms need it"
- :severity :warning
- :block-merge true
- :static? true}
- :internal-downstream/stale {:description "Output is stale, other workspace transforms need fresh data"
- :severity :warning
- :block-merge true
- :static? true}
- :internal-downstream/failed {:description "Transform failed on last run, other workspace transforms need it"
- :severity :error
- :block-merge true
- :static? false}
-
- ;; External dependents (would affect things after merge)
- :external-downstream/not-run {:description "Output hasn't been created yet, external transforms depend on it"
- :severity :warning
- :block-merge true
- :static? true}
- :external-downstream/stale {:description "Output is stale, external transforms are using outdated data"
- :severity :warning
- :block-merge true
- :static? true}
- :external-downstream/removed-field {:description "Field was removed that external transforms reference"
- :severity :error
- :block-merge true
- :static? true}
- :external-downstream/removed-table {:description "Table was removed, external transforms will stop receiving updates"
- :severity :warning
- :block-merge false
- :static? true}
-
- ;; Structural issues (conflicts/cycles)
- :internal/target-conflict {:description "Multiple workspace transforms target the same table"
- :severity :error
- :block-merge true
- :static? true}
- :internal/cycle {:description "Circular dependency between workspace transforms"
- :severity :error
- :block-merge true
- :static? true}
- :external/target-conflict {:description "Workspace transform conflicts with an existing global transform's target"
- :severity :error
- :block-merge true
- :static? true}
- :external/cycle {:description "Workspace changes would create a circular dependency with global transforms"
- :severity :error
- :block-merge true
- :static? true}})
-
-(mr/def ::problem-type (into [:enum] (keys problem-types)))
-
-(mr/def ::severity [:enum :error :warning :info])
-
-;; Categories derived from problem-type namespaces
-(mr/def ::problem-category
- (into [:enum] (distinct (map (comp keyword namespace) (keys problem-types)))))
-
-;; Problem names derived from problem-type names
-(mr/def ::problem-name
- (into [:enum] (distinct (map (comp keyword name) (keys problem-types)))))
-
-(mr/def ::problem
- "A problem detected during workspace validation."
- [:map
- [:category ::problem-category]
- [:problem ::problem-name]
- [:severity ::severity]
- [:block_merge :boolean]
- [:data :map]])
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/util.clj b/enterprise/backend/src/metabase_enterprise/workspaces/util.clj
deleted file mode 100644
index eb42d221e01..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/util.clj
+++ /dev/null
@@ -1,174 +0,0 @@
-(ns metabase-enterprise.workspaces.util
- (:require
- [metabase.util.log :as log]
- [toucan2.core :as t2]))
-
-(defn assert-transform!
- "Test whether we support the given entity type within workspaces yet.
- Named for the only case we support currently, to make call sites assumptions more obvious."
- [entity-type]
- (when (not= "transform" (name entity-type))
- (throw (ex-info "Only transform entity type is supported"
- {:status-code 400
- :entity-type entity-type}))))
-
-(defn assert-transforms!
- "Test that only supported types are given in the given list.
- Named for the only case we support currently, to make call sites assumptions more obvious."
- [entities]
- (when-let [other-types (seq (remove #{:transform} (map :entity-type entities)))]
- (throw (ex-info "Only transform entities are currently supported"
- {:status-code 400
- :unsupported-types other-types}))))
-
-(defn- toposort-visit [node child->parents visited result]
- (cond
- (visited node) [visited result]
- :else (let [parents (child->parents node [])
- [visited' result'] (reduce (fn [[v r] p]
- (toposort-visit p child->parents v r))
- [(conj visited node) result]
- parents)]
- [visited' (conj result' node)])))
-
-(defn toposort-dfs
- "Perform a topological sort using depth-first search.
- Takes a map from child nodes to their parent nodes (dependencies).
- Returns nodes in topological order (dependencies before dependents)."
- [child->parents]
- ;; TODO (Chris 2025-11-20) -- Detect cycles and throw an error.
- (let [all-nodes (set (keys child->parents))]
- (loop [visited #{}
- result []
- remaining all-nodes]
- (if (empty? remaining)
- result
- (let [node (first remaining)
- [visited' result'] (toposort-visit node child->parents visited result)]
- (recur visited' result' (disj remaining node)))))))
-
-;;; Naming
-
-(defn isolated-table-name
- "Generate name for a table mirroring transform target table in the isolated database namespace.
- Returns schema__name when schema is present, or __name when schema is nil (to distinguish from global tables)."
- [schema name]
- ;; In perverse cases, this might not be unique.
- ;; Since we persist the mappings in the appdb associated with each transform output, we *could* detect conflicts and
- ;; restore uniqueness. Given the low risk, we chose to do nothing for now.
- (if schema
- (format "%s__%s" schema name)
- (format "__%s" name)))
-
-(def ^:private password-char-sets
- "Character sets for password generation. Cycles through these to ensure representation from each."
- ["ABCDEFGHJKLMNPQRSTUVWXYZ"
- "abcdefghjkmnpqrstuvwxyz"
- "123456789"
- "!#$%&*+-="])
-
-(defn random-isolated-password
- "Generate a random password suitable for most database engines.
- Ensures the password contains characters from all sets (uppercase, lowercase, digits, special)
- by cycling through the character sets. Result is shuffled for randomness."
- []
- (->> (cycle password-char-sets)
- (take (+ 32 (rand-int 32)))
- (map rand-nth)
- shuffle
- (apply str)))
-
-;;; -------------------------------------------------- Cute Names --------------------------------------------------
-
-(def ^:private adjectives
- "Adjectives for generating cute ref IDs, inspired by Docker's naming scheme."
- ["admiring" "adoring" "affectionate" "agitated" "amazing" "angry" "awesome"
- "beautiful" "blissful" "bold" "boring" "brave" "busy" "charming" "clever"
- "cool" "compassionate" "competent" "condescending" "confident" "cranky"
- "crazy" "dazzling" "determined" "distracted" "dreamy" "eager" "ecstatic"
- "elastic" "elated" "elegant" "eloquent" "epic" "exciting" "fervent"
- "festive" "flamboyant" "focused" "friendly" "frosty" "funny" "gallant"
- "gifted" "goofy" "gracious" "great" "happy" "hardcore" "heuristic" "hopeful"
- "hungry" "infallible" "inspiring" "intelligent" "interesting" "jolly"
- "jovial" "keen" "kind" "laughing" "loving" "lucid" "magical" "modest"
- "musing" "mystifying" "naughty" "nervous" "nice" "nifty" "nostalgic"
- "objective" "optimistic" "peaceful" "pedantic" "pensive" "practical"
- "priceless" "quirky" "quizzical" "recursing" "relaxed" "reverent" "romantic"
- "sad" "serene" "sharp" "silly" "sleepy" "stoic" "strange" "stupefied"
- "suspicious" "sweet" "tender" "thirsty" "trusting" "unruffled" "upbeat"
- "vibrant" "vigilant" "vigorous" "wizardly" "wonderful" "xenodochial" "youthful"
- "zealous" "zen"])
-
-(def ^:private animals
- "Animals for generating cute ref IDs."
- ["albatross" "alligator" "alpaca" "ant" "anteater" "antelope" "armadillo"
- "baboon" "badger" "bat" "bear" "beaver" "bee" "bison" "boar" "buffalo"
- "butterfly" "camel" "capybara" "caribou" "cat" "caterpillar" "cheetah"
- "chicken" "chimpanzee" "chinchilla" "cobra" "condor" "cormorant" "coyote"
- "crab" "crane" "crocodile" "crow" "deer" "dingo" "dog" "dolphin" "donkey"
- "dove" "dragonfly" "duck" "eagle" "echidna" "eel" "elephant" "elk" "emu"
- "falcon" "ferret" "finch" "firefly" "flamingo" "fox" "frog" "gazelle"
- "gerbil" "giraffe" "goat" "goose" "gopher" "gorilla" "grasshopper" "grouse"
- "hamster" "hare" "hawk" "hedgehog" "heron" "hippopotamus" "hornet" "horse"
- "hummingbird" "hyena" "ibex" "iguana" "impala" "jackal" "jaguar" "jellyfish"
- "kangaroo" "kingfisher" "kiwi" "koala" "komodo" "kookaburra" "lemur"
- "leopard" "lion" "lizard" "llama" "lobster" "lynx" "magpie" "mallard"
- "manatee" "mandrill" "marmot" "meerkat" "mink" "mole" "mongoose" "monkey"
- "moose" "moth" "mouse" "mule" "narwhal" "newt" "nightingale" "ocelot"
- "octopus" "okapi" "opossum" "orangutan" "orca" "oryx" "osprey" "ostrich"
- "otter" "owl" "ox" "panda" "panther" "parrot" "partridge" "peacock"
- "pelican" "penguin" "pheasant" "pig" "pigeon" "platypus" "pony" "porcupine"
- "porpoise" "puma" "quail" "rabbit" "raccoon" "ram" "raven" "reindeer"
- "rhinoceros" "salamander" "salmon" "sardine" "scorpion" "seahorse" "seal"
- "shark" "sheep" "shrew" "skunk" "sloth" "snail" "snake" "sparrow" "spider"
- "squid" "squirrel" "starfish" "stingray" "stork" "swallow" "swan" "tapir"
- "tiger" "toad" "toucan" "turkey" "turtle" "viper" "vulture" "wallaby"
- "walrus" "warthog" "wasp" "weasel" "whale" "wolf" "wolverine" "wombat"
- "woodpecker" "yak" "zebra"])
-
-(defn generate-name
- "Generate a cute adjective-animal style name. Making sure it's unique is your job."
- []
- (str (rand-nth adjectives) "-" (rand-nth animals)))
-
-(defn generate-ref-id
- "Generate a cute adjective-animal style ref ID with a random suffix.
- Format: adjective-animal-xxxx (where xxxx is a random 4-char hex suffix)"
- []
- (str (generate-name) "-" (format "%04x" (rand-int 65536))))
-
-;;; -------------------------------- Epochal Versioning Helpers ------------------------------------------
-
-(defmacro ignore-constraint-violation
- "Execute body and silently return nil if a unique constraint violation occurs.
- Used in epochal versioning where concurrent processes may race to insert the same version.
- If the exception is not a constraint violation, it is rethrown."
- [& body]
- `(try
- ~@body
- (catch Exception e#
- ;; Check if this is a constraint violation (database-specific messages)
- ;; H2: "Unique index or primary key violation"
- ;; PostgreSQL: "duplicate key value violates unique constraint"
- ;; MySQL: "Duplicate entry"
- (let [msg# (or (ex-message e#) "")
- cause-msg# (or (some-> e# ex-cause ex-message) "")]
- (if (or (re-find #"(?i)unique|duplicate|constraint" msg#)
- (re-find #"(?i)unique|duplicate|constraint" cause-msg#))
- ;; It's good to keep these visible, as they should be rare and can cause transient consistency issues.
- (log/info "Ignoring constraint violation (concurrent insert race):" msg#)
- (throw e#))))))
-
-;;; -------------------------------- Toucan2 MySQL Workarounds ------------------------------------------
-
-(defn insert-returning-ws-tx!
- "Insert a WorkspaceTransform and return the inserted instance.
-
- Works around a Toucan2 limitation where `t2/insert-returning-instance!` returns nil
- for tables with composite primary keys on MySQL and H2. These databases don't reliably
- support RETURNING for composite PKs, so we fall back to select after insert.
-
- See: https://github.com/camsaul/toucan2/issues/204"
- [row]
- (or (t2/insert-returning-instance! :model/WorkspaceTransform row)
- (t2/select-one :model/WorkspaceTransform :workspace_id (:workspace_id row), :ref_id (:ref_id row))))
diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/validation.clj b/enterprise/backend/src/metabase_enterprise/workspaces/validation.clj
deleted file mode 100644
index 8dfae6e59eb..00000000000
--- a/enterprise/backend/src/metabase_enterprise/workspaces/validation.clj
+++ /dev/null
@@ -1,288 +0,0 @@
-(ns metabase-enterprise.workspaces.validation
- "Validation of workspace changes against downstream dependencies.
-
- ASSUMPTION: All transforms in the workspace have been run, and their outputs are not stale.
- This validation checks the *current* isolated table schema against external transform requirements.
-
- ## Problem Types
-
- See `metabase-enterprise.workspaces.types/problem-types` for the full list of problem types
- with their descriptions, severity levels, and merge-blocking behavior.
-
- ## Currently Implemented
-
- | Category | Problem | Description |
- |---------------------|---------------|----------------------------------------------------------------|
- | unused | not-run | Output hasn't been created, nothing depends on it |
- | internal-downstream | not-run | Output hasn't been created, other workspace transforms need it |
- | external-downstream | not-run | Output hasn't been created, external transforms need it |
- | external-downstream | removed-field | Field was removed that external transforms reference |"
- (:require
- [metabase-enterprise.workspaces.types :as ws.t]
- [metabase.lib-be.core :as lib-be]
- [metabase.lib.core :as lib]
- [metabase.lib.metadata.protocols :as lib.metadata.protocols]
- [toucan2.core :as t2]))
-
-(set! *warn-on-reflection* true)
-
-;;;; ---------------------------------------- Metadata Provider Override ----------------------------------------
-
-(defn- make-field-override-provider
- "Create a metadata provider that overrides a table's fields with a different set of fields.
- Used to simulate what external transforms would see after a merge.
-
- - `base-provider`: the underlying metadata provider
- - `target-table-id`: the global table ID whose fields we're overriding
- - `replacement-fields`: the fields from the isolated table (what fields will exist after merge)"
- [base-provider target-table-id replacement-fields]
- (let [replacement-field-names (into #{} (map :name) replacement-fields)
- ;; TODO (Chris 2026-02-02) -- better to do 1 query up-front for *all* the tables we will validate.
- table-field-id? (t2/select-fn-set :id [:model/Field :id] :table_id target-table-id)]
- (reify
- lib.metadata.protocols/MetadataProvider
- (database [_this]
- (lib.metadata.protocols/database base-provider))
- (metadatas [_this metadata-spec]
- ;; Yes, for some reason :id is actually a set of ids
- (let [{spec-type :lib/type spec-field-ids :id} metadata-spec]
- (if (and (= :metadata/column spec-type) (some table-field-id? spec-field-ids))
- ;; Return replacement fields with :active based on whether they exist
- (let [original-fields (lib.metadata.protocols/metadatas base-provider metadata-spec)]
- (map (fn [field]
- (if (contains? replacement-field-names (:name field))
- field
- (assoc field :active false)))
- original-fields))
- ;; Delegate everything else
- (lib.metadata.protocols/metadatas base-provider metadata-spec))))
- (setting [_this setting-key]
- (lib.metadata.protocols/setting base-provider setting-key))
-
- lib.metadata.protocols/CachedMetadataProvider
- (cached-metadatas [_this metadata-type metadata-ids]
- (lib.metadata.protocols/cached-metadatas base-provider metadata-type metadata-ids))
- (store-metadata! [_this a-metadata]
- (lib.metadata.protocols/store-metadata! base-provider a-metadata))
- (cached-value [_this k not-found]
- (lib.metadata.protocols/cached-value base-provider k not-found))
- (cache-value! [_this k v]
- (lib.metadata.protocols/cache-value! base-provider k v))
- (has-cache? [_this]
- (lib.metadata.protocols/has-cache? base-provider))
- (clear-cache! [_this]
- (lib.metadata.protocols/clear-cache! base-provider)))))
-
-;;;; ---------------------------------------- External Transform Discovery ----------------------------------------
-
-(defn- workspace-outputs
- "Get all workspace outputs with their global and isolated table info.
- Includes both workspace transform outputs and enclosed external transform outputs.
- Enriches each output with :isolated_active from the referenced metabase_table."
- [workspace-id]
- ;; TODO (Chris 2026-02-02) -- rather fetch all this as an input to graph analysis, and save it in [[graph]].
- (let [ws-outputs (t2/select [:model/WorkspaceOutput
- :id :ref_id :db_id
- :global_schema :global_table :global_table_id
- :isolated_schema :isolated_table :isolated_table_id]
- :workspace_id workspace-id)
- ;; External outputs use transform_id (int) instead of ref_id (string)
- ;; Map transform_id to ref_id for compatibility with the rest of the validation code
- ext-outputs (map #(assoc % :ref_id (:transform_id %) :external? true)
- (t2/select [:model/WorkspaceOutputExternal
- :id :transform_id :db_id
- :global_schema :global_table :global_table_id
- :isolated_schema :isolated_table :isolated_table_id]
- :workspace_id workspace-id))
- all-outputs (concat ws-outputs ext-outputs)
- ;; We could avoid this extra query by using a JOIN, but we'd need to define a derived model for this to preserve
- ;; the model transforms (e.g. char(36) trimming on ref_id), and that feels excessive for a single query.
- active-ids (t2/select-fn-set :id [:model/Table :id]
- :id [:in (keep :isolated_table_id all-outputs)]
- :active true)]
- (for [output all-outputs]
- (assoc output :isolated_active (contains? active-ids (:isolated_table_id output))))))
-
-(defn- ids-for-type [entities desired-node-type]
- (for [{:keys [node-type id]} entities, :when (= node-type desired-node-type)] id))
-
-(defn- checked-out-transform-ids
- "Get the global IDs of transforms that are checked out into this workspace.
- Extracts workspace-transform ref_ids from the graph and looks up their global_ids."
- [{:keys [entities] :as _graph}]
- (if-let [ref-ids (seq (ids-for-type entities :workspace-transform))]
- ;; TODO (Chris 2026-02-02) -- rather fetch this as an input to graph analysis, and save it in [[graph]].
- (t2/select-fn-set :global_id
- [:model/WorkspaceTransform :global_id]
- :ref_id [:in ref-ids]
- {:where [:not= :global_id nil]})
- #{}))
-
-(defn- enclosed-transform-ids
- "Get the IDs of external transforms that are enclosed by the workspace graph.
- These transforms run within the workspace, so they don't need further static validation."
- [{:keys [entities] :as _graph}]
- (ids-for-type entities :external-transform))
-
-(def ^:private table? #{:table})
-
-(defn- internal-dependents
- "Build a map of non-table ids to the non-table ids that directly depend on it (internal to workspace).
- This is essentially an inversion of the dependencies map, with some filtering."
- [{:keys [dependencies] :as _graph}]
- ;; :dependencies is {child #{parents...}}, we need to invert to {parent #{children...}}
- (reduce (fn [acc [{child-type :node-type, child-id :id} parents]]
- (if (table? child-type)
- acc
- (reduce (fn [acc {parent-type :node-type, parent-id :id}]
- (if (table? parent-type)
- acc
- (update acc parent-id (fnil conj #{}) child-id)))
- acc
- parents)))
- {}
- dependencies))
-
-(defn- external-transform-dependents
- "Get external transforms that depend on a given table (by global_table_id).
- Excludes transforms that are checked out or enclosed in the workspace."
- [global-table-id checked-out-ids enclosed-ids]
- (when global-table-id
- (let [dependent-transform-ids (t2/select-fn-set :from_entity_id
- [:model/Dependency :from_entity_id]
- :to_entity_type :table
- :to_entity_id global-table-id
- :from_entity_type :transform)
- ;; Remove checked out and enclosed transforms
- external-ids (-> dependent-transform-ids
- (disj nil)
- (as-> ids (apply disj ids checked-out-ids))
- (as-> ids (apply disj ids enclosed-ids)))]
- (when (seq external-ids)
- (t2/select [:model/Transform :id :name :source] :id [:in external-ids])))))
-
-;;;; ---------------------------------------- Validation Logic ----------------------------------------
-
-(defn- validate-transform-against-fields
- "Check if a transform would break given a modified set of fields.
- Returns bad refs if the transform's query references fields that don't exist in replacement-fields,
- or nil if there are no bad refs."
- [transform global-table-id replacement-fields]
- (let [db-id (get-in transform [:source :query :database])]
- (when db-id
- (let [base-provider (lib-be/application-database-metadata-provider db-id)
- override-provider (make-field-override-provider base-provider global-table-id replacement-fields)
- query (lib/query override-provider (get-in transform [:source :query]))]
- (not-empty (lib/find-bad-refs query))))))
-
-(defn- get-table-fields
- "Get all active fields for a table by ID."
- [table-id]
- (when table-id
- (t2/select [:model/Field :id :name :base_type :semantic_type]
- :table_id table-id
- :active true)))
-
-(defn- make-problem
- "Construct a problem map with type metadata from ws.t/problem-types.
- Splits the namespaced problem-type into :category and :problem keys."
- [problem-type data]
- (let [{:keys [severity block-merge description]} (get ws.t/problem-types problem-type)]
- {:category (keyword (namespace problem-type))
- :problem (keyword (name problem-type))
- :severity severity
- :block_merge block-merge
- :description description
- :data data}))
-
-(defn- problems-for-output
- "Find problems related to a single workspace output.
- Returns a sequence of problem maps."
- [output checked-out-ids enclosed-ids internal-dependents-map]
- (let [{:keys [ref_id db_id global_schema global_table global_table_id
- isolated_table_id isolated_active external?]} output
- ;; For external outputs, ref_id is actually the transform_id (an int)
- transform-type (if external? :external-transform :workspace-transform)
- external-transforms (external-transform-dependents global_table_id checked-out-ids enclosed-ids)
- has-external-dependents? (seq external-transforms)
- internal-dependents (get internal-dependents-map ref_id)
- has-internal-dependents? (seq internal-dependents)
- table-coord {:db_id db_id :schema global_schema :table global_table}]
-
- (cond
- ;; Case 1: Isolated table is not active (no row, hasn't been run, or was deactivated)
- (not isolated_active)
- (cond
- ;; External transforms depend on this output that doesn't exist
- has-external-dependents?
- [(make-problem :external-downstream/not-run
- {:output table-coord
- :transform {:type transform-type
- :id ref_id}
- :dependents (mapv (fn [{:keys [id name]}]
- {:type :external-transform
- :id id
- :name name})
- external-transforms)})]
- ;; Internal workspace transforms depend on this output that doesn't exist
- has-internal-dependents?
- [(make-problem :internal-downstream/not-run
- {:output table-coord
- :transform {:type transform-type
- :id ref_id}
- :dependents (mapv (fn [dep-ref-id]
- {:type :workspace-transform
- :id dep-ref-id})
- internal-dependents)})]
- ;; No dependents - just informational
- :else
- [(make-problem :unused/not-run
- {:output table-coord
- :transform {:type transform-type
- :id ref_id}})])
-
- ;; Case 2: Isolated table exists - check for field breakages
- has-external-dependents?
- (let [isolated-fields (get-table-fields isolated_table_id)]
- (into []
- (mapcat (fn [transform]
- (when-let [bad-refs (validate-transform-against-fields
- transform global_table_id isolated-fields)]
- [(make-problem :external-downstream/removed-field
- {:output table-coord
- :transform {:type :external-transform
- :id (:id transform)
- :name (:name transform)}
- :bad-refs bad-refs})])))
- external-transforms))
-
- ;; Case 3: No problems
- :else [])))
-
-;;;; ---------------------------------------- Public API ----------------------------------------
-
-(defn find-downstream-problems
- "Find problems that would affect transforms outside the workspace after merge.
-
- Takes the workspace graph (from `ws.dag/path-induced-subgraph`) as an argument.
-
- Returns a sequence of problem maps, each with:
- - :category - the problem category (e.g. :unused, :internal-downstream, :external-downstream)
- - :problem - the specific problem (e.g. :not-run, :removed-field)
- - :severity - :error, :warning, or :info
- - :block-merge - whether this problem should prevent merging
- - :data - further data, depending on type
-
- Currently implemented problem types (category + problem):
- - :unused/not-run - output table hasn't been created (informational, no dependents)
- - :internal-downstream/not-run - output table hasn't been created, other workspace transforms need it
- - :external-downstream/not-run - output table hasn't been created, but external transforms depend on it
- - :external-downstream/removed-field - a field was removed that external transforms need"
- [workspace-id graph]
- (let [outputs (workspace-outputs workspace-id)
- checked-out-ids (checked-out-transform-ids graph)
- enclosed-ids (enclosed-transform-ids graph)
- dependents (internal-dependents graph)]
- (into []
- (mapcat #(problems-for-output % checked-out-ids enclosed-ids dependents))
- outputs)))
diff --git a/enterprise/backend/test/metabase_enterprise/api/session_test.clj b/enterprise/backend/test/metabase_enterprise/api/session_test.clj
index ba4fced3dc6..2faaf8c8ebc 100644
--- a/enterprise/backend/test/metabase_enterprise/api/session_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/api/session_test.clj
@@ -64,7 +64,6 @@
:database-routing
:tenants
:cloud-custom-smtp
- :workspaces
:writable-connection}
(is (= {:admin_security_center false ;; requires self-hosted (non-cloud)
:advanced_permissions true
@@ -117,7 +116,6 @@
:etl_connections false
:etl_connections_pg false
:dependencies false
- :workspaces true
:writable_connection true}
(:token-features (mt/user-http-request :crowberto :get 200 "session/properties"))))))
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj
index 69f533a7a05..f94c8eb75b4 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj
@@ -121,20 +121,7 @@
:model/SecurityAdvisory
:model/CloudMigration
:model/Comment
- :model/CommentReaction
- ;; TODO (lbrdnk 2025-12-17) -- I've added rest of the workspace models here as Workspace was present. I believe
- ;; going forward all of that will be available for export. We should revisit this later in the project.
- :model/Workspace
- :model/WorkspaceInput
- :model/WorkspaceInputExternal
- :model/WorkspaceInputTransform
- :model/WorkspaceLog
- :model/WorkspaceMerge
- :model/WorkspaceMergeTransform
- :model/WorkspaceGraph
- :model/WorkspaceOutput
- :model/WorkspaceOutputExternal
- :model/WorkspaceTransform})
+ :model/CommentReaction})
(deftest ^:parallel comprehensive-entity-id-test
(let [entity-id-models (->> (v2.entity-ids/toucan-models)
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/api_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/api_test.clj
deleted file mode 100644
index ca82effefab..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/api_test.clj
+++ /dev/null
@@ -1,2396 +0,0 @@
-(ns ^:mb/driver-tests metabase-enterprise.workspaces.api-test
- (:require
- [clojure.string :as str]
- [clojure.test :refer :all]
- [java-time.api :as t]
- [medley.core :as m]
- [metabase-enterprise.workspaces.common :as ws.common]
- [metabase-enterprise.workspaces.execute :as ws.execute]
- [metabase-enterprise.workspaces.impl :as ws.impl]
- [metabase-enterprise.workspaces.isolation :as ws.isolation]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase-enterprise.workspaces.util :as ws.u]
- [metabase.audit-app.core :as audit]
- [metabase.driver :as driver]
- [metabase.driver.sql :as driver.sql]
- [metabase.driver.sql.normalize :as sql.normalize]
- [metabase.driver.sql.util :as sql.u]
- [metabase.lib.core :as lib]
- [metabase.lib.metadata :as lib.metadata]
- [metabase.query-processor.compile :as qp.compile]
- [metabase.test :as mt]
- [metabase.transforms.core :as transforms.core]
- [metabase.transforms.execute :as transforms.execute]
- [metabase.transforms.test-dataset :as transforms-dataset]
- [metabase.transforms.test-util :as transforms.tu :refer [with-transform-cleanup!]]
- [metabase.util :as u]
- [toucan2.core :as t2])
- (:import
- (java.time Instant)))
-
-(set! *warn-on-reflection* true)
-
-(ws.tu/ws-fixtures!)
-
-(use-fixtures :once (fn [thunk] (mt/test-drivers (mt/normal-drivers-with-feature :transforms/table) (thunk))))
-
-(def ws-url
- "Alias for ws.tu/ws-url for convenience."
- ws.tu/ws-url)
-
-(def ^:private q
- "Alias for ws.tu/q for convenience."
- ws.tu/q)
-
-(def ^:private ->native
- "Alias for ws.tu/->native for convenience."
- ws.tu/->native)
-
-(deftest workspace-crud-flow-test
- (let [workspace-name (str "Workspace " (random-uuid))
- created (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name workspace-name
- :database_id (mt/id)})
- workspace-id (:id created)
- collection-id (:collection_id created)]
- (is (=? {:id int?
- :collection_id int?
- :name workspace-name}
- created))
- (testing "the collection exists, and we have a back reference"
- (is (t2/exists? :model/Workspace :id workspace-id :collection_id collection-id))
- (is (t2/exists? :model/Collection :id collection-id :workspace_id workspace-id)))
-
- (testing "workspace appears in list response"
- (let [{:keys [items]} (mt/user-http-request :crowberto :get 200 "ee/workspace")]
- (is (some #(= workspace-id (:id %)) items))))
-
- (testing "workspace can be fetched individually"
- (is (=? {:id workspace-id}
- (mt/user-http-request :crowberto :get 200 (ws-url workspace-id)))))
-
- (testing "workspace can be archived"
- (let [updated (mt/user-http-request :crowberto :post 200 (ws-url workspace-id "/archive"))]
- (is (= "archived" (:status updated)))))
-
- (testing "workspace can be unarchived"
- (let [updated (mt/user-http-request :crowberto :post 200 (ws-url workspace-id "/unarchive"))]
- (is (= "uninitialized" (:status updated)))))
-
- (testing "workspace cannot be deleted if it is not archived"
- (let [message (mt/user-http-request :crowberto :delete 400 (ws-url workspace-id))]
- (is (= "You cannot delete a workspace without first archiving it" message))))
-
- (testing "workspace can be deleted if it is archived"
- (let [updated (mt/user-http-request :crowberto :post 200 (ws-url workspace-id "/archive"))]
- (is (= "archived" (:status updated))))
- (let [response (mt/user-http-request :crowberto :delete 200 (ws-url workspace-id))]
- (is (= {:ok true} response))
- ;; TODO (Chris 2026-02-02) -- would be good to check that the user, schema, and table metadata is gone too.
- (is (false? (t2/exists? :model/Workspace workspace-id)))))))
-
-(deftest archive-workspace-calls-destroy-isolation-test
- (testing "POST /api/ee/workspace/:id/archive calls destroy-workspace-isolation!"
- (let [called? (atom false)
- workspace (ws.tu/create-ready-ws! "Archive Isolation Test")]
- (mt/with-dynamic-fn-redefs [ws.isolation/destroy-workspace-isolation!
- (fn [_database _workspace]
- (reset! called? true))]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/archive"))
- (is @called? "destroy-workspace-isolation! should be called when archiving")))))
-
-(deftest archive-workspace-succeeds-when-cleanup-fails-test
- (testing "POST /api/ee/workspace/:id/archive succeeds even when destroy-workspace-isolation! fails"
- (ws.tu/with-workspaces! [workspace {:name "Archive Cleanup Fail Test"}]
- (mt/with-dynamic-fn-redefs [ws.isolation/destroy-workspace-isolation!
- (fn [_database _workspace]
- (throw (ex-info "Simulated cleanup failure" {:test true})))]
- (is (some? (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/archive"))))
- (is (= :archived (t2/select-one-fn :base_status :model/Workspace :id (:id workspace)))
- "Workspace should have status :archived despite cleanup failure")))))
-
-(deftest ^:synchronized delete-workspace-calls-destroy-isolation-test
- (testing "DELETE /api/ee/workspace/:id calls destroy-workspace-isolation!"
- (let [called? (atom false)
- workspace (ws.tu/create-ready-ws! "Delete Isolation Test")]
- (mt/with-dynamic-fn-redefs [ws.isolation/destroy-workspace-isolation!
- (fn [_database _workspace]
- (reset! called? true))]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/archive"))
- (mt/user-http-request :crowberto :delete 200 (ws-url (:id workspace)))
- (is @called? "destroy-workspace-isolation! should be called when deleting")))))
-
-(deftest ^:synchronized merge-workspace-calls-destroy-isolation-test
- (testing "POST /api/ee/workspace/:id/merge calls destroy-workspace-isolation!"
- (let [called? (atom false)
- workspace (ws.tu/create-ready-ws! "Merge Isolation Test")]
- (mt/with-dynamic-fn-redefs [ws.isolation/destroy-workspace-isolation!
- (fn [_database _workspace]
- (reset! called? true))]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/merge"))
- (is @called? "destroy-workspace-isolation! should be called when merging")))))
-
-(deftest unarchive-workspace-calls-ensure-isolation-test
- (testing "POST /api/ee/workspace/:id/unarchive calls ensure-database-isolation!"
- (let [called? (atom false)
- workspace (ws.tu/create-ready-ws! "Unarchive Isolation Test")]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/archive"))
- (testing "ensure-database-isolation! should be called when unarchiving"
- (mt/with-dynamic-fn-redefs [ws.isolation/ensure-database-isolation!
- (fn [_workspace _database]
- (reset! called? true)
- {:schema "test_schema" :database_details {}})]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/unarchive"))
- (is @called?))))))
-
-(deftest unarchive-workspace-calls-sync-grant-accesses-test
- (testing "POST /api/ee/workspace/:id/unarchive calls sync-grant-accesses!"
- (let [called? (atom false)
- workspace (ws.tu/create-ready-ws! "Unarchive Grant Test")]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/archive"))
- (mt/with-dynamic-fn-redefs [ws.impl/sync-grant-accesses!
- (fn [_workspace]
- (reset! called? true)
- nil)]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/unarchive"))
- (is @called? "sync-grant-accesses! should be called when unarchiving")))))
-
-(deftest archive-unarchive-access-granted-test
- (testing "Archive/unarchive properly manages access_granted flags and grants"
- (let [workspace (ws.tu/create-ready-ws! "Archive Grant Test")
- granted-tables (atom [])]
- (testing "Archive resets access_granted to false"
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/archive"))
- (ws.tu/analyze-workspace! (:id workspace))
- (is (false? (t2/select-one-fn :access_granted :model/WorkspaceInput :workspace_id (:id workspace)))))
-
- (testing "Unarchive re-grants access and sets access_granted to true"
- (mt/with-dynamic-fn-redefs [ws.isolation/grant-read-access-to-tables!
- (fn [_database _workspace tables]
- (reset! granted-tables tables))]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/unarchive"))
- (ws.tu/analyze-workspace! (:id workspace))
- (is (=? [{:schema string? :name "test_table_1"}] @granted-tables)
- "grant-read-access-to-tables! should be called with the input tables")
- (is (true? (t2/select-one-fn :access_granted :model/WorkspaceInput :workspace_id (:id workspace)))
- "access_granted should be true after unarchive"))))))
-
-(deftest merge-workspace-test
- (testing "Cannot merge an already archived workspace"
- (ws.tu/with-workspaces! [workspace {:name "Archived Workspace"}]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/archive"))
- (is (= "Cannot merge an archived workspace"
- (mt/user-http-request :crowberto :post 400 (ws-url (:id workspace) "/merge")))))))
-
-(deftest merge-workspace-with-transform-test
- (testing "POST /api/ee/workspace/:id/merge promotes transforms and archives workspace"
- (mt/with-temp [:model/Table _table {:schema "public" :name "merge_test_table"}
- :model/Transform x1 {:name "Upstream Transform"
- :description "Original description"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table"}}]
- (let [{ws-id :id ws-name :name} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name (mt/random-name)
- :database_id (mt/id)})
- {ws-tx-ref-id :ref_id} (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x1)}
- (select-keys x1 [:name :description :source :target])))
- commit-msg "Test batch merge commit"]
- (testing "We've got our workspace with transform to merge"
- (is (int? ws-id))
- ;; We could make an API call here instead :shrug:
- (t2/update! :model/WorkspaceTransform {:workspace_id ws-id :ref_id ws-tx-ref-id} {:description "Modified in workspace"}))
- (testing "returns merged transforms"
- (is (=? {:merged {:transforms [{:global_id (:id x1)}]}
- :errors []
- :workspace {:id ws-id :name ws-name}}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/merge")
- {:commit-message commit-msg}))))
- (testing "workspace was archived after successful merge"
- (is (= :archived (t2/select-one-fn :base_status :model/Workspace :id ws-id))))
- (testing "merge history was created"
- (is (=? {:commit_message commit-msg
- :creator_id (mt/user->id :crowberto)}
- (t2/select-one :model/WorkspaceMerge :workspace_name ws-name)))
- (is (=? {:transform_id (:id x1)
- :commit_message commit-msg}
- (t2/select-one :model/WorkspaceMergeTransform
- :transform_id (:id x1)))))))))
-
-(deftest merge-sets-transform-creator-from-workspace-transform-test
- (testing "POST /api/ee/workspace/:id/merge sets transform creator_id from workspace_transform creator"
- (mt/with-temp [:model/User user-a {:first_name "UserA" :last_name "Test" :email "[email protected]" :is_superuser true}
- :model/User user-b {:first_name "UserB" :last_name "Test" :email "[email protected]" :is_superuser true}
- :model/User user-c {:first_name "UserC" :last_name "Test" :email "[email protected]" :is_superuser true}]
- ;; mt/with-temp with users will trigger their cleanup and those tables fail with their fks to core_user
- (mt/with-model-cleanup [:model/WorkspaceMerge]
- ;; User A creates the workspace
- (let [{ws-id :id ws-name :name} (mt/user-http-request user-a :post 200 "ee/workspace"
- {:name (mt/random-name)
- :database_id (mt/id)})
- ;; User B creates a new workspace transform (not a checkout of existing)
- {ws-tx-ref-id :ref_id} (mt/user-http-request user-b :post 200 (ws-url ws-id "/transform")
- {:name "Transform created by User B"
- :source {:type :query
- :database (mt/id)
- :query (mt/native-query {:query "SELECT count(*) from orders"})}
- :target {:type "table"
- :schema "public"
- :name "creator_test_table"}})]
-
- (testing "workspace transform has User B as creator"
- (is (= (:id user-b)
- (t2/select-one-fn :creator_id :model/WorkspaceTransform :workspace_id ws-id :ref_id ws-tx-ref-id))))
-
- ;; NOTE: it's user-c merging the workspace
- (let [res (mt/user-http-request user-c :post 200 (ws-url ws-id "/merge")
- {:commit-message "Test creator attribution"})
- new-transform-id (-> res :merged :transforms first :global_id)]
-
- (testing "merge succeeded"
- (is (empty? (:errors res)))
- (is (some? new-transform-id)))
-
- (testing "newly created Transform has User B (ws transform creator) as creator, not User C (merger)"
- (is (= (:id user-b)
- (t2/select-one-fn :creator_id :model/Transform :id new-transform-id))))
-
- (testing "merge history still records User C as the merging user"
- (is (=? {:creator_id (:id user-c)}
- (t2/select-one :model/WorkspaceMerge :workspace_name ws-name))))))))))
-
-(deftest merge-workspace-transaction-failure-test
- (testing "transactions"
- (mt/with-temp [:model/Table _table {:schema "public" :name "merge_test_table"}
- :model/Table _table {:schema "public" :name "merge_test_table_2"}
- :model/Transform x1 {:name "Upstream Transform 1"
- :description "Original description 2"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table"}}
- :model/Transform x2 {:name "Upstream Transform 2"
- :description "Original description 2"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table_2"}}]
- (let [;; Create a workspace
- {ws-id :id} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "Merge test"
- :database_id (mt/id)})
- ;; Add 2 transforms
- {ws-x-1-id :ref_id}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x1)}
- (select-keys x1 [:name :description :source :target])))
- {ws-x-2-id :ref_id}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x2)}
- (select-keys x2 [:name :description :source :target])))
- ;; Ensure deterministic merge order by setting x2's created_at later than x1's.
- x1-created-at (t2/select-one-fn :created_at :model/WorkspaceTransform
- :workspace_id ws-id :ref_id ws-x-1-id)
- _ (t2/update! (t2/table-name :model/WorkspaceTransform) {:workspace_id ws-id :ref_id ws-x-2-id}
- {:created_at (t/plus x1-created-at (t/hours 1))})
-
- ;; Update transform names
- {ws-x-1-id :ref_id :as ws-x-1}
- (mt/user-http-request :crowberto :put 200
- (ws-url ws-id "/transform" ws-x-1-id)
- {:name "UPDATED 1"})
- {ws-x-2-id :ref_id :as ws-x-2}
- (mt/user-http-request :crowberto :put 200
- (ws-url ws-id "/transform" ws-x-2-id)
- {:name "UPDATED 2"})]
-
- (testing "Base: Workspace transforms are updated"
- (testing "X1"
- (is (= "UPDATED 1"
- (t2/select-one-fn :name [:model/WorkspaceTransform :name] :workspace_id ws-id :ref_id ws-x-1-id))))
- (testing "X2"
- (is (= "UPDATED 2"
- (t2/select-one-fn :name [:model/WorkspaceTransform :name] :workspace_id ws-id :ref_id ws-x-2-id)))))
-
- (testing "No updates are propagated back to core app on merge failure"
- (let [update-transform! transforms.core/update-transform!]
- (mt/with-dynamic-fn-redefs [transforms.core/update-transform! (let [call-count (atom 0)]
- (fn [& args]
- (when (> @call-count 0)
- (throw (Exception. "boom")))
- (swap! call-count inc)
- (apply update-transform! args)))]
- (testing "API response: empty merged, single error"
- (let [resp (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/merge"))]
- (is (empty? (get-in resp [:merged :transforms])))
- (is (= 1 (count (:errors resp))))
- (is (= {:op "update"
- :global_id (:id x2)
- :ref_id ws-x-2-id
- :message "boom"}
- (first (:errors resp))))))
- (testing "Core transforms are left unchanged"
- (is (= (:name x1)
- (t2/select-one-fn :name :model/Transform (:id x1))))
- (is (= (:name x2)
- (t2/select-one-fn :name :model/Transform (:id x2)))))
- (testing "Workspace transforms are left unchanged"
- (is (=? (:name ws-x-1)
- (:name (t2/select-one :model/WorkspaceTransform
- :workspace_id ws-id :ref_id (:ref_id ws-x-1)))))
- (is (=? (:name ws-x-2)
- (:name (t2/select-one :model/WorkspaceTransform
- :workspace_id ws-id :ref_id (:ref_id ws-x-2)))))))))))))
-
-(deftest merge-workspace-update-core-test
- (testing "transactions"
- (mt/with-temp [:model/Table _table {:schema "public" :name "merge_test_table"}
- :model/Table _table {:schema "public" :name "merge_test_table_2"}
- :model/Transform x1 {:name "Upstream Transform 1"
- :description "Original description 2"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table"}}
- :model/Transform x2 {:name "Upstream Transform 2"
- :description "Original description 2"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table_2"}}]
- (let [;; Create a workspace
- {ws-id :id} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "Merge test"
- :database_id (mt/id)})
- ;; Add 2 transforms
- {ws-x-1-id :ref_id}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x1)}
- (select-keys x1 [:name :description :source :target])))
- {ws-x-2-id :ref_id}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x2)}
- (select-keys x2 [:name :description :source :target])))
-
- ;; Update transform names
- {ws-x-1-id :ref_id :as ws-x-1}
- (mt/user-http-request :crowberto :put 200
- (ws-url ws-id "/transform" ws-x-1-id)
- {:name "UPDATED 1"})
- {ws-x-2-id :ref_id :as ws-x-2}
- (mt/user-http-request :crowberto :put 200
- (ws-url ws-id "/transform" ws-x-2-id)
- {:name "UPDATED 2"})]
-
- (testing "Global transforms are updated"
- (testing "API response: empty errors, all updates present in merge"
- (let [resp (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/merge"))]
- (is (= 2 (count (get-in resp [:merged :transforms]))))
- (is (= 0 (count (:errors resp))))
- (is (some? (m/find-first #{{:op "update"
- :global_id (:id x1)
- :ref_id ws-x-1-id}}
- (get-in resp [:merged :transforms]))))
- (is (some? (m/find-first #{{:op "update"
- :global_id (:id x2)
- :ref_id ws-x-2-id}}
- (get-in resp [:merged :transforms]))))))
- (testing "Core transforms names are updated"
- (is (= (:name ws-x-1)
- (t2/select-one-fn :name :model/Transform (:id x1))))
- (is (= (:name ws-x-2)
- (t2/select-one-fn :name :model/Transform (:id x2)))))
- (testing "Workspace transforms are not deleted"
- (is (= 2 (t2/count :model/WorkspaceTransform
- :workspace_id ws-id
- :ref_id [:in (map :ref_id [ws-x-1 ws-x-2])])))))
- (testing "Workspace has been archived"
- (is (= :archived (t2/select-one-fn :base_status :model/Workspace :id ws-id))))))))
-
-(deftest merge-empty-workspace-test
- (let [{ws-id :id} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "Merge test"
- :database_id (mt/id)})]
-
- (testing "API response: empty errors, empty updates"
- (let [resp (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/merge"))]
- (is (=? {:errors []
- :merged {:transforms []}}
- resp))))
- (testing "Workspace has been archived"
- (is (= :archived (t2/select-one-fn :base_status :model/Workspace :id ws-id))))))
-
-(deftest merge-transfom-test
- (mt/with-temp [:model/Table _table {:schema "public" :name "merge_test_table"}
- :model/Table _table {:schema "public" :name "merge_test_table_2"}
- :model/Transform x1 {:name "Upstream Transform 1"
- :description "Original description 2"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table"}}
- :model/Transform x2 {:name "Upstream Transform 2"
- :description "Original description 2"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table_2"}}]
- (let [;; Create a workspace
- {ws-id :id} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "Merge test"
- :database_id (mt/id)})
- ;; Add 2 transforms
- {ws-x-1-id :ref_id}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x1)}
- (select-keys x1 [:name :description :source :target])))
- {ws-x-2-id :ref_id}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x2)}
- (select-keys x2 [:name :description :source :target])))
-
- ;; Update transform names
- {ws-x-1-id :ref_id :as ws-x-1}
- (mt/user-http-request :crowberto :put 200
- (ws-url ws-id "/transform" ws-x-1-id)
- {:name "UPDATED 1"})
- {ws-x-2-id :ref_id :as ws-x-2}
- (mt/user-http-request :crowberto :put 200
- (ws-url ws-id "/transform" ws-x-2-id)
- {:name "UPDATED 2"})]
- (testing "Merging first of 2 workspace transfroms"
- (let [commit-msg "Single transform merge 1"
- resp (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform" ws-x-1-id "/merge")
- {:commit-message commit-msg})
- remaining (t2/select :model/WorkspaceTransform :workspace_id ws-id)]
- (testing "Response"
- (is (empty? (:errors resp)))
- (is (= {:op "update"
- :global_id (:id x1)
- :ref_id ws-x-1-id}
- resp)))
- (testing "Workspace transforms are left untouched"
- (is (= 2 (count remaining)))
- (is (=? (into #{} (map :name [ws-x-1 ws-x-2]))
- (into #{} (map :name remaining)))))
- (testing "Propagation back to core"
- (is (= (:name ws-x-1)
- (t2/select-one-fn :name :model/Transform :id (:global_id resp)))))
- (testing "merge history was created for single transform merge"
- (let [merge-transform (t2/select-one :model/WorkspaceMergeTransform
- :transform_id (:id x1))]
- (is (=? {:workspace_merge_id pos-int?
- :transform_id (:id x1)
- :commit_message commit-msg}
- merge-transform))
- (testing "workspace_merge record was also created"
- (is (=? {:commit_message commit-msg
- :creator_id (mt/user->id :crowberto)}
- (t2/select-one :model/WorkspaceMerge
- :id (:workspace_merge_id merge-transform)))))))))
- (testing "Merging last workspace transfrom"
- (let [resp (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform" ws-x-2-id "/merge"))
- remaining (t2/select :model/WorkspaceTransform :workspace_id ws-id)]
- (testing "Response"
- (is (empty? (:errors resp)))
- (is (= {:op "update"
- :global_id (:id x2)
- :ref_id ws-x-2-id}
- resp)))
- (testing "Workspace transforms still remain"
- (is (= 2 (count remaining))))
- (testing "Propagation back to core"
- (is (= (:name ws-x-2)
- (t2/select-one-fn :name :model/Transform :id (:global_id resp)))))
- (testing "Workspace is not archived nor deleted"
- (let [ws-after (t2/select-one :model/Workspace :id ws-id)]
- (is (some? ws-after))
- (is (not= :archived (:status ws-after))))))))))
-
-(deftest merge-history-endpoint-test
- (mt/with-premium-features #{:transforms-basic :transforms-python :workspaces}
- (testing "GET /api/transform/:id/merge-history"
- (mt/with-temp [:model/Table _table {:schema "public" :name "merge_history_test_table"}
- :model/Transform x1 {:name "Transform for history"
- :description "Test transform"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_history_test_table"}}]
- (let [{ws-id :id ws-name :name} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name (mt/random-name)
- :database_id (mt/id)})
- {ws-tx-ref-id :ref_id} (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x1)}
- (select-keys x1 [:name :description :source :target])))
- commit-msg "Test merge for history endpoint"]
- ;; Modify and merge the transform
- (t2/update! :model/WorkspaceTransform {:workspace_id ws-id :ref_id ws-tx-ref-id} {:description "Modified for history test"})
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/merge")
- {:commit-message commit-msg})
-
- (testing "returns merge history for a transform"
- ;; workspace_id is preserved since workspace is archived (not deleted) after merge
- (is (=? [{:id pos-int?
- :workspace_merge_id pos-int?
- :commit_message commit-msg
- :workspace_id ws-id
- :workspace_name ws-name
- :merging_user_id (mt/user->id :crowberto)
- :created_at some?}]
- (mt/user-http-request :crowberto :get 200
- (str "transform/" (:id x1) "/merge-history")))))
-
- (testing "returns 404 for non-existent transform"
- (is (= "Not found."
- (mt/user-http-request :crowberto :get 404
- "transform/999999/merge-history"))))
-
- (testing "requires superuser"
- (is (= "You don't have permissions to do that."
- (mt/user-http-request :rasta :get 403
- (str "transform/" (:id x1) "/merge-history"))))))))))
-
-(deftest merge-single-transform-failure-test
- (mt/with-temp [:model/Table _table {:schema "public" :name "merge_test_table"}
- :model/Transform x1 {:name "Upstream Transform 1"
- :description "Original description 2"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table"}}]
- (let [;; Create a workspace
- {ws-id :id} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "Merge test"
- :database_id (mt/id)})
- ;; Add transform
- {ws-x-1-id :ref_id :as ws-x-1}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x1)}
- (select-keys x1 [:name :description :source :target])))
-
- _ (mt/user-http-request :crowberto :post 204
- (ws-url ws-id "/transform" ws-x-1-id "/archive"))]
- (testing "Failure on merge"
- (mt/with-dynamic-fn-redefs [transforms.core/delete-transform! (fn [& _args]
- (throw (Exception. "boom")))]
- (let [resp (mt/user-http-request :crowberto :post 500
- (ws-url ws-id "/transform" ws-x-1-id "/merge"))]
- (testing "Response"
- (is (=? {:op "delete"
- :global_id (:id x1)
- :ref_id ws-x-1-id
- :message "Failed to merge transform."}
- resp)))
- (testing "no changes"
- (let [ws-xs (t2/select :model/WorkspaceTransform :workspace_id ws-id)]
- (is (= 1 (count ws-xs)))
- (is (= (:name ws-x-1)
- (:name (first ws-xs))))))))))))
-
-(deftest merging-multiple-transforms-incl-ws-only-test
- (let [mp (mt/metadata-provider)]
- (mt/with-temp [:model/Table _table {:schema "public" :name "merge_test_table"}
- :model/Table _table {:schema "public" :name "merge_test_table_2"}
- :model/Table _table {:schema "public" :name "merge_test_table_3"}
- :model/Transform x1 {:name "Upstream Transform 1"
- :description "Original description 2"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table"}}
- :model/Transform x2 {:name "Upstream Transform 2"
- :description "Original description 2"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "merge_test_table_2"}}]
- (let [;; Create a workspace
- {ws-id :id} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "Merge test"
- :database_id (mt/id)})
- ;; Add 2 transforms
- {ws-x-1-id :ref_id :as ws-x-1}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x1)}
- (select-keys x1 [:name :description :source :target])))
- {ws-x-2-id :ref_id}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id (:id x2)}
- (select-keys x2 [:name :description :source :target])))
- ;; Update first
- _ (mt/user-http-request :crowberto :put 200
- (ws-url ws-id "/transform" ws-x-1-id)
- {:name "UPDATED 1"})
- ;; Archive second
- _ (mt/user-http-request :crowberto :post 204
- (ws-url ws-id "/transform" ws-x-2-id "/archive"))
- ;; And add _workspace only transform_
- {ws-x-3-id :ref_id :as ws-x-3}
- (mt/user-http-request :crowberto :post 200
- (ws-url ws-id "/transform")
- {:name "WS only transform"
- :description "this is ws only x"
- :source {:type :query
- :database (mt/id)
- :query (lib/native-query mp "select 1")}
- :target {:type "table"
- :schema "public"
- :name "merge_test_table_3"}})]
- (testing "Merge all 3"
- (let [resp (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/merge"))
- new-global-id (:global_id (m/find-first (comp #{"create"} :op) (get-in resp [:merged :transforms])))]
- (testing "Response"
- (is (empty? (:errors resp)))
- (is (some? (m/find-first
- #{{:op "update"
- :global_id (:id x1)
- :ref_id ws-x-1-id}}
- (get-in resp [:merged :transforms]))))
- (is (some? (m/find-first
- #{{:op "delete"
- :global_id (:id x2)
- :ref_id ws-x-2-id}}
- (get-in resp [:merged :transforms]))))
- (is (some? (m/find-first
- #{{:op "create"
- :global_id new-global-id
- :ref_id ws-x-3-id}}
- (get-in resp [:merged :transforms])))))
- (testing "No transforms are deleted on merge"
- (is (= 3 (count (t2/select :model/WorkspaceTransform :workspace_id ws-id)))))
- (testing "Propagation back to core"
- (is (= "UPDATED 1"
- (t2/select-one-fn :name :model/Transform :id (:global_id ws-x-1))))
- (is (not (t2/exists? :model/Transform :id (:id x2))))
- (is (= (:name ws-x-3)
- (t2/select-one-fn :name :model/Transform :id new-global-id))))))))))
-
-(deftest create-workspace-transform-archived-test
- (testing "Cannot create transform in archived workspace"
- (ws.tu/with-workspaces! [workspace {:name "Archived"}]
- (t2/update! :model/Workspace (:id workspace) {:base_status :archived})
- (is (= "Cannot create transforms in an archived workspace"
- (mt/user-http-request :crowberto :post 400 (ws-url (:id workspace) "/transform")
- {:name "Should Fail"
- :source {:type "query"
- :query (q :venues)}
- :target {:type "table"
- :name "should_fail"}}))))))
-
-(deftest add-transforms-to-workspace-test
- (testing "Add transforms to workspace via POST /transform"
- (with-transform-cleanup! [orig-name "ws_add_transforms_test"]
- (mt/with-temp [:model/Transform {x1-id :id :as x1} {:name "Transform to Check Out"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name orig-name}}]
- (let [{ws-id :id} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "Add Transforms Test"
- :database_id (mt/id)})]
- (is (int? ws-id))
- (testing "Can check out a global transform into workspace"
- (let [response (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- (merge {:global_id x1-id}
- (select-keys x1 [:name :description :source :target])))]
- (is (=? {:ref_id string?
- :global_id x1-id
- :name "Transform to Check Out"
- :target_stale true}
- response))
- (is (= response (mt/user-http-request :crowberto :get 200 (ws-url ws-id "/transform" (:ref_id response)))))))
-
- (testing "Can create a new provisional transform"
- (let [response (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- {:name "New Transform"
- :source {:type "query"
- :query (->native (q :venues))}
- :target {:type "table"
- :name "new_transform_output"}})]
-
- ;; Fetch the graph, to trigger analysis
- (is (=? {:ref_id string?
- :global_id nil?
- :name "New Transform"
- :target_stale true
- ;; TODO (Chris 2026-01-07) -- this is now only populated lazily - is this OK?
- #_#_:target_isolated {:type "table"
- :database pos-int?
- :schema string?
- :name string?}}
- response))
- (is (= response (mt/user-http-request :crowberto :get 200 (ws-url ws-id "transform" (:ref_id response)))))))
-
- (testing "Cannot add transforms to archived workspace"
- (t2/update! :model/Workspace ws-id {:base_status :archived})
- (is (= "Cannot create transforms in an archived workspace"
- (mt/user-http-request :crowberto :post 400 (ws-url ws-id "/transform")
- {:name "Should Fail"
- :source {:type "query"
- :query (->native (q :venues))}
- :target {:type "table"
- :name "should_fail"}})))))))))
-
-(deftest create-workspace-transform-test
- (mt/dataset transforms-dataset/transforms-test
- (let [{ws-id :id} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "Test Workspace"
- :database_id (mt/id)})]
- (with-transform-cleanup! [table-name "workspace_transform_test"]
- (is (=? {:ref_id string?
- :workspace_id ws-id
- ;:creator_id (mt/user->id :crowberto)
- :target {:database (mt/id)}}
- (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform")
- {:name "Workspace Transform"
- :source {:type "query"
- :query (->native (q :transforms_products))}
- :target {:type "table"
- :name table-name}})))
- (is (=? {:id ws-id, :status "ready"}
- (mt/user-http-request :crowberto :get 200 (ws-url ws-id))))
- (is (=? {:transforms [{:ref_id string?, :name "Workspace Transform", :source_type "native"}]}
- (mt/user-http-request :crowberto :get 200 (ws-url ws-id "/transform"))))))))
-
-(deftest tables-endpoint-empty-ws-test
- (let [user-id (mt/user->id :crowberto)
- ws (mt/user-http-request :crowberto :post 200 "ee/workspace/"
- {:name "My test ws"
- :creator_id user-id
- :database_id (mt/id)})]
- (is (= {:inputs []
- :outputs []}
- (mt/user-http-request :crowberto :get 200 (ws-url (:id ws) "/table"))))))
-
-(deftest tables-endpoint-transform-not-run-test
- (with-transform-cleanup! [orig-name "ws_tables_not_run_test"]
- (mt/with-temp [:model/Transform x1 {:name "My X1"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/limit 10)))}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name orig-name}}]
- (let [{ws-id :id} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "Test Workspace"
- :database_id (mt/id)})
- ;; add the transform
- req (assoc (select-keys x1 [:name :description :source :target]) :global_id (:id x1))
- ref-id (:ref_id (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/transform") req))
- ;; get the tables
- tables-result (mt/user-http-request :crowberto :get 200 (ws-url ws-id "/table"))]
- (testing "/tables returns expected results"
- (is (=? {:inputs [{:db_id (mt/id), :schema (t2/select-one-fn :schema :model/Table (mt/id :orders)), :table "orders", :table_id int?}]
- :outputs [{:db_id (mt/id)
- :global {:schema "public", :table orig-name}
- :isolated {:transform_id ref-id}}]}
- tables-result)))))))
-
-(deftest tables-endpoint-test
- (let [mp (mt/metadata-provider)
- ;; Following needed for driver specific sql.
- orders-meta (lib.metadata/table mp (mt/id :orders))
- sql-str (-> (lib/query mp orders-meta)
- (lib/limit 10)
- (qp.compile/compile)
- :query)
- query (lib/native-query mp sql-str)
- orig-schema (or (:schema orders-meta) (driver.sql/default-schema driver/*driver*))
- orig-name (:name orders-meta)
- target-schema (driver.sql/default-schema driver/*driver*)]
- (with-transform-cleanup! [target-name "ws_tables_endpoint_test"]
- (mt/with-temp [:model/Transform x1 {:name "My X1"
- :source {:type "query"
- :query query}
- :target {:type "table"
- :database (mt/id)
- :schema target-schema
- :name target-name}}]
- ;; create the global table
- (transforms.execute/execute! x1 {:run-method :manual})
- (ws.tu/with-workspaces! [workspace {:name "Test Workspace"
- :database_id (mt/id)}]
- (let [body {:name (:name x1)
- :source (:source x1)
- :target (:target x1)}
- ws-transform (ws.common/add-to-changeset! (mt/user->id :crowberto) workspace :transform (:id x1) body)
- workspace (ws.tu/ws-done! (:id workspace))
- ref-id (:ref_id ws-transform)
- orig-id (t2/select-one-fn :id [:model/Table :id]
- :db_id (:database_id workspace)
- :schema (-> ws-transform :target :schema)
- :name (-> ws-transform :target :name))]
- (testing "/table returns expected results"
- ;; Schema is normalized to driver's default schema ("public" for Postgres) when stored
- (is (=? {:inputs [{:db_id (mt/id), :schema orig-schema, :table orig-name, :table_id int?}]
- :outputs
- [{:db_id (mt/id)
- :global {:schema target-schema
- :table target-name
- :table_id orig-id}
- :isolated {:transform_id ref-id
- #_#_:schema (:schema workspace)
- :table string?
- :table_id int?}}]}
- (mt/user-http-request :crowberto :get 200 (ws-url (:id workspace) "/table")))))
- (testing "and after we run the transform, id for isolated table appears"
- (is (=? {:status "succeeded"}
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "transform" ref-id "run"))))
- (is (=? {:inputs [{:db_id (mt/id), :schema orig-schema, :table orig-name, :table_id int?}]
- :outputs
- [{:db_id (mt/id)
- :global {:schema target-schema
- :table target-name
- :table_id orig-id}
- :isolated {:transform_id ref-id
- :schema (:schema workspace)
- ;; maybe this is a bit too specific, but gives me a peace of mind for now
- :table (ws.u/isolated-table-name target-schema target-name)
- :table_id int?}}]}
- (mt/user-http-request :crowberto :get 200 (ws-url (:id workspace) "/table")))))))))))
-
-;; TODO (Chris 2025-12-12) -- write a test for /table that covers the shadowing
-;; e.g. have two transforms in a chain connecting 3 tables: (A -> X1 -> B -> X2 -> C)
-;; raw-inputs: A (from X1) and B (from X2)
-;; outputs: B (from X1) and C (from X2)
-;; external-inputs: A (raw-inputs - outputs)
-
-(deftest rename-workspace-test
- (testing "POST /api/ee/workspace/:id/name updates the workspace name"
- (ws.tu/with-workspaces! [workspace {:name "Original Name"}]
- (let [response (mt/user-http-request :crowberto :put 200 (ws-url (:id workspace))
- {:name "Updated Name"})]
- (is (= "Updated Name"
- (:name response)
- (t2/select-one-fn :name :model/Workspace :id (:id workspace)))))))
-
- (testing "Cannot rename an archived workspace"
- (ws.tu/with-workspaces! [workspace {:name "Archived"}]
- (t2/update! :model/Workspace (:id workspace) {:base_status :archived})
- (is (= "Cannot update an archived workspace"
- (mt/user-http-request :crowberto :put 400 (ws-url (:id workspace))
- {:name "Should Fail"}))))))
-
-(deftest validate-target-test
- (let [table (t2/select-one :model/Table :db_id (mt/id) :active true {:where [:not [:like :schema "mb__%"]]})]
- (ws.tu/with-workspaces! [ws {:name "test" :database_id (:db_id table)}]
- (mt/with-temp [:model/WorkspaceTransform x1 {:workspace_id (:id ws)
- :target {:database (:db_id table)
- :type "table"
- :schema (:schema table)
- :name (str "q_" (:name table))}}]
- (testing "Unique"
- (is (= "OK"
- (mt/with-log-level [metabase.driver.sql-jdbc.sync.describe-table :fatal]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/transform/validate/target")
- {:db_id (:db_id table)
- :target {:type "table"
- :schema "public"
- :name (str/replace (str (random-uuid)) "-" "_")}})))))
- ;; We've decided to defer this error until merge.
- ;; Also, this logic is going to become more relaxed, where we're allowed to take over a "dormant" table.
- #_(testing "Conflict outside of workspace"
- (is (= "A table with that name already exists."
- (mt/user-http-request :crowberto :post 403 (ws-url (:id ws) "/transform/validate/target")
- {:db_id (:db_id table)
- :target {:type "table"
- :schema (:schema table)
- :name (:name table)}}))))
- (testing "Must not target the isolated schema"
- (is (= "Must not target an isolated workspace schema"
- (mt/with-log-level [metabase.driver.sql-jdbc.sync.describe-table :fatal]
- (mt/user-http-request :crowberto :post 403 (ws-url (:id ws) "/transform/validate/target")
- {:db_id (:db_id table)
- :target {:type "table"
- ;; TODO (Chris 2026-01-05) -- the schema on the workspace is only set as part of adding tx
- :schema "mb__isolation_blah" #_(:schema ws)
- :name (str "q_" (:name table))}})))))
-
- (testing "Conflict inside of workspace"
- (is (= "Another transform in this workspace already targets that table"
- (mt/with-log-level [metabase.driver.sql-jdbc.sync.describe-table :fatal]
- (mt/user-http-request :crowberto :post 403 (ws-url (:id ws) "/transform/validate/target")
- {:db_id (:db_id table)
- :target {:type "table"
- :schema (:schema table)
- :name (str "q_" (:name table))}})))))
-
- (testing "No self-conflict when transform-id matches"
- (is (= "OK"
- (mt/with-log-level [metabase.driver.sql-jdbc.sync.describe-table :fatal]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/transform/validate/target")
- {:db_id (:db_id table)
- :target {:type "table"
- :schema (:schema table)
- :name (str "q_" (:name table))}}
- :transform-id (:ref_id x1))))))))))
-
-;;;; Async workspace creation tests
-
-(deftest workspace-log-endpoint-test
- (testing "GET /api/ee/workspace/:id/log returns status and log entries"
- (let [{ws-id :id} (ws.tu/create-ready-ws! "Log tester")]
- (is (=? {:workspace_id ws-id
- :status "ready"
- :updated_at some?
- :last_completed_at some?
- :logs [{:task "database-isolation"
- :status "success"}
- {:task "workspace-setup"}]}
- (mt/user-http-request :crowberto :get 200 (ws-url ws-id "/log")))))))
-
-(deftest workspace-log-endpoint-404-test
- (testing "GET /api/ee/workspace/:id/log returns 404 for non-existent workspace"
- (is (= "Not found."
- (mt/user-http-request :crowberto :get 404 "ee/workspace/999999/log")))))
-
-(deftest workspace-log-entries-created-test
- (testing "WorkspaceLog entries are created during setup"
- (let [{ws-id :id} (ws.tu/create-ready-ws! "Log tester #2")]
- (is (=? [{:task :database-isolation
- :status :success}
- {:task :workspace-setup
- :status :success}]
- (t2/select :model/WorkspaceLog :workspace_id ws-id {:order-by [[:started_at :desc]]}))))))
-
-(deftest workspace-setup-failure-logs-error-test
- (testing "Failed workspace setup logs error message"
- (mt/with-dynamic-fn-redefs [ws.isolation/ensure-database-isolation!
- (fn [& _] (throw (ex-info "Test isolation error" {})))]
- (let [{ws-id :id} (ws.tu/initialize-ws! "Log tester #3")]
- (is (=? [{:task :database-isolation
- :status :failure
- :message "Test isolation error"}
- {:task :workspace-setup
- :status :failure}]
- (t2/select :model/WorkspaceLog :workspace_id ws-id {:order-by [[:started_at :desc]]})))))))
-
-;;; ---------------------------------------- Uninitialized Workspace Tests ----------------------------------------
-
-(deftest uninitialized-workspace-lifecycle-test
- (testing "Workspace can be created without database_id (uses provisional default)"
- (let [{ws-id :id :as ws} (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "uninitialized-lifecycle"})]
- ;; database_id is set to provisional default, but :status is uninitialized
- (is (=? {:status "uninitialized" :database_id pos-int?} ws))
- (testing "can be archived and deleted"
- (is (= "archived" (:status (mt/user-http-request :crowberto :post 200 (ws-url ws-id "/archive")))))
- (is (= {:ok true} (mt/user-http-request :crowberto :delete 200 (ws-url ws-id))))
- (is (not (t2/exists? :model/Workspace :id ws-id)))))))
-
-(deftest ^:synchronized initialize-uninitialized-workspace-test
- (testing "via adding transform"
- (let [ws (mt/user-http-request :crowberto :post 200 "ee/workspace"
- {:name "init-via-transform"})]
- (is (= "uninitialized" (:status ws)))
- (let [transform (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/transform")
- {:name "New Transform"
- :source {:type "query"
- :query (->native (q :venues))}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "init_transform_output"}})]
- (is (some? (:ref_id transform)))
- (let [ws (ws.tu/ws-done! ws)]
- (is (=? {:db_status :ready
- :database_id (mt/id)}
- ws)))
- (testing "PUT database_id fails on already initialized workspace"
- (is (= "Can only set database_id on uninitialized workspace"
- (mt/user-http-request :crowberto :put 400 (ws-url (:id ws))
- {:database_id (mt/id)}))))))))
-
-;;; ---------------------------------------- Workspace Transform CRUD Tests ----------------------------------------
-
-(deftest get-workspace-transforms-test
- (testing "GET /api/ee/workspace/:id/transform"
- (ws.tu/with-workspaces! [workspace {:name "List Transforms Test"}]
- (mt/with-temp [:model/WorkspaceTransform tx1 {:name "Transform 1"
- :workspace_id (:id workspace)}
- :model/WorkspaceTransform tx2 {:name "Transform 2"
- :workspace_id (:id workspace)}
- :model/Transform _tx3 {:name "Global Transform"}]
- (testing "returns transforms in workspace"
- (is (=? {:transforms [{:ref_id (:ref_id tx1)}
- {:ref_id (:ref_id tx2)}]}
- (mt/user-http-request :crowberto :get 200 (ws-url (:id workspace) "/transform")))))
- (testing "returns empty list when no transforms"
- (ws.tu/with-workspaces! [workspace {:name "Empty Workspace"}]
- (is (= {:transforms []}
- (mt/user-http-request :crowberto :get 200 (ws-url (:id workspace) "/transform"))))))
- (testing "returns 404 for non-existent workspace"
- (is (= "Not found."
- (mt/user-http-request :crowberto :get 404 "ee/workspace/999999/transform"))))))))
-
-(deftest get-workspace-transform-by-id-test
- (testing "GET /api/ee/workspace/:id/transform/:txid"
- (ws.tu/with-workspaces! [workspace1 {:name "Workspace 1"}
- workspace2 {:name "Workspace 2"}]
- (mt/with-temp [:model/WorkspaceTransform transform {:name "My Transform"
- :description "Test description"
- :workspace_id (:id workspace1)}]
- (testing "returns specific transform"
- (is (=? {:ref_id (:ref_id transform)
- :name "My Transform"
- :description "Test description"}
- (mt/user-http-request :crowberto :get 200
- (ws-url (:id workspace1) "/transform" (:ref_id transform))))))
- (testing "returns 404 if transform not in workspace"
- (is (= "Not found."
- (mt/user-http-request :crowberto :get 404
- (ws-url (:id workspace2) "/transform" (:ref_id transform))))))))))
-
-(deftest update-workspace-transform-test
- (testing "PUT /api/ee/workspace/:id/transform/:txid"
- (ws.tu/with-workspaces! [workspace1 {:name "Workspace 1"}
- workspace2 {:name "Workspace 2"}]
- (mt/with-temp [:model/WorkspaceTransform transform {:name "Original Name"
- :description "Original description"
- :workspace_id (:id workspace1)}]
- (testing "updates transform"
- (is (=? {:ref_id (:ref_id transform)
- :name "Updated Name"
- :description "Updated description"}
- (mt/user-http-request :crowberto :put 200
- (ws-url (:id workspace1) "/transform" (:ref_id transform))
- {:name "Updated Name"
- :description "Updated description"})))
- (is (= "Updated Name" (t2/select-one-fn :name :model/WorkspaceTransform :workspace_id (:id workspace1) :ref_id (:ref_id transform)))))
- (testing "returns 400 if transform not in workspace (upsert requires all fields)"
- ;; With upsert behavior, PUT to non-existent transform attempts to create,
- ;; so missing required fields returns 400 instead of 404
- (is (= "source is required when creating a new transform"
- (mt/user-http-request :crowberto :put 400
- (ws-url (:id workspace2) "/transform" (:ref_id transform))
- {:name "Should Fail"}))))))))
-
-(deftest ^:synchronized put-workspace-transform-target-conflict-test
- (testing "PUT /api/ee/workspace/:id/transform/:txid returns 400 when updating target to conflict"
- (let [target-schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
- (ws.tu/with-workspaces! [workspace {:name "Workspace 1" :database_id (mt/id)}]
- ;; Create two transforms with different targets via POST API
- (let [tx1 (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/transform")
- {:name "Transform 1"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :schema target-schema
- :name "target_table_1"}})
- _tx2 (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/transform")
- {:name "Transform 2"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :schema target-schema
- :name "target_table_2"}})]
- (testing "updating target to match another transform's target returns 400"
- (is (= "Another transform in this workspace already targets that table"
- (mt/user-http-request :crowberto :put 400
- (ws-url (:id workspace) "/transform" (:ref_id tx1))
- {:target {:type "table"
- :schema target-schema
- :name "target_table_2"}}))))
- (testing "updating target to a unique table succeeds"
- (is (=? {:ref_id (:ref_id tx1)}
- (mt/user-http-request :crowberto :put 200
- (ws-url (:id workspace) "/transform" (:ref_id tx1))
- {:target {:type "table"
- :schema target-schema
- :name "target_table_3"}}))))
- (testing "updating non-target fields doesn't trigger conflict check"
- (is (=? {:ref_id (:ref_id tx1)
- :name "Renamed Transform 1"}
- (mt/user-http-request :crowberto :put 200
- (ws-url (:id workspace) "/transform" (:ref_id tx1))
- {:name "Renamed Transform 1"})))))))))
-
-(deftest ^:synchronized upsert-workspace-transform-test
- (testing "PUT /api/ee/workspace/:id/transform/:txid (upsert behavior)"
- (let [target-schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
- (ws.tu/with-workspaces! [workspace {:name "Workspace 1" :database_id (mt/id)}]
- (let [new-ref-id (ws.u/generate-ref-id)]
- (testing "creates new transform when ref_id doesn't exist"
- (let [result (mt/user-http-request :crowberto :put 200
- (ws-url (:id workspace) "/transform" new-ref-id)
- {:name "New Transform via Upsert"
- :source {:type "query"
- :query (-> (q :orders) (lib/aggregate (lib/count)) ->native)}
- :target {:type "table"
- :schema target-schema
- :name "upsert_test_table"}})]
- (is (=? {:ref_id new-ref-id
- :name "New Transform via Upsert"
- :source {:type "query"}}
- result))
- (is (t2/exists? :model/WorkspaceTransform :workspace_id (:id workspace) :ref_id new-ref-id))))
-
- (testing "updates existing transform with same ref_id"
- (let [result (mt/user-http-request :crowberto :put 200
- (ws-url (:id workspace) "/transform" new-ref-id)
- {:name "Updated Transform Name"})]
- (is (=? {:ref_id new-ref-id
- :name "Updated Transform Name"}
- result))
- (is (= "Updated Transform Name"
- (t2/select-one-fn :name :model/WorkspaceTransform :workspace_id (:id workspace) :ref_id new-ref-id))))))))))
-
-(deftest upsert-transform-missing-required-fields-test
- (testing "PUT /api/ee/workspace/:id/transform/:txid returns 400 when creating without required fields"
- (ws.tu/with-workspaces! [workspace {:name "Workspace 1" :database_id (mt/id)}]
- (let [target-schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
- (testing "missing name returns 400"
- (let [ref-id (ws.u/generate-ref-id)]
- (is (= "name is required when creating a new transform"
- (mt/user-http-request :crowberto :put 400
- (ws-url (:id workspace) "/transform" ref-id)
- {:source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :schema target-schema
- :name "missing_name_test"}})))))
- (testing "missing source returns 400"
- (let [ref-id (ws.u/generate-ref-id)]
- (is (= "source is required when creating a new transform"
- (mt/user-http-request :crowberto :put 400
- (ws-url (:id workspace) "/transform" ref-id)
- {:name "Test Transform"
- :target {:type "table"
- :schema target-schema
- :name "missing_source_test"}})))))
- (testing "missing target returns 400"
- (let [ref-id (ws.u/generate-ref-id)]
- (is (= "target is required when creating a new transform"
- (mt/user-http-request :crowberto :put 400
- (ws-url (:id workspace) "/transform" ref-id)
- {:name "Test Transform"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}})))))))))
-
-(deftest upsert-transform-archived-workspace-test
- (testing "PUT /api/ee/workspace/:id/transform/:txid returns 400 for archived workspace"
- (ws.tu/with-workspaces! [workspace {:name "Workspace 1" :database_id (mt/id)}]
- ;; Archive the workspace
- (t2/update! :model/Workspace (:id workspace) {:base_status :archived})
- (let [new-ref-id (ws.u/generate-ref-id)
- target-schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
- (is (= "Cannot create transforms in an archived workspace"
- (mt/user-http-request :crowberto :put 400
- (ws-url (:id workspace) "/transform" new-ref-id)
- {:name "New Transform"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :schema target-schema
- :name "archived_ws_test"}})))))))
-
-(deftest ^:synchronized upsert-transform-internal-target-conflict-test
- (testing "PUT /api/ee/workspace/:id/transform/:txid returns 400 for internal target conflict"
- (let [target-schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
- (ws.tu/with-workspaces! [workspace {:name "Workspace 1" :database_id (mt/id)}]
- ;; Create first transform targeting a specific table via POST API
- (mt/user-http-request :crowberto :post 200 (ws-url (:id workspace) "/transform")
- {:name "Existing Transform"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :schema target-schema
- :name "conflict_target_table"}})
- ;; Try to upsert a new transform with the same target
- (let [new-ref-id (ws.u/generate-ref-id)]
- (is (= "Another transform in this workspace already targets that table"
- (mt/user-http-request :crowberto :put 400
- (ws-url (:id workspace) "/transform" new-ref-id)
- {:name "Conflicting Transform"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :schema target-schema
- :name "conflict_target_table"}}))))))))
-
-(deftest ^:synchronized upsert-transform-initializes-workspace-test
- (testing "PUT /api/ee/workspace/:id/transform/:txid initializes uninitialized workspace"
- (let [target-schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
- (ws.tu/with-workspaces! [workspace {:name "Uninitialized WS"}]
- ;; Verify workspace starts uninitialized
- (is (= :uninitialized (:db_status (t2/select-one :model/Workspace :id (:id workspace)))))
- (let [new-ref-id (ws.u/generate-ref-id)]
- (mt/user-http-request :crowberto :put 200
- (ws-url (:id workspace) "/transform" new-ref-id)
- {:name "First Transform"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :database (mt/id)
- :schema target-schema
- :name "init_ws_test"}})
- ;; Verify workspace is now initialized
- (let [ws (t2/select-one :model/Workspace :id (:id workspace))]
- (is (not= :uninitialized (:db_status ws)))))))))
-
-(deftest ^:synchronized upsert-transform-transitions-base-status-test
- (testing "PUT /api/ee/workspace/:id/transform/:txid transitions base_status from :empty to :active"
- (let [target-schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
- (ws.tu/with-workspaces! [workspace {:name "Empty WS" :database_id (mt/id)}]
- ;; Verify workspace starts with :empty base_status
- (is (= :empty (:base_status (t2/select-one :model/Workspace :id (:id workspace)))))
- (let [new-ref-id (ws.u/generate-ref-id)]
- (mt/user-http-request :crowberto :put 200
- (ws-url (:id workspace) "/transform" new-ref-id)
- {:name "First Transform"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :schema target-schema
- :name "status_transition_test"}})
- ;; Verify base_status transitioned to :active
- (is (= :active (:base_status (t2/select-one :model/Workspace :id (:id workspace))))))))))
-
-(deftest delete-workspace-transform-test
- (testing "DELETE /api/ee/workspace/:id/transform/:txid"
- (ws.tu/with-workspaces! [workspace1 {:name "Workspace 1"}
- workspace2 {:name "Workspace 2"}]
- (mt/with-temp [:model/WorkspaceTransform transform1 {:name "Transform in WS1"
- :workspace_id (:id workspace1)}
- :model/WorkspaceTransform transform2 {:name "To Delete"
- :workspace_id (:id workspace1)}]
- (is (:ref_id transform1) "Transform 1 created successfully")
- (is (:ref_id transform2) "Transform 2 created successfully")
- (testing "returns 404 if transform not in workspace"
- (is (= "Not found."
- (mt/user-http-request :crowberto :delete 404
- (ws-url (:id workspace2) "/transform" (:ref_id transform1))))))
- (testing "deletes transform"
- (is (nil? (mt/user-http-request :crowberto :delete 204
- (ws-url (:id workspace1) "/transform" (:ref_id transform2)))))
- (is (t2/exists? :model/WorkspaceTransform :workspace_id (:id workspace1) :ref_id (:ref_id transform1)))
- (is (not (t2/exists? :model/WorkspaceTransform :workspace_id (:id workspace1) :ref_id (:ref_id transform2)))))))))
-
-(deftest run-workspace-transform-not-found-test
- (testing "POST /api/ee/workspace/:id/transform/:txid/run returns 404 if transform not in workspace"
- (transforms.tu/with-transform-cleanup! [output-table "ws_api_notfound"]
- (ws.tu/with-workspaces! [ws1 {:name "Workspace 1"}
- ws2 {:name "Workspace 2"}]
- (mt/with-temp [:model/Transform x1 {:name "Transform in WS1"
- :source {:type "query"
- :query (mt/native-query {:query "SELECT count(*) from orders"})}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name output-table}}]
- (let [ref-id (:ref_id (mt/user-http-request :crowberto :post 200 (ws-url (:id ws1) "/transform") x1))]
- (is (= "Not found."
- (mt/user-http-request :crowberto :post 404
- (ws-url (:id ws2) "/transform/" ref-id "/run"))))))))))
-
-(deftest run-workspace-transform-success-test
- (testing "POST /api/ee/workspace/:id/transform/:txid/run successful execution"
- (transforms.tu/with-transform-cleanup! [output-table "ws_api_success"]
- (ws.tu/with-workspaces! [ws {:name "Workspace 1"}]
- (let [target-schema (t2/select-one-fn :schema :model/Table (mt/id :orders))]
- (mt/with-temp [:model/Transform x1 {:name "Transform"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :database (mt/id)
- :schema target-schema
- :name output-table}}]
- (let [ref-id (:ref_id (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/transform") x1))
- ws (ws.tu/ws-done! (:id ws))]
- (testing "returns succeeded status with isolated table info"
- (let [result (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "transform" ref-id "run"))]
- (is (=? {:status "succeeded"
- :message nil
- :start_time some?
- :end_time some?
- :table {:schema (:schema ws)
- :name (str target-schema "__" output-table)}}
- result))))
- (testing "doesn't create excessive transforms in the db"
- (is (= (:id x1)
- (t2/select-one-fn :id [:model/Transform :id] {:order-by [[:id :desc]]}))))
- (testing "transform has last_run_at and last_run_status after success"
- (is (=? {:last_run_at some?
- :last_run_status "succeeded"}
- (mt/user-http-request :crowberto :get 200 (ws-url (:id ws) "transform" ref-id))))))))))))
-
-(deftest run-workspace-transform-failure-test
- (testing "POST /api/ee/workspace/:id/transform/:txid/run failed execution"
- (transforms.tu/with-transform-cleanup! [output-table "ws_api_fail"]
- (ws.tu/with-workspaces! [ws {:name "Workspace for failure test"}]
- (let [bad-transform {:name "Bad Transform"
- :source {:type "query"
- :query (mt/native-query {:query "SELECT * FROM nonexistent_table_xyz"})}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name output-table}}
- ref-id (:ref_id
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/transform") bad-transform))
- ws (ws.tu/ws-done! (:id ws))]
- (testing "returns failed status with error message and isolated table info"
- (let [result (mt/with-log-level [metabase.transforms.query-impl :fatal]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "transform" ref-id "run")))]
- (is (=? {:status "failed"
- :message some?
- :start_time some?
- :end_time some?
- :table {:schema (:schema ws)
- :name (str "public__" output-table)}}
- result))))
- (testing "transform has last_run_at, last_run_status, and last_run_message after failure"
- (is (=? {:last_run_at some?
- :last_run_status "failed"
- :last_run_message some?}
- (mt/user-http-request :crowberto :get 200 (ws-url (:id ws) "transform" ref-id))))))))))
-
-(defn- quote-table-name
- [driver {:keys [schema], table :name}]
- (sql.u/quote-name driver :table schema table))
-
-(deftest run-workspace-transform-bad-column-test
- (testing "POST /api/ee/workspace/:id/transform/:txid/run with non-existent column"
- (transforms.tu/with-transform-cleanup! [output-table "ws_api_badcol"]
- (ws.tu/with-workspaces! [ws {:name "Workspace for bad column test"}]
- (let [order-table (t2/select-one :model/Table (mt/id :orders))
- bad-transform {:name "Bad Column Transform"
- :source {:type "query"
- :query (mt/native-query {:query (format "SELECT nocolumn FROM %s" (quote-table-name (:engine (mt/db)) order-table))})}
- :target {:type "table"
- :database (mt/id)
- :schema (:schema order-table)
- :name output-table}}
- ref-id (:ref_id
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/transform") bad-transform))
- ws (ws.tu/ws-done! (:id ws))]
-
- (testing "returns failed status with error message mentioning the bad column"
- (let [result (mt/with-log-level [metabase.transforms.query-impl :fatal]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "transform" ref-id "run")))]
- (is (=? {:status "failed"
- :message #"(?si).*nocolumn.*"
- :start_time some?
- :end_time some?
- :table {:schema (:schema ws)
- :name (str (:schema order-table) "__" output-table)}}
- result))))
- (testing "transform has last_run_message mentioning the bad column"
- (is (=? {:last_run_at some?
- :last_run_status "failed"
- :last_run_message #"(?si).*nocolumn.*"}
- (mt/user-http-request :crowberto :get 200 (ws-url (:id ws) "transform" ref-id))))))))))
-
-(deftest execute-workspace-test
- (testing "POST /api/ee/workspace/:id/execute"
- (transforms.tu/with-transform-cleanup! [output-table "ws_execute_test"]
- (ws.tu/with-workspaces! [ws-1 {:name "Workspace 1"}
- ws-2 {:name "Workspace 2"}]
- (let [body {:name "Transform for execute test"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :database (mt/id)
- :schema nil
- :name output-table}}
- ws-transform (ws.common/add-to-changeset! (mt/user->id :crowberto) ws-1 :transform nil body)
- ws-1 (ws.tu/ws-done! (:id ws-1))]
- (testing "returns empty when no transforms"
- (is (= {:succeeded []
- :failed []
- :not_run []}
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws-2) "/run")))))
- (testing "executes transforms in workspace"
- (is (= {:succeeded [(:ref_id ws-transform)]
- :failed []
- :not_run []}
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws-1) "/run"))))))))))
-
-(deftest execute-workspace-stale-only-test
- (testing "POST /api/ee/workspace/:id/run?stale_only=true respects staleness with enclosed transforms"
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map global-map]}
- ;; (x1) -> x2 -> (x3)
- {:global {:x1 [:t0], :x2 [:x1], :x3 [:x2]}
- :workspace {:checkouts [:x1 :x3]}}]
- (let [ref-x1 (workspace-map :x1)
- ref-x3 (workspace-map :x3)
- global-x2 (str "global-id:" (global-map :x2))
- ->source (t2/select-fn->fn :ref_id :source [:model/WorkspaceTransform :ref_id :source]
- :workspace_id workspace-id)
- counter (atom 1)
- run! #(ws.tu/with-mocked-execution
- (mt/user-http-request :crowberto :post 200 (ws-url workspace-id "/run") {:stale_only 1}))
- inc-limit #(str (str/replace % #" LIMIT \d+" "") " LIMIT " (swap! counter inc))
- edit! (fn [ref-id]
- (let [current (->source ref-id)
- tweaked (update-in current [:query :stages 0 :native] inc-limit)]
- (mt/user-http-request :crowberto :put 200
- (ws-url workspace-id "/transform/" ref-id)
- {:source tweaked})))]
- (testing "initial run executes all stale transforms"
- (is (= {:succeeded [ref-x1 global-x2 ref-x3]
- :failed []
- :not_run []}
- (run!))))
- (testing "second run with nothing stale executes nothing"
- (is (= {:succeeded []
- :failed []
- :not_run []}
- (run!))))
- (edit! ref-x3)
- (testing "after editing x3, only x3 runs"
- (is (= {:succeeded [ref-x3]
- :failed []
- :not_run []}
- (run!))))
- (testing "after running x3, nothing stale"
- (is (= {:succeeded []
- :failed []
- :not_run []}
- (run!))))
- (edit! ref-x1)
- (testing "after editing x1, staleness propagates through enclosed x2 to x3"
- (is (= {:succeeded [ref-x1 global-x2 ref-x3]
- :failed []
- :not_run []}
- (run!))))
- (testing "after running all, nothing stale"
- (is (= {:succeeded []
- :failed []
- :not_run []}
- (run!))))))))
-
-(deftest dry-run-workspace-transform-api-test
- (testing "POST /api/ee/workspace/:id/transform/:txid/dry-run returns 404 if transform not in workspace"
- (ws.tu/with-workspaces! [ws1 {:name "Workspace 1"}
- ws2 {:name "Workspace 2"}]
- (mt/with-temp [:model/Transform x1 {:name "Transform in WS1"
- :source {:type "query"
- :query (mt/native-query
- {:query "SELECT * FROM (SELECT 1 as id, 'hello' as name UNION ALL SELECT 2, 'world') t ORDER BY 1"})}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "ws_dryrun"}}]
- (let [ref-id (:ref_id (mt/user-http-request :crowberto :post 200 (ws-url (:id ws1) "/transform") x1))
- ws1 (ws.tu/ws-done! (:id ws1))]
- (testing "Not found in different workspace"
- (is (= "Not found."
- (mt/user-http-request :crowberto :post 404
- (ws-url (:id ws2) "/transform/" ref-id "/dry-run")))))
- (testing "returns succeeded status with data"
- (let [result (mt/user-http-request :crowberto :post 200 (ws-url (:id ws1) "transform" ref-id "dry-run"))]
- (is (=? {:status "succeeded"
- :data {:rows [[1 "hello"] [2 "world"]]
- :cols [{:name #"(?i)id"} {:name #"(?i)name"}]}}
- result))))
- (testing "does NOT update last_run_at"
- (is (nil? (:last_run_at (mt/user-http-request :crowberto :get 200 (ws-url (:id ws1) "transform" ref-id))))))
- (testing "returns failed status with message"
- (t2/update! :model/WorkspaceTransform {:workspace_id (:id ws1) :ref_id ref-id}
- {:source {:type "query"
- :query (mt/native-query {:query "SELECT * FROM nonexistent_table_xyz"})}})
- (is (=? {:status "failed"
- :message string?}
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws1) "transform" ref-id "dry-run"))))))))))
-
-(deftest run-transform-with-stale-ancestors-test
- (testing "POST /api/ee/workspace/:id/transform/:txid/run with run_stale_ancestors=true"
- ;; Chain: x1 -> x2 -> x3, where x1 is stale
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:x1] :x3 [:x2]}
- :properties {:x1 {:definition_changed true}
- :x2 {:definition_changed false}
- :x3 {:definition_changed false}}}}]
- (let [x1-ref (workspace-map :x1)
- x2-ref (workspace-map :x2)
- x3-ref (workspace-map :x3)]
- ;; Use a mock that returns :table (required by the API schema)
- (mt/with-dynamic-fn-redefs [ws.execute/run-transform-with-remapping
- (fn [{:keys [target]} _remapping]
- {:status :succeeded
- :end_time (Instant/now)
- :message "Mocked execution"
- :table (select-keys target [:schema :name])})]
- (testing "without flag, ancestors are not run"
- (let [result (mt/user-http-request :crowberto :post 200
- (ws-url workspace-id "/transform/" x3-ref "/run"))]
- (is (= "succeeded" (:status result)))
- (is (nil? (:ancestors result)))))
- (testing "with flag, stale ancestors are run before target"
- (let [result (mt/user-http-request :crowberto :post 200
- (ws-url workspace-id "/transform/" x3-ref "/run")
- {:run_stale_ancestors true})]
- (is (= "succeeded" (:status result)))
- (is (= {:succeeded [x1-ref x2-ref]
- :failed []
- :not_run []}
- (:ancestors result))))))))))
-
-(deftest dry-run-transform-with-stale-ancestors-test
- (testing "POST /api/ee/workspace/:id/transform/:txid/dry-run with run_stale_ancestors=true"
- ;; Chain: x1 -> x2 -> x3, where x1 is stale
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:x1] :x3 [:x2]}
- :properties {:x1 {:definition_changed true}
- :x2 {:definition_changed false}
- :x3 {:definition_changed false}}}}]
- (let [x1-ref (workspace-map :x1)
- x2-ref (workspace-map :x2)
- x3-ref (workspace-map :x3)]
- ;; Mock both run (for ancestors) and preview (for dry-run target)
- (mt/with-dynamic-fn-redefs [ws.execute/run-transform-with-remapping
- (fn [{:keys [target]} _remapping]
- {:status :succeeded
- :end_time (Instant/now)
- :message "Mocked execution"
- :table (select-keys target [:schema :name])})
- ws.execute/run-transform-preview
- (fn [_transform _remapping]
- {:status :succeeded
- :data {:rows [[1 "test"]]
- :cols [{:name "id"} {:name "name"}]}})]
- (testing "with flag, stale ancestors are run before dry-run"
- (let [result (mt/user-http-request :crowberto :post 200
- (ws-url workspace-id "/transform/" x3-ref "/dry-run")
- {:run_stale_ancestors true})]
- (is (= "succeeded" (:status result)))
- (is (= {:succeeded [x1-ref x2-ref]
- :failed []
- :not_run []}
- (:ancestors result))))))))))
-
-;;; ---------------------------------------- Adhoc Query Tests ----------------------------------------
-
-(deftest ^:synchronized adhoc-query-test
- (testing "POST /api/ee/workspace/:id/query"
- (let [ws (ws.tu/create-ready-ws! "Adhoc Query Test")]
- (testing "happy path - returns query results for valid SQL"
- (let [result (mt/user-http-request :crowberto :post 200
- (ws-url (:id ws) "/query")
- {:sql "SELECT 1 as id, 'hello' as name"})]
- (is (=? {:status "succeeded"
- :data {:rows [[1 "hello"]]
- :cols [{:name #"(?i)id"} {:name #"(?i)name"}]}}
- result))))
-
- (testing "returns results for multi-row queries"
- (let [sql "SELECT * FROM (SELECT 1 as num UNION ALL SELECT 2 UNION ALL SELECT 3) t ORDER BY 1"
- result (mt/user-http-request :crowberto :post 200
- (ws-url (:id ws) "/query")
- {:sql sql})]
- (is (=? {:status "succeeded"
- :data {:rows [[1] [2] [3]]}}
- result)))))))
-
-(deftest ^:synchronized adhoc-query-error-handling-test
- (testing "POST /api/ee/workspace/:id/query error handling"
- (let [ws (ws.tu/create-ready-ws! "Adhoc Query Error Test")]
- (testing "returns failed status with message for invalid SQL"
- (let [result (mt/user-http-request :crowberto :post 200
- (ws-url (:id ws) "/query")
- {:sql "SELECT FROM WHERE INVALID"})]
- (is (=? {:status "failed"
- :message string?}
- result))))
-
- (testing "returns failed status for syntax errors"
- (let [result (mt/user-http-request :crowberto :post 200
- (ws-url (:id ws) "/query")
- {:sql "SELECT 1 X LIMIT"})]
- (is (=? {:status "failed"
- :message string?}
- result)))))))
-
-(deftest ^:synchronized adhoc-query-validation-test
- (testing "POST /api/ee/workspace/:id/query validation"
- (ws.tu/with-workspaces! [ws {:name "Adhoc Query Validation Test"}]
- (testing "returns 404 for non-existent workspace"
- (is (= "Not found."
- (mt/user-http-request :crowberto :post 404
- (ws-url 999999 "/query")
- {:sql "SELECT 1"}))))
-
- (testing "returns 400 for missing sql parameter"
- (is (=? {:errors {:sql "string with length >= 1"}}
- (mt/user-http-request :crowberto :post 400
- (ws-url (:id ws) "/query")
- {}))))
-
- (testing "returns 400 for empty sql parameter"
- (is (=? {:errors {:sql "string with length >= 1"}}
- (mt/user-http-request :crowberto :post 400
- (ws-url (:id ws) "/query")
- {:sql ""})))))))
-
-(deftest ^:synchronized adhoc-query-archived-workspace-test
- (testing "POST /api/ee/workspace/:id/query on archived workspace"
- (let [ws (ws.tu/create-ready-ws! "Adhoc Query Archived Test")]
- ;; Archive the workspace
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/archive"))
-
- (testing "returns 400 for archived workspace"
- (is (= "Cannot query archived workspace"
- (mt/user-http-request :crowberto :post 400
- (ws-url (:id ws) "/query")
- {:sql "SELECT 1"})))))))
-
-(deftest ^:synchronized adhoc-query-remapping-test
- (testing "POST /api/ee/workspace/:id/query remaps table references to isolated tables"
- (ws.tu/with-workspaces! [ws {:name "Adhoc Query Remapping Test"}]
- (let [default-schema (driver.sql/default-schema driver/*driver*)
- target-schema (or default-schema (sql.normalize/normalize-name driver/*driver* "public"))
- target-table (str "adhoc_remap_" (str/replace (str (random-uuid)) "-" "_"))
- tx-def {:name "Remapping Test Transform"
- :source {:type "query"
- :query (mt/native-query
- {:query "SELECT 1 as id, 'remapped' as status"})}
- :target {:type "table"
- :database (mt/id)
- :schema target-schema
- :name target-table}}
- ref-id (:ref_id (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/transform") tx-def))
- ws (ws.tu/ws-ready! ws)
- run-result (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/transform/" ref-id "/run"))]
- (is (= "succeeded" (:status run-result)) "Transform should have run successfully")
- (let [run-qry (fn [query-sql]
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws) "/query") {:sql query-sql}))
- expected {:status "succeeded"
- :data {:rows [[1 "remapped"]]
- :cols [{:name #"(?i)id"} {:name #"(?i)status"}]}}]
- (testing "ad-hoc query can SELECT from transform output using schema-qualified table name"
- (is (=? expected (run-qry (str "SELECT * FROM " target-schema "." target-table)))))
- (when default-schema
- (testing "ad-hoc query can SELECT from transform output using unqualified table name"
- (is (=? expected (run-qry (str "SELECT * FROM " target-table)))))))))))
-
-(deftest ^:synchronized adhoc-query-uses-isolated-credentials-test
- (testing "POST /api/ee/workspace/:id/query executes with workspace isolated credentials"
- (let [isolated? (atom false)
- workspace-used (atom nil)
- ws (ws.tu/create-ready-ws! "Adhoc Query Isolation Test")]
- (mt/with-dynamic-fn-redefs [ws.isolation/do-with-workspace-isolation
- (fn [workspace thunk]
- (reset! isolated? true)
- (reset! workspace-used workspace)
- (thunk))]
- (mt/user-http-request :crowberto :post 200
- (ws-url (:id ws) "/query")
- {:sql "SELECT 1"}))
- (is @isolated? "Query should execute within workspace isolation context")
- (is (= (:id ws) (:id @workspace-used)) "Should use correct workspace for isolation")
- (is (some? (:database_details @workspace-used))
- "Workspace should have database_details for proper isolation"))))
-
-(defn- random-target [db-id]
- {:type "table"
- :database db-id
- :schema (driver.sql/default-schema driver/*driver*)
- :name (str/replace (str "t_" (random-uuid)) "-" "_")})
-
-(defn- my-native-query [_db-id sql & [card-mapping]]
- (let [mp (mt/metadata-provider)]
- (cond-> (lib/native-query mp sql)
- card-mapping (lib/with-template-tags
- (u/for-map [[tag card-id] card-mapping]
- [tag {:name tag
- :display-name tag
- :type :card
- :card-id card-id}])))))
-
-(deftest external-transforms-test
- (testing "GET /api/ee/workspace/id/external/transform"
- (mt/with-premium-features #{:transforms-basic :workspaces}
- (let [db-1 (mt/id)]
- (ws.tu/with-workspaces! [ws1 {:name "Our Workspace"}
- ws2 {:name "Their Workspace"}]
- (mt/with-temp [;; Global transforms (workspace_id = null)
- :model/Database {db-2 :id} {:name "Other Db"}
- :model/Transform {xf1-id :id} {:name "Checked out - 1"
- :target (random-target db-1)}
- :model/Transform {xf2-id :id} {:name "Checked out - 2"
- :target (random-target db-1)}
- :model/Transform {xf3-id :id} {:name "Not checked out - python"
- :source {:type "python" :source-database db-1}
- :target (random-target db-1)}
- :model/Transform {xf4-id :id} {:name "Not checked out - mbql"
- :source {:type :query
- :query (q :venues)}
- :target (random-target db-1)}
- :model/Transform {xf5-id :id} {:name "Not checked out - native"
- :source {:type "query"
- :query (my-native-query db-1 "SELECT 1")}
- :target (random-target db-1)}
- ;; Native transform referencing a card - should be disabled once BOT-694 is implemented
- :model/Card {card-id :id} {:name "Source Card"
- :database_id db-1
- :dataset_query (q :venues)}
- :model/Transform {xf6-id :id} {:name "Not checked out - native with card dep"
- :source {:type "query"
- :query (my-native-query
- db-1
- "SELECT * FROM {{card}}"
- {"card" card-id})}
- :target (random-target db-1)}
- :model/Transform {xf7-id :id} {:name "Using another database"
- :source {:type "python" :source-database db-1}
- :target (random-target db-2)}
- ;; Workspace transforms (mirrored from global1 and global2)
- :model/WorkspaceTransform _ {:global_id xf1-id
- :workspace_id (:id ws1)}
- :model/WorkspaceTransform _ {:global_id xf2-id
- :workspace_id (:id ws2)}]
- (testing "excludes irrelevant transforms, and indicates which remaining transforms cannot be checked out."
- (let [transforms (:transforms (mt/user-http-request :crowberto :get 200 (ws-url (:id ws1) "/external/transform")))
- test-ids #{xf1-id xf2-id xf3-id xf4-id xf5-id xf6-id xf7-id}
- ;; Filter out cruft from dev, leaky tests, etc
- ids (into #{} (comp (map :id) (filter test-ids)) transforms)]
- (testing "we filter out the expected transforms"
- ;; ❌ xf1 is checked out in this workspace, so it's filtered out
- ;; ✅ xf2 is only checked out in another workspace, so it's kept
- ;; ❌ xf7 is in another database, so it's filtered out
- (is (= (disj test-ids xf1-id xf7-id) ids)))
- (testing "we get the correct checkout_disabled reasons"
- (is (= {xf2-id nil
- xf3-id nil #_python-is-supported
- xf4-id "mbql"
- xf5-id nil #_native-is-supported
- xf6-id "card-reference"}
- (u/index-by :id :checkout_disabled transforms))))))
- (testing "passing database-id shows transforms from that database"
- (is (= [xf7-id]
- (map :id
- (:transforms
- (mt/user-http-request :crowberto :get 200
- (ws-url (:id ws1) (str "external/transform?database-id=" db-2))))))))))))))
-
-;;; ---------------------------------------- Table ID Fallback Tests ----------------------------------------
-;; These tests verify that when WorkspaceOutput rows have null table IDs (e.g., because sync
-;; hasn't run yet), the /table endpoint will look up the IDs from metabase_table as a fallback.
-
-(deftest tables-endpoint-fallback-global-table-id-test
- (testing "GET /api/ee/workspace/:id/table uses fallback for null global_table_id"
- (mt/with-premium-features #{:workspaces}
- ;; TODO (Chris 2026-01-05) -- remove :schema workaround once this adds a transform properly, triggering async initialization
- (ws.tu/with-workspaces! [workspace {:name "Fallback Test WS"}]
- ;; TODO (Chris 2026-01-07) -- things fail because the workspace won't have been initialized yet.
- ;; ... the correct thing to do would be for the relevant code to initialize it!
- (t2/update! :model/Workspace (:id workspace) {:schema "isolated_schema"})
- (mt/with-temp [:model/WorkspaceTransform ws-tx {:workspace_id (:id workspace)
- :name "Test Transform"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "fallback_test_table"}}
- ;; Create a table that exists but WorkspaceOutput doesn't know about yet
- :model/Table table {:db_id (mt/id)
- :schema "public"
- :name "fallback_test_table"
- :active true}
- ;; Create WorkspaceOutput with null global_table_id (simulating pre-sync state)
- :model/WorkspaceOutput _ {:workspace_id (:id workspace)
- :ref_id (:ref_id ws-tx)
- :db_id (mt/id)
- :global_schema "public"
- :global_table "fallback_test_table"
- :global_table_id nil
- ;; TODO (Chris 2026-01-05) -- another spot
- :isolated_schema (or (:schema workspace) "workaround")
- :isolated_table "public__fallback_test_table"
- :isolated_table_id nil}]
- (let [result (mt/user-http-request :crowberto :get 200 (ws-url (:id workspace) "/table"))]
- (testing "fallback populates global table_id from metabase_table"
- (is (= (:id table)
- (-> result :outputs first :global :table_id))))
- (testing "isolated table_id is populated with transform target table"
- (is (int? (-> result :outputs first :isolated :table_id))))))))))
-
-(deftest ^:parallel tables-endpoint-fallback-isolated-table-id-test
- (testing "GET /api/ee/workspace/:id/table uses fallback for null isolated_table_id"
- (mt/with-premium-features #{:workspaces}
- (mt/with-temp [:model/Workspace workspace {:name "Isolated Fallback Test WS"
- :database_id (mt/id)
- :schema "ws_iso_fallback"}
- :model/WorkspaceTransform ws-tx {:workspace_id (:id workspace)
- :name "Test Transform"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "iso_fallback_table"}}
- ;; Create the isolated table in metabase_table
- :model/Table iso-table {:db_id (mt/id)
- :schema "ws_iso_fallback"
- :name "public__iso_fallback_table"
- :active true}
- ;; Create WorkspaceOutput with null isolated_table_id
- :model/WorkspaceOutput _ {:workspace_id (:id workspace)
- :ref_id (:ref_id ws-tx)
- :db_id (mt/id)
- :global_schema "public"
- :global_table "iso_fallback_table"
- :global_table_id nil
- :isolated_schema "ws_iso_fallback"
- :isolated_table "public__iso_fallback_table"
- :isolated_table_id nil}]
- (let [result (mt/user-http-request :crowberto :get 200 (ws-url (:id workspace) "/table"))]
- (testing "fallback populates isolated table_id from metabase_table"
- (is (= (:id iso-table)
- (-> result :outputs first :isolated :table_id)))))))))
-
-(deftest ^:parallel tables-endpoint-fallback-both-table-ids-test
- (testing "GET /api/ee/workspace/:id/table uses fallback for both null table IDs"
- (mt/with-premium-features #{:workspaces}
- (mt/with-temp [:model/Workspace workspace {:name "Both Fallback Test WS"
- :database_id (mt/id)
- :schema "ws_both_fallback"}
- :model/WorkspaceTransform ws-tx {:workspace_id (:id workspace)
- :name "Test Transform"
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "both_fallback_table"}}
- ;; Create both tables
- :model/Table global-table {:db_id (mt/id)
- :schema "public"
- :name "both_fallback_table"
- :active true}
- :model/Table iso-table {:db_id (mt/id)
- :schema "ws_both_fallback"
- :name "public__both_fallback_table"
- :active true}
- ;; Create WorkspaceOutput with both table IDs null
- :model/WorkspaceOutput _ {:workspace_id (:id workspace)
- :ref_id (:ref_id ws-tx)
- :db_id (mt/id)
- :global_schema "public"
- :global_table "both_fallback_table"
- :global_table_id nil
- :isolated_schema "ws_both_fallback"
- :isolated_table "public__both_fallback_table"
- :isolated_table_id nil}]
- (let [result (mt/user-http-request :crowberto :get 200 (ws-url (:id workspace) "/table"))]
- (testing "fallback populates both table IDs"
- (is (= (:id global-table)
- (-> result :outputs first :global :table_id)))
- (is (= (:id iso-table)
- (-> result :outputs first :isolated :table_id)))))))))
-
-(deftest graph-test
- (testing "GET /api/ee/workspace/:id/graph - explicit shape for a smaller graph"
- (let [{ws-id :workspace-id
- id-map :global-map
- tx-ids :workspace-map} (ws.tu/create-resources! {:global {:x1 [:t0]
- :x2 [:x1]}
- :workspace {:checkouts [:x1]
- :definitions {:x3 [:x2]}}})
-
- ws (ws.tu/ws-done! ws-id)
- tx-1 (t2/select-one :model/WorkspaceTransform :workspace_id ws-id, :ref_id (tx-ids :x1))
- tx-2 (t2/select-one :model/Transform (id-map :x2))
- tx-3 (t2/select-one :model/WorkspaceTransform :workspace_id ws-id, :ref_id (tx-ids :x3))
-
- driver (t2/select-one-fn :engine [:model/Database :engine] (:database_id ws))
- tx-schema (:schema (:target tx-1))
- tx-1-output (:name (:target tx-1))
- tx-2-output (sql.normalize/normalize-name driver (:name (:target tx-2)))
- tx-3-output (:name (:target tx-3))
- {input-id :id
- input-schema :schema
- input-table :name} (t2/select-one :model/Table (id-map :t0))
- ;; Look up output table IDs for transform targets
- tx-1-table-id (t2/select-one-fn :id :model/Table :db_id (mt/id) :schema tx-schema :name tx-1-output)
- tx-2-table-id (t2/select-one-fn :id :model/Table :db_id (mt/id) :schema tx-schema :name tx-2-output)
- tx-3-table-id (t2/select-one-fn :id :model/Table :db_id (mt/id) :schema tx-schema :name tx-3-output)
- tx-1-input (str (mt/id) "-" input-schema "-" input-table)
- t1-ref (:ref_id tx-1)
- t3-ref (:ref_id tx-3)]
-
- (testing "returns enclosed external transform too"
- (is (= {:nodes #{{:type "input-table"
- :id tx-1-input
- :data {:db (mt/id), :schema input-schema, :table input-table, :id input-id}
- :dependents_count {:workspace-transform 1}}
- {:type "workspace-transform"
- :id t1-ref
- :data {:ref_id t1-ref
- :name (:name tx-1)
- :target {:db (mt/id)
- :schema tx-schema
- :table tx-1-output
- :table_id tx-1-table-id}}
- :dependents_count {:external-transform 1}}
- {:type "external-transform"
- :id (:id tx-2)
- :data {:id (:id tx-2)
- :name (:name tx-2)
- :target {:db (mt/id)
- :schema tx-schema
- :table tx-2-output
- :table_id tx-2-table-id}}
- :dependents_count {:workspace-transform 1}}
- {:type "workspace-transform"
- :id t3-ref
- :data {:ref_id t3-ref
- :name (:name tx-3)
- :target {:db (mt/id)
- :schema tx-schema
- :table tx-3-output
- :table_id tx-3-table-id}}
- :dependents_count {}}},
- :edges #{{:to_entity_type "input-table"
- :to_entity_id tx-1-input
- :from_entity_type "workspace-transform"
- :from_entity_id t1-ref}
- {:to_entity_type "workspace-transform"
- :to_entity_id t1-ref
- :from_entity_type "external-transform"
- :from_entity_id (:id tx-2)}
- {:to_entity_type "external-transform"
- :to_entity_id (:id tx-2)
- :from_entity_type "workspace-transform"
- :from_entity_id (:ref_id tx-3)}}}
- (-> (mt/user-http-request :crowberto :get 200 (ws-url (:id ws) "graph"))
- (update-vals set))))))))
-
-;; Edge cases covered:
-;;
-;; 1. excluded ancestor
-;; 2. excluded descendant
-;; 3. disconnected components
-;; 4. enclosed by chain
-;; 5. workspace tx input
-;; 6. enclosed tx input
-;; 7. overridden dependency
-;;
-;; Ideas for more:
-;;
-;; - Removed dependency
-;; - Inverted dependency
-;; - ...
-(deftest larger-test
- (testing "GET /api/ee/workspace/:id/graph - structure for a larger and more complex graph"
- (let [{ws-id :workspace-id
- :as resources-map} (ws.tu/create-resources! {:global {:x1 [:t100]
- :x2 [:x1 :t101]
- :x3 [:x2 :t102]
- :x4 [:x3 :t103]
- :x5 [:x4 :t104]
- :x6 [:t105]
- :x7 [:106]}
- :workspace {:checkouts [:x2 :x4 :x6]
- :definitions {:x4 [:x3 :t199]}}})]
- (testing "returns enclosed external transform too"
- (is (= {:nodes #{;; checked out
- :x2
- :x4
- :x6
- ;; enclosed
- :x3
- ;; output of non-enclosed ancestor
- :t1
- ;; global input for workspace transforms
- :t101
- :t105
- ;; global input for enclosed transform
- :t102
- ;; overridden input
- :t199},
- :edges {:x2 #{:t1 :t101}
- :x3 #{:x2 :t102}
- :x4 #{:x3 :t199}
- :x6 #{:t105}}}
- (-> (mt/user-http-request :crowberto :get 200 (ws-url ws-id "graph"))
- (ws.tu/translate-graph resources-map))))))))
-
-(deftest enabled-test
- (let [url "ee/workspace/enabled"]
- (is (= {:supported true} (mt/user-http-request :crowberto :get 200 url)))
- (mt/with-temp [:model/Database {db-1 :id} {:name "Y", :engine "postgres"}
- ;; For some reason, using a real but unsupported value like "databricks" is returning support :-C
- :model/Database {db-2 :id} {:name "N", :engine "crazy"}]
- (testing "Unsupported driver"
- (is (= {:supported false, :reason "Database type not supported."}
- (mt/user-http-request :crowberto :get 200 (str url "?database-id=" db-2)))))
- (testing "Supported driver"
- (is (= {:supported true}
- (mt/user-http-request :crowberto :get 200 (str url "?database-id=" db-1)))))
- (testing "Audit not returned"
- (is (nil?
- (m/find-first (comp #{audit/audit-db-id} :id)
- (:databases (mt/user-http-request :crowberto :get 200 "ee/workspace/database")))))))))
-
-(deftest workspace-database-listing-test
- (testing "GET /api/ee/workspace/database"
- (testing "databases with workspaces_enabled=true show as enabled"
- (mt/with-temp [:model/Database {db-enabled :id} {:name "DB Enabled"
- :engine driver/*driver*
- :is_audit false
- :is_sample false
- :workspace_permissions_status {:status "ok" :checked_at "2025-01-01"}
- :settings {:database-enable-workspaces true}}
- :model/Database {db-disabled :id} {:name "DB Disabled"
- :engine driver/*driver*
- :is_audit false
- :is_sample false
- :workspace_permissions_status {:status "ok" :checked_at "2025-01-01"}
- :settings {}}]
- (let [response (mt/user-http-request :crowberto :get 200 "ee/workspace/database")
- enabled-entry (m/find-first #(= (:id %) db-enabled) (:databases response))
- disabled-entry (m/find-first #(= (:id %) db-disabled) (:databases response))]
- (is (true? (:enabled enabled-entry)))
- (is (= "ok" (get-in enabled-entry [:workspace_permissions_status :status])))
- (is (false? (:enabled disabled-entry)))
- (is (= "ok" (get-in disabled-entry [:workspace_permissions_status :status]))))))
-
- (testing "databases with failed permission check include permissions_status"
- (mt/with-temp [:model/Database {db-failed :id} {:name "DB Failed"
- :engine driver/*driver*
- :is_audit false
- :is_sample false
- :workspace_permissions_status {:status "failed" :error "permission denied" :checked_at "2025-01-01"}}]
- (let [response (mt/user-http-request :crowberto :get 200 "ee/workspace/database")
- fail-entry (m/find-first #(= (:id %) db-failed) (:databases response))]
- (is (false? (:enabled fail-entry)))
- (is (= "failed" (get-in fail-entry [:workspace_permissions_status :status])))
- (is (= "permission denied" (get-in fail-entry [:workspace_permissions_status :error]))))))
-
- (testing "databases without permission check have unknown permissions_status"
- (mt/with-temp [:model/Database {db-uncached :id} {:name "DB Uncached"
- :engine driver/*driver*
- :is_audit false
- :is_sample false}]
- (let [response (mt/user-http-request :crowberto :get 200 "ee/workspace/database")
- entry (m/find-first #(= (:id %) db-uncached) (:databases response))]
- (is (false? (:enabled entry)))
- (is (= {:status "unknown"} (:workspace_permissions_status entry))))))))
-
-(deftest checkout-endpoint-test
- (testing "GET /api/ee/workspace/checkout returns checkout status for a transform"
- (mt/with-temp [:model/Transform tx {:name "Native Transform"
- :source {:type :query
- :query (mt/native-query {:query "SELECT 1"})}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "checkout_test_table"}}]
- (ws.tu/with-workspaces! [ws1 {:name "Workspace One" :database_id (mt/id)}
- ws2 {:name "Workspace Two" :database_id (mt/id)}]
- (testing "initially all workspaces for the database are returned, none checked out"
- (is (=? {:checkout_disabled nil
- :workspaces [{:id (:id ws1) :name "Workspace One" :status string? :existing nil}
- {:id (:id ws2) :name "Workspace Two" :status string? :existing nil}]
- :transforms []}
- (mt/user-http-request :crowberto :get 200 "ee/workspace/checkout"
- :transform-id (:id tx)))))
-
- (testing "after checkout, the workspace shows the existing checkout info"
- (mt/user-http-request :crowberto :post 200 (ws-url (:id ws1) "/transform")
- (merge {:global_id (:id tx)}
- (select-keys tx [:name :source :target])))
- (is (=? {:checkout_disabled nil
- :workspaces [{:id (:id ws1) :name "Workspace One" :status string?
- :existing {:ref_id string? :name "Native Transform"}}
- {:id (:id ws2) :name "Workspace Two" :status string? :existing nil}]
- :transforms [{:id string? :name "Native Transform"
- :workspace {:id (:id ws1) :name "Workspace One"}}]}
- (mt/user-http-request :crowberto :get 200 "ee/workspace/checkout"
- :transform-id (:id tx)))))
-
- (testing "returns 404 for non-existent transform"
- (is (= "Not found."
- (mt/user-http-request :crowberto :get 404 "ee/workspace/checkout"
- :transform-id 999999))))))))
-
-(deftest checkout-disabled-reason-test
- (testing "GET /api/ee/workspace/checkout returns correct checkout_disabled reasons"
- (testing "MBQL transforms cannot be checked out"
- (mt/with-temp [:model/Transform tx {:name "MBQL Transform"
- :source {:type :query
- :query (q :venues)}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "mbql_checkout_test"}}]
- (is (=? {:checkout_disabled "mbql"
- :workspaces []
- :transforms []}
- (mt/user-http-request :crowberto :get 200 "ee/workspace/checkout"
- :transform-id (:id tx))))))
-
- (testing "Python transforms can be checked out"
- (mt/with-temp [:model/Transform tx {:name "Python Transform"
- :source {:type :python :code "print(1)" :source-database (mt/id)}
- :source_type :python
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "python_checkout_test"}}]
- (is (=? {:checkout_disabled nil
- :workspaces []
- :transforms []}
- (mt/user-http-request :crowberto :get 200 "ee/workspace/checkout"
- :transform-id (:id tx))))))))
-
-(deftest checkout-blocked-for-mbql-transforms-test
- (testing "POST /api/ee/workspace/:id/transform blocks MBQL transform checkout"
- (mt/with-temp [:model/Transform tx {:name "MBQL Transform"
- :source {:type :query
- :query (q :venues)}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "mbql_blocked_test"}}]
- (ws.tu/with-workspaces! [ws {:name "Test Workspace" :database_id (mt/id)}]
- (is (= "MBQL transforms cannot be added to workspaces."
- (mt/user-http-request :crowberto :post 400 (ws-url (:id ws) "/transform")
- (merge {:global_id (:id tx)}
- (select-keys tx [:name :source :target])))))))))
-
-(deftest checkout-blocked-for-card-reference-transforms-test
- (testing "POST /api/ee/workspace/:id/transform blocks transform with card references"
- (mt/with-temp [:model/Card card {:name "Referenced Card"
- :database_id (mt/id)
- :dataset_query (mt/native-query {:query "SELECT 1"})}
- :model/Transform tx {:name "Card Reference Transform"
- :source {:type :query
- :database (mt/id)
- :query (mt/native-query {:query "SELECT * FROM {{#card}}"
- :template-tags {"card" {:type "card"
- :card-id (:id card)
- :display-name "Card"}}})}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "card_ref_blocked_test"}}]
- (ws.tu/with-workspaces! [ws {:name "Test Workspace" :database_id (mt/id)}]
- (is (= "Transforms referencing questions cannot be added to workspaces."
- (mt/user-http-request :crowberto :post 400 (ws-url (:id ws) "/transform")
- (merge {:global_id (:id tx)}
- (select-keys tx [:name :source :target])))))))))
-
-(deftest global-id-immutable-test
- (testing "PUT /api/ee/workspace/:id/transform/:tx-id cannot change global_id"
- (let [{:keys [workspace-id global-map workspace-map]}
- (ws.tu/create-resources!
- {:global {:x1 [:t1]
- :x2 [:t2]}
- :workspace {:checkouts [:x1]
- :definitions {:x3 [:t3]}}})]
- (testing "cannot clear global_id on a checked-out transform"
- (is (=? {:cause "Cannot change global_id of an existing workspace transform."}
- (mt/user-http-request :crowberto :put 400 (ws-url workspace-id "/transform/" (workspace-map :x1))
- {:global_id nil}))))
- (testing "cannot set global_id on a workspace-only transform"
- (is (=? {:cause "Cannot change global_id of an existing workspace transform."}
- (mt/user-http-request :crowberto :put 400 (ws-url workspace-id "/transform/" (workspace-map :x3))
- {:global_id (global-map :x2)})))))))
-
-(defmacro ^:private with-test-resources-cleanup! [& body]
- `(mt/with-model-cleanup [:model/Transform :model/Workspace :model/Table]
- ~@body))
-
-(deftest test-resources-empty
- (testing "POST /api/ee/workspace/test-resources with global transforms only (no workspace)"
- (with-test-resources-cleanup!
- (is (=? {:workspace-id nil
- :global-map {}
- :workspace-map {}}
- (mt/user-http-request :crowberto :post 200 "ee/workspace/test-resources"
- {:global {}}))))))
-
-(deftest test-resources-single
- (testing "POST /api/ee/workspace/test-resources with global transforms only (no workspace)"
- (with-test-resources-cleanup!
- (is (=? {:workspace-id nil
- :global-map {:x1 int?}
- :workspace-map {}}
- (mt/user-http-request :crowberto :post 200 "ee/workspace/test-resources"
- {:global {:x1 []}}))))))
-
-(deftest test-resources-global-only-test
- (testing "POST /api/ee/workspace/test-resources with global transforms only (no workspace)"
- (with-test-resources-cleanup!
- (let [orders (mt/format-name :orders)]
- (is (=? {:workspace-id nil
- :global-map {(keyword orders) int?, :x1 int?, :x2 int?}
- :workspace-map {}}
- (mt/user-http-request :crowberto :post 200 "ee/workspace/test-resources"
- {:global {:x1 [orders], :x2 [:x1]}})))))))
-
-(deftest test-resources-complex-graph-test
- (testing "POST /api/ee/workspace/test-resources with complex graph"
- (with-test-resources-cleanup!
- (let [orders (mt/format-name :orders)
- products (mt/format-name :products)
- people (mt/format-name :people)]
- (is (=? {:workspace-id int?
- :global-map {(keyword orders) int?
- (keyword products) int?
- :t4 int?
- :x1 int?
- :x2 int?
- :x3 int?
- :x4 int?}
- :workspace-map {:x5 string?, :x6 string?}}
- (mt/user-http-request :crowberto :post 200 "ee/workspace/test-resources"
- {:global {:x1 [orders]
- :x2 [products]
- :x3 [:x1 :x2]
- :x4 [:t4]}
- :workspace {:definitions {:x2 [:x1]
- :x5 [orders :x3]
- :x6 [:x5 people]}}})))))))
-
-(deftest test-resources-custom-database-test
- (testing "POST /api/ee/workspace/test-resources with custom database_id"
- (mt/with-temp [:model/Database {other-db-id :id} {:name "Other DB" :engine driver/*driver*}
- :model/Table {table-id :id} {:name "coffee", :db_id other-db-id}]
- (with-test-resources-cleanup!
- (let [result (mt/user-http-request :crowberto :post 200 "ee/workspace/test-resources"
- {:database_id other-db-id
- :global {:x1 [:t1 "coffee"]}
- :workspace {:definitions {:x2 [:t2]}}})]
- (is (=? {:workspace-id int?
- :global-map {:t1 int?, :t2 int?, :x1 int?, :coffee table-id}
- :workspace-map {:x2 string?}}
- result))
- (testing "workspace uses the specified database"
- (is (= other-db-id
- (t2/select-one-fn :database_id :model/Workspace :id (:workspace-id result)))))
- (testing "mock tables are created in the specified database"
- (is (= other-db-id
- (t2/select-one-fn :db_id :model/Table :id (:t1 (:global-map result)))))
- (is (= other-db-id
- (t2/select-one-fn :db_id :model/Table :id (:t2 (:global-map result))))))
- (testing "transform targets the specified database"
- (is (= other-db-id
- (get-in (t2/select-one :model/Transform :id (:x1 (:global-map result))) [:target :database])))))))))
-
-;;; ============================================ Input Grant Endpoint Tests ============================================
-
-(deftest run-rejects-ungranted-inputs-test
- (testing "POST /run and /dry-run reject transforms whose inputs have not been granted access"
- (ws.tu/with-workspaces! [ws {:name "Ungranted Run Test"}]
- (let [transform {:name "Transform with input"
- :source {:type "query"
- :query (->native (-> (q :orders) (lib/aggregate (lib/count))))}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "ungranted_run_test"}}
- ref-id (:ref_id (mt/user-http-request :crowberto :post 200
- (ws-url (:id ws) "/transform") transform))
- ws (ws.tu/ws-done! (:id ws))]
- ;; Explicitly trigger analysis to populate workspace_input_transform table
- (ws.tu/analyze-workspace! (:id ws))
- ;; Set all inputs for this workspace to ungranted
- (t2/update! :model/WorkspaceInput {:workspace_id (:id ws)} {:access_granted false})
- (testing "POST /transform/:tx-id/run returns 400 when inputs are ungranted"
- (is (str/includes?
- (mt/user-http-request :crowberto :post 400
- (ws-url (:id ws) "/transform/" ref-id "/run"))
- "not been granted access")))
- (testing "POST /transform/:tx-id/dry-run returns 400 when inputs are ungranted"
- (is (str/includes?
- (mt/user-http-request :crowberto :post 400
- (ws-url (:id ws) "/transform/" ref-id "/dry-run"))
- "not been granted access")))
- (testing "After granting access, /run succeeds (does not return 400)"
- (t2/update! :model/WorkspaceInput {:workspace_id (:id ws)} {:access_granted true})
- ;; We just check it's not a 400 — the transform may succeed or fail depending on DB state,
- ;; but it should pass the grant check.
- (let [result (mt/user-http-request :crowberto :post 200
- (ws-url (:id ws) "/transform/" ref-id "/run"))]
- (is (contains? result :status))))))))
-
-(deftest input-pending-test
- (testing "GET /:ws-id/input/pending returns ungranted inputs"
- (let [mp (mt/metadata-provider)
- query (lib/query mp (lib.metadata/table mp (mt/id :orders)))
- ws (ws.tu/create-empty-ws! "Pending Input Test")]
- (mt/with-dynamic-fn-redefs [ws.isolation/grant-read-access-to-tables! (constantly nil)]
- ;; Add a transform so workspace has inputs
- (ws.common/add-to-changeset! (mt/user->id :crowberto) ws
- :transform nil
- {:name "Transform with input"
- :source {:type "query" :query query}
- :target {:database (mt/id)
- :schema "analytics"
- :name "pending_test_table"}})
- (ws.tu/analyze-workspace! (:id ws))
- ;; Ensure inputs are ungranted
- (t2/update! :model/WorkspaceInput {:workspace_id (:id ws)} {:access_granted false})
- (testing "returns pending (ungranted) inputs"
- (let [resp (mt/user-http-request :crowberto :get 200
- (ws-url (:id ws) "/input/pending"))]
- (is (seq (:inputs resp)) "Should have at least one pending input")
- (is (every? #(contains? % :table) (:inputs resp)))))
- (testing "after granting, returns empty list"
- (t2/update! :model/WorkspaceInput {:workspace_id (:id ws)} {:access_granted true})
- (let [resp (mt/user-http-request :crowberto :get 200
- (ws-url (:id ws) "/input/pending"))]
- (is (empty? (:inputs resp)) "Should have no pending inputs after granting")))))))
-
-(deftest input-grant-test
- (testing "POST /:ws-id/input/grant grants access to input tables"
- (let [mp (mt/metadata-provider)
- query (lib/query mp (lib.metadata/table mp (mt/id :orders)))
- ws (ws.tu/create-empty-ws! "Grant Input Test")]
- (mt/with-dynamic-fn-redefs [ws.isolation/grant-read-access-to-tables!
- (fn [_database _workspace _tables] nil)]
- ;; Add a transform so workspace has inputs
- (ws.common/add-to-changeset! (mt/user->id :crowberto) ws
- :transform nil
- {:name "Transform with input"
- :source {:type "query" :query query}
- :target {:database (mt/id)
- :schema "analytics"
- :name "grant_test_table"}})
- (ws.tu/analyze-workspace! (:id ws))
- ;; Reset inputs to ungranted so we can test the grant endpoint
- (t2/update! :model/WorkspaceInput {:workspace_id (:id ws)} {:access_granted false})
- (let [input-tables (t2/select [:model/WorkspaceInput :db_id :schema :table]
- :workspace_id (:id ws))
- grant-calls (atom [])]
- (mt/with-dynamic-fn-redefs [ws.isolation/grant-read-access-to-tables!
- (fn [_database _workspace tables]
- (swap! grant-calls conj (set (map :name tables))))]
- (testing "granting with valid table coordinates succeeds"
- (let [result (mt/user-http-request :crowberto :post 200
- (ws-url (:id ws) "/input/grant")
- {:tables input-tables})]
- (is (seq @grant-calls) "grant-read-access-to-tables! should have been called")
- (is (= input-tables (:newly_granted result))
- "All inputs should be in newly_granted")
- (is (empty? (:already_granted result))
- "No inputs should be in already_granted yet")
- (is (every? #(true? (t2/select-one-fn :access_granted :model/WorkspaceInput
- :workspace_id (:id ws)
- :db_id (:db_id %)
- :schema (:schema %)
- :table (:table %)))
- input-tables)
- "All inputs should be marked as granted"))
- (testing "granting already-granted tables is idempotent"
- (reset! grant-calls [])
- (let [result (mt/user-http-request :crowberto :post 200
- (ws-url (:id ws) "/input/grant")
- {:tables input-tables})]
- (is (empty? @grant-calls)
- "grant-read-access-to-tables! should not be called for already-granted tables")
- (is (= input-tables (:already_granted result))
- "All inputs should be in already_granted")
- (is (empty? (:newly_granted result))
- "No inputs should be in newly_granted"))))))))))
-
-;;; ============================================ Authorization Test Matrix ============================================
-
-(deftest superuser-authorization-test
- (testing "All workspace routes require superuser (spot-check)"
- (ws.tu/with-workspaces! [ws {:name "Auth Test"}]
- (is (= "You don't have permissions to do that."
- (mt/user-http-request :rasta :get 403 "ee/workspace")))
- (is (= "You don't have permissions to do that."
- (mt/user-http-request :rasta :get 403 (ws-url (:id ws))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/dag_abstract.clj b/enterprise/backend/test/metabase_enterprise/workspaces/dag_abstract.clj
deleted file mode 100644
index 9d390b34c51..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/dag_abstract.clj
+++ /dev/null
@@ -1,117 +0,0 @@
-(ns metabase-enterprise.workspaces.dag-abstract
- "Abstract graph solver using shorthand notation for testing.
-
- Shorthand uses keywords like :x1, :t2, :m3 where:
- - :x<n> is a transform
- - :t<n> is a table (source/generated)
- - :m<n> is a model (card)"
- (:require
- [clojure.set :as set]
- [flatland.ordered.map :as ordered-map]
- [metabase-enterprise.workspaces.util :as ws.u]
- [metabase.util :as u]))
-
-;;;; Shorthand notation helpers
-
-(defn- related [t id]
- (keyword (str (name t) (subs (name id) 1))))
-
-(def ^:private x->t (partial related :t))
-
-(defn is?
- "Check if id is of type t (e.g., (is? :x :x1) => true)."
- [t id]
- (= (name t) (str (first (name id)))))
-
-(defn- lexico [id]
- (let [n (name id)
- prefix (when (keyword? id) (first n))]
- (if-let [type-order ({\x 1 \t 2 \m 3} prefix)]
- ;; Standard shorthand keyword like :x1, :t2 - sort by number then type
- [(parse-long (subs n 1)) type-order]
- ;; Real table string reference - sort after all standard keywords
- [Long/MAX_VALUE n])))
-
-(defn expand-shorthand
- "As shorthand, we can use transforms in the place of their induced tables.
- This function expands the graph to insert the induced tables, and replace the corresponding references."
- [dependencies]
- (let [xs (set (filter #(is? :x %) (concat (keys dependencies) (mapcat val dependencies))))]
- (into (sorted-map-by #(compare (lexico %1) (lexico %2)))
- (merge (zipmap (map x->t xs) (map vector xs))
- (into {} (filter (comp #(is? :t %) key)) dependencies)
- (update-vals
- (into {} (remove (comp #(is? :t %) key)) dependencies)
- (fn [deps] (->> deps
- (map (fn [id]
- (if (is? :x id)
- (x->t id)
- id)))
- (sort-by lexico)
- (vec))))))))
-
-;;;; Graph traversal helpers
-
-(defn- children [dependencies]
- (reduce
- (fn [acc [child parents]]
- (reduce (fn [acc p] (update acc p u/conjv child)) acc parents))
- (sorted-map-by #(compare (lexico %1) (lexico %2)))
- dependencies))
-
-(defn- ->ts [ids]
- (into #{}
- (keep (fn [id]
- (cond (is? :t id) id
- (is? :x id) (x->t id))))
- ids))
-
-;;;; Toposort
-
-(defn- toposort-map [child->parents]
- (let [child->parents (if (map? child->parents) child->parents (into {} child->parents))]
- (into (ordered-map/ordered-map)
- (keep (fn [n] (when-let [deps (get child->parents n)] [n deps])))
- (ws.u/toposort-dfs child->parents))))
-
-;;;; Abstract path-induced subgraph solver
-
-(def ^:private max-iterations 100)
-
-(defn path-induced-subgraph
- "Abstract solver for path-induced subgraph using shorthand notation."
- [{:keys [check-outs dependencies] :as _graph}]
- (let [->parents dependencies
- ->children (children dependencies)]
- (loop [iteration 1
- below check-outs
- above check-outs
- seen-down? check-outs
- seen-up? check-outs
- to-descend check-outs
- to-ascend check-outs]
- (if (and (empty? to-descend) (empty? to-ascend))
- (let [nodes (set/intersection above below)
- entities (remove #(is? :t %) nodes)
- tables (sort-by lexico (filter #(is? :t %) nodes))]
- {:check-outs (sort-by lexico check-outs)
- :inputs (sort-by lexico (remove nodes (->ts (mapcat ->parents check-outs))))
- :tables tables
- :transforms (sort-by lexico (filter #(is? :x %) nodes))
- :entities (sort-by lexico entities)
- :dependencies (apply dissoc
- (toposort-map
- (for [n nodes]
- [n (vec (filter nodes (get dependencies n)))]))
- tables)})
- (if (> iteration max-iterations)
- {:error "max iterations exceeded"}
- (let [next-down (into #{} (comp (mapcat ->children) (remove seen-down?)) to-descend)
- next-up (into #{} (comp (mapcat ->parents) (remove seen-up?)) to-ascend)]
- (recur (inc iteration)
- (into below next-down)
- (into above next-up)
- (into seen-down? next-down)
- (into seen-up? next-up)
- next-down
- next-up)))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/dag_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/dag_test.clj
deleted file mode 100644
index 36e7e98ae83..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/dag_test.clj
+++ /dev/null
@@ -1,288 +0,0 @@
-(ns metabase-enterprise.workspaces.dag-test
- (:require
- [clojure.test :refer :all]
- [flatland.ordered.map :as ordered-map]
- [metabase-enterprise.workspaces.dag :as ws.dag]
- [metabase-enterprise.workspaces.dag-abstract :as dag-abstract]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase.test :as mt]
- [metabase.util :as u]
- [toucan2.core :as t2]))
-
-(use-fixtures
- :once
- (fn [f]
- (mt/with-premium-features [:dependencies :transforms-basic :workspaces]
- (mt/with-model-cleanup [:model/Dependency :model/Transform :model/Table :model/Workspace]
- (f)))))
-
-;;;; Example graphs for testing
-
-(def ^:private example-graph
- {:x3 [:x1 :t2]
- :x4 [:x3]
- :m6 [:x4 :t5]
- :m10 [:t9]
- :x11 [:m10]
- :m12 [:x11]
- :m13 [:x11 :m12]})
-
-;;;; Test data helpers
-
-(defn- translate-result
- "Translate result from real IDs back to shorthand notation for easier comparison."
- [workspace-id {:keys [inputs outputs entities dependencies] :as _result} id-map]
- (let [reverse-map (u/for-map [[k v] id-map] [v k])
- table->kw (comp reverse-map :id)
- node->kw (fn [{:keys [node-type id]}]
- (reverse-map (case node-type
- :table (:id id)
- :external-transform id
- :workspace-transform (t2/select-one-fn :global_id [:model/WorkspaceTransform :global_id]
- :workspace_id workspace-id :ref_id id))))]
- {:inputs (into #{} (map table->kw) inputs)
- :outputs (into #{} (map table->kw) outputs)
- :entities (into #{} (map node->kw) entities)
- :dependencies (u/for-map [[child parents] dependencies]
- [(node->kw child) (into #{} (map node->kw parents))])}))
-
-;;;; Tests
-
-(deftest path-induced-subgraph-shorthand-test
- (testing "graph built from shorthand matches abstract solver"
- (let [{:keys [workspace-id global-map workspace-map]}
- (ws.tu/create-resources!
- {:global {:x2 [:t1]}
- :workspace {:checkouts [:x2]}})]
- (ws.tu/analyze-workspace! workspace-id)
- (let [entity {:entity-type :transform, :id (workspace-map :x2)}
- result (ws.dag/path-induced-subgraph workspace-id [entity])
- translated (translate-result workspace-id result global-map)]
- (is (=? {:inputs #{:t1}
- :outputs #{:t2}
- :entities #{:x2}
- :dependencies {:x2 #{:t1}}}
- translated))))))
-
-(deftest path-induced-subgraph-larger-test
- (testing "graph built from shorthand matches abstract solver"
- ;; check-outs x2, x4
- (let [{:keys [workspace-id global-map workspace-map]}
- (ws.tu/create-resources!
- {:global {:x1 [:t0]
- :x2 [:x1 :t10]
- :x3 [:x2 :t8]
- :x4 [:x3]
- :x5 [:x2 :x4 :t9]}
- :workspace {:checkouts [:x2 :x4]}})]
- (ws.tu/analyze-workspace! workspace-id)
- (let [entities (for [tx [:x2 :x4]]
- {:entity-type :transform, :id (workspace-map tx)})
- result (ws.dag/path-induced-subgraph workspace-id entities)
- translated (translate-result workspace-id result global-map)]
- (is (=? {:inputs #{:t1 :t8 :t10}
- :outputs #{:t2 :t3 :t4}
- :entities #{:x2 :x3 :x4}
- :dependencies {:x2 #{:t1 :t10}
- :x3 #{:x2 :t8}
- :x4 #{:x3}}}
- translated))))))
-
-(deftest expand-solver-test
- (testing "expand-shorthand inserts interstitial nodes for transform output tables"
- (is (= {:t1 [:x1]
- :x3 [:t1 :t2]
- :t3 [:x3]
- :x4 [:t3]
- :t4 [:x4]
- :m6 [:t4 :t5]
- :m10 [:t9]
- :x11 [:m10]
- :t11 [:x11]
- :m12 [:t11]
- :m13 [:t11 :m12]}
- (dag-abstract/expand-shorthand example-graph)))))
-
-(deftest abstract-path-induced-subgraph-test
- (testing "path-induced-subgraph computes correct result for example graph"
- (is (= {:check-outs [:x3 :m6 :m10 :m13]
- :inputs [:t1 :t2 :t5 :t9]
- :tables [:t3 :t4 :t11]
- :transforms [:x3 :x4 :x11]
- :entities [:x3 :x4 :m6 :m10 :x11 :m12 :m13]
- :dependencies (ordered-map/ordered-map
- :m10 []
- :x11 [:m10]
- :m12 [:t11]
- :m13 [:t11 :m12]
- :x3 []
- :x4 [:t3]
- :m6 [:t4])}
- (dag-abstract/path-induced-subgraph
- {:check-outs #{:x3 :m6 :m10 :m13}
- :dependencies (dag-abstract/expand-shorthand example-graph)})))))
-
-;;;; Graph utility tests
-
-(deftest reverse-graph-test
- (testing "empty graph"
- (is (= {} (ws.dag/reverse-graph {}))))
-
- (testing "single edge"
- (is (= {:a [:b]}
- (ws.dag/reverse-graph {:b [:a]}))))
-
- (testing "chain graph - reverses direction"
- (is (= {:a [:b], :b [:c], :c [:d]}
- (ws.dag/reverse-graph {:b [:a], :c [:b], :d [:c]}))))
-
- (testing "diamond graph - a -> b -> d, a -> c -> d"
- (is (= {:a [:b :c], :b [:d], :c [:d]}
- (ws.dag/reverse-graph {:b [:a], :c [:a], :d [:b :c]}))))
-
- (testing "multiple parents become multiple children - x has parents [a b c] => a, b, c each get child x"
- (is (= {:a [:x], :b [:x], :c [:x]}
- (ws.dag/reverse-graph {:x [:a :b :c]})))))
-
-(deftest bfs-reduce-test
- (testing "empty adjacency returns empty"
- (is (= [] (ws.dag/bfs-reduce {} [:a]))))
-
- (testing "no neighbors returns empty"
- (is (= [] (ws.dag/bfs-reduce {:a []} [:a]))))
-
- (testing "single hop"
- (is (= [:b :c]
- (ws.dag/bfs-reduce {:a [:b :c]} [:a]))))
-
- (testing "chain traversal - collects all reachable nodes"
- (let [graph {:a [:b], :b [:c], :c [:d], :d []}]
- (is (= [:b :c :d] (ws.dag/bfs-reduce graph [:a])))
- (is (= [:c :d] (ws.dag/bfs-reduce graph [:b])))
- (is (= [:d] (ws.dag/bfs-reduce graph [:c])))
- (is (= [] (ws.dag/bfs-reduce graph [:d])))))
-
- (testing "diamond graph - no duplicates (a -> b -> d, a -> c -> d)"
- (let [graph {:a [:b :c], :b [:d], :c [:d], :d []}]
- (is (= [:b :c :d] (ws.dag/bfs-reduce graph [:a])))))
-
- (testing "works with map nodes (like workspace transform nodes)"
- (let [tx1 {:node-type :workspace-transform :id "tx1"}
- tx2 {:node-type :workspace-transform :id "tx2"}
- tx3 {:node-type :workspace-transform :id "tx3"}
- tbl {:node-type :table :id {:db 1 :schema "public" :table "foo"}}
- graph {tx1 [tx2 tbl], tx2 [tx3], tx3 [], tbl []}]
- (is (= [tx2 tbl tx3] (ws.dag/bfs-reduce graph [tx1])))
- (is (= [tx3] (ws.dag/bfs-reduce graph [tx2])))))
-
- (testing "handles cycles gracefully - a -> b -> c -> a (cycle), should not infinite loop"
- (let [graph {:a [:b], :b [:c], :c [:a]}]
- (is (= [:b :c :a] (ws.dag/bfs-reduce graph [:a])))))
-
- (testing "include-start? option"
- (let [graph {:a [:b], :b [:c], :c []}]
- (is (= [:a :b :c] (ws.dag/bfs-reduce graph [:a] :include-start? true)))
- (is (= [:b :c] (ws.dag/bfs-reduce graph [:a] :include-start? false)))))
-
- (testing "multiple start nodes"
- (let [graph {:a [:x], :b [:y], :x [], :y []}]
- (is (= [:x :y] (ws.dag/bfs-reduce graph [:a :b])))
- (is (= [:a :b :x :y] (ws.dag/bfs-reduce graph [:a :b] :include-start? true)))))
-
- (testing "traverses through different node types"
- (let [tx1 {:node-type :workspace-transform :id "tx1"}
- tx2 {:node-type :workspace-transform :id "tx2"}
- ext {:node-type :external-transform :id "ext"}
- graph {tx1 [ext], ext [tx2], tx2 []}]
- (is (= [ext tx2] (ws.dag/bfs-reduce graph [tx1])))))
-
- (testing "custom :init collects into a set"
- (let [graph {:a [:b :c], :b [:d], :c [:d], :d []}]
- (is (= #{:b :c :d} (ws.dag/bfs-reduce graph [:a] :init #{})))
- (is (= #{:a :b :c :d} (ws.dag/bfs-reduce graph [:a] :init #{} :include-start? true)))))
-
- (testing "custom :rf filters during traversal"
- (let [tx1 {:node-type :workspace-transform :id "t1"}
- tx2 {:node-type :workspace-transform :id "t2"}
- tbl {:node-type :table :id "tbl"}
- graph {tx1 [tx2 tbl], tx2 [], tbl []}
- xf (keep #(when (= :workspace-transform (:node-type %)) (:id %)))]
- (is (= ["t2"] (ws.dag/bfs-reduce graph [tx1] :rf (xf conj)))))))
-
-(deftest collapse-test
- (is (= {:x1 [:x2 :x3]
- :x2 [:t3]
- :x3 [:x5]
- :x4 []
- :x5 []}
- (#'ws.dag/collapse
- ws.tu/mock-table?
- {:x1 [:t1 :t2]
- :t1 [:x2]
- :t2 [:x3]
- :x2 [:t3]
- :x3 [:t4]
- :t4 [:x5]
- :t5 [:x4]
- :x4 []
- :x5 []}))))
-
-(defn tx->table [kw]
- (when (ws.tu/transform? kw)
- (keyword (str "t" (ws.tu/kw->id kw)))))
-
-(defn- solve-in-memory [init-nodes graph]
- (let [tx-nodes (filter ws.tu/transform? init-nodes)
- tables (map tx->table tx-nodes)]
- (#'ws.dag/path-induced-subgraph*
- ;; Include all changeset targets in the init-nodes
- (distinct (into init-nodes tables))
- {:node-parents (dag-abstract/expand-shorthand graph)
- :table? ws.tu/mock-table?
- :table-sort ws.tu/kw->id
- :unwrap-table identity})))
-
-(defn- chain->deps [chain]
- (reduce
- (fn [deps [from to]]
- (assoc deps from [to]))
- {}
- (partition 2 1 (reverse chain))))
-
-(deftest in-memory-path-induced-subgraph-test
- (testing "singleton"
- (is (= {:inputs [:t1]
- :outputs [:t2]
- :entities [:x2]
- :dependencies {:x2 [:t1]}}
- (solve-in-memory [:x2] {:x2 [:t1]}))))
-
- (testing "encloses middle of a chain"
- (is (= {:inputs [:t1]
- :outputs [:t2 :t3 :t4]
- :entities [:x2 :x3 :x4]
- :dependencies {:x2 [:t1]
- :x3 [:x2]
- :x4 [:x3]}}
- (solve-in-memory [:x2 :x4] (chain->deps [:x1 :x2 :x3 :x4 :x5])))))
-
- (testing "larger graph"
- (is (= {:inputs [:t1 :t2 :t5 :t9]
- :outputs [:t3 :t4 :t11]
- :entities [:m10 :x11 :m12 :m13 :x3 :x4 :m6]
- :dependencies {:m10 [:t9]
- :m12 [:x11]
- :m13 [:m12 :x11]
- :m6 [:x4 :t5]
- :x11 [:m10]
- :x3 [:t2 :t1]
- :x4 [:x3]}}
- (solve-in-memory
- [:x3 :m6 :m10 :m13]
- {:x3 [:x1 :t2]
- :x4 [:x3]
- :m6 [:x4 :t5]
- :m10 [:t9]
- :x11 [:m10]
- :m12 [:x11]
- :m13 [:x11 :m12]})))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/dependencies_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/dependencies_test.clj
deleted file mode 100644
index d8e2030fd23..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/dependencies_test.clj
+++ /dev/null
@@ -1,273 +0,0 @@
-(ns metabase-enterprise.workspaces.dependencies-test
- (:require
- [clojure.test :refer :all]
- [metabase-enterprise.workspaces.dependencies :as ws.deps]
- [metabase-enterprise.workspaces.impl :as ws.impl]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase.lib.core :as lib]
- [metabase.lib.metadata :as lib.metadata]
- [metabase.test :as mt]
- [metabase.transforms.test-util :as transforms.tu]
- [toucan2.core :as t2]))
-
-(set! *warn-on-reflection* true)
-
-(ws.tu/ws-fixtures!)
-
-;;; ---------------------------------------- analyze-entity tests ----------------------------------------
-
-(deftest ^:parallel analyze-entity-query-transform-test
- (testing "analyze-entity extracts dependencies from a query transform"
- (let [mp (mt/metadata-provider)
- query (lib/query mp (lib.metadata/table mp (mt/id :orders)))
- transform {:source {:type "query"
- :query query}
- :target {:database (mt/id)
- :schema "public"
- :name "orders_with_products"}}
- result (ws.deps/analyze-entity :transform transform)]
- (testing "output is extracted from target"
- (is (= {:db_id (mt/id)
- :schema "public"
- :table "orders_with_products"}
- (:output result))))
- (testing "inputs contain the source table with table_id (since table exists)"
- (let [inputs (:inputs result)
- table-names (set (map :table inputs))]
- (is (= 1 (count inputs)))
- (is (contains? table-names (mt/format-name :orders)))
- ;; MBQL queries have table_id since the tables must exist
- (is (every? #(and (:db_id %)
- (:table %)
- (:table_id %))
- inputs)))))))
-
-(deftest ^:parallel analyze-entity-native-query-existing-table-test
- (testing "analyze-entity extracts dependencies from native query referencing existing table"
- (let [mp (mt/metadata-provider)
- query (lib/native-query mp "SELECT * FROM orders WHERE total > 100")
- transform {:source {:type "query"
- :query query}
- :target {:database (mt/id)
- :schema "analytics"
- :name "high_value_orders"}}
- result (ws.deps/analyze-entity :transform transform)]
- (testing "output is extracted from target"
- (is (= {:db_id (mt/id)
- :schema "analytics"
- :table "high_value_orders"}
- (:output result))))
- (testing "inputs include table_id since orders table exists"
- (let [inputs (:inputs result)]
- ;; Native query parsing should detect ORDERS table reference and look up table_id
- (is (pos? (count inputs)))
- (is (every? #(and (:db_id %)
- (:table %)
- (:table_id %))
- inputs)))))))
-
-(deftest ^:parallel analyze-entity-native-query-nonexistent-table-test
- (testing "analyze-entity handles native query referencing non-existent table"
- (let [mp (mt/metadata-provider)
- ;; Reference a table that doesn't exist in the database
- query (lib/native-query mp "SELECT * FROM future_sales_data WHERE region = 'US'")
- transform {:source {:type "query"
- :query query}
- :target {:database (mt/id)
- :schema "analytics"
- :name "regional_sales"}}
- result (ws.deps/analyze-entity :transform transform)]
- (testing "output is extracted from target"
- (is (= {:db_id (mt/id)
- :schema "analytics"
- :table "regional_sales"}
- (:output result))))
- (testing "inputs have logical reference but no table_id (table doesn't exist)"
- (let [inputs (:inputs result)]
- ;; Should still parse the table reference even though table doesn't exist
- (is (pos? (count inputs)))
- ;; Has db_id and table name but NOT table_id
- (is (every? #(and (:db_id %)
- (:table %))
- inputs))
- ;; Verify table_id is nil or missing for non-existent tables
- (is (every? #(nil? (:table_id %)) inputs)))))))
-
-(deftest ^:parallel analyze-entity-python-transform-test
- (testing "analyze-entity extracts dependencies from a python transform"
- (let [transform {:source {:type "python"
- :source-tables [(transforms.tu/source-table-entry "orders" (mt/id :orders))
- (transforms.tu/source-table-entry "products" (mt/id :products))]
- :body "def transform(orders, products): return orders"}
- :target {:database (mt/id)
- :schema "public"
- :name "python_result"}}
- result (ws.deps/analyze-entity :transform transform)]
- (testing "output is extracted from target"
- (is (= {:db_id (mt/id)
- :schema "public"
- :table "python_result"}
- (:output result))))
- (testing "inputs contain the source tables with table_ids"
- (let [inputs (:inputs result)
- table-names (set (map :table inputs))]
- (is (= 2 (count inputs)))
- (is (contains? table-names (mt/format-name :orders)))
- (is (contains? table-names (mt/format-name :products)))
- ;; Python transforms have table_ids since source-tables maps to existing table IDs
- (is (every? :table_id inputs)))))))
-
-(deftest analyze-entity-asserts-transform-type-test
- (testing "analyze-entity asserts entity-type is :transform"
- (is (thrown-with-msg? Exception #"Only transform entity type is supported"
- (ws.deps/analyze-entity :card {})))))
-
-;;; ---------------------------------------- write-analysis! tests ----------------------------------------
-
-(defn- write-analysis! [workspace-id isolated-schema entity-type ref-id analysis]
- ;; Always do new analysis
- (t2/query {:update :workspace_transform
- :set {:analysis_version [:+ :analysis_version 1]}
- :where [:and [:= :workspace_id workspace-id] [:= :ref_id ref-id]]})
- (ws.deps/write-entity-analysis! workspace-id isolated-schema entity-type ref-id analysis
- (case entity-type
- :transform (t2/select-one-fn :analysis_version
- [:model/WorkspaceTransform :analysis_version]
- :workspace_id workspace-id
- :ref_id ref-id))))
-
-(deftest write-dependencies-creates-output-test
- (testing "write-dependencies! creates workspace_output record"
- (mt/with-temp [:model/Workspace workspace {:name (ws.tu/unique-name)
- :database_id (mt/id)
- :schema "test_isolated_schema"}
- :model/WorkspaceTransform wt {:workspace_id (:id workspace)
- :name "Test Transform"
- :source {:type "query" :query {}}
- :target {:database (mt/id)
- :schema "public"
- :name "test_output"}}]
- (let [analysis {:output {:db_id (mt/id)
- :schema "public"
- :table "test_output"}
- :inputs []}]
- (write-analysis! (:id workspace) "test_isolated_schema" :transform (:ref_id wt) analysis)
- (let [output (t2/select-one :model/WorkspaceOutput
- :workspace_id (:id workspace)
- :ref_id (:ref_id wt))]
- (is (some? output))
- (is (= (mt/id) (:db_id output)))
- (is (= "public" (:global_schema output)))
- (is (= "test_output" (:global_table output)))
- (is (= "test_isolated_schema" (:isolated_schema output)))
- (is (= "public__test_output" (:isolated_table output))))))))
-
-(deftest write-dependencies-creates-inputs-test
- (testing "write-dependencies! creates workspace_input records for external dependencies"
- (let [iso-schema "test_isolated_schema"]
- (mt/with-temp [:model/Workspace workspace {:name (ws.tu/unique-name)
- :database_id (mt/id)
- :schema iso-schema}
- :model/WorkspaceTransform wt {:workspace_id (:id workspace)
- :name "Test Transform"
- :source {:type "query" :query {}}
- :target {:database (mt/id)
- :schema "public"
- :name "test_output"}}]
- (let [orders-table (t2/select-one [:model/Table :db_id :schema :name] :id (mt/id :orders))
- analysis {:output {:db_id (mt/id)
- :schema "public"
- :table "test_output"}
- :inputs [{:db_id (:db_id orders-table)
- :schema (:schema orders-table)
- :table (:name orders-table)}]}]
- (write-analysis! (:id workspace) iso-schema :transform (:ref_id wt) analysis)
- (let [input (t2/select-one :model/WorkspaceInput
- :workspace_id (:id workspace)
- :table (:name orders-table))]
- (is (some? input))
- (is (= (:db_id orders-table) (:db_id input)))
- (is (= (:name orders-table) (:table input)))
- (testing "input is linked to transform via workspace_input_transform"
- (is (t2/exists? :model/WorkspaceInputTransform
- :workspace_input_id (:id input)
- :workspace_id (:id workspace)
- :ref_id (:ref_id wt))))))))))
-
-(deftest write-dependencies-updates-on-change-test
- (testing "write-dependencies! replaces inputs when dependencies change"
- (mt/with-temp [:model/Workspace workspace {:name (ws.tu/unique-name)
- :database_id (mt/id)
- :schema "test_isolated_schema"}
- :model/WorkspaceTransform wt {:workspace_id (:id workspace)
- :name "Test Transform"
- :source {:type "query" :query {}}
- :target {:database (mt/id)
- :schema "public"
- :name "test_output"}}]
- (let [orders-table (t2/select-one [:model/Table :db_id :schema :name] :id (mt/id :orders))
- products-table (t2/select-one [:model/Table :db_id :schema :name] :id (mt/id :products))]
- ;; First write with orders dependency
- (write-analysis! (:id workspace) "test_isolated_schema" :transform (:ref_id wt)
- {:output {:db_id (mt/id)
- :schema "public"
- :table "test_output"}
- :inputs [{:db_id (:db_id orders-table)
- :schema (:schema orders-table)
- :table (:name orders-table)}]})
- (is (= 1 (t2/count :model/WorkspaceInput :workspace_id (:id workspace))))
- (is (= 1 (t2/count :model/WorkspaceInputTransform :workspace_id (:id workspace) :ref_id (:ref_id wt))))
-
- ;; Update to depend on products instead
- (write-analysis! (:id workspace) "test_isolated_schema" :transform (:ref_id wt)
- {:output {:db_id (mt/id)
- :schema "public"
- :table "test_output"}
- :inputs [{:db_id (:db_id products-table)
- :schema (:schema products-table)
- :table (:name products-table)}]})
-
- ;; Trigger clean-up
- (#'ws.impl/cleanup-old-transform-versions! (:id workspace) (:ref_id wt))
-
- (testing "old input link is removed, new input exists"
- ;; After cleanup, old WorkspaceInputTransform rows are removed.
- ;; The WorkspaceInput for orders may still exist (orphaned) but the join row is gone.
- (is (= 1 (t2/count :model/WorkspaceInputTransform :workspace_id (:id workspace) :ref_id (:ref_id wt))))
- (let [wit (t2/select-one :model/WorkspaceInputTransform :workspace_id (:id workspace) :ref_id (:ref_id wt))
- input (t2/select-one :model/WorkspaceInput :id (:workspace_input_id wit))]
- (is (= (:name products-table) (:table input)))))))))
-
-;;; ---------------------------------------- Integration test ----------------------------------------
-
-(deftest analyze-and-write-integration-test
- (testing "Full flow: analyze a real transform and write its dependencies"
- (let [mp (mt/metadata-provider)
- query (lib/query mp (lib.metadata/table mp (mt/id :orders)))]
- (mt/with-temp [:model/Workspace workspace {:name "Integration Test Workspace"
- :database_id (mt/id)
- :schema "test_isolated_schema"}
- :model/WorkspaceTransform wt {:workspace_id (:id workspace)
- :name "Orders Analysis"
- :source {:type "query" :query {}}
- :target {:database (mt/id)
- :schema "analytics"
- :name "orders_analysis"}}]
- ;; Create the transform entity with the proper query (not from DB)
- (let [transform-entity {:source {:type "query"
- :query query}
- :target {:database (mt/id)
- :schema "analytics"
- :name "orders_analysis"}}
- analysis (ws.deps/analyze-entity :transform transform-entity)]
- (write-analysis! (:id workspace) "test_isolated_schema" :transform (:ref_id wt) analysis)
-
- (testing "output record created"
- (is (= 1 (t2/count :model/WorkspaceOutput :workspace_id (:id workspace)))))
- (testing "input record created for ORDERS table, linked via workspace_input_transform"
- (is (= 1 (t2/count :model/WorkspaceInput :workspace_id (:id workspace))))
- (let [input (t2/select-one :model/WorkspaceInput :workspace_id (:id workspace))]
- (is (t2/exists? :model/WorkspaceInputTransform
- :workspace_input_id (:id input)
- :workspace_id (:id workspace)
- :ref_id (:ref_id wt))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/drivers_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/drivers_test.clj
deleted file mode 100644
index ff44280a708..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/drivers_test.clj
+++ /dev/null
@@ -1,20 +0,0 @@
-(ns ^:mb/driver-tests metabase-enterprise.workspaces.drivers-test
- (:require
- [clojure.test :refer :all]
- [metabase.driver.connection.workspaces :as driver.w]
- [metabase.test :as mt]))
-
-(deftest drivers-support-workspaces-has-to-support-db-swapping-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (let [db-swapped? (fn []
- (try
- (mt/run-mbql-query venues {:limit 1})
- false
- (catch Exception _e
- true)))]
- (testing "db is swapped if being executed inside a macros"
- (driver.w/with-swapped-connection-details (mt/id) {:user "unicorn"}
- (is (db-swapped?))))
-
- (testing "sanity check that it's not swapped outside of the macros"
- (is (not (db-swapped?)))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/e2e_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/e2e_test.clj
deleted file mode 100644
index 69213bbb722..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/e2e_test.clj
+++ /dev/null
@@ -1,66 +0,0 @@
-(ns ^:mb/driver-tests metabase-enterprise.workspaces.e2e-test
- (:require
- [clojure.string :as str]
- [clojure.test :refer :all]
- [metabase-enterprise.workspaces.common :as ws.common]
- [metabase-enterprise.workspaces.impl :as ws.impl]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase.lib.core :as lib]
- [metabase.sync.core :as sync]
- [metabase.test :as mt]
- [metabase.transforms.test-util :as transforms.tu]
- [metabase.util :as u]
- [toucan2.core :as t2]))
-
-(ws.tu/ws-fixtures!)
-
-(deftest isolation-e2e-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (transforms.tu/with-transform-cleanup! [output-table-name (str "test_table_1_" (mt/random-name))]
- (mt/with-model-cleanup [:model/Transform :model/Workspace]
- (mt/with-temp [:model/Transform {transform-id :id} {:name "Transform 1"
- :source {:type "query"
- :query (-> (ws.tu/q :orders) (lib/limit 3) ws.tu/->native)}
- :target {:type "table"
- :name output-table-name
- :database (mt/id)
- :schema (t2/select-one-fn :schema :model/Table (mt/id :orders))}}]
- (ws.tu/with-workspaces! [workspace {:name (mt/random-name)
- :database_id (mt/id)}]
- (ws.common/add-to-changeset! (mt/user->id :crowberto) workspace
- :transform transform-id
- (t2/select-one :model/Transform transform-id))
- (u/poll {:thunk #(t2/select-one :model/Workspace (:id workspace))
- :done? #(= :ready (:db_status %))
- :timeout-ms 5000})
- (let [workspace (t2/select-one :model/Workspace (:id workspace))
- graph (ws.impl/get-or-calculate-graph! workspace)
- isolated-transform (t2/select-one :model/WorkspaceTransform :workspace_id (:id workspace))
- executed-transform (mt/with-current-user (mt/user->id :crowberto)
- ;; trigger analysis, so we get the RO grants
- (ws.impl/analyze-transform-if-stale! workspace isolated-transform)
- (ws.impl/run-transform! workspace graph isolated-transform))
- output-table (-> executed-transform :table)
- schema (:schema output-table)
- table-name (:name output-table)]
- (testing "execute the transform with the original query is fine and the output is in an isolated schema"
- (when (u/poll {:thunk #(t2/select-one :model/Table :name table-name :schema schema)
- :done? some?
- :timeout-ms 1000})
- ;; TODO (Ngoc 2026-01-21) -- the table is synced but there are no fields even though the table and fields exist in the db
- ;; ... even force sync-ing it again doesn't seem to help ;_;
- (sync/sync-table! (t2/select-one :model/Table :name table-name :schema schema))
- #_(transforms.tu/wait-for-table (:name output-table) 1000))
- (is (str/starts-with? (:schema output-table) "mb__isolation"))
- #_(is (= 1 (count (transforms.tu/table-rows table-name)))))
-
- (testing "changing the query without granting access will fail"
- (t2/update! :model/WorkspaceTransform
- {:workspace_id (:id workspace) :ref_id (:ref_id isolated-transform)}
- {:source {:type "query"
- :query (ws.tu/->native (-> (ws.tu/q :venues) (lib/limit 1)))}})
- (let [ref-id (:ref_id isolated-transform)
- transform (t2/select-one :model/WorkspaceTransform :workspace_id (:id workspace) :ref_id ref-id)]
- (is (=? {:status :failed}
- (mt/with-current-user (mt/user->id :crowberto)
- (ws.impl/run-transform! workspace graph transform)))))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/execute_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/execute_test.clj
deleted file mode 100644
index 8ac5eabea6f..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/execute_test.clj
+++ /dev/null
@@ -1,390 +0,0 @@
-(ns ^:mb/driver-tests metabase-enterprise.workspaces.execute-test
- (:require
- [clojure.string :as str]
- [clojure.test :refer :all]
- [metabase-enterprise.workspaces.common :as ws.common]
- [metabase-enterprise.workspaces.execute :as ws.execute]
- [metabase-enterprise.workspaces.impl :as ws.impl]
- [metabase-enterprise.workspaces.query-processor.middleware :as ws.qp.middleware]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase.driver :as driver]
- [metabase.driver.sql.util :as sql.u]
- [metabase.lib.core :as lib]
- [metabase.lib.test-metadata :as meta]
- [metabase.query-processor.compile :as qp.compile]
- [metabase.sql-tools.core :as sql-tools]
- [metabase.test :as mt]
- [metabase.transforms.test-util :as transforms.tu]
- [toucan2.core :as t2])
- (:import (clojure.lang ExceptionInfo)))
-
-(set! *warn-on-reflection* true)
-
-(ws.tu/ws-fixtures!)
-
-(deftest run-workspace-transform-no-input-test
- (testing "Executing a workspace transform returns results and rolls back app DB records"
- (transforms.tu/with-transform-cleanup! [output-table "ws_execute_test"]
- (let [workspace (ws.tu/create-ready-ws! "Execute Test Workspace")
- db-id (:database_id workspace)
- body {:name "Test Transform"
- :source {:type "query"
- :query (mt/native-query {:query "SELECT 1 as id, 'hello' as name"})}
- :target {:type "table"
- :database db-id
- :schema nil
- :name output-table}}
- ws-transform (ws.common/add-to-changeset! (mt/user->id :crowberto) workspace :transform nil body)
- ;; get initialized fields
- workspace (t2/select-one :model/Workspace (:id workspace))
- graph (ws.impl/get-or-calculate-graph! workspace)
- ws-schema (t2/select-one-fn :schema :model/Workspace (:id workspace))
- before {:xf (t2/count :model/Transform)
- :xfrun (t2/count :model/TransformRun)}]
- (testing "execution returns expected result structure"
- (is (=? {:status :succeeded
- :start_time some?
- :end_time some?
- :table {:name #(str/includes? % output-table)
- :schema ws-schema}}
- (mt/with-current-user (mt/user->id :crowberto)
- (ws.impl/run-transform! workspace graph ws-transform))))
- (is (=? {:last_run_at some?}
- (t2/select-one :model/WorkspaceTransform :workspace_id (:id workspace) :ref_id (:ref_id ws-transform))))
-
- (testing "The isolated_table_id gets populated"
- (ws.impl/get-or-calculate-graph! workspace)
- (is (=? [{:workspace_id (:id workspace)
- :global_table output-table
- :global_schema nil
- :global_table_id pos-int?
- :isolated_schema string?
- :isolated_table string?
- :isolated_table_id number?}]
- (t2/select :model/WorkspaceOutput :workspace_id (:id workspace) :ref_id (:ref_id ws-transform))))))
-
- (testing "no app DB records are created (transforms-base/execute! skips TransformRun)"
- (is (= before
- {:xf (t2/count :model/Transform)
- :xfrun (t2/count :model/TransformRun)})))))))
-
-(deftest dry-run-workspace-transform-with-template-tags-test
- (testing "Dry-running a workspace transform with template tags succeeds"
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 []}}}]
- (let [ref-id (workspace-map :x1)
- workspace (t2/select-one :model/Workspace workspace-id)
- ;; Update the transform source to use template tags
- native-query (-> (lib/native-query (mt/metadata-provider)
- "SELECT {{num}} as id")
- (lib/with-template-tags
- {"num" {:id "num"
- :name "num"
- :display-name "Num"
- :type :number
- :default "1"}}))
- _ (t2/update! :model/WorkspaceTransform
- {:workspace_id workspace-id :ref_id ref-id}
- {:source {:type "query" :query native-query}})
- ws-transform (t2/select-one :model/WorkspaceTransform :workspace_id workspace-id :ref_id ref-id)
- graph (ws.impl/get-or-calculate-graph! workspace)]
- (is (=? {:status :succeeded
- :data {:rows [[1]]}}
- (mt/with-current-user (mt/user->id :crowberto)
- (ws.impl/dry-run-transform workspace graph ws-transform))))))))
-
-(deftest dry-run-sql-workspace-transform-test
- (testing "Dry-running a workspace transform returns rows without persisting"
- (let [workspace (ws.tu/create-ready-ws! "Dry-Run Test Workspace")
- db-id (:database_id workspace)
- body {:name "Dry-Run Transform"
- :source {:type "query"
- :query (mt/native-query {:query "SELECT * FROM (SELECT 1 as id, 'hello' as name UNION ALL SELECT 2, 'world') t ORDER BY 1"})}
- :target {:type "table"
- :database db-id
- :schema nil
- :name "ws_dryrun_test"}}
- ws-transform (ws.common/add-to-changeset! (mt/user->id :crowberto) workspace :transform nil body)
- graph (ws.impl/get-or-calculate-graph! workspace)
- before {:xf (t2/count :model/Transform)
- :xfrun (t2/count :model/TransformRun)}]
-
- (testing "dry-run returns data nested under :data like /api/dataset"
- (is (=? {:status :succeeded
- :data {:rows [[1 "hello"] [2 "world"]]
- :cols [{:name #"(ID)|(id)"} {:name #"(NAME)|(name)"}]}}
- (mt/with-current-user (mt/user->id :crowberto)
- (ws.impl/dry-run-transform workspace graph ws-transform)))))
-
- (testing "last_run_at is NOT updated in dry-run mode"
- (is (nil? (:last_run_at (t2/select-one :model/WorkspaceTransform :workspace_id (:id workspace) :ref_id (:ref_id ws-transform))))))
-
- (testing "app DB records are NOT created in dry-run mode"
- (is (= before
- {:xf (t2/count :model/Transform)
- :xfrun (t2/count :model/TransformRun)}))))))
-
-(deftest ^:mb/transforms-python-test dry-run-python-workspace-transform-test
- (testing "Dry-running a Python workspace transform returns rows without persisting"
- (mt/test-drivers #{:mysql :postgres}
- (let [workspace (ws.tu/create-ready-ws! "Python Dry-Run Test")
- db-id (:database_id workspace)
- body {:name "Python Dry-Run Transform"
- :source {:type "python"
- :source-tables []
- :body (str "import pandas as pd\n"
- "\n"
- "def transform():\n"
- " return pd.DataFrame({'id': [1, 2], 'name': ['hello', 'world']})")}
- :target {:type "table"
- :database db-id
- :schema nil
- :name "ws_python_dryrun_test"}}
- ws-transform (ws.common/add-to-changeset! (mt/user->id :crowberto) workspace :transform nil body)
- graph (ws.impl/get-or-calculate-graph! workspace)
- before {:xf (t2/count :model/Transform)
- :xfrun (t2/count :model/TransformRun)}]
-
- (testing "dry-run returns data with rows from Python output"
- (is (=? {:status :succeeded
- :data {:rows [[1 "hello"] [2 "world"]]
- :cols [{:name "id"} {:name "name"}]}}
- (mt/with-current-user (mt/user->id :crowberto)
- (ws.impl/dry-run-transform workspace graph ws-transform)))))
-
- (testing "last_run_at is NOT updated in dry-run mode"
- (is (nil? (:last_run_at (t2/select-one :model/WorkspaceTransform :workspace_id (:id workspace) :ref_id (:ref_id ws-transform))))))
-
- (testing "app DB records are NOT created in dry-run mode"
- (is (= before
- {:xf (t2/count :model/Transform)
- :xfrun (t2/count :model/TransformRun)})))))))
-
-(deftest remap-python-source-test
- (let [remap-python-source #'ws.execute/remap-python-source]
- (testing "remaps entry via triple lookup when mapping has :id"
- (let [table-mapping {[1 "public" "orders"] {:db-id 1
- :schema "ws_isolated_123"
- :table "orders_isolated"
- :id 456}}
- source {:type "python"
- :body "import pandas as pd"
- :source-tables [{:alias "orders" :database_id 1
- :schema "public" :table "orders" :table_id 123}]}]
- (is (= [{:alias "orders" :database_id 1
- :schema "ws_isolated_123" :table "orders_isolated" :table_id 456}]
- (:source-tables (remap-python-source table-mapping source))))))
-
- (testing "remaps entry via table_id lookup"
- (let [table-mapping {123 {:db-id 1
- :schema "ws_isolated_123"
- :table "orders_isolated"
- :id 456}}
- source {:type "python"
- :body "import pandas as pd"
- :source-tables [{:alias "orders" :table_id 123 :database_id 1 :schema "public"}]}]
- (is (= [{:alias "orders" :database_id 1
- :schema "ws_isolated_123" :table "orders_isolated" :table_id 456}]
- (:source-tables (remap-python-source table-mapping source))))))
-
- (testing "remaps without table_id when mapping has nil :id"
- (let [table-mapping {[1 "public" "orders"] {:db-id 1
- :schema "ws_isolated_123"
- :table "orders_isolated"
- :id nil}}
- source {:type "python"
- :body "import pandas as pd"
- :source-tables [{:alias "orders" :database_id 1
- :schema "public" :table "orders" :table_id 123}]}]
- (is (= [{:alias "orders" :database_id 1
- :schema "ws_isolated_123" :table "orders_isolated" :table_id 123}]
- (:source-tables (remap-python-source table-mapping source))))))
-
- (testing "leaves source-tables unchanged when no mapping exists"
- (let [table-mapping {}
- source {:type "python"
- :body "import pandas as pd"
- :source-tables [{:alias "orders" :database_id 1
- :schema "public" :table "orders" :table_id 123}]}]
- (is (= source (remap-python-source table-mapping source)))))
-
- (testing "handles multiple entries with mappings"
- (let [table-mapping {[1 "public" "orders"] {:db-id 1
- :schema "ws_isolated_123"
- :table "orders_isolated"
- :id 456}
- 789 {:db-id 1
- :schema "ws_isolated_123"
- :table "customers_isolated"
- :id 999}}
- source {:type "python"
- :body "import pandas as pd"
- :source-tables [{:alias "orders" :database_id 1
- :schema "public" :table "orders" :table_id 123}
- {:alias "customers" :table_id 789 :database_id 1 :schema "public"}]}]
- (is (= [{:alias "orders" :database_id 1
- :schema "ws_isolated_123" :table "orders_isolated" :table_id 456}
- {:alias "customers" :database_id 1
- :schema "ws_isolated_123" :table "customers_isolated" :table_id 999}]
- (:source-tables (remap-python-source table-mapping source))))))
-
- (testing "prefers table_id lookup over triple lookup"
- (let [table-mapping {123 {:db-id 1
- :schema "ws_isolated_123"
- :table "orders_by_id"
- :id 456}
- [1 "public" "orders"] {:db-id 1
- :schema "ws_isolated_123"
- :table "orders_by_triple"
- :id 789}}
- source {:type "python"
- :body "import pandas as pd"
- :source-tables [{:alias "orders" :database_id 1
- :schema "public" :table "orders" :table_id 123}]}]
- (is (= [{:alias "orders" :database_id 1
- :schema "ws_isolated_123" :table "orders_by_id" :table_id 456}]
- (:source-tables (remap-python-source table-mapping source))))))
-
- (testing "falls back to triple lookup when table_id not in mapping"
- (let [table-mapping {[1 "public" "orders"] {:db-id 1
- :schema "ws_isolated_123"
- :table "orders_isolated"
- :id 456}}
- source {:type "python"
- :body "import pandas as pd"
- :source-tables [{:alias "orders" :database_id 1
- :schema "public" :table "orders" :table_id 999}]}]
- (is (= [{:alias "orders" :database_id 1
- :schema "ws_isolated_123" :table "orders_isolated" :table_id 456}]
- (:source-tables (remap-python-source table-mapping source))))))
-
- (testing "keeps original values when mapping has nil :id"
- (let [table-mapping {123 {:db-id 1
- :schema "ws_isolated_123"
- :table "orders_isolated"
- :id nil}}
- source {:type "python"
- :body "import pandas as pd"
- :source-tables [{:alias "orders" :database_id 1
- :schema "public" :table "orders" :table_id 123}]}]
- (is (= [{:alias "orders" :database_id 1
- :schema "ws_isolated_123" :table "orders_isolated" :table_id 123}]
- (:source-tables (remap-python-source table-mapping source))))))
-
- (testing "entry with no matching mapping is left unchanged"
- (let [table-mapping {999 {:db-id 1 :schema "ws" :table "t" :id 456}}
- source {:type "python"
- :body "import pandas as pd"
- :source-tables [{:alias "orders" :database_id 1
- :schema "public" :table "orders" :table_id 123}]}]
- (is (= [{:alias "orders" :database_id 1
- :schema "public" :table "orders" :table_id 123}]
- (:source-tables (remap-python-source table-mapping source))))))))
-
-(defn- sql-tools-quote
- "Quote an identifier using the same pipeline as the workspace middleware.
- Pre-quotes with sql.u/quote-name (triggering was_quoted in the sql-tools backend),
- then feeds through sql-tools/replace-names to get the final dialect-specific quoting
- (e.g., brackets for SQL Server, backticks for MySQL, double quotes for ANSI)."
- [s]
- (let [pre-quoted (sql.u/quote-name driver/*driver* :table s)
- result (sql-tools/replace-names
- driver/*driver*
- "SELECT * FROM __placeholder__"
- {:tables {{:table "__placeholder__"} pre-quoted}}
- {:allow-unused? true})]
- (second (re-find #"(?i)SELECT \* FROM (.+)" result))))
-
-(deftest workspace-sql-remapping-test
- (let [db-id (mt/id)
- ;; The middleware quotes replacement identifiers to preserve case for drivers like Snowflake.
- ;; The final quoting style depends on the sql-tools backend dialect (not HoneySQL),
- ;; so we derive it from the same pipeline the middleware uses.
- q sql-tools-quote]
- (doseq [[label table-mapping input-sql expected-sql]
- [["remaps qualified table reference to isolated table"
- {[db-id "public" "orders"] {:db-id db-id :schema "ws_isolated_123" :table "public__orders" :id 456}}
- "SELECT * FROM public.orders"
- (str "SELECT * FROM " (q "ws_isolated_123") "." (q "public__orders"))]
-
- ["remaps unqualified table reference using nil-schema mapping"
- {[db-id nil "orders"] {:db-id db-id :schema "ws_isolated_123" :table "public__orders" :id 456}}
- "SELECT * FROM orders"
- (str "SELECT * FROM " (q "ws_isolated_123") "." (q "public__orders"))]
-
- ["qualifies unqualified input table reference (no isolation, just adds schema)"
- {[db-id nil "orders"] {:db-id db-id :schema "public" :table "orders" :id 123}}
- "SELECT * FROM orders"
- (str "SELECT * FROM " (q "public") "." (q "orders"))]
-
- ["leaves unmapped tables unchanged"
- {[db-id nil "other_table"] {:db-id db-id :schema "public" :table "other_table" :id 789}}
- "SELECT * FROM orders"
- "SELECT * FROM orders"]
-
- ;; Note: macaw only renames tables in FROM/JOIN clauses, not table qualifiers in column references.
- ;; The output SQL is semantically valid since orders resolves to public.orders in scope.
- ["handles multiple tables in same query"
- {[db-id nil "orders"] {:db-id db-id :schema "public" :table "orders" :id 123}
- [db-id nil "products"] {:db-id db-id :schema "public" :table "products" :id 124}}
- "SELECT * FROM orders JOIN products ON orders.product_id = products.id"
- (str "SELECT * FROM " (q "public") "." (q "orders")
- " JOIN " (q "public") "." (q "products")
- " ON orders.product_id = products.id")]
-
- ["ignores numeric keys in table-mapping"
- {123 {:db-id db-id :schema "ws_isolated_123" :table "public__orders" :id 456}}
- "SELECT * FROM orders"
- "SELECT * FROM orders"]]]
- (testing label
- (let [query {:type "query", :query (lib/native-query (mt/metadata-provider) input-sql)}
- source (#'ws.execute/attach-table-remapping table-mapping query)
- compiled (qp.compile/compile (:query source))]
- (is (= expected-sql (:query compiled))))))))
-
-(deftest workspace-mbql-remapping-throws-test
- (testing "workspace remapping throws on MBQL queries (not yet supported)"
- (let [query (-> (lib/query meta/metadata-provider (meta/table-metadata :orders))
- (assoc-in [:middleware :workspace-remapping]
- {:tables {{:schema "public" :table "orders"}
- {:schema "ws_isolated" :table "public__orders"}}}))]
- (is (thrown-with-msg? ExceptionInfo
- #"Workspace remapping is currently only supported for native queries"
- (ws.qp.middleware/apply-workspace-remapping query))))))
-
-(deftest run-transform-marks-not-stale-on-success
- (testing "Successful transform run marks definition_changed=false"
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0]}
- :properties {:x1 {:definition_changed true :input_data_changed false}}}}]
- (let [t1-ref (workspace-map :x1)]
- (testing "initially stale"
- (is (= {t1-ref {:definition_changed true :input_data_changed false}}
- (ws.tu/staleness-flags workspace-id))))
-
- (ws.tu/mock-run-transform! workspace-id t1-ref)
-
- (testing "after run: definition_changed cleared"
- (is (= {t1-ref {:definition_changed false :input_data_changed false}}
- (ws.tu/staleness-flags workspace-id))))))))
-
-(deftest transform-stale-lifecycle
- (testing "Transform stale lifecycle: create -> run (not stale) -> update (stale)"
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0]}
- :properties {:x1 {:definition_changed true :input_data_changed false}}}}]
- (let [t1-ref (workspace-map :x1)]
- (testing "sanity check that it's stale to start with"
- (is (= {t1-ref {:definition_changed true :input_data_changed false}}
- (ws.tu/staleness-flags workspace-id))))
-
- (testing "Run (mocked): should mark definition_changed as false"
- (ws.tu/mock-run-transform! workspace-id t1-ref)
- (is (= {t1-ref {:definition_changed false :input_data_changed false}}
- (ws.tu/staleness-flags workspace-id))))
-
- (testing "Update source: should mark definition_changed as true"
- (t2/update! :model/WorkspaceTransform {:workspace_id workspace-id :ref_id t1-ref}
- {:source {:type "query" :query (mt/native-query {:query "SELECT 2 as id, 'world' as name"})}})
- (is (= {t1-ref {:definition_changed true :input_data_changed false}}
- (ws.tu/staleness-flags workspace-id))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/impl_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/impl_test.clj
deleted file mode 100644
index 6adfd0358f1..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/impl_test.clj
+++ /dev/null
@@ -1,751 +0,0 @@
-(ns metabase-enterprise.workspaces.impl-test
- (:require
- [clojure.test :refer :all]
- [metabase-enterprise.workspaces.common :as ws.common]
- [metabase-enterprise.workspaces.impl :as ws.impl]
- [metabase-enterprise.workspaces.isolation :as ws.isolation]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase.api.common :as api]
- [metabase.driver.sql :as driver.sql]
- [metabase.lib.core :as lib]
- [metabase.lib.metadata :as lib.metadata]
- [metabase.test :as mt]
- [toucan2.core :as t2]))
-
-(set! *warn-on-reflection* true)
-
-(ws.tu/ws-fixtures!)
-
-(deftest sync-transform-dependencies-test
- (testing "sync-transform-dependencies! writes dependencies and grants access to external inputs"
- (let [mp (mt/metadata-provider)
- query-a (lib/query mp (lib.metadata/table mp (mt/id :orders)))
- query-b (lib/query mp (lib.metadata/table mp (mt/id :products)))
- workspace (ws.tu/create-empty-ws! "Test Workspace")
- grant-calls (atom [])]
- ;; Set up mock BEFORE calling add-to-changeset! since it calls sync-transform-dependencies! internally
- (mt/with-dynamic-fn-redefs [ws.isolation/grant-read-access-to-tables!
- (fn [_database _workspace tables]
- (swap! grant-calls conj (set (map :name tables))))]
- (testing "Transform A depends on ORDERS"
- (ws.common/add-to-changeset! (mt/user->id :crowberto) workspace
- :transform nil
- {:name "Transform A"
- :source {:type "query" :query query-a}
- :target {:database (mt/id)
- :schema "analytics"
- :name "table_a"}})
- (ws.tu/analyze-workspace! (:id workspace))
- (testing "creates output and input records"
- (is (= 1 (t2/count :model/WorkspaceOutput :workspace_id (:id workspace))))
- (is (= 1 (t2/count :model/WorkspaceInput :workspace_id (:id workspace)))))
- (testing "input record has correct table name"
- (is (= (mt/format-name :orders)
- (t2/select-one-fn :table :model/WorkspaceInput :workspace_id (:id workspace)))))
- (testing "grants access to ORDERS"
- (is (= 1 (count @grant-calls)))
- (is (contains? (first @grant-calls) (mt/format-name :orders)))))
-
- (testing "Transform B depends on PRODUCTS, table_a is internal output"
- (reset! grant-calls [])
- (ws.common/add-to-changeset! (mt/user->id :crowberto) workspace
- :transform nil
- {:name "Transform B"
- :source {:type "query" :query query-b}
- :target {:database (mt/id)
- :schema "analytics"
- :name "table_b"}})
- (ws.tu/analyze-workspace! (:id workspace))
- (testing "creates records for both transforms"
- (is (= 2 (t2/count :model/WorkspaceOutput :workspace_id (:id workspace))))
- (is (= 2 (t2/count :model/WorkspaceInput :workspace_id (:id workspace)))))
- (testing "only grants access to newly discovered inputs (PRODUCTS), not already-granted ones"
- (is (= 1 (count @grant-calls)))
- ;; ORDERS was already granted in Transform A, so only PRODUCTS is in this grant call
- (is (not (contains? (first @grant-calls) (mt/format-name :orders))))
- (is (contains? (first @grant-calls) (mt/format-name :products)))
- (is (not (contains? (first @grant-calls) "table_a")))))))))
-
-(deftest sync-transform-dependencies-idempotent-test
- (testing "sync-transform-dependencies! is idempotent"
- (let [mp (mt/metadata-provider)
- query (lib/query mp (lib.metadata/table mp (mt/id :orders)))
- ws (ws.tu/create-empty-ws! "Test Workspace")]
- (mt/with-dynamic-fn-redefs [ws.isolation/grant-read-access-to-tables! (constantly nil)]
- (let [_ (ws.common/add-to-changeset! (mt/user->id :crowberto) ws
- :transform nil
- {:name "Transform"
- :source {:type "query" :query query}
- :target {:database (mt/id)
- :schema "analytics"
- :name "output_table"}})
- ws (t2/select-one :model/Workspace (:id ws))]
- ;; Trigger analysis again to test idempotency
- (ws.impl/increment-graph-version! (:id ws))
- (ws.tu/analyze-workspace! (:id ws))
- (ws.impl/increment-graph-version! (:id ws))
- (ws.tu/analyze-workspace! (:id ws))
- (testing "still has exactly one of each after multiple syncs"
- (is (= 1 (t2/count :model/WorkspaceOutput :workspace_id (:id ws))))
- (is (= 1 (t2/count :model/WorkspaceInput :workspace_id (:id ws))))))))))
-
-;;;; build-remapping tests
-
-(deftest build-remapping-creates-nil-schema-entries-for-default-schema-outputs-test
- (testing "build-remapping creates [db_id nil table] entries for outputs in the default schema"
- (ws.tu/with-resources! [{:keys [workspace-id]} {:workspace {:definitions {:x1 [:t0]}
- :skip-init true}}]
- (let [db (t2/select-one [:model/Database :id :engine :details] (mt/id))
- default-schema (or (driver.sql/default-schema (:engine db))
- ((some-fn :dbname :db) (:details db)))
- ws-transform (t2/select-one :model/WorkspaceTransform :workspace_id workspace-id)]
- ;; Update the transform's target schema to the default schema before analysis,
- ;; so analysis naturally produces an output in the default schema.
- (t2/update! :model/WorkspaceTransform
- {:workspace_id workspace-id, :ref_id (:ref_id ws-transform)}
- {:target (assoc (:target ws-transform) :schema default-schema)})
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- target-table (-> ws-transform :target :name)
- graph (ws.impl/get-or-calculate-graph! workspace)
- result (#'ws.impl/build-remapping workspace graph)
- ws-output (t2/select-one :model/WorkspaceOutput
- :workspace_id workspace-id
- :global_table target-table)
- isolated ((juxt :isolated_schema :isolated_table) ws-output)]
- (doseq [[desc lookup-key] [["qualified [db_id schema table]" [(mt/id) default-schema target-table]]
- ["unqualified [db_id nil table]" [(mt/id) nil target-table]]]]
- (testing (str desc " maps to the isolated table")
- (is (= isolated ((juxt :schema :table) (get (:tables result) lookup-key)))))))))))
-
-;;;; Two-flag staleness tests
-
-(deftest staleness-recomputed-on-graph-read
- (testing "Graph staleness reflects current DB state with two flags"
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0]}
- :properties {:x1 {:definition_changed true
- :input_data_changed false}}}}]
- (let [t1-ref (workspace-map :x1)
- find-t1 (fn [graph] (first (filter #(= t1-ref (:id %)) (:entities graph))))]
- (testing "initial read shows transform as definition_changed"
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/with-staleness workspace (ws.impl/get-or-calculate-graph! workspace))
- entity (find-t1 graph)]
- (is (= {:definition_changed true :input_data_changed false}
- (select-keys entity [:definition_changed :input_data_changed])))))
-
- (t2/update! :model/WorkspaceTransform {:workspace_id workspace-id :ref_id t1-ref}
- {:definition_changed false :input_data_changed true})
-
- (testing "after updating flags in DB, graph read reflects the change"
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/with-staleness workspace (ws.impl/get-or-calculate-graph! workspace))
- entity (find-t1 graph)]
- (is (= {:definition_changed false :input_data_changed true}
- (select-keys entity [:definition_changed :input_data_changed])))))))))
-
-(deftest run-transform-marks-downstream-stale-test
- (testing "Running a transform marks all transitive downstream as input_data_changed"
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:x1]}
- :properties {:x1 {:definition_changed true :input_data_changed false}
- :x2 {:definition_changed false :input_data_changed false}}}}]
- (let [t1-ref (workspace-map :x1)
- t2-ref (workspace-map :x2)]
- (ws.tu/mock-run-transform! workspace-id t1-ref)
-
- (testing "after running t1: t1 is fresh, t2 is input_data_changed"
- (is (= {t1-ref {:definition_changed false :input_data_changed false}
- t2-ref {:definition_changed false :input_data_changed true}}
- (ws.tu/staleness-flags workspace-id))))))))
-
-(deftest run-transform-marks-transitive-downstream-test
- (testing "Running a transform marks all transitive downstream, not just direct"
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:x1] :x3 [:x2]}
- :properties {:x1 {:definition_changed true :input_data_changed false}
- :x2 {:definition_changed false :input_data_changed false}
- :x3 {:definition_changed false :input_data_changed false}}}}]
- (let [t1-ref (workspace-map :x1)
- t2-ref (workspace-map :x2)
- t3-ref (workspace-map :x3)]
- (ws.tu/mock-run-transform! workspace-id t1-ref)
-
- (testing "after running t1: both t2 and t3 are input_data_changed"
- (is (= {t1-ref {:definition_changed false :input_data_changed false}
- t2-ref {:definition_changed false :input_data_changed true}
- t3-ref {:definition_changed false :input_data_changed true}}
- (ws.tu/staleness-flags workspace-id))))))))
-
-(deftest run-transform-clears-both-flags-when-fresh-test
- (testing "Running a transform with fresh ancestor clears both flags"
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:x1]}
- :properties {:x1 {:definition_changed false :input_data_changed false}
- :x2 {:definition_changed true :input_data_changed true}}}}]
- (let [t1-ref (workspace-map :x1)
- t2-ref (workspace-map :x2)]
- (testing "initial state: t1 is fresh, t2 has both flags set"
- (is (= {t1-ref {:definition_changed false :input_data_changed false}
- t2-ref {:definition_changed true :input_data_changed true}}
- (ws.tu/staleness-flags workspace-id))))
-
- (ws.tu/mock-run-transform! workspace-id t2-ref)
-
- (testing "after running t2 with fresh ancestor: both flags are cleared"
- (is (= {t1-ref {:definition_changed false :input_data_changed false}
- t2-ref {:definition_changed false :input_data_changed false}}
- (ws.tu/staleness-flags workspace-id))))))))
-
-;;;; Static graph tests for annotate-staleness
-
-(defn- workspace-transform
- "Create a workspace transform entity for testing."
- [id]
- {:node-type :workspace-transform :id id})
-
-(defn- global-transform
- "Create a global/external transform entity for testing."
- [id]
- {:node-type :external-transform :id id})
-
-(defn- stale->id
- "Group entity IDs by stale status: {true #{stale-ids} false #{non-stale-ids}}"
- [entities]
- (reduce (fn [acc {:keys [id stale]}]
- (update acc (boolean stale) (fnil conj #{}) id))
- {true #{} false #{}}
- entities))
-
-(deftest annotate-staleness-linear-chain-test
- (testing "Linear chain: staleness propagates downstream"
- (let [t1 (workspace-transform "t1")
- t2 (workspace-transform "t2")
- t3 (workspace-transform "t3")
- ;; t1 -> t2 -> t3
- graph {:entities [t1 t2 t3]
- :dependencies {t2 [t1]
- t3 [t2]}}]
- (testing "stale root propagates to all descendants"
- (let [staleness {"t1" {:definition_changed true :input_data_changed false}}
- result (ws.impl/annotate-staleness graph staleness)]
- (is (= {true #{"t1" "t2" "t3"} false #{}}
- (stale->id (:entities result))))))
-
- (testing "stale middle only propagates downstream"
- (let [staleness {"t2" {:definition_changed true :input_data_changed false}}
- result (ws.impl/annotate-staleness graph staleness)]
- (is (= {true #{"t2" "t3"} false #{"t1"}}
- (stale->id (:entities result))))))
-
- (testing "stale leaf doesn't propagate upstream"
- (let [staleness {"t3" {:definition_changed true :input_data_changed false}}
- result (ws.impl/annotate-staleness graph staleness)]
- (is (= {true #{"t3"} false #{"t1" "t2"}}
- (stale->id (:entities result)))))))))
-
-(deftest annotate-staleness-diamond-graph-test
- (testing "Diamond graph: staleness propagates through all paths"
- (let [t1 (workspace-transform "t1")
- t2 (workspace-transform "t2")
- t3 (workspace-transform "t3")
- t4 (workspace-transform "t4")
- ;; t1
- ;; / \
- ;; t2 t3
- ;; \ /
- ;; t4
- graph {:entities [t1 t2 t3 t4]
- :dependencies {t2 [t1]
- t3 [t1]
- t4 [t2 t3]}}]
- (testing "stale root propagates through all paths"
- (let [staleness {"t1" {:definition_changed true :input_data_changed false}}
- result (ws.impl/annotate-staleness graph staleness)]
- (is (= {true #{"t1" "t2" "t3" "t4"} false #{}}
- (stale->id (:entities result))))))
-
- (testing "stale on one branch only propagates through that path"
- (let [staleness {"t2" {:definition_changed true :input_data_changed false}}
- result (ws.impl/annotate-staleness graph staleness)]
- (is (= {true #{"t2" "t4"} false #{"t1" "t3"}}
- (stale->id (:entities result)))))))))
-
-(deftest annotate-staleness-independent-subgraphs-test
- (testing "Independent subgraphs: staleness doesn't cross between them"
- (let [a1 (workspace-transform "a1")
- a2 (workspace-transform "a2")
- b1 (workspace-transform "b1")
- b2 (workspace-transform "b2")
- ;; Subgraph A: a1 -> a2
- ;; Subgraph B: b1 -> b2
- graph {:entities [a1 a2 b1 b2]
- :dependencies {a2 [a1]
- b2 [b1]}}]
- (testing "staleness in subgraph A doesn't affect subgraph B"
- (let [staleness {"a1" {:definition_changed true :input_data_changed false}}
- result (ws.impl/annotate-staleness graph staleness)]
- (is (= {true #{"a1" "a2"} false #{"b1" "b2"}}
- (stale->id (:entities result)))))))))
-
-(deftest annotate-staleness-wide-graph-test
- (testing "Wide graph: stale root propagates to all children"
- (let [t1 (workspace-transform "t1")
- t2 (workspace-transform "t2")
- t3 (workspace-transform "t3")
- t4 (workspace-transform "t4")
- t5 (workspace-transform "t5")
- ;; t1
- ;; / | | | \
- ;; t2 t3 t4 t5 ...
- graph {:entities [t1 t2 t3 t4 t5]
- :dependencies {t2 [t1]
- t3 [t1]
- t4 [t1]
- t5 [t1]}}
- staleness {"t1" {:definition_changed true :input_data_changed false}}
- result (ws.impl/annotate-staleness graph staleness)]
- (is (= {true #{"t1" "t2" "t3" "t4" "t5"} false #{}}
- (stale->id (:entities result)))))))
-
-(deftest annotate-staleness-mixed-transforms-test
- (testing "Mixed transforms: staleness propagates through external transforms"
- (let [t1 (workspace-transform "t1")
- ext (global-transform 100)
- t2 (workspace-transform "t2")
- ;; t1 -> ext -> t2
- graph {:entities [t1 ext t2]
- :dependencies {ext [t1]
- t2 [ext]}}]
- (testing "staleness propagates through external transform to downstream workspace transform"
- (let [staleness {"t1" {:definition_changed true :input_data_changed false}}
- result (ws.impl/annotate-staleness graph staleness)]
- ;; All transforms (workspace and external) downstream of stale t1 should be marked stale
- (is (= {true #{"t1" 100 "t2"} false #{}}
- (stale->id (filter #(#{:workspace-transform :external-transform} (:node-type %))
- (:entities result))))))))))
-
-(deftest annotate-staleness-empty-stale-set-test
- (testing "Empty stale set: nothing is marked stale"
- (let [t1 (workspace-transform "t1")
- t2 (workspace-transform "t2")
- graph {:entities [t1 t2]
- :dependencies {t2 [t1]}}
- staleness {}
- result (ws.impl/annotate-staleness graph staleness)]
- (is (= {true #{} false #{"t1" "t2"}}
- (stale->id (:entities result)))))))
-
-(deftest annotate-staleness-input-data-changed-test
- (testing "input_data_changed triggers staleness just like definition_changed"
- (let [t1 (workspace-transform "t1")
- t2 (workspace-transform "t2")
- graph {:entities [t1 t2]
- :dependencies {t2 [t1]}}
- staleness {"t1" {:definition_changed false :input_data_changed true}}
- result (ws.impl/annotate-staleness graph staleness)]
- (is (= {true #{"t1" "t2"} false #{}}
- (stale->id (:entities result)))))))
-
-(deftest annotate-staleness-preserves-other-fields-test
- (testing "compute-staleness preserves other entity fields"
- (let [t1 {:node-type :workspace-transform :id "t1" :extra-field "preserved"}
- graph {:entities [t1]
- :dependencies {}}
- staleness {"t1" {:definition_changed true :input_data_changed false}}
- result (ws.impl/annotate-staleness graph staleness)
- entity (first (:entities result))]
- (is (= "preserved" (:extra-field entity)))
- (is (true? (:stale entity)))
- (is (true? (:definition_changed entity)))
- (is (false? (:input_data_changed entity))))))
-
-;;;; Static graph tests for graph traversal functions
-
-(deftest upstream-ids-linear-chain-test
- (testing "Linear chain: computes all upstream ancestors"
- (let [t1 (workspace-transform "t1")
- t2 (workspace-transform "t2")
- t3 (workspace-transform "t3")
- ;; t1 -> t2 -> t3
- graph {:entities [t1 t2 t3]
- :dependencies {t2 [t1]
- t3 [t2]}}]
- (testing "t3 has t1 and t2 as ancestors"
- (is (= #{"t1" "t2"}
- (set (ws.impl/upstream-ids graph :workspace-transform "t3")))))
- (testing "t2 has only t1 as ancestor"
- (is (= #{"t1"}
- (set (ws.impl/upstream-ids graph :workspace-transform "t2")))))
- (testing "t1 has no ancestors"
- (is (empty? (ws.impl/upstream-ids graph :workspace-transform "t1")))))))
-
-(deftest upstream-ids-diamond-test
- (testing "Diamond graph: computes all paths"
- (let [t1 (workspace-transform "t1")
- t2 (workspace-transform "t2")
- t3 (workspace-transform "t3")
- t4 (workspace-transform "t4")
- ;; t1
- ;; / \
- ;; t2 t3
- ;; \ /
- ;; t4
- graph {:entities [t1 t2 t3 t4]
- :dependencies {t2 [t1]
- t3 [t1]
- t4 [t2 t3]}}]
- (testing "t4 has all transforms as ancestors"
- (is (= #{"t1" "t2" "t3"}
- (set (ws.impl/upstream-ids graph :workspace-transform "t4")))))
- (testing "t2 has only t1 as ancestor"
- (is (= #{"t1"}
- (set (ws.impl/upstream-ids graph :workspace-transform "t2"))))))))
-
-(deftest upstream-ids-with-external-transforms-test
- (testing "External transforms are traversed but not included when filtered"
- (let [t1 (workspace-transform "t1")
- ext (global-transform 100)
- t2 (workspace-transform "t2")
- ;; t1 -> ext -> t2
- graph {:entities [t1 ext t2]
- :dependencies {ext [t1]
- t2 [ext]}}]
- (testing "t2 can reach through external transform to t1"
- (is (= #{"t1"}
- (set (ws.impl/upstream-ids graph :workspace-transform "t2")))))
- (testing "upstream-nodes returns all node types including external"
- (is (= #{{:node-type :workspace-transform :id "t1"}
- {:node-type :external-transform :id 100}}
- (ws.impl/upstream-nodes graph "t2")))))))
-
-(deftest downstream-ids-linear-chain-test
- (testing "Linear chain: computes all downstream descendants"
- (let [t1 (workspace-transform "t1")
- t2 (workspace-transform "t2")
- t3 (workspace-transform "t3")
- ;; t1 -> t2 -> t3
- graph {:entities [t1 t2 t3]
- :dependencies {t2 [t1]
- t3 [t2]}}]
- (testing "t1 has t2 and t3 as descendants"
- (is (= #{"t2" "t3"}
- (set (ws.impl/downstream-ids graph :workspace-transform "t1")))))
- (testing "t2 has only t3 as descendant"
- (is (= #{"t3"}
- (set (ws.impl/downstream-ids graph :workspace-transform "t2")))))
- (testing "t3 has no descendants"
- (is (empty? (ws.impl/downstream-ids graph :workspace-transform "t3")))))))
-
-(deftest downstream-ids-diamond-test
- (testing "Diamond graph: computes all downstream paths"
- (let [t1 (workspace-transform "t1")
- t2 (workspace-transform "t2")
- t3 (workspace-transform "t3")
- t4 (workspace-transform "t4")
- ;; t1
- ;; / \
- ;; t2 t3
- ;; \ /
- ;; t4
- graph {:entities [t1 t2 t3 t4]
- :dependencies {t2 [t1]
- t3 [t1]
- t4 [t2 t3]}}]
- (testing "t1 has all transforms as descendants"
- (is (= #{"t2" "t3" "t4"}
- (set (ws.impl/downstream-ids graph :workspace-transform "t1")))))
- (testing "t2 has only t4 as descendant"
- (is (= #{"t4"}
- (set (ws.impl/downstream-ids graph :workspace-transform "t2"))))))))
-
-(deftest downstream-ids-with-external-transforms-test
- (testing "External transforms are traversed but not included when filtered"
- (let [t1 (workspace-transform "t1")
- ext (global-transform 100)
- t2 (workspace-transform "t2")
- ;; t1 -> ext -> t2
- graph {:entities [t1 ext t2]
- :dependencies {ext [t1]
- t2 [ext]}}]
- (testing "t1 can reach through external transform to t2"
- (is (= #{"t2"}
- (set (ws.impl/downstream-ids graph :workspace-transform "t1")))))
- (testing "downstream-nodes returns all node types including external"
- (is (= #{{:node-type :workspace-transform, :id "t2"}
- {:node-type :external-transform, :id 100}}
- (ws.impl/downstream-nodes graph "t1")))))))
-
-(deftest downstream-nodes-empty-graph-test
- (testing "Empty graph returns nil"
- (is (nil? (ws.impl/downstream-nodes {:entities [] :dependencies nil} "t1")))))
-
-(deftest upstream-nodes-empty-graph-test
- (testing "Empty graph returns nil"
- (is (nil? (ws.impl/upstream-nodes {:entities [] :dependencies nil} "t1")))))
-
-;;;; Grant gating tests
-
-(deftest non-superuser-does-not-auto-grant-test
- (testing "sync-grant-accesses! is skipped when non-superuser triggers analysis"
- (let [mp (mt/metadata-provider)
- query (lib/query mp (lib.metadata/table mp (mt/id :orders)))
- workspace (ws.tu/create-empty-ws! "Grant Gating Test")
- grant-calls (atom [])]
- (mt/with-dynamic-fn-redefs [ws.isolation/grant-read-access-to-tables!
- (fn [_database _workspace tables]
- (swap! grant-calls conj (set (map :name tables))))]
- ;; Add a transform as superuser so it has source tables
- (ws.common/add-to-changeset! (mt/user->id :crowberto) workspace
- :transform nil
- {:name "Transform A"
- :source {:type "query" :query query}
- :target {:database (mt/id)
- :schema "analytics"
- :name "grant_gate_table"}})
- ;; Wait for workspace initialization to complete
- (ws.tu/ws-done! (:id workspace))
- ;; Reset access_granted to false and clear grant-calls to isolate the test
- (t2/update! :model/WorkspaceInput {:workspace_id (:id workspace)} {:access_granted false})
- (reset! grant-calls [])
- ;; Increment analysis_version to make the transform stale so analyze-stale-transforms! has work to do
- (let [ref-id (t2/select-one-fn :ref_id :model/WorkspaceTransform :workspace_id (:id workspace))]
- (ws.impl/increment-analysis-version! (:id workspace) ref-id))
- (let [workspace (t2/select-one :model/Workspace (:id workspace))]
- (testing "as non-superuser, grant is NOT called"
- (binding [api/*is-superuser?* false]
- (#'ws.impl/analyze-stale-transforms! workspace))
- (is (empty? @grant-calls) "Should not auto-grant when non-superuser"))
- (testing "as superuser, grant IS called"
- (binding [api/*is-superuser?* true]
- (#'ws.impl/analyze-stale-transforms! workspace))
- (is (seq @grant-calls) "Should auto-grant when superuser")))))))
-
-;;;; Workspace input normalization tests
-
-(deftest workspace-input-normalization-test
- (testing "Two transforms sharing an input table produce one WorkspaceInput but two WorkspaceInputTransform rows"
- (let [mp (mt/metadata-provider)
- query (lib/query mp (lib.metadata/table mp (mt/id :orders)))
- ws (ws.tu/create-empty-ws! "Normalization Test")]
- (mt/with-dynamic-fn-redefs [ws.isolation/grant-read-access-to-tables! (constantly nil)]
- ;; Add two transforms that both read from ORDERS
- (ws.common/add-to-changeset! (mt/user->id :crowberto) ws
- :transform nil
- {:name "Transform A"
- :source {:type "query" :query query}
- :target {:database (mt/id)
- :schema "analytics"
- :name "norm_table_a"}})
- (ws.common/add-to-changeset! (mt/user->id :crowberto) ws
- :transform nil
- {:name "Transform B"
- :source {:type "query" :query query}
- :target {:database (mt/id)
- :schema "analytics"
- :name "norm_table_b"}})
- (ws.tu/analyze-workspace! (:id ws))
- (let [orders-name (mt/format-name :orders)]
- (testing "exactly one WorkspaceInput row for ORDERS"
- (is (= 1 (t2/count :model/WorkspaceInput
- :workspace_id (:id ws)
- :table orders-name))))
- (testing "at least two WorkspaceInputTransform rows (one per transform)"
- (let [input-id (t2/select-one-fn :id :model/WorkspaceInput
- :workspace_id (:id ws)
- :table orders-name)
- ref-ids (t2/select-fn-set :ref_id :model/WorkspaceInputTransform
- :workspace_input_id input-id)]
- (is (= 2 (count ref-ids))
- "Two distinct transforms should reference this input"))))))))
-
-;;;; Execute workspace ungranted transform tests
-
-(deftest execute-workspace-fails-ungranted-test
- (testing "execute-workspace! fails transforms with ungranted inputs"
- ;; Use different input tables so each transform has an independent WorkspaceInput
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:t1]}}}]
- (let [t1-ref (workspace-map :x1)
- t2-ref (workspace-map :x2)]
- ;; Un-grant only t2's inputs
- (let [t2-input-ids (t2/select-fn-set :workspace_input_id
- :model/WorkspaceInputTransform
- :workspace_id workspace-id
- :ref_id t2-ref)]
- (is (seq t2-input-ids) "t2 should have WorkspaceInputTransform records after analysis")
- (t2/update! :model/WorkspaceInput
- {:id [:in t2-input-ids]}
- {:access_granted false}))
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/get-or-calculate-graph! workspace)]
- (ws.tu/with-mocked-execution
- (let [result (ws.impl/execute-workspace! workspace graph)]
- (testing "granted transform succeeds"
- (is (some #{t1-ref} (:succeeded result))))
- (testing "ungranted transform is in :not_run"
- (is (some #{t2-ref} (:not_run result)))))))))))
-
-(deftest execute-workspace-skips-ungranted-external-transforms-test
- (testing "execute-workspace! skips external transforms with ungranted external inputs"
- ;; Graph: (x1) -> x2 -> (x3) where x2 is an enclosed external transform
- ;; x1 and x3 are workspace checkouts, x2 is external
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map global-map]}
- {:global {:x1 [:t0] :x2 [:x1] :x3 [:x2]}
- :workspace {:checkouts [:x1 :x3]}}]
- (let [x1-ref (workspace-map :x1)
- x2-id (global-map :x2)
- x2-str (str "global-id:" x2-id)
- x3-ref (workspace-map :x3)
- ;; x2 reads from t0 (a table that exists in the DB); simulate this as an ungranted external input.
- t0-id (global-map :t0)]
- ;; Insert input dependency: x2 depends on table t0
- (t2/insert! :model/Dependency {:from_entity_type "transform"
- :from_entity_id x2-id
- :to_entity_type "table"
- :to_entity_id t0-id})
- ;; Insert an ungranted WorkspaceInputExternal row for t0
- (let [{:keys [db_id schema name]} (t2/select-one [:model/Table :db_id :schema :name] t0-id)]
- (t2/insert! :model/WorkspaceInputExternal
- {:workspace_id workspace-id
- :graph_version 0
- :db_id db_id
- :schema schema
- :table name
- :table_id t0-id
- :access_granted false}))
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/get-or-calculate-graph! workspace)]
- (ws.tu/with-mocked-execution
- (let [result (ws.impl/execute-workspace! workspace graph)]
- (testing "workspace transforms with granted inputs succeed"
- (is (some #{x1-ref} (:succeeded result)))
- (is (some #{x3-ref} (:succeeded result))))
- (testing "external transform with ungranted external input is in :not_run"
- (is (some #{x2-str} (:not_run result)))))))))))
-
-;;;; run-stale-ancestors! tests
-
-(deftest run-stale-ancestors-runs-only-stale-ancestors-test
- (testing "run-stale-ancestors! only runs ancestors that are stale (including transitively stale)"
- ;; Graph:
- ;; x1 -> x2 \
- ;; x3 -> x4 -> x7
- ;; x5 -> x6 /
- ;; x1 and x4 are locally stale, x2 is transitively stale (depends on x1)
- ;; x3, x5, x6 are fresh and should NOT run
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:x1]
- :x3 [:t0] :x4 [:x3]
- :x5 [:t0] :x6 [:x5]
- :x7 [:x2 :x4 :x6]}
- :properties {:x1 {:definition_changed true}
- :x2 {:definition_changed false}
- :x3 {:definition_changed false}
- :x4 {:definition_changed true}
- :x5 {:definition_changed false}
- :x6 {:definition_changed false}
- :x7 {:definition_changed false}}}}]
- (let [t1-ref (workspace-map :x1)
- t2-ref (workspace-map :x2)
- t4-ref (workspace-map :x4)
- t7-ref (workspace-map :x7)]
- (ws.tu/with-mocked-execution
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/get-or-calculate-graph! workspace)
- result (ws.impl/run-stale-ancestors! workspace graph t7-ref)
- succeeded ^java.util.List (:succeeded result)]
- (testing "x1, x2 (transitively stale), and x4 run; x3, x5, x6 do not"
- (is (= (set [t1-ref t2-ref t4-ref]) (set succeeded)))
- (is (= [] (:failed result)))
- (is (= [] (:not_run result))))
- (testing "x1 runs before x2 (dependency order within branch)"
- (is (< (.indexOf succeeded t1-ref) (.indexOf succeeded t2-ref))))))))))
-
-(deftest run-stale-ancestors-respects-dependency-order-test
- (testing "run-stale-ancestors! runs ancestors in dependency order"
- ;; Chain: t1 -> t2 -> t3, where t1 and t2 are stale
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:x1] :x3 [:x2]}
- :properties {:x1 {:definition_changed true}
- :x2 {:definition_changed true}
- :x3 {:definition_changed false}}}}]
- (let [t1-ref (workspace-map :x1)
- t2-ref (workspace-map :x2)
- t3-ref (workspace-map :x3)
- run-order (atom [])]
- (mt/with-dynamic-fn-redefs [ws.impl/run-transform!
- (fn [_ws _graph transform & _]
- (swap! run-order conj (:ref_id transform))
- {:status :succeeded})]
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/get-or-calculate-graph! workspace)
- result (ws.impl/run-stale-ancestors! workspace graph t3-ref)]
- (testing "both stale ancestors are run in order (t1 before t2)"
- (is (= [t1-ref t2-ref] @run-order))
- (is (= [t1-ref t2-ref] (:succeeded result))))))))))
-
-(deftest run-stale-ancestors-stops-on-failure-test
- (testing "run-stale-ancestors! stops on first failure and marks remaining as not_run"
- ;; Chain: t1 -> t2 -> t3, where t1 and t2 are stale, t1 fails
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:x1] :x3 [:x2]}
- :properties {:x1 {:definition_changed true}
- :x2 {:definition_changed true}
- :x3 {:definition_changed false}}}}]
- (let [t1-ref (workspace-map :x1)
- t2-ref (workspace-map :x2)
- t3-ref (workspace-map :x3)]
- (mt/with-dynamic-fn-redefs [ws.impl/run-transform!
- (fn [_ws _graph transform & _]
- (if (= (:ref_id transform) t1-ref)
- {:status :failed :message "Simulated failure"}
- {:status :succeeded}))]
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/get-or-calculate-graph! workspace)
- result (ws.impl/run-stale-ancestors! workspace graph t3-ref)]
- (testing "t1 fails, t2 is not_run"
- (is (= [] (:succeeded result)))
- (is (= [t1-ref] (:failed result)))
- (is (= [t2-ref] (:not_run result))))))))))
-
-(deftest run-stale-ancestors-no-stale-ancestors-test
- (testing "run-stale-ancestors! returns empty results when no ancestors are stale"
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map]}
- {:workspace {:definitions {:x1 [:t0] :x2 [:x1]}
- :properties {:x1 {:definition_changed false}
- :x2 {:definition_changed false}}}}]
- (let [t2-ref (workspace-map :x2)]
- (ws.tu/with-mocked-execution
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/get-or-calculate-graph! workspace)
- result (ws.impl/run-stale-ancestors! workspace graph t2-ref)]
- (testing "no transforms are run"
- (is (= [] (:succeeded result)))
- (is (= [] (:failed result)))
- (is (= [] (:not_run result))))))))))
-
-(deftest run-stale-ancestors-includes-external-transforms-test
- (testing "run-stale-ancestors! includes enclosed external transforms in the ancestor chain"
- ;; Graph: (x1) -> x2 -> (x3) where x2 is an external (global) transform
- ;; x1 is a workspace checkout, x2 is enclosed (global, not checked out), x3 is a workspace checkout
- ;; x1 is locally stale -> x2 becomes transitively stale -> running ancestors for x3 should run both x1 and x2
- (ws.tu/with-resources! [{:keys [workspace-id workspace-map global-map]}
- {:global {:x1 [:t0] :x2 [:x1] :x3 [:x2]}
- :workspace {:checkouts [:x1 :x3]
- :properties {:x1 {:definition_changed true}
- :x3 {:definition_changed false}}}}]
- (let [x1-ref (workspace-map :x1)
- x2-global (str "global-id:" (global-map :x2))
- x3-ref (workspace-map :x3)]
- (ws.tu/with-mocked-execution
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/get-or-calculate-graph! workspace)
- result (ws.impl/run-stale-ancestors! workspace graph x3-ref)
- succeeded ^java.util.List (:succeeded result)]
- (testing "both workspace transform x1 and external transform x2 are run"
- (is (= #{x1-ref x2-global} (set succeeded)))
- (is (= [] (:failed result)))
- (is (= [] (:not_run result))))
- (testing "x1 runs before x2 (dependency order)"
- (is (< (.indexOf succeeded x1-ref) (.indexOf succeeded x2-global))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/isolation_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/isolation_test.clj
deleted file mode 100644
index 62ed154f70e..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/isolation_test.clj
+++ /dev/null
@@ -1,265 +0,0 @@
-(ns ^:mb/driver-tests metabase-enterprise.workspaces.isolation-test
- (:require
- [clojure.java.jdbc :as jdbc]
- [clojure.test :refer :all]
- [metabase-enterprise.workspaces.common :as ws.common]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase.driver :as driver]
- [metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
- [metabase.driver.sql.util :as sql.u]
- [metabase.driver.util :as driver.u]
- [metabase.lib.core :as lib]
- [metabase.test :as mt]
- [toucan2.core :as t2]))
-
-(ws.tu/ws-fixtures!)
-
-(set! *warn-on-reflection* true)
-
-;;; Test helper multimethod to verify cleanup
-
-(defn- has-results?
- "Returns true if the query returns any results."
- [conn-spec query]
- (-> (jdbc/query conn-spec query) seq boolean))
-
-(defmulti workspace-isolation-resources-exist?
- "Check if isolation resources still exist for the workspace.
- Returns a map with keys indicating which resources exist."
- {:arglists '([database workspace])}
- (fn [database _workspace]
- (driver/the-driver (:engine database)))
- :hierarchy #'driver/hierarchy)
-
-(defmethod workspace-isolation-resources-exist? :postgres
- [database workspace]
- (let [schema-name (driver.u/workspace-isolation-namespace-name workspace)
- username (driver.u/workspace-isolation-user-name workspace)
- conn-spec (sql-jdbc.conn/db->pooled-connection-spec (:id database))]
- {:schema (has-results? conn-spec
- ["SELECT 1 FROM information_schema.schemata WHERE schema_name = ?" schema-name])
- :user (has-results? conn-spec
- ["SELECT 1 FROM pg_user WHERE usename = ?" username])}))
-
-(defmethod workspace-isolation-resources-exist? :h2
- [database workspace]
- (let [schema-name (driver.u/workspace-isolation-namespace-name workspace)
- username (driver.u/workspace-isolation-user-name workspace)
- conn-spec (sql-jdbc.conn/db->pooled-connection-spec (:id database))]
- {:schema (has-results? conn-spec
- ["SELECT 1 FROM INFORMATION_SCHEMA.SCHEMATA WHERE UPPER(SCHEMA_NAME) = UPPER(?)" schema-name])
- :user (has-results? conn-spec
- ["SELECT 1 FROM INFORMATION_SCHEMA.USERS WHERE UPPER(USER_NAME) = UPPER(?)" username])}))
-
-(defmethod workspace-isolation-resources-exist? :snowflake
- [database workspace]
- (let [schema-name (driver.u/workspace-isolation-namespace-name workspace)
- db-name (-> database :details :db)
- role-name (format "MB_ISOLATION_ROLE_%s" (:id workspace))
- username (driver.u/workspace-isolation-user-name workspace)
- conn-spec (sql-jdbc.conn/db->pooled-connection-spec (:id database))]
- {:schema (has-results? conn-spec
- [(format "SHOW SCHEMAS LIKE '%s' IN DATABASE \"%s\"" schema-name db-name)])
- :user (has-results? conn-spec
- [(format "SHOW USERS LIKE '%s'" username)])
- :role (has-results? conn-spec
- [(format "SHOW ROLES LIKE '%s'" role-name)])}))
-
-(defmethod workspace-isolation-resources-exist? :sqlserver
- [database workspace]
- (let [schema-name (driver.u/workspace-isolation-namespace-name workspace)
- username (driver.u/workspace-isolation-user-name workspace)
- conn-spec (sql-jdbc.conn/db->pooled-connection-spec (:id database))]
- {:schema (has-results? conn-spec
- ["SELECT 1 FROM sys.schemas WHERE name = ?" schema-name])
- :user (has-results? conn-spec
- ["SELECT 1 FROM sys.database_principals WHERE name = ?" username])
- :login (has-results? conn-spec
- ["SELECT 1 FROM master.sys.server_principals WHERE name = ?" username])}))
-
-(defmethod workspace-isolation-resources-exist? :clickhouse
- [database workspace]
- (let [db-name (driver.u/workspace-isolation-namespace-name workspace)
- username (driver.u/workspace-isolation-user-name workspace)
- conn-spec (sql-jdbc.conn/db->pooled-connection-spec (:id database))]
- {:database (has-results? conn-spec
- ["SELECT 1 FROM system.databases WHERE name = ?" db-name])
- :user (has-results? conn-spec
- ["SELECT 1 FROM system.users WHERE name = ?" username])}))
-
-(defmethod workspace-isolation-resources-exist? :mysql
- [database workspace]
- (let [db-name (driver.u/workspace-isolation-namespace-name workspace)
- username (driver.u/workspace-isolation-user-name workspace)
- conn-spec (sql-jdbc.conn/db->pooled-connection-spec (:id database))]
- {:database (has-results? conn-spec
- ["SELECT 1 FROM information_schema.schemata WHERE schema_name = ?" db-name])
- :user (has-results? conn-spec
- ["SELECT 1 FROM mysql.user WHERE user = ?" username])}))
-
-;;; Tests
-(deftest destroy-workspace-isolation-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (ws.tu/with-workspaces! [workspace {:name "Test destroy isolation"}]
- (ws.common/add-to-changeset! (mt/user->id :crowberto) workspace
- :transform nil
- {:name "Transform A"
- :source {:type "query"
- :query (-> (ws.tu/q :orders) (lib/limit 1))}
- :target {:database (mt/id)
- :schema "analytics"
- :name "table_a"}})
- (let [workspace (ws.tu/ws-done! workspace)
- database (mt/db)]
- (testing "resources are created during workspace initialization"
- (let [resources (workspace-isolation-resources-exist? database workspace)]
- (is (every? true? (vals resources)))))
-
- (testing "destroy removes all isolation resources"
- (driver/destroy-workspace-isolation! (driver.u/database->driver database) database workspace)
- (let [resources (workspace-isolation-resources-exist? database workspace)]
- (is (every? false? (vals resources)))))
-
- (testing "destroy is idempotent"
- (driver/destroy-workspace-isolation! (driver.u/database->driver database) database workspace))))))
-
-;;; check-isolation-permissions tests
-
-(deftest check-isolation-permissions-success-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (testing "returns nil when connection has all required permissions"
- (let [database (mt/db)
- test-table (t2/select-one [:model/Table :schema :name] (mt/id :orders))]
- (is (nil? (driver/check-isolation-permissions
- (driver/the-driver (:engine database))
- database
- test-table)))))))
-
-(deftest check-isolation-permissions-no-artifacts-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (testing "leaves no artifacts after check due to transaction rollback"
- (let [database (mt/db)
- test-workspace {:id "00000000-0000-0000-0000-000000000000"
- :name "_mb_perm_check_"}
- test-table (t2/select-one [:model/Table :schema :name] (mt/id :orders))]
- ;; Run the check
- (driver/check-isolation-permissions
- (driver/the-driver (:engine database))
- database
- test-table)
- ;; Verify no artifacts remain - the test workspace should not have any resources
- (let [resources (workspace-isolation-resources-exist? database test-workspace)]
- (is (every? false? (vals resources))
- "No isolation resources should exist after permission check"))))))
-
-(deftest check-isolation-permissions-init-failure-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (testing "returns error message when init fails"
- (let [database (mt/db)
- test-table (t2/select-one [:model/Table :schema :name] (mt/id :orders))]
- (with-redefs [driver/init-workspace-isolation!
- (fn [_driver _database _workspace]
- (throw (ex-info "permission denied" {:step :init})))]
- (is (some? (driver/check-isolation-permissions
- (driver/the-driver (:engine database))
- database
- test-table))
- "Should return error message when init fails"))))))
-
-(deftest check-isolation-permissions-grant-failure-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (testing "returns error message when grant fails"
- (let [database (mt/db)
- test-table (t2/select-one [:model/Table :schema :name] (mt/id :orders))]
- (with-redefs [driver/grant-workspace-read-access!
- (fn [_driver _database _workspace _tables]
- (throw (ex-info "permission denied" {:step :grant})))]
- (is (some? (driver/check-isolation-permissions
- (driver/the-driver (:engine database))
- database
- test-table))
- "Should return error message when grant fails"))))))
-
-(deftest check-isolation-permissions-destroy-failure-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (testing "returns error message when destroy fails"
- (let [database (mt/db)
- test-table (t2/select-one [:model/Table :schema :name] (mt/id :orders))]
- (with-redefs [driver/destroy-workspace-isolation!
- (fn [_driver _database _workspace]
- (throw (ex-info "permission denied" {:step :destroy})))]
- (is (some? (driver/check-isolation-permissions
- (driver/the-driver (:engine database))
- database
- test-table))
- "Should return error message when destroy fails"))))))
-
-(deftest check-isolation-permissions-nil-table-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (testing "returns nil when test-table is nil (skips grant step)"
- (let [database (mt/db)]
- (is (nil? (driver/check-isolation-permissions
- (driver/the-driver (:engine database))
- database
- nil))
- "Should succeed when test-table is nil")))))
-
-;;; Identifier quoting tests for grant-workspace-read-access!
-
-(defn- with-pg-isolation!
- "Set up Postgres workspace isolation manually and call f with [workspace conn-spec].
- Tears down isolation resources afterward."
- [f]
- (let [database (mt/db)
- test-ws {:id (str (random-uuid))
- :name "_test_quoting_"}
- init-result (driver/init-workspace-isolation! :postgres database test-ws)
- workspace (merge test-ws init-result)
- conn-spec (sql-jdbc.conn/db->pooled-connection-spec (:id database))]
- (try
- (f workspace conn-spec)
- (finally
- (driver/destroy-workspace-isolation! :postgres database workspace)))))
-
-(defn- pg-create-table!
- "Create a table in Postgres using properly-escaped DDL."
- [conn-spec schema table-name]
- (let [qs (sql.u/quote-name :postgres :schema schema)
- qt (sql.u/quote-name :postgres :table table-name)]
- (jdbc/execute! conn-spec [(format "CREATE TABLE %s.%s (id INT)" qs qt)])))
-
-(defn- pg-drop-schema!
- [conn-spec schema]
- (jdbc/execute! conn-spec [(format "DROP SCHEMA IF EXISTS %s CASCADE"
- (sql.u/quote-name :postgres :schema schema))]))
-
-(deftest grant-workspace-read-access-escapes-table-names-test
- (mt/test-driver :postgres
- (testing "table names with embedded delimiter are properly quoted"
- (with-pg-isolation!
- (fn [workspace conn-spec]
- (let [ws-schema (:schema workspace)
- evil-name "evil\"table"]
- (pg-create-table! conn-spec ws-schema evil-name)
- (is (driver/grant-workspace-read-access!
- :postgres (mt/db) workspace
- [{:schema ws-schema :name evil-name}])
- "GRANT should succeed for table names with embedded quotes")))))))
-
-(deftest grant-workspace-read-access-escapes-schema-names-test
- (mt/test-driver :postgres
- (testing "schema names with embedded delimiter are properly quoted"
- (with-pg-isolation!
- (fn [workspace conn-spec]
- (let [evil-schema "evil\"schema"
- table-name "normal_table"]
- (jdbc/execute! conn-spec [(format "CREATE SCHEMA %s"
- (sql.u/quote-name :postgres :schema evil-schema))])
- (try
- (pg-create-table! conn-spec evil-schema table-name)
- (is (driver/grant-workspace-read-access!
- :postgres (mt/db) workspace
- [{:schema evil-schema :name table-name}])
- "GRANT should succeed for schema names with embedded quotes")
- (finally
- (pg-drop-schema! conn-spec evil-schema)))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/models/workspace_transform_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/models/workspace_transform_test.clj
deleted file mode 100644
index 967600cebed..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/models/workspace_transform_test.clj
+++ /dev/null
@@ -1,32 +0,0 @@
-(ns metabase-enterprise.workspaces.models.workspace-transform-test
- "Tests for WorkspaceTransform model behavior."
- (:require
- [clojure.test :refer :all]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase.test :as mt]
- [toucan2.core :as t2]))
-
-(ws.tu/ws-fixtures!)
-
-(deftest workspace-transform-definition-stale-marking
- (testing "WorkspaceTransform definition_changed is marked based on source/target changes"
- (ws.tu/with-resources! [{ws-id :workspace-id, :keys [workspace-map]}
- {:workspace {:definitions {:x1 [:t0]}}}]
- (let [t1-ref (workspace-map :x1)
- ws+ref {:workspace_id ws-id, :ref_id t1-ref}
- unchanged {:definition_changed false, :input_data_changed false}
- change! (fn [updates]
- ;; First reset the stale tracking
- (t2/update! :model/WorkspaceTransform ws+ref unchanged)
- (t2/update! :model/WorkspaceTransform ws+ref updates))]
- (testing "initially definition is stale - as we've never been run"
- (is (= {t1-ref {:definition_changed true, :input_data_changed false}} (ws.tu/staleness-flags ws-id))))
- (testing "marks as stale when source changes"
- (change! {:source {:type "query" :query (mt/native-query {:query "SELECT 2 as id"})}})
- (is (= {t1-ref {:definition_changed true, :input_data_changed false}} (ws.tu/staleness-flags ws-id))))
- (testing "marks as stale when target changes"
- (change! {:target {:type "table", :database (mt/id), :schema nil, :name "new_table"}})
- (is (= {t1-ref {:definition_changed true, :input_data_changed false}} (ws.tu/staleness-flags ws-id))))
- (testing "preserves definition_changed when other fields change"
- (change! {:name "New Name"})
- (is (= {t1-ref {:definition_changed false :input_data_changed false}} (ws.tu/staleness-flags ws-id))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/test_util.clj b/enterprise/backend/test/metabase_enterprise/workspaces/test_util.clj
deleted file mode 100644
index cab38ac77d1..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/test_util.clj
+++ /dev/null
@@ -1,526 +0,0 @@
-(ns ^:mb/driver-tests metabase-enterprise.workspaces.test-util
- (:require
- [clojure.set :as set]
- [clojure.string :as str]
- [clojure.test :refer :all]
- [metabase-enterprise.dependencies.test-util :as deps.test]
- [metabase-enterprise.workspaces.common :as ws.common]
- [metabase-enterprise.workspaces.dag-abstract :as dag-abstract]
- [metabase-enterprise.workspaces.execute :as ws.execute]
- [metabase-enterprise.workspaces.impl :as ws.impl]
- [metabase-enterprise.workspaces.isolation :as ws.isolation]
- [metabase-enterprise.workspaces.models.workspace :as ws.model]
- [metabase.app-db.core :as app-db]
- [metabase.config.core :as config]
- [metabase.driver :as driver]
- [metabase.driver.sql.normalize :as sql.normalize]
- [metabase.driver.sql.query-processor :as sql.qp]
- [metabase.lib.core :as lib]
- [metabase.lib.metadata :as lib.metadata]
- [metabase.query-processor.preprocess :as qp.preprocess]
- ^{:clj-kondo/ignore [:deprecated-namespace]}
- [metabase.query-processor.store :as qp.store]
- [metabase.search.test-util :as search.tu]
- [metabase.test :as mt]
- [metabase.util :as u]
- [metabase.util.log :as log]
- [toucan2.core :as t2])
- (:import
- (java.time Instant)))
-
-(set! *warn-on-reflection* true)
-
-(defn unique-name
- "Generate a unique name for test resources to avoid conflicts."
- ([] (unique-name "Test"))
- ([prefix] (str prefix " " (random-uuid))))
-
-;;;; Shorthand notation helpers
-
-(defn transform?
- "Check if keyword represents a transform (keyword starting with 'x')."
- [kw]
- (and (keyword? kw)
- (= \x (first (name kw)))))
-
-(defn mock-table?
- "Check if keyword represents a mock table (keyword starting with 't')."
- [kw]
- (and (keyword? kw)
- (= \t (first (name kw)))))
-
-(defn real-table?
- "Check if ref is a string (existing table reference by name)."
- [ref]
- (string? ref))
-
-(defn kw->id
- "Extract numeric id from shorthand keyword (e.g., :x1 -> 1, :t2 -> 2)."
- [kw]
- (assert (keyword? kw) (str "kw->id requires a keyword, got: " (pr-str kw)))
- (parse-long (subs (name kw) 1)))
-
-(defn- real-table-id
- "Look up an existing table by name (case-insensitive). Returns table ID."
- [db-id table-name]
- (or (t2/select-one-fn :id :model/Table
- :db_id db-id
- :active true
- {:where [:= [:lower :name] (u/lower-case-en table-name)]})
- (throw (ex-info (str "Existing table not found: " table-name) {:table table-name}))))
-
-;;;; Query helpers
-
-(defn q
- "Create a lib query against a test database table, e.g. `(q :orders)`.
- Can be threaded with lib functions: `(-> (q :orders) (lib/limit 10))`."
- [table-kw]
- (let [mp (mt/metadata-provider)]
- (lib/query mp (lib.metadata/table mp (mt/id table-kw)))))
-
-(defn mbql->native
- "Compile a query to a native SQL map. Works with both legacy MBQL and lib (MBQL 5) queries.
- This generates driver-specific SQL with properly qualified table names."
- [query]
- (qp.store/with-metadata-provider (mt/id)
- (sql.qp/mbql->native driver/*driver* (qp.preprocess/preprocess query))))
-
-(defn ->native
- "Compile a query to native SQL form wrapped as a native query map.
- Useful when building test transforms, which need to be SQL flavored."
- [query]
- (mt/native-query (mbql->native query)))
-
-;;;; Building blocks for test resource creation
-
-(defn- build-source-query
- "Build a native source query referencing the given table IDs."
- [db-id table-ids]
- (if (seq table-ids)
- {:database db-id
- :type :native
- :native {:query (str "SELECT * FROM "
- (->> (t2/select [:model/Table :schema :name] :id [:in table-ids])
- (map #(str (:schema %) "." (:name %)))
- (str/join ", ")))}}
- {:database db-id
- :type :native
- :native {:query "SELECT 1"}}))
-
-(defn- build-transform-target
- "Build target map for a transform."
- [db-id tx-sym schema]
- (let [driver (t2/select-one-fn :engine [:model/Database :engine] db-id)
- normalize #(sql.normalize/normalize-name driver %)]
- {:type "table"
- :database db-id
- :schema (some-> schema normalize)
- :name (normalize (str "test_table_" (kw->id tx-sym)))}))
-
-(defn create-tables!
- "Create test tables for the given table symbols. Returns {symbol -> table-id}."
- [db-id table-syms schema]
- (let [driver (t2/select-one-fn :engine [:model/Database :engine] db-id)
- normalize #(sql.normalize/normalize-name driver %)]
- (into {}
- (for [t table-syms]
- [t (t2/insert-returning-pk! :model/Table
- {:db_id db-id
- :schema (some-> schema normalize)
- :name (normalize (str "test_table_" (kw->id t)))
- :active true})]))))
-
-(defn create-transform!
- "Create a global transform with given dependencies. Returns transform ID."
- [db-id tx-sym deps id-map schema]
- (let [table-ids (->> deps
- (keep #(cond
- (mock-table? %) (id-map %)
- (real-table? %) (real-table-id db-id %)
- :else nil)))
- source (build-source-query db-id table-ids)
- target (build-transform-target db-id tx-sym schema)]
- (t2/insert-returning-pk! :model/Transform
- {:name (str "Test " (name tx-sym))
- :source {:type :query :query source}
- :target target})))
-
-(defn add-transform-to-workspace!
- "Add a transform to a workspace via API. Returns ref-id.
-
- For checkouts: provide :global-tx (the global transform to checkout)
- For new transforms: provide :deps and :id-map to build the source
- If both :global-tx and :deps are provided, the deps override the global source."
- [db-id ws-id tx-sym {:keys [global-tx deps id-map schema]}]
- (let [resolve-table-ids (fn [deps]
- (->> deps
- (keep #(cond
- (mock-table? %) (id-map %)
- (real-table? %) (real-table-id db-id %)
- :else nil))))
- body (if global-tx
- ;; Checkout: use global transform's body (can be overridden with deps)
- (cond-> (select-keys global-tx [:name :description :source :target])
- deps (assoc :source {:type :query
- :query (build-source-query db-id (resolve-table-ids deps))}))
- ;; New: build from deps
- {:name (str "Test " (name tx-sym))
- :source {:type :query :query (build-source-query db-id (resolve-table-ids deps))}
- :target (build-transform-target db-id tx-sym schema)})
- response (mt/user-http-request :crowberto :post 200
- (str "ee/workspace/" ws-id "/transform")
- (cond-> body
- global-tx (assoc :global_id (:id global-tx))))]
- (:ref_id response)))
-
-;;;; Orchestration functions
-
-(defn- create-workspace-for-test! [props]
- (let [creator-id (or (:creator_id props) (mt/user->id :crowberto))
- props (-> props
- (dissoc :creator_id)
- (update :database_id #(or % (mt/id))))]
- (mt/with-current-user creator-id
- (ws.common/create-workspace! creator-id props))))
-
-(defn ws-done!
- "Poll until workspace status is no longer :pending.
- Returns immediately if workspace has not started initializing, which requires a transform being added."
- [ws-or-id]
- (let [ws-id (cond-> ws-or-id
- (map? ws-or-id) :id)]
- (or (u/poll {:thunk #(t2/select-one :model/Workspace :id ws-id)
- :done? #(not= :pending (:db_status %))
- ;; some cloud drivers are really slow
- :timeout-ms (if config/is-dev? 10000 60000)})
- (throw (ex-info "Timeout waiting for workspace to finish initializing" {:workspace-id ws-id})))))
-
-(defn ws-ready!
- "Like [[ws-done!]], but throws if the workspace does not reach :ready status."
- [ws-or-id]
- (u/prog1 (ws-done! ws-or-id)
- (when (not= :ready (:db_status <>))
- (throw (ex-info "Workspace failed to become ready"
- {:db_status (:db_status <>) :workspace-id (:id <>)})))))
-
-(defn analyze-workspace!
- "Trigger the reconstruction and persistence of the workspace graph."
- [id]
- (mt/user-http-request :crowberto :get 200 (str "ee/workspace/" id "/graph")))
-
-(defn force-grant-all-inputs!
- "Mark all WorkspaceInput records for a workspace as granted.
- Test tables created by [[create-tables!]] are metadata-only (no physical DB tables),
- so the isolation layer's GRANT fails silently and `access_granted` stays false.
- Triggers graph calculation first to ensure WorkspaceInput records exist."
- [workspace-id]
- (analyze-workspace! workspace-id)
- (t2/update! :model/WorkspaceInput {:workspace_id workspace-id} {:access_granted true}))
-
-(defn create-resources!
- "Create test resources from shorthand notation for both global and workspace transforms.
-
- Input: {:database-id int (optional, defaults to mt/id)
- :global dependencies-graph (shorthand)
- :workspace {:checkouts ids, :definitions dependencies-graph (shorthand)}}
-
- Returns: {:workspace-id int (or nil if no workspace)
- :global-map {symbol -> db-id}
- :workspace-map {symbol -> ref-id}}
-
- NOTE: Caller should wrap in mt/with-model-cleanup for proper cleanup."
- [{:keys [database-id global workspace]}]
- (let [db-id (or database-id (mt/id))
- definitions (:definitions workspace)
- checkouts (set (:checkouts workspace))
- schema (str/replace (str "sch_" (random-uuid)) "-" "_")
-
- ;; Expand shorthand to insert intermediate table nodes
- expanded-global (dag-abstract/expand-shorthand global)
- expanded-ws-defs (when definitions (dag-abstract/expand-shorthand definitions))
-
- ;; Find all mock tables needed (union of global and workspace)
- global-tables (set (filter mock-table? (concat (keys expanded-global)
- (mapcat val expanded-global))))
- ws-tables (when expanded-ws-defs
- (set (filter mock-table? (concat (keys expanded-ws-defs)
- (mapcat val expanded-ws-defs)))))
- all-tables (set/union global-tables (or ws-tables #{}))
-
- ;; Create all mock tables upfront
- table-ids (create-tables! db-id all-tables schema)
-
- ;; Collect and resolve all real table references
- real-table-ids (into {}
- (for [ref (distinct
- (filter real-table?
- (concat (mapcat val expanded-global)
- (mapcat val (or expanded-ws-defs {})))))]
- [ref (real-table-id db-id ref)]))
-
- ;; Create global transforms
- global-tx-syms (filter transform? (keys expanded-global))
- global-tx-ids (into {}
- (for [tx global-tx-syms]
- [tx (create-transform! db-id tx
- (get expanded-global tx [])
- (merge table-ids real-table-ids) schema)]))
-
- ;; Insert global dependencies
- _ (doseq [[tx-kw tx-id] global-tx-ids]
- (let [output-table-sym (keyword (str "t" (kw->id tx-kw)))]
- (when-let [table-id (table-ids output-table-sym)]
- (app-db/update-or-insert! :model/Dependency
- {:to_entity_type "transform"
- :to_entity_id tx-id
- :from_entity_type "table"
- :from_entity_id table-id}))))
-
- global-map (merge table-ids global-tx-ids real-table-ids)
-
- ;; Create workspace (only if workspace key was provided)
- ws (when workspace
- (create-workspace-for-test! {:name (or (:name workspace)
- (str "test-ws-" (random-uuid)))
- :database_id db-id}))
- ws-id (:id ws)
-
- ;; Determine which workspace transforms to create
- ws-tx-syms (distinct (concat
- ;; Checkouts not overridden in definitions
- (filter #(not (contains? (set (keys definitions)) %)) checkouts)
- ;; All transforms from definitions
- (when expanded-ws-defs
- (filter transform? (keys expanded-ws-defs)))))
-
- ;; Create workspace transforms
- workspace-map (into {}
- (for [tx ws-tx-syms]
- (let [is-checkout? (contains? checkouts tx)
- in-defs? (contains? (set (keys definitions)) tx)
- global-tx (when is-checkout?
- (t2/select-one :model/Transform (global-map tx)))
- deps (when (or (not is-checkout?) in-defs?)
- (get expanded-ws-defs tx []))]
- [tx (add-transform-to-workspace! db-id ws-id tx
- {:global-tx global-tx
- :deps deps
- :id-map global-map
- :schema schema})])))
-
- ;; Apply per-transform properties (e.g., staleness flags)
- _ (when-let [props (:properties workspace)]
- (doseq [[tx-sym updates] props]
- (when-let [ref-id (workspace-map tx-sym)]
- (t2/update! :model/WorkspaceTransform {:workspace_id ws-id :ref_id ref-id} updates))))
- ;; Wait for workspace DB initialization and grant all inputs by default.
- ;; Test tables are metadata-only (no physical DB tables), so the isolation layer's GRANT
- ;; fails silently and `access_granted` stays false — we force-grant to avoid that.
- _ (deps.test/synchronously-run-backfill!)
- _ (when (and ws-id (not (:skip-init workspace)))
- (ws-done! ws-id)
- (force-grant-all-inputs! ws-id))]
- {:workspace-id ws-id
- :global-map global-map
- :workspace-map workspace-map}))
-
-(defmacro with-resources!
- "Create test resources and bind the result map. Cleanup is handled by ws-fixtures!.
-
- Usage: (with-resources! [res {:workspace {:definitions {:x2 [:x1]}
- :properties {:x1 {:definition_changed true}}}}]
- (:workspace-id res))"
- [[binding resource-spec] & body]
- `(let [~binding (create-resources! ~resource-spec)]
- ~@body))
-
-(defn- append-url-part [url part]
- (case [(str/starts-with? part "/")
- (str/ends-with? url "/")]
- [false false] (str url \/ part)
- ([true false]
- [false true]) (str url part)
- (str url (subs part 1))))
-
-(defn ws-url
- "Build an API URL for a workspace resource, e.g. (ws-url 42 \"/transform/\" ref-id)."
- [id & path]
- (when (some nil? (cons id path))
- (throw (ex-info "Cannot build workspace URL without key resources"
- {:id id, :path path})))
- (reduce append-url-part (str "ee/workspace/" id) (map str path)))
-
-(defn staleness-flags
- "Return a map of ref-id to staleness flags for all transforms in a workspace.
- E.g. {\"ref-1\" {:definition_changed false :input_data_changed true}}"
- [workspace-id]
- (t2/select-fn->fn :ref_id #(select-keys % [:definition_changed :input_data_changed])
- [:model/WorkspaceTransform :ref_id :definition_changed :input_data_changed]
- :workspace_id workspace-id))
-
-(defmacro with-mocked-execution
- "Execute body with ws.execute/run-transform-with-remapping stubbed to return success.
- Useful for testing workspace execution logic without running real transforms."
- [& body]
- `(mt/with-dynamic-fn-redefs [ws.execute/run-transform-with-remapping
- (fn [transform# _remapping#]
- {:status :succeeded
- :end_time (Instant/now)
- :message "Mocked execution"
- :table (select-keys (:target transform#) [:schema :name])})]
- ~@body))
-
-(defn mock-run-transform!
- "Mock-execute a workspace transform by ref-id.
- Stubs the execution engine to return success, then calls ws.impl/run-transform!."
- [workspace-id ref-id]
- (with-mocked-execution
- (let [workspace (t2/select-one :model/Workspace workspace-id)
- graph (ws.impl/get-or-calculate-graph! workspace)
- ws-transform (t2/select-one :model/WorkspaceTransform :workspace_id workspace-id :ref_id ref-id)]
- (mt/with-current-user (mt/user->id :crowberto)
- (ws.impl/run-transform! workspace graph ws-transform)))))
-
-(defn ws-fixtures!
- "Sets up test fixtures for workspace tests. Must be called at the top level of test namespaces."
- []
- (use-fixtures :each (fn [tests]
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (mt/with-premium-features [:workspaces :dependencies :transforms-basic :transforms-python]
- (search.tu/with-index-disabled
- (mt/with-model-cleanup [:model/Collection
- :model/Transform
- :model/TransformRun
- :model/Workspace
- :model/WorkspaceTransform
- :model/WorkspaceInput
- :model/WorkspaceInputTransform
- :model/WorkspaceOutput]
- (tests))))))))
-
-(derive :model/Workspace :model/WorkspaceCleanUpInTest)
-
-(t2/define-before-delete :model/WorkspaceCleanUpInTest
- [workspace]
- (try
- (if (:database_details workspace)
- (let [database (t2/select-one :model/Database (:database_id workspace))]
- (log/infof "Cleaning up workspace %d in tests" (:id workspace))
- (ws.isolation/destroy-workspace-isolation! database workspace))
- (log/infof "Skip cleaning up workspace %d due to no database details" (:id workspace)))
- (catch Exception e
- (log/warn e "Failed to destroy isolation" {:workspace workspace})))
- workspace)
-
-(defn create-empty-ws!
- "Create a simple workspace with no transforms. Skips auto-init since there is nothing to analyze."
- [name]
- (t2/select-one :model/Workspace (:workspace-id (create-resources! {:workspace {:name name :skip-init true}}))))
-
-(defn initialize-ws!
- "Create a workspace with a transform to trigger initialization, and wait for it to finish.
- Returns the workspace regardless of its final status (ready, broken, etc.)."
- [name]
- (let [graph {:workspace {:name name, :definitions {:x2 [:t1]}}}
- ws-id (:workspace-id (create-resources! graph))]
- (ws-done! ws-id)))
-
-(defn create-ready-ws!
- "Create a simple workspace and wait for it to finish initializing database resources.
- Throws if workspace does not become ready."
- [name]
- (ws-ready! (initialize-ws! name)))
-
-(defn do-with-workspaces!
- "Function that sets up workspaces for testing and cleans up afterwards.
- Takes a sequence of props for workspace creation and a thunk that receives
- the created workspaces as a vector. Each workspace is cleaned up by its own
- stack frame, so cleanup naturally happens in reverse creation order."
- [props-list thunk]
- (if (empty? props-list)
- (thunk [])
- (let [ws (create-workspace-for-test! (first props-list))]
- (try
- (do-with-workspaces! (rest props-list)
- (fn [rest-workspaces]
- (thunk (into [ws] rest-workspaces))))
- (finally
- (when ws
- (try
- (ws.model/delete! (t2/select-one :model/Workspace :id (:id ws)))
- (catch Exception _
- ;; Workspace may already be deleted by the test
- nil))))))))
-
-(defmacro with-workspaces!
- "Execute body with properly initialized workspaces that are cleaned up afterward.
-
- Creates each workspace using `ws.common/create-workspace!` and waits for it to
- be ready. After body execution (or on error), cleans up using `ws.model/delete!`
- which properly destroys database isolation resources.
-
- Usage:
- (with-workspaces [ws1 {:name \"Test WS 1\"}
- ws2 {:name \"Test WS 2\" :database_id (mt/id)}]
- (testing \"workspace operations\"
- (is (= :ready (:status ws1)))))"
- [bindings & body]
- (assert (vector? bindings) "bindings must be a vector")
- (assert (even? (count bindings)) "bindings must have an even number of forms")
- (let [pairs (partition 2 bindings)
- syms (mapv first pairs)
- props-list (mapv second pairs)]
- `(do-with-workspaces!
- [~@props-list]
- (fn [[~@syms]]
- ~@body))))
-
-(defn- replace-entity [{:keys [input-table workspace-transform external-transform]} entity-type entity-id]
- (get
- (case entity-type
- "input-table" input-table
- "workspace-transform" workspace-transform
- "external-transform" external-transform)
- entity-id entity-id))
-
-(defn- table-ref? [sym]
- (or (mock-table? sym)
- (real-table? sym)))
-
-(defn translate-graph
- "Turn a real workspace graph back into :x1 etc symbols"
- [{:keys [nodes edges]} resources-map]
- (let [mapping (merge (reduce
- (fn [acc [sym id]]
- (assoc-in acc
- [(cond
- (table-ref? sym) :input-table
- (transform? sym) :external-transform
- :else (throw (ex-info "Unexpected symbol" {:symbol sym :id id})))
- (if (table-ref? sym)
- (let [{:keys [db_id schema name]} (t2/select-one [:model/Table :db_id :schema :name] id)]
- (str db_id "-" schema "-" name))
- id)]
- sym))
- {:input-table {}
- :external-transform {}}
- (:global-map resources-map))
- (reduce
- (fn [acc [sym id]]
- (assoc-in acc
- [(cond
- (transform? sym) :workspace-transform
- :else (throw (ex-info "Unexpected symbol" {:symbol sym :id id})))
- id]
- sym))
- {:workspace-transform {}}
- (:workspace-map resources-map)))]
- {:nodes (into #{} (map #(replace-entity mapping (:type %) (:id %))) nodes)
- :edges (reduce
- (fn [acc e]
- (update acc
- (replace-entity mapping (:from_entity_type e) (:from_entity_id e))
- (fnil conj #{})
- (replace-entity mapping (:to_entity_type e) (:to_entity_id e))))
- {}
- edges)}))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/util_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/util_test.clj
deleted file mode 100644
index aeda5eacb3b..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/util_test.clj
+++ /dev/null
@@ -1,48 +0,0 @@
-(ns metabase-enterprise.workspaces.util-test
- (:require
- [clojure.test :refer :all]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase-enterprise.workspaces.util :as ws.u]
- [toucan2.core :as t2]))
-
-(set! *warn-on-reflection* true)
-
-(ws.tu/ws-fixtures!)
-
-(deftest ignore-constraint-violation-test
- (testing "ignore-constraint-violation catches duplicate key violations"
- (let [ws (ws.tu/create-empty-ws! "Test Workspace")]
- (testing "first insert succeeds and returns the inserted row"
- (let [result (ws.u/ignore-constraint-violation
- (t2/insert-returning-instance! :model/WorkspaceGraph
- {:workspace_id (:id ws)
- :graph_version 1
- :graph {:marker "first"}}))]
- (is (= 1 (:graph_version result)))))
-
- (testing "duplicate insert is silently ignored (returns nil)"
- (let [result (ws.u/ignore-constraint-violation
- (t2/insert-returning-instance! :model/WorkspaceGraph
- {:workspace_id (:id ws)
- :graph_version 1
- :graph {:marker "second"}}))]
- (is (nil? result))))
-
- (testing "only one row exists in the database"
- (is (= #{"first"} (t2/select-fn-set (comp :marker :graph) [:model/WorkspaceGraph :graph] :workspace_id (:id ws)))))
-
- (testing "we can insert a non-conflicting row"
- (let [result (ws.u/ignore-constraint-violation
- (t2/insert-returning-instance! :model/WorkspaceGraph
- {:workspace_id (:id ws)
- :graph_version 2
- :graph {:marker "third"}}))]
- (is (some? result))
- (is (= #{"first" "third"} (t2/select-fn-set (comp :marker :graph) [:model/WorkspaceGraph :graph] :workspace_id (:id ws)))))))))
-
-(deftest ignore-constraint-violation-rethrows-other-exceptions-test
- (testing "ignore-constraint-violation rethrows non-constraint exceptions"
- (is (thrown-with-msg? Exception
- #"Test exception"
- (ws.u/ignore-constraint-violation
- (throw (Exception. "Test exception")))))))
diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/validation_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/validation_test.clj
deleted file mode 100644
index 25e77784aab..00000000000
--- a/enterprise/backend/test/metabase_enterprise/workspaces/validation_test.clj
+++ /dev/null
@@ -1,176 +0,0 @@
-(ns ^:mb/driver-tests metabase-enterprise.workspaces.validation-test
- (:require
- [clojure.test :refer :all]
- [metabase-enterprise.dependencies.test-util :as deps.test]
- [metabase-enterprise.workspaces.impl :as ws.impl]
- [metabase-enterprise.workspaces.test-util :as ws.tu]
- [metabase-enterprise.workspaces.validation :as ws.validation]
- [metabase.test :as mt]
- [toucan2.core :as t2]))
-
-(set! *warn-on-reflection* true)
-
-(ws.tu/ws-fixtures!)
-
-(defn- build-graph!
- "Build the workspace graph for validation tests."
- [ws-id]
- (ws.impl/get-or-calculate-graph! (t2/select-one :model/Workspace ws-id)))
-
-;;; ---------------------------------------- Basic API Tests ----------------------------------------
-
-(deftest find-downstream-problems-empty-workspace-test
- (testing "find-downstream-problems returns empty for workspace with no transforms"
- (ws.tu/with-workspaces! [workspace {:name "Empty Workspace"}]
- (is (= [] (ws.validation/find-downstream-problems (:id workspace) nil))))))
-
-(deftest problems-endpoint-returns-empty-for-new-workspace-test
- (testing "GET /api/ee/workspace/:id/problems returns empty list for workspace with no transforms"
- (ws.tu/with-workspaces! [workspace {:name "Test Workspace"}]
- (let [response (mt/user-http-request :crowberto :get 200
- (str "ee/workspace/" (:id workspace) "/problem"))]
- (is (= [] response))))))
-
-(deftest problems-endpoint-requires-superuser-test
- (testing "GET /api/ee/workspace/:id/problems requires superuser"
- (ws.tu/with-workspaces! [workspace {:name "Private Workspace"}]
- (is (= "You don't have permissions to do that."
- (mt/user-http-request :rasta :get 403
- (str "ee/workspace/" (:id workspace) "/problem")))))))
-
-(deftest problems-endpoint-404-for-nonexistent-workspace-test
- (testing "GET /api/ee/workspace/:id/problems returns 404 for non-existent workspace"
- (is (= "Not found."
- (mt/user-http-request :crowberto :get 404 "ee/workspace/999999/problem")))))
-
-;;; ---------------------------------------- Problem Detection Tests ----------------------------------------
-
-(deftest unused-output-not-yet-created-test
- (testing "detects when a workspace output table hasn't been created yet (no external dependents)"
- (ws.tu/with-workspaces! [workspace {:name "Test Workspace"}]
- (let [ws-id (:id workspace)
- ;; Create a workspace transform
- {ref-id :ref_id} (mt/user-http-request :crowberto :post 200
- (str "ee/workspace/" ws-id "/transform")
- {:name "Test Transform"
- :source {:type "query"
- :query (mt/native-query {:query "SELECT 1 as col"})}
- :target {:type "table"
- :schema "public"
- :name "test_output_table"}})
- ;; The transform hasn't been run, so isolated_table_id is nil
- ;; No external transforms depend on it
- graph (build-graph! ws-id)
- problems (ws.validation/find-downstream-problems ws-id graph)]
- (is (= [{:category :unused
- :problem :not-run
- :severity :info
- :block_merge false
- :description "Output hasn't been created yet, but nothing depends on it"
- :data {:output {:db_id (mt/id), :schema "public", :table "test_output_table"}
- :transform {:type :workspace-transform, :id ref-id}}}]
- problems))))))
-
-(deftest dependent-transform-output-not-yet-created-test
- (testing "detects when output table hasn't been created but external transforms depend on it"
- (ws.tu/with-workspaces! [workspace {:name "Test Workspace"}]
- (let [ws-id (:id workspace)]
- ;; First, create the global output table that we'll have a dependency on
- (mt/with-temp [:model/Table output-table {:db_id (mt/id)
- :schema "public"
- :name "global_output_table"
- :active true}]
- ;; Create an external transform that depends on this table
- ;; Note: The dependency will be created automatically by the Transform model hooks
- (mt/with-temp [:model/Transform external-tx {:name "External Transform"
- :source {:type :query
- :query {:database (mt/id)
- :type :query
- :query {:source-table (:id output-table)}}}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "external_output"}}]
- (deps.test/synchronously-run-backfill!)
- ;; Create a workspace transform that targets the same table
- (let [{ref-id :ref_id} (mt/user-http-request :crowberto :post 200
- (str "ee/workspace/" ws-id "/transform")
- {:name "Workspace Transform"
- :source {:type "query"
- :query (mt/native-query {:query "SELECT 1 as col"})}
- :target {:type "table"
- :schema "public"
- :name "global_output_table"}})]
- ;; Manually update the WorkspaceOutput to point to the global table
- ;; (simulating a checked-out transform scenario)
- (t2/update! :model/WorkspaceOutput
- {:workspace_id ws-id :ref_id ref-id}
- {:global_table_id (:id output-table)})
-
- (is (= [{:category :external-downstream
- :problem :not-run
- :severity :warning
- :block_merge true
- :description "Output hasn't been created yet, external transforms depend on it"
- :data {:output {:db_id (mt/id), :schema "public", :table "global_output_table"}
- :transform {:type :workspace-transform, :id ref-id}
- :dependents [{:type :external-transform
- :id (:id external-tx)
- :name "External Transform"}]}}]
- (ws.validation/find-downstream-problems ws-id (build-graph! ws-id)))))))))))
-
-(deftest no-problems-when-output-exists-and-no-field-changes-test
- (testing "no problems when isolated table exists and has all required fields"
- (ws.tu/with-workspaces! [workspace {:name "Test Workspace"}]
- (let [ws-id (:id workspace)]
- ;; Create both global and isolated tables with matching fields
- (mt/with-temp [:model/Table global-table {:db_id (mt/id)
- :schema "public"
- :name "output_table"
- :active true}
- :model/Field _ {:table_id (:id global-table)
- :name "col1"
- :database_type "TEXT"
- :base_type :type/Text
- :active true}
- :model/Table isolated-table {:db_id (mt/id)
- :schema "mb__isolation_test"
- :name "public__output_table"
- :active true}
- :model/Field _ {:table_id (:id isolated-table)
- :name "col1"
- :database_type "TEXT"
- :base_type :type/Text
- :active true}]
- ;; External transform that uses col1 via MBQL source-table
- (mt/with-temp [:model/Transform _external-tx {:name "External Transform"
- :source {:type :query
- :query {:database (mt/id)
- :type :query
- :query {:source-table (:id global-table)}}}
- :target {:type "table"
- :database (mt/id)
- :schema "public"
- :name "external_output"}}]
- ;; Create workspace transform and output
- (let [{ref-id :ref_id} (mt/user-http-request :crowberto :post 200
- (str "ee/workspace/" ws-id "/transform")
- {:name "Workspace Transform"
- :source {:type "query"
- :query {:database (mt/id)
- :type :native
- :native {:query "SELECT 'test' as col1"}}}
- :target {:type "table"
- :schema "public"
- :name "output_table"}})]
- ;; First trigger graph calculation to create the WorkspaceOutput row
- (build-graph! ws-id)
-
- ;; Now the row exists, so we can update it with our test table IDs
- (t2/update! :model/WorkspaceOutput
- {:workspace_id ws-id :ref_id ref-id}
- {:global_table_id (:id global-table)
- :isolated_table_id (:id isolated-table)})
-
- ;; Should have no problems since isolated table has all required fields
- (is (empty? (ws.validation/find-downstream-problems ws-id (build-graph! ws-id)))))))))))
diff --git a/enterprise/frontend/src/metabase-enterprise/api/index.ts b/enterprise/frontend/src/metabase-enterprise/api/index.ts
index 39aa34c4452..6bdaae5ed4e 100644
--- a/enterprise/frontend/src/metabase-enterprise/api/index.ts
+++ b/enterprise/frontend/src/metabase-enterprise/api/index.ts
@@ -19,4 +19,3 @@ export * from "./table";
export * from "./tags";
export * from "./tenants";
export * from "./upload-management";
-export * from "./workspace";
diff --git a/enterprise/frontend/src/metabase-enterprise/api/tags.ts b/enterprise/frontend/src/metabase-enterprise/api/tags.ts
index 3edb67456d1..60f9da0f069 100644
--- a/enterprise/frontend/src/metabase-enterprise/api/tags.ts
+++ b/enterprise/frontend/src/metabase-enterprise/api/tags.ts
@@ -16,7 +16,6 @@ import {
type DependencyGraph,
type DependencyNode,
type DocumentDependencyNode,
- type ExternalTransform,
type MeasureDependencyNode,
type PythonLibrary,
type SandboxDependencyNode,
@@ -26,9 +25,6 @@ import {
type SupportAccessGrant,
type TableDependencyNode,
type TransformDependencyNode,
- type Workspace,
- type WorkspaceAllowedDatabase,
- type WorkspaceItem,
} from "metabase-types/api";
export const ENTERPRISE_TAG_TYPES = [
@@ -36,9 +32,6 @@ export const ENTERPRISE_TAG_TYPES = [
"scim",
"gsheets-status",
"sandbox",
- "workspace-transforms",
- "workspace-transform",
- "workspace-tables",
"git-tree",
"git-file-content",
"collection-dirty-entities",
@@ -48,7 +41,6 @@ export const ENTERPRISE_TAG_TYPES = [
"remote-sync-has-remote-changes",
"source-replacement-run",
"python-transform-library",
- "workspace",
"support-access-grant",
"support-access-grant-current",
"library-collection",
@@ -86,33 +78,6 @@ export function invalidateTags(
return !error ? tags : [];
}
-export function provideWorkspacesTags(
- workspaces: Workspace[],
-): TagDescription<EnterpriseTagType>[] {
- return [listTag("workspace"), ...workspaces.flatMap(provideWorkspaceTags)];
-}
-
-export function provideWorkspaceTags(
- workspace: Workspace | WorkspaceItem,
-): TagDescription<EnterpriseTagType>[] {
- return [idTag("workspace", workspace.id)];
-}
-
-export function provideExternalTransformTags(
- transform: ExternalTransform,
-): TagDescription<EnterpriseTagType>[] {
- return [idTag("external-transform", transform.id)];
-}
-
-export function provideExternalTransformListTags(
- transforms: ExternalTransform[],
-): TagDescription<EnterpriseTagType>[] {
- return [
- listTag("external-transform"),
- ...transforms.flatMap(provideExternalTransformTags),
- ];
-}
-
export function providePythonLibraryTags(
library: PythonLibrary,
): TagDescription<EnterpriseTagType>[] {
@@ -240,8 +205,6 @@ export function provideDependencyNodeTags(
return provideSegmentDependencyNodeTags(node);
case "measure":
return provideMeasureDependencyNodeTags(node);
- case "workspace-transform":
- return [idTag("workspace-transform", node.id)];
}
}
@@ -273,15 +236,6 @@ export function provideSupportAccessGrantListTags(
];
}
-export function provideWorkspaceAllowedDatabaseTags(
- databases: WorkspaceAllowedDatabase[],
-) {
- return [
- listTag("database"),
- ...databases.map((db) => idTag("database", db.id)),
- ];
-}
-
export function provideSourceReplacementRunTags(
run: SourceReplacementRun,
): TagDescription<EnterpriseTagType>[] {
diff --git a/enterprise/frontend/src/metabase-enterprise/api/workspace.ts b/enterprise/frontend/src/metabase-enterprise/api/workspace.ts
deleted file mode 100644
index 571263c1544..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/api/workspace.ts
+++ /dev/null
@@ -1,425 +0,0 @@
-import type {
- CreateWorkspaceRequest,
- CreateWorkspaceTransformRequest,
- CreateWorkspaceTransformResponse,
- ExternalTransformRequest,
- ExternalTransformResponse,
- TransformId,
- UpdateWorkspaceTransformRequest,
- ValidateTableNameRequest,
- ValidateTableNameResponse,
- Workspace,
- WorkspaceAllowedDatabasesResponse,
- WorkspaceCheckoutResponse,
- WorkspaceGraphResponse,
- WorkspaceId,
- WorkspaceListResponse,
- WorkspaceLogResponse,
- WorkspaceMergeResponse,
- WorkspaceProblem,
- WorkspaceRunRequest,
- WorkspaceRunResponse,
- WorkspaceTablesResponse,
- WorkspaceTransform,
- WorkspaceTransformDryRunResponse,
- WorkspaceTransformListItem,
- WorkspaceTransformListResponse,
- WorkspaceTransformMergeResponse,
- WorkspaceTransformRef,
- WorkspaceTransformRunResponse,
-} from "metabase-types/api";
-
-import { EnterpriseApi } from "./api";
-import {
- idTag,
- invalidateTags,
- listTag,
- provideWorkspaceAllowedDatabaseTags,
- provideWorkspaceTags,
- provideWorkspacesTags,
- tag,
-} from "./tags";
-
-export const workspaceApi = EnterpriseApi.injectEndpoints({
- endpoints: (builder) => ({
- getWorkspaces: builder.query<WorkspaceListResponse, void>({
- query: () => ({
- method: "GET",
- url: "/api/ee/workspace",
- }),
- providesTags: (response) =>
- response ? provideWorkspacesTags(response.items) : [],
- }),
- getWorkspace: builder.query<Workspace, WorkspaceId>({
- query: (id) => ({
- method: "GET",
- url: `/api/ee/workspace/${id}`,
- }),
- providesTags: (workspace) =>
- workspace ? provideWorkspaceTags(workspace) : [],
- }),
- createWorkspace: builder.mutation<Workspace, CreateWorkspaceRequest | void>(
- {
- query: (body) => ({
- method: "POST",
- url: "/api/ee/workspace",
- body,
- }),
- invalidatesTags: (_, error) =>
- invalidateTags(error, [listTag("workspace"), listTag("transform")]),
- },
- ),
- updateWorkspace: builder.mutation<
- Workspace,
- { id: WorkspaceId; name?: string; database_id?: number }
- >({
- query: ({ id, ...body }) => ({
- method: "PUT",
- url: `/api/ee/workspace/${id}`,
- body,
- }),
- invalidatesTags: (_, error, { id }) =>
- invalidateTags(error, [idTag("workspace", id)]),
- }),
- createWorkspaceTransform: builder.mutation<
- WorkspaceTransform,
- CreateWorkspaceTransformRequest
- >({
- query: ({ id, ...body }) => ({
- method: "POST",
- url: `/api/ee/workspace/${id}/transform`,
- body,
- }),
- transformResponse: (
- response: CreateWorkspaceTransformResponse,
- ): WorkspaceTransform => ({
- ...response,
- type: "workspace-transform",
- }),
- invalidatesTags: (_, error, { id, global_id }) =>
- invalidateTags(error, [
- idTag("workspace", id),
- idTag("workspace-transforms", id),
- idTag("external-transform", id),
- idTag("workspace-tables", id),
- listTag("transform"),
- ...(global_id != null ? [idTag("transform", global_id)] : []),
- ]),
- }),
- getWorkspaceCheckout: builder.query<WorkspaceCheckoutResponse, TransformId>(
- {
- query: (transformId) => ({
- method: "GET",
- url: `/api/ee/workspace/checkout`,
- params: { "transform-id": transformId },
- }),
- providesTags: (_, __, transformId) => [idTag("transform", transformId)],
- },
- ),
- mergeWorkspace: builder.mutation<
- WorkspaceMergeResponse,
- { id: WorkspaceId; commit_message: string }
- >({
- query: ({ id, commit_message }) => ({
- method: "POST",
- url: `/api/ee/workspace/${id}/merge`,
- body: { commit_message },
- }),
- invalidatesTags: (_, error) =>
- invalidateTags(error, [tag("workspace"), tag("transform")]),
- }),
- mergeWorkspaceTransform: builder.mutation<
- WorkspaceTransformMergeResponse,
- WorkspaceTransformRef
- >({
- query: ({ workspaceId, transformId }) => ({
- method: "POST",
- url: `/api/ee/workspace/${workspaceId}/transform/${transformId}/merge`,
- }),
- invalidatesTags: (_, error) =>
- invalidateTags(error, [tag("workspace"), tag("transform")]),
- }),
- archiveWorkspace: builder.mutation<Workspace, WorkspaceId>({
- query: (id) => ({
- method: "POST",
- url: `/api/ee/workspace/${id}/archive`,
- }),
- invalidatesTags: (_, error) =>
- invalidateTags(error, [tag("workspace"), tag("transform")]),
- }),
- unarchiveWorkspace: builder.mutation<Workspace, WorkspaceId>({
- query: (id) => ({
- method: "POST",
- url: `/api/ee/workspace/${id}/unarchive`,
- }),
- invalidatesTags: (_, error) =>
- invalidateTags(error, [tag("workspace"), tag("transform")]),
- }),
- deleteWorkspace: builder.mutation<void, WorkspaceId>({
- query: (id) => ({
- method: "DELETE",
- url: `/api/ee/workspace/${id}`,
- }),
- async onQueryStarted(id, { dispatch, queryFulfilled }) {
- const patchResult = dispatch(
- workspaceApi.util.updateQueryData(
- "getWorkspaces",
- undefined,
- (draft) => {
- const idx = draft.items.findIndex((w) => w.id === id);
- if (idx !== -1) {
- draft.items.splice(idx, 1);
- }
- },
- ),
- );
-
- try {
- await queryFulfilled;
- } catch {
- patchResult.undo();
- }
- },
- invalidatesTags: (_, error) =>
- invalidateTags(error, [tag("workspace"), tag("transform")]),
- }),
- validateTableName: builder.mutation<
- ValidateTableNameResponse,
- ValidateTableNameRequest
- >({
- query: ({ id, ...body }) => ({
- method: "POST",
- url: `/api/ee/workspace/${id}/transform/validate/target`,
- body,
- }),
- }),
- getWorkspaceTables: builder.query<WorkspaceTablesResponse, WorkspaceId>({
- query: (id) => ({
- method: "GET",
- url: `/api/ee/workspace/${id}/table`,
- }),
- providesTags: (_, __, id) => [idTag("workspace-tables", id)],
- }),
- getWorkspaceGraph: builder.query<WorkspaceGraphResponse, WorkspaceId>({
- query: (id) => ({
- method: "GET",
- url: `/api/ee/workspace/${id}/graph`,
- }),
- providesTags: (_, __, id) => [idTag("workspace", id)],
- }),
- getWorkspaceProblems: builder.query<WorkspaceProblem[], WorkspaceId>({
- query: (id) => ({
- method: "GET",
- url: `/api/ee/workspace/${id}/problem`,
- }),
- providesTags: (_, __, id) => [idTag("workspace", id)],
- }),
- getWorkspaceTransforms: builder.query<
- WorkspaceTransformListItem[],
- WorkspaceId
- >({
- query: (id) => ({
- method: "GET",
- url: `/api/ee/workspace/${id}/transform`,
- }),
- providesTags: (_, __, id) => [idTag("workspace-transforms", id)],
- transformResponse: (response: WorkspaceTransformListResponse) =>
- response.transforms,
- }),
- getExternalTransforms: builder.query<
- ExternalTransformResponse["transforms"],
- ExternalTransformRequest
- >({
- query: ({ workspaceId, databaseId }) => ({
- method: "GET",
- url: `/api/ee/workspace/${workspaceId}/external/transform`,
- params: { database_id: databaseId },
- }),
- providesTags: (_, __, { workspaceId: id }) => [
- listTag("external-transform"),
- idTag("external-transform", id),
- ],
- transformResponse: (response: ExternalTransformResponse) =>
- response.transforms,
- }),
- getWorkspaceTransform: builder.query<
- WorkspaceTransform,
- { workspaceId: WorkspaceId; transformId: string }
- >({
- query: ({ workspaceId, transformId }) => ({
- method: "GET",
- url: `/api/ee/workspace/${workspaceId}/transform/${transformId}`,
- }),
- transformResponse: (
- response: Omit<WorkspaceTransform, "type">,
- ): WorkspaceTransform => ({
- ...response,
- type: "workspace-transform",
- }),
- providesTags: (_, __, { transformId }) => [
- idTag("workspace-transform", transformId),
- ],
- }),
- getWorkspaceLog: builder.query<WorkspaceLogResponse, WorkspaceId>({
- query: (id) => ({
- method: "GET",
- url: `/api/ee/workspace/${id}/log`,
- }),
- providesTags: (_, _error, id) => [idTag("workspace", id)],
- }),
- runWorkspace: builder.mutation<WorkspaceRunResponse, WorkspaceRunRequest>({
- query: ({ id, stale_only }) => ({
- method: "POST",
- url: `/api/ee/workspace/${id}/run`,
- params: stale_only ? { stale_only: 1 } : undefined,
- }),
- invalidatesTags: (_, error, { id }) =>
- invalidateTags(error, [
- idTag("workspace", id),
- idTag("workspace-transforms", id),
- idTag("workspace-tables", id),
- tag("workspace-transform"),
- tag("transform"),
- ]),
- }),
- runWorkspaceTransform: builder.mutation<
- WorkspaceTransformRunResponse,
- WorkspaceTransformRef
- >({
- query: ({ workspaceId, transformId }) => ({
- method: "POST",
- url: `/api/ee/workspace/${workspaceId}/transform/${transformId}/run`,
- }),
- invalidatesTags: (_, error, { workspaceId, transformId }) =>
- invalidateTags(error, [
- idTag("workspace", workspaceId),
- idTag("workspace-transforms", workspaceId),
- idTag("workspace-transform", transformId),
- idTag("workspace-tables", workspaceId),
- ]),
- }),
- dryRunWorkspaceTransform: builder.mutation<
- WorkspaceTransformDryRunResponse,
- WorkspaceTransformRef
- >({
- query: ({ workspaceId, transformId }) => ({
- method: "POST",
- url: `/api/ee/workspace/${workspaceId}/transform/${transformId}/dry-run`,
- }),
- }),
- updateWorkspaceTransform: builder.mutation<
- WorkspaceTransform,
- UpdateWorkspaceTransformRequest
- >({
- query: ({ workspaceId, transformId, ...body }) => ({
- method: "PUT",
- url: `/api/ee/workspace/${workspaceId}/transform/${transformId}`,
- body,
- }),
- transformResponse: (
- response: Omit<WorkspaceTransform, "type">,
- ): WorkspaceTransform => ({
- ...response,
- type: "workspace-transform",
- }),
- invalidatesTags: (_, error, { workspaceId, transformId }) =>
- invalidateTags(error, [
- idTag("workspace", workspaceId),
- idTag("workspace-transforms", workspaceId),
- idTag("workspace-transform", transformId),
- idTag("workspace-tables", workspaceId),
- ]),
- }),
- archiveWorkspaceTransform: builder.mutation<void, WorkspaceTransformRef>({
- query: ({ workspaceId, transformId }) => ({
- method: "POST",
- url: `/api/ee/workspace/${workspaceId}/transform/${transformId}/archive`,
- }),
- invalidatesTags: (_, error, { workspaceId, transformId }) =>
- invalidateTags(error, [
- idTag("workspace", workspaceId),
- idTag("workspace-transforms", workspaceId),
- idTag("workspace-transform", transformId),
- idTag("workspace-tables", workspaceId),
- tag("transform"),
- ]),
- }),
- unarchiveWorkspaceTransform: builder.mutation<void, WorkspaceTransformRef>({
- query: ({ workspaceId, transformId }) => ({
- method: "POST",
- url: `/api/ee/workspace/${workspaceId}/transform/${transformId}/unarchive`,
- }),
- invalidatesTags: (_, error, { workspaceId, transformId }) =>
- invalidateTags(error, [
- idTag("workspace", workspaceId),
- idTag("workspace-transforms", workspaceId),
- idTag("workspace-transform", transformId),
- idTag("workspace-tables", workspaceId),
- tag("transform"),
- ]),
- }),
- deleteWorkspaceTransform: builder.mutation<void, WorkspaceTransformRef>({
- query: ({ workspaceId, transformId }) => ({
- method: "DELETE",
- url: `/api/ee/workspace/${workspaceId}/transform/${transformId}`,
- }),
- invalidatesTags: (_, error, { workspaceId, transformId }) =>
- invalidateTags(error, [
- idTag("workspace", workspaceId),
- idTag("workspace-transforms", workspaceId),
- idTag("external-transform", workspaceId),
- idTag("workspace-transform", transformId),
- idTag("workspace-tables", workspaceId),
- tag("transform"),
- ]),
- }),
- getWorkspaceAllowedDatabases: builder.query<
- WorkspaceAllowedDatabasesResponse,
- void
- >({
- query: () => ({
- method: "GET",
- url: `/api/ee/workspace/database`,
- }),
- providesTags: (response) =>
- provideWorkspaceAllowedDatabaseTags(response?.databases ?? []),
- }),
- }),
-});
-
-export const {
- useGetWorkspacesQuery,
- useGetWorkspaceQuery,
- useGetWorkspaceTransformsQuery,
- useGetExternalTransformsQuery,
- useGetWorkspaceTransformQuery,
- useCreateWorkspaceMutation,
- useCreateWorkspaceTransformMutation,
- useUpdateWorkspaceTransformMutation,
- useArchiveWorkspaceTransformMutation,
- useUnarchiveWorkspaceTransformMutation,
- useDeleteWorkspaceTransformMutation,
- useGetWorkspaceCheckoutQuery,
- useMergeWorkspaceMutation,
- useMergeWorkspaceTransformMutation,
- useArchiveWorkspaceMutation,
- useUnarchiveWorkspaceMutation,
- useDeleteWorkspaceMutation,
- useValidateTableNameMutation,
- useUpdateWorkspaceMutation,
- useGetWorkspaceTablesQuery,
- useLazyGetWorkspaceTablesQuery,
- useGetWorkspaceGraphQuery,
- useGetWorkspaceProblemsQuery,
- useGetWorkspaceLogQuery,
- useRunWorkspaceMutation,
- useRunWorkspaceTransformMutation,
- useDryRunWorkspaceTransformMutation,
- useGetWorkspaceAllowedDatabasesQuery,
-} = workspaceApi;
-
-export const DEFAULT_WORKSPACE_TABLES_QUERY_RESPONSE: WorkspaceTablesResponse =
- {
- inputs: [],
- outputs: [],
- };
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/admin/AdminDatabaseWorkspacesSection.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/admin/AdminDatabaseWorkspacesSection.tsx
deleted file mode 100644
index b94fc60d968..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/admin/AdminDatabaseWorkspacesSection.tsx
+++ /dev/null
@@ -1,196 +0,0 @@
-import { type ChangeEvent, useState } from "react";
-import { t } from "ttag";
-
-import {
- Description,
- Error,
- Label,
-} from "metabase/admin/databases/components/DatabaseFeatureComponents";
-import { DatabaseInfoSection } from "metabase/admin/databases/components/DatabaseInfoSection";
-import {
- hasDbRoutingEnabled,
- hasFeature,
-} from "metabase/admin/databases/utils";
-import { useCheckWorkspacePermissionsMutation } from "metabase/api";
-import { getErrorMessage } from "metabase/api/utils";
-import { Alert, Group, Icon, List, Loader, Stack, Switch } from "metabase/ui";
-import type {
- Database,
- DatabaseData,
- DatabaseId,
- DatabaseLocalSettingAvailability,
-} from "metabase-types/api";
-
-import { DATABASE_WORKSPACES_SETTING } from "../settings";
-
-export function AdminDatabaseWorkspacesSection({
- database,
- settingsAvailable,
- updateDatabase,
-}: {
- database: Database;
- settingsAvailable?: Record<string, DatabaseLocalSettingAvailability>;
- updateDatabase: (
- database: { id: DatabaseId } & Partial<DatabaseData>,
- ) => Promise<void>;
-}) {
- const isEnabled = Boolean(database.settings?.[DATABASE_WORKSPACES_SETTING]);
- const workspacesSetting = settingsAvailable?.[DATABASE_WORKSPACES_SETTING];
- const isSettingDisabled = !workspacesSetting;
- const areWorkspacesSupported = hasFeature(database, "workspace");
- const databaseHasRouting = hasDbRoutingEnabled(database);
-
- const [error, setError] = useState<string | null>(null);
- const [isCheckingPermissions, setIsCheckingPermissions] = useState(false);
- const [isUpdating, setIsUpdating] = useState(false);
- const [permissionsError, setPermissionsError] = useState<string | null>(null);
-
- const [checkWorkspacePermissions] = useCheckWorkspacePermissionsMutation();
-
- const enableWorkspaces = async () => {
- setIsUpdating(true);
-
- try {
- await updateDatabase({
- id: database.id,
- settings: { [DATABASE_WORKSPACES_SETTING]: true },
- });
- } finally {
- setIsUpdating(false);
- }
- };
-
- const disableWorkspaces = async () => {
- setIsUpdating(true);
-
- try {
- await updateDatabase({
- id: database.id,
- settings: { [DATABASE_WORKSPACES_SETTING]: false },
- });
- } finally {
- setIsUpdating(false);
- }
- };
-
- const tryToEnableWorkspaces = async () => {
- setIsCheckingPermissions(true);
-
- try {
- const result = await checkWorkspacePermissions({
- id: database.id,
- cached: false,
- }).unwrap();
-
- if (result.status === "ok") {
- await enableWorkspaces();
- } else {
- setPermissionsError(
- getErrorMessage(
- result.error,
- t`This database connection does not have sufficient permissions`,
- ),
- );
- }
- } catch (error) {
- setPermissionsError(
- getErrorMessage(
- error,
- t`Failed to check workspace permissions for this database`,
- ),
- );
- } finally {
- setIsCheckingPermissions(false);
- }
- };
-
- const handleToggle = async (event: ChangeEvent<HTMLInputElement>) => {
- try {
- setError(null);
- setPermissionsError(null);
-
- if (event.target.checked) {
- await tryToEnableWorkspaces();
- } else {
- await disableWorkspaces();
- }
- } catch (error) {
- setError(getErrorMessage(error));
- }
- };
-
- if (!areWorkspacesSupported || isSettingDisabled) {
- return null;
- }
-
- return (
- <DatabaseInfoSection
- data-testid="database-workspaces-section"
- description={t`Enable workspaces for this database to create isolated data environments for transforms.`}
- name={t`Workspaces`}
- >
- <Stack gap="md">
- <Group align="center" justify="space-between" wrap="nowrap">
- <Label htmlFor="workspaces-toggle">{t`Enable workspaces`}</Label>
-
- <Group align="center" gap="md" wrap="nowrap">
- {(isCheckingPermissions || isUpdating) && <Loader size="sm" />}
-
- <Switch
- checked={isEnabled}
- disabled={
- isCheckingPermissions || (!isEnabled && databaseHasRouting)
- }
- id="workspaces-toggle"
- onChange={handleToggle}
- />
- </Group>
- </Group>
-
- <Stack maw="22.5rem">
- {!permissionsError && (
- <Description>
- {t`Your database connection will need permissions to create users, schemas, and grant table permissions.`}
- </Description>
- )}
-
- {permissionsError && (
- <Stack c="text-secondary" gap="xs" lh={1.4}>
- {t`To enable workspaces, the database connection user needs permissions to:`}
-
- <List>
- <List.Item
- c="text-secondary"
- lh={1.4}
- >{t`Create users and schemas`}</List.Item>
- <List.Item
- c="text-secondary"
- lh={1.4}
- >{t`Grant table permissions`}</List.Item>
- <List.Item
- c="text-secondary"
- lh={1.4}
- >{t`Manage database resources`}</List.Item>
- </List>
- </Stack>
- )}
-
- {error && <Error>{error}</Error>}
-
- {permissionsError && <Error>{permissionsError}</Error>}
- </Stack>
-
- {databaseHasRouting && (
- <Alert
- variant="light"
- color="info"
- icon={<Icon name="info" />}
- mb="md"
- >
- {t`Workspaces can't be enabled when database routing is enabled.`}
- </Alert>
- )}
- </Stack>
- </DatabaseInfoSection>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/EditTransformMenu/EditTransformMenu.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/EditTransformMenu/EditTransformMenu.tsx
deleted file mode 100644
index 2cbc4f7d070..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/EditTransformMenu/EditTransformMenu.tsx
+++ /dev/null
@@ -1,234 +0,0 @@
-import { useMemo } from "react";
-import { Link } from "react-router";
-import { push } from "react-router-redux";
-import { t } from "ttag";
-
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import type { EditTransformMenuProps } from "metabase/plugins/oss/database";
-import {
- Box,
- Button,
- Flex,
- Icon,
- Loader,
- Menu,
- ScrollArea,
- Stack,
- Text,
- Tooltip,
-} from "metabase/ui";
-import { useDispatch } from "metabase/utils/redux";
-import * as Urls from "metabase/utils/urls";
-import { transformEdit } from "metabase/utils/urls";
-import {
- useCreateWorkspaceMutation,
- useGetWorkspaceCheckoutQuery,
- useGetWorkspacesQuery,
-} from "metabase-enterprise/api";
-import { getCheckoutDisabledMessage } from "metabase-enterprise/data-studio/workspaces/utils";
-import type { DatabaseId, Transform } from "metabase-types/api";
-
-export function EditTransformMenu({ transform }: EditTransformMenuProps) {
- const dispatch = useDispatch();
- const { sendErrorToast } = useMetadataToasts();
-
- const sourceDatabaseId = getTransformDatabaseId(transform);
-
- const { data: workspacesData, isLoading: isLoadingWorkspaces } =
- useGetWorkspacesQuery();
- const [createWorkspace, { isLoading: isCreatingWorkspace }] =
- useCreateWorkspaceMutation();
- const { data: checkoutData, isLoading: isWorkspaceCheckoutLoading } =
- useGetWorkspaceCheckoutQuery(transform.id);
-
- const workspaces = useMemo(
- () =>
- workspacesData?.items.filter((item) => item?.status !== "archived") ?? [],
- [workspacesData],
- );
-
- const matchingWorkspaces = useMemo(() => {
- const allMatchingWorkspaceIds =
- workspaces
- ?.filter((item) => item.database_id === sourceDatabaseId)
- ?.map((item) => item.id) ?? [];
-
- const workspacesMap = new Map(workspaces.map((w) => [w.id, w]));
-
- // Workspaces which already include this transform.
- const checkedWorkspaceIds = new Set(
- checkoutData?.workspaces
- ?.toSorted((a, b) => {
- if (a.existing && !b.existing) {
- return -1;
- }
- if (!a.existing && b.existing) {
- return 1;
- }
- return 0;
- })
- ?.map((item) => item?.id),
- );
-
- return Array.from(
- new Set([...checkedWorkspaceIds, ...allMatchingWorkspaceIds]),
- )
- .map((id) => {
- const workspace = workspacesMap.get(id);
- if (!workspace) {
- return null;
- }
- return {
- id,
- isChecked: checkedWorkspaceIds.has(id),
- name: workspace.name,
- };
- })
- .filter((workspace) => !!workspace);
- }, [checkoutData?.workspaces, workspaces, sourceDatabaseId]);
-
- const isBusy =
- isCreatingWorkspace || isLoadingWorkspaces || isWorkspaceCheckoutLoading;
- const emptyMessage =
- workspaces.length === 0 || sourceDatabaseId == null
- ? t`No workspaces yet`
- : t`No workspaces for this database yet`;
-
- const handleWorkspaceSelect = async (workspace: {
- id: number;
- name?: string;
- }) => {
- dispatch(push(Urls.dataStudioWorkspace(workspace.id, transform.id)));
- };
-
- const handleCreateWorkspace = async ({
- databaseId,
- }: {
- databaseId?: DatabaseId | null;
- }) => {
- if (!databaseId) {
- sendErrorToast(t`Failed to create workspace, no database id`);
- return;
- }
-
- try {
- const workspace = await createWorkspace({
- database_id: Number(databaseId),
- }).unwrap();
-
- dispatch(push(Urls.dataStudioWorkspace(workspace.id, transform.id)));
- } catch (error) {
- sendErrorToast(t`Failed to create workspace`);
- }
- };
-
- return (
- <Menu position="bottom-end" width={280}>
- <Menu.Target>
- <Button
- role="button"
- data-testid="transform-edit-menu-button"
- rightSection={<Icon name="chevrondown" />}
- loading={isBusy}
- size="xs"
- >
- {t`Edit`}
- </Button>
- </Menu.Target>
- <Menu.Dropdown>
- <Menu.Item
- component={Link}
- to={transformEdit(transform.id)}
- leftSection={<Icon name="pencil" />}
- >
- {t`Edit definition`}
- </Menu.Item>
-
- {
- <>
- <Menu.Divider />
- <Menu.Label>{t`Add to workspace`}</Menu.Label>
- <Tooltip
- label={getCheckoutDisabledMessage(
- checkoutData?.checkout_disabled,
- )}
- disabled={!checkoutData?.checkout_disabled}
- >
- <Menu.Item
- disabled={isBusy || !!checkoutData?.checkout_disabled}
- leftSection={<Icon name="add" />}
- onClick={() => {
- handleCreateWorkspace({ databaseId: sourceDatabaseId });
- }}
- >
- <Stack gap={0} align="flex-start">
- <Text fw={600}>{t`New workspace`}</Text>
- <Text size="sm" c="text-tertiary">
- {t`Create a new workspace`}
- </Text>
- </Stack>
- </Menu.Item>
- </Tooltip>
- <Menu.Divider />
-
- {isLoadingWorkspaces || isWorkspaceCheckoutLoading ? (
- <Flex justify="center" align="center" py="md">
- <Loader size="sm" />
- </Flex>
- ) : matchingWorkspaces.length === 0 ? (
- <Box px="md" py="sm">
- <Text size="sm" c="text-tertiary">
- {emptyMessage}
- </Text>
- </Box>
- ) : (
- <ScrollArea.Autosize mah={320} type="scroll">
- <Stack gap={0}>
- {matchingWorkspaces.map((workspace) => (
- <Tooltip
- key={workspace.id}
- label={getCheckoutDisabledMessage(
- checkoutData?.checkout_disabled,
- )}
- disabled={!checkoutData?.checkout_disabled}
- >
- <Menu.Item
- leftSection={
- <Icon
- name="sparkles"
- c={workspace.isChecked ? "brand" : "text-primary"}
- />
- }
- onClick={() => handleWorkspaceSelect(workspace)}
- disabled={isBusy || !!checkoutData?.checkout_disabled}
- >
- <Stack gap={2} align="flex-start">
- <Text fw={600}>{workspace.name}</Text>
- </Stack>
- </Menu.Item>
- </Tooltip>
- ))}
- </Stack>
- </ScrollArea.Autosize>
- )}
- </>
- }
- </Menu.Dropdown>
- </Menu>
- );
-}
-
-function getTransformDatabaseId(transform: Transform) {
- if (
- transform.source_type === "python" &&
- "source-database" in transform.source
- ) {
- return transform.source["source-database"];
- }
-
- if ("query" in transform.source) {
- return transform.source.query.database;
- }
-
- return undefined;
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/EditTransformMenu/EditTransformMenu.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/EditTransformMenu/EditTransformMenu.unit.spec.tsx
deleted file mode 100644
index e2ce610fed8..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/EditTransformMenu/EditTransformMenu.unit.spec.tsx
+++ /dev/null
@@ -1,255 +0,0 @@
-import userEvent from "@testing-library/user-event";
-import { Route } from "react-router";
-
-import {
- setupCreateWorkspaceEndpoint,
- setupWorkspaceCheckoutEndpoint,
- setupWorkspacesEndpoint,
-} from "__support__/server-mocks";
-import { renderWithProviders, screen, waitFor } from "__support__/ui";
-import type {
- Transform,
- Workspace,
- WorkspaceCheckoutResponse,
- WorkspaceItem,
-} from "metabase-types/api";
-import { createMockTransform } from "metabase-types/api/mocks";
-
-import { EditTransformMenu } from "./EditTransformMenu";
-
-const DATABASE_ID = 1;
-
-function createMockWorkspaceItem(opts?: Partial<WorkspaceItem>): WorkspaceItem {
- return {
- id: 1,
- name: "Workspace 1",
- database_id: DATABASE_ID,
- status: "ready",
- updated_at: "2024-01-01T00:00:00Z",
- ...opts,
- };
-}
-
-function createMockWorkspace(opts?: Partial<Workspace>): Workspace {
- return {
- id: 1,
- name: "Workspace 1",
- status: "ready",
- database_id: DATABASE_ID,
- ...opts,
- };
-}
-
-type SetupOpts = {
- transform?: Transform;
- workspaces?: WorkspaceItem[];
- checkoutResponse?: Partial<WorkspaceCheckoutResponse>;
-};
-
-function setup({
- transform = createMockTransform({
- id: 1,
- name: "Test Transform",
- source: {
- type: "query",
- query: { database: DATABASE_ID, type: "native", native: { query: "" } },
- },
- }),
- workspaces = [],
- checkoutResponse = {},
-}: SetupOpts = {}) {
- setupWorkspacesEndpoint(workspaces);
- setupWorkspaceCheckoutEndpoint(checkoutResponse);
- setupCreateWorkspaceEndpoint(
- createMockWorkspace({ id: 99, name: "New Workspace" }),
- );
-
- renderWithProviders(
- <Route
- component={() => <EditTransformMenu transform={transform} />}
- path="/"
- />,
- {
- withRouter: true,
- initialRoute: "/",
- },
- );
-}
-
-function findMenuItemByText(text: string) {
- return screen.getAllByRole("menuitem").find((item) => {
- return item.textContent?.includes(text);
- });
-}
-
-describe("EditTransformMenu", () => {
- it("should render menu items and sort workspaces with existing checkouts first", async () => {
- setup({
- workspaces: [
- createMockWorkspaceItem({ id: 1, name: "Workspace A" }),
- createMockWorkspaceItem({ id: 2, name: "Workspace B" }),
- createMockWorkspaceItem({ id: 3, name: "Workspace C" }),
- ],
- checkoutResponse: {
- // Return workspaces in order where existing ones come last from backend
- workspaces: [
- { id: 1, name: "Workspace A", status: "ready", existing: null },
- { id: 2, name: "Workspace B", status: "ready", existing: null },
- {
- id: 3,
- name: "Workspace C",
- status: "ready",
- existing: { ref_id: "abc123", name: "Test Transform" },
- },
- ],
- },
- });
-
- // Wait for button to finish loading before clicking
- const editButton = await screen.findByRole("button", { name: /Edit/i });
- await waitFor(() => {
- expect(editButton).not.toHaveAttribute("data-loading", "true");
- });
-
- await userEvent.click(editButton);
-
- // Verify basic menu structure renders
- expect(screen.getByText("Add to workspace")).toBeInTheDocument();
- expect(screen.getByText("New workspace")).toBeInTheDocument();
-
- // Wait for workspaces to load
- await waitFor(() => {
- expect(screen.getByText("Workspace C")).toBeInTheDocument();
- });
- expect(screen.getByText("Workspace A")).toBeInTheDocument();
- expect(screen.getByText("Workspace B")).toBeInTheDocument();
-
- // Verify sorting: workspaces with existing checkouts should be first
- const menuItems = screen.getAllByRole("menuitem").filter((item) => {
- const text = item.textContent;
- return (
- text?.includes("Workspace A") ||
- text?.includes("Workspace B") ||
- text?.includes("Workspace C")
- );
- });
-
- // Workspace C should be first because it has existing checkout
- expect(menuItems[0]).toHaveTextContent("Workspace C");
- expect(menuItems[1]).toHaveTextContent("Workspace A");
- expect(menuItems[2]).toHaveTextContent("Workspace B");
- });
-
- describe("checkout disabled tooltips", () => {
- it("should disable 'New workspace' and workspace items when checkout_disabled is 'mbql'", async () => {
- setup({
- workspaces: [createMockWorkspaceItem({ id: 1, name: "Workspace A" })],
- checkoutResponse: {
- checkout_disabled: "mbql",
- workspaces: [
- { id: 1, name: "Workspace A", status: "ready", existing: null },
- ],
- },
- });
-
- const editButton = await screen.findByRole("button", { name: /Edit/i });
- await waitFor(() => {
- expect(editButton).not.toHaveAttribute("data-loading", "true");
- });
-
- await userEvent.click(editButton);
-
- // Find menu items
- const newWorkspaceItem = findMenuItemByText("New workspace");
- const workspaceAItem = findMenuItemByText("Workspace A");
-
- expect(newWorkspaceItem).toHaveAttribute("data-disabled", "true");
- expect(workspaceAItem).toHaveAttribute("data-disabled", "true");
- });
-
- it("should show tooltip with MBQL message when hovering disabled items", async () => {
- setup({
- workspaces: [createMockWorkspaceItem({ id: 1, name: "Workspace A" })],
- checkoutResponse: {
- checkout_disabled: "mbql",
- workspaces: [
- { id: 1, name: "Workspace A", status: "ready", existing: null },
- ],
- },
- });
-
- const editButton = await screen.findByRole("button", { name: /Edit/i });
- await waitFor(() => {
- expect(editButton).not.toHaveAttribute("data-loading", "true");
- });
-
- await userEvent.click(editButton);
-
- const newWorkspaceItem = findMenuItemByText("New workspace");
- await userEvent.hover(newWorkspaceItem!);
-
- await waitFor(() => {
- expect(
- screen.getByText(
- "Transforms based on the query builder cannot be edited in a workspace.",
- ),
- ).toBeInTheDocument();
- });
- });
-
- it("should show tooltip with card-reference message when checkout is disabled", async () => {
- setup({
- workspaces: [createMockWorkspaceItem({ id: 1, name: "Workspace A" })],
- checkoutResponse: {
- checkout_disabled: "card-reference",
- workspaces: [
- { id: 1, name: "Workspace A", status: "ready", existing: null },
- ],
- },
- });
-
- const editButton = await screen.findByRole("button", { name: /Edit/i });
- await waitFor(() => {
- expect(editButton).not.toHaveAttribute("data-loading", "true");
- });
-
- await userEvent.click(editButton);
-
- const workspaceItem = findMenuItemByText("Workspace A");
- await userEvent.hover(workspaceItem!);
-
- await waitFor(() => {
- expect(
- screen.getByText(
- "Transforms referencing other questions cannot be edited in a workspace.",
- ),
- ).toBeInTheDocument();
- });
- });
-
- it("should not disable items when checkout_disabled is null", async () => {
- setup({
- workspaces: [createMockWorkspaceItem({ id: 1, name: "Workspace A" })],
- checkoutResponse: {
- checkout_disabled: null,
- workspaces: [
- { id: 1, name: "Workspace A", status: "ready", existing: null },
- ],
- },
- });
-
- const editButton = await screen.findByRole("button", { name: /Edit/i });
- await waitFor(() => {
- expect(editButton).not.toHaveAttribute("data-loading", "true");
- });
-
- await userEvent.click(editButton);
-
- const newWorkspaceItem = findMenuItemByText("New workspace");
- const workspaceAItem = findMenuItemByText("Workspace A");
-
- expect(newWorkspaceItem).not.toHaveAttribute("data-disabled", "true");
- expect(workspaceAItem).not.toHaveAttribute("data-disabled", "true");
- });
- });
-});
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/EditTransformMenu/index.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/EditTransformMenu/index.ts
deleted file mode 100644
index 3670f139598..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/EditTransformMenu/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./EditTransformMenu";
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/MergeWorkspaceModal.module.css b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/MergeWorkspaceModal.module.css
deleted file mode 100644
index a6494638bba..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/MergeWorkspaceModal.module.css
+++ /dev/null
@@ -1,31 +0,0 @@
-.sidebarItem {
- cursor: pointer;
- border-left: 2px solid transparent;
-
- &:hover {
- background: var(--mb-color-background-secondary);
- }
-}
-
-.sidebarItemActive {
- background: var(--mb-color-background-secondary);
- border-left-color: var(--mb-color-brand);
-}
-
-.diffEditor {
- height: 100%;
-
- :global {
- .cm-content {
- padding: 0;
- }
-
- .cm-collapsedLines {
- padding-left: 0;
- }
-
- .cm-scroller {
- font-family: monospace;
- }
- }
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/MergeWorkspaceModal.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/MergeWorkspaceModal.tsx
deleted file mode 100644
index 23c257da5ae..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/MergeWorkspaceModal.tsx
+++ /dev/null
@@ -1,245 +0,0 @@
-import cx from "classnames";
-import { useMemo, useState } from "react";
-import { t } from "ttag";
-import * as Yup from "yup";
-
-import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import { Box, Flex, Icon, Modal, Text, Title } from "metabase/ui";
-import { useGetWorkspaceProblemsQuery } from "metabase-enterprise/api";
-import type {
- WorkspaceId,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-
-import S from "./MergeWorkspaceModal.module.css";
-import { DiffView } from "./components/DiffView";
-import { OverviewPanel } from "./components/OverviewPanel";
-import { TransformListItem } from "./components/TransformListItem";
-
-type MergeWorkspaceModalProps = {
- onClose: VoidFunction;
- onSubmit: (commitMessage: string) => Promise<void>;
- isLoading?: boolean;
- isDisabled?: boolean;
- workspaceId: WorkspaceId;
- workspaceName: string;
- workspaceTransforms: WorkspaceTransformListItem[];
-};
-
-export type MergeWorkspaceFormValues = {
- commit_message: string;
-};
-
-export const initialFormValues: MergeWorkspaceFormValues = {
- commit_message: "",
-};
-export const MAX_COMMIT_MESSAGE_LENGTH = 255;
-
-const getMergeWorkspaceSchema = () =>
- Yup.object().shape({
- commit_message: Yup.string()
- .trim()
- .max(MAX_COMMIT_MESSAGE_LENGTH, t`Commit message is too long.`)
- .required(t`Please provide a commit message.`),
- });
-
-export const MergeWorkspaceModal = ({
- onClose,
- onSubmit,
- isLoading = false,
- isDisabled = false,
- workspaceId,
- workspaceName,
- workspaceTransforms,
-}: MergeWorkspaceModalProps) => {
- const { sendErrorToast } = useMetadataToasts();
- const validationSchema = useMemo(() => getMergeWorkspaceSchema(), []);
-
- const {
- data: workspaceProblems = [],
- isFetching: isLoadingWorkspaceProblems,
- } = useGetWorkspaceProblemsQuery(workspaceId);
- const hasBlockingProblems = useMemo(
- () => workspaceProblems.some((p) => p.block_merge === true),
- [workspaceProblems],
- );
-
- const updatedTransforms = useMemo(
- () => workspaceTransforms.filter((t) => t.global_id != null),
- [workspaceTransforms],
- );
-
- const newTransforms = useMemo(
- () => workspaceTransforms.filter((t) => t.global_id == null),
- [workspaceTransforms],
- );
-
- const [selectedTransformId, setSelectedTransformId] = useState<
- string | "overview"
- >("overview");
-
- const selectedTransform =
- selectedTransformId !== "overview"
- ? workspaceTransforms.find((t) => t.ref_id === selectedTransformId)
- : null;
-
- const handleSubmit = async (values: MergeWorkspaceFormValues) => {
- try {
- await onSubmit(values.commit_message.trim());
- onClose();
- } catch (error) {
- sendErrorToast(t`Failed to merge workspace`);
- throw error;
- }
- };
-
- return (
- <Modal
- data-testid="review-changes-modal"
- onClose={onClose}
- opened
- title={
- <Flex align="center" gap="sm">
- <Icon name="git_branch" c="brand" />
- <Flex direction="column" gap="xs">
- <Title order={3}>{t`Review Changes`}</Title>
- <Text size="sm" c="text-secondary">
- {workspaceName}
- </Text>
- </Flex>
- </Flex>
- }
- size="xl"
- padding={0}
- styles={{
- header: {
- padding: "1rem 1.5rem",
- borderBottom: "1px solid var(--mb-color-border)",
- },
- }}
- >
- <FormProvider
- initialValues={initialFormValues}
- validationSchema={validationSchema}
- onSubmit={handleSubmit}
- >
- {({ values, touched, errors }) => (
- <Form style={{ display: "flex", flexDirection: "column" }}>
- <Flex h={540}>
- <Box
- pt="md"
- w={220}
- miw={220}
- style={{
- borderRight: "1px solid var(--mb-color-border)",
- overflowY: "auto",
- }}
- >
- <Flex
- align="center"
- gap="sm"
- px="md"
- py="sm"
- className={cx(
- S.sidebarItem,
- selectedTransformId === "overview" && S.sidebarItemActive,
- )}
- onClick={() => setSelectedTransformId("overview")}
- >
- <Icon name="document" size={14} c="text-secondary" />
- <Text>{t`Overview`}</Text>
- </Flex>
- {newTransforms.length > 0 && (
- <>
- <Text
- px="md"
- py="sm"
- fz="xs"
- fw={700}
- tt="uppercase"
- c="text-secondary"
- >
- {t`New transforms`}
- </Text>
- {newTransforms.map((transform) => (
- <TransformListItem
- key={transform.ref_id}
- transform={transform}
- isSelected={selectedTransformId === transform.ref_id}
- onClick={() => setSelectedTransformId(transform.ref_id)}
- workspaceId={workspaceId}
- />
- ))}
- </>
- )}
- {updatedTransforms.length > 0 && (
- <>
- <Text
- px="md"
- py="sm"
- fz="xs"
- fw={700}
- tt="uppercase"
- c="text-secondary"
- >
- {t`Modified transforms`}
- </Text>
- {updatedTransforms.map((transform) => (
- <TransformListItem
- key={transform.ref_id}
- transform={transform}
- isSelected={selectedTransformId === transform.ref_id}
- onClick={() => setSelectedTransformId(transform.ref_id)}
- workspaceId={workspaceId}
- />
- ))}
- </>
- )}
- </Box>
- <Box flex={1} miw={0} style={{ overflow: "auto" }}>
- {selectedTransformId === "overview" ? (
- <OverviewPanel
- commitMessageLength={values.commit_message?.length}
- hasCommitMessageError={!!errors.commit_message}
- workspaceId={workspaceId}
- transformCount={workspaceTransforms.length}
- />
- ) : selectedTransform ? (
- <DiffView
- key={selectedTransform.ref_id}
- transform={selectedTransform}
- workspaceId={workspaceId}
- />
- ) : (
- <Flex align="center" justify="center" h="100%">
- <Text c="text-secondary">{t`Transform not found`}</Text>
- </Flex>
- )}
- </Box>
- </Flex>
- <Flex
- justify="flex-end"
- align="center"
- p="md"
- style={{ borderTop: "1px solid var(--mb-color-border)" }}
- >
- <FormSubmitButton
- disabled={
- !values.commit_message?.trim() ||
- (touched.commit_message && !!errors.commit_message) ||
- hasBlockingProblems ||
- isLoadingWorkspaceProblems ||
- isDisabled
- }
- label={t`Merge`}
- loading={isLoading}
- variant="filled"
- />
- </Flex>
- </Form>
- )}
- </FormProvider>
- </Modal>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/DiffView.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/DiffView.tsx
deleted file mode 100644
index 70b0f1a4fab..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/DiffView.tsx
+++ /dev/null
@@ -1,131 +0,0 @@
-import { unifiedMergeView } from "@codemirror/merge";
-import cx from "classnames";
-import { useMemo } from "react";
-import { t } from "ttag";
-import _ from "underscore";
-
-import { CodeMirror } from "metabase/common/components/CodeMirror";
-import EditorS from "metabase/querying/components/CodeMirrorEditor/CodeMirrorEditor.module.css";
-import { Flex, Loader, Stack, Text } from "metabase/ui";
-import type {
- WorkspaceId,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-
-import S from "../MergeWorkspaceModal.module.css";
-import { useTransformSources } from "../hooks/useTransformSources";
-import { areSourceTablesEqual } from "../utils";
-
-import { TableDiff } from "./TableDiff";
-import { TransformSourceTablesDiff } from "./TransformSourceTablesDiff";
-
-type DiffViewProps = {
- transform: WorkspaceTransformListItem;
- workspaceId: WorkspaceId;
-};
-
-export const DiffView = ({ transform, workspaceId }: DiffViewProps) => {
- const {
- oldSource,
- oldSourceTables,
- oldTarget,
- newSource,
- newSourceTables,
- newTarget,
- isLoading,
- hasError,
- } = useTransformSources(workspaceId, transform);
-
- const extensions = useMemo(
- () =>
- _.compact([
- oldSource &&
- unifiedMergeView({
- original: oldSource,
- mergeControls: false,
- }),
- ]),
- [oldSource],
- );
-
- if (isLoading) {
- return (
- <Flex
- align="center"
- justify="center"
- h="100%"
- direction="column"
- gap="sm"
- >
- <Loader size="sm" />
- <Text c="text-secondary">{t`Loading diff...`}</Text>
- </Flex>
- );
- }
-
- if (hasError) {
- return (
- <Flex align="center" justify="center" h="100%">
- <Text c="danger">{t`Failed to load diff`}</Text>
- </Flex>
- );
- }
-
- const schemaChanged = oldTarget?.schema !== newTarget?.schema;
- const tableChanged = oldTarget?.name !== newTarget?.name;
- const targetChanged = schemaChanged || tableChanged;
- const sourceTablesChanged = !areSourceTablesEqual(
- oldSourceTables,
- newSourceTables,
- );
-
- return (
- <Stack gap={0} h="100%">
- {oldTarget && newTarget && targetChanged && (
- <Stack
- data-testid="transform-target-diff"
- gap="xs"
- px="md"
- py="sm"
- style={{
- borderBottom: "1px solid var(--mb-color-border)",
- }}
- >
- <Text component="label" fw="bold">{t`Transform target`}</Text>
- <TableDiff
- newSchema={newTarget.schema}
- newTable={newTarget.name}
- oldSchema={oldTarget.schema}
- oldTable={oldTarget.name}
- />
- </Stack>
- )}
-
- {oldSourceTables && newSourceTables && sourceTablesChanged && (
- <Stack
- data-testid="source-tables-diff"
- gap="xs"
- px="md"
- py="sm"
- style={{
- borderBottom: "1px solid var(--mb-color-border)",
- }}
- >
- <Text component="label" fw="bold">{t`Source tables`}</Text>
- <TransformSourceTablesDiff
- newSourceTables={newSourceTables}
- oldSourceTables={oldSourceTables}
- />
- </Stack>
- )}
-
- <CodeMirror
- className={cx(EditorS.editor, S.diffEditor)}
- extensions={extensions}
- value={newSource}
- readOnly
- autoCorrect="off"
- />
- </Stack>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/OverviewPanel.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/OverviewPanel.tsx
deleted file mode 100644
index 0d8d9b6a67e..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/OverviewPanel.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-import { msgid, ngettext, t } from "ttag";
-
-import { FormTextarea } from "metabase/forms";
-import { Box, Stack, Text } from "metabase/ui";
-import type { WorkspaceId } from "metabase-types/api";
-
-import { MAX_COMMIT_MESSAGE_LENGTH } from "../MergeWorkspaceModal";
-
-import { QualityChecksSection } from "./QualityChecksSection";
-
-type OverviewPanelProps = {
- commitMessageLength?: number;
- hasCommitMessageError: boolean;
- workspaceId: WorkspaceId;
- transformCount: number;
-};
-
-export const OverviewPanel = ({
- commitMessageLength = 0,
- hasCommitMessageError,
- workspaceId,
- transformCount,
-}: OverviewPanelProps) => {
- return (
- <Box p="xl" h="100%" style={{ overflowY: "auto" }}>
- <Stack>
- <Box>
- <Text>{t`This will merge all changes from this workspace back to the source transforms.`}</Text>
- <Text mt="xs">
- {t`The commit message will be used to display the history of transform changes.`}
- </Text>
- </Box>
- <Stack mt="md" gap={0}>
- <FormTextarea
- data-autofocus
- label={t`Commit message`}
- name="commit_message"
- placeholder={t`Describe the changes you made in this workspace...`}
- minRows={4}
- required
- />
- {!hasCommitMessageError && (
- <Text size="sm" c="text-tertiary" pt="sm">
- {commitMessageLength}/{MAX_COMMIT_MESSAGE_LENGTH}
- </Text>
- )}
- </Stack>
- <QualityChecksSection workspaceId={workspaceId} />
- <Box
- p="md"
- style={{
- backgroundColor: "var(--mb-color-background-secondary)",
- borderRadius: "var(--mantine-radius-sm)",
- }}
- >
- <Text>
- {ngettext(
- msgid`${transformCount} transform will be merged`,
- `${transformCount} transforms will be merged`,
- transformCount,
- )}
- </Text>
- </Box>
- </Stack>
- </Box>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/QualityChecksSection.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/QualityChecksSection.tsx
deleted file mode 100644
index ea83c265a98..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/QualityChecksSection.tsx
+++ /dev/null
@@ -1,129 +0,0 @@
-import { useMemo, useState } from "react";
-import { t } from "ttag";
-
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { Box, Collapse, Group, Icon, Loader, Stack, Text } from "metabase/ui";
-import { useGetWorkspaceProblemsQuery } from "metabase-enterprise/api";
-import type { WorkspaceId } from "metabase-types/api";
-
-import type { ProblemCheckCategory } from "../problemUtils";
-import {
- formatProblemDetails,
- getCheckStatus,
- getCheckStatusWithUnused,
- getCheckTitle,
- groupProblemsByCategory,
-} from "../problemUtils";
-
-const CHECK_CATEGORIES: ProblemCheckCategory[] = [
- "external-dependencies",
- "internal-dependencies",
- "structural-issues",
- "unused-outputs",
-];
-
-type QualityChecksSectionProps = {
- workspaceId: WorkspaceId;
-};
-
-export const QualityChecksSection = ({
- workspaceId,
-}: QualityChecksSectionProps) => {
- const {
- data: problems = [],
- error,
- isLoading,
- } = useGetWorkspaceProblemsQuery(workspaceId);
- const grouped = useMemo(() => groupProblemsByCategory(problems), [problems]);
- const [expandedChecks, setExpandedChecks] = useState<
- Set<ProblemCheckCategory>
- >(new Set());
-
- const toggleCheck = (category: ProblemCheckCategory) => {
- setExpandedChecks((prev) => {
- const next = new Set(prev);
- if (next.has(category)) {
- next.delete(category);
- } else {
- next.add(category);
- }
- return next;
- });
- };
-
- return (
- <Stack gap="sm">
- <Text fw="bold">{t`Quality Checks`}</Text>
-
- <LoadingAndErrorWrapper error={error}>
- <Stack gap="sm">
- {CHECK_CATEGORIES.map((category) => {
- const categoryProblems = grouped[category];
- const checkStatus =
- category === "unused-outputs"
- ? getCheckStatusWithUnused(categoryProblems)
- : getCheckStatus(categoryProblems);
- const isExpanded = expandedChecks.has(category);
- const hasProblems = checkStatus.count > 0;
-
- return (
- <Box key={category}>
- <Group
- justify="space-between"
- style={{ cursor: hasProblems ? "pointer" : "default" }}
- onClick={() => hasProblems && toggleCheck(category)}
- >
- <Text>{getCheckTitle(category)}</Text>
-
- {isLoading ? (
- <Loader size="xs" aria-label={t`Loading`} />
- ) : (
- <Group gap="xs">
- {checkStatus.status === "passed" && (
- <Icon name="check" size={14} c="success" />
- )}
-
- <Text
- c={
- checkStatus.status === "passed"
- ? "success"
- : checkStatus.problems.some(
- (p) => p.severity === "error",
- )
- ? "error"
- : "warning"
- }
- >
- {checkStatus.status === "passed"
- ? category === "unused-outputs" &&
- checkStatus.count > 0
- ? t`${checkStatus.count} info`
- : t`Passed`
- : checkStatus.count === 1
- ? t`Failed`
- : t`${checkStatus.count} issues`}
- </Text>
- </Group>
- )}
- </Group>
- {hasProblems && (
- <Collapse in={isExpanded}>
- <Stack gap="xs" mt="xs" pl="md">
- {checkStatus.problems.map((problem, idx) => (
- <Box key={idx}>
- <Text size="sm" c="text-secondary">
- {formatProblemDetails(problem)}
- </Text>
- </Box>
- ))}
- </Stack>
- </Collapse>
- )}
- </Box>
- );
- })}
- </Stack>
- </LoadingAndErrorWrapper>
- </Stack>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/QualityChecksSection.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/QualityChecksSection.unit.spec.tsx
deleted file mode 100644
index d6c62a00719..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/QualityChecksSection.unit.spec.tsx
+++ /dev/null
@@ -1,234 +0,0 @@
-import { setupWorkspaceProblemsEndpoint } from "__support__/server-mocks";
-import {
- renderWithProviders,
- screen,
- waitFor,
- waitForLoaderToBeRemoved,
-} from "__support__/ui";
-import type { WorkspaceId, WorkspaceProblem } from "metabase-types/api";
-import { createMockWorkspaceProblem } from "metabase-types/api/mocks";
-
-import { QualityChecksSection } from "./QualityChecksSection";
-
-const MOCK_WORKSPACE_ID: WorkspaceId = 1;
-
-describe("QualityChecksSection", () => {
- it("should render all check categories", async () => {
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, []);
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
- await waitForLoaderToBeRemoved();
-
- expect(screen.getByText("External dependencies")).toBeInTheDocument();
- expect(screen.getByText("Internal dependencies")).toBeInTheDocument();
- expect(screen.getByText("Structural issues")).toBeInTheDocument();
- expect(screen.getByText("Unused outputs")).toBeInTheDocument();
- });
-
- it("should show loading state while fetching problems", async () => {
- // Use a delayed promise to simulate loading
- let resolvePromise: (value: WorkspaceProblem[]) => void = () => {};
- const delayedPromise = new Promise<WorkspaceProblem[]>((resolve) => {
- resolvePromise = resolve;
- });
-
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, delayedPromise);
-
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
-
- // Verify loaders are rendered (one for each of the 4 categories)
- const loaders = screen.getAllByLabelText("Loading");
- expect(loaders).toHaveLength(4);
-
- // Verify "Passed" status is not shown while loading
- expect(screen.queryByText("Passed")).not.toBeInTheDocument();
-
- // Resolve the promise to clean up
- resolvePromise([]);
- });
-
- it("should show 'Passed' status when there are no problems", async () => {
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, []);
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
- await waitForLoaderToBeRemoved();
-
- await waitFor(() => {
- const passedTexts = screen.getAllByText("Passed");
- expect(passedTexts.length).toBe(4); // All 4 categories should pass
- });
- });
-
- it("should show check icon for passed checks", async () => {
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, []);
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
- await waitForLoaderToBeRemoved();
-
- await waitFor(() => {
- const checkIcons = screen.getAllByLabelText("check icon");
- expect(checkIcons.length).toBe(4); // All 4 categories should have check icons
- });
- });
-
- describe("External dependencies", () => {
- it("should display failed status when there are external dependency problems", async () => {
- const problems: WorkspaceProblem[] = [
- createMockWorkspaceProblem({
- category: "external-downstream",
- problem: "not-run",
- severity: "error",
- description: "External transform depends on this",
- }),
- ];
-
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, problems);
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
- await waitForLoaderToBeRemoved();
-
- await waitFor(() => {
- expect(screen.getByText("Failed")).toBeInTheDocument();
- });
- });
-
- it("should display issue count when there are multiple external dependency problems", async () => {
- const problems: WorkspaceProblem[] = [
- createMockWorkspaceProblem({
- category: "external-downstream",
- problem: "not-run",
- severity: "error",
- description: "External transform 1 depends on this",
- }),
- createMockWorkspaceProblem({
- category: "external-downstream",
- problem: "not-run",
- severity: "warning",
- description: "External transform 2 depends on this",
- }),
- ];
-
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, problems);
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
- await waitForLoaderToBeRemoved();
-
- await waitFor(() => {
- expect(screen.getByText("2 issues")).toBeInTheDocument();
- });
- });
- });
-
- describe("Internal dependencies", () => {
- it("should display failed status when there are internal dependency problems", async () => {
- const problems: WorkspaceProblem[] = [
- createMockWorkspaceProblem({
- category: "internal-downstream",
- problem: "not-run",
- severity: "error",
- description: "Internal transform depends on this",
- }),
- ];
-
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, problems);
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
- await waitForLoaderToBeRemoved();
-
- await waitFor(() => {
- expect(screen.getByText("Failed")).toBeInTheDocument();
- });
- });
- });
-
- describe("Structural issues", () => {
- it("should display failed status for internal structural issues", async () => {
- const problems: WorkspaceProblem[] = [
- createMockWorkspaceProblem({
- category: "internal",
- problem: "removed-field",
- severity: "error",
- description: "Field was removed",
- }),
- ];
-
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, problems);
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
- await waitForLoaderToBeRemoved();
-
- await waitFor(() => {
- expect(screen.getByText("Failed")).toBeInTheDocument();
- });
- });
-
- it("should display failed status for external structural issues", async () => {
- const problems: WorkspaceProblem[] = [
- createMockWorkspaceProblem({
- category: "external",
- problem: "removed-field",
- severity: "error",
- description: "External field was removed",
- }),
- ];
-
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, problems);
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
- await waitForLoaderToBeRemoved();
-
- await waitFor(() => {
- expect(screen.getByText("Failed")).toBeInTheDocument();
- });
- });
- });
-
- describe("Multiple categories with problems", () => {
- it("should display problems from multiple categories", async () => {
- const problems: WorkspaceProblem[] = [
- createMockWorkspaceProblem({
- category: "external-downstream",
- problem: "not-run",
- severity: "error",
- description: "External dependency issue",
- }),
- createMockWorkspaceProblem({
- category: "internal",
- problem: "removed-field",
- severity: "warning",
- description: "Structural issue",
- }),
- createMockWorkspaceProblem({
- category: "unused",
- problem: "not-run",
- severity: "info",
- description: "Unused output",
- }),
- ];
-
- setupWorkspaceProblemsEndpoint(MOCK_WORKSPACE_ID, problems);
- renderWithProviders(
- <QualityChecksSection workspaceId={MOCK_WORKSPACE_ID} />,
- );
- await waitForLoaderToBeRemoved();
-
- await waitFor(() => {
- // There should be multiple "Failed" texts (external dependencies and structural issues)
- const failedTexts = screen.getAllByText("Failed");
- expect(failedTexts.length).toBeGreaterThanOrEqual(2);
- });
-
- expect(screen.getByText("1 info")).toBeInTheDocument();
- });
- });
-});
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/TableDiff.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/TableDiff.tsx
deleted file mode 100644
index 24e51b41ffd..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/TableDiff.tsx
+++ /dev/null
@@ -1,57 +0,0 @@
-import { Group, Icon, Text } from "metabase/ui";
-import type { SchemaName } from "metabase-types/api";
-
-interface Props {
- newSchema: SchemaName | null | undefined;
- newTable: string | undefined;
- oldSchema: SchemaName | null | undefined;
- oldTable: string | undefined;
-}
-
-export const TableDiff = ({
- newSchema,
- newTable,
- oldSchema,
- oldTable,
-}: Props) => {
- const schemaChanged = oldSchema !== newSchema;
- const tableChanged = oldTable !== newTable;
-
- return (
- <Group gap="sm">
- <Group gap="xs">
- <Icon c="text-secondary" name="folder" />
-
- {schemaChanged && oldSchema && (
- <Text c="danger" component="s" td="line-through">
- {oldSchema}
- </Text>
- )}
-
- {newSchema && (
- <Text c={schemaChanged ? "success" : undefined}>{newSchema}</Text>
- )}
- </Group>
-
- <Divider />
-
- <Group gap="xs">
- <Icon c="text-secondary" name="table2" />
-
- {tableChanged && oldTable && (
- <Text c="danger" component="s" td="line-through">
- {oldTable}
- </Text>
- )}
-
- {newTable && (
- <Text c={tableChanged ? "success" : undefined}>{newTable}</Text>
- )}
- </Group>
- </Group>
- );
-};
-
-function Divider() {
- return <Icon name="chevronright" size={8} />;
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/TransformListItem.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/TransformListItem.tsx
deleted file mode 100644
index 7782ff2379e..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/TransformListItem.tsx
+++ /dev/null
@@ -1,53 +0,0 @@
-import cx from "classnames";
-
-import { Flex, Icon, Text } from "metabase/ui";
-import type {
- WorkspaceId,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-
-import S from "../MergeWorkspaceModal.module.css";
-import { useTransformSources } from "../hooks/useTransformSources";
-
-type TransformListItemProps = {
- transform: WorkspaceTransformListItem;
- isSelected: boolean;
- onClick: () => void;
- workspaceId: WorkspaceId;
-};
-
-export const TransformListItem = ({
- transform,
- isSelected,
- onClick,
- workspaceId,
-}: TransformListItemProps) => {
- const { diffStats } = useTransformSources(workspaceId, transform);
-
- return (
- <Flex
- align="center"
- justify="space-between"
- px="md"
- py="sm"
- className={cx(S.sidebarItem, isSelected && S.sidebarItemActive)}
- onClick={onClick}
- data-testid={`transform-list-item`}
- >
- <Flex align="center" gap="sm" style={{ overflow: "hidden" }}>
- <Icon name="code_block" size={14} c="text-secondary" />
- <Text truncate>{transform.name}</Text>
- </Flex>
- {diffStats && (diffStats.additions > 0 || diffStats.deletions > 0) && (
- <Flex gap="xs" fz="xs" style={{ flexShrink: 0 }}>
- {diffStats.additions > 0 && (
- <Text c="success">+{diffStats.additions}</Text>
- )}
- {diffStats.deletions > 0 && (
- <Text c="danger">-{diffStats.deletions}</Text>
- )}
- </Flex>
- )}
- </Flex>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/TransformSourceTablesDiff.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/TransformSourceTablesDiff.tsx
deleted file mode 100644
index b72c7e53e5c..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/components/TransformSourceTablesDiff.tsx
+++ /dev/null
@@ -1,99 +0,0 @@
-import { Fragment } from "react";
-
-import { skipToken, useGetTableQuery } from "metabase/api";
-import { Box, Group, Loader, Text } from "metabase/ui";
-import type { PythonTransformTableAliases, TableId } from "metabase-types/api";
-
-import { TableDiff } from "./TableDiff";
-
-interface Props {
- newSourceTables: PythonTransformTableAliases;
- oldSourceTables: PythonTransformTableAliases;
-}
-
-export const TransformSourceTablesDiff = ({
- newSourceTables,
- oldSourceTables,
-}: Props) => {
- const removedEntries = oldSourceTables.slice(newSourceTables.length);
-
- return (
- <Box
- display="grid"
- style={{
- alignItems: "center",
- gridTemplateColumns: "auto 1fr",
- rowGap: 4,
- columnGap: 32,
- }}
- >
- {newSourceTables.map((entry, index) => {
- const oldEntry = oldSourceTables[index];
- const oldAlias = oldEntry?.alias;
- const newAlias = entry.alias;
- const sourceNameChanged = oldAlias !== newAlias;
-
- return (
- <Fragment key={entry.alias}>
- <Group gap="xs">
- {sourceNameChanged && oldAlias && (
- <Text c="danger" component="s" td="line-through">
- {oldAlias}
- </Text>
- )}
-
- <Text c={sourceNameChanged ? "success" : undefined}>
- {newAlias}
- </Text>
- </Group>
-
- <TableItem
- oldTableId={oldEntry?.table_id}
- tableId={entry.table_id}
- />
- </Fragment>
- );
- })}
-
- {removedEntries.map((entry) => {
- return (
- <Fragment key={entry.alias}>
- <Text c="danger" component="s" td="line-through">
- {entry.alias}
- </Text>
-
- <TableItem oldTableId={entry.table_id} tableId={undefined} />
- </Fragment>
- );
- })}
- </Box>
- );
-};
-
-function TableItem({
- oldTableId,
- tableId,
-}: {
- oldTableId: TableId | undefined;
- tableId: TableId | undefined;
-}) {
- const { data: oldTable } = useGetTableQuery(
- oldTableId ? { id: oldTableId } : skipToken,
- );
- const { data: table } = useGetTableQuery(
- tableId ? { id: tableId } : skipToken,
- );
-
- if (!table && tableId) {
- return <Loader size="xs" />;
- }
-
- return (
- <TableDiff
- newSchema={table?.schema}
- newTable={table?.name}
- oldSchema={oldTable?.schema}
- oldTable={oldTable?.name}
- />
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/hooks/useTransformSources.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/hooks/useTransformSources.ts
deleted file mode 100644
index 5bb13699b14..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/hooks/useTransformSources.ts
+++ /dev/null
@@ -1,103 +0,0 @@
-import { useMemo } from "react";
-
-import { useGetTransformQuery } from "metabase/api";
-import { getMetadata } from "metabase/selectors/metadata";
-import { useSelector } from "metabase/utils/redux";
-import { useGetWorkspaceTransformQuery } from "metabase-enterprise/api";
-import type {
- PythonTransformSource,
- PythonTransformTableAliases,
- TransformSource,
- TransformTarget,
- WorkspaceId,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-
-import { computeDiffStats, getSourceCode } from "../utils";
-
-type UseTransformSourcesResult = {
- oldSource: string;
- oldSourceTables: PythonTransformTableAliases | undefined;
- oldTarget: TransformTarget | undefined;
- newSource: string;
- newSourceTables: PythonTransformTableAliases | undefined;
- newTarget: TransformTarget | undefined;
- isLoading: boolean;
- hasError: boolean;
- diffStats: { additions: number; deletions: number } | null;
-};
-
-export function useTransformSources(
- workspaceId: WorkspaceId,
- transform: WorkspaceTransformListItem,
-): UseTransformSourcesResult {
- const metadata = useSelector(getMetadata);
- const isNewTransform = transform.global_id == null;
-
- const workspaceTransformResult = useGetWorkspaceTransformQuery({
- workspaceId,
- transformId: transform.ref_id,
- });
-
- const globalTransformResult = useGetTransformQuery(transform.global_id!, {
- skip: isNewTransform,
- });
-
- const globalTransform = globalTransformResult.data;
- const workspaceTransform = workspaceTransformResult.data;
-
- const isLoading =
- workspaceTransformResult.isLoading ||
- (!isNewTransform && globalTransformResult.isLoading);
-
- const hasError =
- !!workspaceTransformResult.error ||
- (!isNewTransform && !!globalTransformResult.error);
-
- const oldSource = useMemo(() => {
- return globalTransform ? getSourceCode(globalTransform, metadata) : "";
- }, [globalTransform, metadata]);
-
- const newSource = useMemo(() => {
- return workspaceTransform
- ? getSourceCode(workspaceTransform, metadata)
- : "";
- }, [workspaceTransform, metadata]);
-
- const diffStats = useMemo(() => {
- if (isNewTransform && newSource) {
- const lineCount = newSource.split("\n").length;
- return { additions: lineCount, deletions: 0 };
- }
- if (oldSource && newSource) {
- return computeDiffStats(oldSource, newSource);
- }
- return null;
- }, [isNewTransform, oldSource, newSource]);
-
- return {
- oldSource,
- oldSourceTables: isPythonTransformSource(globalTransform?.source)
- ? globalTransform.source["source-tables"]
- : undefined,
- oldTarget: globalTransform?.target,
- newSource,
- newSourceTables: isPythonTransformSource(workspaceTransform?.source)
- ? workspaceTransform.source["source-tables"]
- : undefined,
- newTarget: workspaceTransform?.target,
- hasError,
- isLoading,
- diffStats,
- };
-}
-
-function isPythonTransformSource(
- source: TransformSource | undefined,
-): source is PythonTransformSource {
- return (
- source != null &&
- source.type === "python" &&
- source["source-database"] !== undefined
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/index.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/index.ts
deleted file mode 100644
index d6c209dcd2a..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/index.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export {
- MergeWorkspaceModal,
- MergeWorkspaceModal as ReviewChangesModal,
-} from "./MergeWorkspaceModal";
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/problemUtils.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/problemUtils.ts
deleted file mode 100644
index 541e53860c5..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/problemUtils.ts
+++ /dev/null
@@ -1,174 +0,0 @@
-import { match } from "ts-pattern";
-import { t } from "ttag";
-
-import type { WorkspaceProblem } from "metabase-types/api";
-import {
- isKnownWorkspaceProblemData,
- isWorkspaceProblemDataExternalDownstreamNotRun,
- isWorkspaceProblemDataInternalDownstreamNotRun,
- isWorkspaceProblemDataRemovedField,
-} from "metabase-types/guards";
-
-export type ProblemCheckCategory =
- | "external-dependencies"
- | "internal-dependencies"
- | "structural-issues"
- | "unused-outputs";
-
-export type GroupedProblems = {
- "external-dependencies": WorkspaceProblem[];
- "internal-dependencies": WorkspaceProblem[];
- "structural-issues": WorkspaceProblem[];
- "unused-outputs": WorkspaceProblem[];
-};
-
-export type CheckStatus = {
- status: "passed" | "failed";
- count: number;
- problems: WorkspaceProblem[];
-};
-
-/**
- * Groups problems by category into logical Quality Check categories
- */
-export function groupProblemsByCategory(
- problems: WorkspaceProblem[],
-): GroupedProblems {
- const grouped: GroupedProblems = {
- "external-dependencies": problems.filter(
- (problem) => problem.category === "external-downstream",
- ),
- "internal-dependencies": problems.filter(
- (problem) => problem.category === "internal-downstream",
- ),
- "structural-issues": problems.filter(
- (problem) =>
- problem.category === "internal" || problem.category === "external",
- ),
- "unused-outputs": problems.filter(
- (problem) => problem.category === "unused",
- ),
- };
-
- return grouped;
-}
-
-/**
- * Calculates the status for a group of problems
- * Unused problems are informational and don't affect status (always "passed")
- */
-export function getCheckStatus(problems: WorkspaceProblem[]): CheckStatus {
- // Filter out unused problems for status calculation - they're informational only
- const relevantProblems = problems.filter(
- (problem) => problem.category !== "unused",
- );
-
- // If all problems are unused, return passed with empty array
- // If there are any non-unused problems, return failed with those problems
- return {
- status: relevantProblems.length === 0 ? "passed" : "failed",
- count: relevantProblems.length,
- problems: relevantProblems,
- };
-}
-
-/**
- * Calculates status including unused problems (for unused-outputs check)
- */
-export function getCheckStatusWithUnused(
- problems: WorkspaceProblem[],
-): CheckStatus {
- return {
- status: "passed", // Unused is always passed (informational)
- count: problems.length,
- problems: problems, // Include all problems for display
- };
-}
-
-/**
- * Formats problem details for display
- */
-export function formatProblemDetails(problem: WorkspaceProblem): string {
- const parts: string[] = [];
-
- const transform = isKnownWorkspaceProblemData(problem)
- ? problem.transform
- : undefined;
-
- // Add transform reference if available
- if (transform) {
- const transformName = transform.name ?? transform.id.toString();
- const transformType =
- transform.type === "workspace-transform"
- ? t`workspace transform`
- : t`external transform`;
-
- parts.push(`${transformType} "${transformName}"`);
- }
-
- const output = isKnownWorkspaceProblemData(problem)
- ? problem.output
- : undefined;
-
- // Add table reference if available
- if (output) {
- const schema = output.schema || "";
- const table = output.table || "";
-
- if (schema && table) {
- parts.push(t`table "${schema}.${table}"`);
- } else if (table) {
- parts.push(t`table "${table}"`);
- }
- }
-
- const badRefs = isWorkspaceProblemDataRemovedField(problem)
- ? problem["bad-refs"]
- : undefined;
-
- // Add bad-refs for removed-field problems
- if (badRefs) {
- const fieldNames = badRefs
- .map((ref) => ref.name || ref.message || null)
- .filter(Boolean);
-
- if (fieldNames.length > 0) {
- parts.push(t`removed fields: ${fieldNames.join(", ")}`);
- }
- }
-
- const dependents =
- isWorkspaceProblemDataInternalDownstreamNotRun(problem) ||
- isWorkspaceProblemDataExternalDownstreamNotRun(problem)
- ? problem.dependents
- : undefined;
-
- // Add dependents if available
- if (dependents) {
- const dependentNames = dependents
- .map((dep: { name?: string; id?: string | number }) =>
- dep.name ? dep.name : dep.id?.toString(),
- )
- .filter(Boolean);
-
- if (dependentNames.length > 0) {
- parts.push(t`affects: ${dependentNames.join(", ")}`);
- }
- }
-
- // If we have the description and no specific details, use description
- if (parts.length === 0 && problem.description) {
- return problem.description;
- }
-
- return [problem.description, ...parts].join(". ");
-}
-
-export function getCheckTitle(category: ProblemCheckCategory): string {
- return match(category)
- .with("external-dependencies", () => t`External dependencies`)
- .with("internal-dependencies", () => t`Internal dependencies`)
- .with("structural-issues", () => t`Structural issues`)
- .with("unused-outputs", () => t`Unused outputs`)
- .exhaustive();
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/utils.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/utils.ts
deleted file mode 100644
index f727e58fdc7..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/utils.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import { diffLines } from "diff";
-
-import * as Lib from "metabase-lib";
-import type Metadata from "metabase-lib/v1/metadata/Metadata";
-import type {
- PythonTransformTableAliases,
- TransformSource,
-} from "metabase-types/api";
-
-export function getSourceCode(
- transform: { source: TransformSource },
- metadata: Metadata,
-): string {
- if (transform.source.type === "python") {
- return transform.source.body;
- }
- if (transform.source.type === "query") {
- const metadataProvider = Lib.metadataProvider(
- transform.source.query.database,
- metadata,
- );
- const query = Lib.fromJsQuery(metadataProvider, transform.source.query);
- if (Lib.queryDisplayInfo(query).isNative) {
- return Lib.rawNativeQuery(query);
- }
- }
- return "";
-}
-
-export function computeDiffStats(
- oldSource: string,
- newSource: string,
-): { additions: number; deletions: number } {
- const changes = diffLines(oldSource, newSource);
- let additions = 0;
- let deletions = 0;
-
- for (const change of changes) {
- const lineCount = change.count ?? 0;
- if (change.added) {
- additions += lineCount;
- } else if (change.removed) {
- deletions += lineCount;
- }
- }
-
- return { additions, deletions };
-}
-
-export function areSourceTablesEqual(
- a: PythonTransformTableAliases | undefined,
- b: PythonTransformTableAliases | undefined,
-) {
- if (a == null || b == null) {
- return a === b;
- }
-
- if (a.length !== b.length) {
- return false;
- }
-
- return a.every(
- (entry, index) =>
- b[index].alias === entry.alias && b[index].table_id === entry.table_id,
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/RunWorkspaceMenu/RunWorkspaceMenu.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/RunWorkspaceMenu/RunWorkspaceMenu.tsx
deleted file mode 100644
index df723a9d7c3..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/RunWorkspaceMenu/RunWorkspaceMenu.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-import { useCallback } from "react";
-import { t } from "ttag";
-
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import { Button, Icon, Menu } from "metabase/ui";
-import { useRunWorkspaceMutation } from "metabase-enterprise/api";
-import type { WorkspaceId } from "metabase-types/api";
-
-type RunWorkspaceMenuProps = {
- workspaceId: WorkspaceId;
- disabled?: boolean;
-};
-
-export function RunWorkspaceMenu({
- workspaceId,
- disabled = false,
-}: RunWorkspaceMenuProps) {
- const { sendErrorToast, sendSuccessToast } = useMetadataToasts();
- const [runWorkspace, { isLoading: isRunning }] = useRunWorkspaceMutation();
-
- const handleRunWorkspace = useCallback(
- async ({ staleOnly } = { staleOnly: false }) => {
- try {
- const response = await runWorkspace({
- id: workspaceId,
- stale_only: staleOnly,
- }).unwrap();
-
- if (response.failed.length > 0) {
- sendErrorToast(t`Some transforms failed to run`);
- } else if (response.succeeded.length > 0) {
- sendSuccessToast(t`Transforms ran successfully`);
- } else {
- sendSuccessToast(t`No transforms were run`);
- }
- } catch (error) {
- sendErrorToast(t`Failed to run transforms`);
- }
- },
- [workspaceId, runWorkspace, sendErrorToast, sendSuccessToast],
- );
-
- return (
- <Menu position="bottom-end">
- <Menu.Target>
- <Button
- data-testid="run-all-button"
- disabled={disabled}
- loading={isRunning}
- rightSection={<Icon name="chevrondown" />}
- size="xs"
- variant="default"
- >
- {t`Run transforms`}
- </Button>
- </Menu.Target>
- <Menu.Dropdown>
- <Menu.Item onClick={() => handleRunWorkspace()}>
- {t`Run all transforms`}
- </Menu.Item>
- <Menu.Item onClick={() => handleRunWorkspace({ staleOnly: true })}>
- {t`Run stale transforms`}
- </Menu.Item>
- </Menu.Dropdown>
- </Menu>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/WorkspaceRunButton/WorkspaceRunButton.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/WorkspaceRunButton/WorkspaceRunButton.tsx
deleted file mode 100644
index 002f71dd71e..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/WorkspaceRunButton/WorkspaceRunButton.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import { RunButton } from "metabase/transforms/components/RunButton";
-import type {
- TransformId,
- TransformJobId,
- TransformRun,
-} from "metabase-types/api";
-
-type WorkspaceRunButtonProps = {
- id: TransformId | TransformJobId | undefined;
- run: TransformRun | null | undefined;
- isDisabled?: boolean;
- allowCancellation?: boolean;
- onRun: () => void;
- onCancel?: () => void;
-};
-
-// A workspace-friendly wrapper that shows visual feedback during and after runs
-export function WorkspaceRunButton({ run, ...rest }: WorkspaceRunButtonProps) {
- // Pass through active/completed run states for visual feedback
- // - started/canceling: show in-progress state
- // - succeeded/failed: show completion state (controlled by parent)
- const activeRun =
- run?.status === "started" ||
- run?.status === "canceling" ||
- run?.status === "succeeded" ||
- run?.status === "failed"
- ? run
- : null;
-
- return <RunButton run={activeRun} size="sm" {...rest} />;
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/WorkspaceSection.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/WorkspaceSection.tsx
deleted file mode 100644
index 31b19f75733..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/components/WorkspaceSection.tsx
+++ /dev/null
@@ -1,389 +0,0 @@
-import { useDisclosure } from "@mantine/hooks";
-import cx from "classnames";
-import dayjs from "dayjs";
-import { useCallback, useMemo, useState } from "react";
-import { push } from "react-router-redux";
-import { t } from "ttag";
-
-import { ConfirmModal } from "metabase/common/components/ConfirmModal/ConfirmModal";
-import { ForwardRefLink } from "metabase/common/components/Link";
-import S from "metabase/data-studio/app/pages/DataStudioLayout/DataStudioLayout.module.css";
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import type { WorkspacesSectionProps } from "metabase/plugins/oss/database";
-import { getLocation } from "metabase/selectors/routing";
-import {
- ActionIcon,
- FixedSizeIcon,
- Flex,
- Group,
- Icon,
- type IconName,
- Loader,
- Menu,
- Skeleton,
- Stack,
- Text,
- Tooltip,
- UnstyledButton,
-} from "metabase/ui";
-import type { MetabaseColorKey } from "metabase/ui/colors/types";
-import { useDispatch, useSelector } from "metabase/utils/redux";
-import * as Urls from "metabase/utils/urls";
-import {
- useArchiveWorkspaceMutation,
- useCreateWorkspaceMutation,
- useDeleteWorkspaceMutation,
- useGetWorkspacesQuery,
- useUnarchiveWorkspaceMutation,
-} from "metabase-enterprise/api/workspace";
-import type {
- Workspace,
- WorkspaceId,
- WorkspaceItem as WorkspaceItemType,
-} from "metabase-types/api";
-
-const TOOLTIP_OPEN_DELAY = 700;
-
-export function WorkspacesSection({ showLabel }: WorkspacesSectionProps) {
- const dispatch = useDispatch();
- const [isWorkspacesExpanded, setIsWorkspacesExpanded] = useState(true);
- const { pathname } = useSelector(getLocation);
- const { data: workspacesData, isLoading: areWorkspacesLoading } =
- useGetWorkspacesQuery();
- const [createWorkspace, { isLoading: isCreatingWorkspace }] =
- useCreateWorkspaceMutation();
-
- const workspaces = useMemo(() => {
- return sortWorkspaceItems(workspacesData?.items ?? []);
- }, [workspacesData]);
-
- const { sendErrorToast, sendSuccessToast } = useMetadataToasts();
-
- const handleCreateWorkspace = useCallback(async () => {
- try {
- const workspace = await createWorkspace().unwrap();
- dispatch(push(Urls.dataStudioWorkspace(workspace.id)));
- } catch (error) {
- sendErrorToast(t`Failed to create workspace`);
- }
- }, [createWorkspace, dispatch, sendErrorToast]);
-
- const [archiveWorkspace] = useArchiveWorkspaceMutation();
- const [unarchiveWorkspace] = useUnarchiveWorkspaceMutation();
- const [deleteWorkspace] = useDeleteWorkspaceMutation();
-
- const handleWorkspaceArchive = async (id: WorkspaceId) => {
- try {
- await archiveWorkspace(id).unwrap();
- sendSuccessToast(t`Workspace archived successfully`);
- } catch (error) {
- sendErrorToast(t`Failed to archive workspace`);
- }
- };
-
- const handleWorkspaceUnarchive = async (id: WorkspaceId) => {
- try {
- await unarchiveWorkspace(id).unwrap();
- sendSuccessToast(t`Workspace restored successfully`);
- } catch (error) {
- sendErrorToast(t`Failed to restore workspace`);
- }
- };
-
- const handleWorkspaceDelete = async (id: WorkspaceId) => {
- try {
- await deleteWorkspace(id).unwrap();
- sendSuccessToast(t`Workspace deleted successfully`);
- dispatch(push(Urls.dataStudioWorkspaceList()));
- } catch (error) {
- sendErrorToast(t`Failed to delete workspace`);
- }
- };
-
- const isWorkspaceListPage = pathname === Urls.dataStudioWorkspaceList();
-
- if (!showLabel) {
- // In collapsed mode, show only an icon button with tooltip
- return (
- <Tooltip
- label={t`Workspaces`}
- position="right"
- openDelay={TOOLTIP_OPEN_DELAY}
- >
- <UnstyledButton
- className={cx(S.tab, { [S.selected]: isWorkspaceListPage })}
- component={ForwardRefLink}
- to={Urls.dataStudioWorkspaceList()}
- p="sm"
- bdrs="md"
- >
- <Flex align="center" justify="center" w="100%">
- <FixedSizeIcon
- name="git_branch"
- display="block"
- c="text-secondary"
- />
- </Flex>
- </UnstyledButton>
- </Tooltip>
- );
- }
-
- return (
- <Stack
- data-testid="workspaces-section"
- gap="0.5rem"
- className={S.workspacesSection}
- flex={1}
- mih={0}
- >
- <UnstyledButton
- className={cx(S.workspacesSectionHeader, {
- [S.selected]: isWorkspaceListPage,
- })}
- onClick={() => setIsWorkspacesExpanded(!isWorkspacesExpanded)}
- p="0.75rem"
- bdrs="md"
- >
- <Flex align="center" justify="space-between" w="100%">
- <Text size="sm" fw={600}>
- {t`Workspaces`}
- </Text>
- <Icon
- name={isWorkspacesExpanded ? "chevrondown" : "chevronright"}
- size={16}
- />
- </Flex>
- </UnstyledButton>
-
- {isWorkspacesExpanded && (
- <>
- <UnstyledButton
- className={S.newWorkspaceButton}
- onClick={handleCreateWorkspace}
- disabled={isCreatingWorkspace || areWorkspacesLoading}
- p="0.5rem"
- bdrs="md"
- >
- <Flex align="center" gap="xs">
- {isCreatingWorkspace ? (
- <Loader size="xs" />
- ) : (
- <Icon name="add" size={16} />
- )}
- <Text c="inherit" size="sm" fw={500}>
- {t`New workspace`}
- </Text>
- </Flex>
- </UnstyledButton>
- <Stack
- gap="0.75rem"
- style={{ flex: 1, overflowY: "auto", minHeight: 0 }}
- >
- {areWorkspacesLoading ? (
- <>
- <Skeleton height={80} radius="md" />
- <Skeleton height={80} radius="md" />
- </>
- ) : workspaces.length === 0 ? (
- <Text c="text-secondary" size="xs" px="0.5rem">
- {t`No workspaces yet`}
- </Text>
- ) : (
- workspaces.map((workspace) => {
- const isSelected =
- pathname === Urls.dataStudioWorkspace(workspace.id);
-
- return (
- <WorkspaceItem
- key={workspace.id}
- workspace={workspace}
- isSelected={isSelected}
- onArchive={handleWorkspaceArchive}
- onUnarchive={handleWorkspaceUnarchive}
- onDelete={handleWorkspaceDelete}
- />
- );
- })
- )}
- </Stack>
- </>
- )}
- </Stack>
- );
-}
-
-interface WorkspaceItemProps {
- workspace: Workspace;
- isSelected: boolean;
- onArchive: (workspaceId: WorkspaceId) => Promise<void>;
- onUnarchive: (workspaceId: WorkspaceId) => Promise<void>;
- onDelete: (workspaceId: WorkspaceId) => Promise<void>;
-}
-
-function sortWorkspaceItems(
- items: WorkspaceItemType[] | undefined,
-): WorkspaceItemType[] {
- const isArchived = (item: WorkspaceItemType) => item.status === "archived";
-
- return [...(items ?? [])].sort((a, b) => {
- // Archived workspaces should be placed at the end
- if (isArchived(a) !== isArchived(b)) {
- return isArchived(a) ? 1 : -1;
- }
-
- // Within each group (archived/unarchived), sort by updated_at descending
- const aDate = a.updated_at ? new Date(a.updated_at).getTime() : 0;
- const bDate = b.updated_at ? new Date(b.updated_at).getTime() : 0;
- return bDate - aDate;
- });
-}
-
-function WorkspaceItem({
- workspace,
- isSelected,
- onArchive,
- onUnarchive,
- onDelete,
-}: WorkspaceItemProps) {
- const [
- deleteModalOpened,
- { open: openDeleteModal, close: closeDeleteModal },
- ] = useDisclosure();
- const timeAgo = workspace.updated_at
- ? dayjs(workspace.updated_at).fromNow()
- : null;
-
- const handleArchive = () => {
- onArchive(workspace.id);
- };
-
- const handleUnarchive = () => {
- onUnarchive(workspace.id);
- };
-
- const handleDelete = () => {
- openDeleteModal();
- };
-
- const handleConfirmDelete = async () => {
- await onDelete(workspace.id);
- closeDeleteModal();
- };
-
- const status = getWorkspaceListStatus(workspace);
-
- return (
- <UnstyledButton
- className={cx(S.workspaceItem, { [S.selected]: isSelected })}
- component={ForwardRefLink}
- to={Urls.dataStudioWorkspace(workspace.id)}
- p="0.75rem"
- bdrs="md"
- name={workspace.name}
- >
- <Flex align="flex-start" justify="space-between" gap="xs">
- <Stack gap="xs" style={{ flex: 1, minWidth: 0 }}>
- <Text size="sm" fw={600} truncate>
- {workspace.name}
- </Text>
- {status && (
- <Group
- gap="xs"
- align="center"
- wrap="nowrap"
- data-testid="workspace-status"
- >
- <Icon name={status.icon} size={10} c={status.color} />
- <Text size="xs" fw={500} c={status.color}>
- {status.label}
- </Text>
- </Group>
- )}
- {timeAgo && (
- <Text size="xs" c="text-secondary" truncate>
- {t`Updated ${timeAgo}`}
- </Text>
- )}
- </Stack>
- <Menu position="right" withinPortal>
- <Menu.Target>
- <ActionIcon
- className={S.workspaceMenuButton}
- component="span"
- aria-label={t`More actions`}
- onClick={(e: React.MouseEvent) => {
- e.preventDefault();
- e.stopPropagation();
- }}
- size="sm"
- variant="subtle"
- >
- <Icon name="ellipsis" size={16} />
- </ActionIcon>
- </Menu.Target>
- <Menu.Dropdown
- onClick={(e: React.MouseEvent) => {
- e.preventDefault();
- e.stopPropagation();
- }}
- >
- {workspace.status === "archived" ? (
- <>
- <Menu.Item
- leftSection={<Icon name="revert" />}
- onClick={handleUnarchive}
- >
- {t`Restore`}
- </Menu.Item>
- <Menu.Divider />
- <Menu.Item
- c="error"
- leftSection={<Icon name="trash" />}
- onClick={handleDelete}
- color="danger"
- >
- {t`Delete`}
- </Menu.Item>
- </>
- ) : (
- <Menu.Item
- leftSection={<Icon name="archive" />}
- onClick={handleArchive}
- >
- {t`Archive`}
- </Menu.Item>
- )}
- </Menu.Dropdown>
- </Menu>
- </Flex>
-
- <ConfirmModal
- confirmButtonText={t`Delete`}
- message={t`This can't be undone.`}
- opened={deleteModalOpened}
- title={t`Delete ${workspace.name}?`}
- onClose={closeDeleteModal}
- onConfirm={handleConfirmDelete}
- />
- </UnstyledButton>
- );
-}
-
-type WorkspaceListStatus = {
- label: string;
- icon: IconName;
- color: MetabaseColorKey;
-};
-
-function getWorkspaceListStatus(workspace: Workspace): WorkspaceListStatus {
- if (workspace.status === "archived") {
- return { label: t`Archived`, icon: "archive", color: "text-tertiary" };
- }
-
- if (workspace.status === "pending") {
- return { label: t`Pending setup`, icon: "clock", color: "warning" };
- }
-
- return { label: t`Ready`, icon: "check", color: "success" };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/hooks/index.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/hooks/index.ts
deleted file mode 100644
index 90775b479df..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/hooks/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { useWorkspaceTransformRun } from "./use-workspace-transform-run";
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/hooks/use-workspace-transform-run.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/hooks/use-workspace-transform-run.ts
deleted file mode 100644
index bf516cb0de3..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/hooks/use-workspace-transform-run.ts
+++ /dev/null
@@ -1,204 +0,0 @@
-import { useCallback, useMemo, useState } from "react";
-import { t } from "ttag";
-
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import { useDispatch } from "metabase/utils/redux";
-import {
- useGetWorkspaceTransformQuery,
- useRunWorkspaceTransformMutation,
- workspaceApi,
-} from "metabase-enterprise/api";
-import type {
- TransformRun,
- WorkspaceId,
- WorkspaceTransform,
-} from "metabase-types/api";
-
-type UseWorkspaceTransformRunOptions = {
- workspaceId: WorkspaceId;
- transform: WorkspaceTransform | null;
-};
-
-type UseWorkspaceTransformRunResult = {
- /** Run object for RunStatus component - always shows last run info */
- statusRun: TransformRun | null;
- /** Run object for button - only shows feedback during/after user-triggered runs */
- buttonRun: TransformRun | null;
- /** Whether the run status is still loading */
- isRunStatusLoading: boolean;
- /** Whether a run is currently in progress */
- isRunning: boolean;
- /** Trigger a transform run */
- handleRun: () => Promise<void>;
-};
-
-type TransformRunState = {
- isRunTriggered: boolean;
- lastRunResult: {
- status: "succeeded" | "failed";
- end_time: string;
- message: string | null;
- } | null;
-};
-
-export function useWorkspaceTransformRun({
- workspaceId,
- transform,
-}: UseWorkspaceTransformRunOptions): UseWorkspaceTransformRunResult {
- const dispatch = useDispatch();
- const { sendErrorToast } = useMetadataToasts();
- const [runTransform] = useRunWorkspaceTransformMutation();
-
- // Store run state per transform ref_id to preserve state when switching tabs
- const [runStateByTransform, setRunStateByTransform] = useState<
- Map<string, TransformRunState>
- >(new Map());
-
- const transformRefId = transform?.ref_id ?? "";
- const currentRunState = runStateByTransform.get(transformRefId);
- const isRunTriggered = currentRunState?.isRunTriggered ?? false;
- const lastRunResult = currentRunState?.lastRunResult ?? null;
-
- const updateRunState = useCallback(
- (transformId: string, patch: Partial<TransformRunState>) => {
- setRunStateByTransform((prev) => {
- const current = prev.get(transformId);
- const newMap = new Map(prev);
- newMap.set(transformId, {
- isRunTriggered:
- patch.isRunTriggered ?? current?.isRunTriggered ?? false,
- lastRunResult: patch.lastRunResult ?? current?.lastRunResult ?? null,
- });
- return newMap;
- });
- },
- [],
- );
-
- // Fetch workspace transform to get updated last_run_at
- const { data: fetchedWorkspaceTransform, isFetching } =
- useGetWorkspaceTransformQuery(
- {
- workspaceId,
- transformId: transform?.ref_id ?? "",
- },
- { skip: !transform?.ref_id },
- );
-
- const lastRunAt =
- fetchedWorkspaceTransform?.last_run_at ?? transform?.last_run_at;
- const lastRunMessage =
- fetchedWorkspaceTransform?.last_run_message ?? transform?.last_run_message;
- const lastRunStatus =
- fetchedWorkspaceTransform?.last_run_status ?? transform?.last_run_status;
-
- const statusRun: TransformRun | null = useMemo(
- () =>
- lastRunResult
- ? {
- id: -1,
- status: lastRunResult.status,
- start_time: lastRunResult.end_time,
- end_time: lastRunResult.end_time,
- message: lastRunResult.message,
- run_method: "manual",
- }
- : lastRunAt && lastRunStatus != null
- ? {
- id: -1,
- status: lastRunStatus,
- start_time: lastRunAt,
- end_time: lastRunAt,
- message: lastRunMessage ?? null,
- run_method: "manual",
- }
- : null,
- [lastRunResult, lastRunAt, lastRunMessage, lastRunStatus],
- );
-
- // Run object for button - only shows feedback during/after user-triggered runs
- const buttonRun: TransformRun | null = useMemo(
- () =>
- isRunTriggered
- ? {
- id: -1,
- status: "started",
- start_time: new Date().toISOString(),
- end_time: null,
- message: null,
- run_method: "manual",
- }
- : lastRunResult
- ? {
- id: -1,
- status: lastRunResult.status,
- start_time: lastRunResult.end_time,
- end_time: lastRunResult.end_time,
- message: lastRunResult.message,
- run_method: "manual",
- }
- : null,
- [isRunTriggered, lastRunResult],
- );
-
- const handleRun = useCallback(async () => {
- if (!transformRefId) {
- return;
- }
-
- try {
- updateRunState(transformRefId, {
- isRunTriggered: true,
- lastRunResult: null,
- });
-
- const result = await runTransform({
- workspaceId,
- transformId: transformRefId,
- }).unwrap();
-
- // Transform completed - store the result
- const endTime = result.end_time ?? new Date().toISOString();
-
- updateRunState(transformRefId, {
- isRunTriggered: false,
- lastRunResult: {
- status: result.status,
- end_time: endTime,
- message: result.message ?? null,
- },
- });
-
- // Invalidate caches to refetch updated data
- dispatch(
- workspaceApi.util.invalidateTags([
- { type: "workspace", id: workspaceId },
- { type: "workspace-transform", id: transformRefId },
- { type: "workspace-tables", id: workspaceId },
- ]),
- );
-
- if (result.status === "failed") {
- sendErrorToast(t`Transform run failed`);
- }
- } catch (error) {
- updateRunState(transformRefId, { isRunTriggered: false });
- sendErrorToast(t`Failed to run transform`);
- }
- }, [
- updateRunState,
- runTransform,
- workspaceId,
- dispatch,
- transformRefId,
- sendErrorToast,
- ]);
-
- return {
- statusRun,
- buttonRun,
- isRunStatusLoading: statusRun == null && isFetching,
- isRunning: isRunTriggered,
- handleRun,
- };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/index.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/index.tsx
deleted file mode 100644
index 73d60aad0db..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/index.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { PLUGIN_WORKSPACES } from "metabase/plugins";
-import { hasPremiumFeature } from "metabase-enterprise/settings";
-
-import { AdminDatabaseWorkspacesSection } from "./admin/AdminDatabaseWorkspacesSection";
-import { EditTransformMenu } from "./components/EditTransformMenu";
-import { WorkspacesSection } from "./components/WorkspaceSection";
-import { getDataStudioWorkspaceRoutes } from "./routes";
-
-export function initializePlugin() {
- if (hasPremiumFeature("workspaces")) {
- PLUGIN_WORKSPACES.isEnabled = true;
- PLUGIN_WORKSPACES.AdminDatabaseWorkspacesSection =
- AdminDatabaseWorkspacesSection;
- PLUGIN_WORKSPACES.WorkspacesSection = WorkspacesSection;
- PLUGIN_WORKSPACES.getDataStudioWorkspaceRoutes =
- getDataStudioWorkspaceRoutes;
- PLUGIN_WORKSPACES.EditTransformMenu = EditTransformMenu;
- }
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspaceListPage/WorkspaceListPage.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspaceListPage/WorkspaceListPage.tsx
deleted file mode 100644
index dd6df4d78eb..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspaceListPage/WorkspaceListPage.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-import { useEffect, useMemo } from "react";
-import { replace } from "react-router-redux";
-import { t } from "ttag";
-
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { Box, Text, Title } from "metabase/ui";
-import { useDispatch } from "metabase/utils/redux";
-import * as Urls from "metabase/utils/urls";
-import { useGetWorkspacesQuery } from "metabase-enterprise/api";
-
-export function WorkspaceListPage() {
- const dispatch = useDispatch();
- const { data: workspacesData, error, isFetching } = useGetWorkspacesQuery();
-
- const workspaces = useMemo(
- () => workspacesData?.items ?? [],
- [workspacesData],
- );
-
- const firstWorkspaceId = workspaces[0]?.id;
-
- useEffect(() => {
- if (error || firstWorkspaceId == null) {
- return;
- }
-
- dispatch(replace(Urls.dataStudioWorkspace(firstWorkspaceId)));
- }, [dispatch, error, firstWorkspaceId]);
-
- if (error) {
- return <LoadingAndErrorWrapper error={error} loading={false} />;
- }
-
- if (firstWorkspaceId != null) {
- return null;
- }
-
- if (isFetching) {
- return <LoadingAndErrorWrapper error={error} loading={isFetching} />;
- }
-
- return (
- <Box data-testid="workspaces-page" p="lg">
- <Title size="lg">{t`No active workspaces`}</Title>
- <Text c="text-secondary">
- {t`Create a new one from the left panel or by editing an existing transform.`}
- </Text>
- </Box>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/AddTransformMenu.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/AddTransformMenu.tsx
deleted file mode 100644
index b486ed14ff6..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/AddTransformMenu.tsx
+++ /dev/null
@@ -1,73 +0,0 @@
-import { t } from "ttag";
-
-import {
- getInitialNativeSource,
- getInitialPythonSource,
-} from "metabase/transforms/pages/NewTransformPage/utils";
-import { ActionIcon, Icon, Menu, Tooltip } from "metabase/ui";
-import type { DatabaseId, TransformSource } from "metabase-types/api";
-
-import { useWorkspace } from "./WorkspaceProvider";
-
-type TransformType = "sql" | "python";
-
-interface Props {
- databaseId: DatabaseId;
- disabled?: boolean;
-}
-
-export const AddTransformMenu = ({ databaseId, disabled }: Props) => {
- const { addUnsavedTransform } = useWorkspace();
-
- const getSource = (type: TransformType): TransformSource => {
- if (type === "sql") {
- const source = getInitialNativeSource();
- return {
- ...source,
- query: { ...source.query, database: databaseId },
- };
- }
- return {
- ...getInitialPythonSource(),
- "source-database": databaseId,
- };
- };
-
- return (
- <>
- <Menu position="bottom-end">
- <Menu.Target>
- <Tooltip label={t`Add transform`}>
- <ActionIcon
- size="2rem"
- p="0"
- ml="auto"
- aria-label={t`Add transform`}
- disabled={disabled}
- >
- <Icon name="add" size={16} aria-hidden />
- </ActionIcon>
- </Tooltip>
- </Menu.Target>
- <Menu.Dropdown>
- <Menu.Item
- leftSection={<Icon name="sql" />}
- onClick={() => {
- addUnsavedTransform(getSource("sql"));
- }}
- >
- {t`SQL Transform`}
- </Menu.Item>
- <Menu.Item
- leftSection={<Icon name="code_block" />}
- onClick={() => {
- addUnsavedTransform(getSource("python"));
- }}
- >
- {t`Python Script`}
- </Menu.Item>
- </Menu.Dropdown>
- </Menu>
- </>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/CodeTab.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/CodeTab.tsx
deleted file mode 100644
index 925e5def2f7..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/CodeTab.tsx
+++ /dev/null
@@ -1,206 +0,0 @@
-import { useCallback } from "react";
-import { t } from "ttag";
-
-import { skipToken } from "metabase/api";
-import { EmptyState } from "metabase/common/components/EmptyState";
-import { Flex, Skeleton, Stack, Text } from "metabase/ui";
-import { useGetExternalTransformsQuery } from "metabase-enterprise/api";
-import { getCheckoutDisabledMessage } from "metabase-enterprise/data-studio/workspaces/utils";
-import type {
- DatabaseId,
- ExternalTransform,
- UnsavedTransform,
- WorkspaceId,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-import { isUnsavedTransform } from "metabase-types/api";
-
-import {
- type AnyWorkspaceTransformRef,
- useWorkspace,
-} from "../WorkspaceProvider";
-
-import { TransformListItem } from "./TransformListItem";
-import { TransformListItemMenu } from "./TransformListItemMenu";
-
-/** Item that can be displayed in the workspace transforms list */
-type WorkspaceTransformItem = UnsavedTransform | WorkspaceTransformListItem;
-
-function getWorkspaceTransformItemId(
- item: WorkspaceTransformItem,
-): string | number {
- if (isUnsavedTransform(item)) {
- return item.id;
- }
- return item.ref_id;
-}
-
-type CodeTabProps = {
- activeTransformId?: number | string;
- databaseId: DatabaseId | null | undefined;
- workspaceId: WorkspaceId;
- workspaceTransforms: WorkspaceTransformItem[];
- isLoadingWorkspaceTransforms?: boolean;
- readOnly: boolean;
- onTransformClick: (transformRef: AnyWorkspaceTransformRef) => void;
-};
-
-export const CodeTab = ({
- activeTransformId,
- databaseId,
- workspaceId,
- workspaceTransforms,
- isLoadingWorkspaceTransforms,
- readOnly,
- onTransformClick,
-}: CodeTabProps) => {
- const { editedTransforms } = useWorkspace();
-
- const {
- data: availableTransforms,
- error,
- isLoading,
- } = useGetExternalTransformsQuery(
- databaseId ? { workspaceId, databaseId } : skipToken,
- );
-
- const handleExternalTransformClick = useCallback(
- async (externalTransform: ExternalTransform) => {
- if (externalTransform.checkout_disabled) {
- return;
- }
-
- onTransformClick({
- type: "transform",
- id: externalTransform.id,
- name: externalTransform.name,
- });
- },
- [onTransformClick],
- );
-
- const handleWorkspaceTransformItemClick = useCallback(
- async (item: WorkspaceTransformItem) => {
- if (isUnsavedTransform(item)) {
- onTransformClick({
- type: "unsaved-transform",
- id: item.id,
- name: item.name,
- });
- } else {
- onTransformClick({
- type: "workspace-transform",
- ref_id: item.ref_id,
- name: item.name,
- });
- }
- },
- [onTransformClick],
- );
-
- return (
- <Stack h="100%" gap={0}>
- <Stack
- data-testid="workspace-transforms"
- gap="xs"
- pb="sm"
- style={{
- borderBottom: "1px solid var(--mb-color-border)",
- }}
- >
- <Stack gap={0}>
- <Text fw={600}>{t`Workspace transforms`}</Text>
- {isLoadingWorkspaceTransforms ? (
- <LoadingSkeleton />
- ) : (
- workspaceTransforms.map((item) => {
- const itemId = getWorkspaceTransformItemId(item);
- const isUnsaved = isUnsavedTransform(item);
- const globalId = isUnsaved ? null : item.global_id;
- const isEdited = isUnsaved || editedTransforms.has(itemId);
- const isActive =
- activeTransformId === itemId || activeTransformId === globalId;
-
- return (
- <TransformListItem
- key={itemId}
- name={item.name}
- icon="pivot_table"
- fw={600}
- isActive={isActive}
- isEdited={isEdited}
- menu={
- readOnly ? null : (
- <TransformListItemMenu
- transform={item}
- workspaceId={workspaceId}
- />
- )
- }
- onClick={() => {
- handleWorkspaceTransformItemClick(item);
- }}
- />
- );
- })
- )}
- </Stack>
-
- {!isLoadingWorkspaceTransforms && workspaceTransforms.length === 0 && (
- <EmptyState message={t`Workspace is empty`} />
- )}
- </Stack>
-
- <Stack data-testid="mainland-transforms" py="sm" gap="xs">
- <Text fw={600} mt="sm">{t`Available transforms`}</Text>
-
- {isLoading ? (
- <LoadingSkeleton />
- ) : error ? (
- <Text c="error" size="sm">{t`Failed to load transforms`}</Text>
- ) : (
- <>
- {availableTransforms?.map((transform) => (
- <TransformListItem
- key={transform.id}
- name={transform.name}
- isActive={activeTransformId === transform.id}
- isEdited={editedTransforms.has(transform.id)}
- onClick={() => {
- handleExternalTransformClick(transform);
- }}
- opacity={transform.checkout_disabled ? 0.5 : 1}
- tooltipLabel={getCheckoutDisabledMessage(
- transform.checkout_disabled,
- )}
- />
- ))}
-
- {availableTransforms?.length === 0 && (
- <EmptyState message={t`No available transforms`} />
- )}
- </>
- )}
- </Stack>
- </Stack>
- );
-};
-
-function LoadingSkeleton() {
- return (
- <Stack data-testid="loading-indicator" gap="md" py="sm">
- <TransformListItemSkeleton />
- <TransformListItemSkeleton />
- <TransformListItemSkeleton />
- </Stack>
- );
-}
-
-function TransformListItemSkeleton() {
- return (
- <Flex align="center" gap="sm" px="md">
- <Skeleton h={14} w={14} circle />
- <Skeleton h={14} w="70%" />
- </Flex>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/TransformListItem.module.css b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/TransformListItem.module.css
deleted file mode 100644
index 67007100e69..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/TransformListItem.module.css
+++ /dev/null
@@ -1,33 +0,0 @@
-.root {
- display: flex;
- align-items: center;
- gap: var(--mantine-spacing-sm);
- padding: var(--mantine-spacing-xs) var(--mantine-spacing-sm);
- border-radius: var(--mantine-radius-sm);
- cursor: default;
- flex-wrap: nowrap;
-
- &:hover .menu {
- visibility: visible;
- }
-
- &:hover {
- background-color: var(--mb-color-background-secondary);
- }
-}
-
-.label {
- display: flex;
- align-items: center;
- gap: var(--mantine-spacing-sm);
- flex: 1;
- min-width: 0;
-}
-
-.cursorPointer {
- cursor: pointer;
-}
-
-.menu {
- visibility: hidden;
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/TransformListItem.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/TransformListItem.tsx
deleted file mode 100644
index 0ff519d6032..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/TransformListItem.tsx
+++ /dev/null
@@ -1,69 +0,0 @@
-import cx from "classnames";
-import type { ReactNode } from "react";
-import { t } from "ttag";
-
-import {
- Box,
- type BoxProps,
- Icon,
- type IconName,
- Text,
- Tooltip,
-} from "metabase/ui";
-
-import { StatusDot } from "../components/StatusDot/StatusDot";
-
-import S from "./TransformListItem.module.css";
-
-type TransformListItemProps = {
- name: string;
- icon?: IconName;
- isActive?: boolean;
- isEdited?: boolean;
- tooltipLabel?: string;
- menu?: ReactNode;
- onClick?: () => void;
-} & BoxProps;
-
-export const TransformListItem = ({
- name,
- icon = "database",
- isActive,
- isEdited,
- tooltipLabel,
- menu,
- onClick,
- ...props
-}: TransformListItemProps) => {
- const label = (
- <Box className={cx(S.label, { [S.cursorPointer]: !tooltipLabel })}>
- <Icon name={icon} size={14} c="brand" />
- <Text c={isActive ? "brand" : "text-primary"} truncate>
- {name}
- </Text>
- {isEdited && (
- <Tooltip label={t`Unsaved changes`}>
- <Box>
- <StatusDot data-testid="status-dot" />
- </Box>
- </Tooltip>
- )}
- </Box>
- );
-
- return (
- <Box className={S.root} onClick={onClick} pl="sm" {...props}>
- {tooltipLabel ? (
- <Tooltip label={tooltipLabel} position="top">
- {label}
- </Tooltip>
- ) : (
- label
- )}
-
- <Box className={S.menu} flex="0 0 auto">
- {menu}
- </Box>
- </Box>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/TransformListItemMenu.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/TransformListItemMenu.tsx
deleted file mode 100644
index 3a7b16d02f8..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/CodeTab/TransformListItemMenu.tsx
+++ /dev/null
@@ -1,75 +0,0 @@
-import { t } from "ttag";
-
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import { ActionIcon, Icon, Menu } from "metabase/ui";
-import { useDeleteWorkspaceTransformMutation } from "metabase-enterprise/api";
-import type {
- UnsavedTransform,
- WorkspaceId,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-import { isUnsavedTransform } from "metabase-types/api";
-
-import { useWorkspace } from "../WorkspaceProvider";
-
-/** Item that can be displayed in the workspace transforms list */
-type WorkspaceTransformItem = UnsavedTransform | WorkspaceTransformListItem;
-
-interface Props {
- transform: WorkspaceTransformItem;
- workspaceId: WorkspaceId;
-}
-
-export function TransformListItemMenu({ transform, workspaceId }: Props) {
- const [deleteWorkspaceTransform] = useDeleteWorkspaceTransformMutation();
-
- const {
- removeEditedTransform,
- removeWorkspaceTransform,
- removeUnsavedTransform,
- } = useWorkspace();
- const { sendErrorToast, sendSuccessToast } = useMetadataToasts();
-
- const handleRemove = async () => {
- // Handle unsaved transforms locally
- if (isUnsavedTransform(transform)) {
- removeUnsavedTransform(transform.id);
- return;
- }
-
- // For WorkspaceTransformListItem, use ref_id
- try {
- await deleteWorkspaceTransform({
- workspaceId,
- transformId: transform.ref_id,
- }).unwrap();
-
- sendSuccessToast(t`Transform removed from the workspace`);
- removeEditedTransform(transform.ref_id);
- removeWorkspaceTransform(transform.ref_id);
- } catch (error) {
- sendErrorToast(t`Failed to remove transform from the workspace`);
- }
- };
-
- return (
- <Menu position="bottom-end" withinPortal>
- <Menu.Target>
- <ActionIcon
- onClick={(event) => event.stopPropagation()}
- size="sm"
- variant="subtle"
- aria-label={t`More actions`}
- >
- <Icon name="ellipsis" />
- </ActionIcon>
- </Menu.Target>
-
- <Menu.Dropdown onClick={(event) => event.stopPropagation()}>
- <Menu.Item leftSection={<Icon name="trash" />} onClick={handleRemove}>
- {t`Remove`}
- </Menu.Item>
- </Menu.Dropdown>
- </Menu>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/DataTab.module.css b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/DataTab.module.css
deleted file mode 100644
index 749525de8ab..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/DataTab.module.css
+++ /dev/null
@@ -1,16 +0,0 @@
-.tabsPanel {
- display: flex;
- gap: 0.5rem;
- flex-wrap: nowrap;
- overflow: auto;
- scrollbar-width: thin;
- border-bottom: 1px solid var(--mb-color-border);
-
- &::before {
- display: none;
- }
-
- & button {
- border-radius: 0;
- }
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/DataTab.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/DataTab.tsx
deleted file mode 100644
index 9b18a684129..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/DataTab.tsx
+++ /dev/null
@@ -1,191 +0,0 @@
-import { useMemo, useState } from "react";
-import { t } from "ttag";
-
-import { createMockMetadata } from "__support__/metadata";
-import { skipToken, useGetTableQuery } from "metabase/api";
-import { AnsiLogs } from "metabase/common/components/AnsiLogs";
-import { EmptyState } from "metabase/common/components/EmptyState";
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import CS from "metabase/css/core/index.css";
-import { Box, Group, Icon, Stack, Tabs } from "metabase/ui";
-import Visualization from "metabase/visualizations/components/Visualization";
-import { useGetWorkspaceTransformQuery } from "metabase-enterprise/api";
-import { ExecutionOutputTable } from "metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/ExecutionOutputTable";
-import type {
- DatabaseId,
- DatasetQuery,
- TableId,
- TestPythonTransformResponse,
-} from "metabase-types/api";
-
-import S from "./DataTab.module.css";
-import { useTablePreview } from "./useTablePreview";
-import { useTransformDryRunPreview } from "./useTransformDryRunPreview";
-
-interface DataTabProps {
- workspaceId: number;
- databaseId: DatabaseId | null;
- tableId: TableId | null;
- transformId?: string;
- query?: DatasetQuery;
- pythonPreviewResult?: any;
-}
-
-export function DataTab({
- workspaceId,
- databaseId,
- tableId,
- transformId,
- query,
- pythonPreviewResult,
-}: DataTabProps) {
- const {
- data: table,
- error: tableError,
- isLoading: tableIsLoading,
- } = useGetTableQuery(tableId && !query ? { id: tableId } : skipToken);
- const { data: transform } = useGetWorkspaceTransformQuery(
- transformId ? { workspaceId, transformId } : skipToken,
- );
-
- // Use existing table preview logic when no query
- const metadata = useMemo(
- () =>
- createMockMetadata({
- tables: table
- ? [
- {
- ...table,
- visibility_type: null,
- },
- ]
- : [],
- }),
- [table],
- );
-
- // we want to use /dataset for table preview
- const shouldUseDryRunPreview = Boolean(query && transformId && workspaceId);
- const tablePreviewResult = useTablePreview({
- databaseId,
- tableId: shouldUseDryRunPreview ? null : tableId,
- metadata,
- last_transform_run_time: transform?.last_run_at,
- query: shouldUseDryRunPreview ? undefined : query,
- });
- const dryRunPreviewResult = useTransformDryRunPreview({
- workspaceId,
- transformId: shouldUseDryRunPreview ? transformId : undefined,
- query: shouldUseDryRunPreview ? query : undefined,
- });
- const previewResult = shouldUseDryRunPreview
- ? dryRunPreviewResult
- : tablePreviewResult;
- const { rawSeries, isFetching, error: previewResultError } = previewResult;
-
- const error = tableError || previewResultError;
- const isLoading = tableIsLoading || isFetching;
-
- if (pythonPreviewResult) {
- return <PythonPreviewResults executionResult={pythonPreviewResult} />;
- }
-
- if (isLoading) {
- return <LoadingAndErrorWrapper loading={isLoading} />;
- }
-
- if (error) {
- const errorMessage =
- typeof error === "string" ? error : t`An error occurred`;
- return <ErrorState error={errorMessage} title={t`Error loading data`} />;
- }
-
- if (!databaseId || (!tableId && !query)) {
- return (
- <Stack p="md">
- <EmptyState message={t`Select a table to view its data`} />
- </Stack>
- );
- }
-
- if (!rawSeries) {
- return (
- <Stack p="md">
- <EmptyState message={t`No data available`} />
- </Stack>
- );
- }
-
- return (
- <Box h="100%" className={CS.relative}>
- <Visualization queryBuilderMode="dataset" rawSeries={rawSeries} />
- </Box>
- );
-}
-
-function PythonPreviewResults({
- executionResult,
-}: {
- executionResult: TestPythonTransformResponse;
-}) {
- const [tab, setTab] = useState<string>("results");
-
- return (
- <Stack gap={0} h="100%">
- <Tabs
- h="100%"
- value={tab}
- onChange={(newTab) => {
- if (newTab) {
- setTab(newTab);
- }
- }}
- >
- <Tabs.List className={S.tabsPanel} px="md">
- <Tabs.Tab value="results">{t`Results`}</Tabs.Tab>
- <Tabs.Tab value="output">{t`Output`}</Tabs.Tab>
- </Tabs.List>
-
- <Tabs.Panel h="100%" p="md" value="results">
- {executionResult?.error ? (
- <ErrorState error={executionResult.error.message} />
- ) : (
- <Box h="100%" style={{ overflow: "auto" }}>
- <ExecutionOutputTable output={executionResult?.output} />
- </Box>
- )}
- </Tabs.Panel>
-
- <Tabs.Panel bg="background-secondary" h="100%" p="md" value="output">
- <Box
- fz="sm"
- h="100%"
- style={{
- whiteSpace: "pre",
- fontFamily: "var(--mb-default-monospace-font-family)",
- overflow: "auto",
- }}
- >
- {executionResult?.logs ? (
- <AnsiLogs>{executionResult.logs}</AnsiLogs>
- ) : (
- <EmptyState message={t`No logs to display`} />
- )}
- </Box>
- </Tabs.Panel>
- </Tabs>
- </Stack>
- );
-}
-
-function ErrorState({ error, title }: { error: string; title?: string }) {
- return (
- <Stack gap="sm" h="100%" p="md" c="error">
- <Group fw="bold" gap="sm">
- <Icon name="warning" />
- {title ?? t`Error`}
- </Group>
- <Box fz="sm">{error}</Box>
- </Stack>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/DataTabSidebar.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/DataTabSidebar.tsx
deleted file mode 100644
index 674f1148017..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/DataTabSidebar.tsx
+++ /dev/null
@@ -1,202 +0,0 @@
-import { useMemo } from "react";
-import { t } from "ttag";
-
-import { useListTransformsQuery } from "metabase/api";
-import { EmptyState } from "metabase/common/components/EmptyState";
-import { Stack, Text } from "metabase/ui";
-import {
- DEFAULT_WORKSPACE_TABLES_QUERY_RESPONSE,
- useGetWorkspaceTablesQuery,
-} from "metabase-enterprise/api";
-import type {
- DatabaseId,
- TableId,
- WorkspaceId,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-
-import { type OpenTable, useWorkspace } from "../WorkspaceProvider";
-
-import { TableListItem, TableListItemSkeleton } from "./TableListItem";
-
-type DataTabSidebarProps = {
- databaseId?: DatabaseId | null;
- readOnly?: boolean;
- runningTransforms?: Set<string>;
- selectedTableId?: TableId | null;
- workspaceId: WorkspaceId;
- workspaceTransforms: WorkspaceTransformListItem[];
- onTransformClick?: (transform: WorkspaceTransformListItem) => void;
- onTableSelect?: (table: OpenTable) => void;
- onRunTransform?: (transform: WorkspaceTransformListItem) => void;
-};
-
-export const DataTabSidebar = ({
- databaseId,
- readOnly,
- runningTransforms,
- selectedTableId,
- workspaceId,
- workspaceTransforms,
- onTransformClick,
- onTableSelect,
- onRunTransform,
-}: DataTabSidebarProps) => {
- const { hasTransformEdits } = useWorkspace();
- const {
- data: tables = DEFAULT_WORKSPACE_TABLES_QUERY_RESPONSE,
- error: tablesError,
- isLoading: isLoadingTables,
- } = useGetWorkspaceTablesQuery(workspaceId);
- const {
- data: allDbTransforms = [],
- error: allDbTransformsError,
- isLoading: isLoadingAllDbTransforms,
- } = useListTransformsQuery({});
-
- const dbTransforms = useMemo(
- () =>
- allDbTransforms.filter((t) => {
- if (t.source_type === "python") {
- return (
- "source-database" in t.source &&
- t.source["source-database"] === databaseId
- );
- }
- if (t.source_type === "native") {
- return "query" in t.source && t.source.query.database === databaseId;
- }
- return false;
- }),
- [allDbTransforms, databaseId],
- );
-
- const error = tablesError || allDbTransformsError;
- const isLoading = isLoadingTables || isLoadingAllDbTransforms;
-
- if (error) {
- return <Text c="error" size="sm">{t`Failed to load tables`}</Text>;
- }
-
- return (
- <Stack h="100%" gap="sm">
- <Stack gap="sm" pb="sm">
- <Text fw={600}>{t`Data active in this workspace`}</Text>
-
- {isLoading ? (
- <>
- <Stack gap="xs">
- <Text
- size="sm"
- fw={600}
- c="text-secondary"
- >{t`Output tables`}</Text>
- <Stack gap={0}>
- <TableListItemSkeleton />
- <TableListItemSkeleton />
- </Stack>
- </Stack>
- <Stack gap="xs">
- <Text
- size="sm"
- fw={600}
- c="text-secondary"
- >{t`Input tables`}</Text>
- <Stack gap={0}>
- <TableListItemSkeleton />
- <TableListItemSkeleton />
- </Stack>
- </Stack>
- </>
- ) : (
- <>
- {tables.outputs.length + tables.inputs.length === 0 && (
- <EmptyState message={t`No tables in this workspace`} />
- )}
-
- {tables.outputs.length > 0 && (
- <Stack gap="xs">
- <Text
- size="sm"
- fw={600}
- c="text-secondary"
- >{t`Output tables`}</Text>
-
- <Stack gap={0}>
- {tables.outputs.map((table, index: number) => {
- const workspaceTransform = workspaceTransforms.find(
- (t) => t.ref_id === table.isolated.transform_id,
- );
- const originalTransform = workspaceTransform?.global_id
- ? dbTransforms.find(
- (t) => t.id === workspaceTransform.global_id,
- )
- : undefined;
- const hasChanges = originalTransform
- ? hasTransformEdits({
- ...originalTransform,
- type: "transform",
- })
- : false;
- const tableId = table.isolated.table_id;
-
- return (
- <TableListItem
- key={`output-${index}`}
- name={table.global.table}
- schema={table.global.schema}
- icon="pivot_table"
- type="output"
- hasChanges={hasChanges}
- transform={workspaceTransform}
- tableId={tableId ?? undefined}
- tableActive={table.isolated.active ?? false}
- isSelected={tableId === selectedTableId}
- isRunning={
- workspaceTransform
- ? runningTransforms?.has(workspaceTransform.ref_id)
- : false
- }
- onTransformClick={onTransformClick}
- onTableClick={onTableSelect}
- onRunTransform={onRunTransform}
- readOnly={readOnly}
- />
- );
- })}
- </Stack>
- </Stack>
- )}
-
- {tables.inputs.length > 0 && (
- <Stack gap="xs">
- <Text
- size="sm"
- fw={600}
- c="text-secondary"
- >{t`Input tables`}</Text>
-
- <Stack gap={0}>
- {tables.inputs.map((table, index) => (
- <TableListItem
- key={`input-${index}`}
- name={table.table}
- schema={table.schema}
- icon="table"
- type="input"
- isSelected={table.table_id === selectedTableId}
- tableId={table.table_id ?? undefined}
- onTransformClick={onTransformClick}
- onTableClick={onTableSelect}
- readOnly={readOnly}
- />
- ))}
- </Stack>
- </Stack>
- )}
- </>
- )}
- </Stack>
- </Stack>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/TableListItem.module.css b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/TableListItem.module.css
deleted file mode 100644
index 4135c2af98b..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/TableListItem.module.css
+++ /dev/null
@@ -1,39 +0,0 @@
-.root {
- display: flex;
- align-items: center;
- gap: var(--mantine-spacing-sm);
- padding: var(--mantine-spacing-xs) var(--mantine-spacing-sm);
- border-radius: var(--mantine-radius-sm);
- flex-wrap: nowrap;
-
- &:hover .menu {
- visibility: visible;
- }
-
- &:hover {
- background-color: var(--mb-color-background-secondary);
- }
-
- &.noResults .name {
- opacity: 0.6;
- }
-}
-
-.clickable {
- cursor: pointer;
-}
-
-.selected {
- background-color: var(--mb-color-background-tertiary);
-}
-
-.name {
- flex: 1;
- min-width: 0;
-}
-
-.actionIcon {
- &:hover {
- background-color: var(--mb-color-background-tertiary) !important;
- }
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/TableListItem.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/TableListItem.tsx
deleted file mode 100644
index 284778e20f3..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/TableListItem.tsx
+++ /dev/null
@@ -1,152 +0,0 @@
-import cx from "classnames";
-import { t } from "ttag";
-
-import {
- ActionIcon,
- Box,
- Flex,
- Icon,
- type IconName,
- Loader,
- Skeleton,
- Text,
- Tooltip,
-} from "metabase/ui";
-import type { TableId, WorkspaceTransformListItem } from "metabase-types/api";
-
-import type { OpenTable } from "../WorkspaceProvider";
-import { StatusDot } from "../components/StatusDot/StatusDot";
-
-import S from "./TableListItem.module.css";
-
-type TableListItemProps = {
- name: string;
- schema?: string | null;
- icon?: IconName;
- type: "input" | "output";
- hasChanges?: boolean;
- transform?: WorkspaceTransformListItem;
- tableId?: TableId;
- tableActive?: boolean;
- isSelected?: boolean;
- isRunning?: boolean;
- readOnly?: boolean;
- onTransformClick?: (transform: WorkspaceTransformListItem) => void;
- onTableClick?: (table: OpenTable) => void;
- onRunTransform?: (transform: WorkspaceTransformListItem) => void;
-};
-
-export const TableListItem = ({
- name,
- schema,
- icon = "table",
- type,
- hasChanges = false,
- transform,
- tableId,
- tableActive = false,
- isSelected = false,
- isRunning = false,
- readOnly = false,
- onTransformClick,
- onTableClick,
- onRunTransform,
-}: TableListItemProps) => {
- const displayName = schema ? `${schema}.${name}` : name;
-
- const handleTransformClick = (e: React.MouseEvent) => {
- e.stopPropagation();
- if (transform && onTransformClick) {
- onTransformClick(transform);
- }
- };
-
- const tableExists = !!tableId && (type !== "output" || tableActive);
-
- const handleTableClick = () => {
- if (isRunning) {
- return;
- }
- if (tableExists && tableId && onTableClick) {
- onTableClick({ tableId, name, schema, transformId: transform?.ref_id });
- } else if (type === "output" && transform && onRunTransform && !readOnly) {
- onRunTransform(transform);
- }
- };
-
- const canRunTransform =
- type === "output" && !tableExists && transform && onRunTransform;
- const isClickable = (tableExists && onTableClick) || canRunTransform;
- const displayTooltip = type !== "input" && !tableExists && !isRunning;
-
- return (
- <Box
- className={cx(S.root, {
- [S.selected]: isSelected,
- [S.clickable]: isClickable,
- [S.noResults]: type === "output" && !tableExists,
- })}
- aria-label={displayName}
- onClick={isClickable ? handleTableClick : undefined}
- >
- {isRunning ? (
- <Loader size="xs" />
- ) : (
- <Icon
- name={icon}
- size={14}
- c={type === "input" ? "saturated-green" : "saturated-yellow"}
- />
- )}
- <Tooltip
- label={
- isRunning
- ? t`Running transform...`
- : t`Run transform to see the results`
- }
- position="top"
- disabled={!displayTooltip && !isRunning}
- >
- <Text
- className={S.name}
- c={displayTooltip ? "text-tertiary" : "text-primary"}
- truncate
- >
- {displayName}
- </Text>
- </Tooltip>
-
- {hasChanges && (
- <Tooltip label={t`Unsaved changes`}>
- <Box>
- <StatusDot />
- </Box>
- </Tooltip>
- )}
-
- {type === "output" && transform && (
- <Tooltip label={t`Open transform`} position="top">
- <ActionIcon
- className={S.actionIcon}
- ml="auto"
- size="sm"
- variant="subtle"
- onClick={handleTransformClick}
- aria-label={t`Open transform`}
- >
- <Icon name="code_block" size={14} c="text-secondary" />
- </ActionIcon>
- </Tooltip>
- )}
- </Box>
- );
-};
-
-export function TableListItemSkeleton() {
- return (
- <Flex align="center" gap="sm" py="xs" px="sm" h="2rem">
- <Skeleton h={14} w={14} circle />
- <Skeleton h={14} w="70%" />
- </Flex>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/index.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/index.ts
deleted file mode 100644
index d69bef75d88..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export { DataTab } from "./DataTab";
-export { DataTabSidebar } from "./DataTabSidebar";
-export type { OpenTable } from "../WorkspaceProvider";
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/useTablePreview.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/useTablePreview.ts
deleted file mode 100644
index 5bda3a1edb6..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/useTablePreview.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-import { useMemo } from "react";
-import _ from "underscore";
-
-import { skipToken, useGetAdhocQueryQuery } from "metabase/api";
-import { getErrorMessage } from "metabase/api/utils";
-import * as Lib from "metabase-lib";
-import type Metadata from "metabase-lib/v1/metadata/Metadata";
-import type {
- DatabaseId,
- DatasetQuery,
- RawSeries,
- TableId,
-} from "metabase-types/api";
-import { createMockCard } from "metabase-types/api/mocks";
-
-interface UseTableQuestionProps {
- databaseId: DatabaseId | null;
- tableId: TableId | null;
- metadata: Metadata;
- last_transform_run_time?: string | null;
- query?: DatasetQuery;
-}
-
-interface UseTablePreviewResult {
- rawSeries?: RawSeries;
- isFetching: boolean;
- isLoading: boolean;
- isError: boolean;
- error?: string;
-}
-
-export function useTablePreview({
- databaseId,
- tableId,
- metadata,
- last_transform_run_time,
- query,
-}: UseTableQuestionProps): UseTablePreviewResult {
- const metadataProvider =
- Object.keys(metadata.tables).length > 0
- ? Lib.metadataProvider(databaseId, metadata)
- : null;
-
- const table =
- metadataProvider && tableId
- ? Lib.tableOrCardMetadata(metadataProvider, tableId)
- : null;
-
- const tableBasedQuery =
- table && metadataProvider
- ? Lib.queryFromTableOrCardMetadata(metadataProvider, table)
- : null;
- const queryToFetch = query || tableBasedQuery;
-
- const { data, ...rest } = useGetAdhocQueryQuery(
- queryToFetch == null
- ? skipToken
- : query
- ? {
- ...query,
- ignore_error: true,
- _refetchDeps: last_transform_run_time,
- }
- : tableBasedQuery
- ? {
- ...Lib.toJsQuery(tableBasedQuery),
- ignore_error: true,
- _refetchDeps: last_transform_run_time,
- }
- : skipToken,
- );
-
- const base = {
- ...rest,
- error: rest.error ? getErrorMessage(rest.error) : undefined,
- rawSeries: undefined,
- };
-
- const rawSeries = useMemo<RawSeries>(
- () =>
- queryToFetch != null && data
- ? [
- {
- card: createMockCard({
- display: "table",
- visualization_settings: {},
- }),
- data: {
- ...data.data,
- rows: _.uniq(data.data.rows ?? []),
- },
- },
- ]
- : [],
- [data, queryToFetch],
- );
-
- if (data?.status === "failed") {
- return { ...base, isError: true, error: getErrorMessage(data) };
- }
-
- if (queryToFetch == null || !data?.data || data.data.cols.length === 0) {
- return base;
- }
-
- return { ...base, rawSeries };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/useTransformDryRunPreview.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/useTransformDryRunPreview.ts
deleted file mode 100644
index 9562cbc4be1..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/DataTab/useTransformDryRunPreview.ts
+++ /dev/null
@@ -1,130 +0,0 @@
-import { useEffect, useMemo, useRef } from "react";
-import _ from "underscore";
-
-import { getErrorMessage } from "metabase/api/utils";
-import { useDryRunWorkspaceTransformMutation } from "metabase-enterprise/api";
-import type {
- DatasetColumn,
- DatasetQuery,
- RawSeries,
- WorkspaceId,
-} from "metabase-types/api";
-import {
- createMockCard,
- createMockDatasetData,
-} from "metabase-types/api/mocks";
-
-interface UseTransformDryRunPreviewOptions {
- workspaceId?: WorkspaceId;
- transformId?: string;
- query?: DatasetQuery;
-}
-
-interface UseTransformDryRunPreviewResult {
- rawSeries?: RawSeries;
- isFetching: boolean;
- isLoading: boolean;
- isError: boolean;
- error?: string;
-}
-
-export function useTransformDryRunPreview({
- workspaceId,
- transformId,
- query,
-}: UseTransformDryRunPreviewOptions): UseTransformDryRunPreviewResult {
- const [dryRunTransform, { data, error, isLoading }] =
- useDryRunWorkspaceTransformMutation();
- const abortRef = useRef<(() => void) | null>(null);
-
- // Track whether we should fetch based on having a query
- // We use a boolean to avoid re-fetching when query object reference changes
- const hasQuery = Boolean(query);
-
- useEffect(() => {
- if (!workspaceId || !transformId || !hasQuery) {
- return;
- }
-
- abortRef.current?.();
-
- const request = dryRunTransform({ workspaceId, transformId });
- abortRef.current = request.abort;
-
- return () => {
- abortRef.current?.();
- abortRef.current = null;
- };
- }, [workspaceId, transformId, hasQuery, dryRunTransform]);
-
- const normalizedCols = useMemo<DatasetColumn[]>(() => {
- const cols: Partial<DatasetColumn>[] = data?.data?.cols ?? [];
- return cols.map((col, index) => {
- const name = col.name ?? `column_${index + 1}`;
-
- return {
- ...col,
- name,
- display_name: col.display_name ?? name,
- source: col.source ?? "native",
- };
- });
- }, [data]);
-
- const previewData = useMemo(() => {
- if (
- !data?.data ||
- data.status === "failed" ||
- normalizedCols.length === 0
- ) {
- return null;
- }
-
- return createMockDatasetData({
- cols: normalizedCols,
- rows: data.data.rows ?? [],
- results_metadata: data.data.results_metadata,
- });
- }, [data, normalizedCols]);
-
- const rawSeries = useMemo<RawSeries | undefined>(() => {
- if (!previewData) {
- return undefined;
- }
-
- return [
- {
- card: createMockCard({
- display: "table",
- visualization_settings: {},
- }),
- data: {
- ...previewData,
- rows: _.uniq(previewData.rows ?? []),
- },
- },
- ];
- }, [previewData]);
-
- const errorMessage = useMemo(() => {
- if (error) {
- return getErrorMessage(error);
- }
- if (data?.status === "failed") {
- return data.message ?? "Transform preview failed";
- }
- return undefined;
- }, [data, error]);
-
- const hasRequest = Boolean(workspaceId && transformId && query);
- const isPending = hasRequest && !data && !error && !isLoading;
- const isFetching = isLoading || isPending;
-
- return {
- rawSeries,
- isFetching,
- isLoading,
- isError: Boolean(errorMessage),
- error: errorMessage,
- };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/GraphTab.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/GraphTab.tsx
deleted file mode 100644
index 3087c396579..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/GraphTab.tsx
+++ /dev/null
@@ -1,170 +0,0 @@
-import { useMemo } from "react";
-import { t } from "ttag";
-
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { Box } from "metabase/ui";
-import { useGetWorkspaceGraphQuery } from "metabase-enterprise/api";
-import { DependencyGraph as DependencyGraphComponent } from "metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph";
-import { WorkspaceGraphNode } from "metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/WorkspaceGraphNode";
-import type {
- DependencyEntry,
- WorkspaceDependencyGraph,
- WorkspaceGraphDependencyEdge,
- WorkspaceGraphDependencyNode,
- WorkspaceGraphResponse,
- WorkspaceGraphTableNode,
- WorkspaceGraphTransformNode,
- WorkspaceId,
-} from "metabase-types/api";
-
-type GraphTabProps = {
- workspaceId: WorkspaceId;
-};
-
-const NODE_TYPES = {
- node: WorkspaceGraphNode,
-};
-
-export function GraphTab({ workspaceId }: GraphTabProps) {
- const {
- data: graphData,
- isFetching,
- error,
- } = useGetWorkspaceGraphQuery(workspaceId);
-
- const dependencyGraph = useDependencyGraph(graphData, workspaceId);
-
- // Create a dummy entry to initialize GraphComponent correctly (not empty).
- const dummyEntry: DependencyEntry = {
- id: workspaceId,
- type: "workspace-transform",
- };
-
- if (isFetching || error) {
- return <LoadingAndErrorWrapper error={error} loading={isFetching} />;
- }
-
- const getGraphUrl = () => `/api/ee/workspace/${workspaceId}/graph`;
-
- return (
- <Box h="100%" w="100%">
- <DependencyGraphComponent
- entry={dummyEntry}
- graph={dependencyGraph}
- getGraphUrl={getGraphUrl}
- withEntryPicker={false}
- nodeTypes={NODE_TYPES}
- openLinksInNewTab={false}
- />
- </Box>
- );
-}
-
-function useDependencyGraph(
- graphData: WorkspaceGraphResponse | undefined,
- workspaceId: WorkspaceId,
-): WorkspaceDependencyGraph | undefined {
- return useMemo(() => {
- if (!graphData) {
- return undefined;
- }
-
- // Transform workspace graph data to match WorkspaceDependencyGraph format
- // Data Studio graph doesn't have a concept of input and output tables,
- // so we need to transform the data to match the expected format.
- const dependencyNodes = [...graphData.nodes].reduce<
- WorkspaceGraphDependencyNode[]
- >((acc, node) => {
- if (node.type === "input-table") {
- const tableNode: WorkspaceGraphTableNode = {
- id: node.id,
- type: "table",
- data: {
- name: node.data?.table || t`Table ${node.id}`,
- display_name: node.data?.table || t`Table ${node.id}`,
- description: null,
- db_id: node.data?.db,
- schema: node.data?.schema,
- fields: [],
- table_id: node.data?.id,
- },
- dependents_count: node.dependents_count,
- };
- acc.push(tableNode);
- } else if (node.type === "workspace-transform") {
- const transformNode: WorkspaceGraphTransformNode = {
- id: node.id,
- type: "workspace-transform",
- data: {
- name: node.data?.name || `Transform ${node.id}`,
- workspace_id: workspaceId,
- ref_id: node.data?.ref_id,
- target: node.data?.target,
- },
- dependents_count: node.dependents_count,
- };
- acc.push(transformNode);
-
- // Create target table node if target information is available
- if (node.data?.target) {
- const targetTableNode: WorkspaceGraphTableNode = {
- id: `target-${node.id}`,
- type: "table",
- data: {
- name: node.data.target.table || t`Target table ${node.id}`,
- display_name:
- node.data.target.table || t`Target table ${node.id}`,
- description: null,
- db_id: node.data.target.db,
- schema: node.data.target.schema,
- fields: [],
- table_id: node.data.target.table_id ?? undefined,
- },
- dependents_count: {},
- };
- acc.push(targetTableNode);
- }
- }
- return acc;
- }, []);
-
- // Transform edges to match WorkspaceGraphDependencyEdge format
- const dependencyEdges: WorkspaceGraphDependencyEdge[] = graphData.edges.map(
- (edge) => {
- const fromEntityType: WorkspaceGraphDependencyEdge["from_entity_type"] =
- edge.from_entity_type === "workspace-transform"
- ? "workspace-transform"
- : "table";
- const toEntityType: WorkspaceGraphDependencyEdge["to_entity_type"] =
- edge.to_entity_type === "workspace-transform"
- ? "workspace-transform"
- : "table";
-
- return {
- from_entity_id: edge.from_entity_id,
- from_entity_type: fromEntityType,
- to_entity_id: edge.to_entity_id,
- to_entity_type: toEntityType,
- };
- },
- );
-
- // Add edges from workspace-transforms to their target tables
- graphData.nodes.forEach((node) => {
- if (node.type === "workspace-transform" && node.data?.target) {
- const targetEdge: WorkspaceGraphDependencyEdge = {
- from_entity_id: `target-${node.id}`,
- from_entity_type: "table",
- to_entity_id: node.id,
- to_entity_type: "workspace-transform",
- };
- dependencyEdges.push(targetEdge);
- }
- });
-
- return {
- nodes: dependencyNodes,
- edges: dependencyEdges,
- };
- }, [graphData, workspaceId]);
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/MetabotTab.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/MetabotTab.tsx
deleted file mode 100644
index 791e4001d39..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/MetabotTab.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-import { MetabotChat } from "metabase/metabot/components/MetabotChat";
-import type { MetabotSuggestionActions } from "metabase/metabot/context";
-import {
- MetabotProvider,
- useRegisterMetabotSuggestionActions,
-} from "metabase/metabot/context";
-import { useRegisterMetabotTransformContext } from "metabase/transforms/hooks/use-register-transform-metabot-context";
-import type {
- DraftTransformSource,
- TaggedTransform,
- UnsavedTransform,
- WorkspaceTransform,
-} from "metabase-types/api";
-
-type AnyWorkspaceTransform =
- | TaggedTransform
- | WorkspaceTransform
- | UnsavedTransform;
-
-type MetabotTabProps = {
- transform?: AnyWorkspaceTransform;
- source?: DraftTransformSource;
- workspaceId?: number;
- suggestionActions?: MetabotSuggestionActions;
-};
-
-const MetabotContextRegistration = ({ transform, source }: MetabotTabProps) => {
- useRegisterMetabotTransformContext(transform, source);
- return null;
-};
-
-const MetabotSuggestionActionsRegistration = ({
- suggestionActions,
-}: {
- suggestionActions?: MetabotSuggestionActions;
-}) => {
- useRegisterMetabotSuggestionActions(suggestionActions ?? null);
- return null;
-};
-
-export const MetabotTab = ({
- transform,
- source,
- suggestionActions,
-}: MetabotTabProps) => {
- return (
- <MetabotProvider>
- <MetabotContextRegistration transform={transform} source={source} />
- <MetabotSuggestionActionsRegistration
- suggestionActions={suggestionActions}
- />
- <MetabotChat
- config={{
- suggestionModels: ["transform", "database", "table"],
- }}
- />
- </MetabotProvider>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/SetupLog.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/SetupLog.tsx
deleted file mode 100644
index d6df014c6de..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/SetupLog.tsx
+++ /dev/null
@@ -1,87 +0,0 @@
-import { match } from "ts-pattern";
-import { t } from "ttag";
-
-import { LoadingAndGenericErrorWrapper } from "metabase/common/components/LoadingAndGenericErrorWrapper";
-import { Group, Icon, Loader, Stack, Text, Tooltip } from "metabase/ui";
-import type { WorkspaceLogStatus } from "metabase-types/api";
-
-import type { SetupStatus } from "./useWorkspaceData";
-
-type SetupLogProps = {
- setupStatus: SetupStatus;
-};
-export const SetupLog = ({ setupStatus }: SetupLogProps) => {
- const { workspace, error, isLoading, logs } = setupStatus;
-
- if (error || isLoading) {
- return <LoadingAndGenericErrorWrapper error={error} loading={isLoading} />;
- }
-
- return (
- <Stack
- bd="1px solid var(--mb-color-border)"
- bg="background-info"
- bdrs="md"
- gap="sm"
- p="md"
- >
- {logs.length === 0 && workspace?.status === "pending" && (
- <Loader size="xs" />
- )}
-
- {logs.length === 0 && workspace?.status !== "pending" && (
- <Text>{t`No logs to display`}</Text>
- )}
-
- {logs.map((log) => {
- return (
- <Group gap="xs" key={log.id} wrap="nowrap">
- <Tooltip disabled={!log.message} label={log.message}>
- <Group>
- <LogIcon status={log.status} />
- </Group>
- </Tooltip>
-
- <span>
- {log.description}
- {log.status === "started" && "…"}
- </span>
- </Group>
- );
- })}
-
- {workspace?.status === "ready" && (
- <Group gap="xs" wrap="nowrap">
- <LogIcon status="success" />
-
- {t`Workspace ready!`}
- </Group>
- )}
-
- {workspace?.status === "archived" && (
- <Group gap="xs" wrap="nowrap">
- <Icon c="text-tertiary" name="archive" />
-
- {t`Workspace is archived`}
- </Group>
- )}
- </Stack>
- );
-};
-
-function LogIcon({ status }: { status: WorkspaceLogStatus | null }) {
- return match(status)
- .with("failure", () => {
- return <Icon c="warning" name="warning_triangle_filled" />;
- })
- .with("started", () => {
- return <Loader size="xs" />;
- })
- .with("success", () => {
- return <Icon c="success" name="check" />;
- })
- .with(null, () => {
- return <Icon name="chevronright" />;
- })
- .exhaustive();
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/SetupTab.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/SetupTab.tsx
deleted file mode 100644
index ff2cc87e382..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/SetupTab.tsx
+++ /dev/null
@@ -1,115 +0,0 @@
-import { useCallback, useMemo } from "react";
-import { t } from "ttag";
-
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import { Select, Stack, Text, Title } from "metabase/ui";
-import {
- useGetWorkspaceAllowedDatabasesQuery,
- useUpdateWorkspaceMutation,
-} from "metabase-enterprise/api/workspace";
-import type { DatabaseId, Workspace } from "metabase-types/api";
-
-import { isWorkspaceUninitialized } from "../../utils";
-
-import { SetupLog } from "./SetupLog";
-import type { SetupStatus } from "./useWorkspaceData";
-
-interface SetupTabProps {
- databaseId?: DatabaseId | null;
- workspace: Workspace;
- setupStatus: SetupStatus;
-}
-
-export const SetupTab = ({
- databaseId,
- workspace,
- setupStatus,
-}: SetupTabProps) => {
- const {
- data: allowedDatabases,
- isLoading,
- error,
- } = useGetWorkspaceAllowedDatabasesQuery();
- const [updateWorkspace] = useUpdateWorkspaceMutation();
- const { sendErrorToast, sendSuccessToast } = useMetadataToasts();
- const workspaceId = workspace.id;
-
- const handleDatabaseChange = useCallback(
- async (value: string) => {
- const newDatabaseId = Number(value);
- if (newDatabaseId !== databaseId) {
- try {
- await updateWorkspace({
- id: workspaceId,
- database_id: newDatabaseId,
- }).unwrap();
- sendSuccessToast(t`Successfully updated workspace database`);
- } catch (error) {
- sendErrorToast(t`Failed to update workspace database`);
- }
- }
- },
- [
- databaseId,
- workspaceId,
- updateWorkspace,
- sendErrorToast,
- sendSuccessToast,
- ],
- );
-
- const databaseOptions = useMemo(
- () =>
- allowedDatabases?.databases
- ?.filter((db) => db.enabled)
- ?.map((db) => ({
- value: db.id.toString(),
- label: db.name,
- })) ?? [],
- [allowedDatabases?.databases],
- );
-
- return (
- <Stack gap="lg">
- <Stack gap="xs">
- <Title order={3}>{t`Workspace Setup`}</Title>
-
- <Text c="text-secondary">
- {t`Configure your data warehouse connection for this workspace`}
- </Text>
- </Stack>
-
- <Stack gap="xs">
- <Text fw="bold">{t`Data warehouse`}</Text>
-
- <LoadingAndErrorWrapper error={error} loading={isLoading}>
- <Select
- data={databaseOptions}
- value={databaseId?.toString() ?? ""}
- onChange={handleDatabaseChange}
- placeholder={
- allowedDatabases != null && databaseOptions.length === 0
- ? t`No database supports workspaces`
- : t`Select a database`
- }
- disabled={!isWorkspaceUninitialized(workspace)}
- maw="20rem"
- />
- </LoadingAndErrorWrapper>
-
- <Text c="text-tertiary" size="sm">
- {t`Data warehouse selection is locked after adding transforms to the workspace`}
- </Text>
- </Stack>
-
- {!isWorkspaceUninitialized(workspace) && (
- <Stack gap="xs">
- <Text fw="bold">{t`Setup log`}</Text>
-
- {setupStatus && <SetupLog setupStatus={setupStatus} />}
- </Stack>
- )}
- </Stack>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformEditor.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformEditor.tsx
deleted file mode 100644
index 10f3e31dd72..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformEditor.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-import { useMemo, useState } from "react";
-import _ from "underscore";
-
-import {
- TransformQueryPageEditor,
- type TransformQueryPageEditorUiState,
-} from "metabase/transforms/pages/TransformQueryPage/TransformQueryPage";
-import type { DatasetQuery, DraftTransformSource } from "metabase-types/api";
-
-type TransformEditorProps = {
- disabled: boolean;
- hideRunButton?: boolean;
- source: DraftTransformSource;
- onChange: (source: DraftTransformSource) => void;
- proposedSource?: DraftTransformSource;
- onAcceptProposed?: () => void;
- onRejectProposed?: () => void;
- onRunQueryStart?: (query: DatasetQuery) => boolean | void;
- onRunTransform?: (result: any) => void;
- /** Custom run handler for Python transforms (used for dry-run) */
- onRun?: () => void;
-};
-
-export function TransformEditor({
- disabled,
- hideRunButton,
- source,
- onChange,
- proposedSource,
- onAcceptProposed,
- onRejectProposed,
- onRunQueryStart,
- onRunTransform,
- onRun,
-}: TransformEditorProps) {
- const [uiState, setUiState] = useState(getInitialUiStateForTransform);
-
- const uiOptions = useMemo(
- () => ({
- canChangeDatabase: false,
- readOnly: disabled,
- hidePreview: true,
- hideRunButton,
- resizable: false,
- }),
- [disabled, hideRunButton],
- );
-
- const handleSourceChange = (source: DraftTransformSource) => {
- onChange?.(source);
- };
-
- return (
- <TransformQueryPageEditor
- source={source}
- proposedSource={proposedSource}
- uiState={uiState}
- setUiState={setUiState}
- uiOptions={uiOptions}
- databases={[]}
- isEditMode={true}
- setSourceAndRejectProposed={handleSourceChange}
- acceptProposed={onAcceptProposed ?? _.noop}
- rejectProposed={onRejectProposed ?? _.noop}
- onRunQueryStart={onRunQueryStart}
- onRunTransform={onRunTransform}
- onRun={onRun}
- />
- );
-}
-
-function getInitialUiStateForTransform(): TransformQueryPageEditorUiState {
- return {
- lastRunResult: null,
- lastRunQuery: null,
- selectionRange: [],
- modalSnippet: null,
- sidebarType: null,
- modalType: null,
- };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformEditor.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformEditor.unit.spec.tsx
deleted file mode 100644
index fad39bcdc37..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformEditor.unit.spec.tsx
+++ /dev/null
@@ -1,123 +0,0 @@
-import {
- setupAdhocQueryMetadataEndpoint,
- setupDatabasesEndpoints,
- setupSearchEndpoints,
- setupTablesEndpoints,
- setupWorkspaceCheckoutEndpoint,
- setupWorkspacesEndpoint,
-} from "__support__/server-mocks";
-import { renderWithProviders } from "__support__/ui";
-import { createMockState } from "metabase/redux/store/mocks";
-import type { DraftTransformSource } from "metabase-types/api";
-import {
- createMockCardQueryMetadata,
- createMockDatabase,
- createMockTable,
-} from "metabase-types/api/mocks";
-
-import { TransformEditor } from "./TransformEditor";
-
-type UiOptions = {
- hideRunButton?: boolean;
-};
-
-type MockProps = {
- uiOptions?: UiOptions;
-};
-
-// Mock the TransformQueryPageEditor to capture uiOptions
-const mockTransformQueryPageEditor = jest.fn((_props: MockProps) => (
- <div data-testid="mock-transform-query-page-editor" />
-));
-
-jest.mock(
- "metabase/transforms/pages/TransformQueryPage/TransformQueryPage",
- () => ({
- TransformQueryPageEditor: (props: MockProps) =>
- mockTransformQueryPageEditor(props),
- }),
-);
-
-const DATABASE_ID = 1;
-const mockDatabase = createMockDatabase({
- id: DATABASE_ID,
- name: "Test Database",
-});
-const mockTable = createMockTable({
- id: 1,
- db_id: DATABASE_ID,
- name: "Test Table",
-});
-
-const mockNativeSource: DraftTransformSource = {
- type: "query",
- query: {
- type: "native",
- database: DATABASE_ID,
- native: {
- query: "SELECT * FROM test_table",
- },
- },
-};
-
-type SetupOpts = {
- source?: DraftTransformSource;
- hideRunButton?: boolean;
- disabled?: boolean;
-};
-
-function setup({
- source = mockNativeSource,
- hideRunButton = false,
- disabled = false,
-}: SetupOpts = {}) {
- setupDatabasesEndpoints([mockDatabase]);
- setupTablesEndpoints([mockTable]);
- setupSearchEndpoints([]);
- setupWorkspacesEndpoint([]);
- setupWorkspaceCheckoutEndpoint({});
- setupAdhocQueryMetadataEndpoint(
- createMockCardQueryMetadata({ databases: [mockDatabase] }),
- );
-
- mockTransformQueryPageEditor.mockClear();
-
- renderWithProviders(
- <TransformEditor
- source={source}
- hideRunButton={hideRunButton}
- disabled={disabled}
- onChange={jest.fn()}
- onAcceptProposed={jest.fn()}
- onRejectProposed={jest.fn()}
- />,
- {
- storeInitialState: createMockState(),
- },
- );
-}
-
-function getLastUiOptions(): UiOptions | undefined {
- const calls = mockTransformQueryPageEditor.mock.calls;
- if (calls.length === 0) {
- return undefined;
- }
- const lastCall = calls[calls.length - 1];
- return lastCall[0]?.uiOptions;
-}
-
-describe("TransformEditor", () => {
- describe("hideRunButton prop", () => {
- it("should not hide run button when hideRunButton is false", () => {
- setup({ hideRunButton: false });
- const uiOptions = getLastUiOptions();
- expect(uiOptions?.hideRunButton).toBe(false);
- });
-
- it("should hide run button when hideRunButton is true", () => {
- setup({ hideRunButton: true });
- const uiOptions = getLastUiOptions();
- expect(uiOptions?.hideRunButton).toBe(true);
- });
- });
-});
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/SaveTransformButton.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/SaveTransformButton.tsx
deleted file mode 100644
index 192c47377a2..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/SaveTransformButton.tsx
+++ /dev/null
@@ -1,263 +0,0 @@
-import { useMemo, useState } from "react";
-import { t } from "ttag";
-
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import { getMetadata } from "metabase/selectors/metadata";
-import { CreateTransformModal } from "metabase/transforms/pages/NewTransformPage/CreateTransformModal/CreateTransformModal";
-import type { NewTransformValues } from "metabase/transforms/pages/NewTransformPage/CreateTransformModal/form";
-import { isSourceEmpty } from "metabase/transforms/utils";
-import { Button } from "metabase/ui";
-import { useDispatch, useSelector } from "metabase/utils/redux";
-import {
- useCreateWorkspaceTransformMutation,
- useUpdateWorkspaceTransformMutation,
- workspaceApi,
-} from "metabase-enterprise/api";
-import { idTag, listTag } from "metabase-enterprise/api/tags";
-import type {
- CreateWorkspaceTransformRequest,
- DatabaseId,
- SchemaName,
- TaggedTransform,
- TransformSource,
- WorkspaceId,
- WorkspaceTransform,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-import {
- isTaggedTransform,
- isUnsavedTransform,
- isWorkspaceTransform,
-} from "metabase-types/api";
-
-import type { AnyWorkspaceTransform } from "../WorkspaceProvider";
-import { useWorkspace } from "../WorkspaceProvider";
-
-import { useEditedTransform } from "./useEditedTransform";
-import { useTransformValidation } from "./useTransformValidation";
-
-const schemasFilter = (schema: SchemaName) =>
- !schema.startsWith("mb__isolation");
-
-type SaveTransformButtonProps = {
- databaseId: DatabaseId;
- workspaceId: WorkspaceId;
- workspaceTransforms: WorkspaceTransformListItem[];
- transform: AnyWorkspaceTransform;
- isDisabled: boolean;
- onSaveTransform: (transform: TaggedTransform | WorkspaceTransform) => void;
-};
-
-export const SaveTransformButton = ({
- databaseId,
- workspaceId,
- workspaceTransforms,
- transform,
- isDisabled,
- onSaveTransform,
-}: SaveTransformButtonProps) => {
- const dispatch = useDispatch();
- const metadata = useSelector(getMetadata);
- const { sendSuccessToast, sendErrorToast } = useMetadataToasts();
- const {
- updateTransformState,
- removeUnsavedTransform,
- removeWorkspaceTransform,
- removeEditedTransform,
- } = useWorkspace();
-
- const [updateTransformMutation, { isLoading: isUpdating }] =
- useUpdateWorkspaceTransformMutation();
- const [createWorkspaceTransform] = useCreateWorkspaceTransformMutation();
- const [saveModalOpen, setSaveModalOpen] = useState(false);
-
- const { editedTransform, hasChanges } = useEditedTransform(transform);
-
- // Determine transform state
- const isSaved =
- isWorkspaceTransform(transform) &&
- workspaceTransforms.some((t) => t.ref_id === transform.ref_id);
- const isNewTransform = isUnsavedTransform(transform);
-
- const validationSchemaExtension = useTransformValidation({
- databaseId,
- target: isUnsavedTransform(transform) ? undefined : transform.target,
- workspaceId,
- });
-
- const initialCreateTransformValues = useMemo(
- () => ({
- name: transform.name,
- }),
- [transform.name],
- );
-
- // Handler for updating existing workspace transform (scenario 1)
- const handleUpdateTransform = async () => {
- if (!isWorkspaceTransform(transform)) {
- throw new Error(t`This is not a workspace transform`);
- }
-
- try {
- const updated = await updateTransformMutation({
- workspaceId,
- transformId: transform.ref_id,
- source: editedTransform.source as TransformSource,
- name: editedTransform.name,
- target: {
- type: "table",
- name:
- "target" in editedTransform
- ? editedTransform.target.name
- : transform.target.name,
- schema: transform.target.schema,
- database: databaseId,
- },
- }).unwrap();
-
- updateTransformState(updated);
- } catch (error) {
- sendErrorToast(t`Failed to save transform`);
- }
- };
-
- // Handler for creating new transform via modal (scenario 2)
- const handleCreateNewTransform = async (
- values: NewTransformValues,
- ): Promise<WorkspaceTransform> => {
- try {
- const request: CreateWorkspaceTransformRequest = values.incremental
- ? {
- id: workspaceId,
- name: values.name,
- description: null,
- source: editedTransform.source as TransformSource,
- target: {
- type: "table-incremental" as const,
- name: values.targetName,
- schema: values.targetSchema,
- database: databaseId,
- "target-incremental-strategy": {
- type: "append" as const,
- },
- },
- }
- : {
- id: workspaceId,
- name: values.name,
- description: null,
- source: editedTransform.source as TransformSource,
- target: {
- type: "table" as const,
- name: values.targetName,
- schema: values.targetSchema,
- database: databaseId,
- },
- };
-
- const savedTransform = await createWorkspaceTransform(request).unwrap();
-
- // Remove from unsaved transforms and refresh workspace
- if (isNewTransform) {
- removeUnsavedTransform(transform.id);
- }
-
- // Invalidate workspace transforms after creating new one
- dispatch(
- workspaceApi.util.invalidateTags([
- idTag("workspace-transforms", workspaceId),
- listTag("external-transform"),
- ]),
- );
-
- onSaveTransform(savedTransform);
-
- sendSuccessToast(t`Transform saved successfully`);
- setSaveModalOpen(false);
-
- return savedTransform;
- } catch (error) {
- sendErrorToast(t`Failed to save transform`);
- throw error;
- }
- };
-
- // Handler for checking out external transform (scenario 3)
- const handleSaveExternalTransform = async () => {
- if (!isTaggedTransform(transform)) {
- return;
- }
-
- try {
- const savedTransform = await createWorkspaceTransform({
- id: workspaceId,
- global_id: transform.id,
- name: editedTransform.name,
- description: transform.description,
- source: editedTransform.source as TransformSource,
- target: transform.target,
- tag_ids: transform.tag_ids,
- }).unwrap();
-
- removeEditedTransform(transform.id);
- removeWorkspaceTransform(transform.id);
- onSaveTransform(savedTransform);
- } catch (error) {
- sendErrorToast(t`Failed to save transform`);
- }
- };
-
- // Determine button props based on scenario
- const getButtonProps = () => {
- if (isSaved) {
- return {
- disabled: !hasChanges || isDisabled,
- loading: isUpdating,
- variant: "filled" as const,
- onClick: handleUpdateTransform,
- };
- }
-
- if (isNewTransform) {
- const hasEmptyContent = isSourceEmpty(
- editedTransform.source,
- databaseId,
- metadata,
- );
- return {
- disabled: isDisabled || hasEmptyContent,
- variant: "filled" as const,
- onClick: () => setSaveModalOpen(true),
- };
- }
-
- // External transform
- return {
- disabled: isDisabled,
- variant: hasChanges ? ("filled" as const) : ("default" as const),
- onClick: handleSaveExternalTransform,
- };
- };
-
- const buttonProps = getButtonProps();
-
- return (
- <>
- <Button size="sm" {...buttonProps}>{t`Save`}</Button>
-
- {saveModalOpen && (
- <CreateTransformModal
- source={editedTransform.source as TransformSource}
- defaultValues={initialCreateTransformValues}
- onClose={() => setSaveModalOpen(false)}
- schemasFilter={schemasFilter}
- validationSchemaExtension={validationSchemaExtension}
- validateOnMount
- handleSubmit={handleCreateNewTransform}
- targetDescription={t`This is the main table this transform owns. Runs from this workspace write to an isolated workspace copy, so the original table isn't changed until you merge the workspace.`}
- showIncrementalSettings={false}
- />
- )}
- </>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/TransformTab.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/TransformTab.tsx
deleted file mode 100644
index e1160282f8f..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/TransformTab.tsx
+++ /dev/null
@@ -1,71 +0,0 @@
-import { t } from "ttag";
-
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { Text } from "metabase/ui";
-import type {
- DatabaseId,
- TaggedTransform,
- WorkspaceId,
- WorkspaceTransform,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-
-import { useWorkspace } from "../WorkspaceProvider";
-import { useActiveTransform } from "../useActiveTransform";
-
-import { TransformTabContent } from "./TransformTabContent";
-
-interface Props {
- databaseId: DatabaseId;
- disabled: boolean;
- workspaceId: WorkspaceId;
- workspaceTransforms: WorkspaceTransformListItem[];
- onSaveTransform: (transform: TaggedTransform | WorkspaceTransform) => void;
-}
-
-export function TransformTab({
- databaseId,
- disabled,
- workspaceId,
- workspaceTransforms,
- onSaveTransform,
-}: Props) {
- const { activeTransformRef, activeEditedTransform, unsavedTransforms } =
- useWorkspace();
-
- const {
- data: activeTransform,
- error: activeTransformError,
- isLoading: activeTransformIsLoading,
- } = useActiveTransform({
- transformRef: activeTransformRef,
- unsavedTransforms,
- workspaceId: workspaceId,
- });
-
- if (activeTransformError || activeTransformIsLoading) {
- return (
- <LoadingAndErrorWrapper
- error={activeTransformError}
- loading={activeTransformIsLoading}
- />
- );
- }
-
- if (!activeEditedTransform || !activeTransform) {
- return (
- <Text c="text-secondary">{t`Select a transform on the right.`}</Text>
- );
- }
-
- return (
- <TransformTabContent
- databaseId={databaseId}
- disabled={disabled}
- transform={activeTransform}
- workspaceId={workspaceId}
- workspaceTransforms={workspaceTransforms}
- onSaveTransform={onSaveTransform}
- />
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/TransformTabContent.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/TransformTabContent.tsx
deleted file mode 100644
index be63fc3c243..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/TransformTabContent.tsx
+++ /dev/null
@@ -1,448 +0,0 @@
-import { useDisclosure } from "@mantine/hooks";
-import { useCallback, useEffect, useRef, useState } from "react";
-import { t } from "ttag";
-
-import {
- deactivateSuggestedTransform,
- getMetabotSuggestedTransform,
-} from "metabase/metabot/state";
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import { getMetadata } from "metabase/selectors/metadata";
-import { RunStatus } from "metabase/transforms/components/RunStatus";
-import {
- getInitialNativeSource,
- getInitialPythonSource,
-} from "metabase/transforms/pages/NewTransformPage/utils";
-import { Box, Button, Group, Icon, Stack } from "metabase/ui";
-import { useDispatch, useSelector } from "metabase/utils/redux";
-import { useDryRunWorkspaceTransformMutation } from "metabase-enterprise/api";
-import { useWorkspaceTransformRun } from "metabase-enterprise/data-studio/workspaces/hooks";
-import * as Lib from "metabase-lib";
-import Question from "metabase-lib/v1/Question";
-import type {
- DatabaseId,
- DatasetQuery,
- DraftTransformSource,
- TaggedTransform,
- TestPythonTransformResponse,
- WorkspaceId,
- WorkspaceTransform,
- WorkspaceTransformDryRunResponse,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-import { isUnsavedTransform, isWorkspaceTransform } from "metabase-types/api";
-
-import { WorkspaceRunButton } from "../../../components/WorkspaceRunButton/WorkspaceRunButton";
-import { TransformEditor } from "../TransformEditor";
-import type { AnyWorkspaceTransform, TableTab } from "../WorkspaceProvider";
-import {
- getNumericTransformId,
- getTransformId,
- useWorkspace,
-} from "../WorkspaceProvider";
-
-import { SaveTransformButton } from "./SaveTransformButton";
-import { UpdateTargetModal } from "./UpdateTargetModal/UpdateTargetModal";
-import { useEditedTransform } from "./useEditedTransform";
-
-interface Props {
- databaseId: DatabaseId;
- transform: AnyWorkspaceTransform;
- workspaceId: WorkspaceId;
- workspaceTransforms: WorkspaceTransformListItem[];
- disabled: boolean;
- onSaveTransform: (transform: TaggedTransform | WorkspaceTransform) => void;
-}
-
-export function TransformTabContent({
- databaseId,
- transform,
- workspaceId,
- workspaceTransforms,
- disabled,
- onSaveTransform,
-}: Props) {
- const {
- updateTransformState,
- addOpenedTab,
- editedTransforms,
- patchEditedTransform,
- } = useWorkspace();
- const { sendErrorToast } = useMetadataToasts();
- const [
- isChangeTargetModalOpen,
- { open: openChangeTargetModal, close: closeChangeTargetModal },
- ] = useDisclosure();
- const dispatch = useDispatch();
- const transformId = getTransformId(transform);
- const numericTransformId = getNumericTransformId(transform);
- const suggestedTransform = useSelector((state) =>
- getMetabotSuggestedTransform(state, numericTransformId),
- );
- const metadata = useSelector(getMetadata);
-
- // Local source state to prevent re-renders on every keystroke
- // This is the key optimization: we manage source locally and sync to provider
- const [localSource, setLocalSource] = useState<DraftTransformSource>(() => {
- const edited = editedTransforms.get(transformId);
- return edited?.source ?? transform.source;
- });
-
- // Track previous transform ID to detect when we switch transforms
- const prevTransformIdRef = useRef(transformId);
-
- // Reset local source when switching to a different transform
- useEffect(() => {
- if (prevTransformIdRef.current !== transformId) {
- const edited = editedTransforms.get(transformId);
- setLocalSource(edited?.source ?? transform.source);
- prevTransformIdRef.current = transformId;
- }
- // Note: editedTransforms is intentionally excluded from deps
- // We only want to sync when transform ID changes, not on every edit
- }, [transformId, transform.source, editedTransforms]);
-
- const { editedTransform, hasChanges, providerEdited } =
- useEditedTransform(transform);
-
- const wsTransform = isWorkspaceTransform(transform) ? transform : null;
- const currentSource = providerEdited?.source ?? localSource;
-
- // Run transform hook - handles run state, API calls, and error handling
- const { statusRun, buttonRun, isRunStatusLoading, isRunning, handleRun } =
- useWorkspaceTransformRun({
- workspaceId,
- transform: wsTransform,
- });
-
- const handleRunQueryStart = useCallback(
- (query: DatasetQuery) => {
- // Preview doesn't have a real table ID, but we need to provide a unique identifier
- // to open preview tab correctly.
- const tableTabId = `table-${transformId}`;
-
- // Use dry-run API to preview the saved transform's source.
- // The preview button is only shown when transform is saved and has no unsaved changes,
- // so we can safely use dry-run which executes the saved source.
- const tableTab: TableTab = {
- id: tableTabId,
- name: t`Preview (${transform.name})`,
- type: "table",
- table: {
- tableId: null,
- name: t`Preview (${transform.name})`,
- query,
- transformId: String(transformId),
- },
- };
- addOpenedTab(tableTab);
- return false;
- },
- [transformId, transform.name, addOpenedTab],
- );
-
- const handleRunTransform = useCallback(
- (result: unknown) => {
- const tableTabId = `table-${transformId}`;
-
- const tableTab: TableTab = {
- id: tableTabId,
- name: t`Preview (${transform.name})`,
- type: "table",
- table: {
- tableId: null,
- name: t`Preview (${transform.name})`,
- transformId: String(transformId),
- pythonPreviewResult: result,
- },
- };
-
- addOpenedTab(tableTab);
- },
- [transformId, transform.name, addOpenedTab],
- );
-
- // Dry-run handler for Python transforms
- const [dryRunTransform] = useDryRunWorkspaceTransformMutation();
-
- const handlePythonRun = useCallback(async () => {
- if (!wsTransform) {
- return;
- }
-
- try {
- const result = await dryRunTransform({
- workspaceId,
- transformId: wsTransform.ref_id,
- }).unwrap();
-
- // Convert dry-run response to TestPythonTransformResponse format
- const converted = convertDryRunToTestResponse(result);
- handleRunTransform(converted);
- } catch (error) {
- // Handle error - show in preview results
- const errorResult: TestPythonTransformResponse = {
- error: {
- message:
- error instanceof Error ? error.message : "Transform preview failed",
- },
- };
- handleRunTransform(errorResult);
- }
- }, [wsTransform, workspaceId, dryRunTransform, handleRunTransform]);
-
- const normalizeSource = useCallback(
- (source: DraftTransformSource): DraftTransformSource => {
- if (source.type !== "query") {
- return source;
- }
-
- const question = Question.create({
- dataset_query: source.query,
- metadata,
- });
- const query = question.query();
- const { isNative } = Lib.queryDisplayInfo(query);
- const normalizedQuery = isNative
- ? Lib.withNativeQuery(query, Lib.rawNativeQuery(query))
- : query;
-
- return {
- type: "query" as const,
- query: question.setQuery(normalizedQuery).datasetQuery(),
- };
- },
- [metadata],
- );
-
- // Show proposed source when there's an active suggested transform
- // Even if sources are the same (e.g., when transform was created with suggested source),
- // we still want to show the buttons so user can reject the suggestion
- const proposedSource: DraftTransformSource | undefined =
- suggestedTransform?.source
- ? normalizeSource(suggestedTransform.source)
- : undefined;
-
- const isSaved =
- isWorkspaceTransform(transform) &&
- workspaceTransforms.some((t) => t.ref_id === transform.ref_id);
- const isEditable = !disabled;
-
- const handleSourceChange = useCallback(
- (source: DraftTransformSource) => {
- setLocalSource(source);
- patchEditedTransform(transformId, { source });
- },
- [transformId, patchEditedTransform],
- );
-
- const handleMetabotAcceptProposed = useCallback(() => {
- if (proposedSource == null) {
- return;
- }
-
- // Allow applying suggestions to both saved workspace transforms and unsaved transforms
- // Only block if it's a tagged transform (external transform) that hasn't been checked out
- const isUnsaved = isUnsavedTransform(transform);
- if (!isSaved && !isUnsaved) {
- sendErrorToast(
- t`Add this transform to the workspace before applying Metabot changes.`,
- );
- return;
- }
-
- // When accepting, we DO need to update localSource to reset the editor
- setLocalSource(proposedSource);
- patchEditedTransform(transformId, { source: proposedSource });
- dispatch(deactivateSuggestedTransform(suggestedTransform?.id));
- }, [
- proposedSource,
- dispatch,
- suggestedTransform?.id,
- isSaved,
- transform,
- sendErrorToast,
- transformId,
- patchEditedTransform,
- ]);
-
- const handleMetabotRejectProposed = useCallback(() => {
- if (suggestedTransform) {
- dispatch(deactivateSuggestedTransform(suggestedTransform.id));
-
- // For unsaved transforms, clear the source back to empty state when rejecting
- if (isUnsavedTransform(transform)) {
- const emptySource = createEmptySourceForType(currentSource);
- if (emptySource) {
- // When rejecting, we DO need to update localSource to reset the editor
- setLocalSource(emptySource);
- patchEditedTransform(transformId, { source: emptySource });
- }
- }
- }
- }, [
- dispatch,
- suggestedTransform,
- transform,
- currentSource,
- transformId,
- patchEditedTransform,
- ]);
-
- const handleTargetUpdate = useCallback(
- (updatedTransform?: WorkspaceTransform) => {
- if (updatedTransform) {
- updateTransformState(updatedTransform);
- }
- closeChangeTargetModal();
- },
- [updateTransformState, closeChangeTargetModal],
- );
-
- return (
- <Stack gap={0} h="100%">
- <Stack
- data-testid="transform-tab-header"
- flex="0 0 auto"
- gap="sm"
- p="md"
- style={{ borderBottom: "1px solid var(--mb-color-border)" }}
- >
- <Group justify="space-between">
- <Group>
- {isSaved && (
- <Button
- leftSection={<Icon name="pencil_lines" />}
- size="sm"
- disabled={isRunning || hasChanges || disabled}
- onClick={openChangeTargetModal}
- >{t`Change target`}</Button>
- )}
- </Group>
-
- <Group>
- {isSaved && (
- <WorkspaceRunButton
- id={numericTransformId}
- run={buttonRun}
- isDisabled={hasChanges || disabled}
- onRun={handleRun}
- />
- )}
-
- <SaveTransformButton
- databaseId={databaseId}
- workspaceId={workspaceId}
- workspaceTransforms={workspaceTransforms}
- transform={transform}
- isDisabled={disabled}
- onSaveTransform={onSaveTransform}
- />
- </Group>
- </Group>
-
- {isSaved &&
- (isRunStatusLoading ? (
- <Group gap="sm">
- <Icon c="text-secondary" name="sync" />
- <Box>{t`Loading run status...`}</Box>
- </Group>
- ) : (
- <RunStatus
- run={statusRun}
- neverRunMessage={t`This transform hasn't been run before.`}
- />
- ))}
- </Stack>
-
- {editedTransform && (
- <Box
- flex="1 1 auto"
- style={{ overflow: "auto", "--native-query-editor-flex": "1 1 auto" }}
- >
- <TransformEditor
- disabled={!isEditable}
- hideRunButton={!isSaved || hasChanges}
- source={localSource}
- proposedSource={proposedSource}
- onAcceptProposed={handleMetabotAcceptProposed}
- onRejectProposed={handleMetabotRejectProposed}
- onChange={handleSourceChange}
- onRunQueryStart={handleRunQueryStart}
- onRunTransform={handleRunTransform}
- onRun={handlePythonRun}
- />
- </Box>
- )}
-
- {isChangeTargetModalOpen && wsTransform && (
- <UpdateTargetModal
- transform={wsTransform}
- onUpdate={handleTargetUpdate}
- onClose={closeChangeTargetModal}
- />
- )}
- </Stack>
- );
-}
-
-/**
- * Creates an empty source based on the type of the current source.
- * Used when rejecting a metabot suggestion on an unsaved transform.
- */
-function createEmptySourceForType(
- currentSource: DraftTransformSource,
-): DraftTransformSource | null {
- if (currentSource.type === "query") {
- const emptySource = getInitialNativeSource();
- // Preserve the database ID from the current source
- const databaseId =
- "database" in currentSource.query ? currentSource.query.database : null;
- if (databaseId) {
- return {
- ...emptySource,
- query: { ...emptySource.query, database: databaseId },
- };
- }
- return emptySource;
- }
-
- if (currentSource.type === "python") {
- const emptySource = getInitialPythonSource();
- // Preserve the database ID from the current source
- return {
- ...emptySource,
- "source-database": currentSource["source-database"],
- };
- }
-
- return null;
-}
-
-/**
- * Converts a dry-run response to the TestPythonTransformResponse format
- * expected by PythonEditorResults component.
- */
-function convertDryRunToTestResponse(
- dryRun: WorkspaceTransformDryRunResponse,
-): TestPythonTransformResponse {
- if (dryRun.status === "failed") {
- return {
- error: { message: dryRun.message ?? "Transform failed" },
- logs: dryRun.logs ?? "",
- };
- }
-
- const cols = (dryRun.data?.cols ?? []).map((col) => ({
- name: col.name ?? "",
- }));
- // Convert rows from array format [[val1, val2], ...] to object format [{col1: val1, col2: val2}, ...]
- const rows = (dryRun.data?.rows ?? []).map((row) =>
- Object.fromEntries(cols.map((col, i) => [col.name, row[i]])),
- );
-
- return {
- logs: dryRun.logs ?? "",
- output: { cols, rows },
- };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/UpdateTargetModal/UpdateTargetModal.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/UpdateTargetModal/UpdateTargetModal.tsx
deleted file mode 100644
index 0234bba72b9..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/UpdateTargetModal/UpdateTargetModal.tsx
+++ /dev/null
@@ -1,201 +0,0 @@
-import { useMemo } from "react";
-import { t } from "ttag";
-import * as Yup from "yup";
-
-import { hasFeature } from "metabase/admin/databases/utils";
-import {
- skipToken,
- useGetDatabaseQuery,
- useListDatabaseSchemasQuery,
-} from "metabase/api";
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import {
- Form,
- FormErrorMessage,
- FormProvider,
- FormSubmitButton,
- FormTextInput,
-} from "metabase/forms";
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import { SchemaFormSelect } from "metabase/transforms/components/SchemaFormSelect";
-import { sourceDatabaseId } from "metabase/transforms/utils";
-import { Box, Button, FocusTrap, Group, Modal, Stack, Text } from "metabase/ui";
-import * as Errors from "metabase/utils/errors";
-import { useUpdateWorkspaceTransformMutation } from "metabase-enterprise/api";
-import type {
- UpdateWorkspaceTransformRequest,
- WorkspaceTransform,
-} from "metabase-types/api";
-
-import { useTransformValidation } from "../useTransformValidation";
-
-type UpdateTargetModalProps = {
- transform: WorkspaceTransform;
- onUpdate: (transform?: WorkspaceTransform) => void;
- onClose: () => void;
-};
-
-export function UpdateTargetModal({
- transform,
- onUpdate,
- onClose,
-}: UpdateTargetModalProps) {
- return (
- <Modal
- title={t`Change the target for this transform`}
- opened
- padding="xl"
- onClose={onClose}
- >
- <FocusTrap.InitialFocus />
- <Box mb="md">
- <Text size="sm" c="text-secondary">
- {t`When you change the target in a workspace, runs from this workspace write to an isolated workspace table. The original table isn't changed until you merge the workspace.`}
- </Text>
- </Box>
- <UpdateTargetForm
- transform={transform}
- onUpdate={onUpdate}
- onClose={onClose}
- />
- </Modal>
- );
-}
-
-type EditTransformValues = {
- targetName: string;
- targetSchema: string | null;
-};
-
-const EDIT_TRANSFORM_SCHEMA = Yup.object({
- targetName: Yup.string().required(Errors.required),
- targetSchema: Yup.string().nullable(),
-});
-
-type UpdateTargetFormProps = {
- transform: WorkspaceTransform;
- onUpdate: (transform?: WorkspaceTransform) => void;
- onClose: () => void;
-};
-
-function UpdateTargetForm({
- transform,
- onUpdate,
- onClose,
-}: UpdateTargetFormProps) {
- const { source } = transform;
- const { sendSuccessToast, sendErrorToast } = useMetadataToasts();
- const databaseId = sourceDatabaseId(source);
- const [updateWorkspaceTransform] = useUpdateWorkspaceTransformMutation();
- const initialValues = useMemo(() => getInitialValues(transform), [transform]);
- const validationSchemaExtension = useTransformValidation({
- databaseId,
- target: transform.target,
- workspaceId: transform.workspace_id,
- });
-
- const validationSchema = useMemo(
- () => EDIT_TRANSFORM_SCHEMA.shape(validationSchemaExtension),
- [validationSchemaExtension],
- );
-
- const {
- data: database,
- isLoading: isDatabaseLoading,
- error: databaseError,
- } = useGetDatabaseQuery(databaseId ? { id: databaseId } : skipToken);
-
- const {
- data: schemas = [],
- isLoading: isSchemasLoading,
- error: schemasError,
- } = useListDatabaseSchemasQuery(
- databaseId ? { id: databaseId, include_hidden: true } : skipToken,
- );
-
- const isLoading = isDatabaseLoading || isSchemasLoading;
- const error = databaseError ?? schemasError;
- const supportsSchemas = database && hasFeature(database, "schemas");
-
- if (isLoading || error != null) {
- return <LoadingAndErrorWrapper loading={isLoading} error={error} />;
- }
-
- const handleSubmit = async (values: EditTransformValues) => {
- if (!databaseId) {
- throw new Error("Database ID is required");
- }
-
- try {
- const updatedTransform = await updateWorkspaceTransform(
- getUpdateTargetRequest(transform, values, databaseId),
- ).unwrap();
-
- sendSuccessToast(t`Transform target updated`);
-
- onUpdate(updatedTransform);
- } catch (error) {
- sendErrorToast(t`Failed to update transform target`);
- }
- };
-
- return (
- <FormProvider
- initialValues={initialValues}
- validationSchema={validationSchema}
- onSubmit={handleSubmit}
- enableReinitialize
- validateOnMount
- >
- {({ dirty }) => (
- <Form>
- <Stack gap="lg">
- {supportsSchemas && (
- <SchemaFormSelect
- name="targetSchema"
- label={t`Schema`}
- data={schemas}
- />
- )}
- <FormTextInput name="targetName" label={t`New table name`} />
- <Group>
- <Box flex={1}>
- <FormErrorMessage />
- </Box>
- <Button onClick={onClose}>{t`Cancel`}</Button>
- <FormSubmitButton
- label={t`Change target`}
- variant="filled"
- disabled={!dirty}
- />
- </Group>
- </Stack>
- </Form>
- )}
- </FormProvider>
- );
-}
-
-function getInitialValues({ target }: WorkspaceTransform): EditTransformValues {
- return {
- targetName: target.name,
- targetSchema: target.schema ?? null,
- };
-}
-
-function getUpdateTargetRequest(
- { ref_id, workspace_id }: WorkspaceTransform,
- { targetName: name, targetSchema: schema }: EditTransformValues,
- databaseId: number,
-): UpdateWorkspaceTransformRequest {
- return {
- workspaceId: workspace_id,
- transformId: ref_id,
- target: {
- type: "table",
- name,
- schema,
- database: databaseId,
- },
- };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/useEditedTransform.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/useEditedTransform.ts
deleted file mode 100644
index 10008c94798..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/useEditedTransform.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import { isSameSource } from "metabase/transforms/utils";
-
-import type {
- AnyWorkspaceTransform,
- EditedTransform,
-} from "../WorkspaceProvider";
-import { getTransformId, useWorkspace } from "../WorkspaceProvider";
-
-interface UseEditedTransformResult {
- editedTransform: EditedTransform;
- hasChanges: boolean;
- providerEdited: EditedTransform | undefined;
-}
-
-/**
- * Hook to get the edited transform state and detect changes.
- * Used by both TransformTab and SaveTransformButton to avoid duplication.
- */
-export function useEditedTransform(
- transform: AnyWorkspaceTransform,
-): UseEditedTransformResult {
- const { editedTransforms } = useWorkspace();
- const transformId = getTransformId(transform);
- const providerEdited = editedTransforms.get(transformId);
-
- const editedTransform: EditedTransform = {
- name: providerEdited?.name ?? transform.name,
- source: providerEdited?.source ?? transform.source,
- target: providerEdited?.target ?? transform.target,
- };
-
- const hasSourceChanged = !isSameSource(
- editedTransform.source,
- transform.source,
- );
- const hasTargetNameChanged =
- "target" in editedTransform &&
- "target" in transform &&
- transform.target.name !== editedTransform.target.name;
- const hasTargetSchemaChanged =
- "target" in editedTransform &&
- "target" in transform &&
- transform.target.schema !== editedTransform.target.schema;
- const hasChanges =
- hasSourceChanged || hasTargetNameChanged || hasTargetSchemaChanged;
-
- return { editedTransform, hasChanges, providerEdited };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/useTransformValidation.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/useTransformValidation.ts
deleted file mode 100644
index ec7bc701643..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/TransformTab/useTransformValidation.ts
+++ /dev/null
@@ -1,106 +0,0 @@
-import { useCallback, useMemo, useRef } from "react";
-import { t } from "ttag";
-import * as Yup from "yup";
-
-import { getErrorMessage } from "metabase/api/utils";
-import { useValidateTableNameMutation } from "metabase-enterprise/api";
-import type {
- DatabaseId,
- TransformTarget,
- WorkspaceId,
-} from "metabase-types/api";
-
-type UseTransformValidationParams = {
- databaseId: DatabaseId | null;
- target?: TransformTarget;
- workspaceId: WorkspaceId;
-};
-
-export const useTransformValidation = ({
- databaseId,
- target,
- workspaceId,
-}: UseTransformValidationParams) => {
- const [validateTableName] = useValidateTableNameMutation();
-
- const validateTableNameDebounceRef = useRef<{
- timeoutId?: ReturnType<typeof setTimeout>;
- pending?: { resolve: (message: string) => void };
- }>({});
-
- // I wasn't able to simplify this logic any further, but maybe a review would be nice.
- // We wrap debounced validation call in a promise to properly set form state,
- // and we need to handle pending state to prevent multiple validation calls.
- const debouncedValidateTableName = useCallback(
- ({ name, schema }: { name: string; schema?: string }) => {
- const debounceState = validateTableNameDebounceRef.current;
-
- if (debounceState.timeoutId) {
- clearTimeout(debounceState.timeoutId);
- }
-
- debounceState.pending?.resolve("OK");
- debounceState.pending = undefined;
-
- if (databaseId == null) {
- return t`Database ID is missing`;
- }
-
- return new Promise<string>((resolve) => {
- const pending = { resolve };
- debounceState.pending = pending;
-
- debounceState.timeoutId = setTimeout(async () => {
- debounceState.timeoutId = undefined;
-
- let message: string;
- try {
- message = await validateTableName({
- id: workspaceId,
- db_id: databaseId,
- target: { type: "table", name, schema: schema ?? null },
- }).unwrap();
- } catch (error) {
- message = getErrorMessage(error);
- }
-
- if (debounceState.pending === pending) {
- debounceState.pending = undefined;
- resolve(message);
- }
- }, 300);
- });
- },
- [databaseId, validateTableName, workspaceId],
- );
-
- const yupSchema = useMemo(
- () => ({
- targetName: Yup.string()
- .required("Target table name is required")
- .test(async (value, context) => {
- if (!value) {
- return context.createError({
- message: t`Target table name is required`,
- });
- }
-
- const schema = context.parent.targetSchema;
-
- if (target && target.name === value && target.schema === schema) {
- return true;
- }
-
- const message = await debouncedValidateTableName({
- name: value,
- schema,
- });
-
- return message === "OK" ? true : context.createError({ message });
- }),
- }),
- [debouncedValidateTableName, target],
- );
-
- return yupSchema;
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/WorkspacePage.module.css b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/WorkspacePage.module.css
deleted file mode 100644
index 310c010425f..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/WorkspacePage.module.css
+++ /dev/null
@@ -1,26 +0,0 @@
-.resizing {
- user-select: none;
-}
-
-.tabsPanel {
- display: flex;
- gap: 0.5rem;
- flex-wrap: nowrap;
- overflow: auto;
- scrollbar-width: thin;
-
- &::before {
- display: none;
- }
-
- & button {
- border-radius: 0;
- }
-}
-
-.sidebarResizableBox {
- display: flex;
- flex-shrink: 0;
- position: relative;
- height: 100%;
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/WorkspacePage.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/WorkspacePage.tsx
deleted file mode 100644
index ade77af1421..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/WorkspacePage.tsx
+++ /dev/null
@@ -1,590 +0,0 @@
-import type { DragEndEvent } from "@dnd-kit/core";
-import { DndContext, PointerSensor, useSensor } from "@dnd-kit/core";
-import {
- restrictToHorizontalAxis,
- restrictToParentElement,
-} from "@dnd-kit/modifiers";
-import {
- SortableContext,
- arrayMove,
- horizontalListSortingStrategy,
-} from "@dnd-kit/sortable";
-import classNames from "classnames";
-import { useCallback, useEffect, useRef, useState } from "react";
-import { ResizableBox } from "react-resizable";
-import type { Route } from "react-router";
-import { replace } from "react-router-redux";
-import { useLocation } from "react-use";
-import { t } from "ttag";
-
-import { NotFound } from "metabase/common/components/ErrorPages";
-import { LeaveRouteConfirmModal } from "metabase/common/components/LeaveConfirmModal";
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { ResizeHandle } from "metabase/common/components/ResizeHandle";
-import { Sortable } from "metabase/common/components/Sortable";
-import { PaneHeaderInput } from "metabase/data-studio/common/components/PaneHeader";
-import { NAME_MAX_LENGTH } from "metabase/transforms/constants";
-import {
- ActionIcon,
- Box,
- Button,
- Flex,
- Group,
- Icon,
- Stack,
- Tabs,
-} from "metabase/ui";
-import { useDispatch } from "metabase/utils/redux";
-import { checkNotNull } from "metabase/utils/types";
-import * as Urls from "metabase/utils/urls";
-import { MergeWorkspaceModal } from "metabase-enterprise/data-studio/workspaces/components/MergeWorkspaceModal/MergeWorkspaceModal";
-import { RunWorkspaceMenu } from "metabase-enterprise/data-studio/workspaces/components/RunWorkspaceMenu/RunWorkspaceMenu";
-
-import { isWorkspaceUninitialized } from "../../utils";
-
-import { AddTransformMenu } from "./AddTransformMenu";
-import { CodeTab } from "./CodeTab/CodeTab";
-import { DataTab, DataTabSidebar } from "./DataTab";
-import { GraphTab } from "./GraphTab";
-import { SetupTab } from "./SetupTab";
-import { TransformTab } from "./TransformTab/TransformTab";
-import styles from "./WorkspacePage.module.css";
-import {
- WorkspaceProvider,
- type WorkspaceTab,
- getTransformId,
- getTransformTabId,
- useWorkspace,
-} from "./WorkspaceProvider";
-import { useWorkspaceActions } from "./useWorkspaceActions";
-import { useWorkspaceData } from "./useWorkspaceData";
-
-const DEFAULT_SIDEBAR_WIDTH = 400;
-
-type WorkspacePageProps = {
- params: {
- workspaceId: string;
- };
- route: Route;
- transformId?: string;
-};
-
-function WorkspacePageContent({
- params,
- route,
- transformId,
-}: WorkspacePageProps) {
- const pointerSensor = useSensor(PointerSensor, {
- activationConstraint: { distance: 10 },
- });
- const dispatch = useDispatch();
- const workspaceId = parseInt(params.workspaceId, 10);
-
- const {
- openedTabs,
- activeTransformRef,
- activeTable,
- activeTab,
- setActiveTab,
- setActiveTable,
- setActiveTransformRef,
- removeOpenedTab,
- setOpenedTabs,
- addOpenedTransform,
- hasUnsavedChanges,
- unsavedTransforms,
- } = useWorkspace();
-
- const [isResizing, setIsResizing] = useState(false);
- const [isMergeModalOpen, setIsMergeModalOpen] = useState(false);
-
- const { tab, setTab, ref: tabsListRef } = useWorkspaceUiTabs();
-
- // Data fetching
- const {
- workspace,
- workspaceTransforms,
- availableTransforms,
- allTransforms,
- setupStatus,
- error,
- isLoading,
- isLoadingWorkspace,
- isLoadingWorkspaceTransforms,
- isArchived,
- isPending,
- } = useWorkspaceData({ workspaceId, unsavedTransforms });
- const databaseId = workspace?.database_id;
-
- // Workspace actions
- const {
- isMerging,
- runningTransforms,
- handleMergeWorkspace,
- handleWorkspaceNameChange,
- handleTableSelect,
- handleRunTransformAndShowPreview,
- handleTransformClick,
- handleNavigateToTransform,
- } = useWorkspaceActions({
- workspaceId,
- workspace,
- onOpenTab: setTab,
- workspaceTransforms,
- availableTransforms,
- });
-
- useEffect(() => {
- // Handle transformId URL param - initialize transform tab if redirected from transform page
- if (!transformId || isLoading) {
- return;
- }
-
- (async () => {
- const parsedId = parseInt(transformId, 10);
- await handleNavigateToTransform(isNaN(parsedId) ? transformId : parsedId);
-
- dispatch(replace(Urls.dataStudioWorkspace(workspaceId)));
- })();
- }, [
- transformId,
- isLoading,
- workspaceId,
- handleNavigateToTransform,
- dispatch,
- ]);
-
- const handleTabClose = useCallback(
- (event: React.MouseEvent, tab: WorkspaceTab, index: number) => {
- event.stopPropagation();
-
- const isActive =
- (tab.type === "transform" &&
- activeTransformRef &&
- getTransformId(activeTransformRef) ===
- getTransformId(tab.transformRef)) ||
- (tab.type === "table" && activeTable?.tableId === tab.table.tableId);
- const remaining = openedTabs.filter((item) => item.id !== tab.id);
-
- removeOpenedTab(tab.id);
-
- if (!isActive) {
- return;
- }
-
- // Prefer previous tab, otherwise use next tab (which is now at the same index after filtering)
- const fallback = remaining[index - 1] ?? remaining[index] ?? undefined;
-
- if (fallback) {
- setActiveTab(fallback);
- setTab(fallback.id);
- } else {
- setActiveTab(null);
- setTab("setup");
- }
- },
- [
- activeTransformRef,
- activeTable,
- removeOpenedTab,
- setActiveTab,
- setTab,
- openedTabs,
- ],
- );
-
- const handleTabDragEnd = useCallback(
- (event: DragEndEvent) => {
- const activeId = event.active.id;
- const overId = event.over?.id;
- if (typeof activeId === "string" && typeof overId === "string") {
- const activeIndex = openedTabs.findIndex(({ id }) => id === activeId);
- const overIndex = openedTabs.findIndex(({ id }) => id === overId);
- const reorderedTabs = arrayMove(openedTabs, activeIndex, overIndex);
- setOpenedTabs(reorderedTabs);
-
- // Activate the dragged tab after reordering
- const draggedTab = reorderedTabs.find((tab) => tab.id === activeId);
- if (draggedTab) {
- setActiveTab(draggedTab);
- }
- }
- },
- [openedTabs, setOpenedTabs, setActiveTab],
- );
-
- const handleTabChange = useCallback(
- (newTab: string | null) => {
- if (newTab) {
- setTab(newTab);
- }
- },
- [setTab],
- );
-
- if (error || isLoadingWorkspace) {
- return (
- <Stack h="100%" justify="center">
- <LoadingAndErrorWrapper error={error} loading={isLoadingWorkspace} />
- </Stack>
- );
- }
-
- if (!workspace) {
- return <NotFound />;
- }
-
- return (
- <Stack
- bg="background-primary"
- className={classNames({
- [styles.resizing]: isResizing,
- })}
- data-testid="workspace-page"
- h="100%"
- gap={0}
- >
- <Group
- px="md"
- py="sm"
- style={{ borderBottom: "1px solid var(--mb-color-border)" }}
- justify="space-between"
- >
- <Flex gap="xs" align="center">
- <Icon name="git_branch" size="1rem" aria-hidden />
- <PaneHeaderInput
- initialValue={workspace.name}
- placeholder={t`Workspace name`}
- maxLength={NAME_MAX_LENGTH}
- onChange={handleWorkspaceNameChange}
- readOnly={isArchived}
- />
- </Flex>
- <Flex gap="sm">
- <RunWorkspaceMenu
- workspaceId={workspaceId}
- disabled={
- isArchived ||
- hasUnsavedChanges ||
- workspaceTransforms.length === 0
- }
- />
- <Button
- variant="filled"
- onClick={() => setIsMergeModalOpen(true)}
- loading={isMerging}
- disabled={
- isArchived ||
- isPending ||
- hasUnsavedChanges ||
- workspaceTransforms.length === 0
- }
- size="xs"
- >
- {t`Merge`}
- </Button>
- </Flex>
- </Group>
-
- <Group
- align="flex-start"
- gap={0}
- flex="1 1 auto"
- wrap="nowrap"
- style={{ overflow: "hidden" }}
- >
- <Box
- data-testid="workspace-content"
- h="100%"
- style={{
- flex: "1 1 auto",
- minWidth: 0,
- borderRight: "1px solid var(--mb-color-border)",
- }}
- pos="relative"
- >
- <Tabs
- defaultValue="setup"
- display="flex"
- h="100%"
- style={{ flexDirection: "column" }}
- value={tab}
- onChange={handleTabChange}
- >
- <Flex
- wrap="nowrap"
- flex="0 0 auto"
- px="md"
- style={{ borderBottom: "1px solid var(--mb-color-border)" }}
- >
- <DndContext
- onDragEnd={handleTabDragEnd}
- modifiers={[restrictToHorizontalAxis, restrictToParentElement]}
- sensors={[pointerSensor]}
- >
- <SortableContext
- items={openedTabs}
- strategy={horizontalListSortingStrategy}
- >
- <Tabs.List
- ref={tabsListRef}
- className={styles.tabsPanel}
- data-testid="workspace-tabs"
- >
- <Tabs.Tab value="setup" onClick={() => setActiveTab(null)}>
- <Group gap="xs" wrap="nowrap">
- <Icon name="database" aria-hidden />
- {t`Setup`}
- </Group>
- </Tabs.Tab>
- <Tabs.Tab value="graph" onClick={() => setActiveTab(null)}>
- <Group gap="xs" wrap="nowrap">
- <Icon name="dependencies" aria-hidden />
- {t`Graph`}
- </Group>
- </Tabs.Tab>
-
- {openedTabs.map((tab, index) => (
- <Sortable
- id={tab.id}
- as="div"
- key={tab.id}
- draggingStyle={{ opacity: 0.5 }}
- >
- <Tabs.Tab
- draggable
- key={tab.id}
- value={tab.id}
- onClick={() => {
- setActiveTab(tab);
- }}
- onMouseDown={(event) => {
- // close tab on middle-click (mouse wheel)
- if (event.button === 1) {
- handleTabClose(event, tab, index);
- }
- }}
- >
- <Group gap="xs" wrap="nowrap">
- <Icon
- name={
- tab.type === "transform"
- ? "pivot_table"
- : "table"
- }
- aria-hidden
- />
- {tab.name}
- <ActionIcon
- component="span"
- size="1rem"
- p="0"
- ml="xs"
- onClick={(event) =>
- handleTabClose(event, tab, index)
- }
- >
- <Icon name="close" size={10} aria-hidden />
- </ActionIcon>
- </Group>
- </Tabs.Tab>
- </Sortable>
- ))}
- </Tabs.List>
- </SortableContext>
- </DndContext>
- </Flex>
-
- <Box flex={1} mih={0}>
- <Tabs.Panel value="setup" h="100%" p="md">
- <SetupTab
- databaseId={databaseId}
- workspace={workspace}
- setupStatus={setupStatus}
- />
- </Tabs.Panel>
- <Tabs.Panel
- bg="background-secondary"
- value="graph"
- h="100%"
- p="md"
- >
- <GraphTab workspaceId={workspace?.id} />
- </Tabs.Panel>
-
- {activeTable && activeTab?.type === "table" && (
- <Tabs.Panel value={activeTab.id} h="100%">
- <DataTab
- workspaceId={workspace?.id}
- databaseId={workspace?.database_id ?? null}
- tableId={activeTable.tableId}
- transformId={activeTable.transformId}
- query={activeTable.query}
- pythonPreviewResult={activeTable.pythonPreviewResult}
- />
- </Tabs.Panel>
- )}
-
- {activeTransformRef && (
- <Tabs.Panel
- value={getTransformTabId(activeTransformRef)}
- h="100%"
- style={{ overflow: "auto" }}
- >
- <TransformTab
- databaseId={checkNotNull(workspace.database_id)}
- disabled={isArchived || isPending}
- workspaceId={workspaceId}
- workspaceTransforms={workspaceTransforms}
- onSaveTransform={(transform) => {
- // After adding first transform to a workspace,
- // show 'Setup' tab with initialization status log.
- if (isWorkspaceUninitialized(workspace)) {
- setActiveTransformRef(transform);
- setTab("setup");
- } else {
- setActiveTransformRef(transform);
- setTab(getTransformTabId(transform));
- }
- }}
- />
- </Tabs.Panel>
- )}
- </Box>
- </Tabs>
- </Box>
-
- <ResizableBox
- axis="x"
- width={DEFAULT_SIDEBAR_WIDTH}
- height={Infinity}
- resizeHandles={["w"]}
- handle={<ResizeHandle />}
- minConstraints={[250, Infinity]}
- maxConstraints={[600, Infinity]}
- onResizeStart={() => setIsResizing(true)}
- onResizeStop={() => setIsResizing(false)}
- className={styles.sidebarResizableBox}
- >
- <Box data-testid="workspace-sidebar" h="100%" w="100%">
- <Tabs defaultValue="code">
- <Flex
- px="md"
- align="center"
- style={{ borderBottom: "1px solid var(--mb-color-border)" }}
- >
- <Tabs.List className={styles.tabsPanel}>
- <Tabs.Tab value="code">{t`Code`}</Tabs.Tab>
- <Tabs.Tab value="data">{t`Data`}</Tabs.Tab>
- </Tabs.List>
- {databaseId && (
- <AddTransformMenu
- databaseId={databaseId}
- disabled={isArchived}
- />
- )}
- </Flex>
- <Tabs.Panel value="code" p="md">
- <CodeTab
- readOnly={isArchived || isPending}
- activeTransformId={
- activeTransformRef
- ? getTransformId(activeTransformRef)
- : undefined
- }
- databaseId={databaseId}
- workspaceId={workspace.id}
- workspaceTransforms={allTransforms}
- isLoadingWorkspaceTransforms={isLoadingWorkspaceTransforms}
- onTransformClick={(transformRef) => {
- addOpenedTransform(transformRef);
- setTab(getTransformTabId(transformRef));
- if (activeTable) {
- setActiveTable(null);
- }
- }}
- />
- </Tabs.Panel>
- <Tabs.Panel value="data" p="md">
- <DataTabSidebar
- readOnly={isArchived || isPending}
- workspaceTransforms={workspaceTransforms}
- databaseId={databaseId}
- selectedTableId={activeTable?.tableId}
- runningTransforms={runningTransforms}
- workspaceId={workspace.id}
- onTransformClick={handleTransformClick}
- onTableSelect={handleTableSelect}
- onRunTransform={handleRunTransformAndShowPreview}
- />
- </Tabs.Panel>
- </Tabs>
- </Box>
- </ResizableBox>
- </Group>
-
- {isMergeModalOpen && (
- <MergeWorkspaceModal
- onClose={() => setIsMergeModalOpen(false)}
- onSubmit={handleMergeWorkspace}
- isLoading={isMerging}
- isDisabled={isPending}
- workspaceId={workspaceId}
- workspaceName={workspace?.name ?? ""}
- workspaceTransforms={workspaceTransforms}
- />
- )}
-
- <LeaveRouteConfirmModal isEnabled={hasUnsavedChanges} route={route} />
- </Stack>
- );
-}
-
-export const WorkspacePage = ({ params, route }: WorkspacePageProps) => {
- const workspaceId = Number(params.workspaceId);
- const { search } = useLocation();
- const transformId = new URLSearchParams(search).get("transformId");
-
- return (
- <WorkspaceProvider workspaceId={workspaceId}>
- <WorkspacePageContent
- key={workspaceId}
- params={params}
- route={route}
- transformId={transformId ?? undefined}
- />
- </WorkspaceProvider>
- );
-};
-
-function useWorkspaceUiTabs() {
- const { activeTab } = useWorkspace();
- const tabsListRef = useRef<HTMLDivElement>(null);
- const [tab, setTab] = useState<string>("setup");
-
- useEffect(() => {
- // Sync UI tabs with active tab changes from workspace.
- if (activeTab) {
- setTab(activeTab.id);
- } else {
- setTab((tab) => (["setup", "graph"].includes(tab) ? tab : "setup"));
- }
- }, [activeTab, setTab]);
-
- useEffect(() => {
- // Scroll to active tab on change.
- if (tabsListRef.current && tab) {
- const activeTabElement =
- tabsListRef.current.querySelector(`[data-active="true"]`);
-
- if (activeTabElement) {
- activeTabElement.scrollIntoView({
- behavior: "smooth",
- block: "nearest",
- });
- }
- }
- }, [tab]);
-
- return { tab, setTab, ref: tabsListRef };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/WorkspaceProvider.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/WorkspaceProvider.tsx
deleted file mode 100644
index 23c87fa0d22..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/WorkspaceProvider.tsx
+++ /dev/null
@@ -1,781 +0,0 @@
-import type { ReactNode } from "react";
-import {
- createContext,
- useCallback,
- useContext,
- useEffect,
- useMemo,
- useState,
-} from "react";
-import { t } from "ttag";
-
-import { isSameSource } from "metabase/transforms/utils";
-import type {
- DatasetQuery,
- DraftTransformSource,
- TableId,
- TaggedTransform,
- TransformTargetType,
- UnsavedTransform,
- WorkspaceId,
- WorkspaceTransform,
-} from "metabase-types/api";
-import { isUnsavedTransform, isWorkspaceTransform } from "metabase-types/api";
-
-import { useActiveTransform } from "./useActiveTransform";
-
-export interface OpenTable {
- tableId: TableId | null;
- name: string;
- schema?: string | null;
- transformId?: string;
- query?: DatasetQuery;
- pythonPreviewResult?: any;
-}
-
-export interface EditedTransform {
- name: string;
- source: DraftTransformSource;
- target: {
- name: string;
- schema: string | null;
- type: TransformTargetType;
- };
-}
-
-/** Union type for all transform variants used in workspace */
-export type AnyWorkspaceTransform =
- | TaggedTransform
- | WorkspaceTransform
- | UnsavedTransform;
-
-export type AnyWorkspaceTransformRef =
- | Pick<TaggedTransform, "id" | "type" | "name">
- | Pick<WorkspaceTransform, "ref_id" | "type" | "name">
- | Pick<UnsavedTransform, "id" | "type" | "name">;
-
-export interface Tab {
- id: string;
- name: string;
- type: "transform" | "table";
-}
-
-export interface TransformTab extends Tab {
- type: "transform";
- transformRef: AnyWorkspaceTransformRef;
-}
-
-export interface TableTab extends Tab {
- type: "table";
- table: OpenTable;
-}
-
-export type WorkspaceTab = TransformTab | TableTab;
-
-export interface WorkspaceContextValue {
- workspaceId: WorkspaceId;
- openedTabs: WorkspaceTab[];
- activeTab: WorkspaceTab | null;
- activeTable: OpenTable | null;
- activeTransformRef: AnyWorkspaceTransformRef | null;
- activeEditedTransform?: EditedTransform | null;
- setActiveTab: (tab: WorkspaceTab | null) => void;
- setActiveTransformRef: (transformRef: AnyWorkspaceTransformRef) => void;
- setActiveTable: (table: OpenTable | null) => void;
- addOpenedTab: (tab: WorkspaceTab, activate?: boolean) => void;
- removeOpenedTab: (tabId: string) => void;
- setOpenedTabs: (tabs: WorkspaceTab[]) => void;
- addOpenedTransform: (transformRef: AnyWorkspaceTransformRef) => void;
- removeWorkspaceTransform: (transformId: string | number) => void;
- editedTransforms: Map<number | string, EditedTransform>;
- patchEditedTransform: (
- transformId: number | string,
- patch: Partial<EditedTransform>,
- ) => void;
- removeEditedTransform: (transformId: string | number) => void;
- updateTransformState: (transform: WorkspaceTransform) => void;
- updateTab: <T extends WorkspaceTab>(tabId: string, patch: Partial<T>) => void;
- hasUnsavedChanges: boolean;
- hasTransformEdits: (originalTransform: AnyWorkspaceTransform) => boolean;
- unsavedTransforms: UnsavedTransform[];
- addUnsavedTransform: (source: DraftTransformSource) => void;
- removeUnsavedTransform: (transformId: number) => void;
-}
-
-const WorkspaceContext = createContext<WorkspaceContextValue | undefined>(
- undefined,
-);
-
-interface WorkspaceState {
- openedTabs: WorkspaceTab[];
- activeTab: WorkspaceTab | null;
- activeTable: OpenTable | null;
- activeTransformRef: AnyWorkspaceTransformRef | null;
- activeEditedTransform?: AnyWorkspaceTransform | null;
- editedTransforms: Map<number | string, EditedTransform>;
- unsavedTransforms: UnsavedTransform[];
- nextUnsavedTransformIndex: number;
-}
-
-interface WorkspaceProviderProps {
- children: ReactNode;
- workspaceId: number;
-}
-
-/** Get the unique identifier used for tabs and transform lookups */
-export function getTransformId(
- transformRef: AnyWorkspaceTransformRef,
-): string | number {
- if (transformRef.type === "workspace-transform") {
- return transformRef.ref_id;
- }
- return transformRef.id;
-}
-
-/** Get the tab ID for a transform */
-export function getTransformTabId(
- transformRef: AnyWorkspaceTransformRef,
-): string {
- return `transform-${getTransformId(transformRef)}`;
-}
-
-/** Get the numeric transform ID (for metabot, RunButton, etc.) */
-export function getNumericTransformId(
- transform: AnyWorkspaceTransform,
-): number | undefined {
- if (isWorkspaceTransform(transform)) {
- return transform.global_id ?? undefined;
- }
- return transform.id;
-}
-
-const createEmptyWorkspaceState = (): WorkspaceState => ({
- openedTabs: [],
- activeTransformRef: null,
- activeTable: null,
- activeTab: null,
- editedTransforms: new Map<number | string, EditedTransform>(),
- unsavedTransforms: [],
- nextUnsavedTransformIndex: 0,
-});
-
-export const WorkspaceProvider = ({
- children,
- workspaceId,
-}: WorkspaceProviderProps) => {
- const [workspaceStates, setWorkspaceStates] = useState<
- Map<WorkspaceId, WorkspaceState>
- >(new Map());
-
- const currentState = useMemo(() => {
- return workspaceStates.get(workspaceId) ?? createEmptyWorkspaceState();
- }, [workspaceId, workspaceStates]);
-
- useEffect(() => {
- setWorkspaceStates((previous) => {
- return previous.has(workspaceId)
- ? previous
- : new Map(previous).set(workspaceId, currentState);
- });
- }, [currentState, workspaceId]);
-
- const {
- openedTabs,
- activeTransformRef,
- activeTable,
- activeTab,
- unsavedTransforms,
- } = currentState;
-
- const { data: activeTransform } = useActiveTransform({
- transformRef: activeTransformRef,
- unsavedTransforms,
- workspaceId,
- });
-
- const updateWorkspaceState = useCallback(
- (updater: (state: WorkspaceState) => WorkspaceState) => {
- setWorkspaceStates((prev) => {
- const currentState =
- prev.get(workspaceId) ?? createEmptyWorkspaceState();
- const newState = updater(currentState);
- return new Map(prev).set(workspaceId, newState);
- });
- },
- [workspaceId],
- );
-
- const setActiveTab = useCallback(
- (tab: WorkspaceTab | null) => {
- updateWorkspaceState((state) => {
- const newActiveTab = tab;
- let newActiveTransformRef = state.activeTransformRef;
- let newActiveTable = state.activeTable;
-
- if (tab?.type === "transform") {
- newActiveTransformRef = tab.transformRef;
- newActiveTable = null;
- } else if (tab?.type === "table") {
- newActiveTable = tab.table;
- newActiveTransformRef = null;
- } else {
- newActiveTransformRef = null;
- newActiveTable = null;
- }
-
- return {
- ...state,
- activeTab: newActiveTab,
- activeTransformRef: newActiveTransformRef,
- activeTable: newActiveTable,
- };
- });
- },
- [updateWorkspaceState],
- );
-
- const addOpenedTab = useCallback(
- (tab: WorkspaceTab) => {
- updateWorkspaceState((state) => {
- const exists = state.openedTabs.some((item) => item.id === tab.id);
- if (exists) {
- return {
- ...state,
- openedTabs: state.openedTabs.map((item) =>
- item.id === tab.id ? tab : item,
- ),
- activeTab: tab,
- activeTransformRef:
- tab.type === "transform"
- ? tab.transformRef
- : state.activeTransformRef,
- activeTable: tab.type === "table" ? tab.table : state.activeTable,
- };
- }
-
- const newOpenedTabs = [...state.openedTabs, tab];
- return {
- ...state,
- openedTabs: newOpenedTabs,
- activeTab: tab,
- activeTransformRef:
- tab.type === "transform"
- ? tab.transformRef
- : state.activeTransformRef,
- activeTable: tab.type === "table" ? tab.table : state.activeTable,
- };
- });
- },
- [updateWorkspaceState],
- );
-
- const removeOpenedTab = useCallback(
- (tabId: string) => {
- updateWorkspaceState((state) => {
- const filteredTabs = state.openedTabs.filter(
- (item) => item.id !== tabId,
- );
-
- const removedTab = state.openedTabs.find((item) => item.id === tabId);
- const wasActive = state.activeTab?.id === tabId;
-
- let newActiveTab = state.activeTab;
- let newActiveTransformRef = state.activeTransformRef;
- let newActiveTable = state.activeTable;
-
- if (wasActive && removedTab) {
- const currentIndex = state.openedTabs.findIndex(
- (item) => item.id === tabId,
- );
-
- const preferPrevious = currentIndex > 0;
- const fallbackTab = preferPrevious
- ? state.openedTabs[currentIndex - 1]
- : filteredTabs[0];
-
- if (fallbackTab) {
- newActiveTab = fallbackTab;
- newActiveTransformRef =
- fallbackTab.type === "transform"
- ? fallbackTab.transformRef
- : null;
- newActiveTable =
- fallbackTab.type === "table" ? fallbackTab.table : null;
- } else {
- newActiveTab = null;
- newActiveTransformRef = null;
- newActiveTable = null;
- }
- }
-
- return {
- ...state,
- openedTabs: filteredTabs,
- activeTab: newActiveTab,
- activeTransformRef: newActiveTransformRef,
- activeTable: newActiveTable,
- };
- });
- },
- [updateWorkspaceState],
- );
-
- const setOpenedTabs = useCallback(
- (tabs: WorkspaceTab[]) => {
- updateWorkspaceState((state) => ({
- ...state,
- openedTabs: tabs,
- }));
- },
- [updateWorkspaceState],
- );
-
- const setActiveTransformRef = useCallback(
- (transformRef: AnyWorkspaceTransformRef) => {
- updateWorkspaceState((state) => {
- const transformTabId = getTransformTabId(transformRef);
- const existingTab = state.openedTabs.find(
- (tab) => tab.type === "transform" && tab.id === transformTabId,
- );
-
- if (existingTab) {
- return {
- ...state,
- activeTab: existingTab,
- activeTransformRef: transformRef,
- activeTable: null,
- };
- } else {
- const newTransformTab: TransformTab = {
- id: transformTabId,
- name: transformRef.name,
- type: "transform",
- transformRef: transformRef,
- };
-
- return {
- ...state,
- openedTabs: [...state.openedTabs, newTransformTab],
- activeTab: newTransformTab,
- activeTransformRef: transformRef,
- activeTable: null,
- };
- }
- });
- },
- [updateWorkspaceState],
- );
-
- const addOpenedTransform = useCallback(
- (transformRef: AnyWorkspaceTransformRef) => {
- const transformTab: TransformTab = {
- id: getTransformTabId(transformRef),
- name: transformRef.name,
- type: "transform",
- transformRef: transformRef,
- };
- addOpenedTab(transformTab);
- },
- [addOpenedTab],
- );
-
- const removeWorkspaceTransform = useCallback(
- (transformId: string | number) => {
- removeOpenedTab(`transform-${transformId}`);
- for (const tab of openedTabs) {
- if (tab.type === "table" && tab.table.transformId === transformId) {
- removeOpenedTab(tab.id);
- }
- }
- },
- [removeOpenedTab, openedTabs],
- );
-
- const patchEditedTransform = useCallback(
- (transformId: number | string, patch: Partial<EditedTransform>) => {
- updateWorkspaceState((state) => {
- if (!activeTransform) {
- return state;
- }
-
- const currentTransform =
- state.editedTransforms.get(transformId) ?? activeTransform;
- const newEditedTransform: EditedTransform = {
- name: patch.name ? patch.name : currentTransform.name,
- source: patch.source ? patch.source : currentTransform.source,
- target: patch.target ? patch.target : currentTransform.target,
- };
-
- const hasChanges =
- !isSameSource(newEditedTransform.source, activeTransform.source) ||
- newEditedTransform.name !== activeTransform.name ||
- newEditedTransform.target.name !== activeTransform.target.name;
-
- const newEditedTransforms = new Map(state.editedTransforms);
-
- if (hasChanges) {
- newEditedTransforms.set(transformId, newEditedTransform);
- } else {
- newEditedTransforms.delete(transformId);
- }
-
- const newOpenedTabs = state.openedTabs.map((tab) => {
- if (
- tab.type === "transform" &&
- getTransformId(tab.transformRef) === transformId
- ) {
- return {
- ...tab,
- name: newEditedTransform.name,
- };
- }
- return tab;
- });
-
- return {
- ...state,
- openedTabs: newOpenedTabs,
- editedTransforms: newEditedTransforms,
- };
- });
- },
- [activeTransform, updateWorkspaceState],
- );
-
- const removeEditedTransform = useCallback(
- (transformId: string | number) => {
- updateWorkspaceState((state) => {
- const newEditedTransforms = new Map(state.editedTransforms);
- newEditedTransforms.delete(transformId);
- return {
- ...state,
- editedTransforms: newEditedTransforms,
- };
- });
- },
- [updateWorkspaceState],
- );
-
- const updateTransformState = useCallback(
- (transform: WorkspaceTransform) => {
- updateWorkspaceState((state) => {
- const transformId = transform.ref_id;
- const newOpenedTabs = state.openedTabs.map((tab) => {
- if (
- tab.type === "transform" &&
- getTransformId(tab.transformRef) === transformId
- ) {
- return {
- ...tab,
- transformRef: transform,
- name: transform.name,
- };
- }
- return tab;
- });
-
- const newEditedTransforms = new Map(state.editedTransforms);
- const currentEdit = state.editedTransforms.get(transformId);
-
- if (currentEdit) {
- const hasNameChanged = currentEdit.name !== transform.name;
- const hasSourceChanged = !isSameSource(
- currentEdit.source,
- transform.source,
- );
-
- if (hasNameChanged || hasSourceChanged) {
- newEditedTransforms.set(transformId, {
- ...currentEdit,
- target: transform.target,
- });
- } else {
- newEditedTransforms.delete(transformId);
- }
- }
-
- const activeTransformId = state.activeTransformRef
- ? getTransformId(state.activeTransformRef)
- : undefined;
-
- return {
- ...state,
- openedTabs: newOpenedTabs,
- activeTransformRef:
- activeTransformId === transformId
- ? transform
- : state.activeTransformRef,
- editedTransforms: newEditedTransforms,
- };
- });
- },
- [updateWorkspaceState],
- );
-
- const updateTab = useCallback(
- <T extends WorkspaceTab>(tabId: string, patch: Partial<T>) => {
- updateWorkspaceState((state) => {
- const newOpenedTabs = state.openedTabs.map((tab): WorkspaceTab => {
- if (tab.id === tabId) {
- return { ...tab, ...patch };
- }
- return tab;
- });
-
- // Also update activeTab if it's the tab being updated
- const newActiveTab: WorkspaceTab | null =
- state.activeTab?.id === tabId
- ? { ...state.activeTab, ...patch }
- : state.activeTab;
-
- return {
- ...state,
- openedTabs: newOpenedTabs,
- activeTab: newActiveTab,
- };
- });
- },
- [updateWorkspaceState],
- );
-
- const hasUnsavedChanges =
- currentState.editedTransforms.size > 0 ||
- currentState.unsavedTransforms.length > 0;
-
- const hasTransformEdits = useCallback(
- (originalTransform: AnyWorkspaceTransform) => {
- // Unsaved transforms always have changes
- if (isUnsavedTransform(originalTransform)) {
- return true;
- }
-
- const transformId = getTransformId(originalTransform);
- const edited = currentState.editedTransforms.get(transformId);
-
- // We don't store workspace transforms sources in the provider, so we can't compare
- // changes. So we just mark all "dirty" workspace transforms as edited.
- if (isWorkspaceTransform(originalTransform) && edited) {
- return true;
- }
-
- return (
- edited != null &&
- (!isSameSource(edited.source, originalTransform.source) ||
- edited.name !== originalTransform.name ||
- edited.target.name !== originalTransform.target.name)
- );
- },
- [currentState.editedTransforms],
- );
-
- const addUnsavedTransform = useCallback(
- (source: DraftTransformSource) => {
- updateWorkspaceState((state) => {
- const currentIndex = state.nextUnsavedTransformIndex;
- const name =
- currentIndex === 0
- ? t`New transform`
- : t`New transform (${currentIndex})`;
-
- const newTransform: UnsavedTransform = {
- type: "unsaved-transform",
- id: -1 - currentIndex, // Use negative IDs to avoid collision with existing transforms
- name,
- source,
- target: {
- name: "",
- schema: null,
- type: "table",
- },
- };
-
- // Add edited transform to mark it as having changes
- const newEditedTransforms = new Map(state.editedTransforms);
- newEditedTransforms.set(newTransform.id, {
- name: newTransform.name,
- source: newTransform.source,
- target: newTransform.target,
- });
-
- // Create and add the new transform tab
- const newTransformTab: TransformTab = {
- id: getTransformTabId(newTransform),
- name: newTransform.name,
- type: "transform",
- transformRef: newTransform,
- };
-
- return {
- ...state,
- unsavedTransforms: [...state.unsavedTransforms, newTransform],
- nextUnsavedTransformIndex: currentIndex + 1,
- editedTransforms: newEditedTransforms,
- openedTabs: [...state.openedTabs, newTransformTab],
- activeTab: newTransformTab,
- activeTransformRef: newTransform,
- activeTable: null,
- };
- });
- },
- [updateWorkspaceState],
- );
-
- const removeUnsavedTransform = useCallback(
- (transformId: number) => {
- updateWorkspaceState((state) => {
- const newUnsavedTransforms = state.unsavedTransforms.filter(
- (transform) => transform.id !== transformId,
- );
-
- const newEditedTransforms = new Map(state.editedTransforms);
- newEditedTransforms.delete(transformId);
-
- // Remove from opened tabs if present
- const tabId = `transform-${transformId}`;
- const newOpenedTabs = state.openedTabs.filter(
- (tab) => tab.id !== tabId,
- );
-
- // Clear active state if this was the active transform
- const activeTransformId = state.activeTransformRef
- ? getTransformId(state.activeTransformRef)
- : undefined;
- const newActiveTransformRef =
- activeTransformId === transformId ? null : state.activeTransformRef;
- const newActiveTab =
- state.activeTab?.id === tabId ? null : state.activeTab;
-
- return {
- ...state,
- unsavedTransforms: newUnsavedTransforms,
- editedTransforms: newEditedTransforms,
- openedTabs: newOpenedTabs,
- activeTransformRef: newActiveTransformRef,
- activeTab: newActiveTab,
- };
- });
- },
- [updateWorkspaceState],
- );
-
- const setActiveTable = useCallback(
- (table: OpenTable | null) => {
- updateWorkspaceState((state) => {
- if (table) {
- const existingTab = state.openedTabs.find(
- (tab) =>
- tab.type === "table" && tab.table.tableId === table.tableId,
- );
-
- if (existingTab) {
- return {
- ...state,
- activeTab: existingTab,
- activeTable: table,
- activeTransformRef: null,
- };
- } else {
- const newTableTab: TableTab = {
- id: `table-${table.tableId}`,
- name: table.schema ? `${table.schema}.${table.name}` : table.name,
- type: "table",
- table,
- };
-
- return {
- ...state,
- openedTabs: [...state.openedTabs, newTableTab],
- activeTab: newTableTab,
- activeTable: table,
- activeTransformRef: null,
- };
- }
- } else {
- return {
- ...state,
- activeTab:
- state.activeTab?.type === "table" ? null : state.activeTab,
- activeTable: null,
- };
- }
- });
- },
- [updateWorkspaceState],
- );
-
- const activeEditedTransform = activeTransform
- ? (currentState.editedTransforms.get(getTransformId(activeTransform)) ??
- activeTransform)
- : activeTransform;
-
- const value = useMemo(
- () => ({
- workspaceId,
- openedTabs,
- activeTransformRef,
- activeTable,
- activeTab,
- activeEditedTransform,
- setActiveTab,
- setActiveTransformRef,
- setActiveTable,
- addOpenedTab,
- removeOpenedTab,
- removeWorkspaceTransform,
- setOpenedTabs,
- addOpenedTransform,
- editedTransforms: currentState.editedTransforms,
- patchEditedTransform,
- removeEditedTransform,
- updateTransformState,
- updateTab,
- hasUnsavedChanges,
- hasTransformEdits,
- unsavedTransforms: currentState.unsavedTransforms,
- addUnsavedTransform,
- removeUnsavedTransform,
- }),
- [
- workspaceId,
- openedTabs,
- activeTransformRef,
- activeTable,
- activeTab,
- activeEditedTransform,
- setActiveTab,
- setActiveTransformRef,
- setActiveTable,
- addOpenedTab,
- removeOpenedTab,
- setOpenedTabs,
- addOpenedTransform,
- removeWorkspaceTransform,
- currentState.editedTransforms,
- currentState.unsavedTransforms,
- patchEditedTransform,
- removeEditedTransform,
- updateTransformState,
- updateTab,
- hasUnsavedChanges,
- hasTransformEdits,
- addUnsavedTransform,
- removeUnsavedTransform,
- ],
- );
-
- return (
- <WorkspaceContext.Provider value={value}>
- {children}
- </WorkspaceContext.Provider>
- );
-};
-
-export const useWorkspace = (): WorkspaceContextValue => {
- const context = useContext(WorkspaceContext);
-
- if (!context) {
- throw new Error("useWorkspace must be used within a WorkspaceProvider");
- }
-
- return context;
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/components/StatusDot/StatusDot.module.css b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/components/StatusDot/StatusDot.module.css
deleted file mode 100644
index 6755084e41d..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/components/StatusDot/StatusDot.module.css
+++ /dev/null
@@ -1,7 +0,0 @@
-.statusDot {
- width: 0.5rem;
- height: 0.5rem;
- border-radius: 50%;
- background-color: var(--mb-color-warning);
- flex-shrink: 0;
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/components/StatusDot/StatusDot.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/components/StatusDot/StatusDot.tsx
deleted file mode 100644
index 5c8ec642f7b..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/components/StatusDot/StatusDot.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-import { Box } from "metabase/ui";
-
-import S from "./StatusDot.module.css";
-
-export const StatusDot = ({
- "data-testid": dataTestId,
-}: {
- "data-testid"?: string;
-}) => {
- return <Box className={S.statusDot} data-testid={dataTestId} />;
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useActiveTransform.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useActiveTransform.ts
deleted file mode 100644
index 5d021aed1ee..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useActiveTransform.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import { useMemo } from "react";
-
-import { skipToken, useGetTransformQuery } from "metabase/api";
-import { useGetWorkspaceTransformQuery } from "metabase-enterprise/api";
-import type {
- TaggedTransform,
- UnsavedTransform,
- WorkspaceId,
-} from "metabase-types/api";
-
-import type { AnyWorkspaceTransformRef } from "./WorkspaceProvider";
-
-export const useActiveTransform = ({
- transformRef,
- unsavedTransforms,
- workspaceId,
-}: {
- transformRef: AnyWorkspaceTransformRef | null;
- unsavedTransforms: UnsavedTransform[];
- workspaceId: WorkspaceId;
-}) => {
- const transformQuery = useGetTransformQuery(
- transformRef?.type === "transform" ? transformRef.id : skipToken,
- );
-
- const workspaceTransformQuery = useGetWorkspaceTransformQuery(
- transformRef?.type === "workspace-transform"
- ? { transformId: transformRef.ref_id, workspaceId }
- : skipToken,
- );
-
- const transform = useMemo(() => {
- const transform = transformQuery.data;
- const taggedTransform: TaggedTransform | null = transform
- ? { ...transform, type: "transform" }
- : null;
-
- return {
- ...transformQuery,
- data: taggedTransform,
- };
- }, [transformQuery]);
-
- const workspaceTransform = useMemo(() => {
- return {
- ...workspaceTransformQuery,
- data: workspaceTransformQuery.data ?? null,
- };
- }, [workspaceTransformQuery]);
-
- if (transformRef?.type === "transform") {
- return transform;
- }
-
- if (transformRef?.type === "workspace-transform") {
- return workspaceTransform;
- }
-
- return {
- data: unsavedTransforms.find(
- (transform) => transform.id === transformRef?.id,
- ),
- isLoading: false,
- error: undefined,
- };
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useWorkspaceActions.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useWorkspaceActions.ts
deleted file mode 100644
index a2561f8e800..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useWorkspaceActions.ts
+++ /dev/null
@@ -1,242 +0,0 @@
-import { useCallback, useState } from "react";
-import { replace } from "react-router-redux";
-import { t } from "ttag";
-
-import { useMetadataToasts } from "metabase/metadata/hooks";
-import { useDispatch } from "metabase/utils/redux";
-import * as Urls from "metabase/utils/urls";
-import {
- useLazyGetWorkspaceTablesQuery,
- useMergeWorkspaceMutation,
- useRunWorkspaceTransformMutation,
- useUpdateWorkspaceMutation,
-} from "metabase-enterprise/api";
-import type {
- ExternalTransform,
- Workspace,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-
-import {
- type OpenTable,
- type WorkspaceTab,
- useWorkspace,
-} from "./WorkspaceProvider";
-
-type UseWorkspaceActionsParams = {
- workspaceId: number;
- workspace: Workspace | undefined;
- onOpenTab: (tabId: string) => void;
- workspaceTransforms: WorkspaceTransformListItem[];
- availableTransforms: ExternalTransform[];
-};
-
-export function useWorkspaceActions({
- workspaceId,
- workspace,
- onOpenTab,
- workspaceTransforms,
- availableTransforms,
-}: UseWorkspaceActionsParams) {
- const dispatch = useDispatch();
- const { sendErrorToast, sendSuccessToast } = useMetadataToasts();
-
- const { addOpenedTab, addOpenedTransform, setActiveTransformRef } =
- useWorkspace();
- const [mergeWorkspace, { isLoading: isMerging }] =
- useMergeWorkspaceMutation();
- const [updateWorkspace] = useUpdateWorkspaceMutation();
- const [runTransform] = useRunWorkspaceTransformMutation();
- const [runningTransforms, setRunningTransforms] = useState<Set<string>>(
- new Set(),
- );
- const [getWorkspaceTables] = useLazyGetWorkspaceTablesQuery();
-
- const handleMergeWorkspace = useCallback(
- async (commitMessage: string) => {
- try {
- const response = await mergeWorkspace({
- id: workspaceId,
- commit_message: commitMessage,
- }).unwrap();
-
- if (response.errors && response.errors.length > 0) {
- sendErrorToast(
- t`Failed to merge workspace: ${response.errors.map((e: any) => e.error).join(", ")}`,
- );
- return;
- }
- dispatch(replace(Urls.transformList()));
- sendSuccessToast(
- t`Workspace '${response.workspace.name}' merged successfully`,
- );
- } catch (error) {
- sendErrorToast(t`Failed to merge workspace`);
- throw error;
- }
- },
- [workspaceId, mergeWorkspace, sendErrorToast, dispatch, sendSuccessToast],
- );
-
- const handleWorkspaceNameChange = useCallback(
- async (newName: string) => {
- if (!workspace || newName.trim() === workspace.name.trim()) {
- return;
- }
-
- try {
- await updateWorkspace({
- id: workspaceId,
- name: newName.trim(),
- }).unwrap();
- sendSuccessToast(t`Workspace renamed successfully`);
- } catch (error) {
- sendErrorToast(t`Failed to update workspace name`);
- }
- },
- [workspace, workspaceId, updateWorkspace, sendErrorToast, sendSuccessToast],
- );
-
- const handleTableSelect = useCallback(
- (table: OpenTable) => {
- const tableTab: WorkspaceTab = {
- id: `table-${table.tableId}`,
- name: table.schema ? `${table.schema}.${table.name}` : table.name,
- type: "table",
- table,
- };
- addOpenedTab(tableTab);
- onOpenTab(tableTab.id);
- },
- [addOpenedTab, onOpenTab],
- );
-
- const handleRunTransformAndShowPreview = useCallback(
- async (transform: WorkspaceTransformListItem) => {
- setRunningTransforms((prev) => new Set(prev).add(transform.ref_id));
-
- try {
- const result = await runTransform({
- workspaceId,
- transformId: transform.ref_id,
- }).unwrap();
-
- if (result.status === "failed") {
- sendErrorToast(t`Transform run failed`);
- return;
- }
-
- const { data: updatedTables, error } = await getWorkspaceTables(
- workspaceId,
- true,
- );
- const updatedOutput = updatedTables?.outputs.find(
- (t) => t.isolated.transform_id === transform.ref_id,
- );
-
- if (error) {
- sendErrorToast(t`Failed to fetch workspace tables`);
- } else if (updatedOutput?.isolated.table_id) {
- handleTableSelect({
- tableId: updatedOutput.isolated.table_id,
- name: updatedOutput.global.table,
- schema: updatedOutput.global.schema,
- transformId: transform.ref_id,
- });
- }
- } catch (error) {
- sendErrorToast(t`Failed to run transform`);
- } finally {
- setRunningTransforms((prev) => {
- const next = new Set(prev);
- next.delete(transform.ref_id);
- return next;
- });
- }
- },
- [
- workspaceId,
- runTransform,
- getWorkspaceTables,
- handleTableSelect,
- sendErrorToast,
- ],
- );
-
- const handleTransformClick = useCallback(
- async (workspaceTransform: WorkspaceTransformListItem) => {
- addOpenedTransform({
- type: "workspace-transform",
- ref_id: workspaceTransform.ref_id,
- name: workspaceTransform.name,
- });
- },
- [addOpenedTransform],
- );
-
- // Callback to navigate to a transform (used by metabot reactions and URL param)
- const handleNavigateToTransform = useCallback(
- async (targetTransformId: number | string) => {
- const transform = [...workspaceTransforms, ...availableTransforms].find(
- (transform) => {
- if ("global_id" in transform) {
- return (
- transform.global_id === targetTransformId ||
- transform.ref_id === targetTransformId
- );
- }
- return transform.id === targetTransformId;
- },
- );
-
- const isWsTransform = !!transform && "global_id" in transform;
-
- if (transform && !isWsTransform) {
- addOpenedTransform({
- type: "transform",
- id: transform.id,
- name: transform.name,
- });
- setActiveTransformRef({
- type: "transform",
- id: transform.id,
- name: transform.name,
- });
- onOpenTab(String(targetTransformId));
- } else if (transform && isWsTransform) {
- addOpenedTransform({
- type: "workspace-transform",
- ref_id: transform.ref_id,
- name: transform.name,
- });
- setActiveTransformRef({
- type: "workspace-transform",
- ref_id: transform.ref_id,
- name: transform.name,
- });
- onOpenTab(String(targetTransformId));
- } else {
- sendErrorToast(`Transform ${targetTransformId} not found`);
- }
- },
- [
- workspaceTransforms,
- availableTransforms,
- addOpenedTransform,
- setActiveTransformRef,
- onOpenTab,
- sendErrorToast,
- ],
- );
-
- return {
- isMerging,
- runningTransforms,
- handleMergeWorkspace,
- handleWorkspaceNameChange,
- handleTableSelect,
- handleRunTransformAndShowPreview,
- handleTransformClick,
- handleNavigateToTransform,
- };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useWorkspaceData.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useWorkspaceData.ts
deleted file mode 100644
index 3bc428d6668..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useWorkspaceData.ts
+++ /dev/null
@@ -1,108 +0,0 @@
-import { useMemo } from "react";
-
-import { skipToken } from "metabase/api";
-import {
- useGetExternalTransformsQuery,
- useGetWorkspaceLogQuery,
- useGetWorkspaceQuery,
- useGetWorkspaceTransformsQuery,
-} from "metabase-enterprise/api";
-import type {
- UnsavedTransform,
- WorkspaceId,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-
-type UseWorkspaceDataParams = {
- workspaceId: number;
- unsavedTransforms: UnsavedTransform[];
-};
-
-export type SetupStatus = ReturnType<typeof useWorkspaceSetupStatus>;
-
-const LOGS_POLLING_INTERVAL_LONG = 5000;
-const LOGS_POLLING_INTERVAL_SHORT = 1000;
-
-export function useWorkspaceData({
- workspaceId,
- unsavedTransforms,
-}: UseWorkspaceDataParams) {
- const {
- data: workspace,
- error: workspaceError,
- isLoading: isLoadingWorkspace,
- } = useGetWorkspaceQuery(workspaceId);
- const {
- data: workspaceTransforms = [],
- error: workspaceTransformsError,
- isLoading: isLoadingWorkspaceTransforms,
- } = useGetWorkspaceTransformsQuery(workspaceId);
- const { data: externalTransforms, isLoading: isLoadingExternalTransforms } =
- useGetExternalTransformsQuery(
- workspace?.database_id
- ? { workspaceId, databaseId: workspace?.database_id }
- : skipToken,
- );
-
- const setupStatus = useWorkspaceSetupStatus({
- pollingInterval:
- workspace?.status === "pending"
- ? LOGS_POLLING_INTERVAL_SHORT
- : LOGS_POLLING_INTERVAL_LONG,
- workspaceId,
- });
-
- const availableTransforms = useMemo(
- () => externalTransforms ?? [],
- [externalTransforms],
- );
-
- const isLoading =
- isLoadingWorkspace ||
- isLoadingWorkspaceTransforms ||
- isLoadingExternalTransforms;
- const error = workspaceError || workspaceTransformsError;
-
- const allTransforms: (UnsavedTransform | WorkspaceTransformListItem)[] =
- useMemo(
- () => [...unsavedTransforms, ...workspaceTransforms],
- [unsavedTransforms, workspaceTransforms],
- );
-
- const isArchived = workspace?.status === "archived";
-
- return {
- workspace,
- workspaceTransforms,
- availableTransforms,
- allTransforms,
- setupStatus,
- error,
- isLoading,
- isLoadingWorkspace,
- isLoadingWorkspaceTransforms,
- isArchived,
- isPending: setupStatus.workspace?.status === "pending",
- };
-}
-
-export function useWorkspaceSetupStatus({
- pollingInterval,
- workspaceId,
-}: {
- pollingInterval: number;
- workspaceId: WorkspaceId;
-}) {
- const {
- data: workspace,
- error,
- isLoading,
- } = useGetWorkspaceLogQuery(workspaceId, {
- pollingInterval,
- refetchOnMountOrArgChange: true,
- });
-
- const logs = useMemo(() => workspace?.logs ?? [], [workspace]);
-
- return { workspace, error, isLoading, logs };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useWorkspaceMetabot.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useWorkspaceMetabot.ts
deleted file mode 100644
index 656e03e2ee6..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/useWorkspaceMetabot.ts
+++ /dev/null
@@ -1,416 +0,0 @@
-import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { push } from "react-router-redux";
-import { t } from "ttag";
-
-import { useLazyGetTransformQuery } from "metabase/api";
-import { useRegisterMetabotContextProvider } from "metabase/metabot";
-import { METABOT_PROFILE_OVERRIDES } from "metabase/metabot/constants";
-import type {
- ApplySuggestionPayload,
- ApplySuggestionResult,
- MetabotSuggestionActions,
-} from "metabase/metabot/context";
-import { useMetabotEnabledEmbeddingAware } from "metabase/metabot/hooks";
-import { useMetabotAgent } from "metabase/metabot/hooks/use-metabot-agent";
-import { useMetabotReactions } from "metabase/metabot/hooks/use-metabot-reactions";
-import type {
- MetabotConverstationState,
- MetabotState,
-} from "metabase/metabot/state";
-import {
- activateSuggestedTransform,
- updateSuggestedTransformId,
-} from "metabase/metabot/state/actions";
-import { metabotActions } from "metabase/metabot/state/reducer";
-import { getMetabotState } from "metabase/metabot/state/selectors";
-import { getIsWorkspace } from "metabase/selectors/routing";
-import { useDispatch } from "metabase/utils/redux";
-import * as Urls from "metabase/utils/urls";
-import { useEnterpriseSelector } from "metabase-enterprise/redux";
-import type {
- DatabaseId,
- DraftTransformSource,
- MetabotSuggestedTransform,
- TaggedTransform,
- Transform,
- UnsavedTransform,
- WorkspaceTransformListItem,
-} from "metabase-types/api";
-import { isUnsavedTransform } from "metabase-types/api";
-
-import {
- type AnyWorkspaceTransform,
- getTransformId,
- getTransformTabId,
- useWorkspace,
-} from "./WorkspaceProvider";
-import { isSavedTransformInfo } from "./utils/guards";
-import {
- getDatabaseIdFromSource,
- setDatabaseIdOnSource,
-} from "./utils/transform-source";
-
-type MetabotConversationSnapshot = Pick<
- MetabotConverstationState,
- | "messages"
- | "history"
- | "state"
- | "activeToolCalls"
- | "errorMessages"
- | "conversationId"
-> & { suggestedTransforms: MetabotSuggestedTransform[] };
-
-type UseWorkspaceMetabotParams = {
- workspaceId: number;
- databaseId: DatabaseId | null | undefined;
- allTransforms: (UnsavedTransform | WorkspaceTransformListItem)[];
- setTab: (tab: string) => void;
- handleNavigateToTransform: (transformId: number) => void;
-};
-
-type UseWorkspaceMetabotReturn = {
- isMetabotAvailable: boolean;
- metabotContextTransform: AnyWorkspaceTransform | undefined;
- metabotContextSource: DraftTransformSource | undefined;
- setMetabotContextTransform: (
- transform: AnyWorkspaceTransform | undefined,
- ) => void;
- setMetabotContextSource: (source: DraftTransformSource | undefined) => void;
- suggestionActions: MetabotSuggestionActions;
-};
-
-export function useWorkspaceMetabot({
- workspaceId,
- databaseId,
- allTransforms,
- setTab,
- handleNavigateToTransform,
-}: UseWorkspaceMetabotParams): UseWorkspaceMetabotReturn {
- const dispatch = useDispatch();
- const isWorkspace = useEnterpriseSelector(getIsWorkspace);
- const {
- openedTabs,
- setActiveTab,
- addOpenedTransform,
- setActiveTransformRef,
- addUnsavedTransform,
- unsavedTransforms,
- patchEditedTransform,
- } = useWorkspace();
-
- const isMetabotAvailable = useMetabotEnabledEmbeddingAware();
- const { navigateToPath, setNavigateToPath } = useMetabotReactions();
- const {
- resetConversation: resetMetabotConversation,
- visible: isMetabotVisible,
- setProfileOverride,
- } = useMetabotAgent();
-
- const [getTransform] = useLazyGetTransformQuery();
-
- const metabotState = useEnterpriseSelector(getMetabotState);
- const metabotStateRef = useRef<MetabotState>(metabotState);
- const metabotSnapshots = useRef<Map<number, MetabotConversationSnapshot>>(
- new Map(),
- );
-
- const [metabotContextTransform, setMetabotContextTransform] = useState<
- AnyWorkspaceTransform | undefined
- >();
- const [metabotContextSource, setMetabotContextSource] = useState<
- DraftTransformSource | undefined
- >();
-
- const openTaggedTransformInWorkspace = useCallback(
- (nextTransform: Transform) => {
- const taggedTransform: TaggedTransform = {
- ...nextTransform,
- type: "transform",
- };
- addOpenedTransform(taggedTransform);
- setActiveTransformRef(taggedTransform);
- setTab(getTransformTabId(taggedTransform));
- },
- [addOpenedTransform, setActiveTransformRef, setTab],
- );
-
- const applySuggestion = useCallback(
- async ({
- editorTransform,
- suggestedTransform,
- }: ApplySuggestionPayload): Promise<ApplySuggestionResult> => {
- const existingTransformId =
- typeof suggestedTransform.id === "number"
- ? suggestedTransform.id
- : undefined;
-
- // If editing an existing transform, fetch and open it
- if (existingTransformId != null) {
- const targetTransform = isSavedTransformInfo(editorTransform)
- ? editorTransform
- : isSavedTransformInfo(suggestedTransform)
- ? suggestedTransform
- : undefined;
-
- if (targetTransform) {
- openTaggedTransformInWorkspace(targetTransform);
- return { status: "applied" };
- }
-
- // Try to fetch the transform if we only have an ID
- try {
- const fetchedTransform =
- await getTransform(existingTransformId).unwrap();
- openTaggedTransformInWorkspace(fetchedTransform);
- return { status: "applied" };
- } catch {
- return {
- status: "error",
- message: t`Failed to load transform`,
- };
- }
- }
-
- // Creating a new transform - create unsaved transform first, then associate suggestion
- if (!suggestedTransform.target) {
- return {
- status: "error",
- message: t`Suggestion is missing a target table`,
- };
- }
-
- const dbId = getDatabaseIdFromSource(
- suggestedTransform.source,
- databaseId,
- );
- const sourceWithDatabase = setDatabaseIdOnSource(
- suggestedTransform.source,
- dbId,
- );
-
- const suggestionId = suggestedTransform.suggestionId;
- if (!suggestionId) {
- return {
- status: "error",
- message: t`Suggestion is missing an ID`,
- };
- }
-
- // Get the count of unsaved transforms before creating a new one
- // This will be used to calculate the ID of the new transform
- const previousUnsavedCount = unsavedTransforms.length;
-
- // Create unsaved transform with the suggested source
- // This will automatically open the transform tab and set it as active
- addUnsavedTransform(sourceWithDatabase);
-
- // Calculate the expected ID of the newly created unsaved transform
- // Based on addUnsavedTransform implementation: id = -1 - currentIndex
- const expectedId = -1 - previousUnsavedCount;
-
- // Update the suggested transform's ID to match the unsaved transform
- // This associates the suggestion with the transform so apply/reject buttons show
- dispatch(
- updateSuggestedTransformId({
- suggestionId,
- newId: expectedId,
- }),
- );
-
- // Activate the suggested transform so it shows as active in the UI
- dispatch(
- activateSuggestedTransform({
- id: expectedId,
- suggestionId,
- }),
- );
-
- // Update the transform name to match the suggestion
- patchEditedTransform(expectedId, {
- name: suggestedTransform.name,
- });
-
- return { status: "applied" };
- },
- [
- databaseId,
- unsavedTransforms,
- addUnsavedTransform,
- patchEditedTransform,
- dispatch,
- getTransform,
- openTaggedTransformInWorkspace,
- ],
- );
-
- const openTransform = useCallback(
- (nextTransform: { type: "transform" } & Transform) => {
- addOpenedTransform(nextTransform);
- setActiveTransformRef(nextTransform);
- },
- [addOpenedTransform, setActiveTransformRef],
- );
-
- const suggestionActions = useMemo<MetabotSuggestionActions>(
- () => ({
- openTransform,
- applySuggestion,
- }),
- [openTransform, applySuggestion],
- );
-
- // Keep metabotStateRef in sync
- useEffect(() => {
- metabotStateRef.current = metabotState;
- }, [metabotState]);
-
- // Register database context provider for Metabot
- useRegisterMetabotContextProvider(async () => {
- if (!databaseId) {
- return;
- }
- return { default_database_id: databaseId };
- }, [databaseId]);
-
- // Switch to metabot tab when metabot becomes visible
- useEffect(() => {
- if (isMetabotAvailable && isMetabotVisible) {
- setTab("metabot");
- setActiveTab(null);
- }
- }, [isMetabotAvailable, isMetabotVisible, setActiveTab, setTab]);
-
- // Clear metabot context when the associated transform tab is closed
- useEffect(() => {
- if (
- metabotContextTransform &&
- !openedTabs.some(
- (tab) =>
- tab.type === "transform" &&
- getTransformId(tab.transformRef) ===
- getTransformId(metabotContextTransform),
- )
- ) {
- setMetabotContextTransform(undefined);
- setMetabotContextSource(undefined);
- }
- }, [openedTabs, metabotContextTransform]);
-
- // Set profile override to transforms_codegen for workspace metabot
- useEffect(() => {
- if (isMetabotAvailable) {
- setProfileOverride(METABOT_PROFILE_OVERRIDES.TRANSFORMS_CODEGEN);
- }
- }, [isMetabotAvailable, isMetabotVisible, setProfileOverride]);
-
- // Restore/save metabot conversation snapshots per workspace
- useEffect(() => {
- const snapshots = metabotSnapshots.current;
- const snapshot = snapshots.get(workspaceId);
- if (snapshot) {
- dispatch(metabotActions.setConversationSnapshot(snapshot));
- } else {
- resetMetabotConversation();
- }
-
- return () => {
- const convo = metabotStateRef.current.conversations["omnibot"];
- if (convo) {
- snapshots.set(workspaceId, {
- messages: convo.messages,
- history: convo.history,
- state: convo.state,
- activeToolCalls: convo.activeToolCalls,
- errorMessages: convo.errorMessages,
- conversationId: convo.conversationId,
- suggestedTransforms:
- metabotStateRef.current.reactions.suggestedTransforms,
- });
- }
- resetMetabotConversation();
- };
- }, [workspaceId, dispatch, resetMetabotConversation]);
-
- // Handle metabot navigation reactions
- useEffect(() => {
- if (!navigateToPath) {
- return;
- }
-
- const transformIdFromPath = (() => {
- const match = navigateToPath.match(/\/transform\/(\d+)/);
- const extracted = Urls.extractEntityId(navigateToPath);
- const idString = match?.[1] ?? (extracted ? String(extracted) : null);
- const parsed = idString ? Number(idString) : NaN;
- return Number.isFinite(parsed) ? parsed : undefined;
- })();
-
- if (transformIdFromPath != null) {
- // Check if transform exists in local workspace state first (already opened/unsaved)
- const localTransform = allTransforms.find(
- (t: UnsavedTransform | WorkspaceTransformListItem) => {
- if (isUnsavedTransform(t)) {
- return t.id === transformIdFromPath;
- }
- return t.ref_id === String(transformIdFromPath);
- },
- );
-
- if (localTransform && !isUnsavedTransform(localTransform)) {
- // For WorkspaceTransformListItem, we need to navigate to fetch full data
- handleNavigateToTransform(transformIdFromPath);
- setNavigateToPath(null);
- return;
- }
-
- // Unsaved transforms are already opened when created, so just activate the tab
- if (localTransform && isUnsavedTransform(localTransform)) {
- // Find the existing tab and activate it
- const existingTab = openedTabs.find(
- (tab) =>
- tab.type === "transform" &&
- getTransformId(tab.transformRef) === localTransform.id,
- );
- if (existingTab) {
- setActiveTab(existingTab);
- }
- setNavigateToPath(null);
- return;
- }
-
- // Otherwise fetch and open the transform
- handleNavigateToTransform(transformIdFromPath);
- setNavigateToPath(null);
- return;
- }
-
- // In workspace context, don't redirect to question pages
- // The profile override should prevent most navigate_to chunks,
- // but if one slips through, we'll just ignore it
- if (isWorkspace) {
- setNavigateToPath(null);
- return;
- }
-
- dispatch(push(navigateToPath));
- setNavigateToPath(null);
- }, [
- navigateToPath,
- allTransforms,
- openedTabs,
- setActiveTab,
- setNavigateToPath,
- handleNavigateToTransform,
- dispatch,
- isWorkspace,
- ]);
-
- return {
- isMetabotAvailable,
- metabotContextTransform,
- metabotContextSource,
- setMetabotContextTransform,
- setMetabotContextSource,
- suggestionActions,
- };
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/utils/guards.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/utils/guards.ts
deleted file mode 100644
index 7a435dbcfda..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/utils/guards.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import type {
- MetabotSuggestedTransform,
- MetabotTransformInfo,
- Transform,
-} from "metabase-types/api";
-
-export const isSavedTransformInfo = (
- transform: MetabotTransformInfo | MetabotSuggestedTransform | undefined,
-): transform is MetabotTransformInfo & Transform => {
- return Boolean(transform && "source_type" in transform);
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/utils/transform-source.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/utils/transform-source.ts
deleted file mode 100644
index dd8960c0f17..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/pages/WorkspacePage/utils/transform-source.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import type { DatabaseId, DraftTransformSource } from "metabase-types/api";
-
-/**
- * Extracts the database ID from a transform source, falling back to the provided default.
- */
-export function getDatabaseIdFromSource(
- source: DraftTransformSource,
- fallbackDatabaseId: DatabaseId | null | undefined,
-): DatabaseId | null | undefined {
- if (source.type === "query") {
- return source.query.database ?? fallbackDatabaseId ?? null;
- }
- if (source.type === "python") {
- return source["source-database"] ?? fallbackDatabaseId ?? undefined;
- }
- return fallbackDatabaseId ?? null;
-}
-
-/**
- * Creates a new source with the database ID properly set.
- */
-export function setDatabaseIdOnSource(
- source: DraftTransformSource,
- databaseId: DatabaseId | null | undefined,
-): DraftTransformSource {
- if (source.type === "python") {
- return {
- ...source,
- "source-database": databaseId ?? undefined,
- };
- }
- if (source.type === "query") {
- return {
- ...source,
- query: {
- ...source.query,
- database: databaseId ?? null,
- },
- };
- }
- return source;
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/routes.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/routes.tsx
deleted file mode 100644
index f4945e1079e..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/routes.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-import { IndexRoute, Route } from "react-router";
-
-import { WorkspaceListPage } from "./pages/WorkspaceListPage/WorkspaceListPage";
-import { WorkspacePage } from "./pages/WorkspacePage/WorkspacePage";
-
-export function getDataStudioWorkspaceRoutes() {
- return (
- <>
- <IndexRoute component={WorkspaceListPage} />
- <Route path=":workspaceId" component={WorkspacePage} />
- </>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/settings.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/settings.tsx
deleted file mode 100644
index ad94c410578..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/settings.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export const DATABASE_WORKSPACES_SETTING = "database-enable-workspaces";
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/utils.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/utils.ts
deleted file mode 100644
index 79718d49367..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/workspaces/utils.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { t } from "ttag";
-
-import type {
- CheckoutDisabledReason,
- WorkspaceSetupStatus,
-} from "metabase-types/api";
-
-export const isWorkspaceUninitialized = (workspace: {
- status: WorkspaceSetupStatus;
-}) => {
- return workspace.status === "uninitialized";
-};
-
-export function getCheckoutDisabledMessage(
- reason: CheckoutDisabledReason | undefined,
-): string | undefined {
- switch (reason) {
- case "mbql":
- return t`Transforms based on the query builder cannot be edited in a workspace.`;
- case "card-reference":
- return t`Transforms referencing other questions cannot be edited in a workspace.`;
- case null:
- case undefined:
- return undefined;
- default:
- return t`This transform cannot be edited in a workspace.`;
- }
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/utils.tsx b/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/utils.tsx
index f44bb66cc43..c34dc31f74b 100644
--- a/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/utils.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/database_routing/DatabaseRoutingSection/utils.tsx
@@ -6,7 +6,6 @@ import {
hasActionsEnabled,
hasFeature,
hasTableEditingEnabled,
- hasWorkspacesEnabled,
hasWritableConnectionDetails,
} from "metabase/admin/databases/utils";
import { Text } from "metabase/ui";
@@ -18,7 +17,6 @@ export const getDisabledFeatureMessage = (
) => {
return match({
hasActionsEnabled: hasActionsEnabled(database),
- hasWorkspacesEnabled: hasWorkspacesEnabled(database),
hasTableEditingEnabled: hasTableEditingEnabled(database),
isPersisted: hasFeature(database, "persist-models-enabled"),
isUploadDb: database.uploads_enabled,
@@ -54,10 +52,6 @@ export const getDisabledFeatureMessage = (
() =>
t`Database routing can't be enabled when a Writable Connection is enabled.`,
)
- .with(
- { hasWorkspacesEnabled: true },
- () => t`Database routing can't be enabled when workspaces are enabled.`,
- )
.with(
{ hasTableEditingEnabled: true },
() => t`Database routing can't be enabled when table editing is enabled.`,
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx
index 0e42e2c533b..b35135030b2 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx
@@ -18,11 +18,7 @@ import { t } from "ttag";
import { useMetadataToasts } from "metabase/metadata/hooks";
import { Group, useColorScheme } from "metabase/ui";
-import type {
- DependencyEntry,
- DependencyGraph,
- WorkspaceDependencyGraph,
-} from "metabase-types/api";
+import type { DependencyEntry, DependencyGraph } from "metabase-types/api";
import S from "./DependencyGraph.module.css";
import { GraphContext } from "./GraphContext";
@@ -50,7 +46,7 @@ const PRO_OPTIONS = {
};
type DependencyGraphProps = {
- graph?: DependencyGraph | WorkspaceDependencyGraph;
+ graph?: DependencyGraph;
isFetching?: boolean;
error?: unknown;
entry?: DependencyEntry;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/utils.ts
index fe119bc2483..505678720b6 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/utils.ts
@@ -23,8 +23,6 @@ export function getHeaderLabel(
: t`Tables that use ${nodeLabel}`;
case "transform":
return t`Transforms that use ${nodeLabel}`;
- case "workspace-transform":
- return t`Workspace transforms that use ${nodeLabel}`;
case "snippet":
return t`Snippets that use ${nodeLabel}`;
case "dashboard":
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/WorkspaceGraphNode.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/WorkspaceGraphNode.tsx
deleted file mode 100644
index c2ab36c82a6..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/WorkspaceGraphNode.tsx
+++ /dev/null
@@ -1,168 +0,0 @@
-import {
- Handle,
- type NodeProps,
- Position,
- useNodeConnections,
- useNodesInitialized,
-} from "@xyflow/react";
-import cx from "classnames";
-import type { MouseEvent } from "react";
-import { memo, useContext } from "react";
-
-import { useLazyGetTableQueryMetadataQuery } from "metabase/api";
-import {
- Box,
- Card,
- FixedSizeIcon,
- Group,
- Pill,
- Stack,
- Text,
- UnstyledButton,
-} from "metabase/ui";
-import type { DependencyNode } from "metabase-types/api";
-
-import type { DependentGroup } from "../../../types";
-import {
- getDependencyGroupType,
- getDependencyGroupTypeInfo,
- getNodeIcon,
- getNodeLabel,
- isSameNode,
-} from "../../../utils";
-import { GraphContext } from "../GraphContext";
-import type { GraphSelection, NodeType } from "../types";
-
-import S from "./GraphNode.module.css";
-import {
- getDependencyGroupTitle,
- getDependentGroupLabel,
- getDependentGroups,
-} from "./utils";
-
-type WorkspaceGraphNodeProps = NodeProps<NodeType>;
-
-export const WorkspaceGraphNode = memo(function ItemNode({
- data: node,
-}: WorkspaceGraphNodeProps) {
- const { selection, setSelection } = useContext(GraphContext);
- const label = getNodeLabel(node);
- const typeInfo = getDependencyGroupTypeInfo(getDependencyGroupType(node));
- const groups = getDependentGroups(node);
- const sources = useNodeConnections({ handleType: "source" });
- const targets = useNodeConnections({ handleType: "target" });
- const isSelected = selection != null && isSameNode(node, selection);
- const isInitialized = useNodesInitialized();
-
- // Fetch table data for input table nodes
- const [fetchTableMetadata] = useLazyGetTableQueryMetadataQuery();
-
- const handleClick = async () => {
- // Fetch table metadata when a table node is clicked
- if (node.type === "table" && node.data.table_id) {
- const tableData = await fetchTableMetadata(
- { id: node.data.table_id },
- true,
- ).unwrap();
- node.data.fields = tableData.fields;
- }
-
- setSelection({ id: node.id, type: node.type });
- };
-
- return (
- <>
- <Card
- className={cx(S.card, {
- [S.initialized]: isInitialized,
- [S.selected]: isSelected,
- })}
- p="lg"
- withBorder
- aria-label={label}
- aria-selected={isSelected}
- data-testid="graph-node"
- onClick={handleClick}
- >
- <Stack gap="sm">
- <Group c={typeInfo.color} gap="xs">
- <FixedSizeIcon name={getNodeIcon(node)} />
- <Box fz="sm" fw="bold" lh="1rem">
- {typeInfo.label}
- </Box>
- </Group>
- <Box fw="bold" lh="1rem">
- {label}
- </Box>
- </Stack>
- <Stack mt="md" gap="sm" align="start">
- <Box c="text-secondary" fz="sm" lh="1rem">
- {getDependencyGroupTitle(node, groups)}
- </Box>
- {groups.map((group) => (
- <Text key={group.type}>{getDependentGroupLabel(group)}</Text>
- ))}
- </Stack>
- </Card>
- {sources.length > 0 && (
- <Handle
- className={cx(S.handle, { [S.initialized]: isInitialized })}
- type="source"
- position={Position.Left}
- isConnectable={false}
- />
- )}
- {targets.length > 0 && (
- <Handle
- className={cx(S.handle, { [S.initialized]: isInitialized })}
- type="target"
- position={Position.Right}
- isConnectable={false}
- />
- )}
- </>
- );
-});
-
-type DependencyGroupButtonProps = {
- node: DependencyNode;
- group: DependentGroup;
- selection: GraphSelection | null;
- onSelectionChange: (selection: GraphSelection) => void;
-};
-
-// TODO (stasgavrylov 2026-01-15) --
-// Leave a simpler representation for rependency group right now, but will
-// probably return to this in
-function _DependencyGroupButton({
- node,
- group,
- selection,
- onSelectionChange,
-}: DependencyGroupButtonProps) {
- const isSelected =
- selection != null &&
- isSameNode(node, selection) &&
- selection.groupType === group.type;
-
- const handleClick = (event: MouseEvent<HTMLDivElement>) => {
- event.stopPropagation();
- onSelectionChange({
- id: node.id,
- type: node.type,
- groupType: group.type,
- });
- };
-
- return (
- <Pill
- key={group.type}
- component={UnstyledButton}
- className={cx(S.pill, { [S.selected]: isSelected })}
- fw="normal"
- onClick={handleClick}
- >
- {getDependentGroupLabel(group)}
- </Pill>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts
index c063a5c86fc..3424562a4ce 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts
@@ -11,7 +11,6 @@ export function getDependentGroups(node: DependencyNode): DependentGroup[] {
metric = 0,
table = 0,
transform = 0,
- "workspace-transform": workspaceTransform = 0,
snippet = 0,
dashboard = 0,
document = 0,
@@ -26,7 +25,6 @@ export function getDependentGroups(node: DependencyNode): DependentGroup[] {
{ type: "metric", count: metric },
{ type: "table", count: table },
{ type: "transform", count: transform },
- { type: "workspace-transform", count: workspaceTransform },
{ type: "snippet", count: snippet },
{ type: "dashboard", count: dashboard },
{ type: "document", count: document },
@@ -69,12 +67,6 @@ export function getDependentGroupLabel({
return ngettext(msgid`${count} table`, `${count} tables`, count);
case "transform":
return ngettext(msgid`${count} transform`, `${count} transforms`, count);
- case "workspace-transform":
- return ngettext(
- msgid`${count} workspace transform`,
- `${count} workspace transforms`,
- count,
- );
case "snippet":
return ngettext(msgid`${count} snippet`, `${count} snippet`, count);
case "dashboard":
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
index 503debd43dc..66ff431c8ee 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
@@ -5,9 +5,6 @@ import type {
DependencyEntry,
DependencyGraph,
DependencyNode,
- WorkspaceDependencyGraph,
- WorkspaceGraphDependencyEdge,
- WorkspaceGraphDependencyNode,
} from "metabase-types/api";
import type { NodeId } from "../../types";
@@ -19,17 +16,14 @@ export function getEdgeId(sourceId: NodeId, targetId: NodeId): EdgeId {
return `${sourceId}-${targetId}`;
}
-type AnyDependencyNode = DependencyNode | WorkspaceGraphDependencyNode;
-type AnyDependencyEdge = DependencyEdge | WorkspaceGraphDependencyEdge;
-
-function getNodes(nodes: AnyDependencyNode[]): NodeType[] {
+function getNodes(nodes: DependencyNode[]): NodeType[] {
return nodes.map((node) => {
const nodeId = getNodeId(node.id, node.type);
return {
id: nodeId,
type: "node",
- data: node as DependencyNode, // Cast for NodeType compatibility
+ data: node,
position: { x: 0, y: 0 },
draggable: false,
deletable: false,
@@ -37,7 +31,7 @@ function getNodes(nodes: AnyDependencyNode[]): NodeType[] {
});
}
-function getEdges(edges: AnyDependencyEdge[]): Edge[] {
+function getEdges(edges: DependencyEdge[]): Edge[] {
return edges.map((edge) => {
const sourceId = getNodeId(edge.from_entity_id, edge.from_entity_type);
const targetId = getNodeId(edge.to_entity_id, edge.to_entity_type);
@@ -54,10 +48,7 @@ function getEdges(edges: AnyDependencyEdge[]): Edge[] {
});
}
-export function getInitialGraph({
- nodes,
- edges,
-}: DependencyGraph | WorkspaceDependencyGraph): GraphData {
+export function getInitialGraph({ nodes, edges }: DependencyGraph): GraphData {
return {
nodes: getNodes(nodes),
edges: getEdges(edges),
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
index d1b543b0cad..aa2a5fc5f8d 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
@@ -60,7 +60,6 @@ export function getNodeDescription(node: DependencyNode): string | null {
switch (node.type) {
case "document":
case "sandbox":
- case "workspace-transform":
return null;
default:
return node.data.description ?? "";
@@ -103,8 +102,6 @@ export function getNodeIconWithType(
return "table";
case "transform":
return "transform";
- case "workspace-transform":
- return "transform";
case "snippet":
return "snippet";
case "dashboard":
@@ -156,17 +153,6 @@ export function getNodeLink(node: DependencyNode): NodeLink | null {
label: t`View this transform`,
url: Urls.transform(node.id),
};
- case "workspace-transform": {
- const workspaceId = node.data.workspace_id;
- const refId = node.data.ref_id;
- if (workspaceId == null) {
- return null;
- }
- return {
- label: t`View this workspace transform`,
- url: Urls.dataStudioWorkspace(workspaceId, refId),
- };
- }
case "dashboard":
return {
label: t`View this dashboard`,
@@ -346,7 +332,6 @@ export function getNodeLocationInfo(
}
return null;
case "transform":
- case "workspace-transform":
case "sandbox":
return null;
}
@@ -464,8 +449,6 @@ export function getNodeFields(node: DependencyNode): Field[] | null {
case "transform":
case "sandbox":
return node.data.table?.fields ?? [];
- case "workspace-transform":
- return [];
case "snippet":
case "dashboard":
case "document":
@@ -539,8 +522,6 @@ export function getDependencyGroupType(
return "table";
case "transform":
return "transform";
- case "workspace-transform":
- return "workspace-transform";
case "dashboard":
return "dashboard";
case "document":
@@ -570,8 +551,6 @@ export function getDependencyGroupTypeInfo(
return { label: t`Table`, color: "brand" };
case "transform":
return { label: t`Transform`, color: "warning" };
- case "workspace-transform":
- return { label: t`Workspace transform`, color: "warning" };
case "snippet":
return { label: t`Snippet`, color: "text-secondary" };
case "dashboard":
diff --git a/enterprise/frontend/src/metabase-enterprise/plugins.ts b/enterprise/frontend/src/metabase-enterprise/plugins.ts
index cddd79d4685..1741148b3d3 100644
--- a/enterprise/frontend/src/metabase-enterprise/plugins.ts
+++ b/enterprise/frontend/src/metabase-enterprise/plugins.ts
@@ -20,7 +20,6 @@ import { initializePlugin as initializeCollections } from "./collections";
import { initializePlugin as initializeContentTranslation } from "./content_translation";
import { initializePlugin as initializeContentVerification } from "./content_verification";
import { initializePlugin as initializeLibrary } from "./data-studio/library";
-import { initializePlugin as initializeWorkspaces } from "./data-studio/workspaces";
import { initializePlugin as initializeDatabaseReplication } from "./database_replication";
import { initializePlugin as initializeDatabaseRouting } from "./database_routing";
import { initializePlugin as initializeDependencies } from "./dependencies";
@@ -100,7 +99,6 @@ export function initializePlugins() {
initializeTransformsPython();
initializeSupport();
initializeTenants?.();
- initializeWorkspaces();
initializeWritableConnection();
initializeAiControls();
}
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorBody/PythonEditorBody.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorBody/PythonEditorBody.tsx
index 1c165cd172a..7e8e1b2113a 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorBody/PythonEditorBody.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorBody/PythonEditorBody.tsx
@@ -178,7 +178,6 @@ function useInitialEditorHeight(
}
if (!showResizeHandle) {
- // No preview panel (e.g. workspace) – height is not used; container uses 100%
return availableHeight;
}
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.tsx
index 8729caae3e6..ae1ceee4703 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.tsx
@@ -83,7 +83,6 @@ export function PythonTransformEditor({
};
const handleRun = () => {
- // Use custom onRun handler if provided (workspace dry-run), otherwise use internal test-run
if (onRun) {
onRun();
} else {
@@ -91,7 +90,6 @@ export function PythonTransformEditor({
}
};
- // Notify workspace when test-run completes in workspace context
useEffect(() => {
const runJustCompleted = wasRunning && !isRunning;
if (
@@ -114,10 +112,6 @@ export function PythonTransformEditor({
if (!isEditMode) {
return;
}
- // In workspaces, disable run shortcut when transform has unsaved changes (hideRunButton)
- // if (uiOptions?.hideRunButton) {
- // return;
- // }
if (isRunning) {
cancel();
} else if (isPythonTransformSource(source)) {
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.unit.spec.tsx
index 9aedae25f7d..712540d4ffa 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.unit.spec.tsx
@@ -2,8 +2,6 @@ import {
setupDatabasesEndpoints,
setupSearchEndpoints,
setupTablesEndpoints,
- setupWorkspaceCheckoutEndpoint,
- setupWorkspacesEndpoint,
} from "__support__/server-mocks";
import { renderWithProviders, screen } from "__support__/ui";
import type { PythonTransformEditorUiOptions } from "metabase/plugins/oss/transforms";
@@ -72,8 +70,6 @@ function setup({
setupDatabasesEndpoints([mockDatabase]);
setupTablesEndpoints([mockTable]);
setupSearchEndpoints([]);
- setupWorkspacesEndpoint([]);
- setupWorkspaceCheckoutEndpoint({});
renderWithProviders(
<PythonTransformEditor
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformTopBar/PythonTransformTopBar.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformTopBar/PythonTransformTopBar.tsx
index 8e86a635374..1f95e46d3e5 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformTopBar/PythonTransformTopBar.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformTopBar/PythonTransformTopBar.tsx
@@ -9,9 +9,7 @@ import { EditDefinitionButton } from "metabase/transforms/components/TransformEd
import { doesDatabaseSupportTransforms } from "metabase/transforms/utils";
import { Flex } from "metabase/ui";
import { useSelector } from "metabase/utils/redux";
-import { EditTransformMenu } from "metabase-enterprise/data-studio/workspaces/components/EditTransformMenu";
import { getIsRemoteSyncReadOnly } from "metabase-enterprise/remote_sync/selectors";
-import { hasPremiumFeature } from "metabase-enterprise/settings";
import type { Database, DatabaseId, Transform } from "metabase-types/api";
import S from "./PythonTransformTopBar.module.css";
@@ -83,18 +81,14 @@ export function PythonTransformTopBar({
)}
{showEditButton && (
<Flex ml="auto" mr="lg" align="center" h="3rem">
- {hasPremiumFeature("workspaces") ? (
- <EditTransformMenu transform={transform} />
- ) : (
- <EditDefinitionButton
- bg="transparent"
- fz="sm"
- h="1.5rem"
- px="sm"
- size="xs"
- transformId={transform.id}
- />
- )}
+ <EditDefinitionButton
+ bg="transparent"
+ fz="sm"
+ h="1.5rem"
+ px="sm"
+ size="xs"
+ transformId={transform.id}
+ />
</Flex>
)}
</Flex>
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformTopBar/PythonTransformTopBar.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformTopBar/PythonTransformTopBar.unit.spec.tsx
index 8de53cfee9e..82b09455569 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformTopBar/PythonTransformTopBar.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformTopBar/PythonTransformTopBar.unit.spec.tsx
@@ -1,15 +1,11 @@
-import userEvent from "@testing-library/user-event";
import { Route } from "react-router";
import {
setupDatabasesEndpoints,
setupSearchEndpoints,
- setupWorkspaceCheckoutEndpoint,
- setupWorkspacesEndpoint,
} from "__support__/server-mocks";
-import { renderWithProviders, screen, waitFor } from "__support__/ui";
+import { renderWithProviders, screen } from "__support__/ui";
import { createMockState } from "metabase/redux/store/mocks";
-import { hasPremiumFeature } from "metabase-enterprise/settings";
import type { Transform } from "metabase-types/api";
import {
createMockDatabase,
@@ -18,14 +14,6 @@ import {
import { PythonTransformTopBar } from "./PythonTransformTopBar";
-jest.mock("metabase-enterprise/settings", () => ({
- hasPremiumFeature: jest.fn(),
-}));
-
-const mockHasPremiumFeature = hasPremiumFeature as jest.MockedFunction<
- typeof hasPremiumFeature
->;
-
const DATABASE_ID = 1;
const mockDatabase = createMockDatabase({
id: DATABASE_ID,
@@ -59,8 +47,6 @@ function setup({
setupDatabasesEndpoints([mockDatabase]);
setupSearchEndpoints([]);
- setupWorkspacesEndpoint([]);
- setupWorkspaceCheckoutEndpoint({});
renderWithProviders(
<Route
@@ -85,36 +71,14 @@ function setup({
}
describe("PythonTransformTopBar", () => {
- beforeEach(() => {
- mockHasPremiumFeature.mockReturnValue(false);
- });
-
describe("view mode (not editing)", () => {
- it("should render EditDefinitionButton when not in edit mode and workspaces feature is disabled", () => {
- mockHasPremiumFeature.mockReturnValue(false);
+ it("should render EditDefinitionButton when not in edit mode", () => {
setup({ isEditMode: false, transform: mockPythonTransform });
expect(
screen.getByRole("link", { name: /edit definition/i }),
).toBeInTheDocument();
});
- it("should render EditTransformMenu when not in edit mode and workspaces feature is enabled", async () => {
- mockHasPremiumFeature.mockImplementation(
- (feature) => feature === "workspaces",
- );
- setup({ isEditMode: false, transform: mockPythonTransform });
-
- const editButton = await screen.findByRole("button", { name: /Edit/i });
- await waitFor(() => {
- expect(editButton).not.toHaveAttribute("data-loading", "true");
- });
-
- await userEvent.click(editButton);
-
- expect(screen.getByText("Edit definition")).toBeInTheDocument();
- expect(screen.getByText("Add to workspace")).toBeInTheDocument();
- });
-
it("should not render edit button when transform is not provided", () => {
setup({ isEditMode: false, transform: undefined });
expect(
diff --git a/frontend/src/metabase-types/api/database.ts b/frontend/src/metabase-types/api/database.ts
index 7fba227d4f1..8633266b88d 100644
--- a/frontend/src/metabase-types/api/database.ts
+++ b/frontend/src/metabase-types/api/database.ts
@@ -57,8 +57,7 @@ export type DatabaseFeature =
| "split-part"
| "collate"
| "transforms/python"
- | "transforms/table"
- | "workspace";
+ | "transforms/table";
export interface Database extends DatabaseData {
id: DatabaseId;
@@ -85,7 +84,6 @@ export interface Database extends DatabaseData {
// Only appears in GET /api/database/:id
"can-manage"?: boolean;
tables?: Table[];
- workspace_permissions_status: CheckWorkspacePermissionsResponse | null;
}
export interface DatabaseData {
@@ -258,14 +256,3 @@ export interface UpdateDatabaseRouterRequest {
id: DatabaseId;
user_attribute: string | null;
}
-
-export type CheckWorkspacePermissionsRequest = {
- id: DatabaseId;
- cached?: boolean;
-};
-
-export type CheckWorkspacePermissionsResponse = {
- status: "ok" | "failed" | "unknown";
- checked_at: string;
- error?: string;
-};
diff --git a/frontend/src/metabase-types/api/dependencies.ts b/frontend/src/metabase-types/api/dependencies.ts
index e3041511789..e2981cb8959 100644
--- a/frontend/src/metabase-types/api/dependencies.ts
+++ b/frontend/src/metabase-types/api/dependencies.ts
@@ -13,7 +13,6 @@ import type { NativeQuerySnippet } from "./snippets";
import type { SortDirection } from "./sorting";
import type { ConcreteTableId, Table } from "./table";
import type { Transform } from "./transform";
-import type { WorkspaceTransform } from "./workspace";
export type DependencyId = number;
@@ -21,7 +20,6 @@ export const DEPENDENCY_TYPES = [
"card",
"table",
"transform",
- "workspace-transform",
"snippet",
"dashboard",
"document",
@@ -37,7 +35,6 @@ export const DEPENDENCY_GROUP_TYPES = [
"metric",
"table",
"transform",
- "workspace-transform",
"snippet",
"dashboard",
"document",
@@ -80,18 +77,6 @@ export type TransformDependencyNodeData = Pick<
"name" | "description" | "table" | "creator" | "created_at" | "owner"
>;
-export type WorkspaceTransformDependencyNodeData = Pick<
- WorkspaceTransform,
- "name" | "ref_id" | "workspace_id"
-> & {
- target?: {
- db: number;
- schema: string;
- table: string;
- table_id?: number | null;
- };
-};
-
export type CardDependencyNodeData = Pick<
Card,
| "name"
@@ -163,11 +148,6 @@ export type TransformDependencyNode = BaseDependencyNode<
TransformDependencyNodeData
>;
-export type WorkspaceTransformDependencyNode = BaseDependencyNode<
- "workspace-transform",
- WorkspaceTransformDependencyNodeData
->;
-
export type CardDependencyNode = BaseDependencyNode<
"card",
CardDependencyNodeData
@@ -220,7 +200,6 @@ export type MeasureDependencyNode = BaseDependencyNode<
export type DependencyNode =
| TableDependencyNode
| TransformDependencyNode
- | WorkspaceTransformDependencyNode
| CardDependencyNode
| SnippetDependencyNode
| DashboardDependencyNode
diff --git a/frontend/src/metabase-types/api/index.ts b/frontend/src/metabase-types/api/index.ts
index f25cdc5eea2..1efb2be176c 100644
--- a/frontend/src/metabase-types/api/index.ts
+++ b/frontend/src/metabase-types/api/index.ts
@@ -65,7 +65,6 @@ export * from "./util";
export * from "./visualization";
export * from "./visualization-settings";
export * from "./visualizer";
-export * from "./workspace";
// ISO8601 timestamp
export type ISO8601Time = string;
diff --git a/frontend/src/metabase-types/api/metabot.ts b/frontend/src/metabase-types/api/metabot.ts
index d75a903320b..710e4cde335 100644
--- a/frontend/src/metabase-types/api/metabot.ts
+++ b/frontend/src/metabase-types/api/metabot.ts
@@ -48,7 +48,6 @@ export type MetabotChatContext = {
user_is_viewing: MetabotUserIsViewingContext;
current_time_with_timezone: string;
default_database_id?: number;
- workspace_id?: number;
capabilities: string[];
code_editor?: MetabotCodeEditorContext;
};
diff --git a/frontend/src/metabase-types/api/mocks/database.ts b/frontend/src/metabase-types/api/mocks/database.ts
index 1d32b3e1daa..47795d33283 100644
--- a/frontend/src/metabase-types/api/mocks/database.ts
+++ b/frontend/src/metabase-types/api/mocks/database.ts
@@ -41,7 +41,6 @@ export const createMockDatabase = (opts?: Partial<Database>): Database => ({
uploads_enabled: false,
uploads_schema_name: null,
uploads_table_prefix: null,
- workspace_permissions_status: null,
...opts,
});
diff --git a/frontend/src/metabase-types/api/mocks/index.ts b/frontend/src/metabase-types/api/mocks/index.ts
index 86434e37012..5a43d0a81bd 100644
--- a/frontend/src/metabase-types/api/mocks/index.ts
+++ b/frontend/src/metabase-types/api/mocks/index.ts
@@ -46,4 +46,3 @@ export * from "./timeline";
export * from "./transform";
export * from "./user";
export * from "./util";
-export * from "./workspace";
diff --git a/frontend/src/metabase-types/api/mocks/settings.ts b/frontend/src/metabase-types/api/mocks/settings.ts
index d7dfc49cdfe..04358b574b6 100644
--- a/frontend/src/metabase-types/api/mocks/settings.ts
+++ b/frontend/src/metabase-types/api/mocks/settings.ts
@@ -147,7 +147,6 @@ export const createMockTokenFeatures = (
library: false,
"support-users": false,
tenants: false,
- workspaces: false,
writable_connection: false,
admin_security_center: false,
ai_controls: false,
diff --git a/frontend/src/metabase-types/api/mocks/workspace.ts b/frontend/src/metabase-types/api/mocks/workspace.ts
deleted file mode 100644
index fa39b5b021f..00000000000
--- a/frontend/src/metabase-types/api/mocks/workspace.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import type { WorkspaceProblem } from "../workspace";
-
-export const createMockWorkspaceProblem = (
- opts?: Partial<WorkspaceProblem>,
-): WorkspaceProblem => ({
- category: "internal",
- problem: "not-run",
- severity: "error",
- block_merge: false,
- description: "Test problem",
- data: {
- output: {
- db_id: 1,
- schema: "public",
- table: "test_table",
- },
- transform: {
- type: "workspace-transform",
- id: "1",
- name: "Test Transform",
- },
- },
- ...opts,
-});
diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.ts
index 0406bcad050..7c24f629798 100644
--- a/frontend/src/metabase-types/api/settings.ts
+++ b/frontend/src/metabase-types/api/settings.ts
@@ -369,7 +369,6 @@ export const tokenFeatures = [
"library",
"support-users",
"tenants",
- "workspaces",
"writable_connection",
"admin_security_center",
"ai_controls",
diff --git a/frontend/src/metabase-types/api/transform.ts b/frontend/src/metabase-types/api/transform.ts
index d52ae1c1b54..b5655dd8fed 100644
--- a/frontend/src/metabase-types/api/transform.ts
+++ b/frontend/src/metabase-types/api/transform.ts
@@ -61,6 +61,20 @@ export type Transform = {
export type SuggestedTransform = Partial<Pick<Transform, "id">> &
Pick<Transform, "name" | "description" | "source" | "target">;
+export type TaggedTransform = Transform & { type: "transform" };
+
+export type UnsavedTransform = {
+ type: "unsaved-transform";
+ id: TransformId;
+ name: string;
+ source: DraftTransformSource;
+ target: {
+ name: string;
+ schema: string | null;
+ type: TransformTargetType;
+ };
+};
+
export type PythonTransformTableEntry = {
alias: string;
table_id: ConcreteTableId;
diff --git a/frontend/src/metabase-types/api/workspace.ts b/frontend/src/metabase-types/api/workspace.ts
deleted file mode 100644
index ac206b5d2a2..00000000000
--- a/frontend/src/metabase-types/api/workspace.ts
+++ /dev/null
@@ -1,567 +0,0 @@
-import type { CollectionId } from "./collection";
-import type { DatabaseId } from "./database";
-import type { DatasetColumn, ResultsMetadata, RowValues } from "./dataset";
-import type { SchemaName } from "./table";
-import type {
- DraftTransformSource,
- Transform,
- TransformId,
- TransformSource,
- TransformTagId,
- TransformTarget,
- TransformTargetType,
-} from "./transform";
-
-/**
- * A Transform from the global transforms module, tagged for discrimination.
- * Used in workspace context to distinguish from WorkspaceTransform.
- */
-export type TaggedTransform = Transform & { type: "transform" };
-
-/**
- * An unsaved transform that exists only in the UI state.
- * Uses a numeric id (negative) for temporary identification.
- */
-export type UnsavedTransform = {
- type: "unsaved-transform";
- id: TransformId;
- name: string;
- source: DraftTransformSource;
- target: {
- name: string;
- schema: string | null;
- type: TransformTargetType;
- };
-};
-
-export type WorkspaceTransform = Omit<Transform, "id"> & {
- type: "workspace-transform";
- ref_id: WorkspaceTransformId;
- workspace_id: WorkspaceId;
- global_id: TransformId | null;
- target_isolated: TransformTarget;
- target_stale: boolean;
- archived_at: string | null;
- last_run_at: string | null;
- last_run_message: string | null;
- last_run_status: WorkspaceRunStatus | null;
-};
-
-export function isTaggedTransform(
- transform:
- | TaggedTransform
- | WorkspaceTransform
- | UnsavedTransform
- | WorkspaceTransformListItem,
-): transform is TaggedTransform {
- return "type" in transform && transform.type === "transform";
-}
-
-export function isWorkspaceTransform(
- transform:
- | TaggedTransform
- | WorkspaceTransform
- | UnsavedTransform
- | WorkspaceTransformListItem,
-): transform is WorkspaceTransform {
- return "type" in transform && transform.type === "workspace-transform";
-}
-
-export function isUnsavedTransform(
- transform:
- | TaggedTransform
- | WorkspaceTransform
- | UnsavedTransform
- | WorkspaceTransformListItem,
-): transform is UnsavedTransform {
- return "type" in transform && transform.type === "unsaved-transform";
-}
-
-export type WorkspaceId = number;
-
-export type Workspace = {
- id: WorkspaceId;
- name: string;
- status: WorkspaceSetupStatus;
- collection_id?: CollectionId | null;
- database_id?: DatabaseId | null;
- created_at?: string;
- updated_at?: string;
-};
-
-export type WorkspaceItem = {
- id: WorkspaceId;
- name: string;
- database_id: DatabaseId;
- status: WorkspaceSetupStatus;
- updated_at?: string;
-};
-
-export type WorkspaceListResponse = {
- items: WorkspaceItem[];
- limit: number | null;
- offset: number | null;
-};
-
-export type CreateWorkspaceRequest = {
- name?: string;
- database_id?: DatabaseId;
-};
-
-export type WorkspaceTransformListItem = {
- ref_id: string;
- global_id: TransformId | null;
- name: string;
- source_type: Transform["source_type"] | null;
-};
-
-export type WorkspaceTransformListResponse = {
- transforms: WorkspaceTransformListItem[];
-};
-
-/**
- * Reason why a transform cannot be checked out to a workspace.
- * null indicates the transform can be checked out.
- */
-export type CheckoutDisabledReason =
- | "mbql"
- | "card-reference"
- | "unknown-type"
- | null;
-
-export type ExternalTransform = {
- id: TransformId;
- name: string;
- source_type: Transform["source_type"];
- checkout_disabled: CheckoutDisabledReason;
-};
-
-export type ExternalTransformRequest = {
- workspaceId: WorkspaceId;
- databaseId?: DatabaseId | null;
-};
-
-export type ExternalTransformResponse = {
- transforms: ExternalTransform[];
-};
-
-export type WorkspaceOutputTableRef = {
- transform_id: number | string | null;
- schema: string;
- table: string;
- table_id: number | null;
-};
-
-export type WorkspaceTransformId = string;
-
-export type WorkspaceRunStatus = "started" | "succeeded" | "failed" | "timeout";
-
-export type ExistingCheckout = {
- ref_id: string;
- name: string;
-};
-
-export type WorkspaceCheckoutStatus = {
- id: WorkspaceId;
- name: string;
- status: WorkspaceSetupStatus;
- existing: ExistingCheckout | null;
-};
-
-/** @deprecated Use WorkspaceCheckoutStatus instead */
-export type WorkspaceCheckoutItem = {
- id: string;
- name: string;
- workspace: WorkspaceItem;
-};
-
-export type WorkspaceCheckoutResponse = {
- checkout_disabled: CheckoutDisabledReason;
- workspaces: WorkspaceCheckoutStatus[];
- /** @deprecated Use workspaces instead */
- transforms: WorkspaceCheckoutItem[];
-};
-
-export type WorkspaceMergeTransformResult = {
- op: "create" | "delete" | "update" | "noop";
- global_id: TransformId | null;
- ref_id: string;
- message?: string;
-};
-
-export type WorkspaceMergeResponse = {
- merged?: WorkspaceMergeTransformResult[];
- errors?: WorkspaceMergeTransformResult[];
- workspace: WorkspaceItem;
-};
-
-export type WorkspaceTransformMergeResponse = WorkspaceMergeTransformResult;
-
-export type ValidateTableNameRequest = {
- id: WorkspaceId;
- db_id: DatabaseId;
- target: {
- type: "table";
- name: string;
- schema: string | null;
- };
-};
-
-export type ValidateTableNameResponse =
- | "OK"
- | "A table with that name already exists";
-
-export type CreateWorkspaceTransformRequest = {
- id: WorkspaceId;
- global_id?: TransformId;
- name: string;
- description?: string | null;
- source: DraftTransformSource;
- target: TransformTarget;
- tag_ids?: TransformTagId[];
-};
-
-export type UpdateWorkspaceTransformRequest = {
- workspaceId: WorkspaceId;
- transformId: string;
- name?: string;
- description?: string | null;
- source?: TransformSource;
- target?: TransformTarget;
- tag_ids?: TransformTagId[];
-};
-
-export type WorkspaceTransformRef = {
- workspaceId: WorkspaceId;
- transformId: string;
-};
-
-export type CreateWorkspaceTransformResponse = WorkspaceTransform;
-
-export type WorkspaceInputTable = {
- db_id: DatabaseId;
- schema: string;
- table_id: number | null;
- table: string;
-};
-
-export type WorkspaceOutputTableEntry = {
- transform_id: string;
- schema: string;
- table: string;
- table_id: number | null;
- active?: boolean;
-};
-
-export type WorkspaceOutputTable = {
- db_id: DatabaseId;
- global: WorkspaceOutputTableEntry;
- isolated: WorkspaceOutputTableEntry;
-};
-
-export type WorkspaceTablesResponse = {
- inputs: WorkspaceInputTable[];
- outputs: WorkspaceOutputTable[];
-};
-
-// Graph types for React Flow dependency diagram
-export type WorkspaceGraphNode = {
- id: string;
- dependents_count: Record<string, number>;
-} & (
- | {
- type: "input-table";
- data: {
- db: number;
- id: number;
- schema: string;
- table: string;
- table_id: number;
- };
- }
- | {
- type: "workspace-transform";
- data: {
- ref_id: string;
- name: string;
- target: {
- db: number;
- schema: string;
- table: string;
- table_id: number | null;
- };
- };
- }
-);
-
-// Note: entity IDs are strings from backend (node-id returns strings for tables like "1-public-users")
-export type WorkspaceGraphEdge = {
- from_entity_type: string;
- from_entity_id: string;
- to_entity_type: string;
- to_entity_id: string;
-};
-
-export type WorkspaceGraphResponse = {
- nodes: WorkspaceGraphNode[];
- edges: WorkspaceGraphEdge[];
-};
-
-// Workspace graph dependency types that use string IDs (matching backend node-id function)
-// These are separate from the standard DependencyNode/DependencyEdge types in dependencies.ts
-export type WorkspaceGraphDependencyId = string;
-
-export type WorkspaceGraphTableNodeData = {
- name: string;
- display_name: string;
- description: string | null;
- db_id: number;
- schema: string;
- fields: unknown[];
- table_id?: number;
-};
-
-export type WorkspaceGraphTransformNodeData = {
- name: string;
- workspace_id?: WorkspaceId;
- ref_id: string;
- target?: {
- db: number;
- schema: string;
- table: string;
- table_id?: number | null;
- };
-};
-
-export type WorkspaceGraphTableNode = {
- id: WorkspaceGraphDependencyId;
- type: "table";
- data: WorkspaceGraphTableNodeData;
- dependents_count?: Record<string, number>;
-};
-
-export type WorkspaceGraphTransformNode = {
- id: WorkspaceGraphDependencyId;
- type: "workspace-transform";
- data: WorkspaceGraphTransformNodeData;
- dependents_count?: Record<string, number>;
-};
-
-export type WorkspaceGraphDependencyNode =
- | WorkspaceGraphTableNode
- | WorkspaceGraphTransformNode;
-
-export type WorkspaceGraphDependencyEdge = {
- from_entity_id: WorkspaceGraphDependencyId;
- from_entity_type: "table" | "workspace-transform";
- to_entity_id: WorkspaceGraphDependencyId;
- to_entity_type: "table" | "workspace-transform";
-};
-
-export type WorkspaceDependencyGraph = {
- nodes: WorkspaceGraphDependencyNode[];
- edges: WorkspaceGraphDependencyEdge[];
-};
-
-// Problem types for workspace validation
-export type WorkspaceEntityRef =
- | { "entity-type": "workspace-transform"; "entity-id": string }
- | { "entity-type": "global-transform"; "entity-id": number };
-
-export type WorkspaceTableRef = {
- db_id: DatabaseId;
- schema: string;
- table: string;
-};
-
-export type WorkspaceProblemCategory =
- | "unused"
- | "internal-downstream"
- | "external-downstream"
- | "internal"
- | "external";
-
-export type WorkspaceProblemType =
- | "not-run"
- | "stale"
- | "failed"
- | "removed-field"
- | "removed-table"
- | "target-conflict"
- | "cycle";
-
-export type WorkspaceProblemSeverity = "error" | "warning" | "info";
-
-// Base types for problem data structures
-export type WorkspaceProblemOutput = {
- db_id: DatabaseId;
- schema: string | null;
- table: string;
-};
-
-export type WorkspaceProblemTransformRef = {
- type: "workspace-transform" | "external-transform";
- id: string | number;
- name?: string;
-};
-
-export type WorkspaceProblemBadRef = {
- type:
- | "validate/missing-column"
- | "validate/missing-table-alias"
- | "validate/duplicate-column"
- | "validate/syntax-error"
- | "validate/validation-exception-error";
- name?: string; // Column/alias name (for missing-column, missing-table-alias, duplicate-column)
- message?: string; // Error message (for validation-exception-error)
-};
-
-// Problem data structures matching backend implementation
-// See enterprise/backend/src/metabase_enterprise/workspaces/validation.clj
-
-// unused/not-run: Output hasn't been created, nothing depends on it
-export type WorkspaceProblemDataUnusedNotRun = {
- output: WorkspaceProblemOutput;
- transform: WorkspaceProblemTransformRef;
-};
-
-// internal-downstream/not-run: Output hasn't been created, other workspace transforms need it
-export type WorkspaceProblemDataInternalDownstreamNotRun = {
- output: WorkspaceProblemOutput;
- transform: WorkspaceProblemTransformRef;
- dependents: Array<{
- type: "workspace-transform";
- id: string;
- }>;
-};
-
-// external-downstream/not-run: Output hasn't been created, external transforms depend on it
-export type WorkspaceProblemDataExternalDownstreamNotRun = {
- output: WorkspaceProblemOutput;
- transform: WorkspaceProblemTransformRef;
- dependents: Array<{
- type: "external-transform";
- id: number;
- name: string;
- }>;
-};
-
-// external-downstream/removed-field: Field was removed that external transforms reference
-export type WorkspaceProblemDataRemovedField = {
- output: WorkspaceProblemOutput;
- transform: {
- type: "external-transform";
- id: number;
- name: string;
- };
- "bad-refs": WorkspaceProblemBadRef[];
-};
-
-export type KnownWorkspaceProblemData =
- | WorkspaceProblemDataUnusedNotRun
- | WorkspaceProblemDataInternalDownstreamNotRun
- | WorkspaceProblemDataExternalDownstreamNotRun
- | WorkspaceProblemDataRemovedField;
-
-export type WorkspaceProblemData =
- | KnownWorkspaceProblemData
- | Record<string, unknown>; // For future problem types not yet implemented
-
-export type WorkspaceProblem = {
- category: WorkspaceProblemCategory;
- problem: WorkspaceProblemType;
- severity: WorkspaceProblemSeverity;
- block_merge: boolean;
- description: string;
- data: WorkspaceProblemData;
-};
-
-export type WorkspaceLogEntryId = number;
-
-// Status used in workspace log responses (different from archived boolean on Workspace)
-export type WorkspaceSetupStatus =
- | "pending"
- | "ready"
- | "archived"
- | "uninitialized"
- | "broken";
-
-export type WorkspaceLogStatus = "started" | "success" | "failure";
-
-export type WorkspaceLogResponse = {
- workspace_id: WorkspaceId;
- status: WorkspaceSetupStatus;
- updated_at: string | null;
- last_completed_at: string | null;
- logs: WorkspaceLogEntry[];
-};
-
-export type WorkspaceTask =
- | "workspace-setup"
- | "database-isolation"
- | "mirror-entities"
- | "grant-read-access";
-
-export type WorkspaceLogEntry = {
- id: WorkspaceLogEntryId;
- task: WorkspaceTask | string;
- description: string;
- started_at: string;
- updated_at: string;
- completed_at: string | null;
- status: WorkspaceLogStatus | null;
- message: string | null;
-};
-
-export type WorkspaceRunRequest = {
- id: WorkspaceId;
- stale_only?: boolean;
-};
-
-export type WorkspaceRunResponse = {
- succeeded: TransformId[];
- failed: TransformId[];
- not_run: TransformId[];
-};
-
-export type WorkspaceTransformRunResponse = {
- status: "succeeded" | "failed";
- start_time?: string | null;
- end_time?: string | null;
- message?: string | null;
- table: {
- name: string;
- schema?: SchemaName | null;
- };
-};
-
-export type WorkspaceTransformDryRunData = {
- rows?: RowValues[];
- cols?: Array<Partial<DatasetColumn>>;
- results_metadata?: ResultsMetadata;
-};
-
-export type WorkspaceTransformDryRunResponse = {
- status: "succeeded" | "failed";
- message?: string | null;
- data?: WorkspaceTransformDryRunData;
- /** Logs from Python transform execution (only present for Python transforms) */
- logs?: string;
-};
-
-export type WorkspacePermissionsStatus = {
- status: "ok" | "failed" | "unknown";
- checked_at?: string;
- error?: string;
-};
-
-export type WorkspaceAllowedDatabase = {
- id: number;
- name: string;
- enabled: boolean;
- workspace_permissions_status?: WorkspacePermissionsStatus;
-};
-
-export type WorkspaceAllowedDatabasesResponse = {
- databases: WorkspaceAllowedDatabase[];
-};
diff --git a/frontend/src/metabase-types/guards/index.ts b/frontend/src/metabase-types/guards/index.ts
index 437eacb7dab..e84d0ba1d10 100644
--- a/frontend/src/metabase-types/guards/index.ts
+++ b/frontend/src/metabase-types/guards/index.ts
@@ -7,4 +7,3 @@ export * from "./react";
export * from "./revision";
export * from "./settings";
export * from "./visualization";
-export * from "./workspace";
diff --git a/frontend/src/metabase-types/guards/workspace.ts b/frontend/src/metabase-types/guards/workspace.ts
deleted file mode 100644
index e9da0901a5d..00000000000
--- a/frontend/src/metabase-types/guards/workspace.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-import type {
- KnownWorkspaceProblemData,
- WorkspaceProblemDataExternalDownstreamNotRun,
- WorkspaceProblemDataInternalDownstreamNotRun,
- WorkspaceProblemDataRemovedField,
- WorkspaceProblemDataUnusedNotRun,
-} from "metabase-types/api";
-
-import { isObject } from "./common";
-
-export function isKnownWorkspaceProblemData(
- value: unknown,
-): value is KnownWorkspaceProblemData {
- return (
- isWorkspaceProblemDataExternalDownstreamNotRun(value) ||
- isWorkspaceProblemDataUnusedNotRun(value) ||
- isWorkspaceProblemDataInternalDownstreamNotRun(value) ||
- isWorkspaceProblemDataExternalDownstreamNotRun(value)
- );
-}
-
-export function isWorkspaceProblemDataRemovedField(
- value: unknown,
-): value is WorkspaceProblemDataRemovedField {
- return (
- isObject(value) &&
- isObject(value.output) &&
- typeof value.output.db_id === "number" &&
- typeof value.output.table === "string" &&
- isObject(value.transform) &&
- value.transform.type === "external-transform" &&
- typeof value.transform.id === "number" &&
- typeof value.transform.name === "string" &&
- Array.isArray(value["bad-refs"])
- );
-}
-
-export function isWorkspaceProblemDataUnusedNotRun(
- value: unknown,
-): value is WorkspaceProblemDataUnusedNotRun {
- return (
- isObject(value) &&
- isObject(value.output) &&
- typeof value.output.db_id === "number" &&
- typeof value.output.table === "string" &&
- isObject(value.transform) &&
- (value.transform.type === "workspace-transform" ||
- value.transform.type === "external-transform") &&
- (typeof value.transform.id === "string" ||
- typeof value.transform.id === "number") &&
- !("dependents" in value)
- );
-}
-
-export function isWorkspaceProblemDataInternalDownstreamNotRun(
- value: unknown,
-): value is WorkspaceProblemDataInternalDownstreamNotRun {
- return (
- isObject(value) &&
- isObject(value.output) &&
- typeof value.output.db_id === "number" &&
- typeof value.output.table === "string" &&
- isObject(value.transform) &&
- Array.isArray(value.dependents) &&
- value.dependents.every(
- (dep: unknown) =>
- isObject(dep) &&
- dep.type === "workspace-transform" &&
- typeof dep.id === "string",
- )
- );
-}
-
-export function isWorkspaceProblemDataExternalDownstreamNotRun(
- value: unknown,
-): value is WorkspaceProblemDataExternalDownstreamNotRun {
- return (
- isObject(value) &&
- isObject(value.output) &&
- typeof value.output.db_id === "number" &&
- typeof value.output.table === "string" &&
- isObject(value.transform) &&
- Array.isArray(value.dependents) &&
- value.dependents.every(
- (dep: unknown) =>
- isObject(dep) &&
- dep.type === "external-transform" &&
- typeof dep.id === "number" &&
- typeof dep.name === "string",
- )
- );
-}
diff --git a/frontend/src/metabase/admin/databases/containers/DatabaseEditApp.tsx b/frontend/src/metabase/admin/databases/containers/DatabaseEditApp.tsx
index 00194e50dec..de9e14b7d3e 100644
--- a/frontend/src/metabase/admin/databases/containers/DatabaseEditApp.tsx
+++ b/frontend/src/metabase/admin/databases/containers/DatabaseEditApp.tsx
@@ -20,7 +20,6 @@ import {
PLUGIN_DATABASE_REPLICATION,
PLUGIN_DB_ROUTING,
PLUGIN_TABLE_EDITING,
- PLUGIN_WORKSPACES,
PLUGIN_WRITABLE_CONNECTION,
} from "metabase/plugins";
import { getUserIsAdmin } from "metabase/selectors/user";
@@ -137,12 +136,6 @@ function DatabaseEditAppInner({
updateDatabase={updateDatabase}
/>
- <PLUGIN_WORKSPACES.AdminDatabaseWorkspacesSection
- database={database}
- settingsAvailable={settingsAvailable?.settings}
- updateDatabase={updateDatabase}
- />
-
<PLUGIN_DB_ROUTING.DatabaseRoutingSection
database={database}
/>
diff --git a/frontend/src/metabase/admin/databases/utils.ts b/frontend/src/metabase/admin/databases/utils.ts
index f764a80c447..0e674b2027e 100644
--- a/frontend/src/metabase/admin/databases/utils.ts
+++ b/frontend/src/metabase/admin/databases/utils.ts
@@ -81,10 +81,6 @@ export const dashboardUsesRoutingEnabledDatabases = (
});
};
-export function hasWorkspacesEnabled(database: Pick<Database, "settings">) {
- return Boolean(database.settings?.["database-enable-workspaces"]);
-}
-
export function hasTableEditingEnabled(database: Pick<Database, "settings">) {
return Boolean(database.settings?.["database-enable-table-editing"]);
}
diff --git a/frontend/src/metabase/api/database.ts b/frontend/src/metabase/api/database.ts
index e139dc9cb9d..57c5f6fde52 100644
--- a/frontend/src/metabase/api/database.ts
+++ b/frontend/src/metabase/api/database.ts
@@ -5,8 +5,6 @@ import type {
AutocompleteSuggestion,
CardAutocompleteRequest,
CardAutocompleteSuggestion,
- CheckWorkspacePermissionsRequest,
- CheckWorkspacePermissionsResponse,
CreateDatabaseRequest,
Database,
DatabaseId,
@@ -277,18 +275,6 @@ export const databaseApi = Api.injectEndpoints({
invalidatesTags: (_, error) =>
invalidateTags(error, [tag("field-values"), tag("parameter-values")]),
}),
- checkWorkspacePermissions: builder.mutation<
- CheckWorkspacePermissionsResponse,
- CheckWorkspacePermissionsRequest
- >({
- query: ({ id, cached = true }) => ({
- method: "POST",
- url: `/api/database/${id}/permission/workspace/check`,
- body: { cached },
- }),
- invalidatesTags: (_, error, { id }) =>
- invalidateTags(error, [idTag("database", id)]),
- }),
addSampleDatabase: builder.mutation<Database, void>({
query: () => ({
method: "POST",
@@ -346,7 +332,6 @@ export const {
useSyncDatabaseSchemaMutation,
useRescanDatabaseFieldValuesMutation,
useDiscardDatabaseFieldValuesMutation,
- useCheckWorkspacePermissionsMutation,
useListAutocompleteSuggestionsQuery,
useLazyListAutocompleteSuggestionsQuery,
useAddSampleDatabaseMutation,
diff --git a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/DataStudioLayout.module.css b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/DataStudioLayout.module.css
index fdf931db03a..fe4c5e6e5b1 100644
--- a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/DataStudioLayout.module.css
+++ b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/DataStudioLayout.module.css
@@ -49,106 +49,6 @@
}
}
-.workspacesSection {
- border-top: 1px solid var(--mb-color-border);
- padding-top: 0.75rem;
-}
-
-.workspacesSectionHeader {
- background-color: var(--mb-color-background-secondary);
- color: var(--mb-color-text-primary);
- font-weight: 600;
- transition: background-color 150ms ease;
-
- &:hover {
- background-color: var(--mb-color-background-selected);
- color: var(--mb-color-brand);
- }
-
- &.selected {
- background-color: var(--mb-color-background-selected);
- color: var(--mb-color-brand);
- }
-}
-
-.workspaceItem {
- background-color: var(--mb-color-background-primary);
- color: var(--mb-color-text-primary);
- cursor: pointer;
- border: 1px solid var(--mb-color-border);
- transition:
- background-color 150ms ease,
- border-color 150ms ease,
- color 150ms ease;
-
- &:hover {
- background-color: var(--mb-color-background-secondary);
- border-color: var(--mb-color-border-stronger);
- }
-
- &:hover .workspaceMenuButton {
- opacity: 1;
- }
-
- &.selected {
- background-color: var(--mb-color-background-hover);
- border-color: var(--mb-color-brand);
- }
-
- &.selected .workspaceMenuButton {
- opacity: 1;
- }
-
- &:disabled {
- opacity: 0.5;
- cursor: not-allowed;
- }
-}
-
-.workspaceMenuButton {
- color: var(--mb-color-text-secondary);
- opacity: 0;
- transition:
- opacity 150ms ease,
- background-color 150ms ease,
- color 150ms ease;
- flex-shrink: 0;
-
- &:hover {
- background-color: var(--mb-color-background-tertiary);
- color: var(--mb-color-text-primary);
- }
-}
-
-.newWorkspaceButton {
- background-color: transparent;
- color: var(--mb-color-text-primary);
- cursor: pointer;
- border: none;
- transition: color 150ms ease;
-
- &:hover {
- color: var(--mb-color-brand);
- }
-
- &:disabled {
- opacity: 0.5;
- cursor: not-allowed;
- }
-
- .hoverButton {
- &:hover {
- .showOnHover {
- opacity: 1;
- }
-
- .hideOnHover {
- opacity: 0;
- }
- }
- }
-}
-
.logoWrapper {
position: relative;
diff --git a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx
index 8f958baf8e0..cc459376094 100644
--- a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx
+++ b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx
@@ -11,10 +11,8 @@ import { useRegisterShortcut } from "metabase/palette/hooks/useRegisterShortcut"
import {
PLUGIN_FEATURE_LEVEL_PERMISSIONS,
PLUGIN_REMOTE_SYNC,
- PLUGIN_WORKSPACES,
} from "metabase/plugins";
import { getLocation } from "metabase/selectors/routing";
-import { getUserIsAdmin } from "metabase/selectors/user";
import {
canAccessTransforms as canAccessTransformsSelector,
getTransformsFeatureAvailable,
@@ -88,7 +86,6 @@ type DataStudioNavProps = {
function DataStudioNav({ isNavbarOpened, onNavbarToggle }: DataStudioNavProps) {
const { pathname } = useSelector(getLocation);
- const isAdmin = useSelector(getUserIsAdmin);
const canAccessDataModel = useSelector(
PLUGIN_FEATURE_LEVEL_PERMISSIONS.canAccessDataModel,
);
@@ -182,9 +179,6 @@ function DataStudioNav({ isNavbarOpened, onNavbarToggle }: DataStudioNavProps) {
}
/>
)}
- {(canAccessTransforms || isAdmin) && (
- <PLUGIN_WORKSPACES.WorkspacesSection showLabel={isNavbarOpened} />
- )}
</Stack>
<Stack gap="0.75rem">
{hasRemoteSyncFeature ? (
diff --git a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/enterprise.unit.spec.tsx b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/enterprise.unit.spec.tsx
index 545a8f6aef0..d159a349fdf 100644
--- a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/enterprise.unit.spec.tsx
+++ b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/enterprise.unit.spec.tsx
@@ -3,11 +3,7 @@ import fetchMock from "fetch-mock";
import { screen, waitFor, within } from "__support__/ui";
-import {
- DEFAULT_EE_SETTINGS,
- DEFAULT_EE_SETTINGS_WITH_WORKSPACES,
- setup,
-} from "./setup";
+import { DEFAULT_EE_SETTINGS, setup } from "./setup";
describe("DataStudioLayout", () => {
beforeEach(() => {
@@ -211,30 +207,4 @@ describe("DataStudioLayout", () => {
).not.toBeInTheDocument();
});
});
-
- describe("workspaces feature", () => {
- it("should not render WorkspacesSection when workspaces feature is not available", async () => {
- setup({ isNavbarOpened: true });
-
- await waitFor(() => {
- expect(screen.getByTestId("data-studio-nav")).toBeInTheDocument();
- });
-
- expect(
- screen.queryByTestId("workspaces-section"),
- ).not.toBeInTheDocument();
- expect(screen.queryByText("Workspaces")).not.toBeInTheDocument();
- });
-
- it("should render WorkspacesSection when workspaces feature is available", async () => {
- setup({ ...DEFAULT_EE_SETTINGS_WITH_WORKSPACES, isNavbarOpened: true });
-
- await waitFor(() => {
- expect(screen.getByTestId("data-studio-nav")).toBeInTheDocument();
- });
-
- expect(screen.getByTestId("workspaces-section")).toBeInTheDocument();
- expect(screen.getByText("Workspaces")).toBeInTheDocument();
- });
- });
});
diff --git a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/setup.tsx b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/setup.tsx
index b2ec2925492..8816c30062e 100644
--- a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/setup.tsx
+++ b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/tests/setup.tsx
@@ -8,7 +8,6 @@ import {
setupRemoteSyncEndpoints,
setupSettingsEndpoints,
setupUserKeyValueEndpoints,
- setupWorkspacesEndpoint,
} from "__support__/server-mocks";
import { mockSettings } from "__support__/settings";
import { renderWithProviders } from "__support__/ui";
@@ -65,11 +64,9 @@ const setupRemoteSyncSettingsEndpoints = (
const setupDirtyEndpoints = ({
dirty = [],
collections = [],
- tokenFeatures = {},
}: {
dirty?: RemoteSyncEntity[];
collections?: Collection[];
- tokenFeatures?: Partial<TokenFeatures>;
} = {}) => {
const changedCollections: Record<number, boolean> = {};
for (const entity of dirty) {
@@ -85,10 +82,6 @@ const setupDirtyEndpoints = ({
});
setupCollectionsEndpoints({ collections });
-
- if (tokenFeatures.workspaces) {
- setupWorkspacesEndpoint([]);
- }
};
const setupNavbarEndpoints = (isOpened = true) => {
@@ -181,7 +174,7 @@ export const setup = ({
setupSettingsEndpoints([]);
setupRemoteSyncSettingsEndpoints(remoteSyncSettings, tokenFeatures);
- setupDirtyEndpoints({ dirty, collections, tokenFeatures });
+ setupDirtyEndpoints({ dirty, collections });
setupNavbarEndpoints(isNavbarOpened);
setupLibraryEndpoints(false);
@@ -239,20 +232,3 @@ export const DEFAULT_EE_SETTINGS: Partial<SetupOpts> = {
dependencies: true,
},
};
-
-export const DEFAULT_EE_SETTINGS_WITH_WORKSPACES: Partial<SetupOpts> = {
- enterprisePlugins: [
- "library",
- "remote_sync",
- "dependencies",
- "feature_level_permissions",
- "workspaces",
- ],
- tokenFeatures: {
- remote_sync: true,
- advanced_permissions: true,
- library: true,
- dependencies: true,
- workspaces: true,
- },
-};
diff --git a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/utils.ts b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/utils.ts
index 56c22a7820e..6db0c63ac53 100644
--- a/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/utils.ts
+++ b/frontend/src/metabase/data-studio/app/pages/DataStudioLayout/utils.ts
@@ -7,7 +7,6 @@ type TabName =
| "jobs"
| "runs"
| "dependencies"
- | "workspace"
| "dependency-diagnostics"
| "glossary"
| "git-sync";
@@ -30,8 +29,6 @@ export const getCurrentTab = (pathname: string): TabName => {
return "runs";
case pathname.startsWith(Urls.transformList()):
return "transforms";
- case pathname.startsWith(Urls.dataStudioWorkspaceList()):
- return "workspace";
default:
return "data";
}
diff --git a/frontend/src/metabase/data-studio/app/pages/WorkspacesSectionLayout/WorkspacesSectionLayout.tsx b/frontend/src/metabase/data-studio/app/pages/WorkspacesSectionLayout/WorkspacesSectionLayout.tsx
deleted file mode 100644
index 4b5d18cf39e..00000000000
--- a/frontend/src/metabase/data-studio/app/pages/WorkspacesSectionLayout/WorkspacesSectionLayout.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-import { t } from "ttag";
-
-import { usePageTitle } from "metabase/hooks/use-page-title";
-
-import { SectionLayout } from "../../components/SectionLayout";
-
-type WorkspacesSectionLayoutProps = {
- children?: React.ReactNode;
-};
-
-export function WorkspacesSectionLayout({
- children,
-}: WorkspacesSectionLayoutProps) {
- usePageTitle(t`Workspaces`);
-
- return <SectionLayout>{children}</SectionLayout>;
-}
diff --git a/frontend/src/metabase/data-studio/app/pages/WorkspacesSectionLayout/index.ts b/frontend/src/metabase/data-studio/app/pages/WorkspacesSectionLayout/index.ts
deleted file mode 100644
index 85d3fb9745d..00000000000
--- a/frontend/src/metabase/data-studio/app/pages/WorkspacesSectionLayout/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./WorkspacesSectionLayout";
diff --git a/frontend/src/metabase/data-studio/routes.tsx b/frontend/src/metabase/data-studio/routes.tsx
index 98ddfda6b02..4b2e227415d 100644
--- a/frontend/src/metabase/data-studio/routes.tsx
+++ b/frontend/src/metabase/data-studio/routes.tsx
@@ -6,7 +6,6 @@ import {
PLUGIN_DEPENDENCIES,
PLUGIN_FEATURE_LEVEL_PERMISSIONS,
PLUGIN_LIBRARY,
- PLUGIN_WORKSPACES,
} from "metabase/plugins";
import type { State } from "metabase/redux/store";
import { getDataStudioTransformRoutes } from "metabase/transforms/routes";
@@ -19,7 +18,6 @@ import { DependenciesSectionLayout } from "./app/pages/DependenciesSectionLayout
import { DependencyDiagnosticsSectionLayout } from "./app/pages/DependencyDiagnosticsSectionLayout";
import { GitSyncSectionLayout } from "./app/pages/GitSyncSectionLayout";
import { TransformsSectionLayout } from "./app/pages/TransformsSectionLayout";
-import { WorkspacesSectionLayout } from "./app/pages/WorkspacesSectionLayout";
import { getDataStudioMetadataRoutes } from "./data-model/routes";
import { getDataStudioGlossaryRoutes } from "./glossary/routes";
import {
@@ -56,11 +54,6 @@ export function getDataStudioRoutes(
) : (
<Route path="library" component={LibraryUpsellPage} />
)}
- {PLUGIN_WORKSPACES.isEnabled && (
- <Route path="workspaces" component={WorkspacesSectionLayout}>
- {PLUGIN_WORKSPACES.getDataStudioWorkspaceRoutes()}
- </Route>
- )}
{PLUGIN_DEPENDENCIES.isEnabled ? (
<Route path="dependencies" component={DependenciesSectionLayout}>
{PLUGIN_DEPENDENCIES.getDataStudioDependencyRoutes()}
diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentSuggestionMessage.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentSuggestionMessage.tsx
index 54c01e6e3c4..dace4ebb4fd 100644
--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentSuggestionMessage.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentSuggestionMessage.tsx
@@ -20,7 +20,6 @@ import {
import { useMetadataToasts } from "metabase/metadata/hooks";
import EditorS from "metabase/querying/components/CodeMirrorEditor/CodeMirrorEditor.module.css";
import { getMetadata } from "metabase/selectors/metadata";
-import { getIsWorkspace } from "metabase/selectors/routing";
import {
Button,
Collapse,
@@ -109,7 +108,6 @@ export const AgentSuggestionMessage = ({
}) => {
const dispatch = useDispatch();
const metadata = useSelector(getMetadata);
- const isWorkspace = useSelector(getIsWorkspace);
const { suggestionActions } = useContext(MetabotContext);
const { sendErrorToast } = useMetadataToasts();
const [isApplying, setIsApplying] = useState(false);
@@ -127,11 +125,8 @@ export const AgentSuggestionMessage = ({
const [opened, { toggle }] = useDisclosure(true);
const url = useLocation();
- // In workspace context, we don't use URL-based navigation, so isViewing should be false
- // This ensures suggestions always show properly in workspace
- const isViewing = isWorkspace
- ? false
- : (url.pathname?.startsWith(getTransformUrl(suggestedTransform)) ?? false);
+ const isViewing =
+ url.pathname?.startsWith(getTransformUrl(suggestedTransform)) ?? false;
const canApply = suggestionActions
? !hasAppliedInContext && !isApplying
@@ -167,16 +162,6 @@ export const AgentSuggestionMessage = ({
return;
}
- // In workspace context, don't redirect - the suggestion actions should handle it
- // If we get here, it means suggestionActions is not available, which shouldn't happen
- // in workspace context, but we'll prevent the redirect anyway
- if (isWorkspace) {
- sendErrorToast(
- t`Unable to apply suggestion. Please try again or refresh the page.`,
- );
- return;
- }
-
dispatch(push(getTransformUrl(suggestedTransform)) as UnknownAction);
};
diff --git a/frontend/src/metabase/metabot/state/actions.ts b/frontend/src/metabase/metabot/state/actions.ts
index 48fcb83c75c..16833cfa879 100644
--- a/frontend/src/metabase/metabot/state/actions.ts
+++ b/frontend/src/metabase/metabot/state/actions.ts
@@ -12,7 +12,6 @@ import { isEmbeddingSdk } from "metabase/embedding-sdk/config";
import { setIsNativeEditorOpen } from "metabase/query_builder/actions";
import type { Dispatch, State } from "metabase/redux/store";
import { addUndo } from "metabase/redux/undo";
-import { getIsWorkspace } from "metabase/selectors/routing";
import { getSetting } from "metabase/selectors/settings";
import { getUser } from "metabase/selectors/user";
import { createAsyncThunk } from "metabase/utils/redux";
@@ -351,7 +350,6 @@ export const sendAgentRequest = createAsyncThunk<
payload,
{ dispatch, getState, signal, rejectWithValue, fulfillWithValue },
) => {
- const isWorkspace = getIsWorkspace(getState());
const { agentId, ...request } = payload;
try {
@@ -393,7 +391,7 @@ export const sendAgentRequest = createAsyncThunk<
.with({ type: "navigate_to" }, (part) => {
dispatch(setNavigateToPath(part.value));
- if (!isEmbeddingSdk() && !isWorkspace) {
+ if (!isEmbeddingSdk()) {
dispatch(push(part.value) as UnknownAction);
}
})
diff --git a/frontend/src/metabase/plugins/index.ts b/frontend/src/metabase/plugins/index.ts
index e44bd171652..c01acd65909 100644
--- a/frontend/src/metabase/plugins/index.ts
+++ b/frontend/src/metabase/plugins/index.ts
@@ -57,7 +57,6 @@ export {
PLUGIN_DB_ROUTING,
PLUGIN_DATABASE_REPLICATION,
PLUGIN_TABLE_EDITING,
- PLUGIN_WORKSPACES,
} from "./oss/database";
export { PLUGIN_EMBEDDING, type SimpleDataPickerProps } from "./oss/embedding";
export { PLUGIN_EMBEDDING_IFRAME_SDK } from "./oss/embedding-iframe-sdk";
diff --git a/frontend/src/metabase/plugins/oss/database.ts b/frontend/src/metabase/plugins/oss/database.ts
index 80bd296626e..4f9c363b767 100644
--- a/frontend/src/metabase/plugins/oss/database.ts
+++ b/frontend/src/metabase/plugins/oss/database.ts
@@ -8,7 +8,6 @@ import type {
DatabaseLocalSettingAvailability,
Database as DatabaseType,
TableId,
- Transform,
} from "metabase-types/api";
const getDefaultPluginDbRouting = () => ({
@@ -53,30 +52,6 @@ const getDefaultPluginTableEditing = () => ({
export const PLUGIN_TABLE_EDITING = getDefaultPluginTableEditing();
-export type WorkspacesSectionProps = {
- showLabel: boolean;
-};
-
-export type EditTransformMenuProps = {
- transform: Transform;
-};
-
-const getDefaultPluginWorkspaces = () => ({
- isEnabled: false,
- AdminDatabaseWorkspacesSection: PluginPlaceholder as ComponentType<{
- database: DatabaseType;
- settingsAvailable?: Record<string, DatabaseLocalSettingAvailability>;
- updateDatabase: (
- database: { id: DatabaseId } & Partial<DatabaseData>,
- ) => Promise<void>;
- }>,
- WorkspacesSection: PluginPlaceholder as ComponentType<WorkspacesSectionProps>,
- getDataStudioWorkspaceRoutes: () => null as React.ReactElement | null,
- EditTransformMenu: PluginPlaceholder as ComponentType<EditTransformMenuProps>,
-});
-
-export const PLUGIN_WORKSPACES = getDefaultPluginWorkspaces();
-
/**
* @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
*/
@@ -87,5 +62,4 @@ export function reinitialize() {
getDefaultPluginDatabaseReplication(),
);
Object.assign(PLUGIN_TABLE_EDITING, getDefaultPluginTableEditing());
- Object.assign(PLUGIN_WORKSPACES, getDefaultPluginWorkspaces());
}
diff --git a/frontend/src/metabase/plugins/oss/transforms.ts b/frontend/src/metabase/plugins/oss/transforms.ts
index 543bc33c0e6..8e8a9929678 100644
--- a/frontend/src/metabase/plugins/oss/transforms.ts
+++ b/frontend/src/metabase/plugins/oss/transforms.ts
@@ -35,7 +35,6 @@ export type PythonTransformEditorProps = {
onAcceptProposed: () => void;
onRejectProposed: () => void;
onRunTransform?: (result: any) => void;
- /** Custom run handler that overrides internal test-run. Used in workspace context for dry-run. */
onRun?: () => void;
};
diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.module.css b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.module.css
index 46485f803f3..d398016185e 100644
--- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.module.css
+++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.module.css
@@ -2,7 +2,6 @@
background-color: var(--mb-color-background-secondary);
display: flex;
flex-direction: column;
- /* Very crude solution to integrate editor to Workspace Transform Tab */
flex: var(--native-query-editor-flex, none);
width: 100%;
}
diff --git a/frontend/src/metabase/selectors/routing.ts b/frontend/src/metabase/selectors/routing.ts
index f6e2c514cf4..d1e6af0f3cb 100644
--- a/frontend/src/metabase/selectors/routing.ts
+++ b/frontend/src/metabase/selectors/routing.ts
@@ -1,16 +1,6 @@
-import { createSelector } from "@reduxjs/toolkit";
-
import type { State } from "metabase/redux/store";
const DEFAULT_LOCATION = { pathname: "" };
export const getLocation = (state: State) =>
state.routing?.locationBeforeTransitions ?? DEFAULT_LOCATION;
-
-/**
- * Returns true if the current route is within a workspace context.
- * Workspaces are accessed via /data-studio/workspaces/:workspaceId
- */
-export const getIsWorkspace = createSelector([getLocation], (location) => {
- return location.pathname?.includes("/data-studio/workspaces/") ?? false;
-});
diff --git a/frontend/src/metabase/transforms/components/TransformEditor/TransformEditor.tsx b/frontend/src/metabase/transforms/components/TransformEditor/TransformEditor.tsx
index 5def6066b94..6f411399a02 100644
--- a/frontend/src/metabase/transforms/components/TransformEditor/TransformEditor.tsx
+++ b/frontend/src/metabase/transforms/components/TransformEditor/TransformEditor.tsx
@@ -1,6 +1,6 @@
import { useMemo } from "react";
-import { PLUGIN_REMOTE_SYNC, PLUGIN_WORKSPACES } from "metabase/plugins";
+import { PLUGIN_REMOTE_SYNC } from "metabase/plugins";
import {
QueryEditor,
type QueryEditorUiOptions,
@@ -99,10 +99,7 @@ export function TransformEditor({
onRunQueryStart={onRunQueryStart}
onBlur={onBlur}
topBarInnerContent={
- showEditButton &&
- (PLUGIN_WORKSPACES.isEnabled && transform ? (
- <PLUGIN_WORKSPACES.EditTransformMenu transform={transform} />
- ) : (
+ showEditButton && (
<EditDefinitionButton
bg="transparent"
fz="sm"
@@ -111,7 +108,7 @@ export function TransformEditor({
size="xs"
transformId={transform.id}
/>
- ))
+ )
}
parametersAreUserVisible={false}
/>
diff --git a/frontend/src/metabase/transforms/hooks/use-register-transform-metabot-context.ts b/frontend/src/metabase/transforms/hooks/use-register-transform-metabot-context.ts
index fc6e170ff71..4f388bb3707 100644
--- a/frontend/src/metabase/transforms/hooks/use-register-transform-metabot-context.ts
+++ b/frontend/src/metabase/transforms/hooks/use-register-transform-metabot-context.ts
@@ -9,13 +9,11 @@ import type {
TaggedTransform,
Transform,
UnsavedTransform,
- WorkspaceTransform,
} from "metabase-types/api";
type AnyTransform =
| Transform
| TaggedTransform
- | WorkspaceTransform
| UnsavedTransform
| SuggestedTransform;
diff --git a/frontend/src/metabase/transforms/pages/NewTransformPage/CreateTransformModal/CreateTransformModal.tsx b/frontend/src/metabase/transforms/pages/NewTransformPage/CreateTransformModal/CreateTransformModal.tsx
index da1e1ce17ca..96eb0e116db 100644
--- a/frontend/src/metabase/transforms/pages/NewTransformPage/CreateTransformModal/CreateTransformModal.tsx
+++ b/frontend/src/metabase/transforms/pages/NewTransformPage/CreateTransformModal/CreateTransformModal.tsx
@@ -25,7 +25,6 @@ import type {
SchemaName,
Transform,
TransformSource,
- WorkspaceTransform,
} from "metabase-types/api";
import { SchemaFormSelect } from "../../../components/SchemaFormSelect";
@@ -45,9 +44,7 @@ type CreateTransformModalProps = {
onClose: () => void;
schemasFilter?: SchemasFilter;
validationSchemaExtension?: ValidationSchemaExtension;
- handleSubmit?: (
- values: NewTransformValues,
- ) => Promise<Transform | WorkspaceTransform>;
+ handleSubmit?: (values: NewTransformValues) => Promise<Transform>;
targetDescription?: string;
validateOnMount?: boolean;
showIncrementalSettings?: boolean;
diff --git a/frontend/src/metabase/transforms/pages/TransformQueryPage/TransformPaneHeaderActions.unit.spec.tsx b/frontend/src/metabase/transforms/pages/TransformQueryPage/TransformPaneHeaderActions.unit.spec.tsx
index 0dc7bb935e3..6f390390157 100644
--- a/frontend/src/metabase/transforms/pages/TransformQueryPage/TransformPaneHeaderActions.unit.spec.tsx
+++ b/frontend/src/metabase/transforms/pages/TransformQueryPage/TransformPaneHeaderActions.unit.spec.tsx
@@ -165,7 +165,7 @@ describe("TransformPaneHeaderActions", () => {
).not.toBeInTheDocument();
});
- it("should render nothing for native transforms when workspaces not available", () => {
+ it("should render nothing for native transforms", () => {
setup({ isEditMode: false, isNative: true });
expect(
@@ -189,20 +189,10 @@ describe("TransformPaneHeaderActions", () => {
screen.getByRole("link", { name: /edit definition/i }),
).toBeInTheDocument();
});
-
- describe("workspaces feature availability", () => {
- it("should render EditDefinitionButton when workspaces feature is not available", () => {
- setup({ isEditMode: false, isNative: false });
-
- expect(
- screen.getByRole("link", { name: /edit definition/i }),
- ).toBeInTheDocument();
- });
- });
});
describe("Python transforms", () => {
- it("should not render EditDefinitionButton for Python transforms (moved to EditTransformMenu in header)", () => {
+ it("should not render EditDefinitionButton for Python transforms", () => {
setup({ isEditMode: false, isPython: true });
expect(
screen.queryByRole("link", { name: /edit definition/i }),
diff --git a/frontend/src/metabase/transforms/pages/TransformQueryPage/TransformQueryPage.tsx b/frontend/src/metabase/transforms/pages/TransformQueryPage/TransformQueryPage.tsx
index 80350550d1b..fc7964fcc4a 100644
--- a/frontend/src/metabase/transforms/pages/TransformQueryPage/TransformQueryPage.tsx
+++ b/frontend/src/metabase/transforms/pages/TransformQueryPage/TransformQueryPage.tsx
@@ -300,7 +300,6 @@ export type TransformQueryPageEditorProps = {
uiOptions?: TransformEditorProps["uiOptions"];
onRunQueryStart?: (query: DatasetQuery) => boolean | void;
onRunTransform?: (result: any) => void;
- /** Custom run handler for Python transforms (used in workspace for dry-run) */
onRun?: () => void;
};
diff --git a/frontend/src/metabase/utils/urls/data-studio.ts b/frontend/src/metabase/utils/urls/data-studio.ts
index 447b4bcc500..32602f2f8e0 100644
--- a/frontend/src/metabase/utils/urls/data-studio.ts
+++ b/frontend/src/metabase/utils/urls/data-studio.ts
@@ -298,20 +298,6 @@ export function dataStudioArchivedSnippets() {
return `${dataStudioLibrary()}/snippets/archived`;
}
-export function dataStudioWorkspaceList() {
- return `${ROOT_URL}/workspaces`;
-}
-
-export function dataStudioWorkspace(
- workspaceId: number,
- transformId?: number | string,
-) {
- if (transformId) {
- return `${dataStudioWorkspaceList()}/${workspaceId}?transformId=${transformId}`;
- }
- return `${dataStudioWorkspaceList()}/${workspaceId}`;
-}
-
export function dataStudioSegment(segmentId: SegmentId) {
return `${dataStudioLibrary()}/segments/${segmentId}`;
}
diff --git a/frontend/test/__support__/enterprise-typed.ts b/frontend/test/__support__/enterprise-typed.ts
index 00068fc8929..f72f6588fae 100644
--- a/frontend/test/__support__/enterprise-typed.ts
+++ b/frontend/test/__support__/enterprise-typed.ts
@@ -50,7 +50,6 @@ export const ENTERPRISE_PLUGIN_NAME_MAPPING = {
content_verification: "metabase-enterprise/content_verification",
moderation: "metabase-enterprise/moderation",
tenants: "metabase-enterprise/tenants",
- workspaces: "metabase-enterprise/data-studio/workspaces",
// Embedding SDK specific plugins
sdk_notifications: "embedding-sdk-ee/notifications",
diff --git a/frontend/test/__support__/server-mocks/index.ts b/frontend/test/__support__/server-mocks/index.ts
index be7b03ecabc..f0a1f6b34bc 100644
--- a/frontend/test/__support__/server-mocks/index.ts
+++ b/frontend/test/__support__/server-mocks/index.ts
@@ -57,4 +57,3 @@ export * from "./transform";
export * from "./user";
export * from "./user-key-value";
export * from "./util";
-export * from "./workspace";
diff --git a/frontend/test/__support__/server-mocks/workspace.ts b/frontend/test/__support__/server-mocks/workspace.ts
deleted file mode 100644
index 416bf9adbc4..00000000000
--- a/frontend/test/__support__/server-mocks/workspace.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import fetchMock from "fetch-mock";
-
-import type {
- Workspace,
- WorkspaceCheckoutResponse,
- WorkspaceId,
- WorkspaceItem,
- WorkspaceListResponse,
- WorkspaceProblem,
-} from "metabase-types/api";
-
-export function setupWorkspaceProblemsEndpoint(
- workspaceId: WorkspaceId,
- problems: WorkspaceProblem[] | Promise<WorkspaceProblem[]> = [],
-) {
- fetchMock.get(`path:/api/ee/workspace/${workspaceId}/problem`, problems);
-}
-
-export function setupWorkspacesEndpoint(workspaces: WorkspaceItem[] = []) {
- const response: WorkspaceListResponse = {
- items: workspaces,
- limit: null,
- offset: null,
- };
- fetchMock.get("path:/api/ee/workspace", response);
-}
-
-export function setupWorkspaceCheckoutEndpoint(
- checkout: Partial<WorkspaceCheckoutResponse> = {},
-) {
- const response: WorkspaceCheckoutResponse = {
- checkout_disabled: null,
- workspaces: [],
- transforms: [],
- ...checkout,
- };
- fetchMock.get("express:/api/ee/workspace/checkout", response);
-}
-
-export function setupCreateWorkspaceEndpoint(workspace: Workspace) {
- fetchMock.post("path:/api/ee/workspace", workspace);
-}
diff --git a/resources/migrations/061/20260422_drop_workspace_tables.yaml b/resources/migrations/061/20260422_drop_workspace_tables.yaml
new file mode 100644
index 00000000000..a878fd95fe9
--- /dev/null
+++ b/resources/migrations/061/20260422_drop_workspace_tables.yaml
@@ -0,0 +1,1190 @@
+## Drop all workspace tables and the workspace_permissions_status column on metabase_database.
+## The workspaces feature was removed; these tables and the column are no longer used.
+## Tables are dropped children-first to respect foreign-key dependencies.
+## Each drop has a rollback that recreates the table (or column) in its pre-drop state so
+## the schema is reversible.
+
+databaseChangeLog:
+
+ - changeSet:
+ id: v61.2026-04-22T00:00:00
+ author: ranquild
+ comment: Drop workspace_merge_transform table
+ changes:
+ - dropTable:
+ tableName: workspace_merge_transform
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_merge_transform
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: workspace_merge_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: workspace_name
+ type: ${text.type}
+ constraints:
+ nullable: false
+ - column:
+ name: transform_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: commit_message
+ type: ${text.type}
+ constraints:
+ nullable: false
+ - column:
+ name: merging_user_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ defaultValueComputed: current_timestamp
+ constraints:
+ nullable: false
+ - createIndex:
+ tableName: workspace_merge_transform
+ indexName: idx_workspace_merge_transform_workspace_merge_id
+ columns:
+ - column:
+ name: workspace_merge_id
+ - createIndex:
+ tableName: workspace_merge_transform
+ indexName: idx_workspace_merge_transform_workspace_id
+ columns:
+ - column:
+ name: workspace_id
+ - createIndex:
+ tableName: workspace_merge_transform
+ indexName: idx_workspace_merge_transform_transform_id
+ columns:
+ - column:
+ name: transform_id
+ - createIndex:
+ tableName: workspace_merge_transform
+ indexName: idx_workspace_merge_transform_merging_user_id
+ columns:
+ - column:
+ name: merging_user_id
+ - addForeignKeyConstraint:
+ baseTableName: workspace_merge_transform
+ baseColumnNames: workspace_merge_id
+ constraintName: fk_workspace_merge_transform_workspace_merge_id
+ referencedTableName: workspace_merge
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_merge_transform
+ baseColumnNames: workspace_id
+ constraintName: fk_workspace_merge_transform_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addForeignKeyConstraint:
+ baseTableName: workspace_merge_transform
+ baseColumnNames: transform_id
+ constraintName: fk_workspace_merge_transform_transform_id
+ referencedTableName: transform
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_merge_transform
+ baseColumnNames: merging_user_id
+ constraintName: fk_workspace_merge_transform_merging_user_id
+ referencedTableName: core_user
+ referencedColumnNames: id
+
+ - changeSet:
+ id: v61.2026-04-22T00:00:10
+ author: ranquild
+ comment: Drop workspace_merge table
+ changes:
+ - dropTable:
+ tableName: workspace_merge
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_merge
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: workspace_name
+ type: ${text.type}
+ constraints:
+ nullable: false
+ - column:
+ name: commit_message
+ type: ${text.type}
+ constraints:
+ nullable: false
+ - column:
+ name: creator_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ defaultValueComputed: current_timestamp
+ constraints:
+ nullable: false
+ - createIndex:
+ tableName: workspace_merge
+ indexName: idx_workspace_merge_workspace_id
+ columns:
+ - column:
+ name: workspace_id
+ - createIndex:
+ tableName: workspace_merge
+ indexName: idx_workspace_merge_creator_id
+ columns:
+ - column:
+ name: creator_id
+ - addForeignKeyConstraint:
+ baseTableName: workspace_merge
+ baseColumnNames: workspace_id
+ constraintName: fk_workspace_merge_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addForeignKeyConstraint:
+ baseTableName: workspace_merge
+ baseColumnNames: creator_id
+ constraintName: fk_workspace_merge_creator_id
+ referencedTableName: core_user
+ referencedColumnNames: id
+
+ - changeSet:
+ id: v61.2026-04-22T00:00:20
+ author: ranquild
+ comment: Drop workspace_input_transform table
+ changes:
+ - dropTable:
+ tableName: workspace_input_transform
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_input_transform
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: workspace_input_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: ref_id
+ type: char(36)
+ constraints:
+ nullable: false
+ - column:
+ name: transform_version
+ type: bigint
+ defaultValueNumeric: 0
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ defaultValueComputed: current_timestamp
+ constraints:
+ nullable: false
+ - createIndex:
+ tableName: workspace_input_transform
+ indexName: idx_workspace_input_transform_input_id
+ columns:
+ - column:
+ name: workspace_input_id
+ - createIndex:
+ tableName: workspace_input_transform
+ indexName: idx_workspace_input_transform_ws_ref
+ columns:
+ - column:
+ name: workspace_id
+ - column:
+ name: ref_id
+ - addForeignKeyConstraint:
+ baseTableName: workspace_input_transform
+ baseColumnNames: workspace_input_id
+ constraintName: fk_wit_workspace_input_id
+ referencedTableName: workspace_input
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_input_transform
+ baseColumnNames: workspace_id
+ constraintName: fk_wit_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addUniqueConstraint:
+ tableName: workspace_input_transform
+ columnNames: workspace_input_id, workspace_id, ref_id, transform_version
+ constraintName: uq_workspace_input_transform_versioned
+
+ - changeSet:
+ id: v61.2026-04-22T00:00:30
+ author: ranquild
+ comment: Drop workspace_output_external table
+ changes:
+ - dropTable:
+ tableName: workspace_output_external
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_output_external
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: transform_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: db_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: global_schema
+ type: varchar(254)
+ constraints:
+ nullable: true
+ - column:
+ name: global_table
+ type: varchar(254)
+ constraints:
+ nullable: false
+ - column:
+ name: global_table_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: isolated_schema
+ type: varchar(254)
+ constraints:
+ nullable: true
+ - column:
+ name: isolated_table
+ type: varchar(254)
+ constraints:
+ nullable: false
+ - column:
+ name: isolated_table_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: graph_version
+ type: bigint
+ defaultValueNumeric: 0
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - column:
+ name: updated_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - createIndex:
+ tableName: workspace_output_external
+ indexName: idx_workspace_output_external_workspace_id
+ columns:
+ - column:
+ name: workspace_id
+ - createIndex:
+ tableName: workspace_output_external
+ indexName: idx_workspace_output_external_transform_id
+ columns:
+ - column:
+ name: transform_id
+ - createIndex:
+ tableName: workspace_output_external
+ indexName: idx_workspace_output_external_global_table_id
+ columns:
+ - column:
+ name: global_table_id
+ - createIndex:
+ tableName: workspace_output_external
+ indexName: idx_workspace_output_external_isolated_table_id
+ columns:
+ - column:
+ name: isolated_table_id
+ - addForeignKeyConstraint:
+ baseTableName: workspace_output_external
+ baseColumnNames: workspace_id
+ constraintName: fk_workspace_output_external_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_output_external
+ baseColumnNames: transform_id
+ constraintName: fk_workspace_output_external_transform_id
+ referencedTableName: transform
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_output_external
+ baseColumnNames: global_table_id
+ constraintName: fk_workspace_output_external_global_table_id
+ referencedTableName: metabase_table
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addForeignKeyConstraint:
+ baseTableName: workspace_output_external
+ baseColumnNames: isolated_table_id
+ constraintName: fk_workspace_output_external_isolated_table_id
+ referencedTableName: metabase_table
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addUniqueConstraint:
+ tableName: workspace_output_external
+ columnNames: workspace_id, transform_id, graph_version
+ constraintName: uq_workspace_output_external_versioned
+
+ - changeSet:
+ id: v61.2026-04-22T00:00:40
+ author: ranquild
+ comment: Drop workspace_input_external table
+ changes:
+ - dropTable:
+ tableName: workspace_input_external
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_input_external
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: db_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: schema
+ type: varchar(254)
+ constraints:
+ nullable: true
+ - column:
+ name: table
+ type: varchar(254)
+ constraints:
+ nullable: false
+ - column:
+ name: table_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: access_granted
+ type: ${boolean.type}
+ defaultValueBoolean: false
+ constraints:
+ nullable: false
+ - column:
+ name: graph_version
+ type: bigint
+ defaultValueNumeric: 0
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - column:
+ name: updated_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - createIndex:
+ tableName: workspace_input_external
+ indexName: idx_workspace_input_external_workspace_id
+ columns:
+ - column:
+ name: workspace_id
+ - createIndex:
+ tableName: workspace_input_external
+ indexName: idx_workspace_input_external_table_id
+ columns:
+ - column:
+ name: table_id
+ - addForeignKeyConstraint:
+ baseTableName: workspace_input_external
+ baseColumnNames: workspace_id
+ constraintName: fk_workspace_input_external_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_input_external
+ baseColumnNames: table_id
+ constraintName: fk_workspace_input_external_table_id
+ referencedTableName: metabase_table
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addUniqueConstraint:
+ tableName: workspace_input_external
+ columnNames: workspace_id, db_id, schema, table, graph_version
+ constraintName: uq_workspace_input_external_versioned
+
+ - changeSet:
+ id: v61.2026-04-22T00:00:50
+ author: ranquild
+ comment: Drop workspace_output table
+ changes:
+ - dropTable:
+ tableName: workspace_output
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_output
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: ref_id
+ type: char(36)
+ constraints:
+ nullable: false
+ - column:
+ name: db_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: global_schema
+ type: varchar(254)
+ constraints:
+ nullable: true
+ - column:
+ name: global_table
+ type: varchar(254)
+ constraints:
+ nullable: false
+ - column:
+ name: global_table_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: isolated_schema
+ type: varchar(254)
+ constraints:
+ nullable: true
+ - column:
+ name: isolated_table
+ type: varchar(254)
+ constraints:
+ nullable: true
+ - column:
+ name: isolated_table_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: transform_version
+ type: bigint
+ defaultValueNumeric: 0
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - column:
+ name: updated_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - createIndex:
+ tableName: workspace_output
+ indexName: idx_workspace_output_workspace_id
+ columns:
+ - column:
+ name: workspace_id
+ - createIndex:
+ tableName: workspace_output
+ indexName: idx_workspace_output_ref_id
+ columns:
+ - column:
+ name: ref_id
+ - createIndex:
+ tableName: workspace_output
+ indexName: idx_workspace_output_global_table_id
+ columns:
+ - column:
+ name: global_table_id
+ - createIndex:
+ tableName: workspace_output
+ indexName: idx_workspace_output_isolated_table_id
+ columns:
+ - column:
+ name: isolated_table_id
+ - addForeignKeyConstraint:
+ baseTableName: workspace_output
+ baseColumnNames: workspace_id
+ constraintName: fk_workspace_output_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_output
+ baseColumnNames: workspace_id, ref_id
+ constraintName: fk_workspace_output_ref_id
+ referencedTableName: workspace_transform
+ referencedColumnNames: workspace_id, ref_id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_output
+ baseColumnNames: global_table_id
+ constraintName: fk_workspace_output_global_table_id
+ referencedTableName: metabase_table
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addForeignKeyConstraint:
+ baseTableName: workspace_output
+ baseColumnNames: isolated_table_id
+ constraintName: fk_workspace_output_isolated_table_id
+ referencedTableName: metabase_table
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addUniqueConstraint:
+ tableName: workspace_output
+ columnNames: workspace_id, ref_id, transform_version
+ constraintName: uq_workspace_output_versioned
+
+ - changeSet:
+ id: v61.2026-04-22T00:01:00
+ author: ranquild
+ comment: Drop workspace_input table
+ changes:
+ - dropTable:
+ tableName: workspace_input
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_input
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: db_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: schema
+ type: varchar(254)
+ constraints:
+ nullable: true
+ - column:
+ name: table
+ type: varchar(254)
+ constraints:
+ nullable: false
+ - column:
+ name: table_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: access_granted
+ type: ${boolean.type}
+ defaultValueBoolean: false
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - column:
+ name: updated_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - createIndex:
+ tableName: workspace_input
+ indexName: idx_workspace_input_workspace_id
+ columns:
+ - column:
+ name: workspace_id
+ - createIndex:
+ tableName: workspace_input
+ indexName: idx_workspace_input_table_id
+ columns:
+ - column:
+ name: table_id
+ - addForeignKeyConstraint:
+ baseTableName: workspace_input
+ baseColumnNames: workspace_id
+ constraintName: fk_workspace_input_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_input
+ baseColumnNames: table_id
+ constraintName: fk_workspace_input_table_id
+ referencedTableName: metabase_table
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addUniqueConstraint:
+ tableName: workspace_input
+ columnNames: workspace_id, db_id, schema, table
+ constraintName: uq_workspace_input_table
+
+ - changeSet:
+ id: v61.2026-04-22T00:01:10
+ author: ranquild
+ comment: Drop workspace_transform table
+ changes:
+ - dropTable:
+ tableName: workspace_transform
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_transform
+ columns:
+ - column:
+ name: ref_id
+ type: char(36)
+ constraints:
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: global_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: collection_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: creator_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: name
+ type: ${text.type}
+ constraints:
+ nullable: false
+ - column:
+ name: description
+ type: ${text.type}
+ constraints:
+ nullable: true
+ - column:
+ name: source
+ type: ${text.type}
+ constraints:
+ nullable: false
+ - column:
+ name: target
+ type: ${text.type}
+ constraints:
+ nullable: false
+ - column:
+ name: entity_id
+ type: char(21)
+ constraints:
+ nullable: true
+ unique: true
+ - column:
+ name: checked_out_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: true
+ - column:
+ name: archived_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: true
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - column:
+ name: updated_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - column:
+ name: last_run_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: true
+ - column:
+ name: last_run_message
+ type: ${text.type}
+ constraints:
+ nullable: true
+ - column:
+ name: last_run_status
+ type: varchar(20)
+ constraints:
+ nullable: true
+ - column:
+ name: definition_changed
+ type: ${boolean.type}
+ defaultValueBoolean: true
+ constraints:
+ nullable: false
+ - column:
+ name: analysis_version
+ type: bigint
+ defaultValueNumeric: 1
+ constraints:
+ nullable: false
+ - column:
+ name: input_data_changed
+ type: ${boolean.type}
+ defaultValueBoolean: false
+ constraints:
+ nullable: false
+ - addPrimaryKey:
+ tableName: workspace_transform
+ columnNames: workspace_id, ref_id
+ constraintName: pk_workspace_transform
+ - createIndex:
+ tableName: workspace_transform
+ indexName: idx_workspace_transform_workspace_id
+ columns:
+ - column:
+ name: workspace_id
+ - createIndex:
+ tableName: workspace_transform
+ indexName: idx_workspace_transform_global_id
+ columns:
+ - column:
+ name: global_id
+ - createIndex:
+ tableName: workspace_transform
+ indexName: idx_workspace_transform_collection_id
+ columns:
+ - column:
+ name: collection_id
+ - createIndex:
+ tableName: workspace_transform
+ indexName: idx_workspace_transform_creator_id
+ columns:
+ - column:
+ name: creator_id
+ - sql:
+ dbms: postgresql
+ sql: CREATE UNIQUE INDEX idx_workspace_transform_workspace_global_unique ON workspace_transform (workspace_id, global_id) WHERE global_id IS NOT NULL
+ - sql:
+ dbms: h2,mysql,mariadb
+ sql: CREATE UNIQUE INDEX idx_workspace_transform_workspace_global_unique ON workspace_transform (workspace_id, global_id)
+ - addForeignKeyConstraint:
+ baseTableName: workspace_transform
+ baseColumnNames: workspace_id
+ constraintName: fk_workspace_transform_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: CASCADE
+ - addForeignKeyConstraint:
+ baseTableName: workspace_transform
+ baseColumnNames: global_id
+ constraintName: fk_workspace_transform_global_id
+ referencedTableName: transform
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addForeignKeyConstraint:
+ baseTableName: workspace_transform
+ baseColumnNames: collection_id
+ constraintName: fk_workspace_transform_collection_id
+ referencedTableName: collection
+ referencedColumnNames: id
+ onDelete: SET NULL
+ - addForeignKeyConstraint:
+ baseTableName: workspace_transform
+ baseColumnNames: creator_id
+ constraintName: fk_workspace_transform_creator_id
+ referencedTableName: core_user
+ referencedColumnNames: id
+ onDelete: SET NULL
+
+ - changeSet:
+ id: v61.2026-04-22T00:01:20
+ author: ranquild
+ comment: Drop workspace_log table
+ changes:
+ - dropTable:
+ tableName: workspace_log
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_log
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: task
+ type: varchar(255)
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - column:
+ name: updated_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - column:
+ name: started_at
+ type: ${timestamp_type}
+ constraints:
+ nullable: false
+ - column:
+ name: completed_at
+ type: ${timestamp_type}
+ - column:
+ name: status
+ type: varchar(20)
+ - column:
+ name: message
+ type: ${text.type}
+ - createIndex:
+ tableName: workspace_log
+ indexName: idx_workspace_log_workspace_id
+ columns:
+ - column:
+ name: workspace_id
+ - addForeignKeyConstraint:
+ baseTableName: workspace_log
+ baseColumnNames: workspace_id
+ constraintName: fk_workspace_log_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: CASCADE
+
+ - changeSet:
+ id: v61.2026-04-22T00:01:30
+ author: ranquild
+ comment: Drop workspace_graph table
+ changes:
+ - dropTable:
+ tableName: workspace_graph
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace_graph
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: false
+ - column:
+ name: graph
+ type: ${text.type}
+ constraints:
+ nullable: false
+ - column:
+ name: graph_version
+ type: bigint
+ defaultValueNumeric: 0
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ defaultValueComputed: current_timestamp
+ constraints:
+ nullable: false
+ - column:
+ name: updated_at
+ type: ${timestamp_type}
+ defaultValueComputed: current_timestamp
+ constraints:
+ nullable: false
+ - createIndex:
+ tableName: workspace_graph
+ indexName: idx_workspace_graph_workspace_version
+ unique: true
+ columns:
+ - column:
+ name: workspace_id
+ - column:
+ name: graph_version
+ - addForeignKeyConstraint:
+ baseTableName: workspace_graph
+ baseColumnNames: workspace_id
+ constraintName: fk_workspace_graph_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: CASCADE
+
+ - changeSet:
+ id: v61.2026-04-22T00:01:35
+ author: ranquild
+ comment: Drop FK fk_collection_workspace_id before dropping the workspace table (MySQL requires explicit FK drop)
+ changes:
+ - dropForeignKeyConstraint:
+ baseTableName: collection
+ constraintName: fk_collection_workspace_id
+ rollback:
+ - addForeignKeyConstraint:
+ baseTableName: collection
+ baseColumnNames: workspace_id
+ constraintName: fk_collection_workspace_id
+ referencedTableName: workspace
+ referencedColumnNames: id
+ onDelete: CASCADE
+
+ - changeSet:
+ id: v61.2026-04-22T00:01:36
+ author: ranquild
+ comment: Drop workspace_id column from collection
+ changes:
+ - dropColumn:
+ tableName: collection
+ columnName: workspace_id
+ rollback:
+ - addColumn:
+ tableName: collection
+ columns:
+ - column:
+ name: workspace_id
+ type: int
+ constraints:
+ nullable: true
+ - createIndex:
+ tableName: collection
+ indexName: idx_collection_workspace_id
+ columns:
+ - column:
+ name: workspace_id
+
+ - changeSet:
+ id: v61.2026-04-22T00:01:40
+ author: ranquild
+ comment: Drop workspace table
+ changes:
+ - dropTable:
+ tableName: workspace
+ cascadeConstraints: true
+ rollback:
+ - createTable:
+ tableName: workspace
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ - column:
+ name: name
+ type: varchar(254)
+ - column:
+ name: collection_id
+ type: int
+ constraints:
+ nullable: true
+ - column:
+ name: creator_id
+ type: int
+ - column:
+ name: execution_user
+ type: int
+ - column:
+ name: database_id
+ type: int
+ - column:
+ name: schema
+ type: varchar(254)
+ constraints:
+ nullable: true
+ - column:
+ name: database_details
+ type: ${text.type}
+ constraints:
+ nullable: true
+ - column:
+ name: db_status
+ type: varchar(20)
+ defaultValue: uninitialized
+ constraints:
+ nullable: false
+ - column:
+ name: base_status
+ type: varchar(20)
+ defaultValue: empty
+ constraints:
+ nullable: false
+ - column:
+ name: graph_version
+ type: bigint
+ defaultValueNumeric: 1
+ constraints:
+ nullable: false
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ defaultValueComputed: current_timestamp
+ - column:
+ name: updated_at
+ type: ${timestamp_type}
+ defaultValueComputed: current_timestamp
+ - createIndex:
+ tableName: workspace
+ indexName: idx_workspace_collection_id
+ columns:
+ - column:
+ name: collection_id
+ - createIndex:
+ tableName: workspace
+ indexName: idx_workspace_creator_id
+ columns:
+ - column:
+ name: creator_id
+ - createIndex:
+ tableName: workspace
+ indexName: idx_workspace_execution_user_id
+ columns:
+ - column:
+ name: execution_user
+ - addUniqueConstraint:
+ tableName: workspace
+ columnNames: name
+ constraintName: idx_workspace_name_unique
+
+ - changeSet:
+ id: v61.2026-04-22T00:01:50
+ author: ranquild
+ comment: Drop workspace_permissions_status column from metabase_database
+ changes:
+ - dropColumn:
+ tableName: metabase_database
+ columnName: workspace_permissions_status
+ rollback:
+ - addColumn:
+ tableName: metabase_database
+ columns:
+ - column:
+ name: workspace_permissions_status
+ type: ${text.type}
+ constraints:
+ nullable: true
diff --git a/src/metabase/agent_api/api.clj b/src/metabase/agent_api/api.clj
index 6f2a4eddae6..0dbd0e06ed0 100644
--- a/src/metabase/agent_api/api.clj
+++ b/src/metabase/agent_api/api.clj
@@ -728,5 +728,5 @@
;;; ---------------------------------------------------- Routes ------------------------------------------------------
(def ^{:arglists '([request respond raise])} routes
- "`/api/agent/` routes. Workspace routes are mounted separately via the EE routes file."
+ "`/api/agent/` routes."
(api.macros/ns-handler *ns* +auth))
diff --git a/src/metabase/analytics/stats.clj b/src/metabase/analytics/stats.clj
index 3185069a219..ad3847a4365 100644
--- a/src/metabase/analytics/stats.clj
+++ b/src/metabase/analytics/stats.clj
@@ -934,9 +934,6 @@
{:name :support-users
:available (premium-features/enable-support-users?)
:enabled (premium-features/enable-support-users?)}
- {:name :workspaces
- :available (premium-features/enable-workspaces?)
- :enabled (premium-features/enable-workspaces?)}
{:name :writable-connection
:available (premium-features/enable-writable-connection?)
:enabled (premium-features/enable-writable-connection?)}
diff --git a/src/metabase/app_db/custom_migrations.clj b/src/metabase/app_db/custom_migrations.clj
index 44fb49b2fdf..052eb677611 100644
--- a/src/metabase/app_db/custom_migrations.clj
+++ b/src/metabase/app_db/custom_migrations.clj
@@ -2174,13 +2174,7 @@
(upsert-table! db-id schema table-name)))))
(t2/reducible-query {:select [:target :target_db_id]
:from [:transform]
- :where [:not= :target_db_id nil]})))
- ;; Invalidate workspace caches so the app re-analyzes and backfills workspace_ table FKs lazily
- (t2/query {:update :workspace_transform
- :set {:analysis_version [:+ :analysis_version 1]
- :definition_changed true}})
- (t2/query {:update :workspace
- :set {:graph_version [:+ :graph_version 1]}}))
+ :where [:not= :target_db_id nil]}))))
(define-migration BackfillTransformTargetTableId
;; For each transform with a non-null target_db_id, extract the table_id from the target JSON column.
@@ -2199,10 +2193,4 @@
:from [:transform]
:where [:and
[:not= :target_db_id nil]
- [:= :target_table_id nil]]}))
- ;; Invalidate workspace caches so they recalculate with target_table_id
- (t2/query {:update :workspace_transform
- :set {:analysis_version [:+ :analysis_version 1]
- :definition_changed true}})
- (t2/query {:update :workspace
- :set {:graph_version [:+ :graph_version 1]}}))
+ [:= :target_table_id nil]]})))
diff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.clj
index 5d6cde76558..47d9ce161c0 100644
--- a/src/metabase/collections/models/collection.clj
+++ b/src/metabase/collections/models/collection.clj
@@ -2104,8 +2104,7 @@
(serdes/fk :model/Collection)
{:export location-path->parent-id
:import parent-id->location-path}))
- :personal_owner_id (serdes/fk :model/User)
- :workspace_id (serdes/fk :model/Workspace)}
+ :personal_owner_id (serdes/fk :model/User)}
:defaults {:archived false
:is_sample false
:is_remote_synced false}})
diff --git a/src/metabase/models/resolution.clj b/src/metabase/models/resolution.clj
index 68209f8ae52..9d710379f51 100644
--- a/src/metabase/models/resolution.clj
+++ b/src/metabase/models/resolution.clj
@@ -125,18 +125,7 @@
:model/User metabase.users.models.user
:model/UserKeyValue metabase.user-key-value.models.user-key-value
:model/UserParameterValue metabase.users.models.user-parameter-value
- :model/ViewLog metabase.view-log.models.view-log
- :model/Workspace metabase-enterprise.workspaces.models.workspace
- :model/WorkspaceInput metabase-enterprise.workspaces.models.workspace-input
- :model/WorkspaceInputExternal metabase-enterprise.workspaces.models.workspace-input-external
- :model/WorkspaceInputTransform metabase-enterprise.workspaces.models.workspace-input-transform
- :model/WorkspaceLog metabase-enterprise.workspaces.models.workspace-log
- :model/WorkspaceMerge metabase-enterprise.workspaces.models.workspace-merge
- :model/WorkspaceMergeTransform metabase-enterprise.workspaces.models.workspace-merge-transform
- :model/WorkspaceOutput metabase-enterprise.workspaces.models.workspace-output
- :model/WorkspaceOutputExternal metabase-enterprise.workspaces.models.workspace-output-external
- :model/WorkspaceGraph metabase-enterprise.workspaces.models.workspace-graph
- :model/WorkspaceTransform metabase-enterprise.workspaces.models.workspace-transform})
+ :model/ViewLog metabase.view-log.models.view-log})
;;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;;; !! !!
diff --git a/src/metabase/premium_features/core.clj b/src/metabase/premium_features/core.clj
index 29854061ad8..435cc1cf906 100644
--- a/src/metabase/premium_features/core.clj
+++ b/src/metabase/premium_features/core.clj
@@ -86,7 +86,6 @@
enable-python-transforms?
enable-upload-management?
enable-whitelabeling?
- enable-workspaces?
enable-writable-connection?
has-attached-dwh?
hide-embed-branding?
diff --git a/src/metabase/premium_features/settings.clj b/src/metabase/premium_features/settings.clj
index a1e4c4cb32f..a81a23d539e 100644
--- a/src/metabase/premium_features/settings.clj
+++ b/src/metabase/premium_features/settings.clj
@@ -309,10 +309,6 @@
"Should the multi-tenant feature be enabled?"
:tenants)
-(define-premium-feature ^{:added "0.59.0"} enable-workspaces?
- "Should we allow users to use workspaces?"
- :workspaces)
-
(define-premium-feature enable-metabot-v3?
"Should we allow users to use the Metabase-managed tiered AI provider?"
:metabot-v3)
@@ -384,7 +380,6 @@
:transforms-python (enable-python-transforms?)
:upload_management (enable-upload-management?)
:whitelabel (enable-whitelabeling?)
- :workspaces (enable-workspaces?)
:writable_connection (enable-writable-connection?)
:ai_controls (enable-ai-controls?)})
diff --git a/src/metabase/transforms/crud.clj b/src/metabase/transforms/crud.clj
index 498538aa1c9..e251045e16a 100644
--- a/src/metabase/transforms/crud.clj
+++ b/src/metabase/transforms/crud.clj
@@ -1,6 +1,6 @@
(ns metabase.transforms.crud
"CRUD operations for transforms. Extracted from `metabase.transforms-rest.api.transform`
- so that non-REST modules (e.g. metabot-v3, workspaces) can use them without depending
+ so that non-REST modules (e.g. metabot-v3) can use them without depending
on the `-rest` module."
(:require
[clojure.string :as str]
@@ -107,7 +107,7 @@
(defn create-transform!
"Create new transform in the appdb.
- Optionally accepts a creator-id to use instead of the current user (for workspace merges)."
+ Optionally accepts a creator-id to use instead of the current user."
([body]
(create-transform! body nil))
([body creator-id]
diff --git a/src/metabase/transforms_rest/api/transform.clj b/src/metabase/transforms_rest/api/transform.clj
index c74f91f5328..2fac307e075 100644
--- a/src/metabase/transforms_rest/api/transform.clj
+++ b/src/metabase/transforms_rest/api/transform.clj
@@ -193,34 +193,6 @@
(->> (t2/hydrate dependencies :creator :owner)
transforms.u/add-source-readable)))
-(def ^:private MergeHistoryEntry
- [:map
- [:id ms/PositiveInt]
- [:workspace_merge_id ms/PositiveInt]
- [:commit_message :string]
- [:workspace_id [:maybe ms/PositiveInt]]
- [:workspace_name :string]
- [:merging_user_id ms/PositiveInt]
- [:created_at :any]])
-
-(api.macros/defendpoint :get "/:id/merge-history"
- :- [:sequential MergeHistoryEntry]
- "Get merge history for a transform. Returns all merge events that affected this transform,
- ordered by created_at descending (newest first)."
- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]
- (api/check-superuser)
- (api/check-404 (t2/select-one :model/Transform id))
- (t2/select [:model/WorkspaceMergeTransform
- :id
- :workspace_merge_id
- :commit_message
- :workspace_id
- :workspace_name
- :merging_user_id
- :created_at]
- {:where [:= :transform_id id]
- :order-by [[:created_at :desc]]}))
-
(api.macros/defendpoint :get "/run" :- [:map {:closed true}
[:data [:sequential TransformRunResponse]]
[:limit pos-int?]
diff --git a/src/metabase/warehouse_schema/models/table.clj b/src/metabase/warehouse_schema/models/table.clj
index f34f2516b01..8d62c961407 100644
--- a/src/metabase/warehouse_schema/models/table.clj
+++ b/src/metabase/warehouse_schema/models/table.clj
@@ -438,7 +438,7 @@
(defn delete-orphaned-provisional-table!
"If `table-id` points at an inactive provisional table that is not referenced by any other
- transform or workspace row (excluding `exclude-transform-id`), delete it."
+ transform (excluding `exclude-transform-id`), delete it."
[table-id exclude-transform-id]
(when table-id
(when-let [table (t2/select-one :model/Table :id table-id
@@ -446,29 +446,17 @@
:data_source :metabase-transform)]
(let [referenced?
(seq
- (t2/query {:union
- (cons
- {:select [[[:inline 1] :ref]]
- :from [:transform]
- :where [:and
- [:= :target_table_id (:id table)]
- [:not= :id exclude-transform-id]]}
- (for [[table-name column-name]
- [["workspace_input" "table_id"]
- ["workspace_output" "global_table_id"]
- ["workspace_output" "isolated_table_id"]
- ["workspace_output_external" "global_table_id"]
- ["workspace_output_external" "isolated_table_id"]
- ["workspace_input_external" "table_id"]]]
- {:select [[[:inline 1] :ref]]
- :from [(keyword table-name)]
- :where [:= (keyword column-name) (:id table)]}))}))]
+ (t2/query {:select [[[:inline 1] :ref]]
+ :from [:transform]
+ :where [:and
+ [:= :target_table_id (:id table)]
+ [:not= :id exclude-transform-id]]}))]
(when-not referenced?
(t2/delete! :model/Table :id (:id table)))))))
(defn gc-transform-target-tables!
"Deletes provisional table rows (created by [[upsert-transform-target-table!]]) that are no longer
- referenced by any Transform or workspace table. Safe because these rows were never active,
+ referenced by any Transform. Safe because these rows were never active,
so they have no child records.
Note: this only handles *inactive* provisional tables. Active tables that were previously
@@ -485,20 +473,11 @@
(let [referenced-ids
(into #{}
(map :id)
- (t2/query {:union
- (for [[table-name column-name]
- [["transform" "target_table_id"]
- ["workspace_input" "table_id"]
- ["workspace_output" "global_table_id"]
- ["workspace_output" "isolated_table_id"]
- ["workspace_output_external" "global_table_id"]
- ["workspace_output_external" "isolated_table_id"]
- ["workspace_input_external" "table_id"]]]
- {:select [[(keyword column-name) :id]]
- :from [(keyword table-name)]
- :where [:and
- [:not= (keyword column-name) nil]
- [:in (keyword column-name) candidate-ids]]})}))
+ (t2/query {:select [[:target_table_id :id]]
+ :from [:transform]
+ :where [:and
+ [:not= :target_table_id nil]
+ [:in :target_table_id candidate-ids]]}))
dead-ids (into [] (remove referenced-ids) candidate-ids)]
(when (seq dead-ids)
(log/infof "Deleting %d orphaned transform target table(s)" (count dead-ids))
diff --git a/src/metabase/warehouses/models/database.clj b/src/metabase/warehouses/models/database.clj
index 22368aeac15..840e4b3c2f0 100644
--- a/src/metabase/warehouses/models/database.clj
+++ b/src/metabase/warehouses/models/database.clj
@@ -57,8 +57,7 @@
:cache_field_values_schedule mi/transform-cron-string
:start_of_week mi/transform-keyword
:settings mi/transform-encrypted-json
- :dbms_version mi/transform-json
- :workspace_permissions_status mi/transform-json})
+ :dbms_version mi/transform-json})
(methodical/defmethod t2/model-for-automagic-hydration [:default :database] [_model _k] :model/Database)
(methodical/defmethod t2/model-for-automagic-hydration [:default :db] [_model _k] :model/Database)
@@ -595,31 +594,6 @@
(log/debug "Redacting non-user-readable database settings during json encoding.")))))))
json-generator)))
-;;; ------------------------------------------ Workspace Permissions Cache --------------------------------------------
-
-(defn check-workspace-permissions
- "Check isolation permissions for a database. Returns the permission check result:
- {:status \"ok\", :checked_at ...} or {:status \"failed\", :error \"...\", :checked_at ...}
- Does NOT update the database - use [[check-and-cache-workspace-permissions!]] if you need to persist."
- [database]
- (let [checked-at (java.time.Instant/now)]
- (try
- (let [db-driver (driver.u/database->driver database)]
- (if-let [error (driver/check-isolation-permissions db-driver database nil)]
- {:status "failed", :error error, :checked_at (str checked-at)}
- {:status "ok", :checked_at (str checked-at)}))
- (catch Exception e
- {:status "failed", :error (ex-message e), :checked_at (str checked-at)}))))
-
-(defn check-and-cache-workspace-permissions!
- "Check isolation permissions for a database and cache the result in workspace_permissions_status column.
- Returns the permission check result: {:status \"ok\", :checked_at ...}
- or {:status \"failed\", :error \"...\", :checked_at ...}"
- [database]
- (let [result (check-workspace-permissions database)]
- (t2/update! :model/Database (:id database) {:workspace_permissions_status result})
- result))
-
;;; ------------------------------------------------ Serialization ----------------------------------------------------
(defmethod serdes/make-spec "Database"
[_model-name {:keys [include-database-secrets]}]
@@ -628,9 +602,7 @@
:metadata_sync_schedule :name :points_of_interest :provider_name :refingerprint :settings :timezone :uploads_enabled
:uploads_schema_name :uploads_table_prefix]
:skip [;; deprecated field
- :cache_ttl
- ;; workspace_permissions_status is instance-specific and should not be serialized
- :workspace_permissions_status]
+ :cache_ttl]
:transform {:created_at (serdes/date)
;; details should be imported if available regardless of options
:details {:export-with-context
diff --git a/src/metabase/warehouses_rest/api.clj b/src/metabase/warehouses_rest/api.clj
index 8567b2df84a..1ccfbf07b45 100644
--- a/src/metabase/warehouses_rest/api.clj
+++ b/src/metabase/warehouses_rest/api.clj
@@ -1777,24 +1777,6 @@
(delete-all-field-values-for-database! db))
{:status :ok})
-(api.macros/defendpoint :post "/:id/permission/workspace/check"
- :- [:map
- [:status :string]
- [:checked_at :string]
- [:error {:optional true} :string]]
- "Check if database's connection has the required permissions to manage workspaces.
- By default it'll return the cached permission check."
- [{:keys [id cached]} :- [:map [:id ms/PositiveInt]
- [:cached {:optional true
- :default true} :boolean]]]
- (api/check-superuser)
- (let [db (api/check-404 (t2/select-one :model/Database id))
- _ (api/check-400 (driver.u/supports? (:engine db) :workspace db)
- "Database does not support workspaces")]
- (or (when cached
- (t2/select-one-fn :workspace_permissions_status :model/Database id))
- (database/check-and-cache-workspace-permissions! db))))
-
;;; ------------------------------------------ GET /api/database/:id/schemas -----------------------------------------
(defenterprise current-user-can-manage-schema-metadata?
@@ -1839,7 +1821,7 @@
(defn database-schemas
"Returns a list of all the schemas with tables found for the database `id`. Excludes schemas with no tables."
- [id {:keys [include-editable-data-model? include-hidden? can-query? can-write-metadata? include-workspace?]}]
+ [id {:keys [include-editable-data-model? include-hidden? can-query? can-write-metadata?]}]
(let [filter-schemas (fn [schemas]
(if include-editable-data-model?
(if-let [f (u/ignore-exceptions
@@ -1851,18 +1833,7 @@
clauses (cond-> []
;; a non-nil value means Table is hidden --
;; see [[metabase.warehouse-schema.models.table/visibility-types]]
- (not include-hidden?) (conj [:= :visibility_type nil])
- (not include-workspace?) (conj [:or
- [:= :schema nil]
- [:not
- (driver.u/workspace-isolated-schema-clause :schema)
- ;; TODO (Chris 2025-12-09) -- this might behave terribly without an index when there are lots of workspaces
- #_[:exists {:select [1]
- :from [[(t2/table-name :model/Workspace) :w]]
- :where [:and
- [:= :w.database_id id]
- [:= :w.schema :metabase_table.schema]
- [:= :w.archived_at nil]]}]]]))
+ (not include-hidden?) (conj [:= :visibility_type nil]))
;; For can-query? and can-write-metadata?, we need to filter based on tables in each schema
filter-schemas-by-tables (fn [schemas]
(if (or can-query? can-write-metadata?)
@@ -1902,22 +1873,15 @@
{:keys [include_editable_data_model
include_hidden
can-query
- can-write-metadata
- include_workspace]} :- [:map
- [:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]
- [:include_hidden {:default false} [:maybe ms/BooleanValue]]
- [:can-query {:optional true} [:maybe :boolean]]
- [:can-write-metadata {:optional true} [:maybe :boolean]]
- [:include_workspace {:default false} [:maybe ms/BooleanValue]]]]
+ can-write-metadata]} :- [:map
+ [:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]
+ [:include_hidden {:default false} [:maybe ms/BooleanValue]]
+ [:can-query {:optional true} [:maybe :boolean]]
+ [:can-write-metadata {:optional true} [:maybe :boolean]]]]
(database-schemas id {:include-editable-data-model? include_editable_data_model
- :include-hidden? include_hidden
+ :include-hidden? include_hidden
:can-query? can-query
- :can-write-metadata? can-write-metadata
- ;; TODO (Chris 2025-12-09) -- filtering out workspace schemas has a weird FE consequence - if you type one of those
- ;; schemas out manually in the targets, it will offer to create it for you.
- ;; this ends up being a no-op, so i guess it's harmless for now?
- ;; it will look very weird when we add validation to refuse saving that target.
- :include-workspace? include_workspace}))
+ :can-write-metadata? can-write-metadata}))
;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to
;; use our API + we will need it when we make auto-TypeScript-signature generation happen
diff --git a/src/metabase/workspaces/core.clj b/src/metabase/workspaces/core.clj
deleted file mode 100644
index 572e66e39fd..00000000000
--- a/src/metabase/workspaces/core.clj
+++ /dev/null
@@ -1,35 +0,0 @@
-(ns metabase.workspaces.core
- "Workspace utilities that operate on the raw database tables (which exist in all editions).
- These must run regardless of whether the workspaces feature flag is enabled, because workspace
- data can exist from a previous period when it was enabled, and we need to maintain invariants
- on that data so it isn't corrupt when the feature is re-enabled."
- (:require
- [metabase.util.json :as json]
- [toucan2.core :as t2]))
-
-(defn target->triple
- "Extracts `[db_id schema name]` from a target map."
- [{:keys [database schema name]}]
- [database schema name])
-
-(defn- parse-target
- "Parses target JSON — raw query bypasses Toucan2 model transforms."
- [target]
- (if (string? target)
- (try (json/decode+kw target)
- (catch Exception _ nil))
- target))
-
-(defn reducible-target-triples
- "Reducible of `[db_id schema name]` triples for workspace transforms targeting any of the given `db-ids`.
- Used by [[metabase.warehouse-schema.models.table/gc-transform-target-tables!]]."
- [db-ids]
- (eduction
- (map (fn [{:keys [target database_id]}]
- (-> (parse-target target)
- (update :database #(or % database_id))
- target->triple)))
- (t2/reducible-query {:select [[:wt.target :target], [:w.database_id :database_id]]
- :from [[:workspace_transform :wt]]
- :join [[:workspace :w] [:= :wt.workspace_id :w.id]]
- :where [:in :w.database_id db-ids]})))
diff --git a/test/metabase/app_db/custom_migrations_test.clj b/test/metabase/app_db/custom_migrations_test.clj
index 17b1ee2cc34..71bb0dc4c69 100644
--- a/test/metabase/app_db/custom_migrations_test.clj
+++ b/test/metabase/app_db/custom_migrations_test.clj
@@ -2943,97 +2943,10 @@
(testing "Native transform strategy is stripped (can't resolve source table)"
(is (not (contains? (get-source native-id) :source-incremental-strategy))))))))
-(deftest unify-source-tables-format-test
- (testing "v60.2026-03-03T12:00:00: convert source-tables from map to vec format"
- (impl/test-migrations ["v60.2026-03-03T12:00:00"] [migrate!]
- (let [user-id (:id (new-instance-with-default :core_user))
- db-id (:id (new-instance-with-default :metabase_database))
- ;; source-tables as map with int values (FE format)
- int-source (json/encode {:type "python" :body "x=1" :source-database db-id
- :source-tables {"orders" 42 "products" 99}})
- ;; source-tables as map with ref values (normalized format)
- ref-source (json/encode {:type "python" :body "x=1" :source-database db-id
- :source-tables {"input" {"database_id" db-id "schema" "public"
- "table" "my_table" "table_id" 7}}})
- ;; query transform (no source-tables) — should be untouched
- query-source (json/encode {:type "query" :query {:database db-id}})
- target (json/encode {:type "table" :schema "public" :name "out"})
- insert-transform!
- (fn [source]
- (t2/insert-returning-pk!
- :transform {:name (mt/random-name)
- :source source
- :target target
- :source_type "python"
- :source_database_id db-id
- :created_at :%now
- :updated_at :%now}))
- int-id (insert-transform! int-source)
- ref-id (insert-transform! ref-source)
- query-id (insert-transform! query-source)
- ;; Also test workspace_transform
- ws-id (:id (t2/insert-returning-instance!
- :workspace {:name "test-ws"
- :creator_id user-id
- :created_at :%now
- :updated_at :%now}))
- _ (t2/insert! :workspace_transform
- {:ref_id (str (random-uuid))
- :workspace_id ws-id
- :name "ws-transform"
- :source int-source
- :target target
- :created_at :%now
- :updated_at :%now})
- get-source-tables (fn [table-name pk-map]
- (let [where (into [:and] (map (fn [[k v]] [:= k v]) pk-map))
- row (first (t2/query {:select [:source] :from [table-name] :where where}))]
- (get (json/decode (:source row)) "source-tables")))]
- (testing "Before migration, source-tables are maps"
- (is (map? (get-source-tables :transform {:id int-id})))
- (is (map? (get-source-tables :transform {:id ref-id}))))
-
- (migrate!)
-
- (testing "After migration, int-value maps become vec of entries"
- (let [st (get-source-tables :transform {:id int-id})]
- (is (sequential? st))
- (is (= 2 (count st)))
- (is (= #{"orders" "products"} (set (map #(get % "alias") st))))
- (is (= #{42 99} (set (map #(get % "table_id") st))))))
-
- (testing "After migration, ref-value maps become vec of entries with alias"
- (let [st (get-source-tables :transform {:id ref-id})]
- (is (sequential? st))
- (is (= "input" (get (first st) "alias")))
- (is (= 7 (get (first st) "table_id")))))
-
- (testing "Query transforms are untouched"
- (is (nil? (get-source-tables :transform {:id query-id}))))
-
- (testing "workspace_transform is also migrated"
- (let [ws-rows (t2/query {:select [:source] :from [:workspace_transform] :where [:= :workspace_id ws-id]})
- st (get (json/decode (:source (first ws-rows))) "source-tables")]
- (is (sequential? st))
- (is (= 2 (count st)))))
-
- (testing "Rollback converts vec back to map"
- (migrate! :down 59)
- (let [st (get-source-tables :transform {:id int-id})]
- (is (map? st))
- (is (= 42 (get st "orders")))
- (is (= 99 (get st "products")))))))))
-
(deftest backfill-transform-target-tables-test
- (testing "v60.2026-03-07T00:00:04 : backfill transform target tables and invalidate workspace caches"
+ (testing "v60.2026-03-07T00:00:04 : backfill transform target tables"
(impl/test-migrations ["v60.2026-03-07T00:00:04"] [migrate!]
- (let [user-id (:id (new-instance-with-default :core_user))
- db-id (:id (new-instance-with-default :metabase_database))
- ws-id (:id (t2/insert-returning-instance!
- :workspace {:name "test-ws"
- :creator_id user-id
- :created_at :%now
- :updated_at :%now}))
+ (let [db-id (:id (new-instance-with-default :metabase_database))
source (json/encode {:type "query" :query {:database db-id}})
;; -- Transform with a target that has no existing metabase_table → should create provisional row --
_ (t2/insert-returning-pk!
@@ -3044,19 +2957,7 @@
:source_database_id db-id
:target_db_id db-id
:created_at :%now
- :updated_at :%now})
- ;; -- workspace_transform to verify analysis_version bump --
- _ (t2/insert! :workspace_transform
- {:ref_id (str (random-uuid))
- :workspace_id ws-id
- :name "ws-tx"
- :source source
- :target (json/encode {:type "table" :schema "public" :name "orders"})
- :created_at :%now
- :updated_at :%now})]
- (testing "Before migration"
- (is (= 1 (:graph_version (t2/select-one :workspace :id ws-id))))
- (is (= 1 (:analysis_version (first (t2/select :workspace_transform :workspace_id ws-id))))))
+ :updated_at :%now})]
(migrate!)
(testing "Provisional metabase_table created for transform target"
(let [provisional (first (t2/query {:select [:active :transform_target :data_source :data_authority :display_name]
@@ -3070,8 +2971,4 @@
(is (true? (:transform_target provisional)))
(is (= "metabase-transform" (:data_source provisional)))
(is (= "computed" (:data_authority provisional)))
- (is (= "New Target Table" (:display_name provisional)))))
- (testing "Workspace caches invalidated"
- ;; Both BackfillTransformTargetTables and BackfillTransformTargetTableId bump these
- (is (= 3 (:graph_version (t2/select-one :workspace :id ws-id))))
- (is (= 3 (:analysis_version (first (t2/select :workspace_transform :workspace_id ws-id))))))))))
+ (is (= "New Target Table" (:display_name provisional)))))))))
diff --git a/test/metabase/cmd/copy_test.clj b/test/metabase/cmd/copy_test.clj
index 1e3731916d4..ac5ab0bbd29 100644
--- a/test/metabase/cmd/copy_test.clj
+++ b/test/metabase/cmd/copy_test.clj
@@ -66,18 +66,7 @@
:model/TransformTag
:model/TransformTransformTag
:model/Undo
- :model/UserKeyValue
- :model/Workspace
- :model/WorkspaceGraph
- :model/WorkspaceInput
- :model/WorkspaceInputExternal
- :model/WorkspaceInputTransform
- :model/WorkspaceLog
- :model/WorkspaceMerge
- :model/WorkspaceMergeTransform
- :model/WorkspaceOutput
- :model/WorkspaceOutputExternal
- :model/WorkspaceTransform})
+ :model/UserKeyValue})
(defn- all-model-names []
(into (sorted-set)
diff --git a/test/metabase/revisions/impl/card_test.clj b/test/metabase/revisions/impl/card_test.clj
index 5db31dab234..a3619378b78 100644
--- a/test/metabase/revisions/impl/card_test.clj
+++ b/test/metabase/revisions/impl/card_test.clj
@@ -138,9 +138,7 @@
:card_schema
;; we don't expect a description for this column because it should never change
;; once created by the migration
- :dataset_query_metrics_v2_migration_backup
- ;; this column is immutable in practice, and doesn't warrant a description
- :workspace_id}
+ :dataset_query_metrics_v2_migration_backup}
col)
(testing (format "we should have a revision description for %s" col)
(let [diff-strings (revision/diff-strings
diff --git a/test/metabase/search/appdb/index_test.clj b/test/metabase/search/appdb/index_test.clj
index a74e5971041..a393c7c3ab7 100644
--- a/test/metabase/search/appdb/index_test.clj
+++ b/test/metabase/search/appdb/index_test.clj
@@ -547,8 +547,7 @@
"metabase_table" #{"action" "measure" "model_index_value" "report_card" "segment"}
"document" #{"action" "model_index_value" "report_card"}
"report_card" #{"action" "model_index_value"}
- "report_dashboard" #{"action" "model_index_value" "report_card"}
- "workspace" #{"collection"}})
+ "report_dashboard" #{"action" "model_index_value" "report_card"}})
(deftest search-model-cascade-test
(is (= model->deleted-descendants
diff --git a/test/metabase/test/util.clj b/test/metabase/test/util.clj
index 010814b3f7e..160913294c1 100644
--- a/test/metabase/test/util.clj
+++ b/test/metabase/test/util.clj
@@ -20,7 +20,6 @@
[metabase.collections.models.collection :as collection]
[metabase.config.core :as config]
[metabase.content-verification.models.moderation-review :as moderation-review]
- [metabase.driver.util :as driver.u]
[metabase.lib.core :as lib]
[metabase.permissions-rest.data-permissions.graph :as data-perms.graph]
[metabase.permissions.core :as perms]
@@ -49,8 +48,7 @@
[toucan2.model :as t2.model]
[toucan2.tools.before-update :as t2.before-update]
[toucan2.tools.transformed :as t2.transformed]
- [toucan2.tools.with-temp :as t2.with-temp]
- [toucan2.util :as t2.u])
+ [toucan2.tools.with-temp :as t2.with-temp])
(:import
(java.io File FileInputStream)
(java.net ServerSocket)
@@ -376,46 +374,7 @@
:email (u.random/random-email)
:password (u.random/random-name)
:date_joined (t/zoned-date-time)
- :updated_at (t/zoned-date-time)})
-
- :model/Workspace
- (fn [_]
- (default-timestamped
- {:name (str "Test Workspace " (u/generate-nano-id))
- :schema (str @#'driver.u/workspace-isolated-prefix (u/generate-nano-id))}))
-
- :model/WorkspaceTransform
- (fn [_]
- (default-timestamped
- {:name (str "Test Transform " (u/generate-nano-id))
- :ref_id ((requiring-resolve 'metabase-enterprise.workspaces.util/generate-ref-id))
- :source {:type "query"
- :query (lib/native-query (data/metadata-provider) "SELECT 1 as num")}
- :target {:type "table"
- :name (str "test_table_" (str/replace (u/generate-nano-id) "-" "_"))}}))})
-
-;; WorkspaceTransform use composite primary keys are currently t2/insert-returning-instance!
-;; does not return the instance for model with composite keys on h2 and mysql
-;; so we have to define a custom with-temp here
-(methodical/defmethod t2.with-temp/do-with-temp* :model/WorkspaceTransform
- [model explicit-attributes f]
- (assert (some? model) (format "%s model cannot be nil." `with-temp))
- (when (some? explicit-attributes)
- (assert (map? explicit-attributes) (format "attributes passed to %s must be a map." `with-temp)))
- (let [defaults (t2.with-temp/with-temp-defaults model)
- merged-attributes (merge {} defaults explicit-attributes)]
- (t2.u/try-with-error-context ["with temp" {::model model
- ::explicit-attributes explicit-attributes
- ::default-attributes defaults
- ::merged-attributes merged-attributes}]
- (let [temp-object (or (t2/insert-returning-instance! model merged-attributes)
- (t2/select-one :model/WorkspaceTransform :ref_id (:ref_id merged-attributes)
- :workspace_id (:workspace_id merged-attributes)))]
- (try
- (testing (format "\nwith temporary %s\n" (pr-str model))
- (f temp-object))
- (finally
- (t2/delete! model :toucan/pk ((t2/select-pks-fn model) temp-object))))))))
+ :updated_at (t/zoned-date-time)})})
;; `with-temp` cleanup calls `t2/delete!` directly, which would hit our before-delete guard.
;; Bind `*allow-direct-deletion*` so with-temp cleanup works.
@@ -893,11 +852,6 @@
[_]
[:not= :id audit/audit-db-id])
-(def ^:private models-with-cleanup-hooks
- "Models that require `t2/delete!` instead of raw SQL delete during cleanup.
- Use this for models that have `before-delete` or `after-delete` hooks that must run."
- #{:model/Workspace})
-
(defn- model->model&pk [model]
(if (vector? model)
model
@@ -931,21 +885,16 @@
max-id-condition (if old-max-id [:> pk old-max-id] true)
additional-conditions (with-model-cleanup-additional-conditions model)
where-clause [:and max-id-condition additional-conditions]]]
- (if (contains? models-with-cleanup-hooks model)
- ;; Use t2/delete! to trigger before-delete/after-delete hooks
- (t2/delete! model {:where where-clause})
- ;; Fast path: raw SQL for models without hooks
- (t2/query-one
- {:delete-from (t2/table-name model)
- :where where-clause})))
+ (t2/query-one
+ {:delete-from (t2/table-name model)
+ :where where-clause}))
;; TODO we don't (currently) have index update hooks on deletes, so we need this to ensure rollback happens.
(search/reindex! {:in-place? true :async? false})))))
(defmacro with-model-cleanup
"Execute `body`, then delete any *new* rows created for each model in `models`.
- By default, uses raw SQL DELETE for performance. For models in [[models-with-cleanup-hooks]],
- uses `t2/delete!` to ensure `before-delete`/`after-delete` hooks are triggered.
+ Uses raw SQL DELETE for performance. Does not trigger `before-delete`/`after-delete` hooks.
It's preferable to use `with-temp` instead, but you can use this macro if `with-temp` wouldn't work in your
situation (e.g. when creating objects via the API).
diff --git a/test/metabase/warehouse_schema_rest/api/table_test.clj b/test/metabase/warehouse_schema_rest/api/table_test.clj
index ca0e6efa9c9..1fc3a696b32 100644
--- a/test/metabase/warehouse_schema_rest/api/table_test.clj
+++ b/test/metabase/warehouse_schema_rest/api/table_test.clj
@@ -53,7 +53,6 @@
:settings {}
:cache_ttl nil
:provider_name nil
- :workspace_permissions_status nil
:is_audit false}))
(defn- table-defaults
diff --git a/test/metabase/warehouses_rest/api_test.clj b/test/metabase/warehouses_rest/api_test.clj
index 8baf6f45bf9..643b0a59c7f 100644
--- a/test/metabase/warehouses_rest/api_test.clj
+++ b/test/metabase/warehouses_rest/api_test.clj
@@ -3001,63 +3001,6 @@
:api-test-disabled-for-custom-reasons
:api-test-disabled-for-multiple-reasons])))))))))
-;;; ---------------------------------------- workspace permissions endpoint tests ----------------------------------------
-
-(deftest workspace-permission-endpoint-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (testing "POST /api/database/:id/permission/workspace/check"
- (testing "returns cached status when available"
- ;; First call to populate cache
- (mt/user-http-request :crowberto :post 200
- (format "database/%d/permission/workspace/check" (mt/id))
- {:cached false})
- ;; Second call should return cached result
- (let [response (mt/user-http-request :crowberto :post 200
- (format "database/%d/permission/workspace/check" (mt/id)))]
- (is (= "ok" (:status response)))
- (is (some? (:checked_at response)))
- (is (nil? (:error response)))))
-
- (testing "runs permission check when no cache exists"
- ;; Clear the cache
- (t2/update! :model/Database (mt/id) {:workspace_permissions_status nil})
- (let [response (mt/user-http-request :crowberto :post 200
- (format "database/%d/permission/workspace/check" (mt/id)))]
- (is (= "ok" (:status response)) (str "response: " (pr-str response)))
- (is (some? (:checked_at response)))
- ;; Verify it was cached
- (let [db (t2/select-one :model/Database (mt/id))]
- (is (= "ok" (:status (:workspace_permissions_status db)))
- (str "cached: " (pr-str (:workspace_permissions_status db)))))))
-
- (testing "cached=false forces permission check"
- ;; Set a stale cache value
- (t2/update! :model/Database (mt/id) {:workspace_permissions_status {:status "stale" :checked_at "2020-01-01T00:00:00Z"}})
- (let [response (mt/user-http-request :crowberto :post 200
- (format "database/%d/permission/workspace/check" (mt/id))
- {:cached false})]
- (is (= "ok" (:status response)))
- ;; Verify cache was updated
- (let [db (t2/select-one :model/Database (mt/id))]
- (is (= "ok" (:status (:workspace_permissions_status db)))))))
-
- (testing "requires superuser"
- (is (= "You don't have permissions to do that."
- (mt/user-http-request :rasta :post 403
- (format "database/%d/permission/workspace/check" (mt/id)))))))))
-
-(deftest workspace-permission-failure-test
- (mt/test-drivers (mt/normal-drivers-with-feature :workspace)
- (testing "returns failed status when permissions check fails"
- (mt/with-dynamic-fn-redefs [driver/check-isolation-permissions
- (fn [_driver _database _table]
- "permission denied")]
- (let [response (mt/user-http-request :crowberto :post 200
- (format "database/%d/permission/workspace/check" (mt/id))
- {:cached false})]
- (is (= "failed" (:status response)))
- (is (= "permission denied" (:error response))))))))
-
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | can-query filter tests |
;;; +----------------------------------------------------------------------------------------------------------------+