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
Add transform as a serdes dependency of table (#74473)
Nicola Mometto2e638062407d
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.cljindex 12fd6c4e527..a8d8ed8a9d2 100644--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj@@ -2429,6 +2429,41 @@(is (= #{transform-eid python-transform-eid}(ids-by-model "Transform" (extract/extract {}))))))))))+(deftest table-with-transform-id-dependency-test+ (testing "Table created by a Transform declares the Transform as a serdes dependency (GDGT-2444)"+ (mt/with-premium-features #{:transforms-basic}+ (mt/with-empty-h2-app-db!+ (ts/with-temp-dpc [:model/Database+ {db-id :id}+ {:name "My Database"}++ :model/Transform+ {transform-id :id+ transform-eid :entity_id}+ {:name "Transform Creating Table"+ :entity_id "transformCreatingTblx"+ :source {:query {:database db-id+ :type "native"+ :native {:query "select 1 as x"}}+ :type "query"}+ :target {:database db-id+ :type "table"+ :schema "public"+ :name "transform_output"}}++ :model/Table+ {table-id :id}+ {:name "transform_output"+ :db_id db-id+ :schema "public"+ :transform_id transform-id}]+ (let [ser (ts/extract-one "Table" table-id)]+ (testing "transform_id is transformed to entity_id"+ (is (= transform-eid (:transform_id ser))))+ (testing "depends on the transform"+ (is (contains? (set (serdes/dependencies ser))+ [{:model "Transform" :id transform-eid}])))))))))+(deftest transform-job-extraction-test(testing "TransformJob extraction and serialization"(mt/with-premium-features #{:transforms-basic}diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.cljindex 8b0e9cda7f6..a8d6b8a4c27 100644--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/load_test.clj@@ -2007,6 +2007,40 @@(is (some? transform))(is (= (:id db) (:source_database_id transform)))))))))))+(deftest table-created-by-transform-load-test+ (testing "Table created by a Transform can be imported via serialization (GDGT-2444)"+ (mt/with-premium-features #{:transforms-basic}+ (let [serialized (atom nil)]+ (ts/with-dbs [source-db dest-db]+ (ts/with-db source-db+ (t2/delete! :model/TransformTag)+ (let [db (ts/create! :model/Database :name "my-db")+ transform (ts/create! :model/Transform+ :name "Hello Transform"+ :source {:query {:database (:id db)+ :type "native"+ :native {:query "select 'hello' message"}}+ :type "query"}+ :target {:database (:id db)+ :type "table"+ :schema "public"+ :name "hello_transforms_world"})]+ (ts/create! :model/Table+ :name "hello_transforms_world"+ :db_id (:id db)+ :schema "public"+ :transform_id (:id transform))+ (reset! serialized (into [] (serdes.extract/extract {})))))++ (ts/with-db dest-db+ (t2/delete! :model/TransformTag)+ (serdes.load/load-metabase! (ingestion-in-memory @serialized))+ (let [transform (t2/select-one :model/Transform :name "Hello Transform")+ table (t2/select-one :model/Table :name "hello_transforms_world")]+ (is (some? transform))+ (is (some? table))+ (is (= (:id transform) (:transform_id table))))))))))+(deftest dashboard-minimal-required-properties-test(testing "Dashboard deserialized with only: serdes/meta, entity_id, name, creator_id"(let [serialized (atom nil)]diff --git a/src/metabase/warehouse_schema/models/table.clj b/src/metabase/warehouse_schema/models/table.cljindex 26425cc78be..cde9cf2d314 100644--- a/src/metabase/warehouse_schema/models/table.clj+++ b/src/metabase/warehouse_schema/models/table.clj@@ -565,9 +565,10 @@(t2/select-one :model/Database :id (:db_id table)));;; ------------------------------------------------- Serialization --------------------------------------------------(defmethod serdes/dependencies "Table" [{:keys [db_id collection_id]}]+(defmethod serdes/dependencies "Table" [{:keys [db_id collection_id transform_id]}](cond-> [[{:model "Database" :id db_id}]]- collection_id (conj [{:model "Collection" :id collection_id}])))+ collection_id (conj [{:model "Collection" :id collection_id}])+ transform_id (conj [{:model "Transform" :id transform_id}])))(defmethod serdes/descendants "Table" [_model-name id {:keys [skip-archived]}](let [fields (into {} (for [field-id (t2/select-pks-set :model/Field {:where [:= :table_id id]})]