Skip to content
Snippets Groups Projects
Unverified Commit 84735b55 authored by Cal Herries's avatar Cal Herries Committed by GitHub
Browse files

Revert "Revert updating FKs during metadata sync (#39679) (#39924)" (#40233)

parent f2e8df68
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,9 @@
;; - fk_target_field_id is NULL and the new target is not NULL
;; - fk_target_field_id is not NULL but the new target is different and not NULL
[pk-field-id-query :pk]
[:= :f.fk_target_field_id nil]]
[:or
[:= :f.fk_target_field_id nil]
[:not= :f.fk_target_field_id :pk.id]]]
:set {:fk_target_field_id :pk.id
:semantic_type "type/FK"}}
:postgres
......@@ -62,7 +64,9 @@
:semantic_type "type/FK"}
:where [:and
[:= :fk.id :f.id]
[:= :f.fk_target_field_id nil]]}
[:or
[:= :f.fk_target_field_id nil]
[:not= :f.fk_target_field_id :pk.id]]]}
:h2
{:update [:metabase_field :f]
:set {:fk_target_field_id pk-field-id-query
......@@ -70,7 +74,9 @@
:where [:and
[:= :f.id fk-field-id-query]
[:not= pk-field-id-query nil]
[:= :f.fk_target_field_id nil]]})]
[:or
[:= :f.fk_target_field_id nil]
[:not= :f.fk_target_field_id pk-field-id-query]]]})]
(sql/format q :dialect (mdb.connection/quoting-style (mdb.connection/db-type)))))
(mu/defn ^:private mark-fk!
......
......@@ -247,8 +247,7 @@
;; 3. add back the FK relationship but targeting continent_2
(jdbc/execute! db-spec "ALTER TABLE country ADD CONSTRAINT country_continent_id_fkey FOREIGN KEY (continent_id) REFERENCES continent_2(id);")
(sync/sync-database! db {:scan :schema})
;; FIXME: The following test fails. This was fixed (metabase#39679) but regressed to solve a flakey test (metabase#39861)
#_(testing "initially country's continent_id is targeting continent_2"
(testing "initially country's continent_id is targeting continent_2"
(is (=? {:fk_target_field_id (mt/id :continent_2 :id)
:semantic_type :type/FK}
(get-fk)))))))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment