]> git.openstreetmap.org Git - rails.git/blob - db/migrate/20241023004427_backfill_note_subscriptions.rb
Add frozen_string_literal comments to ruby files
[rails.git] / db / migrate / 20241023004427_backfill_note_subscriptions.rb
1 # frozen_string_literal: true
2
3 class BackfillNoteSubscriptions < ActiveRecord::Migration[7.2]
4   class NoteComment < ApplicationRecord; end
5   class NoteSubscription < ApplicationRecord; end
6
7   disable_ddl_transaction!
8
9   def up
10     attrs = %w[user_id note_id]
11
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 })
15     end
16   end
17 end