From c848a88240a627711635627d03fbd4ef90955c93 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 23 Oct 2024 18:20:25 +0300 Subject: [PATCH] Backfill note subscriptions --- .../20241023004427_backfill_note_subscriptions.rb | 15 +++++++++++++++ db/structure.sql | 1 + 2 files changed, 16 insertions(+) create mode 100644 db/migrate/20241023004427_backfill_note_subscriptions.rb diff --git a/db/migrate/20241023004427_backfill_note_subscriptions.rb b/db/migrate/20241023004427_backfill_note_subscriptions.rb new file mode 100644 index 000000000..3c9a2ef9b --- /dev/null +++ b/db/migrate/20241023004427_backfill_note_subscriptions.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index 35ef5e2b3..9679e0b92 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3397,6 +3397,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('23'), ('22'), ('21'), +('20241023004427'), ('20241022141247'), ('20240913171951'), ('20240912181413'), -- 2.39.5