about summary refs log tree commit diff
path: root/db/post_migrate/20200917193528_migrate_notifications_type.rb
blob: 9dc9ecd48e2d40b4ab0eded71e57f38ce65af87d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

class MigrateNotificationsType < ActiveRecord::Migration[5.2]
  disable_ddl_transaction!

  TYPES_TO_MIGRATE = {
    'Mention' => :mention,
    'Status' => :reblog,
    'Follow' => :follow,
    'FollowRequest' => :follow_request,
    'Favourite' => :favourite,
    'Poll' => :poll,
  }.freeze

  def up
    TYPES_TO_MIGRATE.each_pair do |activity_type, type|
      Notification.where(activity_type: activity_type, type: nil).in_batches.update_all(type: type)
    end
  end

  def down; end
end