From 4445c9e1bdb5e1d0c4a72efa4609c15334651b19 Mon Sep 17 00:00:00 2001 From: Noah Moss <32746338+noahmoss@users.noreply.github.com> Date: Fri, 14 Oct 2022 16:43:05 -0400 Subject: [PATCH] Automatically set initial sync status of crufty tables to `complete` (#25945) * set initial sync status of crufty tables to complete automatically * fix test --- src/metabase/sync/sync_metadata/tables.clj | 18 ++++++++++-------- .../sync/sync_metadata/tables_test.clj | 6 +++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/metabase/sync/sync_metadata/tables.clj b/src/metabase/sync/sync_metadata/tables.clj index 82b640d5b5e..cf0a76e6788 100644 --- a/src/metabase/sync/sync_metadata/tables.clj +++ b/src/metabase/sync/sync_metadata/tables.clj @@ -110,14 +110,16 @@ (db/update! Table existing-id :active true) ;; otherwise create a new Table - (db/insert! Table - :db_id (u/the-id database) - :schema schema - :name table-name - :display_name (humanization/name->human-readable-name table-name) - :active true - :visibility_type (when (is-crufty-table? table) - :cruft))))) + (let [is-crufty? (is-crufty-table? table)] + (db/insert! Table + :db_id (u/the-id database) + :schema schema + :name table-name + :display_name (humanization/name->human-readable-name table-name) + :active true + :visibility_type (when is-crufty? :cruft) + ;; if this is a crufty table, mark initial sync as complete since we'll skip the subsequent sync steps + :initial_sync_status (if is-crufty? "complete" "incomplete")))))) (s/defn ^:private retire-tables! diff --git a/test/metabase/sync/sync_metadata/tables_test.clj b/test/metabase/sync/sync_metadata/tables_test.clj index ec60cf98376..7a68b443f1e 100644 --- a/test/metabase/sync/sync_metadata/tables_test.clj +++ b/test/metabase/sync/sync_metadata/tables_test.clj @@ -25,9 +25,9 @@ (deftest crufty-tables-test (testing "south_migrationhistory, being a CRUFTY table, should still be synced, but marked as such" (mt/dataset metabase.sync.sync-metadata.tables-test/db-with-some-cruft - (is (= #{{:name "SOUTH_MIGRATIONHISTORY", :visibility_type :cruft} - {:name "ACQUIRED_TOUCANS", :visibility_type nil}} - (set (for [table (db/select [Table :name :visibility_type], :db_id (mt/id))] + (is (= #{{:name "SOUTH_MIGRATIONHISTORY", :visibility_type :cruft, :initial_sync_status "complete"} + {:name "ACQUIRED_TOUCANS", :visibility_type nil, :initial_sync_status "complete"}} + (set (for [table (db/select [Table :name :visibility_type :initial_sync_status], :db_id (mt/id))] (into {} table)))))))) (deftest retire-tables-test -- GitLab