]> git.openstreetmap.org Git - rails.git/commitdiff
Backfill note subscriptions
authorAnton Khorev <tony29@yandex.ru>
Wed, 23 Oct 2024 15:20:25 +0000 (18:20 +0300)
committerAnton Khorev <tony29@yandex.ru>
Fri, 8 Nov 2024 07:30:43 +0000 (10:30 +0300)
db/migrate/20241023004427_backfill_note_subscriptions.rb [new file with mode: 0644]
db/structure.sql

diff --git a/db/migrate/20241023004427_backfill_note_subscriptions.rb b/db/migrate/20241023004427_backfill_note_subscriptions.rb
new file mode 100644 (file)
index 0000000..3c9a2ef
--- /dev/null
@@ -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
index 35ef5e2b3107518378de971a2691f8413c7271fa..9679e0b92561617b120b347632a2373bfa9aebcc 100644 (file)
@@ -3397,6 +3397,7 @@ INSERT INTO "schema_migrations" (version) VALUES
 ('23'),
 ('22'),
 ('21'),
 ('23'),
 ('22'),
 ('21'),
+('20241023004427'),
 ('20241022141247'),
 ('20240913171951'),
 ('20240912181413'),
 ('20241022141247'),
 ('20240913171951'),
 ('20240912181413'),