1 # frozen_string_literal: true
 
   3 class BackfillNoteSubscriptions < ActiveRecord::Migration[7.2]
 
   4   class NoteComment < ApplicationRecord; end
 
   5   class NoteSubscription < ApplicationRecord; end
 
   7   disable_ddl_transaction!
 
  10     attrs = %w[user_id note_id]
 
  12     NoteComment.in_batches(:of => 1000) do |note_comments|
 
  13       rows = note_comments.distinct.where.not(:author_id => nil).pluck(:author_id, :note_id)
 
  14       NoteSubscription.upsert_all(rows.map { |r| attrs.zip(r).to_h })