about summary refs log tree commit diff
path: root/db/migrate/20200407202420_migrate_unavailable_inboxes.rb
blob: 8f9c687942b011723c95728efce7b534c3a14025 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class MigrateUnavailableInboxes < ActiveRecord::Migration[5.2]
  disable_ddl_transaction!

  def up
    redis = RedisConfiguration.pool.checkout
    urls = redis.smembers('unavailable_inboxes')

    hosts = urls.map do |url|
      Addressable::URI.parse(url).normalized_host
    end.compact.uniq

    UnavailableDomain.delete_all

    hosts.each do |host|
      UnavailableDomain.create(domain: host)
    end

    redis.del(*(['unavailable_inboxes'] + redis.keys('exhausted_deliveries:*')))
  end

  def down; end
end