discourse/db/migrate/20220428094027_fix_post_hotlinked_media_index.rb
David Taylor 19d2d55011
FIX: Ensure post_hotlinked_media index does not exceed size limit (#16609)
On some installations, this would fail with 'index row size exceeds btree version 4 maximum'. This commit replaces the (post_id, url)` index with a `(post_id, md5(url))` index, which is much more space efficient.
2022-05-03 15:47:58 +01:00

23 lines
648 B
Ruby

# frozen_string_literal: true
class FixPostHotlinkedMediaIndex < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
execute <<~SQL
CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS index_post_hotlinked_media_on_post_id_and_url_md5
ON post_hotlinked_media (post_id, md5(url));
SQL
# Failed index introduced in 20220428094026_create_post_hotlinked_media. On some installations it succeeded,
# so we need to clean it up.
execute <<~SQL
DROP INDEX CONCURRENTLY IF EXISTS index_post_hotlinked_media_on_post_id_and_url;
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end