The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Dependencies - unreferenced & broken items (#66279)
Alexander Polyankinda9fbb67a2fa
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex e2de3c73d23..64479825711 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -498,7 +498,8 @@:api #{metabase.documents.apimetabase.documents.coremetabase.documents.init- metabase.documents.prose-mirror}+ metabase.documents.prose-mirror+ metabase.documents.schema}:uses #{activity-feedapiapp-db@@ -748,6 +749,7 @@metabase.lib.schema.template-tagmetabase.lib.schema.temporal-bucketingmetabase.lib.schema.util+ metabase.lib.schema.validatemetabase.lib.temporal-bucketmetabase.lib.types.isametabase.lib.util@@ -965,6 +967,7 @@app-dbclassloaderconfig+ eventsinternal-statssettingstask@@ -1056,6 +1059,7 @@configcontent-verificationdashboards+ documentseventsliblib-be@@ -1961,7 +1965,9 @@metabase-enterprise.dependencies.init}:uses #{analyzeapi+ app-dbcollections+ configdocumentsdriverevents@@ -1977,7 +1983,8 @@revisionssettingstask- util}}+ util+ enterprise/transforms}}enterprise/email{:team "UX West"@@ -2211,6 +2218,7 @@appearancecollectionsconfig+ eventsloggermodelsplugins@@ -2296,6 +2304,7 @@metabase-enterprise.transforms.initmetabase-enterprise.transforms.instrumentationmetabase-enterprise.transforms.interface+ metabase-enterprise.transforms.schemametabase-enterprise.transforms.util}:uses #{analyticsapidiff --git a/e2e/support/helpers/e2e-data-studio-helpers.ts b/e2e/support/helpers/e2e-data-studio-helpers.tsindex a477b00ca65..87ff8cf1327 100644--- a/e2e/support/helpers/e2e-data-studio-helpers.ts+++ b/e2e/support/helpers/e2e-data-studio-helpers.ts@@ -130,4 +130,22 @@ export const DataStudio = {collectionItem: (name: string) =>libraryPage().findAllByTestId("collection-name").contains(name),},+ Tasks: {+ visitBrokenEntities: () => cy.visit("/data-studio/tasks/broken"),+ visitUnreferencedEntities: () =>+ cy.visit("/data-studio/tasks/unreferenced"),+ list: () => cy.findByTestId("dependency-list"),+ searchInput: () => cy.findByTestId("dependency-list-search-input"),+ filterButton: () => cy.findByTestId("dependency-list-filter-button"),+ sidebar: () => cy.findByTestId("dependency-list-sidebar"),++ Sidebar: {+ get: () => cy.findByTestId("dependency-list-sidebar"),+ header: () => cy.findByTestId("dependency-list-sidebar-header"),+ locationInfo: () => cy.findByRole("region", { name: "Location" }),+ errorInfo: (label: string) => cy.findByRole("region", { name: label }),+ creationInfo: () =>+ cy.findByRole("region", { name: "Creator and last editor" }),+ },+ },};diff --git a/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.tsnew file mode 100644index 00000000000..57fbb23707b--- /dev/null+++ b/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts@@ -0,0 +1,520 @@+const { H } = cy;++import { WRITABLE_DB_ID } from "e2e/support/cypress_data";+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";+import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";+import type { CardId, CardType, FieldId, TableId } from "metabase-types/api";++const { ORDERS_ID, ORDERS, REVIEWS } = SAMPLE_DATABASE;++const WRITABLE_TABLE_NAME = "scoreboard_actions";++const VALID_CARD_COLUMN_ID = "Valid card column with id";+const VALID_CARD_COLUMN_NAME = "Valid card column with name";+const VALID_NATIVE_CARD = "Valid native card";+const VALID_SEGMENT = "Valid segment";+const VALID_METRIC = "Valid metric";++const VALID_ENTITY_NAMES = [+ VALID_CARD_COLUMN_ID,+ VALID_CARD_COLUMN_NAME,+ VALID_NATIVE_CARD,+ VALID_SEGMENT,+ VALID_METRIC,+];++const CARD_COLUMN_ID_MISSING = "Card with a non-existing column with an id";+const CARD_COLUMN_WRONG_TABLE = "Card with a column on a wrong table";+const CARD_COLUMN_NAME_MISSING = "Card with a non-existing column with a name";+const NATIVE_CARD_COLUMN_MISSING = "Native card with a non-existing column";+const NATIVE_CARD_TABLE_ALIAS_MISSING =+ "Native card with a missing table alias";+const NATIVE_CARD_SYNTAX_ERROR = "Native card with a syntax error";++const BROKEN_MBQL_CARD_NAMES = [+ CARD_COLUMN_ID_MISSING,+ CARD_COLUMN_WRONG_TABLE,+ CARD_COLUMN_NAME_MISSING,+];++const BROKEN_MBQL_CARD_ERRORS = {+ [CARD_COLUMN_ID_MISSING]: { "1 missing column": ["Unknown Field"] },+ [CARD_COLUMN_WRONG_TABLE]: { "1 missing column": ["RATING"] },+ [CARD_COLUMN_NAME_MISSING]: { "1 missing column": ["BAD_NAME"] },+};++const BROKEN_NATIVE_CARD_NAMES = [+ NATIVE_CARD_COLUMN_MISSING,+ NATIVE_CARD_TABLE_ALIAS_MISSING,+ NATIVE_CARD_SYNTAX_ERROR,+];++const BROKEN_NATIVE_CARD_ERRORS = {+ [NATIVE_CARD_COLUMN_MISSING]: { "1 missing column": ["RATING"] },+ [NATIVE_CARD_TABLE_ALIAS_MISSING]: { "1 missing table alias": ["P"] },+ [NATIVE_CARD_SYNTAX_ERROR]: { "1 syntax error": [] },+};++const BROKEN_CARD_NAMES = [+ ...BROKEN_MBQL_CARD_NAMES,+ ...BROKEN_NATIVE_CARD_NAMES,+];++const BROKEN_CARD_ERRORS = {+ ...BROKEN_MBQL_CARD_ERRORS,+ ...BROKEN_NATIVE_CARD_ERRORS,+};++const SEGMENT_COLUMN_ID_MISSING =+ "Segment with a non-existing column with an id";+const BROKEN_SEGMENT_NAMES = [SEGMENT_COLUMN_ID_MISSING];++const TRANSFORM_COLUMN_ID_MISSING =+ "Transform with a non-existing column with an id";+const TRANSFORM_COLUMN_WRONG_TABLE = "Transform with a column on a wrong table";+const TRANSFORM_CARD_COLUMN_MISSING =+ "Native transform with a non-existing column";+const TRANSFORM_CARD_TABLE_ALIAS_MISSING =+ "Native transform with a missing table alias";+const TRANSFORM_CARD_SYNTAX_ERROR = "Native transform with a syntax error";++const BROKEN_TRANSFORM_NAMES = [+ TRANSFORM_COLUMN_ID_MISSING,+ TRANSFORM_COLUMN_WRONG_TABLE,+ TRANSFORM_CARD_COLUMN_MISSING,+ TRANSFORM_CARD_TABLE_ALIAS_MISSING,+ TRANSFORM_CARD_SYNTAX_ERROR,+];++const BROKEN_TRANSFORM_ERRORS = {+ [TRANSFORM_COLUMN_ID_MISSING]: { "1 missing column": ["Unknown Field"] },+ [TRANSFORM_COLUMN_WRONG_TABLE]: { "1 missing column": ["Unknown Field"] },+ [TRANSFORM_CARD_COLUMN_MISSING]: { "1 missing column": ["rating"] },+ [TRANSFORM_CARD_TABLE_ALIAS_MISSING]: { "1 missing table alias": ["P"] },+ [TRANSFORM_CARD_SYNTAX_ERROR]: { "1 syntax error": [] },+};++describe("scenarios > dependencies > broken list", () => {+ beforeEach(() => {+ H.restore("postgres-writable");+ cy.signInAsAdmin();+ H.activateToken("bleeding-edge");+ H.resetTestTable({ type: "postgres", table: WRITABLE_TABLE_NAME });+ H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: WRITABLE_TABLE_NAME });+ cy.viewport(1600, 1400);+ });++ describe("analysis", () => {+ it("should not show valid entities", () => {+ createValidEntities();+ createBrokenCards({ type: "question" });+ H.DataStudio.Tasks.visitBrokenEntities();+ H.DataStudio.Tasks.list().within(() => {+ VALID_ENTITY_NAMES.forEach((name) => {+ cy.findByText(name).should("not.exist");+ });+ });+ });++ it("should show broken questions", () => {+ createBrokenCards({ type: "question" });+ H.DataStudio.Tasks.visitBrokenEntities();+ H.DataStudio.Tasks.list().within(() => {+ BROKEN_CARD_NAMES.forEach((name) => {+ cy.findByText(name).should("be.visible");+ });+ });+ });++ it("should show broken models", () => {+ createBrokenCards({ type: "model" });+ H.DataStudio.Tasks.visitBrokenEntities();+ H.DataStudio.Tasks.list().within(() => {+ BROKEN_CARD_NAMES.forEach((name) => {+ cy.findByText(name).should("be.visible");+ });+ });+ });++ it("should show broken metrics", () => {+ createBrokenCards({ type: "metric" });+ H.DataStudio.Tasks.visitBrokenEntities();+ H.DataStudio.Tasks.list().within(() => {+ BROKEN_MBQL_CARD_NAMES.forEach((name) => {+ cy.findByText(name).should("be.visible");+ });+ });+ });++ it("should show broken segments", () => {+ createBrokenSegments();+ H.DataStudio.Tasks.visitBrokenEntities();+ H.DataStudio.Tasks.list().within(() => {+ BROKEN_SEGMENT_NAMES.forEach((name) => {+ cy.findByText(name).should("be.visible");+ });+ });+ });++ it("should show broken transforms", () => {+ createBrokenTransforms();+ H.DataStudio.Tasks.visitBrokenEntities();+ H.DataStudio.Tasks.list().within(() => {+ BROKEN_TRANSFORM_NAMES.forEach((name) => {+ cy.findByText(name).should("be.visible");+ });+ });+ });+ });++ describe("search", () => {+ it("should search for entities", () => {+ createBrokenCards({ type: "question" });+ H.DataStudio.Tasks.visitBrokenEntities();+ H.DataStudio.Tasks.searchInput().type(CARD_COLUMN_ID_MISSING);+ checkList({+ visibleEntities: [CARD_COLUMN_ID_MISSING],+ hiddenEntities: [CARD_COLUMN_WRONG_TABLE],+ });+ });+ });++ describe("filters", () => {+ it("should filter entities by type", () => {+ createBrokenCards({ type: "question" });+ createBrokenSegments();+ createBrokenTransforms();+ H.DataStudio.Tasks.visitBrokenEntities();+ checkList({+ visibleEntities: [...BROKEN_CARD_NAMES, ...BROKEN_TRANSFORM_NAMES],+ });++ H.DataStudio.Tasks.filterButton().click();+ H.popover().findByText("Question").click();+ checkList({+ visibleEntities: [...BROKEN_CARD_NAMES],+ hiddenEntities: [...BROKEN_TRANSFORM_NAMES],+ });+ });+ });++ describe("sidebar", () => {+ it("should show the sidebar for questions with error info", () => {+ createBrokenCards({ type: "question" });+ H.DataStudio.Tasks.visitBrokenEntities();+ openSidebarAndCheckErrors(BROKEN_CARD_ERRORS);+ });++ it("should show the sidebar for models with error info", () => {+ createBrokenCards({ type: "model" });+ H.DataStudio.Tasks.visitBrokenEntities();+ openSidebarAndCheckErrors(BROKEN_CARD_ERRORS);+ });++ it("should show the sidebar for metrics with error info", () => {+ createBrokenCards({ type: "metric" });+ H.DataStudio.Tasks.visitBrokenEntities();+ openSidebarAndCheckErrors(BROKEN_MBQL_CARD_ERRORS);+ });++ it("should show the sidebar for transforms with error info", () => {+ createBrokenTransforms();+ H.DataStudio.Tasks.visitBrokenEntities();+ openSidebarAndCheckErrors(BROKEN_TRANSFORM_ERRORS);+ });+ });+});++function createValidEntities() {+ createCardWithFieldIdRef({+ name: VALID_CARD_COLUMN_ID,+ type: "question",+ tableId: ORDERS_ID,+ fieldId: ORDERS.TOTAL,+ });+ createCardWithFieldNameRef({+ name: VALID_CARD_COLUMN_NAME,+ type: "model",+ cardId: ORDERS_QUESTION_ID,+ fieldName: "TOTAL",+ baseType: "type/Float",+ });+ createNativeCard({+ name: VALID_NATIVE_CARD,+ type: "metric",+ query: "SELECT ID, TOTAL FROM ORDERS",+ });+ createSegmentWithFieldIdRef({+ name: VALID_SEGMENT,+ tableId: ORDERS_ID,+ fieldId: ORDERS.TOTAL,+ });+}++function createBrokenCards({ type }: { type: CardType }) {+ createCardWithFieldIdRef({+ name: CARD_COLUMN_WRONG_TABLE,+ type,+ tableId: ORDERS_ID,+ fieldId: REVIEWS.RATING,+ });+ createCardWithFieldIdRef({+ name: CARD_COLUMN_ID_MISSING,+ type,+ tableId: ORDERS_ID,+ fieldId: 1000,+ });+ createCardWithFieldNameRef({+ name: CARD_COLUMN_NAME_MISSING,+ type,+ cardId: ORDERS_QUESTION_ID,+ fieldName: "BAD_NAME",+ baseType: "type/Integer",+ });++ if (type !== "metric") {+ createNativeCard({+ name: NATIVE_CARD_COLUMN_MISSING,+ type,+ query: "SELECT ID, RATING FROM ORDERS",+ });+ createNativeCard({+ name: NATIVE_CARD_TABLE_ALIAS_MISSING,+ type,+ query: "SELECT P.ID, P.PRICE FROM ORDERS",+ });+ createNativeCard({+ name: NATIVE_CARD_SYNTAX_ERROR,+ type,+ query: "SELECT FROM",+ });+ }+}++function createBrokenSegments() {+ createSegmentWithFieldIdRef({+ name: SEGMENT_COLUMN_ID_MISSING,+ tableId: ORDERS_ID,+ fieldId: REVIEWS.RATING,+ });+}++function createBrokenTransforms() {+ H.getTableId({ name: WRITABLE_TABLE_NAME, databaseId: WRITABLE_DB_ID }).then(+ (tableId) => {+ createTransformWithFieldIdRef({+ name: TRANSFORM_COLUMN_ID_MISSING,+ tableId: tableId,+ fieldId: 1000,+ });+ createTransformWithFieldIdRef({+ name: TRANSFORM_COLUMN_WRONG_TABLE,+ tableId: tableId,+ fieldId: ORDERS.TOTAL,+ });+ createNativeTransform({+ name: TRANSFORM_CARD_COLUMN_MISSING,+ query: `SELECT RATING FROM "${WRITABLE_TABLE_NAME}"`,+ });+ createNativeTransform({+ name: TRANSFORM_CARD_TABLE_ALIAS_MISSING,+ query: `SELECT P.ID, P.PRICE FROM "${WRITABLE_TABLE_NAME}"`,+ });+ createNativeTransform({+ name: TRANSFORM_CARD_SYNTAX_ERROR,+ query: "SELECT FROM",+ });+ },+ );+}++function createCardWithFieldIdRef({+ name,+ type,+ tableId,+ fieldId,+}: {+ name: string;+ type: CardType;+ tableId: TableId;+ fieldId: FieldId;+}) {+ return H.createQuestion({+ name,+ type,+ query: {+ "source-table": tableId,+ filter: ["not-null", ["field", fieldId, null]],+ aggregation: [["count"]],+ },+ });+}++function createCardWithFieldNameRef({+ name,+ type,+ cardId,+ fieldName,+ baseType,+}: {+ name: string;+ type: CardType;+ cardId: CardId;+ fieldName: string;+ baseType: string;+}) {+ return H.createQuestion({+ name,+ type,+ query: {+ "source-table": `card__${cardId}`,+ filter: ["not-null", ["field", fieldName, { "base-type": baseType }]],+ aggregation: [["count"]],+ },+ });+}++function createNativeCard({+ name,+ type,+ query,+}: {+ name: string;+ type: CardType;+ query: string;+}) {+ return H.createNativeQuestion({+ name,+ type,+ native: {+ query,+ },+ });+}++function createSegmentWithFieldIdRef({+ name,+ tableId,+ fieldId,+}: {+ name: string;+ tableId: TableId;+ fieldId: FieldId;+}) {+ return H.createSegment({+ name,+ table_id: tableId,+ definition: {+ "source-table": tableId,+ filter: ["not-null", ["field", fieldId, null]],+ },+ });+}++function createTransformWithFieldIdRef({+ name,+ tableId,+ fieldId,+}: {+ name: string;+ tableId: TableId;+ fieldId: FieldId;+}) {+ return H.createTransform({+ name,+ source: {+ type: "query",+ query: {+ type: "query",+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ filter: ["not-null", ["field", fieldId, null]],+ },+ },+ },+ target: {+ type: "table",+ database: WRITABLE_DB_ID,+ name,+ schema: "public",+ },+ });+}++function createNativeTransform({+ name,+ query,+}: {+ name: string;+ query: string;+}) {+ return H.createTransform({+ name,+ source: {+ type: "query",+ query: {+ database: WRITABLE_DB_ID,+ type: "native",+ native: { query },+ },+ },+ target: {+ type: "table",+ database: WRITABLE_DB_ID,+ name,+ schema: "public",+ },+ });+}++function checkList({+ visibleEntities = [],+ hiddenEntities = [],+}: {+ visibleEntities?: string[];+ hiddenEntities?: string[];+}) {+ H.DataStudio.Tasks.list().within(() => {+ visibleEntities.forEach((name) => {+ cy.findByText(name).should("be.visible");+ });+ hiddenEntities.forEach((name) => {+ cy.findByText(name).should("not.exist");+ });+ });+}++function checkSidebar({+ entityName,+ errors = {},+}: {+ entityName: string;+ locationName?: string;+ creatorName?: string;+ errors?: Record<string, string[]>;+}) {+ H.DataStudio.Tasks.Sidebar.header()+ .findByText(entityName)+ .should("be.visible");++ Object.entries(errors).forEach(([label, errors]) => {+ H.DataStudio.Tasks.Sidebar.errorInfo(label).within(() => {+ errors.forEach((error) => {+ cy.findByText(error).should("be.visible");+ });+ });+ });+}++function openSidebarAndCheckErrors(+ errors: Record<string, Record<string, string[]>>,+) {+ Object.entries(errors).forEach(([entityName, errors]) => {+ H.DataStudio.Tasks.list().findByText(entityName).click();+ checkSidebar({+ entityName,+ errors,+ });+ });+}diff --git a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.tsnew file mode 100644index 00000000000..98f301e80cf--- /dev/null+++ b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts@@ -0,0 +1,934 @@+const { H } = cy;++import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";+import { FIRST_COLLECTION_ID } from "e2e/support/cypress_sample_instance_data";+import type {+ CardId,+ CollectionId,+ FieldId,+ NativeQuerySnippetId,+ SegmentId,+ TableId,+} from "metabase-types/api";+import { createMockParameter } from "metabase-types/api/mocks";++const { ORDERS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;++const MODEL_FOR_QUESTION_DATA_SOURCE = "Model for question data source";+const MODEL_FOR_MODEL_DATA_SOURCE = "Model for model data source";+const MODEL_FOR_METRIC_DATA_SOURCE = "Model for metric data source";+const MODEL_FOR_NATIVE_QUESTION_CARD_TAG = "Model for native question card tag";+const MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE =+ "Model for native question parameter source";+const MODEL_FOR_DASHBOARD_CARD = "Model for dashboard card";+const MODEL_FOR_DASHBOARD_PARAMETER_SOURCE =+ "Model for dashboard parameter source";+const SEGMENT_FOR_QUESTION_FILTER = "Segment for question filter";+const SEGMENT_FOR_MODEL_FILTER = "Segment for model filter";+const SEGMENT_FOR_SEGMENT_FILTER = "Segment for segment filter";+const SEGMENT_FOR_METRIC_FILTER = "Segment for metric filter";+const METRIC_FOR_QUESTION_AGGREGATION = "Metric for question aggregation";+const METRIC_FOR_MODEL_AGGREGATION = "Metric for model aggregation";+const METRIC_FOR_METRIC_AGGREGATION = "Metric for metric aggregation";+const METRIC_FOR_DASHBOARD_CARD = "Metric for dashboard card";+const SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG =+ "Snippet for native question card tag";+const SNIPPET_FOR_SNIPPET_TAG = "Snippet for snippet tag";++const MODEL_NAMES = [+ MODEL_FOR_QUESTION_DATA_SOURCE,+ MODEL_FOR_MODEL_DATA_SOURCE,+ MODEL_FOR_METRIC_DATA_SOURCE,+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,+ MODEL_FOR_DASHBOARD_CARD,+ MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,+];++const SEGMENT_NAMES = [+ SEGMENT_FOR_QUESTION_FILTER,+ SEGMENT_FOR_MODEL_FILTER,+ SEGMENT_FOR_SEGMENT_FILTER,+ SEGMENT_FOR_METRIC_FILTER,+];++const METRIC_NAMES = [+ METRIC_FOR_QUESTION_AGGREGATION,+ METRIC_FOR_MODEL_AGGREGATION,+ METRIC_FOR_METRIC_AGGREGATION,+ METRIC_FOR_DASHBOARD_CARD,+];++const SNIPPET_NAMES = [+ SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ SNIPPET_FOR_SNIPPET_TAG,+];++const ENTITY_NAMES = [+ ...MODEL_NAMES,+ ...SEGMENT_NAMES,+ ...METRIC_NAMES,+ ...SNIPPET_NAMES,+];++describe("scenarios > dependencies > unreferenced list", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("bleeding-edge");+ cy.viewport(1600, 1400);+ });++ describe("analysis", () => {+ it("should show unreferenced entities", () => {+ createEntities();+ H.DataStudio.Tasks.visitUnreferencedEntities();+ H.DataStudio.Tasks.list().within(() => {+ ENTITY_NAMES.forEach((name) => {+ cy.findByText(name).should("be.visible");+ });+ });+ });++ it("should not show referenced entities", () => {+ createEntities({ withReferences: true });+ H.DataStudio.Tasks.visitUnreferencedEntities();+ H.DataStudio.Tasks.list().within(() => {+ ENTITY_NAMES.forEach((name) => {+ cy.findByText(name).should("not.exist");+ });+ });+ });+ });++ describe("search", () => {+ it("should search for entities", () => {+ createEntities();+ H.DataStudio.Tasks.visitUnreferencedEntities();+ H.DataStudio.Tasks.searchInput().type(MODEL_FOR_QUESTION_DATA_SOURCE);+ checkList({+ visibleEntities: [MODEL_FOR_QUESTION_DATA_SOURCE],+ hiddenEntities: [MODEL_FOR_MODEL_DATA_SOURCE],+ });+ });++ it("should search for entities with type filters", () => {+ createEntities();+ H.DataStudio.Tasks.visitUnreferencedEntities();+ H.DataStudio.Tasks.searchInput().type("tag");+ checkList({+ visibleEntities: [+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ SNIPPET_FOR_SNIPPET_TAG,+ ],+ hiddenEntities: [MODEL_FOR_QUESTION_DATA_SOURCE],+ });++ H.DataStudio.Tasks.filterButton().click();+ H.popover().findByText("Model").click();+ checkList({+ visibleEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG],+ hiddenEntities: [SNIPPET_FOR_SNIPPET_TAG],+ });+ });+ });++ describe("filters", () => {+ it("should filter entities by type", () => {+ createEntities();+ H.DataStudio.Tasks.visitUnreferencedEntities();+ checkList({ visibleEntities: ENTITY_NAMES });++ H.DataStudio.Tasks.filterButton().click();+ H.popover().findByText("Model").click();+ checkList({ visibleEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG] });++ H.popover().findByText("Segment").click();+ checkList({+ visibleEntities: [+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ SEGMENT_FOR_QUESTION_FILTER,+ ],+ });++ H.popover().findByText("Metric").click();+ checkList({+ visibleEntities: [+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ SEGMENT_FOR_QUESTION_FILTER,+ METRIC_FOR_QUESTION_AGGREGATION,+ ],+ });++ H.popover().findByText("Snippet").click();+ checkList({+ visibleEntities: [+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ SEGMENT_FOR_QUESTION_FILTER,+ METRIC_FOR_QUESTION_AGGREGATION,+ SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ ],+ });+ });+ });++ describe("sidebar", () => {+ it("should show the sidebar for supported entities", () => {+ createEntities();+ H.DataStudio.Tasks.visitUnreferencedEntities();++ H.DataStudio.Tasks.list()+ .findByText(MODEL_FOR_QUESTION_DATA_SOURCE)+ .click();+ checkSidebar({+ entityName: MODEL_FOR_QUESTION_DATA_SOURCE,+ locationName: "Our analytics",+ creatorName: "Bobby Tables",+ });++ H.DataStudio.Tasks.list().findByText(MODEL_FOR_MODEL_DATA_SOURCE).click();+ checkSidebar({+ entityName: MODEL_FOR_MODEL_DATA_SOURCE,+ locationName: "First collection",+ creatorName: "Bobby Tables",+ });++ H.DataStudio.Tasks.list().findByText(SEGMENT_FOR_QUESTION_FILTER).click();+ checkSidebar({+ entityName: SEGMENT_FOR_QUESTION_FILTER,+ locationName: "Orders",+ creatorName: "Bobby Tables",+ });++ H.DataStudio.Tasks.list()+ .findByText(METRIC_FOR_QUESTION_AGGREGATION)+ .click();+ checkSidebar({+ entityName: METRIC_FOR_QUESTION_AGGREGATION,+ locationName: "Our analytics",+ creatorName: "Bobby Tables",+ });++ H.DataStudio.Tasks.list()+ .findByText(METRIC_FOR_MODEL_AGGREGATION)+ .click();+ checkSidebar({+ entityName: METRIC_FOR_MODEL_AGGREGATION,+ locationName: "First collection",+ creatorName: "Bobby Tables",+ });++ H.DataStudio.Tasks.list()+ .findByText(SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG)+ .click();+ checkSidebar({+ entityName: SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ locationName: "SQL snippets",+ creatorName: "Bobby Tables",+ });+ });+ });+});++function createEntities({+ withReferences = false,+}: { withReferences?: boolean } = {}) {+ createModelContent({ withReferences });+ createSegmentContent({ withReferences });+ createMetricContent({ withReferences });+ createSnippetContent({ withReferences });+}++function createModelContent({+ withReferences = false,+}: {+ withReferences?: boolean;+}) {+ createModelWithTableDataSource({+ name: MODEL_FOR_QUESTION_DATA_SOURCE,+ tableId: ORDERS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createQuestionWithModelDataSource({+ name: `${MODEL_FOR_QUESTION_DATA_SOURCE} -> Question`,+ modelId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_MODEL_DATA_SOURCE,+ tableId: ORDERS_ID,+ collectionId: FIRST_COLLECTION_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createModelWithModelDataSource({+ name: `${MODEL_FOR_MODEL_DATA_SOURCE} -> Model`,+ modelId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_METRIC_DATA_SOURCE,+ tableId: ORDERS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createMetricWithModelDataSource({+ name: `${MODEL_FOR_METRIC_DATA_SOURCE} -> Metric`,+ modelId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ tableId: ORDERS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createNativeQuestionWithCardTag({+ name: `${MODEL_FOR_NATIVE_QUESTION_CARD_TAG} -> Question`,+ cardId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,+ tableId: PRODUCTS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createNativeQuestionWithParameterWithCardSource({+ name: `${MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE} -> Question`,+ tableName: "PRODUCTS",+ tableFieldId: PRODUCTS.CATEGORY,+ cardId: model.id,+ cardFieldName: "CATEGORY",+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_DASHBOARD_CARD,+ tableId: ORDERS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createDashboardWithCard({+ name: `${MODEL_FOR_DASHBOARD_CARD} -> Dashboard Card`,+ cardId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,+ tableId: PRODUCTS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createDashboardWithParameterWithCardSource({+ name: `${MODEL_FOR_DASHBOARD_PARAMETER_SOURCE} -> Dashboard`,+ cardId: model.id,+ cardFieldName: "CATEGORY",+ });+ }+ });+}++function createSegmentContent({+ withReferences = false,+}: {+ withReferences?: boolean;+}) {+ createSegmentWithTableDataSource({+ name: SEGMENT_FOR_QUESTION_FILTER,+ tableId: ORDERS_ID,+ }).then(({ body: segment }) => {+ if (withReferences) {+ createQuestionWithSegmentClause({+ name: `${SEGMENT_FOR_QUESTION_FILTER} -> Question`,+ tableId: ORDERS_ID,+ segmentId: segment.id,+ });+ }+ });++ createSegmentWithTableDataSource({+ name: SEGMENT_FOR_MODEL_FILTER,+ tableId: ORDERS_ID,+ }).then(({ body: segment }) => {+ if (withReferences) {+ createModelWithSegmentClause({+ name: `${SEGMENT_FOR_MODEL_FILTER} -> Model`,+ tableId: ORDERS_ID,+ segmentId: segment.id,+ });+ }+ });++ createSegmentWithTableDataSource({+ name: SEGMENT_FOR_SEGMENT_FILTER,+ tableId: ORDERS_ID,+ }).then(({ body: segment }) => {+ if (withReferences) {+ createSegmentWithSegmentClause({+ name: `${SEGMENT_FOR_SEGMENT_FILTER} -> Segment`,+ tableId: ORDERS_ID,+ segmentId: segment.id,+ });+ }+ });++ createSegmentWithTableDataSource({+ name: SEGMENT_FOR_METRIC_FILTER,+ tableId: ORDERS_ID,+ }).then(({ body: segment }) => {+ if (withReferences) {+ createMetricWithSegmentClause({+ name: `${SEGMENT_FOR_METRIC_FILTER} -> Metric`,+ tableId: ORDERS_ID,+ segmentId: segment.id,+ });+ }+ });+}++function createMetricContent({+ withReferences = false,+}: {+ withReferences?: boolean;+}) {+ createMetricWithTableDataSource({+ name: METRIC_FOR_QUESTION_AGGREGATION,+ tableId: ORDERS_ID,+ }).then(({ body: metric }) => {+ if (withReferences) {+ createQuestionWithMetricClause({+ name: `${METRIC_FOR_QUESTION_AGGREGATION} -> Question`,+ tableId: ORDERS_ID,+ metricId: metric.id,+ });+ }+ });++ createMetricWithTableDataSource({+ name: METRIC_FOR_MODEL_AGGREGATION,+ tableId: ORDERS_ID,+ collectionId: FIRST_COLLECTION_ID,+ }).then(({ body: metric }) => {+ if (withReferences) {+ createModelWithMetricClause({+ name: `${METRIC_FOR_MODEL_AGGREGATION} -> Model`,+ tableId: ORDERS_ID,+ metricId: metric.id,+ });+ }+ });++ createMetricWithTableDataSource({+ name: METRIC_FOR_METRIC_AGGREGATION,+ tableId: ORDERS_ID,+ }).then(({ body: metric }) => {+ if (withReferences) {+ createMetricWithMetricClause({+ name: `${METRIC_FOR_METRIC_AGGREGATION} -> Metric`,+ tableId: ORDERS_ID,+ metricId: metric.id,+ });+ }+ });++ createMetricWithTableDataSource({+ name: METRIC_FOR_DASHBOARD_CARD,+ tableId: ORDERS_ID,+ }).then(({ body: metric }) => {+ if (withReferences) {+ createDashboardWithCard({+ name: `${METRIC_FOR_DASHBOARD_CARD} -> Dashboard Card`,+ cardId: metric.id,+ });+ }+ });+}++function createSnippetContent({+ withReferences = false,+}: {+ withReferences?: boolean;+}) {+ createSnippetWithBasicFilter({+ name: SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ }).then(({ body: snippet }) => {+ if (withReferences) {+ createNativeQuestionWithSnippetTag({+ name: `${SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG} -> Question`,+ tableName: "ORDERS",+ snippetId: snippet.id,+ snippetName: snippet.name,+ });+ }+ });++ createSnippetWithBasicFilter({ name: SNIPPET_FOR_SNIPPET_TAG }).then(+ ({ body: snippet }) => {+ if (withReferences) {+ createSnippetWithSnippetTag({+ name: `${SNIPPET_FOR_SNIPPET_TAG} -> Snippet`,+ snippetName: snippet.name,+ });+ }+ },+ );+}++function createQuestionWithModelDataSource({+ name,+ modelId,+}: {+ name: string;+ modelId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "question",+ query: {+ "source-table": `card__${modelId}`,+ },+ });+}++function createQuestionWithSegmentClause({+ name,+ tableId,+ segmentId,+}: {+ name: string;+ tableId: TableId;+ segmentId: SegmentId;+}) {+ return H.createQuestion({+ name,+ type: "question",+ query: {+ "source-table": tableId,+ filter: ["segment", segmentId],+ },+ });+}++function createQuestionWithMetricClause({+ name,+ tableId,+ metricId,+}: {+ name: string;+ tableId: TableId;+ metricId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "question",+ query: {+ "source-table": tableId,+ aggregation: [["metric", metricId]],+ },+ });+}++function createNativeQuestionWithCardTag({+ name,+ cardId,+}: {+ name: string;+ cardId: CardId;+}) {+ const tagName = `#${cardId}`;++ return H.createNativeQuestion({+ name,+ type: "question",+ native: {+ query: `select * from {{${tagName}}}`,+ "template-tags": {+ [tagName]: {+ id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",+ type: "card",+ name: tagName,+ "display-name": tagName,+ "card-id": cardId,+ },+ },+ },+ });+}++function createNativeQuestionWithParameterWithCardSource({+ name,+ tableName,+ tableFieldId,+ cardId,+ cardFieldName,+}: {+ name: string;+ tableName: string;+ tableFieldId: FieldId;+ cardId: CardId;+ cardFieldName: string;+}) {+ return H.createNativeQuestion({+ name,+ native: {+ query: `select * from ${tableName} where {{filter}}`,+ "template-tags": {+ filter: {+ id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",+ type: "dimension",+ name: "filter",+ "display-name": "Filter",+ dimension: ["field", tableFieldId, null],+ "widget-type": "string/=",+ },+ },+ },+ parameters: [+ createMockParameter({+ id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",+ name: "Filter",+ slug: "filter",+ type: "string/=",+ target: ["dimension", ["template-tag", "filter"]],+ values_source_type: "card",+ values_source_config: {+ card_id: cardId,+ value_field: ["field", cardFieldName, { "base-type": "type/Text" }],+ },+ }),+ ],+ });+}++function createNativeQuestionWithSnippetTag({+ name,+ tableName,+ snippetId,+ snippetName,+}: {+ name: string;+ tableName: string;+ snippetId: NativeQuerySnippetId;+ snippetName: string;+}) {+ const tagName = `snippet: ${snippetName}`;++ return H.createNativeQuestion({+ name,+ type: "question",+ native: {+ query: `select * from ${tableName} where {{${tagName}}}`,+ "template-tags": {+ [tagName]: {+ id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",+ type: "snippet",+ name: tagName,+ "display-name": snippetName,+ "snippet-id": snippetId,+ "snippet-name": snippetName,+ },+ },+ },+ });+}++function createModelWithTableDataSource({+ name,+ tableId,+ collectionId,+}: {+ name: string;+ tableId: TableId;+ collectionId?: CollectionId;+}) {+ return H.createQuestion({+ name,+ type: "model",+ query: {+ "source-table": tableId,+ },+ collection_id: collectionId,+ });+}++function createModelWithModelDataSource({+ name,+ modelId,+}: {+ name: string;+ modelId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "model",+ query: {+ "source-table": `card__${modelId}`,+ },+ });+}++function createModelWithSegmentClause({+ name,+ tableId,+ segmentId,+}: {+ name: string;+ tableId: TableId;+ segmentId: SegmentId;+}) {+ return H.createQuestion({+ name,+ type: "model",+ query: {+ "source-table": tableId,+ filter: ["segment", segmentId],+ },+ });+}++function createModelWithMetricClause({+ name,+ tableId,+ metricId,+}: {+ name: string;+ tableId: TableId;+ metricId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "model",+ query: {+ "source-table": tableId,+ aggregation: [["metric", metricId]],+ },+ });+}++function createSegmentWithTableDataSource({+ name,+ tableId,+}: {+ name: string;+ tableId: TableId;+}) {+ return H.createSegment({+ name,+ table_id: tableId,+ definition: {+ "source-table": tableId,+ filter: [["=", "A", "A"]],+ },+ });+}++function createSegmentWithSegmentClause({+ name,+ tableId,+ segmentId,+}: {+ name: string;+ tableId: TableId;+ segmentId: SegmentId;+}) {+ return H.createSegment({+ name,+ table_id: tableId,+ definition: {+ "source-table": tableId,+ filter: ["segment", segmentId],+ },+ });+}++function createMetricWithTableDataSource({+ name,+ tableId,+ collectionId,+}: {+ name: string;+ tableId: TableId;+ collectionId?: CollectionId;+}) {+ return H.createQuestion({+ name,+ type: "metric",+ query: {+ "source-table": tableId,+ aggregation: [["count"]],+ },+ collection_id: collectionId,+ });+}++function createMetricWithModelDataSource({+ name,+ modelId,+}: {+ name: string;+ modelId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "metric",+ query: {+ "source-table": `card__${modelId}`,+ aggregation: [["count"]],+ },+ });+}++function createMetricWithSegmentClause({+ name,+ tableId,+ segmentId,+}: {+ name: string;+ tableId: TableId;+ segmentId: SegmentId;+}) {+ return H.createQuestion({+ name,+ type: "metric",+ query: {+ "source-table": tableId,+ filter: ["segment", segmentId],+ aggregation: [["count"]],+ },+ });+}++function createMetricWithMetricClause({+ name,+ tableId,+ metricId,+}: {+ name: string;+ tableId: TableId;+ metricId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "metric",+ query: {+ "source-table": tableId,+ aggregation: [["metric", metricId]],+ },+ });+}++function createSnippetWithBasicFilter({ name }: { name: string }) {+ return H.createSnippet({+ name,+ content: "1 = 1",+ });+}++function createSnippetWithSnippetTag({+ name,+ snippetName,+}: {+ name: string;+ snippetName: string;+}) {+ return H.createSnippet({+ name,+ content: `{{snippet: ${snippetName}}}`,+ });+}++function createDashboardWithCard({+ name,+ cardId,+}: {+ name: string;+ cardId: CardId;+}) {+ return H.createDashboard({ name }).then(({ body: dashboard }) => {+ H.updateDashboardCards({+ dashboard_id: dashboard.id,+ cards: [+ {+ card_id: cardId,+ },+ ],+ });+ });+}++function createDashboardWithParameterWithCardSource({+ name,+ cardId,+ cardFieldName,+}: {+ name: string;+ cardId: CardId;+ cardFieldName: string;+}) {+ return H.createDashboard({+ name,+ parameters: [+ createMockParameter({+ id: "10422a0f",+ name: "Filter",+ slug: "filter",+ type: "string/=",+ values_source_type: "card",+ values_source_config: {+ card_id: cardId,+ value_field: ["field", cardFieldName, { "base-type": "type/Text" }],+ },+ }),+ ],+ });+}++function checkList({+ visibleEntities = [],+ hiddenEntities = [],+}: {+ visibleEntities?: string[];+ hiddenEntities?: string[];+}) {+ H.DataStudio.Tasks.list().within(() => {+ visibleEntities.forEach((name) => {+ cy.findByText(name).should("be.visible");+ });+ hiddenEntities.forEach((name) => {+ cy.findByText(name).should("not.exist");+ });+ });+}++function checkSidebar({+ entityName,+ locationName,+ creatorName,+}: {+ entityName: string;+ locationName?: string;+ creatorName?: string;+}) {+ H.DataStudio.Tasks.sidebar().within(() => {+ H.DataStudio.Tasks.Sidebar.header()+ .findByText(entityName)+ .should("be.visible");+ if (locationName) {+ H.DataStudio.Tasks.Sidebar.locationInfo()+ .findByText(locationName)+ .should("be.visible");+ }+ if (creatorName) {+ H.DataStudio.Tasks.Sidebar.creationInfo().should(+ "contain.text",+ creatorName,+ );+ }+ });+}diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/analysis.clj b/enterprise/backend/src/metabase_enterprise/dependencies/analysis.cljnew file mode 100644index 00000000000..23da2103fae--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/dependencies/analysis.clj@@ -0,0 +1,78 @@+(ns metabase-enterprise.dependencies.analysis+ (:require+ [metabase-enterprise.dependencies.native-validation :as deps.native]+ [metabase.lib.core :as lib]+ [metabase.lib.metadata :as lib.metadata]+ [metabase.lib.schema :as lib.schema]+ [metabase.lib.schema.id :as lib.schema.id]+ [metabase.lib.schema.metadata :as lib.schema.metadata]+ [metabase.lib.schema.validate :as lib.schema.validate]+ [metabase.util.malli :as mu]))++(mu/defn returned-columns+ "Get the returned columns of a `query`"+ [driver :- :keyword+ query :- ::lib.schema/query]+ (if (lib/any-native-stage? query)+ (deps.native/native-result-metadata driver query)+ (lib/returned-columns query)))++;; Analyzing an entity in memory ================================================================+(mu/defn- check-query :- [:set [:ref ::lib.schema.validate/error]]+ "Find any bad refs in a `query`."+ [driver :- :keyword+ query :- ::lib.schema/query]+ (if (lib/any-native-stage? query)+ (deps.native/validate-native-query driver query)+ (lib/find-bad-refs query)))++(defmulti check-entity+ "Given a metadata provider, an entity type and an entity id, find any bad refs in that entity."+ {:arglists '([metadata-provider entity-type entity-id])}+ (fn [_metadata-provider entity-type _entity-id]+ entity-type))++(defmethod check-entity :default+ [_metadata-provider _entity-type _entity-id]+ nil)++(mu/defmethod check-entity :card :- [:set [:ref ::lib.schema.validate/error]]+ "Given a `MetadataProvider` and a card ID, analyses the card's query to find any bad refs or other issues.+ Returns any findings, and `nil` for a clean query."+ [metadata-provider :- ::lib.schema.metadata/metadata-provider+ _entity-type+ card-id :- ::lib.schema.id/card]+ (let [query (lib/query metadata-provider (:dataset-query (lib.metadata/card metadata-provider card-id)))+ driver (:engine (lib.metadata/database query))]+ (check-query driver query)))++(mu/defmethod check-entity :transform :- [:set [:ref ::lib.schema.validate/error]]+ "Given a `MetadataProvider` and a transform ID, analyses the transform's query to find any bad refs or other issues.++ Returns any findings, and `nil` for a clean transform."+ [metadata-provider :- ::lib.schema.metadata/metadata-provider+ _entity-type+ transform-id :- ::lib.schema.id/transform]+ (let [{{query :query} :source+ :as _transform} (lib.metadata/transform metadata-provider transform-id)+ driver (:engine (lib.metadata/database metadata-provider))+ query (lib/query metadata-provider query)+ output-fields (returned-columns driver query)+ duplicated-fields (->> output-fields+ (group-by :name)+ vals+ (keep #(when (> (count %) 1)+ (lib/duplicate-column-error (-> % first :name))))+ seq)]+ (cond-> (check-query driver query)+ duplicated-fields (into duplicated-fields))))++(mu/defmethod check-entity :segment :- [:set [:ref ::lib.schema.validate/error]]+ [metadata-provider :- ::lib.schema.metadata/metadata-provider+ _entity-type+ segment-id :- ::lib.schema.id/segment]+ (let [query (->> (lib.metadata/segment metadata-provider segment-id)+ :definition+ (lib/query metadata-provider))+ driver (:engine (lib.metadata/database query))]+ (check-query driver query)))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.cljindex fa25b80b40a..4317177d7bf 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj@@ -2,26 +2,35 @@(:require[medley.core :as m][metabase-enterprise.dependencies.core :as dependencies]+ [metabase-enterprise.dependencies.dependency-types :as deps.dependency-types][metabase-enterprise.dependencies.models.dependency :as dependency]+ [metabase-enterprise.transforms.schema :as transforms.schema][metabase.analyze.core :as analyze][metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]][metabase.api.util.handlers :as handlers]+ [metabase.app-db.core :as mdb][metabase.collections.models.collection :as collection][metabase.collections.models.collection.root :as collection.root]+ [metabase.documents.schema :as documents.schema][metabase.graph.core :as graph][metabase.lib-be.core :as lib-be][metabase.lib.metadata :as lib.metadata]+ [metabase.lib.schema.id :as lib.schema.id]+ [metabase.lib.schema.metadata :as lib.schema.metadata]+ [metabase.lib.schema.validate :as lib.schema.validate][metabase.models.interface :as mi][metabase.native-query-snippets.core :as native-query-snippets][metabase.permissions.core :as perms][metabase.queries.schema :as queries.schema][metabase.revisions.core :as revisions][metabase.util.i18n :refer [tru]]+ [metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]- [toucan2.core :as t2]))+ [toucan2.core :as t2]+ [toucan2.util :as u]))(mr/def ::card-body[:merge@@ -30,7 +39,13 @@[:map[:result_metadata {:optional true} [:maybe analyze/ResultsMetadata]]]])-(defn- broken-cards-response+(mr/def ::broken-cards-response+ [:map+ [:success :boolean]+ [:bad_cards {:optional true} [:sequential ::queries.schema/card]]+ [:bad_transforms {:optional true} [:sequential ::transforms.schema/transform]]])++(mu/defn- broken-cards-response :- ::broken-cards-response[{:keys [card transform]}](let [broken-card-ids (keys card)broken-cards (when (seq broken-card-ids)@@ -52,12 +67,8 @@;; TODO (Cam 10/28/25) -- fix this endpoint route to use kebab-case for consistency with the rest of our REST API;;-;; 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-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-route-uses-kebab-case- :metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :post "/check_card"+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-route-uses-kebab-case]}+(api.macros/defendpoint :post "/check_card" :- ::broken-cards-response"Check a proposed edit to a card, and return the card IDs for those cards this edit will break."[_route-params_query-params@@ -81,8 +92,8 @@(mr/def ::transform-body[:map- [:id {:optional false} ms/PositiveInt]- [:name {:optional true} :string]+ [:id {:optional false} ::lib.schema.id/transform]+ [:name {:optional true} :string];; TODO (Cam 10/8/25) -- no idea what the correct schema for these is supposed to be -- it was just `map` before --;; this is my attempt to guess it[:source {:optional true} [:maybe [:map@@ -92,12 +103,8 @@;; TODO (Cam 10/28/25) -- fix this endpoint route to use kebab-case for consistency with the rest of our REST API;;-;; 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-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-route-uses-kebab-case- :metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :post "/check_transform"+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-route-uses-kebab-case]}+(api.macros/defendpoint :post "/check_transform" :- ::broken-cards-response"Check a proposed edit to a transform, and return the card, transform, etc. IDs for things that will break."[_route-params_query-params@@ -118,19 +125,15 @@;; TODO (Cam 10/28/25) -- fix this endpoint route to use kebab-case for consistency with the rest of our REST API;;-;; 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-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-route-uses-kebab-case- :metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :post "/check_snippet"+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-route-uses-kebab-case]}+(api.macros/defendpoint :post "/check_snippet" :- ::broken-cards-response"Check a proposed edit to a native snippet, and return the cards, etc. which will be broken."[_route-params_query-params{:keys [id content], snippet-name :name}:- [:map- [:id {:optional false} ms/PositiveInt]- [:name {:optional true} native-query-snippets/NativeQuerySnippetName]+ [:id {:optional false} ::lib.schema.id/snippet]+ [:name {:optional true} native-query-snippets/NativeQuerySnippetName][:content {:optional true} :string]]](api/read-check :model/NativeQuerySnippet id)(let [original (t2/select-one :model/NativeQuerySnippet id)@@ -152,13 +155,13 @@:card [:name :type :display :database_id :view_count:created_at :creator :creator_id :description:result_metadata :last-edit-info- :collection :collection_id :dashboard :dashboard_id- :document :document_id]- :snippet [:name :description]- :transform [:name :description :creator :table]+ :collection :collection_id :dashboard :dashboard_id :document :document_id]+ :snippet [:name :description :created_at :creator :creator_id :collection :collection_id]+ :transform [:name :description :creator :table :last_run]:dashboard [:name :description :view_count:created_at :creator :creator_id :last-edit-info- :collection :collection_id]+ :collection :collection_id+ :moderation_reviews]:document [:name :description :view_count:created_at :creator:collection :collection_id]@@ -173,23 +176,112 @@:model/Document (select-keys entity [:id :name])entity))-(defn- entity-value [entity-type {:keys [id] :as entity} usages]- {:id id- :type entity-type- :data (->> (select-keys entity (entity-keys entity-type))- (m/map-vals format-subentity))- :dependents_count (usages [entity-type id])})--(def ^:private entity-model- {:table :model/Table- :card :model/Card- :snippet :model/NativeQuerySnippet- :transform :model/Transform- :dashboard :model/Dashboard- :document :model/Document- :sandbox :model/Sandbox- :segment :model/Segment- :measure :model/Measure})+(mr/def ::entity-id pos-int?)++(mr/def ::usages+ [:map-of+ [:enum :table :snippet :transform :dashboard :document :sandbox :segment :question :model :metric :measure]+ ::entity-id])++(mr/def ::base-entity+ [:map+ [:id pos-int?]+ [:type :keyword]+ [:data [:map]]+ [:dependents_count [:maybe [:ref ::usages]]]+ [:errors {:optional true} [:set [:ref ::lib.schema.validate/error]]]])++(defn- fields-for [entity-key]+ ;; these specs should really use something like+ #_[:data [:select-keys [:ref :blah/table] (entity-keys :table)]]+ ;; but :select-keys seems to mess up open-api spec generation+ (into [:map]+ (map (fn [key] [key {:optional true} :any]))+ (entity-keys entity-key)))++(mr/def ::table-entity+ [:merge ::base-entity+ [:map+ [:id ::lib.schema.id/table]+ [:type [:= :table]]+ [:data (fields-for :table)]]])++(mr/def ::card-entity+ [:merge ::base-entity+ [:map+ [:id ::lib.schema.id/card]+ [:type [:= :card]]+ [:data (fields-for :card)]]])++(mr/def ::snippet-entity+ [:merge ::base-entity+ [:map+ [:id ::lib.schema.id/snippet]+ [:type [:= :snippet]]+ [:data (fields-for :snippet)]]])++(mr/def ::transform-entity+ [:merge ::base-entity+ [:map+ [:id ::lib.schema.id/transform]+ [:type [:= :transform]]+ [:data (fields-for :transform)]]])++(mr/def ::dashboard-entity+ [:merge ::base-entity+ [:map+ [:id ::lib.schema.id/dashboard]+ [:type [:= :dashboard]]+ [:data (fields-for :dashboard)]]])++(mr/def ::document-entity+ [:merge ::base-entity+ [:map+ [:id ::documents.schema/document.id]+ [:type [:= :document]]+ [:data (fields-for :document)]]])++(mr/def ::sandbox-entity+ [:merge ::base-entity+ [:map+ [:id ::lib.schema.id/sandbox]+ [:type [:= :sandbox]]+ [:data (fields-for :sandbox)]]])++(mr/def ::segment-entity+ [:merge ::base-entity+ [:map+ [:id ::lib.schema.id/segment]+ [:type [:= :segment]]+ [:data (fields-for :card)]]])++(mr/def ::measure-entity+ [:merge ::base-entity+ [:map+ [:id ::lib.schema.id/measure]+ [:type [:= :measure]]+ [:data (fields-for :measure)]]])++(mr/def ::entity+ [:multi {:dispatch :type}+ [:table [:ref ::table-entity]]+ [:card [:ref ::card-entity]]+ [:snippet [:ref ::snippet-entity]]+ [:transform [:ref ::transform-entity]]+ [:dashboard [:ref ::dashboard-entity]]+ [:document [:ref ::document-entity]]+ [:sandbox [:ref ::sandbox-entity]]+ [:segment [:ref ::segment-entity]]+ [:measure [:ref ::measure-entity]]])++(mu/defn- entity-value :- ::entity+ [entity-type {:keys [id] :as entity} usages errors]+ (cond-> {:id id+ :type entity-type+ :data (->> (select-keys entity (entity-keys entity-type))+ (m/map-vals format-subentity))+ :dependents_count (usages [entity-type id])}+ errors (assoc :errors (get errors [entity-type id]))));; IMPORTANT: This map defines which fields to select when fetching entities for the dependency graph.;; These field lists MUST be kept in sync with the frontend type definitions in:@@ -210,7 +302,7 @@:transform [:id :name :description :creator_id;; :source has to be selected otherwise the BE won't know what DB it belongs to:source]- :snippet [:id :name :description]+ :snippet [:id :name :description :created_at :creator_id :collection_id]:sandbox [:id :table_id]:segment [:id :name :description :created_at :creator_id :table_id]:measure [:id :name :description :created_at :creator_id :table_id]})@@ -266,7 +358,7 @@(keyword (name table-name) "collection_id"){:include-archived-items include-archived-items}{:current-user-id api/*current-user-id*- :is-superuser? api/*is-superuser?*})+ :is-superuser? api/*is-superuser?*});; Filter by entity archived status(case include-archived-items:exclude [:= archived-column false]@@ -290,9 +382,9 @@{:perms/view-data :unrestricted:perms/create-queries :query-builder})](case include-archived-items- :exclude [:and- [:= active-column true]- [:= visibility-type-column nil]]+ :exclude [:and+ [:= active-column true]+ [:= visibility-type-column nil]](:only :all) nil)]}]]);; Segment/Measure with table permissions and archived filtering@@ -323,7 +415,7 @@:exclude [:= archived-column false]:only [:= archived-column true]:all nil)]}]])))))- entity-model)))+ deps.dependency-types/dependency-type->model)))(defn- readable-graph-dependencies([]@@ -341,7 +433,7 @@(fn [entity-type-field entity-id-field](visible-entities-filter-clause entity-type-field entity-id-field opts)))))-(defn- calc-usages+(defn- node-usages"Calculates the count of direct dependents for all nodes in `nodes`, based on `graph`. "[graph nodes](let [children-map (graph/children-of graph nodes)@@ -362,35 +454,67 @@(apply merge-with +)))children-map)))-(defn- expanded-nodes [downstream-graph nodes]- (let [usages (calc-usages downstream-graph nodes)+(defn- node-errors [nodes-by-type]+ (-> (into {}+ (mapcat (fn [[type ids]]+ (->> (t2/select [:model/AnalysisFinding :analyzed_entity_id :finding_details]+ :analyzed_entity_type type+ :analyzed_entity_id [:in ids])+ (map (fn [{:keys [analyzed_entity_id finding_details]}]+ [[type analyzed_entity_id] finding_details])))))+ nodes-by-type)+ not-empty))++(defn- hydrate-entities [entity-type entities]+ (case entity-type+ :card (-> entities+ (t2/hydrate :creator :dashboard :document [:collection :is_personal])+ (->> (map collection.root/hydrate-root-collection))+ (revisions/with-last-edit-info :card))+ :table (t2/hydrate entities :fields :db)+ :transform (t2/hydrate entities :creator :table-with-db-and-fields :last_run)+ :dashboard (-> entities+ (t2/hydrate :creator [:collection :is_personal])+ (->> (map collection.root/hydrate-root-collection))+ (revisions/with-last-edit-info :dashboard))+ :document (-> entities+ (t2/hydrate :creator [:collection :is_personal])+ (->> (map collection.root/hydrate-root-collection)))+ :sandbox (t2/hydrate entities [:table :db :fields])+ :snippet (-> entities+ (t2/hydrate :creator)+ (->> (map #(collection.root/hydrate-root-collection % (collection.root/hydrated-root-collection :snippets)))))+ (:segment :measure) (t2/hydrate entities :creator [:table :db])))++(defn- expanded-nodes [downstream-graph nodes {:keys [include-errors?]}]+ (let [usages (node-usages downstream-graph nodes)nodes-by-type (->> (group-by first nodes)- (m/map-vals #(map second %)))]- (mapcat (fn [[entity-type entity-ids]]- (let [model (entity-model entity-type)- fields (entity-select-fields entity-type)]- (->> (cond-> (t2/select (into [model] fields) :id [:in entity-ids])- (= entity-type :card) (-> (t2/hydrate :creator :dashboard :document [:collection :is_personal])- (->> (map collection.root/hydrate-root-collection))- (revisions/with-last-edit-info :card))- (= entity-type :table) (t2/hydrate :fields :db)- (= entity-type :transform) (t2/hydrate :creator :table-with-db-and-fields)- (= entity-type :dashboard) (-> (t2/hydrate :creator [:collection :is_personal])- (->> (map collection.root/hydrate-root-collection))- (revisions/with-last-edit-info :dashboard))- (= entity-type :document) (-> (t2/hydrate :creator [:collection :is_personal])- (->> (map collection.root/hydrate-root-collection)))- (= entity-type :sandbox) (t2/hydrate [:table :db :fields])- (= entity-type :segment) (t2/hydrate :creator [:table :db])- (= entity-type :measure) (t2/hydrate :creator [:table :db]))- (mapv #(entity-value entity-type % usages)))))- nodes-by-type)))--;; 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-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/graph"+ (m/map-vals #(map second %)))+ errors (when include-errors?+ (node-errors nodes-by-type))+ nodes-by-type-and-id+ (into {}+ (mapcat (fn [[entity-type entity-ids]]+ (let [model (deps.dependency-types/dependency-type->model entity-type)+ fields (entity-select-fields entity-type)]+ (->> (t2/select (into [model] fields) :id [:in entity-ids])+ (hydrate-entities entity-type)+ (map (fn [entity]+ [[entity-type (:id entity)]+ (entity-value entity-type entity usages errors)]))))))+ nodes-by-type)]+ (keep nodes-by-type-and-id nodes)))++(mr/def ::graph-response+ [:map+ [:nodes [:sequential ::entity]]+ [:edges [:sequential [:map+ [:from_entity_type ::deps.dependency-types/dependency-types]+ [:from_entity_id ::entity-id]+ [:to_entity_type ::deps.dependency-types/dependency-types]+ [:to_entity_id ::entity-id]]]]])++(api.macros/defendpoint :get "/graph" :- ::graph-response"This endpoint takes an :id and a supported entity :type, and returns a graph of all its upstream dependencies.The graph is represented by a list of :nodes and a list of :edges. Each node has an :id, :type, :data (whichdepends on the node type), and a map of :dependent_counts per entity type. Each edge is a :model/Dependency.@@ -401,9 +525,9 @@[_route-params{:keys [id type archived]} :- [:map[:id {:optional true} ms/PositiveInt]- [:type {:optional true} (ms/enum-decode-keyword (vec (keys entity-model)))]+ [:type {:optional true} ::deps.dependency-types/dependency-types][:archived {:optional true} :boolean]]]- (api/read-check (entity-model type) id)+ (api/read-check (deps.dependency-types/dependency-type->model type) id)(lib-be/with-metadata-provider-cache(let [graph-opts {:include-archived-items (if archived :all :exclude)}starting-nodes [[type id]]@@ -413,24 +537,19 @@downstream-graph (graph/cached-graph (readable-graph-dependents graph-opts))nodes (into (set starting-nodes)(graph/transitive upstream-graph starting-nodes))- edges (graph/calc-edges-between downstream-graph nodes)]- {:nodes (expanded-nodes downstream-graph nodes)+ edges (graph/edges-between downstream-graph nodes)]+ {:nodes (expanded-nodes downstream-graph nodes {:include-errors? false}):edges edges})))(def ^:private dependents-args[:map- [:id ms/PositiveInt]- [:type (ms/enum-decode-keyword (vec (keys entity-model)))]- [:dependent_type (ms/enum-decode-keyword (vec (keys entity-model)))]- [:dependent_card_type {:optional true} (ms/enum-decode-keyword- [:question :model :metric])]- [:archived {:optional true} :boolean]])--;; 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-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/graph/dependents"+ [:id ms/PositiveInt]+ [:type ::deps.dependency-types/dependency-types]+ [:dependent_type ::deps.dependency-types/dependency-types]+ [:dependent_card_type {:optional true} (ms/enum-decode-keyword lib.schema.metadata/card-types)]+ [:archived {:optional true} :boolean]])++(api.macros/defendpoint :get "/graph/dependents" :- [:sequential ::entity]"This endpoint takes an :id, :type, :dependent_type, and an optional :dependent_card_type, and returns a list ofall that entity's dependents with :dependent_type. If the :dependent_type is :card, the dependents are furtherfiltered by :dependent_card_type.@@ -440,17 +559,140 @@- true: Includes entities in archived collections"[_route-params{:keys [id type dependent_type dependent_card_type archived]} :- dependents-args]- (api/read-check (entity-model type) id)+ (api/read-check (deps.dependency-types/dependency-type->model type) id)(lib-be/with-metadata-provider-cache(let [graph-opts {:include-archived-items (if archived :all :exclude)}downstream-graph (graph/cached-graph (readable-graph-dependents graph-opts))nodes (-> (graph/children-of downstream-graph [[type id]])(get [type id]))]- (->> (expanded-nodes downstream-graph nodes)+ (->> (expanded-nodes downstream-graph nodes {:include-errors? false})(filter #(and (= (:type %) dependent_type)(or (not= dependent_type :card)(= (-> % :data :type) dependent_card_type))))))))+(defn- unreferenced-query [entity-type card-types query]+ (let [table-name (case entity-type+ :card :report_card+ :table :metabase_table+ :transform :transform+ :snippet :native_query_snippet+ :dashboard :report_dashboard+ :document :document+ :sandbox :sandboxes+ :segment :segment)+ name-column (case entity-type+ :table :entity.display_name+ :sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]+ :entity.name)]+ {:select [[[:inline (name entity-type)] :entity_type]+ [:entity.id :entity_id]+ [name-column :sort_key]]+ :from [[table-name :entity]]+ :left-join [:dependency [:and+ [:= :dependency.to_entity_id :entity.id]+ [:= :dependency.to_entity_type [:inline (name entity-type)]]]]+ :where (cond->> [:= :dependency.id nil]+ (and (= entity-type :card)+ (seq card-types)) (conj [:and [:in :entity.type (mapv name card-types)]])+ (and query (not= entity-type :sandbox)) (conj [:and [:like [:lower name-column] (str "%" (u/lower-case-en query) "%")]]))}))++(def ^:private unreferenced-items-args+ [:map+ [:types {:optional true} [:or+ ::deps.dependency-types/dependency-types+ [:sequential ::deps.dependency-types/dependency-types]]]+ [:card_types {:optional true} [:or+ (ms/enum-decode-keyword lib.schema.metadata/card-types)+ [:sequential (ms/enum-decode-keyword lib.schema.metadata/card-types)]]]+ [:query {:optional true} :string]])++(api.macros/defendpoint :get "/graph/unreferenced" :- [:sequential ::entity]+ "Returns a list of all unreferenced items in the instance.+ An unreferenced item is one that is not a dependency of any other item.++ Accepts optional parameters for filtering:+ - types: List of entity types to include (e.g., [:card :transform :snippet :dashboard])+ - card_types: List of card types to include when filtering cards (e.g., [:question :model :metric])+ - query: Search string to filter by name or location++ Returns a list of unreferenced items, each with :id, :type, and :data fields."+ [_route-params+ {:keys [types card_types query]+ :or {types (vec deps.dependency-types/dependency-types)+ card_types (vec lib.schema.metadata/card-types)}} :- unreferenced-items-args]+ (let [selected-types (cond->> (if (sequential? types) types [types])+ ;; Sandboxes don't support query filtering, so exclude them when a query is provided+ query (remove #{:sandbox}))+ card-types (if (sequential? card_types) card_types [card_types])+ union-queries (map #(unreferenced-query % card-types query) selected-types)+ union-query {:union-all union-queries}+ all-ids (->> (t2/query (assoc union-query :order-by [[:sort_key :asc]]))+ (map (fn [{:keys [entity_id entity_type]}]+ [(keyword entity_type) entity_id])))+ downstream-graph (graph/cached-graph (readable-graph-dependents))]+ (expanded-nodes downstream-graph all-ids {:include-errors? false})))++(def ^:private broken-items-args+ [:map+ [:types {:optional true} [:or+ ::deps.dependency-types/dependency-types+ [:sequential ::deps.dependency-types/dependency-types]]]+ [:card_types {:optional true} [:or+ (ms/enum-decode-keyword lib.schema.metadata/card-types)+ [:sequential (ms/enum-decode-keyword lib.schema.metadata/card-types)]]]+ [:query {:optional true} :string]])++(defn- broken-query [entity-type card-types query]+ (let [table-name (case entity-type+ :card :report_card+ :table :metabase_table+ :transform :transform+ :snippet :native_query_snippet+ :dashboard :report_dashboard+ :document :document+ :sandbox :sandboxes+ :segment :segment)+ name-column (case entity-type+ :table :entity.display_name+ :sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]+ :entity.name)]+ {:select [[[:inline (name entity-type)] :entity_type]+ [:entity.id :entity_id]+ [name-column :sort_key]]+ :from [[table-name :entity]]+ :left-join [:analysis_finding [:and+ [:= :analysis_finding.analyzed_entity_id :entity.id]+ [:= :analysis_finding.analyzed_entity_type (name entity-type)]]]+ :where (cond->> [:= :analysis_finding.result false]+ (and (= entity-type :card)+ (seq card-types)) (conj [:and [:in :entity.type (mapv name card-types)]])+ (and query (not= entity-type :sandbox)) (conj [:and [:like [:lower name-column] (str "%" (u/lower-case-en query) "%")]]))}))++(api.macros/defendpoint :get "/graph/broken" :- [:sequential ::entity]+ "Returns a list of all items with broken queries.++ Accepts optional parameters for filtering:+ - `types`: List of entity types to include (e.g., `[:card :transform :snippet :dashboard]`)+ - `card_types`: List of card types to include when filtering cards (e.g., `[:question :model :metric]`)+ - `query`: Search string to filter by name or location++ Returns a list of broken items, each with `:id`, `:type`, `:data`, and `:error`s fields."+ [_route-params+ {:keys [types card_types query]+ :or {types (vec deps.dependency-types/dependency-types)+ card_types (vec lib.schema.metadata/card-types)}} :- broken-items-args]+ (let [selected-types (cond->> (if (sequential? types) types [types])+ ;; Sandboxes don't support query filtering, so exclude them when a query is provided+ query (remove #{:sandbox}))+ card-types (if (sequential? card_types) card_types [card_types])+ union-queries (map #(broken-query % card-types query) selected-types)+ union-query {:union-all union-queries}+ all-ids (->> (t2/query (assoc union-query :order-by [[:sort_key :asc]]))+ (map (fn [{:keys [entity_id entity_type]}]+ [(keyword entity_type) entity_id])))+ downstream-graph (graph/cached-graph (readable-graph-dependents))]+ (expanded-nodes downstream-graph all-ids {:include-errors? true})))+(def ^{:arglists '([request respond raise])} routes"`/api/ee/dependencies` routes."(handlers/routesdiff --git a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.cljindex 50ea6d4fd4d..267f8a12170 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj@@ -109,7 +109,7 @@(prose-mirror/collect-ast document (fn [{:keys [type attrs]}](cond(and (= prose-mirror/smart-link-type type)- (#{"card" "dashboard" "table"} (:model attrs)))+ (#{"card" "dashboard" "table" "document"} (:model attrs)))[(keyword (:model attrs)) (:entityId attrs)](= prose-mirror/card-embed-type type)diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/core.clj b/enterprise/backend/src/metabase_enterprise/dependencies/core.cljindex 931a6fd6b1d..c8c874d5a0c 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/core.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/core.clj@@ -3,16 +3,15 @@Call [[errors-from-proposed-edits]] to find out what things will break downstream of a set of new/updated entities."(:require+ [metabase-enterprise.dependencies.analysis :as deps.analysis][metabase-enterprise.dependencies.metadata-provider :as deps.provider][metabase-enterprise.dependencies.models.dependency :as deps.graph]- [metabase-enterprise.dependencies.native-validation :as deps.native][metabase.graph.core :as graph][metabase.lib-be.core :as lib-be]- [metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata][metabase.lib.metadata.protocols :as lib.metadata.protocols]- [metabase.lib.schema :as lib.schema][metabase.lib.schema.metadata :as lib.schema.metadata]+ [metabase.lib.schema.validate :as lib.schema.validate][metabase.util :as u][metabase.util.log :as log][metabase.util.malli :as mu]@@ -43,56 +42,7 @@(let [dependents (or dependents (deps.graph/transitive-dependents graph updated-entities))](deps.provider/override-metadata-provider base-provider updated-entities dependents))))-(mu/defn- check-query- "Find any bad refs in a `query`."- [driver :- :keyword- query :- ::lib.schema/query]- (if (lib/any-native-stage? query)- (deps.native/validate-native-query driver query)- (lib/find-bad-refs query)))--(defmulti ^:private check-entity- "Given a `MetadataProvider`, and entity type, and an entity id, find any bad refs in that entity."- {:arglists '([metadata-provider entity-type entity-id])}- (fn [_mp entity-type _entity-id]- entity-type))--(defmethod check-entity :default- [_mp _entity-type _entity-id]- nil)--;; TODO (Cam 10/2/25) -- we already have keywords for these things, `:model/Card` and `:model/Transform`, can use-;; those for consistency and discoverability?-(defmethod check-entity :card- [mp _entity-type card-id]- (let [query (lib/query mp (:dataset-query (lib.metadata/card mp card-id)))- driver (:engine (lib.metadata/database query))]- (check-query driver query)))--(defmethod check-entity :transform- [mp _entity-type entity-id]- (let [{{target-schema :schema target-name :name} :target- {query :query} :source- :as _transform} (lib.metadata/transform mp entity-id)- driver (:engine (lib.metadata/database mp))- query (lib/query mp query)- output-table (some #(when (and (= (:schema %) target-schema)- (= (:name %) target-name))- %)- (lib.metadata/tables mp))- output-fields (lib.metadata/active-fields mp (:id output-table))- {:keys [duplicate-fields]} (reduce (fn [{:keys [seen duplicate-fields]}- {name :name :as field}]- (if (seen name)- {:seen seen- :duplicate-fields (conj duplicate-fields field)}- {:seen (conj seen name)- :duplicate-fields duplicate-fields}))- {:seen #{}}- output-fields)]- (into duplicate-fields (check-query driver query))))--(mu/defn- check-query-soundness ;; :- [:map-of ::lib.schema.id/card [:sequential ::lib.schema.mbql-clause/clause]]+(mu/defn- check-query-soundness :- [:map-of ::entity-type [:map-of :int [:set [:ref ::lib.schema.validate/error]]]]"Given a `MetadataProvider` as returned by [[metadata-provider]], scan all its updated entities and their dependentsto check that everything is still sound.@@ -109,7 +59,7 @@errors (volatile! {})](doseq [[entity-type ids] overridesid ids- :let [bad-refs (check-entity provider entity-type id)]]+ :let [bad-refs (deps.analysis/check-entity provider entity-type id)]](when (seq bad-refs)(vswap! errors assoc-in [entity-type id] bad-refs)))@errors))@@ -136,10 +86,7 @@@by-db))-;; TODO: (Braden 09/22/2025) More precise schemas for the errors this function returns. Currently they're pretty-;; opaque, since the consumers of this function really care about "working/broken" and not the details of what's wrong-;; with any particular card.-(mu/defn errors-from-proposed-edits :- [:map-of ::entity-type [:map-of :int [:or :boolean [:sequential :any]]]]+(mu/defn errors-from-proposed-edits :- [:map-of ::entity-type [:map-of :int [:set [:ref ::lib.schema.validate/error]]]]"Given a regular `MetadataProvider`, and a map of entity types (`:card`, `:transform`, `:snippet`) to lists ofupdated entities, this returns a map of `{entity-type {entity-id [bad-ref ...]}}`.diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/dependency_types.clj b/enterprise/backend/src/metabase_enterprise/dependencies/dependency_types.cljnew file mode 100644index 00000000000..bbf46871be8--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/dependencies/dependency_types.clj@@ -0,0 +1,32 @@+(ns metabase-enterprise.dependencies.dependency-types+ (:require+ [clojure.set :as set]+ [metabase.util.malli.registry :as mr]+ [metabase.util.malli.schema :as ms]))++(def model->dependency-type+ "A map relating models to their corresponding dependency type."+ {:model/Card :card+ :model/Table :table+ :model/NativeQuerySnippet :snippet+ :model/Transform :transform+ :model/Dashboard :dashboard+ :model/Document :document+ :model/Sandbox :sandbox+ :model/Segment :segment+ :model/Measure :measure})++(def dependency-type->model+ "A map relating dependency types to their corresponding model."+ (set/map-invert model->dependency-type))++(def dependency-types+ "The set of all dependency types."+ (-> model->dependency-type vals set))++(def models+ "The set of all models that are handled by dependencies."+ (-> model->dependency-type keys set))++(mr/def ::dependency-types+ (ms/enum-decode-keyword dependency-types))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/events.clj b/enterprise/backend/src/metabase_enterprise/dependencies/events.cljindex 23ec662a5da..de951a7ab61 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/events.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/events.clj@@ -1,8 +1,11 @@(ns metabase-enterprise.dependencies.events(:require[metabase-enterprise.dependencies.calculation :as deps.calculation]+ [metabase-enterprise.dependencies.dependency-types :as deps.dependency-types]+ [metabase-enterprise.dependencies.findings :as deps.findings][metabase-enterprise.dependencies.models.dependency :as models.dependency][metabase.events.core :as events]+ [metabase.lib-be.core :as lib-be][metabase.premium-features.core :as premium-features][metabase.util.log :as log][methodical.core :as methodical]@@ -126,8 +129,8 @@(methodical/defmethod events/publish-event! ::transform-delete[_ {:keys [id]}]+ ;; TODO: (Braden 09/18/2025) Shouldn't we be deleting the downstream deps for dead edges as well as upstream?(when (premium-features/has-feature? :dependencies)- ;; TODO: (Braden 09/18/2025) Shouldn't we be deleting the downstream deps for dead edges as well as upstream?(t2/delete! :model/Dependency :from_entity_type :transform :from_entity_id id)));; On *executing* a transform, its (freshly synced) output table is made to depend on the transform.@@ -151,6 +154,8 @@(derive ::dashboard-deps :metabase/event)(derive :event/dashboard-create ::dashboard-deps)(derive :event/dashboard-update ::dashboard-deps)+;; Backfill-only event that triggers dependency calculation without creating a revision+(derive :event/dashboard-dependency-backfill ::dashboard-deps)(methodical/defmethod events/publish-event! ::dashboard-deps[_ {:keys [object]}]@@ -245,8 +250,21 @@(methodical/defmethod events/publish-event! ::segment-delete[_ {:keys [object]}]- (when (premium-features/has-feature? :dependencies)- (t2/delete! :model/Dependency :from_entity_type :segment :from_entity_id (:id object))))+ (t2/delete! :model/Dependency :from_entity_type :segment :from_entity_id (:id object)))++(defn- check-dependents! [type object recur-through-transforms?]+ (let [graph (if recur-through-transforms?+ (models.dependency/graph-dependents)+ (models.dependency/filtered-graph-dependents+ nil+ (fn [type-field _id-field]+ [:not= type-field "transform"])))+ children-map (models.dependency/transitive-dependents graph {type [object]})]+ (doseq [[type children] children-map+ :when (deps.findings/supported-entities type)+ instances (partition 50 50 nil children)]+ (-> (t2/select (deps.dependency-types/dependency-type->model type) :id [:in instances])+ deps.findings/analyze-instances!))));; ### Measures(derive ::measure-deps :metabase/event)@@ -271,3 +289,47 @@[_ {:keys [object]}](when (premium-features/has-feature? :dependencies)(t2/delete! :model/Dependency :from_entity_type :measure :from_entity_id (:id object))))++(derive ::check-card-dependents :metabase/event)+(derive :event/card-create ::check-card-dependents)+(derive :event/card-update ::check-card-dependents)+(derive :event/card-delete ::check-card-dependents)++(methodical/defmethod events/publish-event! ::check-card-dependents+ [_ {:keys [object]}]+ (when (premium-features/has-feature? :dependencies)+ (lib-be/with-metadata-provider-cache+ (deps.findings/upsert-analysis! object)+ (check-dependents! :card object false))))++(derive ::check-transform :metabase/event)+(derive :event/create-transform ::check-transform)+(derive :event/update-transform ::check-transform)+(derive :event/delete-transform ::check-transform)++(methodical/defmethod events/publish-event! ::check-transform+ [_ {:keys [object]}]+ (when (premium-features/has-feature? :dependencies)+ (lib-be/with-metadata-provider-cache+ (deps.findings/upsert-analysis! object))))++(derive ::check-segment-dependents :metabase/event)+(derive :event/segment-create ::check-segment-dependents)+(derive :event/segment-update ::check-segment-dependents)+(derive :event/segment-delete ::check-segment-dependents)++(methodical/defmethod events/publish-event! ::check-segment-dependents+ [_ {:keys [object]}]+ (when (premium-features/has-feature? :dependencies)+ (lib-be/with-metadata-provider-cache+ (deps.findings/upsert-analysis! object)+ (check-dependents! :segment object false))))++(derive ::check-transform-dependents :metabase/event)+(derive :event/transform-run-complete ::check-transform-dependents)++(methodical/defmethod events/publish-event! ::check-transform-dependents+ [_ {:keys [object]}]+ (when (premium-features/has-feature? :dependencies)+ (lib-be/with-metadata-provider-cache+ (check-dependents! :transform {:id (:transform-id object)} true))))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/findings.clj b/enterprise/backend/src/metabase_enterprise/dependencies/findings.cljnew file mode 100644index 00000000000..86cdf733801--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/dependencies/findings.clj@@ -0,0 +1,72 @@+(ns metabase-enterprise.dependencies.findings+ (:require+ [metabase-enterprise.dependencies.analysis :as deps.analysis]+ [metabase-enterprise.dependencies.dependency-types :as deps.dependency-types]+ [metabase-enterprise.dependencies.models.analysis-finding :as deps.analysis-finding]+ [metabase.lib-be.core :as lib-be]+ [metabase.lib.core :as lib]+ [metabase.util.log :as log]+ [metabase.util.malli :as mu]+ [toucan2.core :as t2]))++(set! *warn-on-reflection* true)++(defmulti ^:private instance-db-id+ "Gets the database id for a toucan instance"+ {:arglists '([toucan-instance])}+ t2/model)++(defmethod instance-db-id :default+ [toucan-instance]+ (:database_id toucan-instance))++(defmethod instance-db-id :model/Transform+ [toucan-instance]+ (some-> toucan-instance :source :query lib/database-id))++(defmethod instance-db-id :model/Segment+ [toucan-instance]+ (some-> toucan-instance :definition lib/database-id))++(defn upsert-analysis!+ "Given a Toucan entity, run its analysis and write the results into `:model/AnalysisFinding`.++ If any row exists already, it is replaced. If it does not exist, it is created."+ [toucan-instance]+ (when-not (lib-be/metadata-provider-cache)+ (throw (ex-info "FIXME: deps.findings/upsert-analysis! ran without reusing `MetadataProvider`s"+ {:instance toucan-instance})))+ (when-let [db-id (instance-db-id toucan-instance)]+ (let [mp (lib-be/application-database-metadata-provider db-id)+ model (t2/model toucan-instance)+ results (try (deps.analysis/check-entity mp (deps.dependency-types/model->dependency-type model) (:id toucan-instance))+ (catch Exception e+ (log/error e "Error analyzing entity")+ [(lib/validation-exception-error (.getMessage e))]))+ success (empty? results)]+ (deps.analysis-finding/upsert-analysis! (deps.dependency-types/model->dependency-type model) (:id toucan-instance) success results))))++(defn analyze-instances!+ "Given a series of toucan entities, upsert analyses for all of them and catch errors."+ [instances]+ (doseq [instance instances]+ (try (upsert-analysis! instance)+ (catch Exception e+ (log/errorf e "Analyzing entity %s %s failed"+ (t2/model instance) (:id instance))))))++(def supported-entities+ "Entities supported by the analysis findings code"+ #{:card :transform :segment})++(mu/defn analyze-batch! :- nat-int?+ "Add or update analyses for a batch of entities.++ Takes in an entity type and batch size, and looks for a batch of entities with missing or out of date+ AnalysisFindings and then upsert new analyses for them."+ [type :- (into [:enum] supported-entities)+ batch-size :- pos-int?]+ (let [instances (deps.analysis-finding/instances-for-analysis type batch-size)]+ (lib-be/with-metadata-provider-cache+ (analyze-instances! instances))+ (count instances)))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/init.clj b/enterprise/backend/src/metabase_enterprise/dependencies/init.cljindex 3903f741651..a3a702e187f 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/init.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/init.clj@@ -3,4 +3,5 @@[metabase-enterprise.dependencies.events][metabase-enterprise.dependencies.schema][metabase-enterprise.dependencies.settings]- [metabase-enterprise.dependencies.task.backfill]))+ [metabase-enterprise.dependencies.task.backfill]+ [metabase-enterprise.dependencies.task.entity-check]))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj b/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.cljindex a006edb1b45..9077ef739be 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/metadata_provider.clj@@ -11,7 +11,7 @@downstream entities in any order."(:require[medley.core :as m]- [metabase-enterprise.dependencies.native-validation :as deps.native]+ [metabase-enterprise.dependencies.analysis :as deps.analysis][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata][metabase.lib.metadata.protocols :as lib.metadata.protocols]@@ -112,12 +112,9 @@(assoc-in m ks v))% kvs)))-(defn- get-returned-columns [mp queryable]- (let [query (lib/query mp queryable)]- (if (lib/native-only-query? query)- (deps.native/native-result-metadata (:engine (lib.metadata/database mp))- query)- (lib/returned-columns query))))+(defn- returned-columns [mp queryable]+ (deps.analysis/returned-columns (:engine (lib.metadata/database mp))+ (lib/query mp queryable)))(defmethod add-override :card [^OverridingMetadataProvider mp _entity-type id updates](with-overrides mp@@ -129,7 +126,7 @@(dissoc :result-metadata)))updates));; This uses the outer OMP and so the overrides are visible!- [::card-columns id] (delay (get-returned-columns mp (lib.metadata/card mp id)))}))+ [::card-columns id] (delay (returned-columns mp (lib.metadata/card mp id)))}))(defonce ^:private last-fake-id (atom 2000000000))@@ -158,7 +155,7 @@(lib/returned-columns (lib/query (inner-mp mp) existing-table)))output-cols (delay;; Note that this will analyze the query with any upstream changes included!- (let [new-cols (get-returned-columns mp (:query source))+ (let [new-cols (returned-columns mp (:query source))by-name (m/index-by :lib/desired-column-alias existing-cols)](into [] (for [col new-cols:let [old-col (by-name (:lib/desired-column-alias col))]]diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/models/analysis_finding.clj b/enterprise/backend/src/metabase_enterprise/dependencies/models/analysis_finding.cljnew file mode 100644index 00000000000..0300b256bec--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/dependencies/models/analysis_finding.clj@@ -0,0 +1,63 @@+(ns metabase-enterprise.dependencies.models.analysis-finding+ (:require+ [metabase-enterprise.dependencies.dependency-types :as deps.dependency-types]+ [metabase.lib.normalize :as lib.normalize]+ [metabase.models.interface :as mi]+ [methodical.core :as methodical]+ [toucan2.core :as t2]))++(methodical/defmethod t2/table-name :model/AnalysisFinding [_model] :analysis_finding)++(derive :model/AnalysisFinding :metabase/model)++(defn- analysis-finding-details-out [finding]+ (some->> (mi/json-out-with-keywordization finding)+ (into #{} (map #(lib.normalize/normalize :metabase.lib.schema.validate/error %)))))++(t2/deftransforms :model/AnalysisFinding+ {:analyzed_entity_type mi/transform-keyword+ :finding_details {:in mi/json-in+ :out analysis-finding-details-out}})++(def ^:dynamic *current-analysis-finding-version*+ "Current version of the query validation logic.+ This should be incremented when the analysis logic changes.+ The background task will re-analyze anything with out-of-date analyses.++ This generally shouldn't be rebound in real code, but making it dynamic is convenient for testing"+ 3)++(defn upsert-analysis!+ "Given the details of an AnalysisFinding row, upsert the data into the actual db."+ [type instance-id result finding-details]+ (let [update {:analyzed_at (mi/now)+ :analysis_version *current-analysis-finding-version*+ :result result+ :finding_details finding-details}+ existing-id (t2/select-one-fn :id [:model/AnalysisFinding :id]+ :analyzed_entity_type type+ :analyzed_entity_id instance-id)]+ (if existing-id+ (t2/update! :model/AnalysisFinding existing-id update)+ (t2/insert! :model/AnalysisFinding+ (assoc update+ :analyzed_entity_type type+ :analyzed_entity_id instance-id)))))++(defn instances-for-analysis+ "Find a batch of instances with missing or outdated AnalysisFindings"+ [type batch-size]+ (let [model (deps.dependency-types/dependency-type->model type)+ table-name (t2/table-name model)+ id-field (keyword (name table-name) "id")+ table-wildcard (keyword (name table-name) "*")]+ (t2/select model+ {:select [table-wildcard]+ :from table-name+ :left-join [:analysis_finding [:and+ [:= :analysis_finding.analyzed_entity_id id-field]+ [:= :analysis_finding.analyzed_entity_type (name type)]]]+ :where [:<+ [:coalesce :analysis_finding.analysis_version 0]+ *current-analysis-finding-version*]+ :limit batch-size})))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.clj b/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.cljindex 55c56c114a7..0e6c43eff6e 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.clj@@ -11,7 +11,7 @@(def current-dependency-analysis-version"Current version of the dependency analysis logic.This should be incremented when the dependency analysis logic changes."- 3)+ 4)(methodical/defmethod t2/table-name :model/Dependency [_model] :dependency)@@ -27,12 +27,14 @@Returns a map from [src-type src-id] tuples to sets of [dst-type dst-id] tuples representing dependencies.When `destination-filter-fn` is provided, it should be a function accepting two arguments+ (entity-type-field, entity-id-field) and returning a HoneySQL WHERE clause for filtering destination entities.++ When `source-filter-fn` is provided, it should be a function accepting two arguments(entity-type-field, entity-id-field) and returning a HoneySQL WHERE clause for filtering destination entities."- ([src-type src-id dst-type dst-id key-seq]- (deps-children src-type src-id dst-type dst-id key-seq nil))- ([src-type src-id dst-type dst-id key-seq destination-filter-fn]+ ([{:keys [src-type src-id dst-type dst-id key-seq destination-filter-fn source-filter-fn]}](let [base-filter (cond-> [:and]- destination-filter-fn (conj (destination-filter-fn dst-type dst-id)))]+ destination-filter-fn (conj (destination-filter-fn dst-type dst-id))+ source-filter-fn (conj (source-filter-fn src-type src-id)))](transduce (map (fn [[entity-type entity-keys]](let [full-filter (conj base-filter[:= src-type (name entity-type)]@@ -52,11 +54,23 @@to sets of dependent (downstream) entity keys.When `destination-filter-fn` is provided, it should be a function accepting two arguments- (entity-type-field, entity-id-field) and returning a HoneySQL WHERE clause for filtering."+ (entity-type-field, entity-id-field) and returning a HoneySQL WHERE clause for filtering+ the child side of a dependency.++ When `source-filter-fn` is provided, it should be a function accepting two arguments+ (entity-type-field, entity-id-field) and returning a HoneySQL WHERE clause for filtering+ the child side of a dependency."([key-seq]- (key-dependents key-seq nil))- ([key-seq destination-filter-fn]- (deps-children :to_entity_type :to_entity_id :from_entity_type :from_entity_id key-seq destination-filter-fn)))+ (key-dependents key-seq nil nil))+ ([key-seq destination-filter-fn source-filter-fn]+ (deps-children+ {:src-type :to_entity_type+ :src-id :to_entity_id+ :dst-type :from_entity_type+ :dst-id :from_entity_id+ :key-seq key-seq+ :destination-filter-fn destination-filter-fn+ :source-filter-fn source-filter-fn})))(defn- key-dependencies"Get the dependency entity keys for the entity keys in `key-seq`.@@ -65,11 +79,23 @@to sets of dependency (upstream) entity keys.When `destination-filter-fn` is provided, it should be a function accepting two arguments- (entity-type-field, entity-id-field) and returning a HoneySQL WHERE clause for filtering."+ (entity-type-field, entity-id-field) and returning a HoneySQL WHERE clause for filtering+ the child side of a dependency.++ When `source-filter-fn` is provided, it should be a function accepting two arguments+ (entity-type-field, entity-id-field) and returning a HoneySQL WHERE clause for filtering+ the child side of a dependency."([key-seq]- (key-dependencies key-seq nil))- ([key-seq destination-filter-fn]- (deps-children :from_entity_type :from_entity_id :to_entity_type :to_entity_id key-seq destination-filter-fn)))+ (key-dependencies key-seq nil nil))+ ([key-seq destination-filter-fn source-filter-fn]+ (deps-children+ {:src-type :from_entity_type+ :src-id :from_entity_id+ :dst-type :to_entity_type+ :dst-id :to_entity_id+ :key-seq key-seq+ :destination-filter-fn destination-filter-fn+ :source-filter-fn source-filter-fn})))(p/deftype+ DependencyGraph [children-fn]graph/Graph@@ -92,29 +118,40 @@Arguments:- `key-fn`: Either key-dependencies or key-dependents, determining graph direction- `destination-filter-fn`: Function accepting (entity-type-field, entity-id-field)- and returning a HoneySQL WHERE clause"- [key-fn destination-filter-fn]+ and returning a HoneySQL WHERE clause that will filter the child side of a dependency+ - `source-filter-fn`: Function accepting (entity-type-field, entity-id-field) and+ returning a HoneySQL WHERE clause that will filter the parent side of a dependency"++ [key-fn destination-filter-fn source-filter-fn](->DependencyGraph(fn [key-seq]- (key-fn key-seq destination-filter-fn))))+ (key-fn key-seq destination-filter-fn source-filter-fn))))(defn filtered-graph-dependencies"Create a permission-aware dependency graph for finding upstream dependencies.Arguments:- `destination-filter-fn`: Function accepting (entity-type-field, entity-id-field)- and returning a HoneySQL WHERE clause for filtering destination entities"- [destination-filter-fn]- (filtered-graph key-dependencies destination-filter-fn))+ and returning a HoneySQL WHERE clause for filtering destination entities+ - `source-filter-fn`: Optional function accepting (entity-type-field, entity-id-field)+ and returning a HoneySQL WHERE clause that will filter the parent side of a dependency"+ ([destination-filter-fn]+ (filtered-graph-dependencies destination-filter-fn nil))+ ([destination-filter-fn source-filter-fn]+ (filtered-graph key-dependencies destination-filter-fn source-filter-fn)))(defn filtered-graph-dependents"Create a permission-aware dependency graph for finding downstream dependents.Arguments:- `destination-filter-fn`: Function accepting (entity-type-field, entity-id-field)- and returning a HoneySQL WHERE clause for filtering destination entities"- [destination-filter-fn]- (filtered-graph key-dependents destination-filter-fn))+ and returning a HoneySQL WHERE clause for filtering destination entities+ - `source-filter-fn`: Optional function accepting (entity-type-field, entity-id-field)+ and returning a HoneySQL WHERE clause that will filter the parent side of a dependency"+ ([destination-filter-fn]+ (filtered-graph-dependents destination-filter-fn nil))+ ([destination-filter-fn source-filter-fn]+ (filtered-graph key-dependents destination-filter-fn source-filter-fn)))(defn transitive-dependents"Given a map of updated entities `{entity-type [{:id 1, ...} ...]}`, return a map of its transitive dependentsdiff --git a/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj b/enterprise/backend/src/metabase_enterprise/dependencies/schema.cljindex 5be605e1aa5..38a61d1e866 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/schema.clj@@ -1,5 +1,6 @@(ns metabase-enterprise.dependencies.schema(:require+ [metabase.documents.schema :as documents.schema][metabase.lib.schema.id :as lib.schema.id][metabase.util.malli.registry :as mr]))@@ -10,6 +11,6 @@[:snippet {:optional true} [:set ::lib.schema.id/snippet]][:transform {:optional true} [:set ::lib.schema.id/transform]][:dashboard {:optional true} [:set ::lib.schema.id/dashboard]]- [:document {:optional true} [:set ::lib.schema.id/document]]+ [:document {:optional true} [:set ::documents.schema/document.id]][:sandbox {:optional true} [:set ::lib.schema.id/sandbox]][:segment {:optional true} [:set ::lib.schema.id/segment]]])diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/settings.clj b/enterprise/backend/src/metabase_enterprise/dependencies/settings.cljindex 3db8ff862da..c66e6b0eaa4 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/settings.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/settings.clj@@ -3,7 +3,7 @@[metabase.settings.core :refer [defsetting]]))(defsetting dependency-backfill-batch-size- "Batch size."+ "The number of entities that the dependency backfill job will process per run.":visibility :internal:type :integer:default 500@@ -11,7 +11,7 @@:export? false)(defsetting dependency-backfill-delay-minutes- "Backfill delay in minutes."+ "The average delay between when the dependency backfill job will run.":visibility :internal:type :integer:default 60@@ -19,7 +19,35 @@:export? false)(defsetting dependency-backfill-variance-minutes- "Backfill variance (?) whatever that means."+ "The variation in when the dependency backfill job will run. The actual delay between runs will be a random value+ between `dependency-backfill-delay-minutes - dependency-backfill-variance-minutes` and+ `dependency-backfill-delay-minutes + dependency-backfill-variance-minutes`."+ :visibility :internal+ :type :integer+ :default 30+ :setter :none+ :export? false)++(defsetting dependency-entity-check-batch-size+ "The number of entities that the entity check job will process per run."+ :visibility :internal+ :type :integer+ :default 500+ :setter :none+ :export? false)++(defsetting dependency-entity-check-delay-minutes+ "The average delay between when the entity check job will run."+ :visibility :internal+ :type :integer+ :default 60+ :setter :none+ :export? false)++(defsetting dependency-entity-check-variance-minutes+ "The variation in when the entity check job will run. The actual delay between runs will be a random value+ between `dependency-entity-check-delay-minutes - dependency-entity-check-variance-minutes` and+ `dependency-entity-check-delay-minutes + dependency-entity-check-variance-minutes`.":visibility :internal:type :integer:default 30diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/task/backfill.clj b/enterprise/backend/src/metabase_enterprise/dependencies/task/backfill.cljindex 910df6ee1a5..02fbe658c9c 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/task/backfill.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/task/backfill.clj@@ -9,17 +9,17 @@and populates the dependency table. For cards, the event is emitted by the job handler itself,because the update of the record doesn't trigger the event handler. "(:require- [clojurewerkz.quartzite.jobs :as jobs]- [clojurewerkz.quartzite.scheduler :as qs]- [clojurewerkz.quartzite.triggers :as triggers][java-time.api :as t][metabase-enterprise.dependencies.models.dependency :as models.dependency][metabase-enterprise.dependencies.settings :as deps.settings]+ [metabase-enterprise.dependencies.task-util :as deps.task-util]+ [metabase.config.core :as config][metabase.events.core :as events][metabase.premium-features.core :as premium-features][metabase.task.core :as task][metabase.util :as u][metabase.util.log :as log]+ [methodical.core :as methodical][toucan2.core :as t2])(:import(java.util Map Set)@@ -33,6 +33,10 @@(t/to-millis-from-epoch (t/instant)))(def ^:private entities+ "The list of models to backfill.++ This is not the same as deps.dependency-types/models, because tables shouldn't be backfilled. Instead, links+ involing tables are found via analysis of the other side of the relation."[:model/Card:model/Transform:model/NativeQuerySnippet@@ -69,25 +73,30 @@(take batch-size))(t2/reducible-select [model-kw :id] :dependency_analysis_version [:< target-version]))))-(defn- backfill-card!- [id target-version]- ;; We don't want to change the card at all, we just want to update the dependency data and- ;; mark the card as processed for this dependency analysis version.- (let [update-count (t2/update! :model/Card id :dependency_analysis_version [:< target-version]+(def ^:private custom-backfill-events+ {:model/Card :event/card-dependency-backfill+ :model/Dashboard :event/dashboard-dependency-backfill})++(defn- custom-backfill-entity!+ [model-kw event id target-version]+ ;; We don't want to change the entity at all, we just want to update the dependency data and+ ;; mark the entity as processed for this dependency analysis version.+ (let [update-count (t2/update! model-kw id :dependency_analysis_version [:< target-version]{:dependency_analysis_version target-version})]- (when-let [card (and (pos? update-count)- (t2/select-one :model/Card id))]- (events/publish-event! :event/card-dependency-backfill {:object card}))+ (when-let [entity (and (pos? update-count)+ (t2/select-one model-kw id))]+ (events/publish-event! event {:object entity}))update-count))(defn- backfill-entity id)- (u/prog1 (t2/with-transaction [_]- (case model-kw- :model/Card (backfill-card! id target-version)- (t2/update! model-kw id :dependency_analysis_version [:< target-version]- {:dependency_analysis_version target-version})))+ (u/prog1+ (t2/with-transaction [_]+ (if-let [event (custom-backfill-events model-kw)]+ (custom-backfill-entity! model-kw event id target-version)+ (t2/update! model-kw id :dependency_analysis_version [:< target-version]+ {:dependency_analysis_version target-version})))(log/debug "Backfilled " (name model-kw) id)))(defn- backfill-entity-batch!@@ -157,9 +166,9 @@retries? (has-pending-retries?)](if (or full-batch-selected?retries?)- (let [delay-seconds (* (deps.settings/dependency-backfill-delay-minutes) 60)- variance-seconds (* (deps.settings/dependency-backfill-variance-minutes) 60)- delay-in-seconds (max 0 (+ (- delay-seconds variance-seconds) (rand-int (* 2 variance-seconds))))]+ (let [delay-in-seconds (deps.task-util/job-delay+ (deps.settings/dependency-backfill-delay-minutes)+ (deps.settings/dependency-backfill-variance-minutes))](schedule-next-run! delay-in-seconds (.getScheduler ctx)))(log/info "No more entities to backfill for, stopping."))))@@ -169,20 +178,27 @@(defn- schedule-next-run!([delay-in-seconds] (schedule-next-run! delay-in-seconds nil))([delay-in-seconds scheduler]- (let [start-at (java.util.Date. (long (+ (current-millis) (* delay-in-seconds 1000))))- trigger (triggers/build- (triggers/with-identity (triggers/key (str trigger-key \. (random-uuid))))- (triggers/for-job job-key)- (triggers/start-at start-at))]- (log/info "Scheduling next run at" start-at)- (if scheduler- ;; re-scheduling from the job- (qs/add-trigger scheduler trigger)- ;; first schedule- (let [job (jobs/build (jobs/of-type BackfillDependencies) (jobs/with-identity job-key))]- (task/schedule-task! job trigger))))))+ (deps.task-util/schedule-next-run!+ {:job-type BackfillDependencies+ :job-name "Dependency Backfill"+ :job-key job-key+ :trigger-key trigger-key+ :delay-in-seconds delay-in-seconds+ :scheduler scheduler})))(defmethod task/init! ::DependencyBackfill [_](if (pos? (deps.settings/dependency-backfill-batch-size))- (schedule-next-run! (rand-int (* (deps.settings/dependency-backfill-variance-minutes) 60)))+ (schedule-next-run! (if config/is-test?+ 0+ (deps.task-util/job-initial-delay+ (deps.settings/dependency-backfill-variance-minutes))))(log/info "Not starting dependency backfill job because the batch size is not positive")))++(derive ::backfill :metabase/event)+(derive :event/serdes-load ::backfill)+(derive :event/set-premium-embedding-token ::backfill)++(methodical/defmethod events/publish-event! ::backfill+ [_ _]+ (when (premium-features/has-feature? :dependencies)+ (backfill-dependencies!)))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/task/entity_check.clj b/enterprise/backend/src/metabase_enterprise/dependencies/task/entity_check.cljnew file mode 100644index 00000000000..285502d04a4--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/dependencies/task/entity_check.clj@@ -0,0 +1,58 @@+(ns metabase-enterprise.dependencies.task.entity-check+ (:require+ [metabase-enterprise.dependencies.findings :as deps.findings]+ [metabase-enterprise.dependencies.settings :as deps.settings]+ [metabase-enterprise.dependencies.task-util :as deps.task-util]+ [metabase.premium-features.core :as premium-features]+ [metabase.task.core :as task]+ [metabase.util.log :as log]))++(set! *warn-on-reflection* true)++(defn- check-entities!+ []+ (when (premium-features/has-feature? :dependencies)+ (-> (reduce (fn [batch-size entity-type]+ (if (< batch-size 1)+ (reduced 0)+ (let [processed (deps.findings/analyze-batch! entity-type batch-size)]+ (when (pos? processed)+ (log/info "Updated" processed "entities of type" entity-type))+ (- batch-size processed))))+ (deps.settings/dependency-entity-check-batch-size)+ deps.findings/supported-entities)+ (< 1))))++(declare schedule-next-run!)++(task/defjob+ ^{:doc "Check all entities for validity"+ org.quartz.DisallowConcurrentExecution true}+ DependencyEntityCheck [ctx]+ (log/info "Executing DependencyEntityCheck job...")+ (check-entities!)+ (let [delay-in-seconds (deps.task-util/job-delay+ (deps.settings/dependency-entity-check-delay-minutes)+ (deps.settings/dependency-entity-check-variance-minutes))]+ (schedule-next-run! delay-in-seconds (.getScheduler ctx))))++(def ^:private job-key "metabase.dependencies.task.entity-check.job")+(def ^:private trigger-key "metabase.dependencies.task.entity-check.trigger")++(defn- schedule-next-run!+ ([delay-in-seconds] (schedule-next-run! delay-in-seconds nil))+ ([delay-in-seconds scheduler]+ (deps.task-util/schedule-next-run!+ {:job-type DependencyEntityCheck+ :job-name "Dependency Entity Check"+ :job-key job-key+ :trigger-key trigger-key+ :delay-in-seconds delay-in-seconds+ :scheduler scheduler})))++(defmethod task/init! ::DependencyEntityCheck [_]+ (if (pos? (deps.settings/dependency-entity-check-batch-size))+ (-> (deps.settings/dependency-entity-check-variance-minutes)+ deps.task-util/job-initial-delay+ schedule-next-run!)+ (log/info "Not starting dependency entity check job because the batch size is not positive")))diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/task_util.clj b/enterprise/backend/src/metabase_enterprise/dependencies/task_util.cljnew file mode 100644index 00000000000..7b5e7405178--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/dependencies/task_util.clj@@ -0,0 +1,50 @@+(ns metabase-enterprise.dependencies.task-util+ (:require+ [clojurewerkz.quartzite.jobs :as jobs]+ [clojurewerkz.quartzite.scheduler :as qs]+ [clojurewerkz.quartzite.triggers :as triggers]+ [java-time.api :as t]+ [metabase.task.core :as task]+ [metabase.util.log :as log]))++(set! *warn-on-reflection* true)++(defn job-delay+ "Generates a random delay in seconds based on `delay` and `variance`.++ Both `delay` and `variance` should be in minutes, and the result will vary between `delay-variance` and+ `delay+variance`."+ [delay variance]+ (let [delay-duration (t/duration delay :minutes)+ variance-duration (t/duration variance :minutes)]+ (max 0 (.. delay-duration+ (minus variance-duration)+ (plusSeconds (rand-int (.. variance-duration+ (multipliedBy 2)+ toSeconds)))+ toSeconds))))++(defn job-initial-delay+ "Generates a random delay in seconds based on `variance`.++ `variance` is in minutes and the result will vary between 0 and `variance`"+ [variance]+ (rand-int (.toSeconds (t/duration variance :minutes))))++(defn schedule-next-run!+ "Schedule the passed in job after a given delay."+ [{:keys [job-type job-name job-key trigger-key delay-in-seconds scheduler]}]+ (let [start-at (-> (t/instant)+ (t/+ (t/duration delay-in-seconds :seconds))+ java.util.Date/from)+ trigger (triggers/build+ (triggers/with-identity (triggers/key (str trigger-key \. (random-uuid))))+ (triggers/for-job job-key)+ (triggers/start-at start-at))]+ (log/info "Scheduling next run of job" job-name "at" start-at)+ (if scheduler+ ;; re-scheduling from the job+ (qs/add-trigger scheduler trigger)+ ;; first schedule+ (let [job (jobs/build (jobs/of-type job-type) (jobs/with-identity job-key))]+ (task/schedule-task! job trigger)))))diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/schema.clj b/enterprise/backend/src/metabase_enterprise/sandbox/schema.cljindex 1e2d20c6bc4..856e8d8ed93 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/schema.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/schema.clj@@ -31,3 +31,7 @@"Toucan transform spec for the Sandbox `attribute_remappings` column."{:in (comp mi/json-in normalize-attribute-remappings):out (comp normalize-attribute-remappings mi/json-out-without-keywordization)})++(mr/def ::sandbox+ [:map+ [:id ::lib.schema.id/sandbox]])diff --git a/enterprise/backend/src/metabase_enterprise/serialization/cmd.clj b/enterprise/backend/src/metabase_enterprise/serialization/cmd.cljindex 218cea64ced..5bf58202df6 100644--- a/enterprise/backend/src/metabase_enterprise/serialization/cmd.clj+++ b/enterprise/backend/src/metabase_enterprise/serialization/cmd.clj@@ -10,6 +10,7 @@[metabase-enterprise.serialization.v2.storage :as v2.storage][metabase.analytics.core :as analytics][metabase.app-db.core :as mdb]+ [metabase.events.core :as events][metabase.models.serialization :as serdes][metabase.plugins.core :as plugins][metabase.premium-features.core :as premium-features]@@ -47,12 +48,13 @@(throw (ex-info "You cannot `import` into an empty database. Please set up Metabase normally, then retry." {})))(when token-check?(check-premium-token!))- ; TODO This should be restored, but there's no manifest or other meta file written by v2 dumps.- ;(when-not (load/compatible? path)- ; (log/warn "Dump was produced using a different version of Metabase. Things may break!"))+ ;; TODO This should be restored, but there's no manifest or other meta file written by v2 dumps.+ ;;(when-not (load/compatible? path)+ ;; (log/warn "Dump was produced using a different version of Metabase. Things may break!"))(log/infof "Loading serialized Metabase files from %s" path)- (serdes/with-cache- (v2.load/load-metabase! (v2.ingest/ingest-yaml path) opts)))+ (u/prog1 (serdes/with-cache+ (v2.load/load-metabase! (v2.ingest/ingest-yaml path) opts))+ (events/publish-event! :event/serdes-load {})))(mu/defn v2-load!"SerDes v2 load entry point.@@ -112,6 +114,8 @@(serdes/with-cache(-> (v2.extract/extract opts)(v2.storage/store! path)))+ ;; we could publish :event/serdes-dump to go with :event/serdes-load above, but+ ;; nothing would listen to it currently(catch Exception e(reset! err e)))](analytics/track-event! :snowplow/serializationdiff --git a/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj b/enterprise/backend/src/metabase_enterprise/serialization/v2/models.cljindex 90ec9cf9ed4..d008da6282d 100644--- a/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj+++ b/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj@@ -49,7 +49,8 @@(def excluded-models"List of models which are not going to be serialized ever."- ["ApiKey"+ ["AnalysisFinding"+ "ApiKey""ApplicationPermissionsRevision""AuditLog""AuthIdentity"diff --git a/enterprise/backend/src/metabase_enterprise/transforms/schema.clj b/enterprise/backend/src/metabase_enterprise/transforms/schema.cljindex a0360a8d7a7..8fc48dfc54c 100644--- a/enterprise/backend/src/metabase_enterprise/transforms/schema.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms/schema.clj@@ -1,6 +1,7 @@(ns metabase-enterprise.transforms.schema(:require[metabase.lib.metadata.column :as lib.metadata.column]+ [metabase.lib.schema.common :as lib.schema.common][metabase.queries.schema :as queries.schema][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]))@@ -35,7 +36,7 @@[:multi {:dispatch (comp keyword :type)}[:query[:map- [:type [:= "query"]]+ [:type {:decode/normalize lib.schema.common/normalize-keyword} [:= :query]][:query ::queries.schema/query][:source-incremental-strategy {:optional true} ::source-incremental-strategy]]][:python@@ -43,7 +44,7 @@[:source-database {:optional true} :int];; NB: if source is checkpoint, only one table allowed[:source-tables [:map-of :string ::source-table-value]]- [:type [:= "python"]]+ [:type {:decode/normalize lib.schema.common/normalize-keyword} [:= :python]][:body :string][:source-incremental-strategy {:optional true} ::source-incremental-strategy]]]])@@ -73,3 +74,10 @@[:multi {:dispatch :type}["table" ::table-target]["table-incremental" ::table-incremental-target]])++(mr/def ::transform+ [:map+ [:description {:optional true} [:maybe :string]]+ [:name :string]+ [:source [:ref ::transform-source]]+ [:target [:ref ::transform-target]]])diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.cljindex 4f3207a6f23..185db5eecfe 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj@@ -2,6 +2,9 @@(:require[clojure.test :refer :all][medley.core :as m]+ [metabase-enterprise.dependencies.events]+ [metabase-enterprise.dependencies.findings :as dependencies.findings]+ [metabase-enterprise.dependencies.task.backfill :as dependencies.backfill][metabase.events.core :as events][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata]@@ -11,6 +14,9 @@[metabase.test :as mt][metabase.util :as u]))+(comment+ metabase-enterprise.dependencies.events/keep-me)+(defn card-with-query"Create a card map with the given name and dataset query."[card-name dataset-query]@@ -305,7 +311,7 @@:type "table"}]}(-> response(update :edges set)- (update :nodes #(sort-by :type %)))))))))))+ (update :nodes #(sort-by (juxt :type :id) %)))))))))))(deftest graph-transform-hydrates-creator-test(testing "GET /api/ee/dependencies/graph hydrates creator for transforms"@@ -1010,3 +1016,266 @@(is (contains? node-ids measure-b-id) "measure B should appear with archived=true")(is (contains? node-ids measure-c-id) "measure C should appear")(is (contains? node-ids products-id) "products table should appear"))))))))++(deftest ^:sequential unreferenced-questions-test+ (testing "GET /api/ee/dependencies/unreferenced - only unreferenced questions are returned"+ (mt/with-premium-features #{:dependencies}+ (let [mp (mt/metadata-provider)+ products (lib.metadata/table mp (mt/id :products))]+ (mt/with-temp [:model/Card {referenced-card-id :id} {:name "Referenced Card - unreftest"+ :type :question+ :dataset_query (lib/query mp products)}+ :model/Card {unreffed-card-id :id} {:name "Unreferenced Card - unreftest"+ :type :question+ :dataset_query (->> referenced-card-id+ (lib.metadata/card mp)+ (lib/query mp))}]+ (while (#'dependencies.backfill/backfill-dependencies!))+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=question&query=unreftest")]+ (is (=? [{:id unreffed-card-id+ :type "card"+ :data {:name "Unreferenced Card - unreftest"}}]+ response))))))))++(deftest ^:sequential unreferenced-tables-test+ (testing "GET /api/ee/dependencies/unreferenced - only unreferenced tables are returned"+ (mt/with-premium-features #{:dependencies}+ (let [mp (mt/metadata-provider)]+ (mt/with-temp [:model/Table {unreffed-table-id :id} {:name "Unreferenced Table - unreftest"}+ :model/Table {referenced-table-id :id} {:name "Referenced Table - unreftest"}+ :model/Card _card {:name "Referencing Card"+ :type :question+ :dataset_query (lib/query mp (lib.metadata/table mp referenced-table-id))}]+ (while (#'dependencies.backfill/backfill-dependencies!))+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=table&query=unreftest")]+ (is (=? [{:id unreffed-table-id+ :type "table"+ :data {:name "Unreferenced Table - unreftest"}}]+ response))))))))++(deftest ^:sequential unreferenced-transforms-test+ (testing "GET /api/ee/dependencies/unreferenced - only unreferenced transforms are returned"+ (mt/with-premium-features #{:dependencies}+ (let [mp (mt/metadata-provider)+ products (lib.metadata/table mp (mt/id :products))]+ (mt/with-temp [:model/Transform {unreffed-transform-id :id} {:name "Unreferenced Transform - unreftest"+ :source {:type :query+ :query (lib/query mp products)}+ :target {:schema "PUBLIC"+ :name "unreferenced_transform_table"}}+ :model/Transform {referenced-transform-id :id} {:name "Referenced Transform - unreftest"+ :source {:type :query+ :query (lib/query mp products)}+ :target {:schema "PUBLIC"+ :name "referenced_transform_table"}}+ :model/Table _ {:name "referenced_transform_table"+ :db_id (mt/id)+ :schema "PUBLIC"}]+ (events/publish-event! :event/transform-run-complete+ {:object {:db-id (mt/id)+ :output-schema "PUBLIC"+ :output-table "referenced_transform_table"+ :transform-id referenced-transform-id}})+ (while (#'dependencies.backfill/backfill-dependencies!))+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=transform&query=unreftest")]+ (is (=? [{:id unreffed-transform-id+ :type "transform"+ :data {:name "Unreferenced Transform - unreftest"}}]+ response))))))))++(deftest ^:sequential unreferenced-snippets-test+ (testing "GET /api/ee/dependencies/unreferenced - only unreferenced snippets are returned"+ (mt/with-premium-features #{:dependencies}+ (let [mp (mt/metadata-provider)]+ (mt/with-temp [:model/NativeQuerySnippet {unreffed-snippet-id :id} {:name "Unreferenced Snippet - unreftest"+ :content "WHERE ID > 10"}+ :model/NativeQuerySnippet {referenced-snippet-id :id snippet-name :name} {:name "Referenced Snippet - unreftest"+ :content "WHERE ID > 20"}]+ (let [tag-name (str "snippet: " snippet-name)+ native-query (-> (lib/native-query mp (format "SELECT * FROM PRODUCTS %s" (str "{{" tag-name "}}")))+ (lib/with-template-tags {tag-name {:name tag-name+ :display-name (str "Snippet: " snippet-name)+ :type :snippet+ :snippet-name snippet-name+ :snippet-id referenced-snippet-id}}))]+ (mt/with-temp [:model/Card _card {:name "Card using snippet"+ :type :question+ :dataset_query native-query}]+ (while (#'dependencies.backfill/backfill-dependencies!))+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=snippet&query=unreftest")]+ (is (=? [{:id unreffed-snippet-id+ :type "snippet"+ :data {:name "Unreferenced Snippet - unreftest"}}]+ response))))))))))++(deftest ^:sequential unreferenced-dashboards-test+ (testing "GET /api/ee/dependencies/unreferenced - only unreferenced dashboards are returned"+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/Dashboard {unreffed-dashboard-id :id} {:name "Unreferenced Dashboard - unreftest"}+ :model/Dashboard {referenced-dashboard-id :id} {:name "Referenced Dashboard - unreftest"}+ :model/Document _ {:name "Document with dashboard link"+ :dependency_analysis_version 0+ :document {:type "doc"+ :content [{:type "paragraph"+ :content [{:type "smartLink"+ :attrs {:entityId referenced-dashboard-id+ :model "dashboard"}}]}]}+ :content_type "application/json+vnd.prose-mirror"}]+ (while (#'dependencies.backfill/backfill-dependencies!))+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=dashboard&query=unreftest")]+ (is (=? [{:id unreffed-dashboard-id+ :type "dashboard"+ :data {:name "Unreferenced Dashboard - unreftest"}}]+ response)))))))++(deftest ^:sequential unreferenced-documents-test+ (testing "GET /api/ee/dependencies/unreferenced - only unreferenced documents are returned"+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/Document {referenced-document-id :id} {:name "Referenced Document - unreftest"}+ :model/Document {unreffed-document-id :id} {:name "Unreferenced Document - unreftest"+ :document {:type "doc"+ :content [{:type "paragraph"+ :content [{:type "smartLink"+ :attrs {:entityId referenced-document-id+ :model "document"}}]}]}+ :content_type "application/json+vnd.prose-mirror"}]+ (while (#'dependencies.backfill/backfill-dependencies!))+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=document&query=unreftest")]+ (is (=? [{:id unreffed-document-id+ :type "document"+ :data {:name "Unreferenced Document - unreftest"}}]+ response)))))))++(deftest ^:sequential unreferenced-sandboxes-test+ (testing "GET /api/ee/dependencies/unreferenced - unreferenced sandboxes are returned"+ (mt/with-premium-features #{:dependencies :sandboxes}+ (let [mp (mt/metadata-provider)+ products (lib.metadata/table mp (mt/id :products))]+ (mt/with-temp [:model/PermissionsGroup {group-id :id} {:name "Sandbox Group - unreftest"}+ :model/Card {sandbox-card-id :id} {:name "Sandbox Card - unreftest"+ :type :question+ :dataset_query (lib/query mp products)}+ :model/Sandbox {sandbox-id :id} {:group_id group-id+ :table_id (mt/id :products)+ :card_id sandbox-card-id}]+ (while (#'dependencies.backfill/backfill-dependencies!))+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=sandbox")]+ (is (=? [{:id sandbox-id+ :type "sandbox"+ :data {:table {:name "PRODUCTS"}}}]+ response))))))))++(deftest ^:sequential unreferenced-card-types-test+ (testing "GET /api/ee/dependencies/unreferenced - unreferenced models and metrics are filtered by card_types and pagination"+ (mt/with-premium-features #{:dependencies}+ (let [mp (mt/metadata-provider)+ products (lib.metadata/table mp (mt/id :products))]+ (mt/with-temp [:model/Card {unreffed-model-id :id} {:name "A - Unreferenced Model - cardtype"+ :type :model+ :dataset_query (lib/query mp products)}+ :model/Card {unreffed-metric-id :id} {:name "B - Unreferenced Metric - cardtype"+ :type :metric+ :dataset_query (lib/query mp products)}]+ (while (#'dependencies.backfill/backfill-dependencies!))+ (testing "filtering by model only"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=model&query=cardtype")]+ (is (=? [{:id unreffed-model-id+ :type "card"+ :data {:name "A - Unreferenced Model - cardtype"+ :type "model"}}]+ response))))+ (testing "filtering by metric only"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=metric&query=cardtype")]+ (is (=? [{:id unreffed-metric-id+ :type "card"+ :data {:name "B - Unreferenced Metric - cardtype"+ :type "metric"}}]+ response))))+ (testing "filtering by model and metric as the default card types"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&query=cardtype")]+ (is (=? [{:id unreffed-model-id+ :type "card"+ :data {:name "A - Unreferenced Model - cardtype"+ :type "model"}}+ {:id unreffed-metric-id+ :type "card"+ :data {:name "B - Unreferenced Metric - cardtype"+ :type "metric"}}]+ response)))))))))++(deftest ^:sequential broken-questions-test+ (testing "GET /api/ee/dependencies/broken - only broken questions are returned"+ (mt/with-premium-features #{:dependencies}+ (let [mp (mt/metadata-provider)+ products (lib.metadata/table mp (mt/id :products))]+ (mt/with-temp [:model/Card _ {:name "Good Card - brokentest"+ :type :question+ :dataset_query (lib/query mp products)}+ :model/Card {broken-card-id :id} {:name "Broken Card - brokentest"+ :type :question+ :dataset_query (lib/native-query mp "not a query")}]+ (while (> (dependencies.findings/analyze-batch! :card 50) 0))+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=brokentest")]+ (is (=? [{:id broken-card-id+ :type "card"+ :data {:name "Broken Card - brokentest"}}]+ response))))))))++(deftest ^:sequential broken-transforms-test+ (testing "GET /api/ee/dependencies/broken - only broken transforms are returned"+ (mt/with-premium-features #{:dependencies}+ (let [mp (mt/metadata-provider)+ products (lib.metadata/table mp (mt/id :products))]+ (mt/with-temp [:model/Transform {broken-transform-id :id} {:name "Broken Transform - brokentest"+ :source {:type :query+ :query (lib/native-query mp "not a query")}+ :target {:schema "PUBLIC"+ :name "broken_transform_table"}}+ :model/Transform _ {:name "Good Transform - brokentest"+ :source {:type :query+ :query (lib/query mp products)}+ :target {:schema "PUBLIC"+ :name "referenced_transform_table"}}]+ (while (> (dependencies.findings/analyze-batch! :transform 50) 0))+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=transform&query=brokentest")]+ (is (=? [{:id broken-transform-id+ :type "transform"+ :data {:name "Broken Transform - brokentest"}}]+ response))))))))++(deftest ^:sequential broken-card-types-test+ (testing "GET /api/ee/dependencies/broken - broken models and metrics are filtered by card_types and pagination"+ (mt/with-premium-features #{:dependencies}+ (let [mp (mt/metadata-provider)]+ (mt/with-temp [:model/Card {broken-model-id :id} {:name "A - Broken Model - cardtype"+ :type :model+ :dataset_query (lib/native-query mp "not a query")}+ :model/Card {broken-metric-id :id} {:name "B - Broken Metric - cardtype"+ :type :metric+ :dataset_query (lib/native-query mp "not a query")}]+ (while (> (dependencies.findings/analyze-batch! :card 50) 0))+ (testing "filtering by model only"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=model&query=cardtype")]+ (is (=? [{:id broken-model-id+ :type "card"+ :data {:name "A - Broken Model - cardtype"+ :type "model"}}]+ response))))+ (testing "filtering by metric only"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=metric&query=cardtype")]+ (is (=? [{:id broken-metric-id+ :type "card"+ :data {:name "B - Broken Metric - cardtype"+ :type "metric"}}]+ response))))+ (testing "filtering by model and metric as the default card types"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=cardtype")]+ (is (=? [{:id broken-model-id+ :type "card"+ :data {:name "A - Broken Model - cardtype"+ :type "model"}}+ {:id broken-metric-id+ :type "card"+ :data {:name "B - Broken Metric - cardtype"+ :type "metric"}}]+ response)))))))))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/core_test.cljindex b35b656231a..d08c7d5b835 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj@@ -121,7 +121,6 @@:sql-base (lib.metadata/card mp 7):sql-transform transform2:sql-transform-output tf2-output- :sql-transform-cols (m/index-by :name tf2-cols):sql-transform-mbql-consumer (lib.metadata/card mp 303):sql-transform-sql-consumer (lib.metadata/card mp 304)}))@@ -133,7 +132,6 @@(deftest ^:parallel basic-mbql-card-test(testing "when changing an MBQL card with dependents"(let [{:keys [provider graph mbql-base]- {tax-rate "Tax Rate"} :mbql-transform-cols{downstream-card-id :id} :mbql-dependent{transformed-card-id :id} :mbql-transform-consumer} (testbed)](testing "a column that no longer exists will cause errors when referenced"@@ -144,8 +142,8 @@lib/update-options assoc :lib/expression-name "Sales Taxes")(dissoc :result-metadata))errors (dependencies/errors-from-proposed-edits provider graph {:card [card']})]- (is (=? {:card {downstream-card-id [[:field {} "Tax Rate"]]- transformed-card-id [[:field {} (:id tax-rate)]]}}+ (is (=? {:card {downstream-card-id #{(lib/missing-column-error "Tax Rate")}+ transformed-card-id #{(lib/missing-column-error "Tax Rate")}}}errors))(is (= [:card] (keys errors)))(is (= #{downstream-card-id transformed-card-id} (set (keys (:card errors)))))))@@ -158,7 +156,7 @@(deftest ^:parallel sql-snippet->card->transform->cards-test(testing "changing a snippet correctly finds downstream errors"- (let [{:keys [provider graph sql-transform snippet-inner sql-transform-cols]+ (let [{:keys [provider graph sql-transform snippet-inner]{direct-sql-card-id :id} :sql-base{transformed-sql-card-id :id} :sql-transform-sql-consumer{transformed-mbql-card-id :id} :sql-transform-mbql-consumer} (testbed)]@@ -166,20 +164,13 @@(let [snippet' (assoc snippet-inner:content "nonexistent_table":template-tags {})- rating (get sql-transform-cols "RATING")errors (dependencies/errors-from-proposed-edits provider graph {:snippet [snippet']})];; That breaks (1) the SQL card which uses the snippets, (2) the transforms, (3) both the MBQL and (4) SQL;; queries that consume the transform's table.- (is (=? {:card {direct-sql-card-id [{:table {:table "NONEXISTENT_TABLE"},- :type :all-columns,- :metabase.driver.sql/bad-reference true}]- transformed-sql-card-id [{:table {:schema "TRANSFORMED", :table "OUTPUT_TF31"},- :type :all-columns,- :metabase.driver.sql/bad-reference true}]- transformed-mbql-card-id [[:field {} (:id rating)]]}- :transform {(:id sql-transform) [{:table {:table "NONEXISTENT_TABLE"},- :type :all-columns,- :metabase.driver.sql/bad-reference true}]}}+ (is (=? {:card {direct-sql-card-id #{(lib/missing-table-alias-error "NONEXISTENT_TABLE")}+ transformed-sql-card-id #{(lib/missing-table-alias-error "TRANSFORMED.OUTPUT_TF31")}+ transformed-mbql-card-id #{(lib/missing-column-error "RATING")}}+ :transform {(:id sql-transform) #{(lib/missing-table-alias-error "NONEXISTENT_TABLE")}}}errors))(is (= #{:card :transform}(set (keys errors))))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/events_test.cljindex 57fe7ac7d69..866e31df9c5 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj@@ -2,587 +2,884 @@(:require[clojure.test :refer [deftest is testing]][metabase-enterprise.dependencies.calculation :as deps.calculation]+ [metabase-enterprise.dependencies.events]+ [metabase-enterprise.dependencies.findings :as deps.findings]+ [metabase-enterprise.dependencies.models.analysis-finding :as models.analysis-finding][metabase-enterprise.dependencies.models.dependency :as models.dependency][metabase.api.common :as api][metabase.events.core :as events]+ [metabase.lib-be.core :as lib-be][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata][metabase.test :as mt][metabase.util.log.capture :as log.capture][toucan2.core :as t2]))-(deftest dashboard-update-sets-correct-dependencies+(comment+ metabase-enterprise.dependencies.events/keep-me)++(defn- run-with-dependencies-setup [thunk](mt/with-test-user :rasta- (let [mp (mt/metadata-provider)- products-id (mt/id :products)- orders-id (mt/id :orders)- products (lib.metadata/table mp products-id)- orders (lib.metadata/table mp orders-id)- category-field (lib.metadata/field mp (mt/id :products :category))]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Card {basic-card-id :id} {:dataset_query (lib/query mp products)}- :model/Card {series-card-id :id} {:dataset_query (lib/query mp orders)}- :model/Card {param-source-card-id :id} {:dataset_query (-> (lib/query mp products)- (lib/aggregate (lib/count))- (lib/breakout category-field))}- :model/Dashboard {dashboard-id :id :as dashboard} {:parameters [{:id "category-param"- :type "category"- :values_source_type "card"- :values_source_config {:card_id param-source-card-id}}]}- :model/DashboardCard {basic-dashcard-id :id} {:dashboard_id dashboard-id- :card_id basic-card-id}- :model/DashboardCardSeries _ {:dashboardcard_id basic-dashcard-id- :card_id series-card-id- :position 0}]- (events/publish-event! :event/dashboard-create {:object dashboard :user-id api/*current-user-id*})- (is (=? #{{:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :card- :to_entity_id basic-card-id}- {:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :card- :to_entity_id series-card-id}- {:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :card- :to_entity_id param-source-card-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard)))))- (t2/delete! :model/DashboardCard :id basic-dashcard-id)- (t2/update! :model/Dashboard dashboard-id {:parameters []})- (mt/with-temp [:model/Card {scalar-card-id :id} {:dataset_query (-> (lib/query mp products)- (lib/aggregate (lib/count)))- :display :scalar}- :model/Card {scalar-click-target-card-id :id} {:dataset_query (lib/query mp products)}- :model/DashboardCard _ {:dashboard_id dashboard-id- :card_id scalar-card-id- :visualization_settings {:click_behavior {:type "link"- :linkType "question"- :targetId scalar-click-target-card-id}}}- :model/Card {scalar-card-2-id :id} {:dataset_query (-> (lib/query mp orders)- (lib/aggregate (lib/count)))- :display :scalar}- :model/Dashboard {scalar-click-target-dashboard-id :id} {}- :model/DashboardCard _ {:dashboard_id dashboard-id- :card_id scalar-card-2-id- :visualization_settings {:click_behavior {:type "link"- :linkType "dashboard"- :targetId scalar-click-target-dashboard-id}}}- :model/Card {table-card-id :id} {:dataset_query (-> (lib/query mp products)- (lib/breakout category-field)+ (mt/with-premium-features #{:dependencies}+ (lib-be/with-metadata-provider-cache+ (let [mp (mt/metadata-provider)]+ (thunk mp))))))++(deftest dashboard-update-sets-correct-dependencies+ (run-with-dependencies-setup+ (fn [mp]+ (let [products-id (mt/id :products)+ orders-id (mt/id :orders)+ products (lib.metadata/table mp products-id)+ orders (lib.metadata/table mp orders-id)+ category-field (lib.metadata/field mp (mt/id :products :category))]+ (mt/with-temp [:model/Card {basic-card-id :id} {:dataset_query (lib/query mp products)}+ :model/Card {series-card-id :id} {:dataset_query (lib/query mp orders)}+ :model/Card {param-source-card-id :id} {:dataset_query (-> (lib/query mp products)+ (lib/aggregate (lib/count))+ (lib/breakout category-field))}+ :model/Dashboard {dashboard-id :id :as dashboard} {:parameters [{:id "category-param"+ :type "category"+ :values_source_type "card"+ :values_source_config {:card_id param-source-card-id}}]}+ :model/DashboardCard {basic-dashcard-id :id} {:dashboard_id dashboard-id+ :card_id basic-card-id}+ :model/DashboardCardSeries _ {:dashboardcard_id basic-dashcard-id+ :card_id series-card-id+ :position 0}]+ (events/publish-event! :event/dashboard-create {:object dashboard :user-id api/*current-user-id*})+ (is (=? #{{:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :card+ :to_entity_id basic-card-id}+ {:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :card+ :to_entity_id series-card-id}+ {:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :card+ :to_entity_id param-source-card-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard)))))+ (t2/delete! :model/DashboardCard :id basic-dashcard-id)+ (t2/update! :model/Dashboard dashboard-id {:parameters []})+ (mt/with-temp [:model/Card {scalar-card-id :id} {:dataset_query (-> (lib/query mp products)(lib/aggregate (lib/count)))- :display :table}- :model/Card {column-click-target-card-id :id} {:dataset_query (lib/query mp products)}- :model/DashboardCard _ {:dashboard_id dashboard-id- :card_id table-card-id- :visualization_settings {:column_settings {"[\"name\",\"CATEGORY\"]" {:click_behavior {:type "link"- :linkType "question"- :targetId column-click-target-card-id}}}}}- :model/Dashboard {column-click-target-dashboard-id :id} {}- :model/Card {table-card-2-id :id} {:dataset_query (-> (lib/query mp orders)- (lib/breakout category-field)+ :display :scalar}+ :model/Card {scalar-click-target-card-id :id} {:dataset_query (lib/query mp products)}+ :model/DashboardCard _ {:dashboard_id dashboard-id+ :card_id scalar-card-id+ :visualization_settings {:click_behavior {:type "link"+ :linkType "question"+ :targetId scalar-click-target-card-id}}}+ :model/Card {scalar-card-2-id :id} {:dataset_query (-> (lib/query mp orders)(lib/aggregate (lib/count)))- :display :table}- :model/DashboardCard _ {:dashboard_id dashboard-id- :card_id table-card-2-id- :visualization_settings {:column_settings {"[\"name\",\"CATEGORY\"]" {:click_behavior {:type "link"- :linkType "dashboard"- :targetId column-click-target-dashboard-id}}}}}]- (let [updated-dashboard (t2/select-one :model/Dashboard :id dashboard-id)]- (events/publish-event! :event/dashboard-update {:object updated-dashboard :user-id api/*current-user-id*})- (is (=? #{{:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :card- :to_entity_id scalar-card-id}- {:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :card- :to_entity_id scalar-click-target-card-id}- {:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :card- :to_entity_id scalar-card-2-id}- {:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :dashboard- :to_entity_id scalar-click-target-dashboard-id}- {:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :card- :to_entity_id table-card-id}- {:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :card- :to_entity_id column-click-target-card-id}- {:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :card- :to_entity_id table-card-2-id}- {:from_entity_type :dashboard- :from_entity_id dashboard-id- :to_entity_type :dashboard- :to_entity_id column-click-target-dashboard-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard)))))- (t2/delete! :model/Dashboard dashboard-id)- (events/publish-event! :event/dashboard-delete {:object updated-dashboard :user-id api/*current-user-id*})- (is (empty? (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard))))))))))+ :display :scalar}+ :model/Dashboard {scalar-click-target-dashboard-id :id} {}+ :model/DashboardCard _ {:dashboard_id dashboard-id+ :card_id scalar-card-2-id+ :visualization_settings {:click_behavior {:type "link"+ :linkType "dashboard"+ :targetId scalar-click-target-dashboard-id}}}+ :model/Card {table-card-id :id} {:dataset_query (-> (lib/query mp products)+ (lib/breakout category-field)+ (lib/aggregate (lib/count)))+ :display :table}+ :model/Card {column-click-target-card-id :id} {:dataset_query (lib/query mp products)}+ :model/DashboardCard _ {:dashboard_id dashboard-id+ :card_id table-card-id+ :visualization_settings {:column_settings {"[\"name\",\"CATEGORY\"]" {:click_behavior {:type "link"+ :linkType "question"+ :targetId column-click-target-card-id}}}}}+ :model/Dashboard {column-click-target-dashboard-id :id} {}+ :model/Card {table-card-2-id :id} {:dataset_query (-> (lib/query mp orders)+ (lib/breakout category-field)+ (lib/aggregate (lib/count)))+ :display :table}+ :model/DashboardCard _ {:dashboard_id dashboard-id+ :card_id table-card-2-id+ :visualization_settings {:column_settings {"[\"name\",\"CATEGORY\"]" {:click_behavior {:type "link"+ :linkType "dashboard"+ :targetId column-click-target-dashboard-id}}}}}]+ (let [updated-dashboard (t2/select-one :model/Dashboard :id dashboard-id)]+ (events/publish-event! :event/dashboard-update {:object updated-dashboard :user-id api/*current-user-id*})+ (is (=? #{{:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :card+ :to_entity_id scalar-card-id}+ {:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :card+ :to_entity_id scalar-click-target-card-id}+ {:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :card+ :to_entity_id scalar-card-2-id}+ {:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :dashboard+ :to_entity_id scalar-click-target-dashboard-id}+ {:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :card+ :to_entity_id table-card-id}+ {:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :card+ :to_entity_id column-click-target-card-id}+ {:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :card+ :to_entity_id table-card-2-id}+ {:from_entity_type :dashboard+ :from_entity_id dashboard-id+ :to_entity_type :dashboard+ :to_entity_id column-click-target-dashboard-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard)))))+ (t2/delete! :model/Dashboard dashboard-id)+ (events/publish-event! :event/dashboard-delete {:object updated-dashboard :user-id api/*current-user-id*})+ (is (empty? (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard))))))))))(deftest document-update-sets-correct-dependencies- (mt/with-test-user :rasta- (let [mp (mt/metadata-provider)- products-id (mt/id :products)- products (lib.metadata/table mp products-id)]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/query mp products)}- :model/Card {embedded-card-id :id} {:dataset_query (lib/query mp products)}- :model/Dashboard {dashboard-id :id} {}- :model/Document {document-id :id :as document} {:content_type "application/json+vnd.prose-mirror"- :document {:type "doc"- :content [{:type "paragraph"- :content [{:type "smartLink"- :attrs {:entityId card-id- :model "card"}}]}- {:type "cardEmbed"- :attrs {:id embedded-card-id}}]}}]- (events/publish-event! :event/document-create {:object document :user-id api/*current-user-id*})- (is (=? #{{:from_entity_type :document- :from_entity_id document-id- :to_entity_type :card- :to_entity_id card-id}- {:from_entity_type :document- :from_entity_id document-id- :to_entity_type :card- :to_entity_id embedded-card-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document)))))- (let [updated-doc (assoc document :document {:type "doc"- :content [{:type "paragraph"- :content [{:type "smartLink"- :attrs {:entityId dashboard-id- :model "dashboard"}}- {:type "smartLink"- :attrs {:entityId products-id- :model "table"}}]}]})]- (t2/update! :model/Document document-id updated-doc)- (events/publish-event! :event/document-update {:object updated-doc :user-id api/*current-user-id*})- (is (=? #{{:from_entity_type :document- :from_entity_id document-id- :to_entity_type :dashboard- :to_entity_id dashboard-id}- {:from_entity_type :document- :from_entity_id document-id- :to_entity_type :table- :to_entity_id products-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document)))))- (t2/delete! :model/Document document-id)- (events/publish-event! :event/document-delete {:object document :user-id api/*current-user-id*})- (is (empty? (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document)))))))))+ (run-with-dependencies-setup+ (fn [mp]+ (let [products-id (mt/id :products)+ products (lib.metadata/table mp products-id)]+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/query mp products)}+ :model/Card {embedded-card-id :id} {:dataset_query (lib/query mp products)}+ :model/Dashboard {dashboard-id :id} {}+ :model/Document {document-id :id :as document} {:content_type "application/json+vnd.prose-mirror"+ :document {:type "doc"+ :content [{:type "paragraph"+ :content [{:type "smartLink"+ :attrs {:entityId card-id+ :model "card"}}]}+ {:type "cardEmbed"+ :attrs {:id embedded-card-id}}]}}]+ (events/publish-event! :event/document-create {:object document :user-id api/*current-user-id*})+ (is (=? #{{:from_entity_type :document+ :from_entity_id document-id+ :to_entity_type :card+ :to_entity_id card-id}+ {:from_entity_type :document+ :from_entity_id document-id+ :to_entity_type :card+ :to_entity_id embedded-card-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document)))))+ (let [updated-doc (assoc document :document {:type "doc"+ :content [{:type "paragraph"+ :content [{:type "smartLink"+ :attrs {:entityId dashboard-id+ :model "dashboard"}}+ {:type "smartLink"+ :attrs {:entityId products-id+ :model "table"}}]}]})]+ (t2/update! :model/Document document-id updated-doc)+ (events/publish-event! :event/document-update {:object updated-doc :user-id api/*current-user-id*})+ (is (=? #{{:from_entity_type :document+ :from_entity_id document-id+ :to_entity_type :dashboard+ :to_entity_id dashboard-id}+ {:from_entity_type :document+ :from_entity_id document-id+ :to_entity_type :table+ :to_entity_id products-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document)))))+ (t2/delete! :model/Document document-id)+ (events/publish-event! :event/document-delete {:object document :user-id api/*current-user-id*})+ (is (empty? (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document))))))))))(deftest sandbox-update-sets-correct-dependencies(mt/with-premium-features #{:sandboxes}- (mt/with-test-user :rasta- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/PermissionsGroup {group-id :id} {:name "sandbox group"}- :model/Card {card1-id :id} {}- :model/Card {card2-id :id} {}- :model/Sandbox {sandbox-id :id :as sandbox} {:group_id group-id- :table_id (mt/id :products)- :card_id card1-id}]- (events/publish-event! :event/sandbox-create {:object sandbox :user-id api/*current-user-id*})- (is (=? #{{:from_entity_type :sandbox- :from_entity_id sandbox-id- :to_entity_type :card- :to_entity_id card1-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox)))))- (t2/update! :model/Sandbox sandbox-id (assoc sandbox :card_id card2-id))- (let [updated-sandbox (t2/select-one :model/Sandbox :id sandbox-id)]- (events/publish-event! :event/sandbox-update {:object updated-sandbox :user-id api/*current-user-id*})- (is (=? #{{:from_entity_type :sandbox- :from_entity_id sandbox-id- :to_entity_type :card- :to_entity_id card2-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox)))))- (t2/delete! :model/Sandbox sandbox-id)- (events/publish-event! :event/sandbox-delete {:object sandbox :user-id api/*current-user-id*})- (is (empty? (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox)))))))))+ (run-with-dependencies-setup+ (fn [_]+ (mt/with-temp [:model/PermissionsGroup {group-id :id} {:name "sandbox group"}+ :model/Card {card1-id :id} {}+ :model/Card {card2-id :id} {}+ :model/Sandbox {sandbox-id :id :as sandbox} {:group_id group-id+ :table_id (mt/id :products)+ :card_id card1-id}]+ (events/publish-event! :event/sandbox-create {:object sandbox :user-id api/*current-user-id*})+ (is (=? #{{:from_entity_type :sandbox+ :from_entity_id sandbox-id+ :to_entity_type :card+ :to_entity_id card1-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox)))))+ (t2/update! :model/Sandbox sandbox-id (assoc sandbox :card_id card2-id))+ (let [updated-sandbox (t2/select-one :model/Sandbox :id sandbox-id)]+ (events/publish-event! :event/sandbox-update {:object updated-sandbox :user-id api/*current-user-id*})+ (is (=? #{{:from_entity_type :sandbox+ :from_entity_id sandbox-id+ :to_entity_type :card+ :to_entity_id card2-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox)))))+ (t2/delete! :model/Sandbox sandbox-id)+ (events/publish-event! :event/sandbox-delete {:object sandbox :user-id api/*current-user-id*})+ (is (empty? (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox)))))))))(deftest card-dependency-calculation-error-handling-test(testing "When dependency calculation throws an error, it should be logged and the version should still be updated"- (mt/with-test-user :rasta- (let [mp (mt/metadata-provider)- products-id (mt/id :products)- products (lib.metadata/table mp products-id)]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Card {card-id :id :as card} {:dataset_query (lib/query mp products)}]- (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]- (with-redefs [deps.calculation/upstream-deps:card (fn [_]- (throw (ex-info "Dependency calculation failed"- {:card-id card-id})))]- (testing "on create event"- (events/publish-event! :event/card-create {:object card :user-id api/*current-user-id*})- (is (some #(and (= "Dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Card :id card-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id card-id :from_entity_type :card))))- (testing "on update event"- (events/publish-event! :event/card-update {:object card :user-id api/*current-user-id*})- (is (some #(and (= "Dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Card :id card-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id card-id :from_entity_type :card))))))))))))+ (run-with-dependencies-setup+ (fn [mp]+ (let [products-id (mt/id :products)+ products (lib.metadata/table mp products-id)]+ (mt/with-temp [:model/Card {card-id :id :as card} {:dataset_query (lib/query mp products)}]+ (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]+ (with-redefs [deps.calculation/upstream-deps:card (fn [_]+ (throw (ex-info "Dependency calculation failed"+ {:card-id card-id})))]+ (testing "on create event"+ (events/publish-event! :event/card-create {:object card :user-id api/*current-user-id*})+ (is (some #(and (= "Dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Card :id card-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id card-id :from_entity_type :card))))+ (testing "on update event"+ (events/publish-event! :event/card-update {:object card :user-id api/*current-user-id*})+ (is (some #(and (= "Dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Card :id card-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id card-id :from_entity_type :card))))))))))))(deftest snippet-dependency-calculation-error-handling-test(testing "When snippet dependency calculation throws an error, it should be logged and the version should still be updated"- (mt/with-test-user :rasta- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/NativeQuerySnippet {snippet-id :id :as snippet} {:name "test snippet"- :content "SELECT 1"}]- (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]- (with-redefs [deps.calculation/upstream-deps:snippet (fn [_]- (throw (ex-info "Snippet dependency calculation failed"- {:snippet-id snippet-id})))]- (testing "on create event"- (events/publish-event! :event/snippet-create {:object snippet :user-id api/*current-user-id*})- (is (some #(and (= "Snippet dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/NativeQuerySnippet :id snippet-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id snippet-id :from_entity_type :snippet))))- (testing "on update event"- (events/publish-event! :event/snippet-update {:object snippet :user-id api/*current-user-id*})- (is (some #(and (= "Snippet dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/NativeQuerySnippet :id snippet-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id snippet-id :from_entity_type :snippet)))))))))))+ (run-with-dependencies-setup+ (fn [_]+ (mt/with-temp [:model/NativeQuerySnippet {snippet-id :id :as snippet} {:name "test snippet"+ :content "SELECT 1"}]+ (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]+ (with-redefs [deps.calculation/upstream-deps:snippet (fn [_]+ (throw (ex-info "Snippet dependency calculation failed"+ {:snippet-id snippet-id})))]+ (testing "on create event"+ (events/publish-event! :event/snippet-create {:object snippet :user-id api/*current-user-id*})+ (is (some #(and (= "Snippet dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/NativeQuerySnippet :id snippet-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id snippet-id :from_entity_type :snippet))))+ (testing "on update event"+ (events/publish-event! :event/snippet-update {:object snippet :user-id api/*current-user-id*})+ (is (some #(and (= "Snippet dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/NativeQuerySnippet :id snippet-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id snippet-id :from_entity_type :snippet)))))))))))(deftest transform-dependency-calculation-error-handling-test(testing "When transform dependency calculation throws an error, it should be logged and the version should still be updated"- (mt/with-test-user :rasta- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Transform {transform-id :id :as transform} {}]- (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]- (with-redefs [deps.calculation/upstream-deps:transform (fn [_]- (throw (ex-info "Transform dependency calculation failed"- {:transform-id transform-id})))]- (testing "on create event"- (events/publish-event! :event/create-transform {:object transform :user-id api/*current-user-id*})- (is (some #(and (= "Transform dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Transform :id transform-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id transform-id :from_entity_type :transform))))- (testing "on update event"- (events/publish-event! :event/update-transform {:object transform :user-id api/*current-user-id*})- (is (some #(and (= "Transform dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Transform :id transform-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id transform-id :from_entity_type :transform)))))))))))+ (run-with-dependencies-setup+ (fn [_]+ (mt/with-temp [:model/Transform {transform-id :id :as transform} {}]+ (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]+ (with-redefs [deps.calculation/upstream-deps:transform (fn [_]+ (throw (ex-info "Transform dependency calculation failed"+ {:transform-id transform-id})))]+ (testing "on create event"+ (events/publish-event! :event/create-transform {:object transform :user-id api/*current-user-id*})+ (is (some #(and (= "Transform dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Transform :id transform-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id transform-id :from_entity_type :transform))))+ (testing "on update event"+ (events/publish-event! :event/update-transform {:object transform :user-id api/*current-user-id*})+ (is (some #(and (= "Transform dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Transform :id transform-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id transform-id :from_entity_type :transform)))))))))))(deftest dashboard-dependency-calculation-error-handling-test(testing "When dashboard dependency calculation throws an error, it should be logged and the version should still be updated"- (mt/with-test-user :rasta- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Dashboard {dashboard-id :id :as dashboard} {}]- (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]- (with-redefs [deps.calculation/upstream-deps:dashboard (fn [_]- (throw (ex-info "Dashboard dependency calculation failed"- {:dashboard-id dashboard-id})))]- (testing "on create event"- (events/publish-event! :event/dashboard-create {:object dashboard :user-id api/*current-user-id*})- (is (some #(and (= "Dashboard dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Dashboard :id dashboard-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard))))- (testing "on update event"- (events/publish-event! :event/dashboard-update {:object dashboard :user-id api/*current-user-id*})- (is (some #(and (= "Dashboard dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Dashboard :id dashboard-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard)))))))))))+ (run-with-dependencies-setup+ (fn [_]+ (mt/with-temp [:model/Dashboard {dashboard-id :id :as dashboard} {}]+ (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]+ (with-redefs [deps.calculation/upstream-deps:dashboard (fn [_]+ (throw (ex-info "Dashboard dependency calculation failed"+ {:dashboard-id dashboard-id})))]+ (testing "on create event"+ (events/publish-event! :event/dashboard-create {:object dashboard :user-id api/*current-user-id*})+ (is (some #(and (= "Dashboard dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Dashboard :id dashboard-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard))))+ (testing "on update event"+ (events/publish-event! :event/dashboard-update {:object dashboard :user-id api/*current-user-id*})+ (is (some #(and (= "Dashboard dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Dashboard :id dashboard-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id dashboard-id :from_entity_type :dashboard)))))))))))(deftest document-dependency-calculation-error-handling-test(testing "When document dependency calculation throws an error, it should be logged and the version should still be updated"- (mt/with-test-user :rasta- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Document {document-id :id :as document} {:content_type "application/json+vnd.prose-mirror"- :document {:type "doc" :content []}}]- (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]- (with-redefs [deps.calculation/upstream-deps:document (fn [_]- (throw (ex-info "Document dependency calculation failed"- {:document-id document-id})))]- (testing "on create event"- (events/publish-event! :event/document-create {:object document :user-id api/*current-user-id*})- (is (some #(and (= "Document dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Document :id document-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document))))- (testing "on update event"- (events/publish-event! :event/document-update {:object document :user-id api/*current-user-id*})- (is (some #(and (= "Document dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Document :id document-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document)))))))))))+ (run-with-dependencies-setup+ (fn [_]+ (mt/with-temp [:model/Document {document-id :id :as document} {:content_type "application/json+vnd.prose-mirror"+ :document {:type "doc" :content []}}]+ (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]+ (with-redefs [deps.calculation/upstream-deps:document (fn [_]+ (throw (ex-info "Document dependency calculation failed"+ {:document-id document-id})))]+ (testing "on create event"+ (events/publish-event! :event/document-create {:object document :user-id api/*current-user-id*})+ (is (some #(and (= "Document dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Document :id document-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document))))+ (testing "on update event"+ (events/publish-event! :event/document-update {:object document :user-id api/*current-user-id*})+ (is (some #(and (= "Document dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Document :id document-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id document-id :from_entity_type :document)))))))))))(deftest sandbox-dependency-calculation-error-handling-test(testing "When sandbox dependency calculation throws an error, it should be logged and the version should still be updated"(mt/with-premium-features #{:sandboxes}- (mt/with-test-user :rasta- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/PermissionsGroup {group-id :id} {:name "test group"}- :model/Card {card-id :id} {}- :model/Sandbox {sandbox-id :id :as sandbox} {:group_id group-id- :table_id (mt/id :products)- :card_id card-id}]- (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]- (with-redefs [deps.calculation/upstream-deps:sandbox (fn [_]- (throw (ex-info "Sandbox dependency calculation failed"- {:sandbox-id sandbox-id})))]- (testing "on create event"- (events/publish-event! :event/sandbox-create {:object sandbox :user-id api/*current-user-id*})- (is (some #(and (= "Sandbox dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Sandbox :id sandbox-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox))))- (testing "on update event"- (events/publish-event! :event/sandbox-update {:object sandbox :user-id api/*current-user-id*})- (is (some #(and (= "Sandbox dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Sandbox :id sandbox-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox))))))))))))+ (run-with-dependencies-setup+ (fn [_]+ (mt/with-temp [:model/PermissionsGroup {group-id :id} {:name "test group"}+ :model/Card {card-id :id} {}+ :model/Sandbox {sandbox-id :id :as sandbox} {:group_id group-id+ :table_id (mt/id :products)+ :card_id card-id}]+ (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]+ (with-redefs [deps.calculation/upstream-deps:sandbox (fn [_]+ (throw (ex-info "Sandbox dependency calculation failed"+ {:sandbox-id sandbox-id})))]+ (testing "on create event"+ (events/publish-event! :event/sandbox-create {:object sandbox :user-id api/*current-user-id*})+ (is (some #(and (= "Sandbox dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Sandbox :id sandbox-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox))))+ (testing "on update event"+ (events/publish-event! :event/sandbox-update {:object sandbox :user-id api/*current-user-id*})+ (is (some #(and (= "Sandbox dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Sandbox :id sandbox-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id sandbox-id :from_entity_type :sandbox))))))))))))(deftest segment-update-sets-correct-dependencies- (mt/with-test-user :rasta- (let [products-id (mt/id :products)- price-field-id (mt/id :products :price)- category-field-id (mt/id :products :category)]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Segment {segment-id :id :as segment} {:table_id products-id- :definition {:filter [:> [:field price-field-id nil] 50]}}]- (testing "creating a segment creates dependency to its table"- (events/publish-event! :event/segment-create {:object segment :user-id api/*current-user-id*})- (is (= #{{:from_entity_type :segment- :from_entity_id segment-id- :to_entity_type :table- :to_entity_id products-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment))))))- (testing "updating segment definition recalculates dependencies"- (t2/update! :model/Segment segment-id {:definition {:filter [:= [:field category-field-id nil] "Widget"]}})- (let [updated-segment (t2/select-one :model/Segment :id segment-id)]- (events/publish-event! :event/segment-update {:object updated-segment :user-id api/*current-user-id*})- (is (= #{{:from_entity_type :segment- :from_entity_id segment-id- :to_entity_type :table- :to_entity_id products-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment)))))))- (testing "deleting segment removes all dependencies"- (t2/delete! :model/Segment segment-id)- (events/publish-event! :event/segment-delete {:object segment :user-id api/*current-user-id*})- (is (empty? (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment)))))))))+ (run-with-dependencies-setup+ (fn [_]+ (let [products-id (mt/id :products)+ price-field-id (mt/id :products :price)+ category-field-id (mt/id :products :category)]+ (mt/with-temp [:model/Segment {segment-id :id :as segment} {:table_id products-id+ :definition {:filter [:> [:field price-field-id nil] 50]}}]+ (testing "creating a segment creates dependency to its table"+ (events/publish-event! :event/segment-create {:object segment :user-id api/*current-user-id*})+ (is (= #{{:from_entity_type :segment+ :from_entity_id segment-id+ :to_entity_type :table+ :to_entity_id products-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment))))))+ (testing "updating segment definition recalculates dependencies"+ (t2/update! :model/Segment segment-id {:definition {:filter [:= [:field category-field-id nil] "Widget"]}})+ (let [updated-segment (t2/select-one :model/Segment :id segment-id)]+ (events/publish-event! :event/segment-update {:object updated-segment :user-id api/*current-user-id*})+ (is (= #{{:from_entity_type :segment+ :from_entity_id segment-id+ :to_entity_type :table+ :to_entity_id products-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment)))))))+ (testing "deleting segment removes all dependencies"+ (t2/delete! :model/Segment segment-id)+ (events/publish-event! :event/segment-delete {:object segment :user-id api/*current-user-id*})+ (is (empty? (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment)))))))))(deftest card-with-segment-dependencies- (mt/with-test-user :rasta- (let [products-id (mt/id :products)- price-field-id (mt/id :products :price)]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Segment {segment-id :id :as segment} {:table_id products-id- :definition {:filter [:> [:field price-field-id nil] 50]}}]- (testing "creating a card using a segment creates dependencies to both segment and table"- (events/publish-event! :event/segment-create {:object segment :user-id api/*current-user-id*})- (mt/with-temp [:model/Card {card-id :id :as card} {:dataset_query {:database (mt/id)- :type :query- :query {:source-table products-id- :filter [:segment segment-id]}}}]- (events/publish-event! :event/card-create {:object card :user-id api/*current-user-id*})- (is (= #{{:from_entity_type :card- :from_entity_id card-id- :to_entity_type :segment- :to_entity_id segment-id}- {:from_entity_type :card- :from_entity_id card-id- :to_entity_type :table- :to_entity_id products-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id card-id :from_entity_type :card))))))))))))+ (run-with-dependencies-setup+ (fn [_]+ (let [products-id (mt/id :products)+ price-field-id (mt/id :products :price)]+ (mt/with-temp [:model/Segment {segment-id :id :as segment} {:table_id products-id+ :definition {:filter [:> [:field price-field-id nil] 50]}}]+ (testing "creating a card using a segment creates dependencies to both segment and table"+ (events/publish-event! :event/segment-create {:object segment :user-id api/*current-user-id*})+ (mt/with-temp [:model/Card {card-id :id :as card} {:dataset_query {:database (mt/id)+ :type :query+ :query {:source-table products-id+ :filter [:segment segment-id]}}}]+ (events/publish-event! :event/card-create {:object card :user-id api/*current-user-id*})+ (is (= #{{:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :segment+ :to_entity_id segment-id}+ {:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :table+ :to_entity_id products-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id card-id :from_entity_type :card))))))))))))(deftest segment-dependency-calculation-error-handling-test(testing "When segment dependency calculation throws an error, it should be logged and the version should still be updated"- (mt/with-test-user :rasta- (let [products-id (mt/id :products)- price-field-id (mt/id :products :price)]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Segment {segment-id :id :as segment} {:table_id products-id- :definition {:filter [:> [:field price-field-id nil] 50]}}]- (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]- (with-redefs [deps.calculation/upstream-deps:segment (fn [_]- (throw (ex-info "Segment dependency calculation failed"- {:segment-id segment-id})))]- (testing "on create event"- (events/publish-event! :event/segment-create {:object segment :user-id api/*current-user-id*})- (is (some #(and (= "Segment dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Segment :id segment-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment))))- (testing "on update event"- (events/publish-event! :event/segment-update {:object segment :user-id api/*current-user-id*})- (is (some #(and (= "Segment dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Segment :id segment-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment))))))))))))+ (run-with-dependencies-setup+ (fn [_]+ (let [products-id (mt/id :products)+ price-field-id (mt/id :products :price)]+ (mt/with-temp [:model/Segment {segment-id :id :as segment} {:table_id products-id+ :definition {:filter [:> [:field price-field-id nil] 50]}}]+ (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]+ (with-redefs [deps.calculation/upstream-deps:segment (fn [_]+ (throw (ex-info "Segment dependency calculation failed"+ {:segment-id segment-id})))]+ (testing "on create event"+ (events/publish-event! :event/segment-create {:object segment :user-id api/*current-user-id*})+ (is (some #(and (= "Segment dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Segment :id segment-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment))))+ (testing "on update event"+ (events/publish-event! :event/segment-update {:object segment :user-id api/*current-user-id*})+ (is (some #(and (= "Segment dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Segment :id segment-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id segment-id :from_entity_type :segment))))))))))))(deftest measure-update-sets-correct-dependencies- (mt/with-test-user :rasta- (let [mp (mt/metadata-provider)- orders-id (mt/id :orders)- orders (lib.metadata/table mp orders-id)- quantity (lib.metadata/field mp (mt/id :orders :quantity))- subtotal (lib.metadata/field mp (mt/id :orders :subtotal))]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Measure {measure-id :id :as measure} {:table_id orders-id- :definition (-> (lib/query mp orders)- (lib/aggregate (lib/sum quantity)))}]- (testing "creating a measure creates dependency to its table"- (events/publish-event! :event/measure-create {:object measure :user-id api/*current-user-id*})- (is (= #{{:from_entity_type :measure- :from_entity_id measure-id- :to_entity_type :table- :to_entity_id orders-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))))- (testing "updating measure definition recalculates dependencies"- (t2/update! :model/Measure measure-id {:definition (-> (lib/query mp orders)- (lib/aggregate (lib/sum subtotal)))})- (let [updated-measure (t2/select-one :model/Measure :id measure-id)]- (events/publish-event! :event/measure-update {:object updated-measure :user-id api/*current-user-id*})- (is (= #{{:from_entity_type :measure- :from_entity_id measure-id- :to_entity_type :table- :to_entity_id orders-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure)))))))- (testing "deleting measure removes all dependencies"- (t2/delete! :model/Measure measure-id)- (events/publish-event! :event/measure-delete {:object measure :user-id api/*current-user-id*})- (is (empty? (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure)))))))))+ (run-with-dependencies-setup+ (fn [mp]+ (mt/with-test-user :rasta+ (let [orders-id (mt/id :orders)+ orders (lib.metadata/table mp orders-id)+ quantity (lib.metadata/field mp (mt/id :orders :quantity))+ subtotal (lib.metadata/field mp (mt/id :orders :subtotal))]+ (mt/with-temp [:model/Measure {measure-id :id :as measure} {:table_id orders-id+ :definition (-> (lib/query mp orders)+ (lib/aggregate (lib/sum quantity)))}]+ (testing "creating a measure creates dependency to its table"+ (events/publish-event! :event/measure-create {:object measure :user-id api/*current-user-id*})+ (is (= #{{:from_entity_type :measure+ :from_entity_id measure-id+ :to_entity_type :table+ :to_entity_id orders-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))))+ (testing "updating measure definition recalculates dependencies"+ (t2/update! :model/Measure measure-id {:definition (-> (lib/query mp orders)+ (lib/aggregate (lib/sum subtotal)))})+ (let [updated-measure (t2/select-one :model/Measure :id measure-id)]+ (events/publish-event! :event/measure-update {:object updated-measure :user-id api/*current-user-id*})+ (is (= #{{:from_entity_type :measure+ :from_entity_id measure-id+ :to_entity_type :table+ :to_entity_id orders-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure)))))))+ (testing "deleting measure removes all dependencies"+ (t2/delete! :model/Measure measure-id)+ (events/publish-event! :event/measure-delete {:object measure :user-id api/*current-user-id*})+ (is (empty? (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))))))))(deftest measure-with-measure-dependencies- (mt/with-test-user :rasta- (let [mp (mt/metadata-provider)- orders-id (mt/id :orders)- orders (lib.metadata/table mp orders-id)- quantity (lib.metadata/field mp (mt/id :orders :quantity))- subtotal (lib.metadata/field mp (mt/id :orders :subtotal))]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Measure {measure1-id :id :as measure1} {:table_id orders-id- :definition (-> (lib/query mp orders)- (lib/aggregate (lib/sum quantity)))}]- (let [mp' (mt/metadata-provider)]- (mt/with-temp [:model/Measure {measure2-id :id :as measure2} {:table_id orders-id- :definition (-> (lib/query mp' orders)- (lib/aggregate (lib/+ (lib.metadata/measure mp' measure1-id)- (lib/sum subtotal))))}]- (testing "creating a measure that references another measure creates dependencies to both"- (events/publish-event! :event/measure-create {:object measure1 :user-id api/*current-user-id*})- (events/publish-event! :event/measure-create {:object measure2 :user-id api/*current-user-id*})- (is (= #{{:from_entity_type :measure- :from_entity_id measure2-id- :to_entity_type :table- :to_entity_id orders-id}- {:from_entity_type :measure- :from_entity_id measure2-id- :to_entity_type :measure- :to_entity_id measure1-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id measure2-id :from_entity_type :measure)))))))))))))+ (run-with-dependencies-setup+ (fn [mp]+ (let [orders-id (mt/id :orders)+ orders (lib.metadata/table mp orders-id)+ quantity (lib.metadata/field mp (mt/id :orders :quantity))+ subtotal (lib.metadata/field mp (mt/id :orders :subtotal))]+ (mt/with-temp [:model/Measure {measure1-id :id :as measure1} {:table_id orders-id+ :definition (-> (lib/query mp orders)+ (lib/aggregate (lib/sum quantity)))}]+ (let [mp' (mt/metadata-provider)]+ (mt/with-temp [:model/Measure {measure2-id :id :as measure2} {:table_id orders-id+ :definition (-> (lib/query mp' orders)+ (lib/aggregate (lib/+ (lib.metadata/measure mp' measure1-id)+ (lib/sum subtotal))))}]+ (testing "creating a measure that references another measure creates dependencies to both"+ (events/publish-event! :event/measure-create {:object measure1 :user-id api/*current-user-id*})+ (events/publish-event! :event/measure-create {:object measure2 :user-id api/*current-user-id*})+ (is (= #{{:from_entity_type :measure+ :from_entity_id measure2-id+ :to_entity_type :table+ :to_entity_id orders-id}+ {:from_entity_type :measure+ :from_entity_id measure2-id+ :to_entity_type :measure+ :to_entity_id measure1-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id measure2-id :from_entity_type :measure)))))))))))))(deftest card-with-measure-dependencies- (mt/with-test-user :rasta- (let [mp (mt/metadata-provider)- orders-id (mt/id :orders)- orders (lib.metadata/table mp orders-id)- quantity (lib.metadata/field mp (mt/id :orders :quantity))]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Measure {measure-id :id :as measure} {:table_id orders-id- :definition (-> (lib/query mp orders)- (lib/aggregate (lib/sum quantity)))}]- (events/publish-event! :event/measure-create {:object measure :user-id api/*current-user-id*})- (testing "creating a card using a measure creates dependencies to both measure and table"- (let [mp' (mt/metadata-provider)- query (-> (lib/query mp' orders)- (lib/aggregate (lib.metadata/measure mp' measure-id)))]- (mt/with-temp [:model/Card {card-id :id :as card} {:dataset_query query}]- (events/publish-event! :event/card-create {:object card :user-id api/*current-user-id*})- (is (= #{{:from_entity_type :card- :from_entity_id card-id- :to_entity_type :measure- :to_entity_id measure-id}- {:from_entity_type :card- :from_entity_id card-id- :to_entity_type :table- :to_entity_id orders-id}}- (into #{} (map #(dissoc % :id)- (t2/select :model/Dependency :from_entity_id card-id :from_entity_type :card)))))))))))))+ (run-with-dependencies-setup+ (fn [mp]+ (let [orders-id (mt/id :orders)+ orders (lib.metadata/table mp orders-id)+ quantity (lib.metadata/field mp (mt/id :orders :quantity))]+ (mt/with-temp [:model/Measure {measure-id :id :as measure} {:table_id orders-id+ :definition (-> (lib/query mp orders)+ (lib/aggregate (lib/sum quantity)))}]+ (events/publish-event! :event/measure-create {:object measure :user-id api/*current-user-id*})+ (testing "creating a card using a measure creates dependencies to both measure and table"+ (let [mp' (mt/metadata-provider)+ query (-> (lib/query mp' orders)+ (lib/aggregate (lib.metadata/measure mp' measure-id)))]+ (mt/with-temp [:model/Card {card-id :id :as card} {:dataset_query query}]+ (events/publish-event! :event/card-create {:object card :user-id api/*current-user-id*})+ (is (= #{{:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :measure+ :to_entity_id measure-id}+ {:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :table+ :to_entity_id orders-id}}+ (into #{} (map #(dissoc % :id)+ (t2/select :model/Dependency :from_entity_id card-id :from_entity_type :card)))))))))))))(deftest measure-dependency-calculation-error-handling-test(testing "When measure dependency calculation throws an error, it should be logged and the version should still be updated"- (mt/with-test-user :rasta- (let [mp (mt/metadata-provider)- orders-id (mt/id :orders)- orders (lib.metadata/table mp orders-id)- quantity (lib.metadata/field mp (mt/id :orders :quantity))]- (mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/Measure {measure-id :id :as measure} {:table_id orders-id- :definition (-> (lib/query mp orders)- (lib/aggregate (lib/sum quantity)))}]- (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]- (with-redefs [deps.calculation/upstream-deps:measure (fn [_]- (throw (ex-info "Measure dependency calculation failed"- {:measure-id measure-id})))]- (testing "on create event"- (events/publish-event! :event/measure-create {:object measure :user-id api/*current-user-id*})- (is (some #(and (= "Measure dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Measure :id measure-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))- (testing "on update event"- (events/publish-event! :event/measure-update {:object measure :user-id api/*current-user-id*})- (is (some #(and (= "Measure dependency calculation failed" (ex-message (:e %)))- (= :error (:level %)))- (messages)))- (is (= models.dependency/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Measure :id measure-id)))- (is (empty? (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))))))))))+ (run-with-dependencies-setup+ (fn [mp]+ (let [orders-id (mt/id :orders)+ orders (lib.metadata/table mp orders-id)+ quantity (lib.metadata/field mp (mt/id :orders :quantity))]+ (mt/with-temp [:model/Measure {measure-id :id :as measure} {:table_id orders-id+ :definition (-> (lib/query mp orders)+ (lib/aggregate (lib/sum quantity)))}]+ (log.capture/with-log-messages-for-level [messages ["metabase-enterprise.dependencies.events" :error]]+ (with-redefs [deps.calculation/upstream-deps:measure (fn [_]+ (throw (ex-info "Measure dependency calculation failed"+ {:measure-id measure-id})))]+ (testing "on create event"+ (events/publish-event! :event/measure-create {:object measure :user-id api/*current-user-id*})+ (is (some #(and (= "Measure dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Measure :id measure-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))+ (testing "on update event"+ (events/publish-event! :event/measure-update {:object measure :user-id api/*current-user-id*})+ (is (some #(and (= "Measure dependency calculation failed" (ex-message (:e %)))+ (= :error (:level %)))+ (messages)))+ (is (= models.dependency/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Measure :id measure-id)))+ (is (empty? (t2/select :model/Dependency :from_entity_id measure-id :from_entity_type :measure))))))))))))++(defn- assert-has-analyses+ "Asserts that a given set of entities have the appropriate analysis version.++ Format is `{entity-type {entity-id analysis-version}}`.++ Use -1 for analysis-version if you want to check that an analysis exists without asserting a specific version."+ [spec]+ (doseq [[entity-type ids-and-versions] spec]+ (let [analyses-map (->> (t2/select [:model/AnalysisFinding :analyzed_entity_id :analysis_version])+ (into {} (map (juxt :analyzed_entity_id :analysis_version))))]+ (doseq [[id expected-version] ids-and-versions]+ (testing (str "Checking " entity-type " " id)+ (if (= expected-version -1)+ (is (contains? analyses-map id))+ (is (= expected-version (analyses-map id)))))))))++(deftest ^:sequential card-update-works-with-no-analyses-test+ (run-with-dependencies-setup+ (fn [mp]+ (testing "Card updates should publish new analyses when no existing ones exist"+ (let [products-id (mt/id :products)+ products (lib.metadata/table mp products-id)]+ (mt/with-temp [:model/Card {parent-card-id :id :as parent-card} {:dataset_query (lib/query mp products)}+ :model/Card {child-card-id :id} {:dataset_query (lib/query mp (lib.metadata/card mp parent-card-id))}+ :model/Dependency _ {:from_entity_type :card+ :from_entity_id child-card-id+ :to_entity_type :card+ :to_entity_id parent-card-id}]+ (events/publish-event! :event/card-update {:object parent-card :user-id api/*current-user-id*})+ (assert-has-analyses+ {:card {parent-card-id -1+ child-card-id -1}})))))))++(deftest ^:sequential card-update-updates-analyses-test+ (run-with-dependencies-setup+ (fn [mp]+ (testing "Card updates should update existing analyses when they exist"+ (let [products-id (mt/id :products)+ orders-id (mt/id :orders)+ products (lib.metadata/table mp products-id)+ orders (lib.metadata/table mp orders-id)+ old-version models.analysis-finding/*current-analysis-finding-version*+ new-version (inc models.analysis-finding/*current-analysis-finding-version*)]+ (mt/with-temp [:model/Card {parent-card-id :id :as parent-card} {:dataset_query (lib/query mp products)}+ :model/Card {child-card-id :id :as child-card} {:dataset_query (lib/query mp (lib.metadata/card mp parent-card-id))}+ :model/Card {other-card-id :id :as other-card} {:dataset_query (lib/query mp orders)}+ :model/Dependency _ {:from_entity_type :card+ :from_entity_id child-card-id+ :to_entity_type :card+ :to_entity_id parent-card-id}]+ (deps.findings/upsert-analysis! parent-card)+ (deps.findings/upsert-analysis! child-card)+ (deps.findings/upsert-analysis! other-card)+ (testing "Checking that the initial analyses exist"+ (assert-has-analyses+ {:card {parent-card-id old-version+ child-card-id old-version+ other-card-id old-version}}))+ (binding [models.analysis-finding/*current-analysis-finding-version* new-version]+ (events/publish-event! :event/card-update {:object parent-card :user-id api/*current-user-id*}))+ (testing "Checking that the analyses were updated appropriately"+ (assert-has-analyses+ {:card {parent-card-id new-version+ child-card-id new-version+ other-card-id old-version}}))))))))++(deftest ^:sequential card-update-stops-on-transforms-test+ (run-with-dependencies-setup+ (fn [mp]+ (testing "Card updates should continue analyzing through a transform"+ (let [products-id (mt/id :products)+ orders-id (mt/id :orders)+ products (lib.metadata/table mp products-id)+ orders (lib.metadata/table mp orders-id)+ old-version models.analysis-finding/*current-analysis-finding-version*+ new-version (inc models.analysis-finding/*current-analysis-finding-version*)]+ (mt/with-temp [:model/Card {parent-card-id :id :as parent-card} {:dataset_query (lib/query mp products)}+ :model/Transform {transform-id :id :as transform} {:source {:type :query+ :query (lib/query mp products)}+ :name "transform_sample"+ :target {:schema "public"+ :name "sample"+ :type :table}}+ :model/Card {child-card-id :id :as child-card} {:dataset_query (lib/query mp orders)}+ :model/Dependency _ {:from_entity_type :card+ :from_entity_id child-card-id+ :to_entity_type :transform+ :to_entity_id transform-id}+ :model/Dependency _ {:from_entity_type :transform+ :from_entity_id transform-id+ :to_entity_type :card+ :to_entity_id parent-card-id}]+ (deps.findings/upsert-analysis! parent-card)+ (deps.findings/upsert-analysis! transform)+ (deps.findings/upsert-analysis! child-card)+ (testing "Checking that initial analyses exist"+ (assert-has-analyses+ {:card {parent-card-id old-version+ child-card-id old-version}+ :transform {transform-id old-version}}))+ (binding [models.analysis-finding/*current-analysis-finding-version* new-version]+ (events/publish-event! :event/card-update {:object parent-card :user-id api/*current-user-id*}))+ (testing "Checking that analyses were updated correctly"+ (assert-has-analyses+ {:card {parent-card-id new-version+ child-card-id old-version}+ :transform {transform-id new-version}}))))))))++(deftest ^:sequential transform-update-works-with-no-analyses-test+ (run-with-dependencies-setup+ (fn [mp]+ (testing "transform update creates new analyses"+ (let [products-id (mt/id :products)+ products (lib.metadata/table mp products-id)]+ (mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/query mp products)}+ :model/Transform {transform-id :id :as transform} {:source {:type :query+ :query (lib/query mp products)}+ :name "transform_sample"+ :target {:schema "public"+ :name "sample"+ :type :table}}+ :model/Dependency _ {:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :transform+ :to_entity_id transform-id}]+ (events/publish-event! :event/transform-update {:object transform :user-id api/*current-user-id*})+ (assert-has-analyses+ ;; child cards shouldn't be updated on transform update, only on run+ {:card {card-id nil}+ :transform {transform-id -1}})))))))++(deftest ^:sequential transform-update-updates-analyses-test+ (run-with-dependencies-setup+ (fn [mp]+ (testing "transform update updates analyses when they exist"+ (let [products-id (mt/id :products)+ orders-id (mt/id :orders)+ products (lib.metadata/table mp products-id)+ orders (lib.metadata/table mp orders-id)+ old-version models.analysis-finding/*current-analysis-finding-version*+ new-version (inc models.analysis-finding/*current-analysis-finding-version*)]+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/Card {card-id :id :as card} {:dataset_query (lib/query mp products)}+ :model/Transform {transform-id :id :as transform} {:source {:type :query+ :query (lib/query mp products)}+ :name "transform_sample"+ :target {:schema "public"+ :name "sample"+ :type :table}}+ :model/Card {other-card-id :id :as other-card} {:dataset_query (lib/query mp orders)}+ :model/Dependency _ {:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :transform+ :to_entity_id transform-id}]+ (deps.findings/upsert-analysis! card)+ (deps.findings/upsert-analysis! transform)+ (deps.findings/upsert-analysis! other-card)+ (testing "Checking that initial analyses exist"+ (assert-has-analyses+ {:card {card-id old-version+ other-card-id old-version}+ :transform {transform-id old-version}}))+ (binding [models.analysis-finding/*current-analysis-finding-version* new-version]+ (events/publish-event! :event/update-transform {:object transform :user-id api/*current-user-id*}))+ (testing "Checking that the correct analyses were updated"+ (assert-has-analyses+ ;; neither unrelated cards nor dependent cards should be updated on transform update+ {:card {card-id old-version+ other-card-id old-version}+ :transform {transform-id new-version}})))))))))++(deftest ^:sequential transform-run-works-with-no-analyses-test+ (run-with-dependencies-setup+ (fn [mp]+ (testing "transform runs create analyses for dependent cards"+ (let [products-id (mt/id :products)+ products (lib.metadata/table mp products-id)]+ (mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/query mp products)}+ :model/Transform {transform-id :id} {:source {:type :query+ :query (lib/query mp products)}+ :name "transform_sample"+ :target {:schema "public"+ :name "sample"+ :type :table}}+ :model/Dependency _ {:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :transform+ :to_entity_id transform-id}]+ (events/publish-event! :event/transform-run-complete+ {:object {:db-id (mt/id)+ :output-schema "public"+ :output-table "sample"+ :transform-id transform-id}+ :user-id api/*current-user-id*})+ (assert-has-analyses+ {:card {card-id -1}})))))))++(deftest ^:sequential transform-run-updates-analyses-test+ (run-with-dependencies-setup+ (fn [mp]+ (testing "transform runs update existing analyses when they exist"+ (let [products-id (mt/id :products)+ orders-id (mt/id :orders)+ products (lib.metadata/table mp products-id)+ orders (lib.metadata/table mp orders-id)+ old-version models.analysis-finding/*current-analysis-finding-version*+ new-version (inc models.analysis-finding/*current-analysis-finding-version*)]+ (mt/with-temp [:model/Card {card-id :id :as card} {:dataset_query (lib/query mp products)}+ :model/Transform {transform-id :id :as transform} {:source {:type :query+ :query (lib/query mp products)}+ :name "transform_sample"+ :target {:schema "public"+ :name "sample"+ :type :table}}+ :model/Card {other-card-id :id :as other-card} {:dataset_query (lib/query mp orders)}+ :model/Dependency _ {:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :transform+ :to_entity_id transform-id}]+ (deps.findings/upsert-analysis! card)+ (deps.findings/upsert-analysis! transform)+ (deps.findings/upsert-analysis! other-card)+ (testing "checking that initial analyses exist"+ (assert-has-analyses+ {:card {card-id old-version+ other-card-id old-version}+ :transform {transform-id old-version}}))+ (binding [models.analysis-finding/*current-analysis-finding-version* (inc models.analysis-finding/*current-analysis-finding-version*)]+ (events/publish-event! :event/transform-run-complete+ {:object {:db-id (mt/id)+ :output-schema "public"+ :output-table "sample"+ :transform-id transform-id}+ :user-id api/*current-user-id*}))+ (testing "checking that analyses were updated appropriately"+ (assert-has-analyses+ {:card {card-id new-version+ other-card-id old-version}+ :transform {transform-id old-version}}))))))))++(deftest ^:sequential segment-update-works-with-no-analyses-test+ (run-with-dependencies-setup+ (fn [mp]+ (testing "segment update creates analyses when necessary"+ (let [products-id (mt/id :products)+ price-field-id (mt/id :products :price)+ products (lib.metadata/table mp products-id)]+ (mt/with-temp [:model/Segment {segment-id :id :as segment} {:table_id products-id+ :definition {:filter [:> [:field price-field-id nil] 50]}}+ :model/Card {card-id :id} {:dataset_query (lib/query mp products)}+ :model/Dependency _ {:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :segment+ :to_entity_id segment-id}]+ (events/publish-event! :event/segment-update {:object segment :user-id api/*current-user-id*})+ (assert-has-analyses+ {:card {card-id -1}+ :segment {segment-id -1}})))))))++(deftest ^:sequential segment-update-updates-analyses-test+ (run-with-dependencies-setup+ (fn [mp]+ (testing "segment update updates analyses when they exist"+ (let [products-id (mt/id :products)+ price-field-id (mt/id :products :price)+ products (lib.metadata/table mp products-id)+ old-version models.analysis-finding/*current-analysis-finding-version*+ new-version (inc models.analysis-finding/*current-analysis-finding-version*)]+ (mt/with-temp [:model/Segment {segment-id :id :as segment} {:table_id products-id+ :definition {:filter [:> [:field price-field-id nil] 50]}}+ :model/Card {card-id :id :as card} {:dataset_query (lib/query mp products)}+ :model/Dependency _ {:from_entity_type :card+ :from_entity_id card-id+ :to_entity_type :segment+ :to_entity_id segment-id}]+ (deps.findings/upsert-analysis! segment)+ (deps.findings/upsert-analysis! card)+ (testing "checking that initial analyses exist"+ (assert-has-analyses+ {:card {card-id old-version}+ :segment {segment-id old-version}}))+ (binding [models.analysis-finding/*current-analysis-finding-version* (inc models.analysis-finding/*current-analysis-finding-version*)]+ (events/publish-event! :event/segment-update {:object segment :user-id api/*current-user-id*}))+ (testing "checking that analyses were updated correctly"+ (assert-has-analyses+ {:card {card-id new-version}+ :segment {segment-id new-version}}))))))))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/findings_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/findings_test.cljnew file mode 100644index 00000000000..042e1bcad1a--- /dev/null+++ b/enterprise/backend/test/metabase_enterprise/dependencies/findings_test.clj@@ -0,0 +1,51 @@+(ns metabase-enterprise.dependencies.findings-test+ (:require+ [clojure.test :refer :all]+ [metabase-enterprise.dependencies.findings :as deps.findings]+ [metabase-enterprise.dependencies.models.analysis-finding :as models.analysis-finding]+ [metabase.lib.core :as lib]+ [metabase.lib.metadata :as lib.metadata]+ [metabase.test :as mt]+ [toucan2.core :as t2]))++(defn- backfill-all-entity-analyses! []+ (doseq [model [:card :transform :segment]]+ (while (pos? (deps.findings/analyze-batch! model 100)))))++(deftest ^:sequential can-analyze-entity-batches-test+ (backfill-all-entity-analyses!)+ (let [mp (mt/metadata-provider)+ products-id (mt/id :products)+ orders-id (mt/id :orders)+ products (lib.metadata/table mp products-id)+ orders (lib.metadata/table mp orders-id)]+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/Card {card-id :id} {:dataset_query (lib/query mp products)}+ :model/Card {other-card-id :id} {:dataset_query (lib/query mp orders)}]+ (is (= 2 (deps.findings/analyze-batch! :card 2)))+ (is (= #{models.analysis-finding/*current-analysis-finding-version*}+ (t2/select-fn-set :analysis_version+ :model/AnalysisFinding+ :analyzed_entity_id [:in [card-id other-card-id]]+ :analyzed_entity_type :card)))))))++(deftest ^:sequential does-not-repeatedly-analyze-entities-test+ (backfill-all-entity-analyses!)+ (let [mp (mt/metadata-provider)+ products-id (mt/id :products)+ orders-id (mt/id :orders)+ products (lib.metadata/table mp products-id)+ orders (lib.metadata/table mp orders-id)]+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/Card _ {:dataset_query (lib/query mp products)}+ :model/Card _ {:dataset_query (lib/query mp orders)}]+ (is (= 2 (deps.findings/analyze-batch! :card 2)))+ (is (= 0 (deps.findings/analyze-batch! :card 2)))))))++(deftest ^:sequential re-analyze-entities-when-analysis-version-bumped-test+ (backfill-all-entity-analyses!)+ (mt/with-premium-features #{:dependencies}+ (is (= 0 (deps.findings/analyze-batch! :card 2)))+ (binding [models.analysis-finding/*current-analysis-finding-version* (inc models.analysis-finding/*current-analysis-finding-version*)]+ ;; can't check the actual cards analyzed here because this could be any starting card in the data+ (is (= 2 (deps.findings/analyze-batch! :card 2))))))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/native_validation_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/native_validation_test.cljindex 224e0713e34..435a6da0622 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/native_validation_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/native_validation_test.clj@@ -66,23 +66,17 @@(let [mp (deps.tu/default-metadata-provider)driver (:engine (lib.metadata/database mp))](testing "complete nonsense query"- (is (= [{:error :metabase.driver.sql/bad-sql}]+ (is (= #{(lib/syntax-error)}(deps.native-validation/validate-native-querydriver(fake-query mp "this is not a query")))))(testing "bad table wildcard"- (is (= [{:type :invalid-table-wildcard,- :table "products",- :metabase.driver.sql/bad-reference true}]+ (is (= #{(lib/missing-table-alias-error "products")}(deps.native-validation/validate-native-querydriver(fake-query mp "select products.* from orders")))))(testing "bad col reference"- (is (= [{:column "BAD",- :alias nil,- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS"}}]],- :metabase.driver.sql/bad-reference true}]+ (is (= #{(lib/missing-column-error "BAD")}(deps.native-validation/validate-native-querydriver(fake-query mp "select bad from products"))))))))@@ -91,7 +85,7 @@(testing "can validate queries using table functions"(let [mp (deps.tu/default-metadata-provider)driver (:engine (lib.metadata/database mp))]- (is (= []+ (is (= #{}(deps.native-validation/validate-native-querydriver(fake-query mp "select i from my_function(1, 100)")))))))@@ -104,59 +98,15 @@(testing "Valid query - selecting existing columns from subquery"(validates? mp driver 10 empty?))(testing "Invalid query - selecting non-existent column from subquery"- (validates? mp driver 11 [{:column "CATEGORY",- :alias nil,- :type :single-column,- :source-columns [[{:column "ID",- :alias nil,- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PEOPLE"}}]]}- {:column "NAME",- :alias nil,- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PEOPLE"}}]]}]],- :metabase.driver.sql/bad-reference true}])- (validates? mp driver 12 [{:column "CATEGORY",- :alias nil,- :type :single-column,- :source-columns [[{:column "ID",- :alias nil,- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PEOPLE"}}]]}- {:column "NAME",- :alias nil,- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PEOPLE"}}]]}]],- :metabase.driver.sql/bad-reference true}]))+ (validates? mp driver 11 #{(lib/missing-column-error "CATEGORY")})+ (validates? mp driver 12 #{(lib/missing-column-error "CATEGORY")}))(testing "Nested subqueries"(validates? mp driver 13 empty?)- (validates? mp driver 14 [{:column "CATEGORY",- :alias nil,- :type :single-column,- :source-columns [[{:column "ID",- :alias nil,- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PEOPLE"}}]]}- {:column "NAME",- :alias nil,- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PEOPLE"}}]]}]],- :metabase.driver.sql/bad-reference true}]))+ (validates? mp driver 14 #{(lib/missing-column-error "CATEGORY")}))(testing "SELECT * from subquery expands to subquery columns"(validates? mp driver 15 empty?)(validates? mp driver 16 empty?)- (validates? mp driver 17 [{:column "EMAIL",- :alias nil,- :type :single-column,- :source-columns [[{:column "ID",- :alias nil,- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PEOPLE"}}]]}- {:column "NAME",- :alias nil,- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PEOPLE"}}]]}]],- :metabase.driver.sql/bad-reference true}])))))+ (validates? mp driver 17 #{(lib/missing-column-error "EMAIL")})))))(deftest ^:parallel validate-card-reference-after-expansion-test(testing "Validation of queries after card references have been expanded"@@ -166,123 +116,17 @@(validates? mp driver 18 empty?))(testing "Card reference expanded to subquery - invalid column"(validates? mp driver 19- [{:column "DESCRIPTION",- :alias nil,- :type :single-column,- :source-columns- [[{:column "ID",- :alias "ID",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "EAN",- :alias "EAN",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "TITLE",- :alias "TITLE",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "CATEGORY",- :alias "CATEGORY",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "VENDOR",- :alias "VENDOR",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "PRICE",- :alias "PRICE",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "RATING",- :alias "RATING",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "CREATED_AT",- :alias "CREATED_AT",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}]],- :metabase.driver.sql/bad-reference true}]))+ #{(lib/missing-column-error "DESCRIPTION")}))(testing "Card reference with alias - valid column"(validates? mp driver 20 empty?))(testing "Card reference with alias - invalid column"(validates? mp driver 21- [{:column "PASSWORD",- :alias nil,- :type :single-column,- :source-columns [[{:column "ID",- :alias "ID",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "EAN",- :alias "EAN",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "TITLE",- :alias "TITLE",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "CATEGORY",- :alias "CATEGORY",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "VENDOR",- :alias "VENDOR",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "PRICE",- :alias "PRICE",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "RATING",- :alias "RATING",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "CREATED_AT",- :alias "CREATED_AT",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}]]- :metabase.driver.sql/bad-reference true}]))+ #{(lib/missing-column-error "PASSWORD")}))(testing "Wildcard selection from card reference"(validates? mp driver 22 empty?))(testing "Invalid column from aliased card"(validates? mp driver 23- [{:column "LATITUDE",- :alias nil,- :type :single-column,- :source-columns [[{:column "ID",- :alias "ID",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "EAN",- :alias "EAN",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "TITLE",- :alias "TITLE",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "CATEGORY",- :alias "CATEGORY",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "VENDOR",- :alias "VENDOR",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "PRICE",- :alias "PRICE",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "RATING",- :alias "RATING",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}- {:column "CREATED_AT",- :alias "CREATED_AT",- :type :single-column,- :source-columns [[{:type :all-columns, :table {:table "PRODUCTS", :schema "PUBLIC"}}]]}]],- :metabase.driver.sql/bad-reference true}])))))+ #{(lib/missing-column-error "LATITUDE")})))))(defn- check-result-metadata [driver mp query expected](is (=? expected@@ -347,6 +191,16 @@:base-type :type/Float,:effective-type :type/Float,:semantic-type :Semantic/*}]))+ (testing "Selecting a union of custom fields"+ (check-result-metadata+ driver mp+ "select 1 as TOTAL union select 2"+ [{:name "TOTAL",+ :lib/desired-column-alias "TOTAL",+ :display-name "Total",+ :base-type :type/*,+ :effective-type :type/*,+ :semantic-type :Semantic/*}]))(testing "Selecting a union with different types"(check-result-metadatadriver mpdiff --git a/enterprise/backend/test/metabase_enterprise/dependencies/task/backfill_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/task/backfill_test.cljindex dce5eaed7f6..86d3c6fd975 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/task/backfill_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/task/backfill_test.clj@@ -5,6 +5,7 @@[java-time.api :as t][metabase-enterprise.dependencies.models.dependency :as dependencies.model][metabase-enterprise.dependencies.task.backfill :as dependencies.backfill]+ [metabase.events.core :as events][metabase.task.core :as task][metabase.test :as mt][metabase.test.fixtures :as fixtures]@@ -247,5 +248,33 @@dep-version-after (t2/select-one-fn :dependency_analysis_version :model/Card :id card-id)deps-after (t2/count :model/Dependency :from_entity_type :card :from_entity_id card-id)](is (= 0 revision-count-after))- (is (= 3 dep-version-after))+ (is (= dependencies.model/current-dependency-analysis-version dep-version-after))(is (= 1 deps-after))))))))++(deftest ^:sequential backfill-dependencies-on-serdes-load-test+ (testing "Test that serdes load correctly updates the dependency_analysis_version"+ (backfill-all-existing-entities!)+ (let [query (mt/mbql-query orders)]+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/Card {card1-id :id} {:dependency_analysis_version 0, :dataset_query query}+ :model/Card {card2-id :id} {:dependency_analysis_version 0, :dataset_query query}+ :model/Card {card3-id :id} {:dependency_analysis_version 0, :dataset_query query}]+ (let [card-count (fn [& args]+ (apply t2/count :model/Card :id [:in [card1-id card2-id card3-id]] args))+ current-version dependencies.model/current-dependency-analysis-version]+ (events/publish-event! :event/serdes-load {})+ (is (= 3 (card-count :dependency_analysis_version current-version)))))))))++(deftest ^:sequential backfill-dependencies-on-token-update-test+ (testing "Test that token update correctly updates the dependency_analysis_version"+ (backfill-all-existing-entities!)+ (let [query (mt/mbql-query orders)]+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/Card {card1-id :id} {:dependency_analysis_version 0, :dataset_query query}+ :model/Card {card2-id :id} {:dependency_analysis_version 0, :dataset_query query}+ :model/Card {card3-id :id} {:dependency_analysis_version 0, :dataset_query query}]+ (let [card-count (fn [& args]+ (apply t2/count :model/Card :id [:in [card1-id card2-id card3-id]] args))+ current-version dependencies.model/current-dependency-analysis-version]+ (events/publish-event! :event/set-premium-embedding-token {})+ (is (= 3 (card-count :dependency_analysis_version current-version)))))))))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/test_util.clj b/enterprise/backend/test/metabase_enterprise/dependencies/test_util.cljindex 57bd8f407b7..ef87562760b 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/test_util.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/test_util.clj@@ -44,12 +44,12 @@(let [snippets (map mock-snippet[{:id 1:name "inner"- :content "{{#card-ref}}"- :template-tags {"#card-ref" {:card-id 1- :type :card- :name "#card-ref"- :display-name "#Card Ref"- :id (str (random-uuid))}}}+ :content "{{#1-card-ref}}"+ :template-tags {"#1-card-ref" {:card-id 1+ :type :card+ :name "#1-card-ref"+ :display-name "#1-Card Ref"+ :id (str (random-uuid))}}}{:id 2:name "outer":content "{{snippet: inner}}"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.cljindex 80f895e0f62..5f9c8724f57 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@@ -32,7 +32,8 @@- not exported in serialization; or- exported as a child of something else (eg. timeline_event under timeline)so they don't need a generated entity_id."- #{:model/ApiKey+ #{:model/AnalysisFinding+ :model/ApiKey:model/AuthIdentity:model/HTTPAction:model/ImplicitActiondiff --git a/enterprise/frontend/src/metabase-enterprise/api/dependencies.ts b/enterprise/frontend/src/metabase-enterprise/api/dependencies.tsindex f594d5897a1..e3d5d0e8a3c 100644--- a/enterprise/frontend/src/metabase-enterprise/api/dependencies.ts+++ b/enterprise/frontend/src/metabase-enterprise/api/dependencies.ts@@ -6,7 +6,9 @@ import type {DependencyGraph,DependencyNode,GetDependencyGraphRequest,+ ListBrokenGraphNodesRequest,ListNodeDependentsRequest,+ ListUnreferencedGraphNodesRequest,} from "metabase-types/api";import { EnterpriseApi } from "./api";@@ -40,6 +42,30 @@ export const dependencyApi = EnterpriseApi.injectEndpoints({providesTags: (nodes) =>nodes ? provideDependencyNodeListTags(nodes) : [],}),+ listBrokenGraphNodes: builder.query<+ DependencyNode[],+ ListBrokenGraphNodesRequest+ >({+ query: (params) => ({+ method: "GET",+ url: "/api/ee/dependencies/graph/broken",+ params,+ }),+ providesTags: (nodes) =>+ nodes ? provideDependencyNodeListTags(nodes) : [],+ }),+ listUnreferencedGraphNodes: builder.query<+ DependencyNode[],+ ListUnreferencedGraphNodesRequest+ >({+ query: (params) => ({+ method: "GET",+ url: "/api/ee/dependencies/graph/unreferenced",+ params,+ }),+ providesTags: (nodes) =>+ nodes ? provideDependencyNodeListTags(nodes) : [],+ }),checkCardDependencies: builder.query<CheckDependenciesResponse,CheckCardDependenciesRequest@@ -76,6 +102,8 @@ export const dependencyApi = EnterpriseApi.injectEndpoints({export const {useGetDependencyGraphQuery,useListNodeDependentsQuery,+ useListBrokenGraphNodesQuery,+ useListUnreferencedGraphNodesQuery,useLazyCheckCardDependenciesQuery,useLazyCheckSnippetDependenciesQuery,useLazyCheckTransformDependenciesQuery,diff --git a/enterprise/frontend/src/metabase-enterprise/api/tags.ts b/enterprise/frontend/src/metabase-enterprise/api/tags.tsindex 114ce6161ba..45b1434d3ba 100644--- a/enterprise/frontend/src/metabase-enterprise/api/tags.ts+++ b/enterprise/frontend/src/metabase-enterprise/api/tags.ts@@ -9,26 +9,27 @@ import {provideTableTags,provideUserTags,} from "metabase/api/tags";-import type {- BulkTableInfo,- BulkTableSelectionInfo,- CardDependencyNode,- DashboardDependencyNode,- DependencyGraph,- DependencyNode,- DocumentDependencyNode,- MeasureDependencyNode,- PythonLibrary,- SandboxDependencyNode,- SegmentDependencyNode,- SnippetDependencyNode,- SupportAccessGrant,- TableDependencyNode,- Transform,- TransformDependencyNode,- TransformJob,- TransformRun,- TransformTag,+import {+ type BulkTableInfo,+ type BulkTableSelectionInfo,+ type CardDependencyNode,+ DEPENDENCY_TYPES,+ type DashboardDependencyNode,+ type DependencyGraph,+ type DependencyNode,+ type DocumentDependencyNode,+ type MeasureDependencyNode,+ type PythonLibrary,+ type SandboxDependencyNode,+ type SegmentDependencyNode,+ type SnippetDependencyNode,+ type SupportAccessGrant,+ type TableDependencyNode,+ type Transform,+ type TransformDependencyNode,+ type TransformJob,+ type TransformRun,+ type TransformTag,} from "metabase-types/api";export const ENTERPRISE_TAG_TYPES = [@@ -273,10 +274,7 @@ export function provideDependencyNodeTags(export function provideDependencyNodeListTags(nodes: DependencyNode[]) {return [- listTag("card"),- listTag("table"),- listTag("transform"),- listTag("snippet"),+ ...DEPENDENCY_TYPES.map(listTag),...nodes.flatMap(provideDependencyNodeTags),];}diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsxindex d9f53eb8cf7..c2beafb874a 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx@@ -146,6 +146,15 @@ function DataStudioNav({ isNavbarOpened, onNavbarToggle }: DataStudioNavProps) {showLabel={isNavbarOpened}/>)}+ {PLUGIN_DEPENDENCIES.isEnabled && (+ <DataStudioTab+ label={t`Tasks`}+ icon="list"+ to={Urls.dataStudioTasks()}+ isSelected={currentTab === "tasks"}+ showLabel={isNavbarOpened}+ />+ )}{canAccessTransforms && (<DataStudioTablabel={t`Transforms`}diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.tsindex 277e56f18cd..0106e61b083 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.ts@@ -6,6 +6,7 @@ type TabName =| "transforms"| "jobs"| "runs"+ | "tasks"| "dependencies"| "glossary";@@ -15,6 +16,8 @@ export const getCurrentTab = (pathname: string): TabName => {return "glossary";case pathname.startsWith(Urls.transformJobList()):return "jobs";+ case pathname.startsWith(Urls.dataStudioTasks()):+ return "tasks";case pathname.startsWith(Urls.dependencyGraph()):return "dependencies";case pathname.startsWith(Urls.dataStudioLibrary()):diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/TasksSectionLayout/TasksSectionLayout.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/TasksSectionLayout/TasksSectionLayout.tsxnew file mode 100644index 00000000000..84a77ea16ae--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/TasksSectionLayout/TasksSectionLayout.tsx@@ -0,0 +1,15 @@+import type { ReactNode } from "react";+import { t } from "ttag";++import { usePageTitle } from "metabase/hooks/use-page-title";++import { SectionLayout } from "../../components/SectionLayout";++type TasksSectionLayoutProps = {+ children?: ReactNode;+};++export function TasksSectionLayout({ children }: TasksSectionLayoutProps) {+ usePageTitle(t`Tasks`);+ return <SectionLayout>{children}</SectionLayout>;+}diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/TasksSectionLayout/index.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/TasksSectionLayout/index.tsnew file mode 100644index 00000000000..7a5a8f6a7d6--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/TasksSectionLayout/index.ts@@ -0,0 +1 @@+export * from "./TasksSectionLayout";diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.module.css b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.module.cssdeleted file mode 100644index e280f5f39c2..00000000000--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.module.css+++ /dev/null@@ -1,67 +0,0 @@-.row {- display: flex;- width: 100%;- border-bottom: 1px solid var(--mb-color-border);- color: var(--mb-color-text-primary);- padding-top: 0.75rem;- padding-bottom: 0.75rem;- padding-right: 1rem;- font-size: 14px;- line-height: 20px;- background: inherit;- cursor: pointer;-- &:hover {- background-color: var(--mb-color-brand-light);- }-}--.cell {- display: flex;- align-items: center;- gap: 0.5rem;-}--.table {- background: inherit;- display: grid;-}--.header {- background: inherit;- display: grid;- position: sticky;- top: 0;- z-index: 1;-- .row {- cursor: unset;- padding-left: 1rem;-- &:hover {- background-color: inherit;- }- }-}--.headerBadge {- cursor: pointer;- user-select: none;-}--.headerBadgeLabel {- text-transform: none;- font-size: 0.75rem;-}--.scrollContainer {- background: inherit;- overflow: auto;- position: relative;-}--.body {- .row:last-of-type {- border-bottom: none;- }-}diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.tsxdeleted file mode 100644index cfd54fefe42..00000000000--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.tsx+++ /dev/null@@ -1,221 +0,0 @@-import {- type ColumnDef,- type Row,- type Table,- flexRender,- getCoreRowModel,- getExpandedRowModel,- getSortedRowModel,- useReactTable,-} from "@tanstack/react-table";-import {- type VirtualItem,- type Virtualizer,- useVirtualizer,-} from "@tanstack/react-virtual";-import { type CSSProperties, type ReactNode, useState } from "react";--import { Badge, Icon } from "metabase/ui";--import S from "./Table.module.css";--const DEFAULT_ROW_HEIGHT = 47;--export const TableComponent = <- T extends Record<string, any> & { children?: T[] },->({- data,- columns,- onSelect,-}: {- data: T[];- columns: ColumnDef<T, ReactNode>[];- onSelect: (item: T) => void;-}) => {- const [scrollRef, setScrollRef] = useState<HTMLDivElement | null>(null);-- const table = useReactTable({- data,- columns,- getCoreRowModel: getCoreRowModel(),- getSortedRowModel: getSortedRowModel(),- getExpandedRowModel: getExpandedRowModel(),- getSubRows: (row) => row.children,- initialState: {- expanded: true,- },- });-- return (- <div className={S.scrollContainer} ref={(e) => setScrollRef(e)}>- {/* Even though we're still using semantic table tags, we must use CSS grid and flexbox for dynamic row heights */}- <table className={S.table}>- <thead className={S.header}>- {table.getHeaderGroups().map((headerGroup) => (- <tr key={headerGroup.id} className={S.row}>- {headerGroup.headers.map((header) => {- const headerContent = flexRender(- header.column.columnDef.header,- header.getContext(),- );- return (- <th- key={header.id}- style={{- display: "flex",- ...getColumWidthStyle(header.column.columnDef),- }}- >- {headerContent && (- <Badge- onClick={header.column.getToggleSortingHandler()}- classNames={{- root: S.headerBadge,- label: S.headerBadgeLabel,- }}- rightSection={- {- asc: <Icon name="chevronup" size={10} />,- desc: <Icon name="chevrondown" size={10} />,- }[header.column.getIsSorted() as string] ?? null- }- >- {headerContent}- </Badge>- )}- </th>- );- })}- </tr>- ))}- </thead>- {scrollRef && (- <TableBody- table={table}- tableContainerRef={scrollRef}- onSelect={onSelect}- />- )}- </table>- </div>- );-};--interface TableBodyProps<T> {- table: Table<T>;- tableContainerRef: HTMLDivElement;- onSelect: (item: T) => void;-}--function TableBody<T>({- table,- tableContainerRef,- onSelect,-}: TableBodyProps<T>) {- const { rows } = table.getRowModel();-- // Important: Keep the row virtualizer in the lowest component possible to avoid unnecessary re-renders.- const rowVirtualizer = useVirtualizer<HTMLDivElement, HTMLTableRowElement>({- count: rows.length,- estimateSize: () => DEFAULT_ROW_HEIGHT, //estimate row height for accurate scrollbar dragging- getScrollElement: () => tableContainerRef,- measureElement:- typeof window !== "undefined"- ? (element) => element?.getBoundingClientRect().height- : undefined,- overscan: 5,- });-- return (- <tbody- className={S.body}- style={{- display: "grid",- height: `${rowVirtualizer.getTotalSize()}px`, //tells scrollbar how big the table is- position: "relative", //needed for absolute positioning of rows- }}- >- {rowVirtualizer.getVirtualItems().map((virtualRow) => {- const row = rows[virtualRow.index] as Row<T>;- return (- <TableBodyRow- key={row.id}- row={row}- virtualRow={virtualRow}- rowVirtualizer={rowVirtualizer}- onSelect={onSelect}- />- );- })}- </tbody>- );-}--interface TableBodyRowProps<T> {- row: Row<T>;- virtualRow: VirtualItem;- rowVirtualizer: Virtualizer<HTMLDivElement, HTMLTableRowElement>;- onSelect: (item: T) => void;-}--function TableBodyRow<T>({- row,- virtualRow,- rowVirtualizer,- onSelect,-}: TableBodyRowProps<T>) {- const { depth } = row;-- const canExpand = row.getCanExpand();-- return (- <tr- data-index={virtualRow.index} //needed for dynamic row height measurement- ref={(node) => rowVirtualizer.measureElement(node)} //measure dynamic row height- key={row.id}- className={S.row}- style={{- position: "absolute",- transform: `translateY(${virtualRow.start}px)`, //this should always be a `style` as it changes on scroll- paddingLeft: `calc(${depth * 18}px + 1rem)`,- }}- onClick={- canExpand- ? row.getToggleExpandedHandler()- : () => onSelect?.(row.original)- }- >- {row.getVisibleCells().map((cell, index) => {- return (- <td- key={cell.id}- className={S.cell}- style={{- ...getColumWidthStyle(cell.column.columnDef),- }}- >- {canExpand && index === 0 && (- <Icon- size={10}- name={row.getIsExpanded() ? "chevrondown" : "chevronright"}- />- )}- {flexRender(cell.column.columnDef.cell, cell.getContext())}- </td>- );- })}- </tr>- );-}--const getColumWidthStyle = <T,>(column: ColumnDef<T>): CSSProperties => {- if (column.meta?.width === "auto") {- return {- flexGrow: 1,- flexBasis: 0,- };- }- return {- width: column.size,- };-};diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/index.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/index.tsdeleted file mode 100644index 973e41951f3..00000000000--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/index.ts+++ /dev/null@@ -1 +0,0 @@-export { TableComponent as Table } from "./Table";diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/Table.stories.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/Table.stories.tsxdeleted file mode 100644index 79c1c19966c..00000000000--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/Table.stories.tsx+++ /dev/null@@ -1,48 +0,0 @@-import type { ColumnDef } from "@tanstack/react-table";-import type { ReactNode } from "react";--import { Card, Group, Icon, ThemeProvider } from "metabase/ui";--import { Table } from "..";--import data from "./data.json";--const columns: ColumnDef<Record<string, any>, ReactNode>[] = [- {- accessorKey: "name",- header: "Name",- meta: { width: "auto" },- cell: ({ getValue, row }) => {- const data = row.original;- return (- <Group data-testid={`${data.model}-name`} gap="sm">- {data.icon && <Icon name={data.icon} c="brand" />}- {getValue()}- </Group>- );- },- },- {- accessorKey: "updatedAt",- header: "Updated At",- },-];--const Template = () => {- return (- <ThemeProvider>- <Card p={0} withBorder h={600} w={600}>- <Table data={data} columns={columns} onSelect={() => {}} />- </Card>- </ThemeProvider>- );-};--export default {- title: "Components/Table",- component: Table,-};--export const Default = {- render: Template,-};diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/data.json b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/data.jsondeleted file mode 100644index 2a26679d1e1..00000000000--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/data.json+++ /dev/null@@ -1,475 +0,0 @@-[- {- "name": "Data",- "id": 8,- "icon": "table",- "data": {- "authority_level": null,- "description": null,- "archived": false,- "children": [],- "slug": "data",- "archive_operation_id": null,- "can_write": true,- "name": "Data",- "is_remote_synced": false,- "personal_owner_id": null,- "type": "library-data",- "here": ["table"],- "is_sample": false,- "id": 8,- "archived_directly": null,- "entity_id": "1z7rDfL_9EEIifEZZLVtV",- "location": "/7/",- "namespace": null,- "created_at": "2025-12-08T14:53:32.380269Z",- "model": "collection"- },- "model": "collection",- "children": [- {- "name": "Action",- "icon": "table",- "data": {- "authority_level": null,- "description": "An action is something you can do, such as run a readwrite query",- "archived": false,- "collection_position": null,- "table_id": 97,- "database_id": 2,- "collection_id": 8,- "query_type": null,- "name": "Action",- "is_remote_synced": null,- "personal_owner_id": null,- "last_used_at": null,- "icon": null,- "moderated_status": null,- "dataset_query": null,- "id": 97,- "display": null,- "entity_id": null,- "is_upload": null,- "collection_preview": null,- "location": null,- "dashboard_id": null,- "model": "table"- },- "id": 97,- "model": "table"- },- {- "name": "Api Key",- "icon": "table",- "data": {- "authority_level": null,- "description": "An API Key",- "archived": false,- "collection_position": null,- "table_id": 42,- "database_id": 2,- "collection_id": 8,- "query_type": null,- "name": "Api Key",- "is_remote_synced": null,- "personal_owner_id": null,- "last_used_at": null,- "icon": null,- "moderated_status": null,- "dataset_query": null,- "id": 42,- "display": null,- "entity_id": null,- "is_upload": null,- "collection_preview": null,- "location": null,- "dashboard_id": null,- "model": "table"- },- "id": 42,- "model": "table"- },- {- "name": "Application Permissions Revision",- "icon": "table",- "data": {- "authority_level": null,- "description": null,- "archived": false,- "collection_position": null,- "table_id": 89,- "database_id": 2,- "collection_id": 8,- "query_type": null,- "name": "Application Permissions Revision",- "is_remote_synced": null,- "personal_owner_id": null,- "last_used_at": null,- "icon": null,- "moderated_status": null,- "dataset_query": null,- "id": 89,- "display": null,- "entity_id": null,- "is_upload": null,- "collection_preview": null,- "location": null,- "dashboard_id": null,- "model": "table"- },- "id": 89,- "model": "table"- },- {- "name": "Audit Log",- "icon": "table",- "data": {- "authority_level": null,- "description": "Used to store application events for auditing use cases",- "archived": false,- "collection_position": null,- "table_id": 124,- "database_id": 2,- "collection_id": 8,- "query_type": null,- "name": "Audit Log",- "is_remote_synced": null,- "personal_owner_id": null,- "last_used_at": null,- "icon": null,- "moderated_status": null,- "dataset_query": null,- "id": 124,- "display": null,- "entity_id": null,- "is_upload": null,- "collection_preview": null,- "location": null,- "dashboard_id": null,- "model": "table"- },- "id": 124,- "model": "table"- },- {- "name": "Auth Identity",- "icon": "table",- "data": {- "authority_level": null,- "description": "Stores authentication credentials for users. A user can have multiple auth identities.",- "archived": false,- "collection_position": null,- "table_id": 150,- "database_id": 2,- "collection_id": 8,- "query_type": null,- "name": "Auth Identity",- "is_remote_synced": null,- "personal_owner_id": null,- "last_used_at": null,- "icon": null,- "moderated_status": null,- "dataset_query": null,- "id": 150,- "display": null,- "entity_id": null,- "is_upload": null,- "collection_preview": null,- "location": null,- "dashboard_id": null,- "model": "table"- },- "id": 150,- "model": "table"- },- {- "name": "Bookmark Ordering",- "icon": "table",- "data": {- "authority_level": null,- "description": null,- "archived": false,- "collection_position": null,- "table_id": 26,- "database_id": 2,- "collection_id": 8,- "query_type": null,- "name": "Bookmark Ordering",- "is_remote_synced": null,- "personal_owner_id": null,- "last_used_at": null,- "icon": null,- "moderated_status": null,- "dataset_query": null,- "id": 26,- "display": null,- "entity_id": null,- "is_upload": null,- "collection_preview": null,- "location": null,- "dashboard_id": null,- "model": "table"- },- "id": 26,- "model": "table"- },- {- "name": "Cache Config",- "icon": "table",- "data": {- "authority_level": null,- "description": "Cache Configuration",- "archived": false,- "collection_position": null,- "table_id": 101,- "database_id": 2,- "collection_id": 8,- "query_type": null,- "name": "Cache Config",- "is_remote_synced": null,- "personal_owner_id": null,- "last_used_at": null,- "icon": null,- "moderated_status": null,- "dataset_query": null,- "id": 101,- "display": null,- "entity_id": null,- "is_upload": null,- "collection_preview": null,- "location": null,- "dashboard_id": null,- "model": "table"- },- "id": 101,- "model": "table"- }- ]- },- {- "name": "Metrics",- "id": 9,- "icon": "metric",- "data": {- "authority_level": null,- "description": null,- "archived": false,- "children": [],- "slug": "metrics",- "archive_operation_id": null,- "can_write": true,- "name": "Metrics",- "is_remote_synced": false,- "personal_owner_id": null,- "type": "library-metrics",- "here": ["metric"],- "is_sample": false,- "id": 9,- "archived_directly": null,- "entity_id": "7v6-Hdh0vm94n28nKiQXP",- "location": "/7/",- "namespace": null,- "created_at": "2025-12-08T14:53:32.397579Z",- "model": "collection"- },- "model": "collection",- "children": [- {- "name": "Number of Orders - Duplicate",- "updatedAt": "2025-12-08T14:54:11.762685Z",- "icon": "metric",- "data": {- "description": "Canonical metric for number of orders placed",- "archived": false,- "collection_position": 2,- "can_write": true,- "database_id": null,- "collection_id": 9,- "name": "Number of Orders - Duplicate",- "is_remote_synced": false,- "dashboard_count": 0,- "fully_parameterized": true,- "last_used_at": "2025-12-09T14:38:37.011576Z",- "dashboard": null,- "can_restore": false,- "moderated_status": null,- "id": 113,- "display": "line",- "entity_id": "GciYt6tgWa1Mmxql59wd8",- "collection_preview": true,- "last-edit-info": {- "id": 1,- "last_name": "Fitzpatrick",- "first_name": "Nicholas",- "email": "[email protected]",- "timestamp": "2025-12-08T14:54:11.762685Z"- },- "location": null,- "dashboard_id": null,- "can_delete": false,- "model": "metric"- },- "id": 113,- "model": "metric"- },- {- "name": "Revenue - Duplicate",- "updatedAt": "2025-12-08T14:54:29.023573Z",- "icon": "metric",- "data": {- "description": "Canonical metric for revenue across all product lines",- "archived": false,- "collection_position": 1,- "can_write": true,- "database_id": null,- "collection_id": 9,- "name": "Revenue - Duplicate",- "is_remote_synced": false,- "dashboard_count": 0,- "fully_parameterized": true,- "last_used_at": "2025-12-08T17:41:03.27253Z",- "dashboard": null,- "can_restore": false,- "moderated_status": null,- "id": 114,- "display": "line",- "entity_id": "rW_8izY2VcNcOl7YTi9h9",- "collection_preview": true,- "last-edit-info": {- "id": 1,- "last_name": "Fitzpatrick",- "first_name": "Nicholas",- "email": "[email protected]",- "timestamp": "2025-12-08T14:54:29.023573Z"- },- "location": null,- "dashboard_id": null,- "can_delete": false,- "model": "metric"- },- "id": 114,- "model": "metric"- }- ]- },- {- "id": "root",- "name": "SQL snippets",- "model": "collection",- "icon": "snippet",- "data": {- "authority_level": null,- "can_write": true,- "name": "Top folder",- "is_remote_synced": null,- "effective_ancestors": [],- "can_restore": false,- "effective_location": null,- "parent_id": null,- "id": "root",- "namespace": "snippets",- "is_personal": false,- "can_delete": false,- "model": "collection"- },- "children": [- {- "id": 10,- "name": "Child Folder",- "model": "collection",- "icon": "folder",- "data": {- "authority_level": null,- "description": null,- "archived": false,- "slug": "child_folder",- "archive_operation_id": null,- "can_write": true,- "name": "Child Folder",- "is_remote_synced": false,- "personal_owner_id": null,- "type": null,- "is_sample": false,- "parent_id": null,- "id": 10,- "archived_directly": null,- "entity_id": "XDsrJhm7QE5P3wRfCOqHF",- "location": "/",- "namespace": "snippets",- "is_personal": false,- "created_at": "2025-12-10T15:06:57.01592Z",- "can_delete": false,- "model": "collection"- },- "children": [- {- "id": 11,- "name": "Sub Sub Folder",- "model": "collection",- "icon": "folder",- "data": {- "authority_level": null,- "description": null,- "archived": false,- "slug": "sub_sub_folder",- "archive_operation_id": null,- "can_write": true,- "name": "Sub Sub Folder",- "is_remote_synced": false,- "personal_owner_id": null,- "type": null,- "is_sample": false,- "parent_id": 10,- "id": 11,- "archived_directly": null,- "entity_id": "-XxBiHgFNe4Kq1u3cROa-",- "location": "/10/",- "namespace": "snippets",- "is_personal": false,- "created_at": "2025-12-10T15:07:21.323663Z",- "can_delete": false,- "model": "collection"- },- "children": [- {- "id": 1,- "name": "My Snippet",- "icon": "snippet",- "model": "snippet",- "data": {- "description": null,- "archived": false,- "dependency_analysis_version": 3,- "creator": {- "email": "[email protected]",- "first_name": "Nicholas",- "last_login": "2025-12-08T14:34:17.749893Z",- "is_qbnewb": false,- "is_superuser": true,- "id": 1,- "last_name": "Fitzpatrick",- "tenant_id": null,- "date_joined": "2025-12-08T14:34:17.511001Z",- "common_name": "Nicholas Fitzpatrick"- },- "content": "order.id === 1",- "collection_id": 11,- "name": "My Snippet",- "is_remote_synced": null,- "creator_id": 1,- "updated_at": "2025-12-10T15:07:50.438363Z",- "id": 1,- "entity_id": "6dBsu95KeBRBCpV9cK7VN",- "template_tags": {},- "created_at": "2025-12-10T15:07:50.438363Z",- "model": "snippet"- },- "updatedAt": "2025-12-10T15:07:50.438363Z"- }- ]- }- ]- }- ]- }-]diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.tsdeleted file mode 100644index 7daef066be5..00000000000--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.ts+++ /dev/null@@ -1,57 +0,0 @@-import { useMemo } from "react";--export const useTreeFilter = <- T extends Record<string, any> & { children?: T[] },- K extends keyof T,->({- data,- searchQuery,- searchProps,-}: {- data: T[];- searchQuery: string | undefined;- searchProps: K[];-}): T[] => {- return useMemo(() => {- const filterLevel = (nodes: T[]): T[] => {- return nodes- .map((node) => {- if (node.children) {- const filteredChildren = filterLevel(node.children);- if (filteredChildren.length > 0) {- return { ...node, children: filteredChildren };- } else {- return null;- }- }-- // Dealing with leaf nodes-- if (- searchProps.some((s) => {- if (- typeof node[s] === "string" &&- typeof searchQuery === "string"- ) {- return node[s]- .toLowerCase()- .includes(searchQuery.toLowerCase());- }- return false;- })- ) {- return node;- }-- return null;- })- .filter((x) => !!x);- };-- if (!searchQuery) {- return data;- }-- return filterLevel(data);- }, [data, searchQuery, searchProps]);-};diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.unit.spec.tsxdeleted file mode 100644index ed5c0dbbc26..00000000000--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.unit.spec.tsx+++ /dev/null@@ -1,96 +0,0 @@-import { renderHook } from "__support__/ui";--import { useTreeFilter } from "./useTreeFilter";--type Node = {- name: string;- category: string;- children?: Node[];-};--const TEST_TREE: Node[] = [- {- name: "FOO",- category: "Doohickey",- children: [- {- name: "Hudson Borer",- category: "Doohickey",- },- {- name: "Domenica Williamson",- category: "Doohickey",- },- {- name: "Lina Heaney",- category: "Gadget",- },- {- name: "Arnold Adams",- category: "Doohickey",- },- ],- },- {- name: "BAR",- category: "Gadget",- children: [- {- name: "Rene Muller",- category: "Gadget",- },- {- name: "Roselyn Bosco",- category: "Gadget",- children: [- {- name: "Lavonne Senger",- category: "Doohickey",- },- ],- },- {- name: "Aracely Jenkins",- category: "Gadget",- },- {- name: "Anais Ward",- category: "Doohickey",- },- ],- },-];--describe("useTreeFilter", () => {- it("should filter child nodes using specified props", () => {- const {- result: { current: tree },- } = renderHook(() =>- useTreeFilter({- data: TEST_TREE,- searchProps: ["category"],- searchQuery: "gadg",- }),- );-- // This is actually asserting many things- // - Only leaf nodes are considered in search,- // - parent nodes with no filtered children should not be returned. this is why Roselyn was filtered out- // - We shouldn't change the order that of returned values- // - That search is not case sensitive-- expect(tree).toMatchObject([- {- name: "FOO",- children: [expect.objectContaining({ name: "Lina Heaney" })],- },- {- name: "BAR",- children: [- expect.objectContaining({ name: "Rene Muller" }),- expect.objectContaining({ name: "Aracely Jenkins" }),- ],- },- ]);- });-});diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/routes.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/routes.tsxindex 60f6e29f868..7581f6703f8 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/routes.tsx+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/routes.tsx@@ -14,6 +14,7 @@ import { DataSectionLayout } from "./app/pages/DataSectionLayout";import { DataStudioLayout } from "./app/pages/DataStudioLayout";import { DependenciesSectionLayout } from "./app/pages/DependenciesSectionLayout";import { LibrarySectionLayout } from "./app/pages/LibrarySectionLayout";+import { TasksSectionLayout } from "./app/pages/TasksSectionLayout";import { TransformsSectionLayout } from "./app/pages/TransformsSectionLayout";import { getDataStudioMetadataRoutes } from "./data-model/routes";import { getDataStudioGlossaryRoutes } from "./glossary/routes";@@ -56,6 +57,11 @@ export function getDataStudioRoutes({getDataStudioSegmentRoutes()}{getDataStudioSnippetRoutes()}</Route>+ {PLUGIN_DEPENDENCIES.isEnabled && (+ <Route path="tasks" component={TasksSectionLayout}>+ {PLUGIN_DEPENDENCIES.getDataStudioTasksRoutes()}+ </Route>+ )}{PLUGIN_DEPENDENCIES.isEnabled && (<Route path="dependencies" component={DependenciesSectionLayout}>{PLUGIN_DEPENDENCIES.getDataStudioDependencyRoutes()}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsxindex e48c45565e9..400cb0445fe 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx@@ -57,6 +57,7 @@ export function DependencyGraph({isFetching,error,} = useGetDependencyGraphQuery(entry ?? skipToken);+const [nodes, setNodes, onNodesChange] = useNodesState<NodeType>([]);const [edges, setEdges, onEdgesChange] = useEdgesState<Edge>([]);const [selection, setSelection] = useState<GraphSelection | null>(null);@@ -87,7 +88,7 @@ export function DependencyGraph({useEffect(() => {if (error != null) {- sendErrorToast(t`Failed to load dependencies`);+ sendErrorToast(t`Failed to load the dependency graph`);}}, [error, sendErrorToast]);diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphBreadcrumbs/GraphBreadcrumbs.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphBreadcrumbs/GraphBreadcrumbs.tsxindex 246b3d50ba1..e76ff602201 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphBreadcrumbs/GraphBreadcrumbs.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphBreadcrumbs/GraphBreadcrumbs.tsx@@ -3,32 +3,29 @@ import { Link } from "react-router";import { Box, Group, type GroupProps } from "metabase/ui";-import type { NodeLink } from "../types";+import type { NodeLink } from "../../../types";import S from "./GraphBreadcrumbs.module.css";type GraphBreadcrumbsProps = GroupProps & {- location: NodeLink[];+ links: NodeLink[];};-export function GraphBreadcrumbs({- location,- ...props-}: GraphBreadcrumbsProps) {+export function GraphBreadcrumbs({ links, ...props }: GraphBreadcrumbsProps) {return (<Group c="text-secondary" gap="sm" wrap="nowrap" {...props}><Group fz="sm" gap="xs">- {location.map((part, partIndex) => (- <Fragment key={partIndex}>- {partIndex > 0 && <Box>/</Box>}+ {links.map((link, linkIndex) => (+ <Fragment key={linkIndex}>+ {linkIndex > 0 && <Box>/</Box>}<BoxclassName={S.link}component={Link}- to={part.url}+ to={link.url}target="_blank"lh="1rem">- {part.label}+ {link.label}</Box></Fragment>))}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsxindex 9ad0f0ae553..fd977eb5f9b 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx@@ -3,9 +3,6 @@ import { memo } from "react";import { Box, Group, Stack } from "metabase/ui";import type { DependencyEntry, DependencyNode } from "metabase-types/api";-import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";-import { GraphExternalLink } from "../../GraphExternalLink";-import { GraphLink } from "../../GraphLink";import {getNodeIcon,getNodeId,@@ -13,7 +10,10 @@ import {getNodeLink,getNodeLocationInfo,getNodeViewCount,-} from "../../utils";+} from "../../../../utils";+import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";+import { GraphExternalLink } from "../../GraphExternalLink";+import { GraphLink } from "../../GraphLink";import S from "./PanelBody.module.css";import { getNodeViewCountLabel } from "./utils";@@ -73,7 +73,7 @@ function ListItem({ node, getGraphUrl }: ListItemProps) {wrap="nowrap">{location != null && (- <GraphBreadcrumbs location={location} ml="1rem" pl="sm" />+ <GraphBreadcrumbs links={location.links} ml="1rem" pl="sm" />)}{link != null && viewCount != null && (<GraphExternalLink label={link.label} url={link.url} />diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/PanelHeader.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/PanelHeader.tsxindex 915a8459400..33dd3704a0b 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/PanelHeader.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelHeader/PanelHeader.tsx@@ -7,11 +7,9 @@ import {Stack,TextInput,Title,- rem,} from "metabase/ui";import type { DependencyGroupType, DependencyNode } from "metabase-types/api";-import { ACTION_ICON_PADDING } from "../../constants";import type { FilterOption, SortOptions } from "../types";import { canFilter } from "../utils";@@ -53,11 +51,7 @@ export function PanelHeader({<Title flex={1} order={4} lh="1rem">{getHeaderLabel(node, groupType)}</Title>- <ActionIcon- m={rem(-ACTION_ICON_PADDING)}- aria-label={t`Close`}- onClick={onClose}- >+ <ActionIcon m="-sm" aria-label={t`Close`} onClick={onClose}><FixedSizeIcon name="close" /></ActionIcon></Group>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.tsindex 72dcdc3f53b..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@@ -2,7 +2,7 @@ import { t } from "ttag";import type { DependencyGroupType, DependencyNode } from "metabase-types/api";-import { getNodeLabel } from "../../utils";+import { getNodeLabel } from "../../../../utils";export function getHeaderLabel(node: DependencyNode,diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.tsindex 929b7aef55a..b27d9f19fd0 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts@@ -10,7 +10,7 @@ import {getNodeLabel,getNodeLocationInfo,getNodeViewCount,-} from "../utils";+} from "../../../utils";import { FILTER_OPTIONS } from "./constants";import type {@@ -113,13 +113,13 @@ const COMPARATORS: Record<SortColumn, SortCallback> = {return label1.localeCompare(label2);},location: (node1, node2) => {- const parts1 = getNodeLocationInfo(node1) ?? [];- const parts2 = getNodeLocationInfo(node2) ?? [];- const minParts = parts1.length < parts2.length ? parts1 : parts2;- const result = minParts- .map((_link, i) => parts1[i].label.localeCompare(parts2[i].label))+ const links1 = getNodeLocationInfo(node1)?.links ?? [];+ const links2 = getNodeLocationInfo(node2)?.links ?? [];+ const minLinks = links1.length < links2.length ? links1 : links2;+ const result = minLinks+ .map((_link, i) => links1[i].label.localeCompare(links2[i].label)).find((result) => result !== 0);- return result ?? parts1.length - parts2.length;+ return result ?? links1.length - links2.length;},"view-count": (node1, node2) => {const count1 = getNodeViewCount(node1) ?? 0;diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryButton/EntryButton.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryButton/EntryButton.tsxindex f36b0c53a76..e95a6e83125 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryButton/EntryButton.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryButton/EntryButton.tsx@@ -4,7 +4,7 @@ import { t } from "ttag";import { Button, FixedSizeIcon } from "metabase/ui";import type { DependencyEntry, DependencyNode } from "metabase-types/api";-import { getNodeIcon, getNodeLabel } from "../../utils";+import { getNodeIcon, getNodeLabel } from "../../../../utils";type EntryButtonProps = {node: DependencyNode | null;diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/utils.tsindex 4bc16a5dbbe..1aba68ed859 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryPickerModal/utils.ts@@ -13,7 +13,7 @@ import type {SearchResponse,} from "metabase-types/api";-import { getDependencyType } from "../../utils";+import { getDependencyType } from "../../../../utils";import { SEARCH_MODEL_TO_GROUP_TYPE } from "../constants";import type { EntryPickerItem } from "./types";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/utils.tsindex 27188fe994d..2b307feda06 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/utils.ts@@ -10,7 +10,7 @@ import type {SearchResultId,} from "metabase-types/api";-import { getDependencyType, getNodeIconWithType } from "../../utils";+import { getDependencyType, getNodeIconWithType } from "../../../../utils";import { SEARCH_MODEL_TO_GROUP_TYPE } from "../constants";import { BROWSE_OPTION_VALUE } from "./constants";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphExternalLink/GraphExternalLink.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphExternalLink/GraphExternalLink.tsxindex b7485759be5..d8864b266a5 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphExternalLink/GraphExternalLink.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphExternalLink/GraphExternalLink.tsx@@ -1,7 +1,7 @@import { ForwardRefLink } from "metabase/common/components/Link";-import { ActionIcon, FixedSizeIcon, Tooltip, rem } from "metabase/ui";+import { ActionIcon, FixedSizeIcon, Tooltip } from "metabase/ui";-import { ACTION_ICON_PADDING, TOOLTIP_OPEN_DELAY } from "../constants";+import { TOOLTIP_OPEN_DELAY_MS } from "../../../constants";type GraphExternalLinkProps = {label: string;@@ -10,12 +10,12 @@ type GraphExternalLinkProps = {export function GraphExternalLink({ label, url }: GraphExternalLinkProps) {return (- <Tooltip label={label} openDelay={TOOLTIP_OPEN_DELAY}>+ <Tooltip label={label} openDelay={TOOLTIP_OPEN_DELAY_MS}><ActionIconcomponent={ForwardRefLink}to={url}target="_blank"- m={rem(-ACTION_ICON_PADDING)}+ m="-sm"aria-label={label}><FixedSizeIcon name="external" />diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsxindex c92bbcc4a1d..8fc6a0765f9 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx@@ -1,27 +1,24 @@-import { c, t } from "ttag";+import { t } from "ttag";-import DateTime from "metabase/common/components/DateTime";+import { EntityCreationInfo } from "metabase/common/components/EntityCreationInfo";import { getColumnIcon } from "metabase/common/utils/columns";-import { getUserName } from "metabase/lib/user";import { Box, FixedSizeIcon, Group, Stack, Title } from "metabase/ui";import * as Lib from "metabase-lib";import type { DependencyEntry, DependencyNode } from "metabase-types/api";-import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";-import { GraphExternalLink } from "../../GraphExternalLink";-import { GraphLink } from "../../GraphLink";-import { getNodeDescription } from "../../utils";--import S from "./PanelBody.module.css";import {getNodeCreatedAt,getNodeCreatedBy,- getNodeFields,- getNodeFieldsLabel,+ getNodeDescription,getNodeLastEditedAt,getNodeLastEditedBy,- getNodeTableInfo,-} from "./utils";+} from "../../../../utils";+import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";+import { GraphExternalLink } from "../../GraphExternalLink";+import { GraphLink } from "../../GraphLink";++import S from "./PanelBody.module.css";+import { getNodeFields, getNodeFieldsLabel, getNodeTableInfo } from "./utils";type PanelBodyProps = {node: DependencyNode;@@ -69,33 +66,12 @@ function CreatorAndLastEditorSection({ node }: SectionProps) {}return (- <Stack gap="sm" lh="1rem">- <Title order={6}>{t`Creator and last editor`}</Title>- {createdAt != null && createdBy != null && (- <Group gap="sm" wrap="nowrap">- <FixedSizeIcon name="ai" />- <Box>- {c(- "Describes when an entity was created. {0} is a date/time and {1} is a person's name",- ).jt`${(- <DateTime unit="day" value={createdAt} key="date" />- )} by ${getUserName(createdBy)}`}- </Box>- </Group>- )}- {editedAt != null && editedBy != null && (- <Group gap="sm" wrap="nowrap">- <FixedSizeIcon name="pencil" />- <Box>- {c(- "Describes when an entity was last edited. {0} is a date/time and {1} is a person's name",- ).jt`${(- <DateTime unit="day" value={editedAt} key="date" />- )} by ${getUserName(editedBy)}`}- </Box>- </Group>- )}- </Stack>+ <EntityCreationInfo+ createdAt={createdAt}+ creator={createdBy}+ lastEditedAt={editedAt}+ lastEditor={editedBy}+ />);}@@ -121,7 +97,7 @@ function TableSection({ node, getGraphUrl }: TableSectionProps) {/></Group>{info.location && (- <GraphBreadcrumbs location={info.location} ml="1rem" pl="sm" />+ <GraphBreadcrumbs links={info.location} ml="1rem" pl="sm" />)}</Stack>);diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/types.tsindex f1822b8bd56..e06673b7900 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/types.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/types.ts@@ -1,4 +1,4 @@-import type { NodeLink } from "../../types";+import type { NodeLink } from "../../../../types";export type NodeTableInfo = {label: string;diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.tsindex 90674c5d6ed..e4287495f31 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts@@ -5,76 +5,10 @@ import type {DependencyEntry,DependencyNode,Field,- LastEditInfo,- UserInfo,} from "metabase-types/api";import type { NodeTableInfo } from "./types";-export function getNodeCreatedAt(node: DependencyNode): string | null {- switch (node.type) {- case "card":- case "dashboard":- case "document":- case "segment":- case "measure":- return node.data.created_at;- case "table":- case "transform":- case "snippet":- case "sandbox":- return null;- }-}--export function getNodeCreatedBy(node: DependencyNode): UserInfo | null {- switch (node.type) {- case "card":- case "dashboard":- case "document":- case "segment":- case "measure":- return node.data.creator ?? null;- case "table":- case "transform":- case "snippet":- case "sandbox":- return null;- }-}--export function getNodeLastEditedAt(node: DependencyNode): string | null {- switch (node.type) {- case "card":- case "dashboard":- return node.data["last-edit-info"]?.timestamp ?? null;- case "segment":- case "measure":- case "table":- case "transform":- case "snippet":- case "document":- case "sandbox":- return null;- }-}--export function getNodeLastEditedBy(node: DependencyNode): LastEditInfo | null {- switch (node.type) {- case "card":- case "dashboard":- return node.data["last-edit-info"] ?? null;- case "segment":- case "measure":- case "table":- case "transform":- case "snippet":- case "document":- case "sandbox":- return null;- }-}-export function getNodeTableInfo(node: DependencyNode,getGraphUrl: (entry: DependencyEntry) => string,diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelHeader/PanelHeader.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelHeader/PanelHeader.tsxindex 52058c3c850..dfe6189b0f1 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelHeader/PanelHeader.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelHeader/PanelHeader.tsx@@ -7,19 +7,17 @@ import {Group,Stack,Title,- rem,} from "metabase/ui";import type { DependencyNode } from "metabase-types/api";-import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";-import { GraphExternalLink } from "../../GraphExternalLink";-import { ACTION_ICON_PADDING } from "../../constants";import {getNodeIcon,getNodeLabel,getNodeLink,getNodeLocationInfo,-} from "../../utils";+} from "../../../../utils";+import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";+import { GraphExternalLink } from "../../GraphExternalLink";import S from "./PanelHeader.module.css";@@ -41,9 +39,9 @@ export function PanelHeader({ node, onClose }: PanelHeaderProps) {<Title order={3} lh="1.5rem">{getNodeLabel(node)}</Title>- {location != null && <GraphBreadcrumbs location={location} />}+ {location != null && <GraphBreadcrumbs links={location.links} />}</Stack>- <Group m={rem(-ACTION_ICON_PADDING)} gap="xs">+ <Group m="-sm" gap="xs">{link != null && (<GraphExternalLink label={link.label} url={link.url} />)}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsxindex 68ed2f34d6a..b55e630ecfa 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx@@ -19,14 +19,15 @@ import {} from "metabase/ui";import type { DependencyNode } from "metabase-types/api";-import { GraphContext } from "../GraphContext";-import type { GraphSelection, NodeType } from "../types";import {+ getDependencyGroupType,+ getDependencyGroupTypeInfo,getNodeIcon,getNodeLabel,- getNodeTypeInfo,isSameNode,-} from "../utils";+} from "../../../utils";+import { GraphContext } from "../GraphContext";+import type { GraphSelection, NodeType } from "../types";import S from "./GraphNode.module.css";import type { DependentGroup } from "./types";@@ -43,7 +44,7 @@ export const GraphNode = memo(function ItemNode({}: GraphNodeProps) {const { selection, setSelection } = useContext(GraphContext);const label = getNodeLabel(node);- const typeInfo = getNodeTypeInfo(node);+ const typeInfo = getDependencyGroupTypeInfo(getDependencyGroupType(node));const groups = getDependentGroups(node);const sources = useNodeConnections({ handleType: "source" });const targets = useNodeConnections({ handleType: "target" });diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphSelectionInput/GraphSelectionInput.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphSelectionInput/GraphSelectionInput.tsxindex 6f770f0a2a1..357794d3ed0 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphSelectionInput/GraphSelectionInput.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphSelectionInput/GraphSelectionInput.tsx@@ -5,9 +5,9 @@ import { t } from "ttag";import { Button, Card, FixedSizeIcon, Select, Tooltip } from "metabase/ui";-import { TOOLTIP_OPEN_DELAY } from "../constants";+import { TOOLTIP_OPEN_DELAY_MS } from "../../../constants";+import { getNodeIcon, getNodeLabel } from "../../../utils";import type { NodeType } from "../types";-import { getNodeIcon, getNodeLabel } from "../utils";type GraphSelectInputProps = {nodes: NodeType[];@@ -44,7 +44,7 @@ export function GraphSelectInput({ nodes }: GraphSelectInputProps) {) : (<Tooltiplabel={t`Jump to an item on the graph`}- openDelay={TOOLTIP_OPEN_DELAY}+ openDelay={TOOLTIP_OPEN_DELAY_MS}><ButtonleftSection={<FixedSizeIcon name="search" />}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/constants.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/constants.tsindex aa11ca9e746..711c8253c4a 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/constants.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/constants.ts@@ -1,5 +1,3 @@export const MIN_ZOOM = 0.1;export const MAX_ZOOM = 1;-export const ACTION_ICON_PADDING = 6;export const DEPENDENTS_SEARCH_THRESHOLD = 5;-export const TOOLTIP_OPEN_DELAY = 700;diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.tsindex 36d49c29195..66ff431c8ee 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts@@ -1,33 +1,16 @@import type { Edge } from "@xyflow/react";-import { t } from "ttag";-import * as Urls from "metabase/lib/urls";-import type { IconName } from "metabase/ui";-import visualizations from "metabase/visualizations";import type {- CardType,DependencyEdge,DependencyEntry,DependencyGraph,- DependencyGroupType,- DependencyId,DependencyNode,- DependencyType,- VisualizationDisplay,} from "metabase-types/api";-import type {- EdgeId,- GraphData,- NodeId,- NodeLink,- NodeType,- NodeTypeInfo,-} from "./types";+import type { NodeId } from "../../types";+import { getNodeId, isSameNode } from "../../utils";-export function getNodeId(id: DependencyId, type: DependencyType): NodeId {- return `${id}-${type}`;-}+import type { EdgeId, GraphData, NodeType } from "./types";export function getEdgeId(sourceId: NodeId, targetId: NodeId): EdgeId {return `${sourceId}-${targetId}`;@@ -72,327 +55,9 @@ export function getInitialGraph({ nodes, edges }: DependencyGraph): GraphData {};}-export function isSameNode(- entry1: DependencyEntry,- entry2: DependencyEntry,-): boolean {- return entry1.id === entry2.id && entry1.type === entry2.type;-}-export function findNode(nodes: NodeType[],entry: DependencyEntry,): NodeType | undefined {return nodes.find((node) => isSameNode(node.data, entry));}--export function getNodeLabel(node: DependencyNode): string {- switch (node.type) {- case "table":- return node.data.display_name;- case "sandbox":- return node.data.table?.display_name ?? t`Row and column security rule`;- default:- return node.data.name;- }-}--export function getNodeDescription(node: DependencyNode): string | null {- switch (node.type) {- case "document":- case "sandbox":- return null;- default:- return node.data.description ?? "";- }-}--export function getNodeIcon(node: DependencyNode): IconName {- return getNodeIconWithType(- node.type,- node.type === "card" ? node.data.type : undefined,- node.type === "card" ? node.data.display : undefined,- );-}--export function getNodeIconWithType(- type: DependencyType,- cardType?: CardType,- cardDisplay?: VisualizationDisplay,-): IconName {- switch (type) {- case "card":- switch (cardType) {- case "question":- return cardDisplay != null- ? (visualizations.get(cardDisplay)?.iconName ?? "table2")- : "table2";- case "model":- return "model";- case "metric":- return "metric";- default:- return "table2";- }- case "table":- return "table";- case "transform":- return "transform";- case "snippet":- return "sql";- case "dashboard":- return "dashboard";- case "document":- return "document";- case "sandbox":- return "permissions_limited";- case "segment":- return "segment";- case "measure":- return "sum";- }-}--function getCardLinkLabel(cardType: CardType): string {- switch (cardType) {- case "question":- return t`View this question`;- case "model":- return t`View this model`;- case "metric":- return t`View this metric`;- }-}--export function getNodeLink(node: DependencyNode): NodeLink | null {- switch (node.type) {- case "card":- return {- label: getCardLinkLabel(node.data.type),- url: Urls.question({- id: node.id,- name: node.data.name,- type: node.data.type,- }),- };- case "table":- return {- label: t`View metadata`,- url: Urls.dataStudioData({- databaseId: node.data.db_id,- schemaName: node.data.schema,- tableId: node.id,- }),- };- case "transform":- return {- label: t`View this transform`,- url: Urls.transform(node.id),- };- case "dashboard":- return {- label: `View this dashboard`,- url: Urls.dashboard({ id: node.id, name: node.data.name }),- };- case "document":- return {- label: `View this document`,- url: Urls.document({ id: node.id }),- };- case "sandbox":- if (node.data.table != null) {- return {- label: `View this permission`,- url: Urls.tableDataPermissions(- node.data.table.db_id,- node.data.table.schema,- node.data.table.id,- ),- };- }- return null;- case "segment":- if (node.data.table != null) {- return {- label: t`View this segment`,- url: Urls.dataStudioDataModelSegment({- databaseId: node.data.table.db_id,- schemaName: node.data.table.schema,- tableId: node.data.table.id,- segmentId: node.id,- }),- };- }- return null;- case "measure":- if (node.data.table != null) {- return {- label: t`View this measure`,- url: Urls.dataStudioDataModelMeasure({- databaseId: node.data.table.db_id,- schemaName: node.data.table.schema,- tableId: node.data.table.id,- measureId: node.id,- }),- };- }- return null;- case "snippet":- return null;- }-}--export function getNodeLocationInfo(node: DependencyNode): NodeLink[] | null {- switch (node.type) {- case "card":- if (node.data.dashboard != null) {- return [- {- label: node.data.dashboard.name,- url: Urls.dashboard(node.data.dashboard),- },- ];- }- if (node.data.document != null) {- return [- {- label: node.data.document.name,- url: Urls.document(node.data.document),- },- ];- }- if (node.data.collection != null) {- return [- {- label: node.data.collection.name,- url: Urls.collection(node.data.collection),- },- ];- }- return null;- case "table":- if (node.data.db != null) {- return [- {- label: node.data.db.name,- url: Urls.dataStudioData({ databaseId: node.data.db_id }),- },- {- label: node.data.schema,- url: Urls.dataStudioData({- databaseId: node.data.db_id,- schemaName: node.data.schema,- }),- },- ];- }- return null;- case "dashboard":- case "document":- if (node.data.collection != null) {- return [- {- label: node.data.collection.name,- url: Urls.collection(node.data.collection),- },- ];- }- return null;- case "segment":- case "measure":- if (node.data.table != null) {- return [- {- label: node.data.table.display_name,- url: Urls.dataStudioData({- databaseId: node.data.table.db_id,- schemaName: node.data.table.schema,- tableId: node.data.table.id,- tab: node.type === "segment" ? "segments" : "measures",- }),- },- ];- }- return null;- case "transform":- case "snippet":- case "sandbox":- return null;- }-}--export function getNodeViewCount(node: DependencyNode): number | null {- switch (node.type) {- case "card":- // view_count is not calculated property for models and metrics since- // they are typically not run directly- return node.data.type === "question"- ? (node.data.view_count ?? null)- : null;- case "dashboard":- case "document":- return node.data.view_count ?? null;- case "table":- case "transform":- case "snippet":- case "sandbox":- case "segment":- case "measure":- return null;- }-}--export function getCardType(groupType: DependencyGroupType): CardType | null {- switch (groupType) {- case "question":- case "model":- case "metric":- return groupType;- default:- return null;- }-}--export function getDependencyType(- groupType: DependencyGroupType,-): DependencyType {- switch (groupType) {- case "question":- case "model":- case "metric":- return "card";- default:- return groupType;- }-}--export function getNodeTypeInfo(node: DependencyNode): NodeTypeInfo {- switch (node.type) {- case "card":- switch (node.data.type) {- case "question":- return { label: t`Question`, color: "text-secondary" };- case "model":- return { label: t`Model`, color: "brand" };- case "metric":- return { label: t`Metric`, color: "summarize" };- }- break;- case "table":- return { label: t`Table`, color: "brand" };- case "transform":- return { label: t`Transform`, color: "warning" };- case "snippet":- return { label: t`Snippet`, color: "text-secondary" };- case "dashboard":- return { label: t`Dashboard`, color: "filter" };- case "document":- return { label: t`Document`, color: "text-secondary" };- case "sandbox":- return { label: t`Row and column security rule`, color: "error" };- case "segment":- return { label: t`Segment`, color: "accent2" };- case "measure":- return { label: t`Measure`, color: "summarize" };- }-}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.module.cssnew file mode 100644index 00000000000..0073571bccc--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.module.css@@ -0,0 +1,3 @@+.main {+ overflow: hidden;+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsxnew file mode 100644index 00000000000..90a56cfe7a5--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx@@ -0,0 +1,94 @@+import { useMemo } from "react";++import { DelayedLoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper/DelayedLoadingAndErrorWrapper";+import { Center, Flex, Stack } from "metabase/ui";+import type {+ DependencyEntry,+ DependencyGroupType,+ DependencyNode,+} from "metabase-types/api";++import type { DependencyFilterOptions } from "../../types";+import { isSameNode } from "../../utils";++import S from "./DependencyList.module.css";+import { ListBody } from "./ListBody";+import { ListEmptyState } from "./ListEmptyState";+import { ListHeader } from "./ListHeader";+import { ListSearchBar } from "./ListSearchBar";+import { ListSidebar } from "./ListSidebar";++type DependencyListProps = {+ nodes: DependencyNode[];+ selectedEntry: DependencyEntry | null;+ searchValue: string;+ filterOptions: DependencyFilterOptions;+ availableGroupTypes: DependencyGroupType[];+ notFoundMessage: string;+ isLoading: boolean;+ isFetching: boolean;+ error: unknown;+ withErrorsColumn?: boolean;+ withDependentsCountColumn?: boolean;+ onSelect: (entry: DependencyEntry | null) => void;+ onSearchValueChange: (searchValue: string) => void;+ onFilterOptionsChange: (filterOptions: DependencyFilterOptions) => void;+};++export function DependencyList({+ nodes,+ searchValue,+ filterOptions,+ availableGroupTypes,+ notFoundMessage,+ isLoading,+ isFetching,+ error,+ selectedEntry,+ withErrorsColumn = false,+ withDependentsCountColumn = false,+ onSelect,+ onSearchValueChange,+ onFilterOptionsChange,+}: DependencyListProps) {+ const selectedNode = useMemo(() => {+ return selectedEntry != null+ ? nodes.find((node) => isSameNode(node, selectedEntry))+ : null;+ }, [nodes, selectedEntry]);++ return (+ <Flex h="100%">+ <Stack className={S.main} flex={1} px="3.5rem" py="md" gap="md">+ <ListHeader />+ <ListSearchBar+ searchValue={searchValue}+ filterOptions={filterOptions}+ availableGroupTypes={availableGroupTypes}+ hasLoader={isFetching && !isLoading}+ onSearchValueChange={onSearchValueChange}+ onFilterOptionsChange={onFilterOptionsChange}+ />+ {isLoading || error != null ? (+ <Center flex={1}>+ <DelayedLoadingAndErrorWrapper loading={isLoading} error={error} />+ </Center>+ ) : nodes.length === 0 ? (+ <Center flex={1}>+ <ListEmptyState label={notFoundMessage} />+ </Center>+ ) : (+ <ListBody+ nodes={nodes}+ withErrorsColumn={withErrorsColumn}+ withDependentsCountColumn={withDependentsCountColumn}+ onSelect={onSelect}+ />+ )}+ </Stack>+ {selectedNode != null && (+ <ListSidebar node={selectedNode} onClose={() => onSelect(null)} />+ )}+ </Flex>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/ErrorsCell.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/ErrorsCell.tsxnew file mode 100644index 00000000000..bae9d2db070--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/ErrorsCell.tsx@@ -0,0 +1,23 @@+import type { DependencyNode } from "metabase-types/api";++import { getDependencyErrorInfo } from "../../../../utils";++type ErrorsCellProps = {+ node: DependencyNode;+};++export function ErrorsCell({ node }: ErrorsCellProps) {+ const errors = node.errors ?? [];+ const errorsInfo = getDependencyErrorInfo(errors);++ if (!errorsInfo) {+ return null;+ }++ return (+ <div>+ <span>{errorsInfo.label}</span>{" "}+ {errorsInfo.detail && <strong>{errorsInfo.detail}</strong>}+ </div>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/index.tsnew file mode 100644index 00000000000..a64a61a5dd4--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/index.ts@@ -0,0 +1 @@+export * from "./ErrorsCell";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ListBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ListBody.tsxnew file mode 100644index 00000000000..ff58c9cbca2--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ListBody.tsx@@ -0,0 +1,46 @@+import type { Row } from "@tanstack/react-table";+import { memo, useCallback, useMemo } from "react";++import { Card, TreeTable, useTreeTableInstance } from "metabase/ui";+import type { DependencyNode } from "metabase-types/api";++import { getNodeId } from "../../../utils";++import { getColumns } from "./utils";++type ListBodyProps = {+ nodes: DependencyNode[];+ withErrorsColumn?: boolean;+ withDependentsCountColumn?: boolean;+ onSelect: (node: DependencyNode) => void;+};++export const ListBody = memo(function ListBody({+ nodes,+ withErrorsColumn = false,+ withDependentsCountColumn = false,+ onSelect,+}: ListBodyProps) {+ const columns = useMemo(+ () => getColumns({ withErrorsColumn, withDependentsCountColumn }),+ [withErrorsColumn, withDependentsCountColumn],+ );++ const handleRowActivate = useCallback(+ (row: Row<DependencyNode>) => onSelect(row.original),+ [onSelect],+ );++ const treeTableInstance = useTreeTableInstance<DependencyNode>({+ data: nodes,+ columns,+ getNodeId: (node) => getNodeId(node.id, node.type),+ onRowActivate: handleRowActivate,+ });++ return (+ <Card flex={1} mih={0} p={0} withBorder data-testid="dependency-list">+ <TreeTable instance={treeTableInstance} onRowClick={handleRowActivate} />+ </Card>+ );+});diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/LocationCell/LocationCell.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/LocationCell/LocationCell.tsxnew file mode 100644index 00000000000..2c3e943d890--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/LocationCell/LocationCell.tsx@@ -0,0 +1,33 @@+import { Fragment } from "react";++import { Box, FixedSizeIcon, Flex } from "metabase/ui";+import type { DependencyNode } from "metabase-types/api";++import { getNodeLocationInfo } from "../../../../utils";++type LocationCellProps = {+ node: DependencyNode;+};++export function LocationCell({ node }: LocationCellProps) {+ const location = getNodeLocationInfo(node);+ if (location == null) {+ return null;+ }++ const { icon, links } = location;++ return (+ <Flex align="center" gap="sm">+ {links.map((link, linkIndex) => (+ <Fragment key={linkIndex}>+ {linkIndex > 0 && <Box>/</Box>}+ <Flex align="center" gap="sm">+ {linkIndex === 0 && icon && <FixedSizeIcon name={icon} />}+ {link.label}+ </Flex>+ </Fragment>+ ))}+ </Flex>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/LocationCell/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/LocationCell/index.tsnew file mode 100644index 00000000000..552d82a44f2--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/LocationCell/index.ts@@ -0,0 +1 @@+export * from "./LocationCell";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/NameCell/NameCell.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/NameCell/NameCell.tsxnew file mode 100644index 00000000000..2174b829f4e--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/NameCell/NameCell.tsx@@ -0,0 +1,20 @@+import { FixedSizeIcon, Flex } from "metabase/ui";+import type { DependencyNode } from "metabase-types/api";++import { getNodeIcon, getNodeLabel } from "../../../../utils";++type NameCellProps = {+ node: DependencyNode;+};++export function NameCell({ node }: NameCellProps) {+ const label = getNodeLabel(node);+ const icon = getNodeIcon(node);++ return (+ <Flex align="center" gap="sm">+ {icon && <FixedSizeIcon name={icon} />}+ {label}+ </Flex>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/NameCell/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/NameCell/index.tsnew file mode 100644index 00000000000..a3df8b11b65--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/NameCell/index.ts@@ -0,0 +1 @@+export * from "./NameCell";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/index.tsnew file mode 100644index 00000000000..2ee22290de3--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/index.ts@@ -0,0 +1 @@+export * from "./ListBody";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsxnew file mode 100644index 00000000000..7ebb5d68d95--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx@@ -0,0 +1,96 @@+import { t } from "ttag";++import type { TreeTableColumnDef } from "metabase/ui";+import type { DependencyNode } from "metabase-types/api";++import {+ getNodeDependentsCount,+ getNodeLabel,+ getNodeLocationInfo,+} from "../../../utils";++import { ErrorsCell } from "./ErrorsCell";+import { LocationCell } from "./LocationCell";+import { NameCell } from "./NameCell";++function getNodeNameColumn(): TreeTableColumnDef<DependencyNode> {+ return {+ id: "name",+ header: t`Name`,+ meta: {+ width: "auto",+ },+ accessorFn: (node) => getNodeLabel(node),+ cell: ({ row }) => {+ const node = row.original;+ return <NameCell node={node} />;+ },+ };+}++function getNodeLocationColumn(): TreeTableColumnDef<DependencyNode> {+ return {+ id: "location",+ header: t`Location`,+ meta: {+ width: "auto",+ },+ accessorFn: (node) => {+ const location = getNodeLocationInfo(node);+ const links = location?.links ?? [];+ return links.map((link) => link.label).join(", ");+ },+ cell: ({ row }) => {+ const node = row.original;+ return <LocationCell node={node} />;+ },+ };+}++function getNodeErrorsColumn(): TreeTableColumnDef<DependencyNode> {+ return {+ id: "error",+ header: t`Errors`,+ meta: {+ width: "auto",+ },+ accessorFn: (node) => node.errors?.length ?? 0,+ cell: ({ row }) => {+ const node = row.original;+ const errors = node.errors ?? [];+ if (errors.length === 0) {+ return null;+ }+ return <ErrorsCell node={node} />;+ },+ };+}++function getNodeDependentsCountColumn(): TreeTableColumnDef<DependencyNode> {+ return {+ id: "dependents-count",+ header: t`Dependents`,+ accessorFn: (node) => getNodeDependentsCount(node),+ cell: ({ row }) => {+ const node = row.original;+ return getNodeDependentsCount(node);+ },+ };+}++type ColumnOptions = {+ withErrorsColumn: boolean;+ withDependentsCountColumn: boolean;+};++export function getColumns({+ withErrorsColumn,+ withDependentsCountColumn,+}: ColumnOptions): TreeTableColumnDef<DependencyNode>[] {+ return [+ getNodeNameColumn(),+ getNodeLocationColumn(),+ ...(withErrorsColumn ? [getNodeErrorsColumn()] : []),+ ...(withDependentsCountColumn ? [getNodeDependentsCountColumn()] : []),+ ];+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListEmptyState/ListEmptyState.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListEmptyState/ListEmptyState.tsxnew file mode 100644index 00000000000..2a6b48e8bc3--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListEmptyState/ListEmptyState.tsx@@ -0,0 +1,22 @@+import { t } from "ttag";++import EmptyDashboardBot from "assets/img/dashboard-empty.svg";+import { Stack, Text } from "metabase/ui";++type ListEmptyStateProps = {+ label: string;+};++export function ListEmptyState({ label }: ListEmptyStateProps) {+ return (+ <Stack p="xl" align="center">+ <img+ src={EmptyDashboardBot}+ alt={t`Empty list`}+ width={100}+ height={100}+ />+ <Text c="text-secondary">{label}</Text>+ </Stack>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListEmptyState/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListEmptyState/index.tsnew file mode 100644index 00000000000..4c37680372c--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListEmptyState/index.ts@@ -0,0 +1 @@+export * from "./ListEmptyState";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsxnew file mode 100644index 00000000000..2721124b9ae--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx@@ -0,0 +1,31 @@+import { memo } from "react";+import { t } from "ttag";++import * as Urls from "metabase/lib/urls";+import { Stack, Title } from "metabase/ui";+import {+ type PaneHeaderTab,+ PaneHeaderTabs,+} from "metabase-enterprise/data-studio/common/components/PaneHeader";++export const ListHeader = memo(function ListHeader() {+ const tabs: PaneHeaderTab[] = [+ {+ label: t`Broken`,+ to: Urls.dataStudioBrokenEntities(),+ icon: "list",+ },+ {+ label: t`Unreferenced`,+ to: Urls.dataStudioUnreferencedEntities(),+ icon: "list",+ },+ ];++ return (+ <Stack gap="md">+ <Title order={1} py="sm" fz="sm" lh="1rem" fw="normal">{t`Tasks`}</Title>+ <PaneHeaderTabs tabs={tabs} />+ </Stack>+ );+});diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/index.tsnew file mode 100644index 00000000000..b8dcd5fc70b--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/index.ts@@ -0,0 +1 @@+export * from "./ListHeader";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/FilterOptionsPicker.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/FilterOptionsPicker.tsxnew file mode 100644index 00000000000..2b118dbd0b8--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/FilterOptionsPicker.tsx@@ -0,0 +1,72 @@+import { useDisclosure } from "@mantine/hooks";+import { t } from "ttag";++import { Box, Button, FixedSizeIcon, Popover, Stack } from "metabase/ui";+import type { DependencyGroupType } from "metabase-types/api";++import type { DependencyFilterOptions } from "../../../../types";++import { TypeFilterPicker } from "./TypeFilterPicker";++type FilterOptionsPickerProps = {+ filterOptions: DependencyFilterOptions;+ availableGroupTypes: DependencyGroupType[];+ onFilterOptionsChange: (filterOptions: DependencyFilterOptions) => void;+};++export function FilterOptionsPicker({+ filterOptions,+ availableGroupTypes,+ onFilterOptionsChange,+}: FilterOptionsPickerProps) {+ const [isOpened, { toggle, close }] = useDisclosure();++ return (+ <Popover opened={isOpened} onDismiss={close}>+ <Popover.Target>+ <Button+ leftSection={<FixedSizeIcon name="filter" aria-hidden />}+ data-testid="dependency-list-filter-button"+ onClick={toggle}+ >+ {t`Filter`}+ </Button>+ </Popover.Target>+ <Popover.Dropdown>+ <FilterOptionsPopover+ filterOptions={filterOptions}+ availableGroupTypes={availableGroupTypes}+ onFilterOptionsChange={onFilterOptionsChange}+ />+ </Popover.Dropdown>+ </Popover>+ );+}++type FilterOptionsPopoverProps = {+ filterOptions: DependencyFilterOptions;+ availableGroupTypes: DependencyGroupType[];+ onFilterOptionsChange: (filterOptions: DependencyFilterOptions) => void;+};++function FilterOptionsPopover({+ filterOptions,+ availableGroupTypes,+ onFilterOptionsChange,+}: FilterOptionsPopoverProps) {+ const handleTypesChange = (groupTypes: DependencyGroupType[]) => {+ onFilterOptionsChange({ ...filterOptions, groupTypes });+ };++ return (+ <Box w="20rem" p="md">+ <Stack>+ <TypeFilterPicker+ groupTypes={filterOptions.groupTypes ?? []}+ availableGroupTypes={availableGroupTypes}+ onChange={handleTypesChange}+ />+ </Stack>+ </Box>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/TypeFilterPicker.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/TypeFilterPicker.tsxnew file mode 100644index 00000000000..05bd81ad6b4--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/TypeFilterPicker.tsx@@ -0,0 +1,53 @@+import { useMemo } from "react";+import { t } from "ttag";++import { Checkbox, Stack } from "metabase/ui";+import type { DependencyGroupType } from "metabase-types/api";++import { getDependencyGroupTypeInfo } from "../../../../../utils";++type TypeFilterPickerProps = {+ groupTypes: DependencyGroupType[];+ availableGroupTypes: DependencyGroupType[];+ onChange: (groupTypes: DependencyGroupType[]) => void;+};++export function TypeFilterPicker({+ groupTypes,+ availableGroupTypes,+ onChange,+}: TypeFilterPickerProps) {+ const groupOptions = useMemo(+ () =>+ availableGroupTypes.map((groupType) => ({+ value: groupType,+ label: getDependencyGroupTypeInfo(groupType).label,+ })),+ [availableGroupTypes],+ );++ const handleChange = (value: string[]) => {+ const newGroupTypes = availableGroupTypes.filter((groupType) =>+ value.includes(groupType),+ );+ onChange(newGroupTypes);+ };++ return (+ <Checkbox.Group+ label={t`Entity type`}+ value={groupTypes}+ onChange={handleChange}+ >+ <Stack gap="sm" mt="sm">+ {groupOptions.map((groupOption) => (+ <Checkbox+ key={groupOption.value}+ value={groupOption.value}+ label={groupOption.label}+ />+ ))}+ </Stack>+ </Checkbox.Group>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/index.tsnew file mode 100644index 00000000000..fa6db7eb0c0--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/index.ts@@ -0,0 +1 @@+export * from "./TypeFilterPicker";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/index.tsnew file mode 100644index 00000000000..ba6bd22e417--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/index.ts@@ -0,0 +1 @@+export * from "./FilterOptionsPicker";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsxnew file mode 100644index 00000000000..b69caa8adf3--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsx@@ -0,0 +1,50 @@+import { type ChangeEvent, memo } from "react";+import { t } from "ttag";++import { Flex, Icon, Loader, TextInput } from "metabase/ui";+import type { DependencyGroupType } from "metabase-types/api";++import type { DependencyFilterOptions } from "../../../types";++import { FilterOptionsPicker } from "./FilterOptionsPicker";++type ListSearchBarProps = {+ searchValue: string;+ filterOptions: DependencyFilterOptions;+ availableGroupTypes: DependencyGroupType[];+ hasLoader: boolean;+ onSearchValueChange: (searchValue: string) => void;+ onFilterOptionsChange: (filterOptions: DependencyFilterOptions) => void;+};++export const ListSearchBar = memo(function ListSearchBar({+ searchValue,+ filterOptions,+ availableGroupTypes,+ hasLoader,+ onSearchValueChange,+ onFilterOptionsChange,+}: ListSearchBarProps) {+ const handleSearchChange = (event: ChangeEvent<HTMLInputElement>) => {+ onSearchValueChange(event.target.value);+ };++ return (+ <Flex gap="md" align="center">+ <TextInput+ value={searchValue}+ placeholder={t`Search…`}+ flex={1}+ leftSection={<Icon name="search" />}+ rightSection={hasLoader ? <Loader size="sm" /> : undefined}+ data-testid="dependency-list-search-input"+ onChange={handleSearchChange}+ />+ <FilterOptionsPicker+ filterOptions={filterOptions}+ availableGroupTypes={availableGroupTypes}+ onFilterOptionsChange={onFilterOptionsChange}+ />+ </Flex>+ );+});diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/index.tsnew file mode 100644index 00000000000..03df54ffa7a--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/index.ts@@ -0,0 +1 @@+export * from "./ListSearchBar";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.module.cssnew file mode 100644index 00000000000..7b441d75e53--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.module.css@@ -0,0 +1,4 @@+.panel {+ overflow: auto;+ border-left: 1px solid var(--mb-color-border);+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsxnew file mode 100644index 00000000000..545e601e72c--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx@@ -0,0 +1,44 @@+import { memo } from "react";++import { Stack } from "metabase/ui";+import type { DependencyNode } from "metabase-types/api";++import S from "./ListSidebar.module.css";+import { SidebarCreationInfo } from "./SidebarCreationInfo";+import { SidebarErrorInfo } from "./SidebarErrorInfo";+import { SidebarHeader } from "./SidebarHeader";+import { SidebarLocationInfo } from "./SidebarLocationInfo";+import { getDependencyErrorGroups } from "./utils";++type ListSidebarProps = {+ node: DependencyNode;+ onClose: () => void;+};++export const ListSidebar = memo(function ListSidebar({+ node,+ onClose,+}: ListSidebarProps) {+ const errorGroups = getDependencyErrorGroups(node.errors ?? []);++ return (+ <Stack+ className={S.panel}+ p="lg"+ w="25rem"+ gap="lg"+ data-testid="dependency-list-sidebar"+ >+ <SidebarHeader node={node} onClose={onClose} />+ <SidebarCreationInfo node={node} />+ <SidebarLocationInfo node={node} />+ {errorGroups.map((errorGroup) => (+ <SidebarErrorInfo+ key={errorGroup.type}+ type={errorGroup.type}+ errors={errorGroup.errors}+ />+ ))}+ </Stack>+ );+});diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/SidebarCreationInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/SidebarCreationInfo.tsxnew file mode 100644index 00000000000..81ef1aa263f--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/SidebarCreationInfo.tsx@@ -0,0 +1,45 @@+import { t } from "ttag";++import { EntityCreationInfo } from "metabase/common/components/EntityCreationInfo";+import { Card, Stack, Title } from "metabase/ui";+import type { DependencyNode } from "metabase-types/api";++import {+ getNodeCreatedAt,+ getNodeCreatedBy,+ getNodeLastEditedAt,+ getNodeLastEditedBy,+} from "../../../../utils";++type SidebarCreationInfoProps = {+ node: DependencyNode;+};++export function SidebarCreationInfo({ node }: SidebarCreationInfoProps) {+ const title = t`Creator and last editor`;+ const createdAt = getNodeCreatedAt(node);+ const createdBy = getNodeCreatedBy(node);+ const editedAt = getNodeLastEditedAt(node);+ const editedBy = getNodeLastEditedBy(node);+ const hasCreatedInfo = createdAt != null && createdBy != null;+ const hasEditedInfo = editedAt != null && editedBy != null;++ if (!hasCreatedInfo && !hasEditedInfo) {+ return null;+ }++ return (+ <Stack gap="sm" role="region" aria-label={title}>+ <Title order={4}>{title}</Title>+ <Card p="md" shadow="none" withBorder>+ <EntityCreationInfo+ createdAt={createdAt}+ creator={createdBy}+ lastEditedAt={editedAt}+ lastEditor={editedBy}+ withTitle={false}+ />+ </Card>+ </Stack>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/index.tsnew file mode 100644index 00000000000..38c20047114--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/index.ts@@ -0,0 +1 @@+export * from "./SidebarCreationInfo";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.module.cssnew file mode 100644index 00000000000..1b2f651934d--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.module.css@@ -0,0 +1,5 @@+.item {+ &:not(:last-child) {+ border-bottom: 1px solid var(--mb-color-border);+ }+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.tsxnew file mode 100644index 00000000000..55ae320ac40--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.tsx@@ -0,0 +1,44 @@+import { CopyButton } from "metabase/common/components/CopyButton";+import { Box, Card, Group, Stack, Title } from "metabase/ui";+import type { DependencyError, DependencyErrorType } from "metabase-types/api";++import {+ getDependencyErrorDetail,+ getDependencyErrorTypeCountMessage,+} from "../../../../utils";++import S from "./SidebarErrorInfo.module.css";++type SidebarErrorInfoProps = {+ type: DependencyErrorType;+ errors: DependencyError[];+};++export function SidebarErrorInfo({ type, errors }: SidebarErrorInfoProps) {+ const title = getDependencyErrorTypeCountMessage(type, errors.length);+ const details = errors+ .map((error) => getDependencyErrorDetail(error))+ .filter((detail) => detail != null);++ return (+ <Stack gap="sm" role="region" aria-label={title}>+ <Title order={4}>{title}</Title>+ {details.length > 0 && (+ <Card p={0} shadow="none" withBorder>+ {details.map((detail, detailIndex) => (+ <Group+ key={detailIndex}+ className={S.item}+ p="md"+ justify="space-between"+ wrap="nowrap"+ >+ <Box>{detail}</Box>+ <CopyButton value={detail} />+ </Group>+ ))}+ </Card>+ )}+ </Stack>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/index.tsnew file mode 100644index 00000000000..6883d40b59f--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/index.ts@@ -0,0 +1 @@+export * from "./SidebarErrorInfo";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsxnew file mode 100644index 00000000000..9088d772f45--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsx@@ -0,0 +1,47 @@+import { t } from "ttag";++import { ForwardRefLink } from "metabase/common/components/Link";+import { ActionIcon, FixedSizeIcon, Group, Title, Tooltip } from "metabase/ui";+import type { DependencyNode } from "metabase-types/api";++import { TOOLTIP_OPEN_DELAY_MS } from "../../../../constants";+import { getNodeLabel, getNodeLink } from "../../../../utils";++type SidebarHeaderProps = {+ node: DependencyNode;+ onClose: () => void;+};++export function SidebarHeader({ node, onClose }: SidebarHeaderProps) {+ const link = getNodeLink(node);++ return (+ <Group+ gap="0.75rem"+ wrap="nowrap"+ align="start"+ data-testid="dependency-list-sidebar-header"+ >+ <Title flex={1} order={3} lh="1.5rem">+ {getNodeLabel(node)}+ </Title>+ <Group gap="xs" wrap="nowrap">+ {link != null && (+ <Tooltip label={link.label} openDelay={TOOLTIP_OPEN_DELAY_MS}>+ <ActionIcon+ component={ForwardRefLink}+ to={link.url}+ target="_blank"+ aria-label={link.label}+ >+ <FixedSizeIcon name="external" />+ </ActionIcon>+ </Tooltip>+ )}+ <ActionIcon aria-label={t`Close`} onClick={onClose}>+ <FixedSizeIcon name="close" />+ </ActionIcon>+ </Group>+ </Group>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/index.tsnew file mode 100644index 00000000000..1014b0afde5--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/index.ts@@ -0,0 +1 @@+export * from "./SidebarHeader";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsxnew file mode 100644index 00000000000..a93525cb73f--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx@@ -0,0 +1,40 @@+import { Fragment } from "react";+import { Link } from "react-router";+import { t } from "ttag";++import { Anchor, Box, Card, Group, Icon, Stack, Title } from "metabase/ui";+import type { DependencyNode } from "metabase-types/api";++import { getNodeLocationInfo } from "../../../../utils";++type SidebarLocationInfoProps = {+ node: DependencyNode;+};++export function SidebarLocationInfo({ node }: SidebarLocationInfoProps) {+ const title = t`Location`;+ const locationInfo = getNodeLocationInfo(node);++ if (locationInfo == null) {+ return null;+ }++ return (+ <Stack gap="sm" role="region" aria-label={title}>+ <Title order={4}>{title}</Title>+ <Card p="md" shadow="none" withBorder>+ {locationInfo.links.map((link, linkIndex) => (+ <Fragment key={linkIndex}>+ {linkIndex > 0 && <Box>/</Box>}+ <Anchor component={Link} to={link.url}>+ <Group gap="sm" wrap="nowrap">+ {linkIndex === 0 && <Icon name={locationInfo.icon} />}+ {link.label}+ </Group>+ </Anchor>+ </Fragment>+ ))}+ </Card>+ </Stack>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/index.tsnew file mode 100644index 00000000000..a2aa298fdc0--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/index.ts@@ -0,0 +1 @@+export * from "./SidebarLocationInfo";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/index.tsnew file mode 100644index 00000000000..bbfe620db31--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/index.ts@@ -0,0 +1 @@+export * from "./ListSidebar";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/types.tsnew file mode 100644index 00000000000..43920b2e929--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/types.ts@@ -0,0 +1,6 @@+import type { DependencyError, DependencyErrorType } from "metabase-types/api";++export type DependencyErrorGroup = {+ type: DependencyErrorType;+ errors: DependencyError[];+};diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/utils.tsnew file mode 100644index 00000000000..17d237a8d02--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/utils.ts@@ -0,0 +1,21 @@+import type { DependencyError, DependencyErrorType } from "metabase-types/api";++import type { DependencyErrorGroup } from "./types";++export function getDependencyErrorGroups(+ errors: DependencyError[],+): DependencyErrorGroup[] {+ const groups: Partial<Record<DependencyErrorType, DependencyError[]>> = {};+ for (const error of errors) {+ const group = groups[error.type];+ if (group) {+ group.push(error);+ } else {+ groups[error.type] = [error];+ }+ }+ return Object.values(groups).map((errors) => ({+ type: errors[0].type,+ errors,+ }));+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/index.tsnew file mode 100644index 00000000000..45be276a60d--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/index.ts@@ -0,0 +1 @@+export * from "./DependencyList";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/constants.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/constants.tsnew file mode 100644index 00000000000..2de436790d7--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/constants.ts@@ -0,0 +1 @@+export const TOOLTIP_OPEN_DELAY_MS = 700;diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/index.tsindex 1ebebdc4bd5..c267d398093 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/index.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/index.ts@@ -9,7 +9,10 @@ import { useCheckSnippetDependencies } from "./hooks/use-check-snippet-dependencimport { useCheckTransformDependencies } from "./hooks/use-check-transform-dependencies";import { useGetDependenciesCount } from "./hooks/use-get-dependencies-count";import { DependencyGraphPage } from "./pages/DependencyGraphPage";-import { getDataStudioDependencyRoutes } from "./routes";+import {+ getDataStudioDependencyRoutes,+ getDataStudioTasksRoutes,+} from "./routes";/*** Initialize dependencies plugin features that depend on hasPremiumFeature.@@ -19,6 +22,7 @@ export function initializePlugin() {PLUGIN_DEPENDENCIES.isEnabled = true;PLUGIN_DEPENDENCIES.getDataStudioDependencyRoutes =getDataStudioDependencyRoutes;+ PLUGIN_DEPENDENCIES.getDataStudioTasksRoutes = getDataStudioTasksRoutes;PLUGIN_DEPENDENCIES.DependencyGraphPage = DependencyGraphPage;PLUGIN_DEPENDENCIES.CheckDependenciesForm = CheckDependenciesForm;PLUGIN_DEPENDENCIES.CheckDependenciesModal = CheckDependenciesModal;diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/BrokenDependencyListPage.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/BrokenDependencyListPage.tsxnew file mode 100644index 00000000000..e390dc27520--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/BrokenDependencyListPage.tsx@@ -0,0 +1,74 @@+import { useDebouncedValue } from "@mantine/hooks";+import { useState } from "react";+import { t } from "ttag";++import { SEARCH_DEBOUNCE_DURATION } from "metabase/lib/constants";+import { useListBrokenGraphNodesQuery } from "metabase-enterprise/api";+import type {+ DependencyEntry,+ DependencyGroupType,+ DependencyNode,+} from "metabase-types/api";++import { DependencyList } from "../../components/DependencyList";+import type { DependencyFilterOptions } from "../../types";+import { getCardTypes, getDependencyTypes, getSearchQuery } from "../../utils";++const EMPTY_NODES: DependencyNode[] = [];++export const AVAILABLE_GROUP_TYPES: DependencyGroupType[] = [+ "question",+ "model",+ "metric",+ "segment",+ "transform",+];++export function BrokenDependencyListPage() {+ const [searchValue, setSearchValue] = useState("");+ const [searchQuery] = useDebouncedValue(+ getSearchQuery(searchValue),+ SEARCH_DEBOUNCE_DURATION,+ );+ const [filterOptions, setFilterOptions] = useState<DependencyFilterOptions>({+ groupTypes: [],+ });+ const [selectedEntry, setSelectedEntry] = useState<DependencyEntry | null>(+ null,+ );++ const groupTypes =+ filterOptions.groupTypes.length > 0+ ? filterOptions.groupTypes+ : AVAILABLE_GROUP_TYPES;++ const {+ data: nodes = EMPTY_NODES,+ isFetching,+ isLoading,+ error,+ } = useListBrokenGraphNodesQuery({+ query: searchQuery,+ types: getDependencyTypes(groupTypes),+ card_types: getCardTypes(groupTypes),+ });++ return (+ <DependencyList+ nodes={nodes}+ selectedEntry={selectedEntry}+ searchValue={searchValue}+ filterOptions={filterOptions}+ availableGroupTypes={AVAILABLE_GROUP_TYPES}+ notFoundMessage={t`No broken entities found`}+ isLoading={isLoading}+ isFetching={isFetching}+ error={error}+ withErrorsColumn={true}+ withDependentsCountColumn={true}+ onSelect={setSelectedEntry}+ onSearchValueChange={setSearchValue}+ onFilterOptionsChange={setFilterOptions}+ />+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/index.tsnew file mode 100644index 00000000000..75e03097579--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/index.ts@@ -0,0 +1 @@+export * from "./BrokenDependencyListPage";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsxindex 5d3a4211c58..d0e93bf8213 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx@@ -6,7 +6,7 @@ import { PLUGIN_DEPENDENCIES } from "metabase/plugins";import { Stack } from "metabase/ui";import { DependencyGraph } from "../../components/DependencyGraph";-import { isSameNode } from "../../components/DependencyGraph/utils";+import { isSameNode } from "../../utils";import { parseDependencyEntry } from "./utils";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.tsindex ec5645c3f84..bbb11f0297c 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts@@ -1,28 +1,13 @@import * as Urls from "metabase/lib/urls";-import type { DependencyEntry, DependencyType } from "metabase-types/api";+import { DEPENDENCY_TYPES, type DependencyEntry } from "metabase-types/api";++import { parseEnum } from "../../utils";export function parseDependencyEntry(rawId?: string,rawType?: string,): DependencyEntry | undefined {const id = Urls.extractEntityId(rawId);- const type = parseDependencyType(rawType);+ const type = parseEnum(rawType, DEPENDENCY_TYPES);return id != null && type != null ? { id, type } : undefined;}--function parseDependencyType(type: unknown): DependencyType | undefined {- switch (type) {- case "card":- case "table":- case "transform":- case "snippet":- case "dashboard":- case "document":- case "sandbox":- case "segment":- case "measure":- return type;- default:- return undefined;- }-}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/UnreferencedDependencyListPage.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/UnreferencedDependencyListPage.tsxnew file mode 100644index 00000000000..71317856727--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/UnreferencedDependencyListPage.tsx@@ -0,0 +1,71 @@+import { useDebouncedValue } from "@mantine/hooks";+import { useState } from "react";+import { t } from "ttag";++import { SEARCH_DEBOUNCE_DURATION } from "metabase/lib/constants";+import { useListUnreferencedGraphNodesQuery } from "metabase-enterprise/api";+import type {+ DependencyEntry,+ DependencyGroupType,+ DependencyNode,+} from "metabase-types/api";++import { DependencyList } from "../../components/DependencyList";+import type { DependencyFilterOptions } from "../../types";+import { getCardTypes, getDependencyTypes, getSearchQuery } from "../../utils";++const EMPTY_NODES: DependencyNode[] = [];++export const AVAILABLE_GROUP_TYPES: DependencyGroupType[] = [+ "model",+ "metric",+ "segment",+ "snippet",+];++export function UnreferencedDependencyListPage() {+ const [searchValue, setSearchValue] = useState("");+ const [searchQuery] = useDebouncedValue(+ getSearchQuery(searchValue),+ SEARCH_DEBOUNCE_DURATION,+ );+ const [filterOptions, setFilterOptions] = useState<DependencyFilterOptions>({+ groupTypes: [],+ });+ const [selectedEntry, setSelectedEntry] = useState<DependencyEntry | null>(+ null,+ );++ const groupTypes =+ filterOptions.groupTypes.length > 0+ ? filterOptions.groupTypes+ : AVAILABLE_GROUP_TYPES;++ const {+ data: nodes = EMPTY_NODES,+ isFetching,+ isLoading,+ error,+ } = useListUnreferencedGraphNodesQuery({+ query: searchQuery,+ types: getDependencyTypes(groupTypes),+ card_types: getCardTypes(groupTypes),+ });++ return (+ <DependencyList+ nodes={nodes}+ selectedEntry={selectedEntry}+ searchValue={searchValue}+ filterOptions={filterOptions}+ availableGroupTypes={AVAILABLE_GROUP_TYPES}+ notFoundMessage={t`No unreferenced entities found`}+ isLoading={isLoading}+ isFetching={isFetching}+ error={error}+ onSelect={setSelectedEntry}+ onSearchValueChange={setSearchValue}+ onFilterOptionsChange={setFilterOptions}+ />+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/index.tsnew file mode 100644index 00000000000..d76e5ec6f4a--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/index.ts@@ -0,0 +1 @@+export * from "./UnreferencedDependencyListPage";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsxindex 74c8a24ddb2..8a4287dc564 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx@@ -1,7 +1,19 @@-import { IndexRoute } from "react-router";+import { IndexRedirect, IndexRoute, Route } from "react-router";+import { BrokenDependencyListPage } from "./pages/BrokenDependencyListPage";import { DependencyGraphPage } from "./pages/DependencyGraphPage";+import { UnreferencedDependencyListPage } from "./pages/UnreferencedDependencyListPage";export function getDataStudioDependencyRoutes() {return <IndexRoute component={DependencyGraphPage} />;}++export function getDataStudioTasksRoutes() {+ return (+ <>+ <IndexRedirect to="broken" />+ <Route path="broken" component={BrokenDependencyListPage} />+ <Route path="unreferenced" component={UnreferencedDependencyListPage} />+ </>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/types.tsindex 910df0c50cd..4f4c6f2f70a 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts@@ -1,4 +1,28 @@-export type DependencyGraphRawParams = {- id?: string;- type?: string;+import type { IconName } from "metabase/ui";+import type { DependencyGroupType } from "metabase-types/api";++export type NodeId = string;++export type DependencyGroupTypeInfo = {+ label: string;+ color: string;+};++export type NodeLink = {+ label: string;+ url: string;+};++export type NodeLocationInfo = {+ icon: IconName;+ links: NodeLink[];+};++export type DependencyErrorInfo = {+ label: string;+ detail: string | null;+};++export type DependencyFilterOptions = {+ groupTypes: DependencyGroupType[];};diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.tsnew file mode 100644index 00000000000..dcf5d91c9b5--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts@@ -0,0 +1,628 @@+import { msgid, ngettext, t } from "ttag";++import * as Urls from "metabase/lib/urls";+import type { IconName } from "metabase/ui";+import visualizations from "metabase/visualizations";+import type {+ CardType,+ DependencyEntry,+ DependencyError,+ DependencyErrorType,+ DependencyGroupType,+ DependencyId,+ DependencyNode,+ DependencyType,+ LastEditInfo,+ UserInfo,+ VisualizationDisplay,+} from "metabase-types/api";++import type {+ DependencyErrorInfo,+ DependencyGroupTypeInfo,+ NodeId,+ NodeLink,+ NodeLocationInfo,+} from "./types";++export function isSameNode(+ entry1: DependencyEntry,+ entry2: DependencyEntry,+): boolean {+ return entry1.id === entry2.id && entry1.type === entry2.type;+}++export function getNodeId(id: DependencyId, type: DependencyType): NodeId {+ return `${id}-${type}`;+}++export function getNodeLabel(node: DependencyNode): string {+ switch (node.type) {+ case "table":+ return node.data.display_name;+ case "sandbox":+ return node.data.table?.display_name ?? t`Row and column security rule`;+ default:+ return node.data.name;+ }+}++export function getNodeDescription(node: DependencyNode): string | null {+ switch (node.type) {+ case "document":+ case "sandbox":+ return null;+ default:+ return node.data.description ?? "";+ }+}++export function getNodeIcon(node: DependencyNode): IconName {+ return getNodeIconWithType(+ node.type,+ node.type === "card" ? node.data.type : undefined,+ node.type === "card" ? node.data.display : undefined,+ );+}++export function getNodeIconWithType(+ type: DependencyType,+ cardType?: CardType,+ cardDisplay?: VisualizationDisplay,+): IconName {+ switch (type) {+ case "card":+ switch (cardType) {+ case "question":+ return cardDisplay != null+ ? (visualizations.get(cardDisplay)?.iconName ?? "table2")+ : "table2";+ case "model":+ return "model";+ case "metric":+ return "metric";+ default:+ return "table2";+ }+ case "table":+ return "table";+ case "transform":+ return "transform";+ case "snippet":+ return "sql";+ case "dashboard":+ return "dashboard";+ case "document":+ return "document";+ case "sandbox":+ return "permissions_limited";+ case "segment":+ return "segment";+ case "measure":+ return "sum";+ }+}++function getCardLinkLabel(cardType: CardType): string {+ switch (cardType) {+ case "question":+ return t`View this question`;+ case "model":+ return t`View this model`;+ case "metric":+ return t`View this metric`;+ }+}++export function getNodeLink(node: DependencyNode): NodeLink | null {+ switch (node.type) {+ case "card":+ return {+ label: getCardLinkLabel(node.data.type),+ url: Urls.question({+ id: node.id,+ name: node.data.name,+ type: node.data.type,+ }),+ };+ case "table":+ return {+ label: t`View metadata`,+ url: Urls.dataStudioData({+ databaseId: node.data.db_id,+ schemaName: node.data.schema,+ tableId: node.id,+ }),+ };+ case "transform":+ return {+ label: t`View this transform`,+ url: Urls.transform(node.id),+ };+ case "dashboard":+ return {+ label: `View this dashboard`,+ url: Urls.dashboard({ id: node.id, name: node.data.name }),+ };+ case "document":+ return {+ label: `View this document`,+ url: Urls.document({ id: node.id }),+ };+ case "sandbox":+ if (node.data.table != null) {+ return {+ label: `View this permission`,+ url: Urls.tableDataPermissions(+ node.data.table.db_id,+ node.data.table.schema,+ node.data.table.id,+ ),+ };+ }+ return null;+ case "segment":+ if (node.data.table != null) {+ return {+ label: t`View this segment`,+ url: Urls.dataStudioDataModelSegment({+ databaseId: node.data.table.db_id,+ schemaName: node.data.table.schema,+ tableId: node.data.table.id,+ segmentId: node.id,+ }),+ };+ }+ return null;+ case "measure":+ if (node.data.table != null) {+ return {+ label: t`View this measure`,+ url: Urls.dataStudioDataModelMeasure({+ databaseId: node.data.table.db_id,+ schemaName: node.data.table.schema,+ tableId: node.data.table.id,+ measureId: node.id,+ }),+ };+ }+ return null;+ case "snippet":+ return {+ label: t`View this snippet`,+ url: Urls.dataStudioSnippet(node.id),+ };+ }+}++export function getNodeLocationInfo(+ node: DependencyNode,+): NodeLocationInfo | null {+ switch (node.type) {+ case "card":+ if (node.data.dashboard != null) {+ return {+ icon: "dashboard",+ links: [+ {+ label: node.data.dashboard.name,+ url: Urls.dashboard(node.data.dashboard),+ },+ ],+ };+ }+ if (node.data.document != null) {+ return {+ icon: "document",+ links: [+ {+ label: node.data.document.name,+ url: Urls.document(node.data.document),+ },+ ],+ };+ }+ if (node.data.collection != null) {+ return {+ icon: "collection",+ links: [+ {+ label: node.data.collection.name,+ url: Urls.collection(node.data.collection),+ },+ ],+ };+ }+ return null;+ case "table":+ if (node.data.db != null) {+ return {+ icon: "database",+ links: [+ {+ label: node.data.db.name,+ url: Urls.dataStudioData({ databaseId: node.data.db_id }),+ },+ {+ label: node.data.schema,+ url: Urls.dataStudioData({+ databaseId: node.data.db_id,+ schemaName: node.data.schema,+ }),+ },+ ],+ };+ }+ return null;+ case "dashboard":+ case "document":+ if (node.data.collection != null) {+ return {+ icon: "collection",+ links: [+ {+ label: node.data.collection.name,+ url: Urls.collection(node.data.collection),+ },+ ],+ };+ }+ return null;+ case "segment":+ if (node.data.table != null) {+ return {+ icon: "table",+ links: [+ {+ label: node.data.table.display_name,+ url: Urls.dataStudioData({+ databaseId: node.data.table.db_id,+ schemaName: node.data.table.schema,+ tableId: node.data.table.id,+ tab: "segments",+ }),+ },+ ],+ };+ }+ return null;+ case "measure":+ if (node.data.table != null) {+ return {+ icon: "table",+ links: [+ {+ label: node.data.table.display_name,+ url: Urls.dataStudioData({+ databaseId: node.data.table.db_id,+ schemaName: node.data.table.schema,+ tableId: node.data.table.id,+ tab: "measures",+ }),+ },+ ],+ };+ }+ return null;+ case "snippet":+ if (node.data.collection != null) {+ return {+ icon: "collection",+ links: [+ {+ label: node.data.collection.name,+ url: Urls.dataStudioLibrary(),+ },+ ],+ };+ }+ return null;+ case "transform":+ case "sandbox":+ return null;+ }+}++export function getNodeCreatedAt(node: DependencyNode): string | null {+ switch (node.type) {+ case "card":+ case "dashboard":+ case "document":+ case "segment":+ case "measure":+ case "snippet":+ case "transform":+ return node.data.created_at;+ case "table":+ case "sandbox":+ return null;+ }+}++export function getNodeCreatedBy(node: DependencyNode): UserInfo | null {+ switch (node.type) {+ case "card":+ case "dashboard":+ case "document":+ case "segment":+ case "measure":+ case "snippet":+ case "transform":+ return node.data.creator ?? null;+ case "table":+ case "sandbox":+ return null;+ }+}++export function getNodeLastEditedAt(node: DependencyNode): string | null {+ switch (node.type) {+ case "card":+ case "dashboard":+ return node.data["last-edit-info"]?.timestamp ?? null;+ case "segment":+ case "measure":+ case "table":+ case "transform":+ case "snippet":+ case "document":+ case "sandbox":+ return null;+ }+}++export function getNodeLastEditedBy(node: DependencyNode): LastEditInfo | null {+ switch (node.type) {+ case "card":+ case "dashboard":+ return node.data["last-edit-info"] ?? null;+ case "segment":+ case "measure":+ case "table":+ case "transform":+ case "snippet":+ case "document":+ case "sandbox":+ return null;+ }+}++export function getNodeViewCount(node: DependencyNode): number | null {+ switch (node.type) {+ case "card":+ // view_count is not calculated property for models and metrics since+ // they are typically not run directly+ return node.data.type === "question"+ ? (node.data.view_count ?? null)+ : null;+ case "dashboard":+ case "document":+ return node.data.view_count ?? null;+ case "table":+ case "measure":+ case "transform":+ case "snippet":+ case "sandbox":+ case "segment":+ return null;+ }+}++export function getNodeDependentsCount(node: DependencyNode): number {+ const dependentsCount = node.dependents_count;+ if (dependentsCount == null) {+ return 0;+ }+ return Object.values(dependentsCount).reduce(+ (total, count) => total + count,+ 0,+ );+}++export function getCardType(groupType: DependencyGroupType): CardType | null {+ switch (groupType) {+ case "question":+ case "model":+ case "metric":+ return groupType;+ default:+ return null;+ }+}++export function getDependencyType(+ groupType: DependencyGroupType,+): DependencyType {+ switch (groupType) {+ case "question":+ case "model":+ case "metric":+ return "card";+ default:+ return groupType;+ }+}++export function getDependencyGroupType(+ node: DependencyNode,+): DependencyGroupType {+ switch (node.type) {+ case "card":+ return node.data.type;+ case "table":+ return "table";+ case "transform":+ return "transform";+ case "dashboard":+ return "dashboard";+ case "document":+ return "document";+ case "sandbox":+ return "sandbox";+ case "segment":+ return "segment";+ case "measure":+ return "measure";+ case "snippet":+ return "snippet";+ }+}++export function getDependencyGroupTypeInfo(+ groupType: DependencyGroupType,+): DependencyGroupTypeInfo {+ switch (groupType) {+ case "question":+ return { label: t`Question`, color: "text-secondary" };+ case "model":+ return { label: t`Model`, color: "brand" };+ case "metric":+ return { label: t`Metric`, color: "summarize" };+ case "table":+ return { label: t`Table`, color: "brand" };+ case "transform":+ return { label: t`Transform`, color: "warning" };+ case "snippet":+ return { label: t`Snippet`, color: "text-secondary" };+ case "dashboard":+ return { label: t`Dashboard`, color: "filter" };+ case "document":+ return { label: t`Document`, color: "text-secondary" };+ case "sandbox":+ return { label: t`Row and column security rule`, color: "error" };+ case "segment":+ return { label: t`Segment`, color: "accent2" };+ case "measure":+ return { label: t`Measure`, color: "summarize" };+ }+}++export function getDependencyTypes(+ groupTypes: DependencyGroupType[],+): DependencyType[] {+ const types = groupTypes.map(getDependencyType);+ return Array.from(new Set(types));+}++export function getCardTypes(groupTypes: DependencyGroupType[]): CardType[] {+ const cardTypes = groupTypes+ .map(getCardType)+ .filter((cardType) => cardType !== null);+ return Array.from(new Set(cardTypes));+}++export function getDependencyErrorTypeLabel(type: DependencyErrorType): string {+ switch (type) {+ case "validate/missing-column":+ return t`Missing column`;+ case "validate/missing-table-alias":+ return t`Missing table alias`;+ case "validate/duplicate-column":+ return t`Duplicate column`;+ case "validate/syntax-error":+ return t`Syntax error`;+ case "validate/validation-error":+ return t`Unknown error`;+ }+}++export function getDependencyErrorTypeCountMessage(+ type: DependencyErrorType,+ count: number,+): string {+ switch (type) {+ case "validate/missing-column":+ return ngettext(+ msgid`${count} missing column`,+ `${count} missing columns`,+ count,+ );+ case "validate/missing-table-alias":+ return ngettext(+ msgid`${count} missing table alias`,+ `${count} missing table aliases`,+ count,+ );+ case "validate/duplicate-column":+ return ngettext(+ msgid`${count} duplicate column`,+ `${count} duplicate columns`,+ count,+ );+ case "validate/syntax-error":+ return ngettext(+ msgid`${count} syntax error`,+ `${count} syntax errors`,+ count,+ );+ case "validate/validation-error":+ return ngettext(+ msgid`${count} unknown error`,+ `${count} unknown errors`,+ count,+ );+ }+}++export function getDependencyErrorDetail(+ error: DependencyError,+): string | null {+ switch (error.type) {+ case "validate/missing-column":+ case "validate/missing-table-alias":+ case "validate/duplicate-column":+ return error.name;+ case "validate/syntax-error":+ case "validate/validation-error":+ return null;+ }+}++export function getDependencyErrorInfo(+ errors: DependencyError[],+): DependencyErrorInfo | undefined {+ if (errors.length === 0) {+ return undefined;+ }++ if (errors.length === 1) {+ const [error] = errors;+ const label = getDependencyErrorTypeLabel(error.type);+ const detail = getDependencyErrorDetail(error);+ return { label, detail };+ }++ const types = new Set(errors.map((error) => error.type));+ if (types.size === 1) {+ const [type] = types;+ return {+ label: getDependencyErrorTypeCountMessage(type, errors.length),+ detail: null,+ };+ }++ return {+ label: ngettext(+ msgid`${errors.length} error`,+ `${errors.length} errors`,+ errors.length,+ ),+ detail: null,+ };+}++export function parseEnum<T extends string>(+ value: unknown,+ items: readonly T[],+): T | undefined {+ if (typeof value !== "string") {+ return undefined;+ }+ const item = items.find((item) => item === value);+ return item != null ? item : undefined;+}++export function getSearchQuery(searchValue: string): string | undefined {+ const searchQuery = searchValue.trim();+ return searchQuery.length > 0 ? searchQuery : undefined;+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.tssimilarity index 95%rename from enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.unit.spec.tsrename to enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.tsindex 4586fb2f481..b2e46b3106f 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.unit.spec.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts@@ -62,7 +62,7 @@ describe("getNodeIcon", () => {node: createMockSnippetDependencyNode(),expectedIcon: "sql",},- ])("should get the node icon", ({ node, expectedIcon }) => {+ ])("should get the $node.type node icon", ({ node, expectedIcon }) => {expect(getNodeIcon(node)).toBe(expectedIcon);});});@@ -139,7 +139,7 @@ describe("getNodeLink", () => {url: "/data-studio/data/database/1/schema/1:public/table/1/segments/1",},},- ])("should get the node link", ({ node, expectedLink }) => {+ ])("should get the $node.type node link", ({ node, expectedLink }) => {expect(getNodeLink(node)).toEqual(expectedLink);});});diff --git a/frontend/src/metabase-types/api/card.ts b/frontend/src/metabase-types/api/card.tsindex b4c56dd106a..bc8cc05b618 100644--- a/frontend/src/metabase-types/api/card.ts+++ b/frontend/src/metabase-types/api/card.ts@@ -84,6 +84,7 @@ export interface Card<Q extends DatasetQuery = DatasetQuery>creator?: UserInfo;"last-edit-info"?: LastEditInfo;table_id?: TableId;+ view_count?: number;download_perms?: DownloadPermission;}diff --git a/frontend/src/metabase-types/api/dashboard.ts b/frontend/src/metabase-types/api/dashboard.tsindex 97ee42967bf..d70c1dbe23c 100644--- a/frontend/src/metabase-types/api/dashboard.ts+++ b/frontend/src/metabase-types/api/dashboard.ts@@ -87,6 +87,7 @@ export interface Dashboard {param_fields?: Record<ParameterId, Field[]>;moderation_reviews: ModerationReview[];+ view_count?: number;/* Indicates whether static embedding for this dashboard has been published */enable_embedding: boolean;diff --git a/frontend/src/metabase-types/api/dependencies.ts b/frontend/src/metabase-types/api/dependencies.tsindex 02091dac5fd..a73f88d7d18 100644--- a/frontend/src/metabase-types/api/dependencies.ts+++ b/frontend/src/metabase-types/api/dependencies.ts@@ -13,17 +13,34 @@ import type { Table, TableId } from "./table";import type { Transform } from "./transform";export type DependencyId = number;-export type DependencyType =- | "card"- | "table"- | "transform"- | "snippet"- | "dashboard"- | "document"- | "sandbox"- | "segment"- | "measure";-export type DependencyGroupType = CardType | Exclude<DependencyType, "card">;++export const DEPENDENCY_TYPES = [+ "card",+ "table",+ "transform",+ "snippet",+ "dashboard",+ "document",+ "sandbox",+ "segment",+ "measure",+] as const;+export type DependencyType = (typeof DEPENDENCY_TYPES)[number];++export const DEPENDENCY_GROUP_TYPES = [+ "question",+ "model",+ "metric",+ "table",+ "transform",+ "snippet",+ "dashboard",+ "document",+ "sandbox",+ "segment",+ "measure",+] as const;+export type DependencyGroupType = (typeof DEPENDENCY_GROUP_TYPES)[number];export type DependencyEntry = {id: DependencyId;@@ -36,6 +53,7 @@ type BaseDependencyNode<TType extends DependencyType, TData> = {id: DependencyId;type: TType;data: TData;+ errors?: DependencyError[] | null;dependents_count?: DependentsCount | null;};@@ -46,7 +64,7 @@ export type TableDependencyNodeData = Pick<export type TransformDependencyNodeData = Pick<Transform,- "name" | "description" | "table"+ "name" | "description" | "table" | "creator" | "created_at">;export type CardDependencyNodeData = Pick<@@ -66,13 +84,18 @@ export type CardDependencyNodeData = Pick<| "creator"| "created_at"| "last-edit-info"-> & {- view_count?: number | null;-};+ | "view_count"+>;export type SnippetDependencyNodeData = Pick<NativeQuerySnippet,- "name" | "description"+ | "name"+ | "description"+ | "creator_id"+ | "creator"+ | "created_at"+ | "collection_id"+ | "collection">;export type DashboardDependencyNodeData = Pick<@@ -85,16 +108,18 @@ export type DashboardDependencyNodeData = Pick<| "collection_id"| "collection"| "moderation_reviews"-> & {- view_count?: number | null;-};+ | "view_count"+>;export type DocumentDependencyNodeData = Pick<Document,- "name" | "created_at" | "creator" | "collection_id" | "collection"-> & {- view_count?: number | null;-};+ | "name"+ | "created_at"+ | "creator"+ | "collection_id"+ | "collection"+ | "view_count"+>;export type SandboxDependencyNodeData = {table_id: TableId;@@ -171,6 +196,47 @@ export type DependencyNode =| SegmentDependencyNode| MeasureDependencyNode;+export const DEPENDENCY_ERROR_TYPES = [+ "validate/missing-column",+ "validate/missing-table-alias",+ "validate/duplicate-column",+ "validate/syntax-error",+ "validate/validation-error",+] as const;+export type DependencyErrorType = (typeof DEPENDENCY_ERROR_TYPES)[number];++type BaseDependencyError<TType extends DependencyErrorType> = {+ type: TType;+};++export type MissingColumnDependencyError =+ BaseDependencyError<"validate/missing-column"> & {+ name: string;+ };++export type MissingTableAliasDependencyError =+ BaseDependencyError<"validate/missing-table-alias"> & {+ name: string;+ };++export type DuplicateColumnDependencyError =+ BaseDependencyError<"validate/duplicate-column"> & {+ name: string;+ };++export type SyntaxErrorDependencyError =+ BaseDependencyError<"validate/syntax-error">;++export type ValidationErrorDependencyError =+ BaseDependencyError<"validate/validation-error">;++export type DependencyError =+ | MissingColumnDependencyError+ | MissingTableAliasDependencyError+ | DuplicateColumnDependencyError+ | SyntaxErrorDependencyError+ | ValidationErrorDependencyError;+export type DependencyEdge = {from_entity_id: DependencyId;from_entity_type: DependencyType;@@ -210,3 +276,15 @@ export type CheckSnippetDependenciesRequest = Pick<NativeQuerySnippet, "id"> &export type CheckTransformDependenciesRequest = Pick<Transform, "id"> &Partial<Pick<Transform, "source">>;++export type ListBrokenGraphNodesRequest = {+ types?: DependencyType[];+ card_types?: CardType[];+ query?: string;+};++export type ListUnreferencedGraphNodesRequest = {+ types?: DependencyType[];+ card_types?: CardType[];+ query?: string;+};diff --git a/frontend/src/metabase-types/api/document.ts b/frontend/src/metabase-types/api/document.tsindex 031157a5068..51c85e76a21 100644--- a/frontend/src/metabase-types/api/document.ts+++ b/frontend/src/metabase-types/api/document.ts@@ -26,6 +26,7 @@ export type Document = {public_uuid?: string | null;made_public_by_id?: UserId | null;cards?: Record<number, Card>; // Map of card ID -> card metadata, hydrated for public documents+ view_count?: number;};export type GetDocumentRequest = { id: DocumentId };diff --git a/frontend/src/metabase-types/api/mocks/dependencies.ts b/frontend/src/metabase-types/api/mocks/dependencies.tsindex 7829a685308..a62acdd026f 100644--- a/frontend/src/metabase-types/api/mocks/dependencies.ts+++ b/frontend/src/metabase-types/api/mocks/dependencies.ts@@ -47,6 +47,7 @@ export function createMockTransformDependencyNodeData(return {name: "Transform",description: null,+ created_at: "2020-01-01T00:00:00Z",...opts,};}@@ -144,6 +145,9 @@ export function createMockSnippetDependencyNodeData(return {name: "Snippet",description: null,+ created_at: "2020-01-01T00:00:00Z",+ creator_id: 1,+ collection_id: null,...opts,};}diff --git a/frontend/src/metabase-types/api/snippets.ts b/frontend/src/metabase-types/api/snippets.tsindex e81bb9e7d7e..321a3ede2e5 100644--- a/frontend/src/metabase-types/api/snippets.ts+++ b/frontend/src/metabase-types/api/snippets.ts@@ -1,4 +1,4 @@-import type { RegularCollectionId } from "./collection";+import type { Collection, RegularCollectionId } from "./collection";import type { TemplateTags } from "./dataset";import type { BaseEntityId } from "./entity-id";import type { UserId, UserInfo } from "./user";@@ -13,11 +13,13 @@ export interface NativeQuerySnippet {template_tags: TemplateTags | null;collection_id: RegularCollectionId | null;creator_id: UserId;- creator: UserInfo;archived: boolean;entity_id: BaseEntityId;created_at: string;updated_at: string;++ creator?: UserInfo;+ collection?: Collection;}export interface ListSnippetsParams {diff --git a/frontend/src/metabase-types/api/transform.ts b/frontend/src/metabase-types/api/transform.tsindex 79170d80b4b..ef8fb7e5e78 100644--- a/frontend/src/metabase-types/api/transform.ts+++ b/frontend/src/metabase-types/api/transform.ts@@ -4,6 +4,7 @@ import type { PaginationRequest, PaginationResponse } from "./pagination";import type { DatasetQuery } from "./query";import type { ScheduleDisplayType } from "./settings";import type { ConcreteTableId, Table } from "./table";+import type { UserInfo } from "./user";export type TransformId = number;export type TransformTagId = number;@@ -24,6 +25,7 @@ export type Transform = {tag_ids?: TransformTagId[];table?: Table | null;last_run?: TransformRun | null;+ creator?: UserInfo;};export type SuggestedTransform = Partial<Pick<Transform, "id">> &diff --git a/frontend/src/metabase/common/components/EntityCreationInfo/EntityCreationInfo.tsx b/frontend/src/metabase/common/components/EntityCreationInfo/EntityCreationInfo.tsxindex f73daa6872d..2c3ba901766 100644--- a/frontend/src/metabase/common/components/EntityCreationInfo/EntityCreationInfo.tsx+++ b/frontend/src/metabase/common/components/EntityCreationInfo/EntityCreationInfo.tsx@@ -10,6 +10,7 @@ type EntityCreationInfoProps = {creator?: UserInfo | null;lastEditedAt?: string | null;lastEditor?: LastEditInfo | null;+ withTitle?: boolean;};export function EntityCreationInfo({@@ -17,6 +18,7 @@ export function EntityCreationInfo({creator,lastEditedAt,lastEditor,+ withTitle = true,}: EntityCreationInfoProps) {const hasCreatedInfo = createdAt != null && creator != null;const hasEditedInfo = lastEditedAt != null && lastEditor != null;@@ -27,9 +29,13 @@ export function EntityCreationInfo({return (<Stack gap="sm" lh="1rem">- <Title order={6}>{t`Creator and last editor`}</Title>+ {withTitle && <Title order={6}>{t`Creator and last editor`}</Title>}{createdAt != null && creator != null && (- <Group gap="sm" wrap="nowrap">+ <Group+ gap="sm"+ wrap="nowrap"+ data-testid="entity-creation-info-created"+ ><FixedSizeIcon name="ai" /><Box>{c(@@ -41,7 +47,7 @@ export function EntityCreationInfo({</Group>)}{lastEditedAt != null && lastEditor != null && (- <Group gap="sm" wrap="nowrap">+ <Group gap="sm" wrap="nowrap" data-testid="entity-creation-info-edited"><FixedSizeIcon name="pencil" /><Box>{c(diff --git a/frontend/src/metabase/lib/urls/data-studio.ts b/frontend/src/metabase/lib/urls/data-studio.tsindex 2e84c3afe91..18c69b237f4 100644--- a/frontend/src/metabase/lib/urls/data-studio.ts+++ b/frontend/src/metabase/lib/urls/data-studio.ts@@ -296,3 +296,27 @@ export function dataStudioSnippetDependencies(snippetId: NativeQuerySnippetId) {export function newDataStudioSnippet() {return `${dataStudioLibrary()}/snippets/new`;}++export function dataStudioSegment(segmentId: SegmentId) {+ return `${dataStudioLibrary()}/segments/${segmentId}`;+}++export function newDataStudioSegment(tableId: TableId) {+ return `${dataStudioLibrary()}/segments/new?tableId=${tableId}`;+}++export function dataStudioSegmentDependencies(segmentId: SegmentId) {+ return `${dataStudioSegment(segmentId)}/dependencies`;+}++export function dataStudioTasks() {+ return `${ROOT_URL}/tasks`;+}++export function dataStudioBrokenEntities() {+ return `${dataStudioTasks()}/broken`;+}++export function dataStudioUnreferencedEntities() {+ return `${dataStudioTasks()}/unreferenced`;+}diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsxindex e3072ac4db4..999168f0d73 100644--- a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx+++ b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx@@ -40,6 +40,7 @@ export const SearchInputContainer = styled.div<{}return css`background-color: var(--mb-color-background-primary);+&:hover {background-color: var(--mb-color-background-secondary);}diff --git a/frontend/src/metabase/plugins/oss/transforms.ts b/frontend/src/metabase/plugins/oss/transforms.tsindex 5feedb421dc..52454db7714 100644--- a/frontend/src/metabase/plugins/oss/transforms.ts+++ b/frontend/src/metabase/plugins/oss/transforms.ts@@ -76,6 +76,7 @@ export type PythonTransformsPlugin = {type DependenciesPlugin = {isEnabled: boolean;getDataStudioDependencyRoutes: () => ReactNode;+ getDataStudioTasksRoutes: () => ReactNode;DependencyGraphPage: ComponentType;DependencyGraphPageContext: Context<DependencyGraphPageContextType>;CheckDependenciesForm: ComponentType<CheckDependenciesFormProps>;@@ -166,6 +167,7 @@ export const PLUGIN_TRANSFORMS_PYTHON = getDefaultPluginTransformsPython();const getDefaultPluginDependencies = (): DependenciesPlugin => ({isEnabled: false,getDataStudioDependencyRoutes: () => null,+ getDataStudioTasksRoutes: () => null,DependencyGraphPage: PluginPlaceholder,DependencyGraphPageContext: createContext({}),CheckDependenciesForm: PluginPlaceholder,diff --git a/resources/migrations/059_update_migrations.yaml b/resources/migrations/059_update_migrations.yamlindex 9fe0983dd15..d821fdf8fc1 100644--- a/resources/migrations/059_update_migrations.yaml+++ b/resources/migrations/059_update_migrations.yaml@@ -148,3 +148,144 @@ databaseChangeLog:- dropForeignKeyConstraint:baseTableName: measureconstraintName: fk_measure_ref_creator_id++ - changeSet:+ id: v59.2026-01-07T00:00:01+ author: bshepherdson+ comment: Create analysis finding table+ changes:+ - createTable:+ tableName: analysis_finding+ remarks: Findings from analysis of cards, transforms, dashboards, etc.+ columns:+ - column:+ name: id+ remarks: Unique ID+ type: int+ autoIncrement: true+ constraints:+ primaryKey: true+ nullable: false+ - column:+ name: analyzed_entity_type+ type: varchar(254)+ remarks: The type of the analyzed entity+ constraints:+ nullable: false+ - column:+ name: analyzed_entity_id+ type: int+ remarks: The ID of the analyzed entity+ constraints:+ nullable: false+ - column:+ name: analysis_version+ remarks: The version of the analysis that was performed+ type: int+ constraints:+ nullable: false+ - column:+ name: analyzed_at+ remarks: The timestamp of when the analysis was performed+ type: ${timestamp_type}+ defaultValueComputed: current_timestamp+ constraints:+ nullable: false+ - column:+ name: result+ type: ${boolean.type}+ remarks: The result of the analysis - true for passed, false for failed+ constraints:+ nullable: false+ - column:+ name: finding_details+ type: ${text.type}+ remarks: Arbitrary EDN text of the findings+ constraints:+ nullable: true++ - changeSet:+ id: v59.2026-01-07T00:00:02+ author: bshepherdson+ comment: Unique constraint to prevent duplicate analyses+ changes:+ - addUniqueConstraint:+ tableName: analysis_finding+ columnNames: analyzed_entity_type, analyzed_entity_id+ constraintName: idx_unique_analysis_finding++ - changeSet:+ id: v59.2026-01-07T00:00:03+ author: bshepherdson+ comment: Index for analysis_finding by analyzed entity+ changes:+ - createIndex:+ tableName: analysis_finding+ indexName: idx_analyzed_entity+ columns:+ - column:+ name: analyzed_entity_type+ - column:+ name: analyzed_entity_id++ - changeSet:+ id: v59.2026-01-07T00:00:04+ author: bshepherdson+ comment: Index for analysis_finding by analysis result+ changes:+ - createIndex:+ tableName: analysis_finding+ indexName: idx_analysis_result+ columns:+ - column:+ name: result++# >>>>>>>>>> DO NOT ADD NEW MIGRATIONS BELOW THIS LINE! ADD THEM ABOVE <<<<<<<<<<++########################################################################################################################+#+# ADVICE:+#+# 1) Think through some of these points when writing a migration, learn from our past mistakes:+# - Do you really need a migration? Could the feature work without it? Prefer not to if possible.+# Data in the wild can be vastly different from what you expect, and it's hard to get right.+# - Make sure your migration is backward compatible: it might not be possible to add a constraint back+# if you drop it in a migration.+# - Postgres, MySQL and H2 have their differences. Make sure your migration works for all.+# - Database encryption is a major issue:+# - Fields like `metabase_database.details` or `setting.value` can be encrypted, so you need to decrypt them in+# your migration. See #42617, #44048.+# - Database could be partially encrypted, see https://www.notion.so/72575933ef2a446bafd16909e05a7387+# - Custom migrations:+# - Prefer SQL migrations when possible.+# - Never use application code: it can change and *will* break your migration.+# - Do not use Toucan models - refer table names directly.+# - If it's a big change, consider using Quartz, see #42279+# - More in `metabase.app_db.custom_migrations` namespace doc.+# - Never delete a migration: users won't be able to downgrade. If you really need to, see #44908+# - Migration id (`vXX.<date>`) must match its earliest released version:+# - Do not backport `v51....` to version 50, Metabase will try to downgrade it.+# - Instead, write a migration with an oldest target you plan to backport to in mind.+#+# 2) Migrations should go in the ###_update_migrations.yaml file for the target version.+#+# 3) Run mage lint-migrations to run core.spec checks against any changes you make here. Liquibase is pretty+# forgiving and won't complain if you accidentally mix up things like deleteCascade and onDelete: CASCADE. CI runs+# this check but it's nicer to know now instead of waiting for CI.+#+# 3) Migration IDs should follow the format+#+# vMM.TIMESTAMP+#+# Where+#+# M = major version+# TIMESTAMP = the current timestamp with format `yyyy-MM-dd'T'HH:mm:ss`+# To get this timestamp, evaluate this in your REPL: `(dev/migration-timestamp)`+#+# E.g: You're adding a new migration for version 49, And it's 10:30:00AM on April 1, 2023 (UTC),+# your migration id should be: `v49.2023-04-01T10:30:00`.+#+# PLEASE KEEP THIS MESSAGE AT THE BOTTOM OF THIS FILE!!!!! Add new migrations above the message.+#+########################################################################################################################diff --git a/src/metabase/collections/models/collection/root.clj b/src/metabase/collections/models/collection/root.cljindex b155682403a..0da932cc0bf 100644--- a/src/metabase/collections/models/collection/root.clj+++ b/src/metabase/collections/models/collection/root.clj@@ -67,10 +67,13 @@:is_remote_synced false))(defn hydrated-root-collection- "Return the root collection entity."- []- (-> (root-collection-with-ui-details nil)- (hydrate :can_write)))+ "Return the root collection entity for the given namespace.+ By default, returns the root collection for the non-namespaced collection subtree."+ ([]+ (hydrated-root-collection nil))+ ([collection-namespace]+ (-> (root-collection-with-ui-details collection-namespace)+ (hydrate :can_write))))(defn hydrate-root-collection"Hydrate `:collection` onto entity when the id is `nil`."diff --git a/src/metabase/collections_rest/api.clj b/src/metabase/collections_rest/api.cljindex 7ecfb0f0e43..f50863117d3 100644--- a/src/metabase/collections_rest/api.clj+++ b/src/metabase/collections_rest/api.clj@@ -547,7 +547,7 @@(when-not show-dashboard-questions?[:= :c.dashboard_id nil])[:= :c.document_id nil]- [:= :archived (boolean archived?)]+ [:= :c.archived (boolean archived?)](case card-type:model[:= :c.type (h2x/literal "model")]@@ -620,7 +620,7 @@:d.archived_directly[(h2x/literal "dashboard") :model][:u.id :last_edit_user]- :archived+ :d.archived[:u.email :last_edit_email][:u.first_name :last_edit_first_name][:u.last_name :last_edit_last_name]@@ -643,7 +643,7 @@[:and[:= :d.collection_id (:id collection)][:not= :d.archived_directly true]])- [:= :archived (boolean archived?)]]}+ [:= :d.archived (boolean archived?)]]}(sql.helpers/where (pinned-state->clause pinned-state))))(defmethod collection-children-query :dashboarddiff --git a/src/metabase/documents/models/document.clj b/src/metabase/documents/models/document.cljindex 00dc7181e3b..4ed83285fc3 100644--- a/src/metabase/documents/models/document.clj+++ b/src/metabase/documents/models/document.clj@@ -4,6 +4,7 @@[metabase.api.common :as api][metabase.collections.models.collection :as collection][metabase.documents.prose-mirror :as prose-mirror]+ [metabase.events.core :as events][metabase.models.interface :as mi][metabase.models.serialization :as serdes][metabase.public-sharing.core :as public-sharing]@@ -97,6 +98,7 @@(sync-document-cards-collection! id collection_id:archived archived:archived-directly archived_directly)+ (events/publish-event! :event/document-update {:object instance})instance)(t2/define-after-select :model/Documentdiff --git a/src/metabase/documents/schema.clj b/src/metabase/documents/schema.cljnew file mode 100644index 00000000000..0e91c611e57--- /dev/null+++ b/src/metabase/documents/schema.clj@@ -0,0 +1,12 @@+(ns metabase.documents.schema+ (:require+ [metabase.util.malli.registry :as mr]))++(mr/def ::document.id+ "Valid Document ID"+ pos-int?)++(mr/def ::document+ "Schema for an instance of a `:model/Document`."+ [:map+ [:id ::document.id]])diff --git a/src/metabase/driver/common/parameters/parse.clj b/src/metabase/driver/common/parameters/parse.cljindex 2cd21ac4d6e..353357022b4 100644--- a/src/metabase/driver/common/parameters/parse.clj+++ b/src/metabase/driver/common/parameters/parse.clj@@ -26,7 +26,7 @@(match [value][s :guard string?] s[{:type :metabase.lib.parse/param- :name name}] (params/->Param (str/trim name))+ :name name}] (params/->Param (or (lib/match-and-normalize-tag-name name) (str/trim name)))[{:type :metabase.lib.parse/optional:contents contents}] (params/->Optional (map ->param contents))))diff --git a/src/metabase/driver/common/parameters/values.clj b/src/metabase/driver/common/parameters/values.cljindex 75e2ccfbe48..2b7ca4f245e 100644--- a/src/metabase/driver/common/parameters/values.clj+++ b/src/metabase/driver/common/parameters/values.clj@@ -484,7 +484,7 @@:let [v (value-for-tag tag params)]](do(log/tracef "Value for tag %s\n%s\n->\n%s" (pr-str k) (u/pprint-to-str tag) (u/pprint-to-str v))- [k v])))+ [(or (lib/match-and-normalize-tag-name k) k) v])))(catch Throwable e(throw (ex-info (tru "Error building query parameter map: {0}" (ex-message e)){:type (or (:type (ex-data e)) qp.error-type/invalid-parameter)diff --git a/src/metabase/driver/sql.clj b/src/metabase/driver/sql.cljindex 37d43fa431f..345b2f2b730 100644--- a/src/metabase/driver/sql.clj+++ b/src/metabase/driver/sql.clj@@ -219,8 +219,10 @@(find-table-or-transform driver (driver-api/tables metadata-provider) (driver-api/transforms metadata-provider)):table(driver-api/active-fields metadata-provider)- (map #(assoc % :lib/desired-column-alias (:name %))))- [(assoc col-spec ::bad-reference true)]))+ (map #(-> (assoc % :lib/desired-column-alias (:name %))+ sql.references/wrap-col)))+ [{:error (driver-api/missing-table-alias-error+ (sql.references/table-name (:table col-spec)))}]))(defmethod resolve-field :single-column[driver metadata-provider {:keys [alias] :as col-spec}]@@ -246,12 +248,12 @@:display-name (->> name (u.humanization/name->human-readable-name :simple)):effective-type :type/*:semantic-type :Semantic/*}])- (resolve-field driver metadata-provider current-col)))+ (keep :col (resolve-field driver metadata-provider current-col))))source-col-set)(some #(when (= (:name %) (:column col-spec))%))))))]- (assoc found :lib/desired-column-alias (or alias name))- (assoc col-spec ::bad-reference true))])+ {:col (assoc found :lib/desired-column-alias (or alias name))}+ {:error (driver-api/missing-column-error (:column col-spec))})])(defn- get-name [m](or (:alias m) (str (gensym "new-col"))))@@ -262,21 +264,17 @@(defmethod resolve-field :custom-field[_driver _metadata-provider col-spec]- [{:base-type :type/*- :name (get-name col-spec)- :lib/desired-column-alias (get-name col-spec)- :display-name (get-display-name col-spec)- :effective-type :type/*- :semantic-type :Semantic/*}])--(defmethod resolve-field :invalid-table-wildcard- [_driver _metadata-provider col-spec]- [(assoc col-spec ::bad-reference true)])+ [{:col {:base-type :type/*+ :name (get-name col-spec)+ :lib/desired-column-alias (get-name col-spec)+ :display-name (get-display-name col-spec)+ :effective-type :type/*+ :semantic-type :Semantic/*}}])(defn- lca [default-type & types](let [ancestor-sets (for [t types:when t]- (conj (ancestors t) t))+ (conj (set (ancestors t)) t))common-ancestors (when (seq ancestor-sets)(apply set/intersection ancestor-sets))](if (seq common-ancestors)@@ -285,14 +283,15 @@(defmethod resolve-field :composite-field[driver metadata-provider col-spec]- (let [member-fields (mapcat (partial resolve-field driver metadata-provider)+ (let [member-fields (mapcat #(->> (resolve-field driver metadata-provider %)+ (keep :col))(:member-fields col-spec))]- [{:name (get-name col-spec)- :lib/desired-column-alias (get-name col-spec)- :display-name (get-display-name col-spec)- :base-type (apply lca :type/* (map :base-type member-fields))- :effective-type (apply lca :type/* (map :effective-type member-fields))- :semantic-type (apply lca :Semantic/* (map :semantic-type member-fields))}]))+ [{:col {:name (get-name col-spec)+ :lib/desired-column-alias (get-name col-spec)+ :display-name (get-display-name col-spec)+ :base-type (apply lca :type/* (map :base-type member-fields))+ :effective-type (apply lca :type/* (map :effective-type member-fields))+ :semantic-type (apply lca :Semantic/* (map :semantic-type member-fields))}}]))(defmethod resolve-field :unknown-columns[_driver _metadata-provider _col-spec]@@ -306,26 +305,25 @@macaw/parsed-querymacaw/->ast(sql.references/field-references driver))]- (->> (mapcat (partial resolve-field driver native-query) returned-fields)- (remove ::bad-reference))))+ (mapcat #(->> (resolve-field driver native-query %)+ (keep :col))+ returned-fields)))-(mu/defmethod driver/validate-native-query-fields :sql+(mu/defmethod driver/validate-native-query-fields :sql :- [:set [:ref driver-api/schema.validate.error]][driver :- :keywordnative-query :- :metabase.lib.schema/native-only-query]- (let [{:keys [used-fields returned-fields bad-sql]} (->> native-query- driver-api/raw-native-query- macaw/parsed-query- macaw/->ast- (sql.references/field-references driver))+ (let [{:keys [used-fields returned-fields errors]} (->> native-query+ driver-api/raw-native-query+ macaw/parsed-query+ macaw/->ast+ (sql.references/field-references driver))check-fields #(mapcat (fn [col-spec](->> (resolve-field driver (driver-api/->metadata-provider native-query) col-spec)- (filter ::bad-reference)))+ (keep :error)))%)]- (-> (concat (when bad-sql- [{:error ::bad-sql}])- (check-fields used-fields)- (check-fields returned-fields))- distinct)))+ (-> errors+ (into (check-fields used-fields))+ (into (check-fields returned-fields)))));;; +----------------------------------------------------------------------------------------------------------------+;;; | Convenience Imports |diff --git a/src/metabase/driver/sql/references.clj b/src/metabase/driver/sql/references.cljindex 2a1b2152799..9d4d8c69c2f 100644--- a/src/metabase/driver/sql/references.clj+++ b/src/metabase/driver/sql/references.clj@@ -1,8 +1,10 @@(ns metabase.driver.sql.references(:refer-clojure :exclude [every? mapv select-keys some])(:require+ [clojure.string :as str][macaw.ast-types :as macaw.ast-types][metabase.driver :as driver]+ [metabase.driver-api.core :as driver-api][metabase.driver.sql.normalize :as sql.normalize][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]@@ -54,14 +56,13 @@[:all-columns [:ref ::all-columns]][:unknown-columns [:ref ::unknown-columns]][:custom-field [:ref ::custom-field]]- [:composite-field [:ref ::composite-field]]- [:invalid-table-wildcard [:ref ::invalid-table-wildcard]]])+ [:composite-field [:ref ::composite-field]]])(mr/def ::field-references[:map[:used-fields [:set [:ref ::col-spec]]][:returned-fields [:sequential [:ref ::col-spec]]]- [:bad-sql {:optional true} :boolean]])+ [:errors [:set [:ref driver-api/schema.validate.error]]]])(defn- normalize-fields [driver m](update-vals m@@ -88,6 +89,17 @@sublist))sources))+(mu/defn table-name :- [:maybe :string]+ "Computes a table name from a table reference"+ [raw-col :- [:map+ [:database {:optional true} :string]+ [:schema {:optional true} :string]+ [:table {:optional true} :string]]]+ (when (:table raw-col)+ (->> [:database :schema :table]+ (keep raw-col)+ (str/join "."))))+(defn- get-column [driver sources raw-col {:keys [return-table-matches?]}](if (and (nil? (:table raw-col))(nil? (:schema raw-col))@@ -115,18 +127,23 @@sources))](cond;; we have a direct column match- source-column [(cond-> source-column- alias (assoc :alias alias))]+ source-column [{:col (cond-> source-column+ alias (assoc :alias alias))}];; we have a match to a tablesource-matches (when return-table-matches?- [{:type :custom-field- :alias (or alias column)- :used-fields (set source-matches)}])- ;; we don't have a direct match, so show the possible columns this could match to- :else [(-> {:column column- :alias alias- :type :single-column}- (assoc :source-columns source-columns))]))))+ [{:col {:type :custom-field+ :alias (or alias column)+ :used-fields (set source-matches)}}])+ ;; we don't have a direct match, so list the possible sources+ :else [{:col {:column column+ :alias alias+ :type :single-column+ :source-columns source-columns}+ ;; if we didn't find any potential sources, signal an error here+ :errors (when-not (some #(some identity %) valid-sources)+ #{(if-let [name (table-name raw-col)]+ (driver-api/missing-table-alias-error name)+ (driver-api/missing-column-error column))})}]))))(defmulti find-used-fields"Finds the fields used in a given sql expression."@@ -202,37 +219,44 @@(defmethod find-returned-fields :default[driver sources withs {:keys [alias] :as expr}]- [{:alias (when alias- (sql.normalize/normalize-name driver alias))- :type :custom-field- :used-fields (into #{} (find-used-fields driver sources withs expr))}])+ [{:col {:alias (when alias+ (sql.normalize/normalize-name driver alias))+ :type :custom-field+ :used-fields (into #{} (keep :col) (find-used-fields driver sources withs expr))}}])(defmethod find-returned-fields [:sql :macaw.ast/column][driver sources _withs expr](get-column driver sources expr {:return-table-matches? true}))+(defn wrap-col+ "Wraps the argument in `{:col _}`"+ [col]+ {:col col})+(defmethod find-returned-fields [:sql :macaw.ast/wildcard][_driver sources _withs _expr](into []- (mapcat :returned-fields)+ (mapcat #(->> % :returned-fields (map wrap-col)))(first sources)))(defmethod find-returned-fields [:sql :macaw.ast/table-wildcard][driver sources _withs expr]- (or (some-> (find-source (col-fields driver expr) sources)- :returned-fields)- [(assoc expr- :type :invalid-table-wildcard)]))+ (or (some->> (find-source (col-fields driver expr) sources)+ :returned-fields+ (map wrap-col))+ [{:errors #{(driver-api/missing-table-alias-error (table-name expr))}}]))(defmethod find-returned-fields [:sql :macaw.ast/set-operation][driver sources withs expr](->> (map (partial find-returned-fields driver sources withs)(:selects expr))(apply map (fn [& fields]- {:alias (or (:alias (first fields))- (:column (first fields)))- :type :composite-field- :member-fields (into [] fields)}))))+ (let [cols (keep :col fields)]+ {:col {:alias (or (:alias (first cols))+ (:column (first cols)))+ :type :composite-field+ :member-fields (into [] cols)}+ :errors (mapcat :errors fields)})))))(defmulti field-references-impl"Implementation of field-references."@@ -249,6 +273,7 @@:returned-fields [{:type :all-columns:table (->> (select-keys expr [:table :schema :database :table-alias])(normalize-fields driver))}]+ :errors #{}:names (normalize-fields driver expr)}))(defn- get-select-sources@@ -262,23 +287,23 @@with-outside (cons local-sources outside-sources)with-select (cons [{:used-fields #{}:returned-fields (->> (find-returned-fields driver outside-sources withs expr)+ (map :col)(filter :alias))- :names nil}]+ :names nil+ :errors #{}}]with-outside)rec (partial find-used-fields driver with-select withs)]- (-> (into #{}- ;; a select can't refer to its own aliases, so don't include them in sources here- (mapcat (partial find-used-fields driver with-outside withs))- (:select expr))- (into (rec (:where expr)))- (into (mapcat rec)- (:join expr))- (into (mapcat rec)- (:group-by expr))- (into (mapcat rec)- (:order-by expr))- (into (mapcat :used-fields)- local-sources))))+ (into #{}+ cat+ [ ;; a select can't refer to its own aliases, so don't include them in sources here+ (mapcat (partial find-used-fields driver with-outside withs)+ (:select expr))+ (rec (:where expr))+ (mapcat rec (:join expr))+ (mapcat rec (:group-by expr))+ (mapcat rec (:order-by expr))+ (mapcat #(->> % :used-fields (map wrap-col))+ local-sources)])))(defmethod find-returned-fields [:sql :macaw.ast/select][driver outside-sources withs expr]@@ -289,7 +314,7 @@;; :alias is a column alias, so this is presumably something like `select (select * from ...)`;; there should only be one field returned, and that field should have the appropriate alias(do (assert (= 1 (count returned-fields)))- (map #(assoc % :alias (sql.normalize/normalize-name driver (:alias expr)))+ (map #(assoc-in % [:col :alias] (sql.normalize/normalize-name driver (:alias expr)))returned-fields))returned-fields)))@@ -299,12 +324,17 @@(conj current-withs (field-references-impl driver outside-sources current-withs with-expr)))outside-withs(:with expr))- withs (into outside-withs local-withs)]- {:used-fields (into (find-used-fields driver outside-sources withs expr)- (mapcat :used-fields)- local-withs)- :returned-fields (into []- (find-returned-fields driver outside-sources withs expr))+ withs (into outside-withs local-withs)+ current-used-fields (find-used-fields driver outside-sources withs expr)+ returned-fields (find-returned-fields driver outside-sources withs expr)]+ {:used-fields (into #{}+ cat+ [(keep :col current-used-fields)+ (mapcat :used-fields local-withs)])+ :returned-fields (into [] (keep :col) returned-fields)+ :errors (into #{}+ (comp cat (mapcat :errors))+ [returned-fields current-used-fields local-withs]):names (when-let [alias (:table-alias expr)]{:table-alias (sql.normalize/normalize-name driver alias)})}))@@ -314,26 +344,30 @@(defmethod field-references-impl [:sql :macaw.ast/set-operation][driver outside-sources withs expr]- {:used-fields (->> (find-used-fields driver outside-sources withs expr)- (into #{}))- :returned-fields (->> (find-returned-fields driver outside-sources withs expr)- (into []))- :names (when-let [alias (:table-alias expr)]- {:table-alias (sql.normalize/normalize-name driver alias)})})+ (let [used-fields (find-used-fields driver outside-sources withs expr)+ returned-fields (find-returned-fields driver outside-sources withs expr)]+ {:used-fields (into #{} (keep :col) used-fields)+ :returned-fields (into [] (keep :col) returned-fields)+ :errors (into #{}+ (comp cat (mapcat :errors))+ [used-fields returned-fields])+ :names (when-let [alias (:table-alias expr)]+ {:table-alias (sql.normalize/normalize-name driver alias)})}))(defmethod field-references-impl [:sql :macaw.ast/table-function][driver _outside-sources _withs expr]{:used-fields #{}:returned-fields [{:type :unknown-columns}]:names (when-let [alias (:table-alias expr)]- {:table-alias (sql.normalize/normalize-name driver alias)})})+ {:table-alias (sql.normalize/normalize-name driver alias)})+ :errors #{}})(defmethod field-references-impl :default[_driver _outside-sources _outside-withs _expr]{:used-fields #{}:returned-fields []:names nil- :bad-sql true})+ :errors #{(driver-api/syntax-error)}})(mu/defn field-references :- [:ref ::field-references]"Takes a sql query in the macaw ast format and returns the fields referenced by a query.diff --git a/src/metabase/driver_api/core.clj b/src/metabase/driver_api/core.cljindex 4bbd24b3eb8..12642e2ae72 100644--- a/src/metabase/driver_api/core.clj+++ b/src/metabase/driver_api/core.clj@@ -27,6 +27,7 @@[metabase.lib.schema.metadata :as lib.schema.metadata][metabase.lib.schema.parameter :as lib.schema.parameter][metabase.lib.schema.temporal-bucketing :as lib.schema.temporal-bucketing]+ [metabase.lib.schema.validate :as lib.schema.validate][metabase.lib.types.isa :as lib.types.isa][metabase.lib.util.match :as lib.util.match][metabase.logger.core :as logger]@@ -110,10 +111,16 @@lib/truncate-aliaslib/->legacy-MBQLlib/->metadata-provider+ lib/duplicate-column-error+ lib/match-and-normalize-tag-name+ lib/missing-column-error+ lib/missing-table-alias-errorlib/normalizelib/order-by-clauselib/query-from-legacy-inner-querylib/raw-native-query+ lib/syntax-error+ lib/validation-exception-errorlimit/absolute-max-resultslimit/determine-query-max-rowslogger/level-enabled?@@ -246,6 +253,30 @@"::lib.schema.parameter/type"::lib.schema.parameter/type)+(def schema.validate.missing-column-error+ "::lib.schema.validate/missing-column-error"+ ::lib.schema.validate/missing-column-error)++(def schema.validate.missing-table-alias-error+ "::lib.schema.validate/missing-table-alias-error"+ ::lib.schema.validate/missing-table-alias-error)++(def schema.validate.duplicate-column-error+ "::lib.schema.validate/duplicate-column-error"+ ::lib.schema.validate/duplicate-column-error)++(def schema.validate.syntax-error+ "::lib.schema.validate/syntax-error"+ ::lib.schema.validate/syntax-error)++(def schema.validate.validation-exception-error+ "::lib.schema.validate/validation-exception-error"+ ::lib.schema.validate/validation-exception-error)++(def schema.validate.error+ "::lib.schema.validate/error"+ ::lib.schema.validate/error)+(def mbql.schema.DateTimeValue"::mbql.s/DateTimeValue"::mbql.s/DateTimeValue)diff --git a/src/metabase/graph/core.cljc b/src/metabase/graph/core.cljcindex 0b995d04dcd..a6de1d46c63 100644--- a/src/metabase/graph/core.cljc+++ b/src/metabase/graph/core.cljc@@ -75,7 +75,7 @@(recur new-children))(drop (count key-seq) (->iterable))))))-(defn calc-edges-between+(defn edges-between"Calculates the edges within `nodes`, based on `graph`."[graph nodes](let [node-set (into #{} nodes)diff --git a/src/metabase/lib/core.cljc b/src/metabase/lib/core.cljcindex c6e21facf28..83d1616e100 100644--- a/src/metabase/lib/core.cljc+++ b/src/metabase/lib/core.cljc@@ -44,6 +44,7 @@[metabase.lib.order-by :as lib.order-by][metabase.lib.page][metabase.lib.parameters]+ [metabase.lib.parameters.parse :as lib.parameters.parse][metabase.lib.parse :as lib.parse][metabase.lib.query :as lib.query][metabase.lib.ref :as lib.ref]@@ -419,6 +420,8 @@parameter-target-is-dimension?parameter-target-template-tag-nameupdate-parameter-target-dimension-options]+ [lib.parameters.parse+ match-and-normalize-tag-name][lib.parseparse][lib.query@@ -499,7 +502,12 @@unique-name-generatorunique-name-generator-with-options][lib.validate- find-bad-refs]+ duplicate-column-error+ find-bad-refs+ missing-column-error+ missing-table-alias-error+ syntax-error+ validation-exception-error][metabase.lib.walk.utilall-field-idsall-implicitly-joined-field-idsdiff --git a/src/metabase/lib/native.cljc b/src/metabase/lib/native.cljcindex d5de186433d..401d855311c 100644--- a/src/metabase/lib/native.cljc+++ b/src/metabase/lib/native.cljc@@ -26,67 +26,12 @@[metabase.util.malli.registry :as mr][metabase.util.performance :refer [every? mapv select-keys some empty? not-empty]]))-;; Template Tags: Variables--(def ^:private variable-tag-regex- #"\{\{\s*([A-Za-z0-9_\.]+)\s*\}\}")--(defn- normalize-variable-tag- "Matches and normalizes a variable tag like {{my_var}}.- Returns normalized-name or nil if not a variable tag."- [full-tag]- (when-let [[_ content] (re-matches variable-tag-regex full-tag)]- content))--;; Template Tags: Snippets--(def ^:private snippet-tag-regex- ;; any spaces, snippet:, any spaces, name, any trailing spaces- #"\{\{\s*(snippet:\s*[^}]*[^}\s])\s*\}\}")--(defn- tag-name->snippet-name [tag-name]- (when (str/starts-with? tag-name "snippet:")- (str/trim (subs tag-name (count "snippet:")))))--(defn- normalize-snippet-tag- "Normalizes a snippet tag like {{snippet: foo}}. E.g., 'snippet: foo ' -> 'snippet: foo'.- Returns normalized string or nil if not a snippet tag."- [full-tag]- (when-let [[_ content] (re-matches snippet-tag-regex full-tag)]- (let [snippet-name (tag-name->snippet-name content)]- (str "snippet: " snippet-name))))--;; Template Tags: Cards--(def ^:private card-tag-regex- #"\{\{\s*(#([0-9]*)(-[a-z0-9-]*)?)\s*\}\}")--(defn- tag-name->card-id [tag-name]- (when-let [[_ id-str] (re-matches #"^#(\d+)(-[a-z0-9-]*)?$" tag-name)]- (parse-long id-str)))--(defn- normalize-card-tag- "Matches and normalizes a card tag like {{#123}} or {{#123-slug}}.- Normalizes '#123-slug' -> '#123'.- Returns normalized-name or nil if not a card tag."- [full-tag]- (when-let [[_ content _card-id _slug] (re-matches card-tag-regex full-tag)]- ;; TODO: see tech debt issue #39378 and `native-test/card-tag-test`- content))--(def ^:private match-and-normalize-tag-name- "Matches a full tag string against tag normalizer functions and returns- normalized-name or nil if no match."- (some-fn normalize-variable-tag- normalize-snippet-tag- normalize-card-tag))-(defn- finish-tag [{tag-name :name :as tag}](merge tag- (when-let [card-id (tag-name->card-id tag-name)]+ (when-let [card-id (lib.params.parse/tag-name->card-id tag-name)]{:type :card:card-id card-id})- (when-let [snippet-name (tag-name->snippet-name tag-name)]+ (when-let [snippet-name (lib.params.parse/tag-name->snippet-name tag-name)]{:type :snippet:snippet-name snippet-name})(when-not (:display-name tag)@@ -109,8 +54,7 @@[_ :guard string?] (recur found more)[{:type ::lib.parse/param, :name tag-name}]- (let [full-tag (str "{{" tag-name "}}")- normalized-name (match-and-normalize-tag-name full-tag)]+ (let [normalized-name (lib.params.parse/match-and-normalize-tag-name tag-name)](recur (cond-> found(and normalized-name (not (found normalized-name)))(assoc normalized-name (fresh-tag normalized-name)))diff --git a/src/metabase/lib/parameters/parse.cljc b/src/metabase/lib/parameters/parse.cljcindex c0287b5c0c7..50b955e868a 100644--- a/src/metabase/lib/parameters/parse.cljc+++ b/src/metabase/lib/parameters/parse.cljc@@ -16,6 +16,65 @@::lib.params.parse.types/function-param::lib.params.parse.types/optional])+;; Template Tags: Variables++(def ^:private variable-tag-regex+ #"\s*([A-Za-z0-9_\.]+)\s*")++(defn- normalize-variable-tag+ "Matches and normalizes a variable tag like {{my_var}}.+ Returns normalized-name or nil if not a variable tag."+ [tag-name]+ (when-let [[_ content] (re-matches variable-tag-regex tag-name)]+ content))++;; Template Tags: Snippets++(def ^:private snippet-tag-regex+ ;; any spaces, snippet:, any spaces, name, any trailing spaces+ #"\s*(snippet:\s*[^}]*[^}\s])\s*")++(defn tag-name->snippet-name+ "Get a snippet name from a snippet tag."+ [tag-name]+ (when (str/starts-with? tag-name "snippet:")+ (str/trim (subs tag-name (count "snippet:")))))++(defn- normalize-snippet-tag+ "Normalizes a snippet tag like {{snippet: foo}}. E.g., 'snippet: foo ' -> 'snippet: foo'.+ Returns normalized string or nil if not a snippet tag."+ [tag-name]+ (when-let [[_ content] (re-matches snippet-tag-regex tag-name)]+ (let [snippet-name (tag-name->snippet-name content)]+ (str "snippet: " snippet-name))))++;; Template Tags: Cards++(def ^:private card-tag-regex+ #"\s*(#([0-9]*)(-[a-z0-9-]*)?)\s*")++(defn tag-name->card-id+ "Get the card id from a card tag."+ [tag-name]+ (when-let [[_ id-str] (re-matches #"^#(\d+)(-[a-z0-9-]*)?$" tag-name)]+ (parse-long id-str)))++(defn- normalize-card-tag+ "Matches and normalizes a card tag like {{#123}} or {{#123-slug}}.+ Normalizes '#123-slug' -> '#123'.+ Returns normalized-name or nil if not a card tag."+ [tag-name]+ (when-let [[_ content _card-id _slug] (re-matches card-tag-regex tag-name)]+ ;; TODO: see tech debt issue #39378 and `native-test/card-tag-test`+ content))++(def ^{:arglists '([tag-name])} match-and-normalize-tag-name+ "Matches a full tag string against tag normalizer functions and returns+ normalized-name or nil if no match."+ (some-fn normalize-variable-tag+ normalize-snippet-tag+ normalize-card-tag))+(defn- ->param [value](match [value][s :guard string?]@@ -23,7 +82,8 @@[{:type :metabase.lib.parse/param:name param-name}]- (lib.params.parse.types/param {:k (str/trim param-name)})+ (lib.params.parse.types/param {:k (or (match-and-normalize-tag-name param-name)+ (str/trim param-name))})[{:type :metabase.lib.parse/function-param:name param-namediff --git a/src/metabase/lib/schema/id.cljc b/src/metabase/lib/schema/id.cljcindex a5710ba3de5..1aa180b49e3 100644--- a/src/metabase/lib/schema/id.cljc+++ b/src/metabase/lib/schema/id.cljc@@ -94,10 +94,6 @@"Valid Collection ID"pos-int?)-(mr/def ::document- "Valid Document ID"- pos-int?)-(mr/def ::sandbox"Valid Sandbox ID"pos-int?)diff --git a/src/metabase/lib/schema/validate.cljc b/src/metabase/lib/schema/validate.cljcnew file mode 100644index 00000000000..db8d3b67788--- /dev/null+++ b/src/metabase/lib/schema/validate.cljc@@ -0,0 +1,43 @@+(ns metabase.lib.schema.validate+ (:require+ [metabase.lib.schema.common :as common]+ [metabase.util.malli.registry :as mr]))++(mr/def ::missing-column-error+ [:map+ [:type [:= :validate/missing-column]]+ [:name :string]])++(mr/def ::missing-table-alias-error+ [:map+ [:type [:= :validate/missing-table-alias]]+ [:name :string]])++(mr/def ::duplicate-column-error+ [:map+ [:type [:= :validate/duplicate-column]]+ [:name :string]])++(mr/def ::syntax-error+ [:map+ [:type [:= :validate/syntax-error]]])++(mr/def ::validation-exception-error+ [:map+ [:type [:= :validate/validation-exception-error]]+ [:message :string]])++(mr/def ::validate-error-type+ [:and+ :keyword+ [:fn {:error/message "Must be in the validate ns"} #(= (namespace %) "validate")]])++(mr/def ::error+ [:and+ [:map [:type {:decode/normalize common/normalize-keyword} ::validate-error-type]]+ [:multi {:dispatch #(-> % :type keyword)}+ [:validate/missing-column [:ref ::missing-column-error]]+ [:validate/missing-table-alias [:ref ::missing-table-alias-error]]+ [:validate/duplicate-column [:ref ::duplicate-column-error]]+ [:validate/syntax-error [:ref ::syntax-error]]+ [:validate/validation-exception-error [:ref ::validation-exception-error]]]])diff --git a/src/metabase/lib/validate.cljc b/src/metabase/lib/validate.cljcindex fb720628047..fee621f83b9 100644--- a/src/metabase/lib/validate.cljc+++ b/src/metabase/lib/validate.cljc@@ -1,20 +1,48 @@(ns metabase.lib.validate"Checks and validation for queries."- (:refer-clojure :exclude [not-empty])(:require[metabase.lib.field.resolution :as lib.field.resolution]+ [metabase.lib.metadata.calculation :as lib.metadata.calculation][metabase.lib.schema :as lib.schema]- [metabase.lib.schema.mbql-clause :as lib.schema.mbql-clause]+ [metabase.lib.schema.validate :as lib.schema.validate][metabase.lib.walk :as lib.walk]- [metabase.util.malli :as mu]- [metabase.util.performance :refer [not-empty]]))+ [metabase.util.malli :as mu]))-(mu/defn find-bad-refs :- [:maybe [:sequential ::lib.schema.mbql-clause/clause]]- "Returns a list of bad `:field` refs on this query.+(mu/defn missing-column-error :- [:ref ::lib.schema.validate/missing-column-error]+ "Create a missing-column lib validation error"+ [col-name :- :string]+ {:type :validate/missing-column+ :name col-name})- Returns nil if all refs on the query are sound, that is if they can be resolved to a column from some source."+(mu/defn missing-table-alias-error :- [:ref ::lib.schema.validate/missing-table-alias-error]+ "Create a missing-table-alias lib validation error"+ [alias-name :- :string]+ {:type :validate/missing-table-alias+ :name alias-name})++(mu/defn duplicate-column-error :- [:ref ::lib.schema.validate/duplicate-column-error]+ "Create a duplicate-column lib validation error"+ [col-name :- :string]+ {:type :validate/duplicate-column+ :name col-name})++(mu/defn syntax-error :- [:ref ::lib.schema.validate/syntax-error]+ "Create a syntax-error lib validation error"+ []+ {:type :validate/syntax-error})++(mu/defn validation-exception-error :- [:ref ::lib.schema.validate/validation-exception-error]+ "Create a validation-exception-error lib validation error"+ [message :- :string]+ {:type :validate/validation-exception-error+ :message message})++(mu/defn find-bad-refs :- [:set [:ref ::lib.schema.validate/error]]+ "Returns a set of validation errors in this query.++ Returns empty set if all refs on the query are sound, that is if they can be resolved to a column from some source."[query :- ::lib.schema/query]- (let [bad-fields (volatile! [])]+ (let [bad-fields (volatile! #{})](lib.walk/walk-clausesquery(fn [query path-type path clause]@@ -27,9 +55,10 @@(when (or (not column)(::lib.field.resolution/fallback-metadata? column)(not (:active column true)))- (vswap! bad-fields conj clause))))+ (vswap! bad-fields conj (missing-column-error+ (lib.metadata.calculation/column-name query (second path) column))))))nil))- (not-empty @bad-fields)))+ @bad-fields))(comment(require '[metabase.lib.core :as lib])diff --git a/src/metabase/models/resolution.clj b/src/metabase/models/resolution.cljindex dea38e7ba53..060686b1ea1 100644--- a/src/metabase/models/resolution.clj+++ b/src/metabase/models/resolution.clj@@ -13,6 +13,7 @@Tests will check to make sure new models get included in this map."'{:model/Action metabase.actions.models+ :model/AnalysisFinding metabase-enterprise.dependencies.models.analysis-finding:model/ApiKey metabase.api-keys.models.api-key:model/ApplicationPermissionsRevision metabase.permissions.models.application-permissions-revision:model/AuditLog metabase.audit-app.models.audit-logdiff --git a/src/metabase/native_query_snippets/schema.clj b/src/metabase/native_query_snippets/schema.cljnew file mode 100644index 00000000000..fd688b3c362--- /dev/null+++ b/src/metabase/native_query_snippets/schema.clj@@ -0,0 +1,15 @@+(ns metabase.native-query-snippets.schema+ (:require+ [metabase.lib.schema.id :as lib.schema.id]+ [metabase.lib.schema.template-tag :as lib.schema.template-tag]+ [metabase.util.malli.registry :as mr]))++(mr/def ::native-query-snippet+ "Schema for an instance of a `:model/NativeQuerySnippet`."+ [:map+ [:id ::lib.schema.id/snippet]+ [:name :string]+ [:content :string]+ [:description {:optional true} [:maybe :string]]+ [:collection_id {:optional true} [:maybe ::lib.schema.id/collection]]+ [:template_tags [:ref ::lib.schema.template-tag/template-tag-map]]])diff --git a/src/metabase/premium_features/token_check.clj b/src/metabase/premium_features/token_check.cljindex 67b57a18eb5..477b42de05f 100644--- a/src/metabase/premium_features/token_check.clj+++ b/src/metabase/premium_features/token_check.clj@@ -14,6 +14,7 @@[environ.core :refer [env]][java-time.api :as t][metabase.config.core :as config]+ [metabase.events.core :as events][metabase.internal-stats.core :as internal-stats][metabase.premium-features.defenterprise :refer [defenterprise]][metabase.premium-features.settings :as premium-features.settings]@@ -458,6 +459,8 @@([checker token](-check-token checker token)))+(derive :event/set-premium-embedding-token :metabase/event)+(defn -set-premium-embedding-token!"Setter for the [[metabase.premium-features.settings/token-status]] setting."[new-value]@@ -475,6 +478,7 @@(throw (ex-info "Invalid token" {:token (u.str/mask new-value)}))))(log/info "Token is valid."))(setting/set-value-of-type! :string :premium-embedding-token new-value)+ (events/publish-event! :event/set-premium-embedding-token {})(catch Throwable e(log/error e "Error setting premium features token");; merge in error-details if presentdiff --git a/src/metabase/queries/schema.clj b/src/metabase/queries/schema.cljindex 5cdb31d611a..b12e8663e03 100644--- a/src/metabase/queries/schema.clj+++ b/src/metabase/queries/schema.clj@@ -1,5 +1,6 @@(ns metabase.queries.schema(:require+ [metabase.documents.schema :as documents.schema][metabase.lib-be.core :as lib-be][metabase.lib.core :as lib][metabase.lib.schema :as lib.schema]@@ -61,7 +62,13 @@"Schema for an instance of a `:model/Card` (everything is optional to support updates)."[:map[:id {:optional true} [:maybe ::lib.schema.id/card]]+ [:collection_id {:optional true} [:maybe ::lib.schema.id/collection]]+ [:dashboard_id {:optional true} [:maybe ::lib.schema.id/dashboard]]+ [:database_id {:optional true} [:maybe ::lib.schema.id/database]]+ [:document_id {:optional true} [:maybe ::documents.schema/document.id]][:dataset_query {:optional true} [:maybe ::query]]+ [:description {:optional true} [:maybe :string]]+ [:name {:optional true} [:maybe :string]][:parameters {:optional true} [:maybe [:ref ::parameters.schema/parameters]]][:parameter_mappings {:optional true} [:maybe [:ref ::parameters.schema/parameter-mappings]]][:type {:optional true} [:maybe ::lib.schema.metadata/card.type]]diff --git a/src/metabase/warehouse_schema/schema.clj b/src/metabase/warehouse_schema/schema.cljnew file mode 100644index 00000000000..03dfe9057fd--- /dev/null+++ b/src/metabase/warehouse_schema/schema.clj@@ -0,0 +1,13 @@+(ns metabase.warehouse-schema.schema+ (:require+ [metabase.lib.schema.id :as lib.schema.id]+ [metabase.util.malli.registry :as mr]))++(mr/def ::table+ "Schema for an instance of a `:model/Table`."+ [:map+ [:id ::lib.schema.id/table]+ [:name :string]+ [:description {:optional true} [:maybe :string]]+ [:schema {:optional true} [:maybe :string]]+ [:db_id ::lib.schema.id/database]])diff --git a/test/metabase/cmd/copy_test.clj b/test/metabase/cmd/copy_test.cljindex 665f45e231e..0b8f7caf0ce 100644--- a/test/metabase/cmd/copy_test.clj+++ b/test/metabase/cmd/copy_test.clj@@ -25,7 +25,8 @@(def ^:private models-to-exclude"Models that should *not* be migrated in `load-from-h2`."- #{:model/ApiKey+ #{:model/AnalysisFinding+ :model/ApiKey:model/CacheConfig:model/CardFavorite:model/CloudMigrationdiff --git a/test/metabase/driver/common/parameters/values_test.clj b/test/metabase/driver/common/parameters/values_test.cljindex 06325facc39..5752a127686 100644--- a/test/metabase/driver/common/parameters/values_test.clj+++ b/test/metabase/driver/common/parameters/values_test.clj@@ -595,6 +595,21 @@(is (= expected(query->params-map (query-with-snippet :snippet-id 1, :snippet-name "Old Name")))))))))+(deftest ^:parallel unnormalized-snippet-test+ (testing "Snippet parsing should normalize snippet names when parsing"+ (mt/with-temp [:model/NativeQuerySnippet {snippet-id :id} {:name "expensive-venues"+ :content "venues WHERE price = 4"}]+ (let [expected {"snippet: expensive-venues" (params/map->ReferencedQuerySnippet {:snippet-id snippet-id+ :content "venues WHERE price = 4"})}+ query (assoc (mt/native-query {:query "SELECT * FROM {{snippet:expensive-venues}}"})+ :template-tags {"snippet:expensive-venues" {:type :snippet+ :name "expensive-venues"+ :display-name "Expensive Venues"+ :snippet-name "expensive-venues"+ :snippet-id snippet-id}})]+ (is (= expected+ (query->params-map query)))))))+(deftest ^:parallel invalid-param-test(testing "Should throw an Exception if we try to pass with a `:type` we don't understand"(let [query (assoc (mt/native-query {:query "SELECT * FROM table WHERE {{x}}"})diff --git a/test/metabase/driver/sql/parameters/substitute_test.clj b/test/metabase/driver/sql/parameters/substitute_test.cljindex 7e18834c94c..cb3ed619453 100644--- a/test/metabase/driver/sql/parameters/substitute_test.clj+++ b/test/metabase/driver/sql/parameters/substitute_test.clj@@ -318,16 +318,16 @@(deftest ^:parallel substitute-native-query-snippets-test(testing "Native query snippet substitution"- (let [query ["SELECT * FROM test_scores WHERE " (param "snippet:symbol_is_A")]]+ (let [query ["SELECT * FROM test_scores WHERE " (param "snippet: symbol_is_A")]](is (=? ["SELECT * FROM test_scores WHERE symbol = 'A'" nil]- (substitute query {"snippet:symbol_is_A" (params/->ReferencedQuerySnippet 123 "symbol = 'A'")}))))))+ (substitute query {"snippet: symbol_is_A" (params/->ReferencedQuerySnippet 123 "symbol = 'A'")}))))))(deftest ^:parallel substitute-recursive-native-query-snippets-test(testing "Recursive native query snippet substitution"- (let [query ["SELECT * FROM test_scores WHERE " (param "snippet:outer")]]+ (let [query ["SELECT * FROM test_scores WHERE " (param "snippet: outer")]](is (=? ["SELECT * FROM test_scores WHERE symbol = 'A'" nil]- (substitute query {"snippet:outer" (params/->ReferencedQuerySnippet 123 "{{snippet:symbol_is_A}}")- "snippet:symbol_is_A" (params/->ReferencedQuerySnippet 124 "symbol = 'A'")}))))))+ (substitute query {"snippet: outer" (params/->ReferencedQuerySnippet 123 "{{snippet:symbol_is_A}}")+ "snippet: symbol_is_A" (params/->ReferencedQuerySnippet 124 "symbol = 'A'")}))))));;; ------------------------------------------ simple substitution — {{x}} ------------------------------------------diff --git a/test/metabase/driver/sql/references_test.clj b/test/metabase/driver/sql/references_test.cljindex 4f063395fdd..26e7c70762c 100644--- a/test/metabase/driver/sql/references_test.clj+++ b/test/metabase/driver/sql/references_test.clj@@ -2,6 +2,7 @@(:require[clojure.test :refer :all][macaw.core :as macaw]+ [metabase.driver-api.core :as driver-api][metabase.driver.sql.references :as sql.references]))(defn- ->references [query]@@ -10,7 +11,7 @@(deftest ^:parallel garbage-test(is (= {:used-fields #{}:returned-fields []- :bad-sql true}+ :errors #{(driver-api/syntax-error)}}(->references "nothing"))))(deftest ^:parallel basic-select-test@@ -31,7 +32,8 @@{:column "b",:alias nil,:type :single-column,- :source-columns [[{:type :all-columns, :table {:table "products"}}]]}]}+ :source-columns [[{:type :all-columns, :table {:table "products"}}]]}]+ :errors #{}}(->references "select * from (select a, b from products)"))))(deftest ^:parallel basic-join-test@@ -53,7 +55,8 @@{:column "id",:alias nil,:type :single-column,- :source-columns [[{:type :all-columns, :table {:table "orders"}}]]}]}+ :source-columns [[{:type :all-columns, :table {:table "orders"}}]]}]+ :errors #{}}(->references "select products.*, orders.id from products inner join orders on products.id = orders.product_id"))))(deftest ^:parallel indeterminite-join-test@@ -78,7 +81,8 @@:type :single-column,:source-columns[[{:type :all-columns, :table {:table "orders"}}- {:type :all-columns, :table {:table "products"}}]]}]}+ {:type :all-columns, :table {:table "products"}}]]}]+ :errors #{}}(->references "select id from products inner join orders on products.id = orders.product_id"))))(deftest ^:parallel table-wildcard-join-test@@ -94,7 +98,8 @@:source-columns [[{:type :all-columns,:table {:table "orders"}}]]}},:returned-fields- [{:type :all-columns, :table {:table "orders"}}]}+ [{:type :all-columns, :table {:table "orders"}}]+ :errors #{}}(->references "select orders.* from products inner join orders on products.id = orders.product_id"))))(deftest ^:parallel wildcard-join-test@@ -111,7 +116,8 @@:table {:table "orders"}}]]}},:returned-fields[{:type :all-columns, :table {:table "orders"}}- {:type :all-columns, :table {:table "products"}}]}+ {:type :all-columns, :table {:table "products"}}]+ :errors #{}}(->references "select * from products inner join orders on products.id = orders.product_id"))))(deftest ^:parallel basic-alias-test@@ -132,7 +138,8 @@{:column "c",:alias "d",:type :single-column,- :source-columns [[{:type :all-columns, :table {:table-alias "p", :table "products"}}]]}]}+ :source-columns [[{:type :all-columns, :table {:table-alias "p", :table "products"}}]]}]+ :errors #{}}(->references "select p.a as b, p.c as d from products p"))))(deftest ^:parallel basic-nested-query-test@@ -157,7 +164,8 @@:alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "products"}}]]}]}+ :table {:table "products"}}]]}]+ :errors #{}}(->references "select a, b from (select a, b from products)"))))(deftest ^:parallel renamed-nested-query-test@@ -177,7 +185,8 @@:alias "c",:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "products"}}]]}]}+ :table {:table "products"}}]]}]+ :errors #{}}(->references "select b as c from (select a as b from products)"))))(deftest ^:parallel broken-nested-query-test@@ -203,7 +212,8 @@[[{:column "b",:alias nil,:type :single-column,- :source-columns [[{:type :all-columns, :table {:table "products"}}]]}]]}]}+ :source-columns [[{:type :all-columns, :table {:table "products"}}]]}]]}]+ :errors #{}}(->references "select a from (select b from products)"))))(deftest ^:parallel different-case-nested-query-test@@ -218,7 +228,8 @@:alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "orders"}}]]}]}+ :table {:table "orders"}}]]}]+ :errors #{}}(->references "select A from (select a from orders)"))))(deftest ^:parallel wildcard-nested-query-test@@ -233,7 +244,8 @@:alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "orders"}}]]}]}+ :table {:table "orders"}}]]}]+ :errors #{}}(->references "select * from (select a from orders)"))))(deftest ^:parallel table-wildcard-nested-query-test@@ -248,7 +260,8 @@:alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "orders"}}]]}]}+ :table {:table "orders"}}]]}]+ :errors #{}}(->references "select o.* from (select a from orders) o"))))(deftest ^:parallel bad-table-wildcard-nested-query-test@@ -258,8 +271,8 @@:type :single-column,:source-columns [[{:type :all-columns,:table {:table "orders"}}]]}},- :returned-fields- [{:type :invalid-table-wildcard, :table "foo"}]}+ :returned-fields []+ :errors #{(driver-api/missing-table-alias-error "foo")}}(->references "select foo.* from (select a from orders)"))))(deftest ^:parallel bad-table-name-test@@ -272,9 +285,31 @@[{:column "a",:alias nil,:type :single-column,- :source-columns []}]}+ :source-columns []}]+ :errors #{(driver-api/missing-table-alias-error "bad")}}(->references "select bad.a from products"))))+(deftest ^:parallel no-possible-sources-test+ (is (= {:used-fields+ #{{:column "a"+ :alias nil+ :type :single-column+ :source-columns []}}+ :returned-fields+ [{:column "a"+ :alias nil+ :type :single-column+ :source-columns []}]+ :errors #{(driver-api/missing-column-error "a")}}+ (->references "select a"))))++(deftest ^:parallel select-constant-test+ (is (= {:used-fields #{},+ :returned-fields+ [{:alias nil, :type :custom-field, :used-fields #{}}],+ :errors #{}}+ (->references "select 1"))))+(deftest ^:parallel basic-where-test(is (= {:used-fields#{{:column "category",@@ -283,17 +318,20 @@:source-columns [[{:type :all-columns,:table {:table "products"}}]]}},:returned-fields [{:type :all-columns,- :table {:table "products"}}]}+ :table {:table "products"}}]+ :errors #{}}(->references "select * from products where category = 'hello'"))))(deftest ^:parallel basic-aggregation-test(is (=? {:used-fields #{},- :returned-fields [{:alias nil, :type :custom-field, :used-fields #{}}]}+ :returned-fields [{:alias nil, :type :custom-field, :used-fields #{}}]+ :errors #{}}(->references "select count(*) from products"))))(deftest ^:parallel named-aggregation-test(is (=? {:used-fields #{},- :returned-fields [{:alias "count", :type :custom-field, :used-fields #{}}]}+ :returned-fields [{:alias "count", :type :custom-field, :used-fields #{}}]+ :errors #{}}(->references "select count(*) as count from products"))))(deftest ^:parallel extra-names-test@@ -314,7 +352,8 @@[[{:type :all-columns,:table {:database "db",:schema "schema",- :table "table"}}]]}]}+ :table "table"}}]]}]+ :errors #{}}(->references "select db.schema.table.col from db.schema.table"))))(deftest ^:parallel basic-grouping-test@@ -343,7 +382,8 @@#{{:column "total",:alias nil,:type :single-column,- :source-columns [[{:type :all-columns, :table {:table "orders"}}]]}}}]}+ :source-columns [[{:type :all-columns, :table {:table "orders"}}]]}}}]+ :errors #{}}(->references "select sum(total) as sum from orders group by category"))))(deftest ^:parallel grouping-order-by-test@@ -382,7 +422,8 @@#{{:column "creator_id",:alias nil,:type :single-column,- :source-columns [[{:type :all-columns, :table {:table "report_card"}}]]}}}]}+ :source-columns [[{:type :all-columns, :table {:table "report_card"}}]]}}}]+ :errors #{}}(->references "SELECT creator_id, COUNT(creator_id) AS cards_created FROM report_card GROUP BY creator_id ORDER BY cards_created DESC"))))(deftest ^:parallel basic-arg-test@@ -393,7 +434,8 @@:source-columns [[{:type :all-columns,:table {:table "products"}}]]}},:returned-fields [{:type :all-columns,- :table {:table "products"}}]}+ :table {:table "products"}}]+ :errors #{}}(->references "select * from products where category = ?"))))(deftest ^:parallel basic-case-test@@ -431,7 +473,8 @@:alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "orders"}}]]}}}]}+ :table {:table "orders"}}]]}}}]+ :errors #{}}(->references "select case when total < 0 then -subtotal else tax end from orders"))))(deftest ^:parallel switch-case-test@@ -449,7 +492,8 @@:alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "products"}}]]}}}]}+ :table {:table "products"}}]]}}}]+ :errors #{}}(->references "select case category when 'Gizmo' then 'is gizmo' else 'is not gizmo' end from products"))))(deftest ^:parallel basic-select-subquery-test@@ -479,7 +523,8 @@:table {:table "products"}}][{:type :all-columns,:table {:table "orders"}}]]}- {:type :all-columns, :table {:table "orders"}}]}+ {:type :all-columns, :table {:table "orders"}}]+ :errors #{}}(->references "select (select category from products where products.id = orders.product_id), * from orders"))))(deftest ^:parallel named-select-subquery-test@@ -509,7 +554,8 @@:table {:table "products"}}][{:type :all-columns,:table {:table "orders"}}]]}- {:type :all-columns, :table {:table "orders"}}]}+ {:type :all-columns, :table {:table "orders"}}]+ :errors #{}}(->references "select (select category from products where products.id = orders.product_id) as category2, * from orders"))))(deftest ^:parallel nested-select-subquery-test@@ -539,7 +585,8 @@:table {:table "products"}}][{:type :all-columns,:table {:table "orders"}}]]}- {:type :all-columns, :table {:table "orders"}}]}+ {:type :all-columns, :table {:table "orders"}}]+ :errors #{}}(->references "select (select (select category from products where products.id = orders.product_id)), * from orders"))))(deftest ^:parallel select-subquery-with-normal-subquery-test@@ -569,7 +616,8 @@:table {:table "products"}}][{:type :all-columns,:table {:table "orders"}}]]}- {:type :all-columns, :table {:table "orders"}}]}+ {:type :all-columns, :table {:table "orders"}}]+ :errors #{}}(->references "select (select * from (select category from products where products.id = orders.product_id) sub), * from orders"))))(deftest ^:parallel nested-select-subquery-with-reference-to-middle-select-test@@ -594,7 +642,8 @@:type :single-column,:source-columns[[{:type :all-columns, :table {:table "products"}}]- [{:type :all-columns, :table {:table "orders"}}]]}]}+ [{:type :all-columns, :table {:table "orders"}}]]}]+ :errors #{}}(->references "select (select (select category) from products where products.id = orders.product_id) from orders"))))(deftest ^:parallel nested-select-subquery-with-direct-match-in-outer-query@@ -621,7 +670,8 @@[{:column "a",:alias nil,:type :single-column,- :source-columns [[{:type :all-columns, :table {:table "t2"}}]]}]]}]}+ :source-columns [[{:type :all-columns, :table {:table "t2"}}]]}]]}]+ :errors #{}}(->references "select (select a from t1) from (select a from t2)"))))(deftest ^:parallel basic-exists-test@@ -656,7 +706,8 @@:alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table-alias "u", :table "users"}}]]}]}+ :table {:table-alias "u", :table "users"}}]]}]+ :errors #{}}(->references "SELECT u.name, u.emailFROM users uWHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id)"))))@@ -669,7 +720,8 @@ WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id)")))):source-columns [[{:type :all-columns,:table {:table "products"}}]]}},:returned-fields [{:type :all-columns,- :table {:table "products"}}]}+ :table {:table "products"}}]+ :errors #{}}(->references "select * from products where not (category = 'Gizmo')"))))(deftest ^:parallel basic-is-null-test@@ -680,7 +732,8 @@ WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id)")))):source-columns [[{:type :all-columns,:table {:table "products"}}]]}},:returned-fields [{:type :all-columns,- :table {:table "products"}}]}+ :table {:table "products"}}]+ :errors #{}}(->references "select * from products where category is null"))))(deftest ^:parallel negated-is-null-test@@ -691,7 +744,8 @@ WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id)")))):source-columns [[{:type :all-columns,:table {:table "products"}}]]}},:returned-fields [{:type :all-columns,- :table {:table "products"}}]}+ :table {:table "products"}}]+ :errors #{}}(->references "select * from products where category is not null"))))(deftest ^:parallel basic-between-test@@ -708,7 +762,8 @@ WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id)")))):alias nil,:type :single-column,:source-columns [[{:type :all-columns, :table {:table "orders"}}]]}},- :returned-fields [{:type :all-columns, :table {:table "orders"}}]}+ :returned-fields [{:type :all-columns, :table {:table "orders"}}]+ :errors #{}}(->references "select * from orders where created_at between left and right"))))(deftest ^:parallel basic-select-table-alias-test@@ -716,7 +771,8 @@ WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id)")))):returned-fields[{:type :custom-field,:alias "o",- :used-fields #{{:type :all-columns, :table {:table "orders"}}}}]}+ :used-fields #{{:type :all-columns, :table {:table "orders"}}}}]+ :errors #{}}(->references "select o from (select * from orders) as o"))))(deftest ^:parallel select-table-alias-with-alias-test@@ -724,11 +780,12 @@ WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id)")))):returned-fields[{:type :custom-field,:alias "o2",- :used-fields #{{:type :all-columns, :table {:table "orders"}}}}]}+ :used-fields #{{:type :all-columns, :table {:table "orders"}}}}]+ :errors #{}}(->references "select o as o2 from (select * from orders) as o"))))(deftest ^:parallel table-function-test- (is (= {:used-fields #{}, :returned-fields [{:type :unknown-columns}]}+ (is (= {:used-fields #{}, :returned-fields [{:type :unknown-columns}] :errors #{}}(->references "select i.* from generate_series(1, 500) as i"))))(deftest ^:parallel basic-cte-test@@ -758,7 +815,8 @@ WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id)")))):alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "users"}}]]}]}+ :table {:table "users"}}]]}]+ :errors #{}}(->references "WITH active_users AS (SELECT id, name FROM users WHERE active = true)SELECT * FROM active_users"))))@@ -780,7 +838,8 @@ SELECT * FROM active_users")))):source-columns [[{:type :all-columns,:table {:table "users"}}]]}},:returned-fields [{:type :all-columns,- :table {:table "products"}}]}+ :table {:table "products"}}]+ :errors #{}}(->references "WITH active_users AS (SELECT id, name FROM users WHERE active = true)SELECT * FROM products"))))@@ -794,7 +853,8 @@ SELECT * FROM products"))))[{:column "id",:alias nil,:type :single-column,- :source-columns [[{:type :all-columns, :table {:table "orders"}}]]}]}+ :source-columns [[{:type :all-columns, :table {:table "orders"}}]]}]+ :errors #{}}(->references "WITH orders_a AS (select * from orders),orders_b AS (select * from orders_a)@@ -838,7 +898,8 @@ SELECT id from orders_b")))){:column "x",:alias "c",:type :single-column,- :source-columns [[{:type :all-columns, :table {:table "a"}}]]}]}+ :source-columns [[{:type :all-columns, :table {:table "a"}}]]}]+ :errors #{}}(->references "WITH c AS (WITH b AS (SELECT@@ -955,7 +1016,8 @@ FROM c;")))):type :single-column,:source-columns[[{:type :all-columns, :table {:table-alias "h",- :table "emp_hierarchy"}}]]}}}]}]}+ :table "emp_hierarchy"}}]]}}}]}]+ :errors #{}}(->references "WITH RECURSIVE emp_hierarchy AS (SELECT id, name, manager_id, 0 AS levelFROM employees@@ -1015,7 +1077,8 @@ SELECT name, level FROM emp_hierarchy")))):alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "archived_users"}}]]}]}]}+ :table {:table "archived_users"}}]]}]}]+ :errors #{}}(->references "SELECT id, name FROM usersUNIONSELECT id, name FROM archived_users"))))@@ -1045,7 +1108,8 @@ SELECT id, name FROM archived_users")))):alias nil,:type :single-column,:source-columns [[{:type :all-columns,- :table {:table "employees"}}]]}}}]}+ :table {:table "employees"}}]]}}}]+ :errors #{}}(->references "SELECT name, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rankFROM employees"))))@@ -1078,7 +1142,8 @@ FROM employees")))){:column "department",:alias nil,:type :single-column,- :source-columns [[{:type :all-columns, :table {:table "employees"}}]]}}}]}+ :source-columns [[{:type :all-columns, :table {:table "employees"}}]]}}}]+ :errors #{}}(->references "SELECT name,RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS dept_rankFROM employees"))))@@ -1099,7 +1164,8 @@ FROM employees")))):type :single-column,:source-columns [[{:type :all-columns, :table {:schema "public",:table "orders"}}]]}}}- {:alias "count", :type :custom-field, :used-fields #{}}]}+ {:alias "count", :type :custom-field, :used-fields #{}}]+ :errors #{}}(->references "SELECT(DATE_TRUNC(@@ -1141,7 +1207,8 @@ ORDER BY:type :single-column,:source-columns [[{:type :all-columns, :table {:schema "public",:table "orders"}}]]}}}- {:alias "count", :type :custom-field, :used-fields #{}}]}+ {:alias "count", :type :custom-field, :used-fields #{}}]+ :errors #{}}(->references "SELECTCEIL((@@ -1325,7 +1392,8 @@ ORDER BY:type :single-column,:source-columns [[{:type :all-columns, :table {:schema "public",:table "orders"}}]]}}}- {:alias "count", :type :custom-field, :used-fields #{}}]}+ {:alias "count", :type :custom-field, :used-fields #{}}]+ :errors #{}}(->references "SELECTDATE_TRUNC('month', \"source\".\"created_at\") AS \"created_at\",\"source\".\"upper_category\" AS \"upper_category\",@@ -2156,7 +2224,8 @@ ORDER BY:table {:table-alias "ah", :schema "dbt_models", :table "account_history"}}]]}{:alias "month",:type :custom-field,- :used-fields #{}}}}]}+ :used-fields #{}}}}]+ :errors #{}}(->references "with months as (selectgenerate_series(date_trunc('month', '2024-01-01'::date),