]> git.openstreetmap.org Git - rails.git/blob - db/migrate/20241023004427_backfill_note_subscriptions.rb
Don't send comment text when reopening a note
[rails.git] / db / migrate / 20241023004427_backfill_note_subscriptions.rb
1 class BackfillNoteSubscriptions < ActiveRecord::Migration[7.2]
2   class NoteComment < ApplicationRecord; end
3   class NoteSubscription < ApplicationRecord; end
4
5   disable_ddl_transaction!
6
7   def up
8     attrs = %w[user_id note_id]
9
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 })
13     end
14   end
15 end