FIX: Delete extraneous topic bookmarks (#16926)
Otherwise the migration can fail Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
parent
95e7e10417
commit
f00e282067
|
@ -14,6 +14,17 @@ class BackfillPolymorphicBookmarksAndMakeDefault < ActiveRecord::Migration[7.0]
|
|||
WHERE NOT bookmarks.for_topic AND bookmarkable_id IS NULL
|
||||
SQL
|
||||
|
||||
DB.exec(<<~SQL)
|
||||
DELETE FROM bookmarks
|
||||
WHERE id NOT IN (
|
||||
SELECT MIN(bookmarks.id)
|
||||
FROM bookmarks
|
||||
INNER JOIN posts ON bookmarks.post_id = posts.id
|
||||
WHERE bookmarks.for_topic
|
||||
GROUP BY (bookmarks.user_id, posts.topic_id)
|
||||
)
|
||||
SQL
|
||||
|
||||
DB.exec(<<~SQL)
|
||||
UPDATE bookmarks
|
||||
SET bookmarkable_id = posts.topic_id, bookmarkable_type = 'Topic'
|
||||
|
|
Loading…
Reference in New Issue