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