Skip to content
Snippets Groups Projects
Commit fc015c60 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

add a data migration to clean up the duplicate FK entries.

parent 6e56924e
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
(metabase.models [activity :refer [Activity]]
[card :refer [Card]]
[database :refer [Database]]
[foreign-key :refer [ForeignKey]]
[table :refer [Table]]
[setting :as setting])
[metabase.sample-data :as sample-data]
......@@ -96,3 +97,14 @@
(when-not (contains? activity-feed-topics :database-sync-begin)
(k/delete Activity
(k/where {:topic "database-sync"}))))
;; Clean up duplicate FK entries
(defmigration remove-duplicate-fk-entries
(let [existing-fks (db/sel :many ForeignKey)
grouped-fks (group-by #(str (:origin_id %) "_" (:destination_id %)) existing-fks)]
(doseq [[k fks] grouped-fks]
(when (< 1 (count fks))
(log/debug "Removing duplicate FK entries for" k)
(doseq [duplicate-fk (drop-last fks)]
(db/del ForeignKey :id (:id duplicate-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