Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backfill note subscriptions #5304

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions db/migrate/20241023004427_backfill_note_subscriptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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
1 change: 1 addition & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3397,6 +3397,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('23'),
('22'),
('21'),
('20241023004427'),
('20241022141247'),
('20240913171951'),
('20240912181413'),
Expand Down