Skip to content

Commit

Permalink
Merge pull request metabase#6568 from metabase/fix-native-queries-wit…
Browse files Browse the repository at this point in the history
…h-deleted-db-27

Check to ensure database exists before updating card in migration
  • Loading branch information
senior authored Dec 12, 2017
2 parents 055e448 + 1a58489 commit 96e708e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/metabase/db/migrations.clj
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,12 @@
;; missing those database ids
(defmigration ^{:author "senior", :added "0.27.0"} populate-card-database-id
(doseq [[db-id cards] (group-by #(get-in % [:dataset_query :database])
(db/select [Card :dataset_query :id] :database_id [:= nil]))
(db/select [Card :dataset_query :id :name] :database_id [:= nil]))
:when (not= db-id virtual-id)]
(db/update-where! Card {:id [:in (map :id cards)]}
:database_id db-id)))
(if (and (seq cards)
(db/exists? Database :id db-id))
(db/update-where! Card {:id [:in (map :id cards)]}
:database_id db-id)
(doseq [{id :id card-name :name} cards]
(log/warnf "Cleaning up orphaned Question '%s', associated to a now deleted database" card-name)
(db/delete! Card :id id)))))

0 comments on commit 96e708e

Please sign in to comment.