diaspora/db/migrate/20170917163640_cleanup_invalid_o_embed_caches.rb
Benjamin Neff b8fb4b6251
Delete invalid oEmbed caches with binary titles
There are a few old oEmbed caches which have the title saved in binary
(because they contain Chinese characters). This fails with
`ActionView::Template::Error ("å" from ASCII-8BIT to UTF-8)`. Since I
found only very old OEmbed caches with this problem (newest from 2012),
I think we can just remove these. When I create a new oEmbed cache for
the same URL it creates it without `!binary`.

closes #7620
2017-09-28 23:10:07 +02:00

12 lines
386 B
Ruby

class CleanupInvalidOEmbedCaches < ActiveRecord::Migration[5.1]
class OEmbedCache < ApplicationRecord
end
class Post < ApplicationRecord
end
def up
ids = OEmbedCache.where("data LIKE '%!binary%'").ids
Post.where(o_embed_cache_id: ids).update_all(o_embed_cache_id: nil) # rubocop:disable Rails/SkipsModelValidations
OEmbedCache.where(id: ids).delete_all
end
end