openstreetmap-website/db/migrate/20241023004427_backfill_note_subscriptions.rb
2024-11-08 10:30:43 +03:00

15 lines
469 B
Ruby

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