diff --git a/db/migrate/20181024224956_migrate_account_conversations.rb b/db/migrate/20181024224956_migrate_account_conversations.rb index b718f9e1d524e7..fdb35b0c9ec7d6 100644 --- a/db/migrate/20181024224956_migrate_account_conversations.rb +++ b/db/migrate/20181024224956_migrate_account_conversations.rb @@ -2,40 +2,7 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - say '' - say 'WARNING: This migration may take a *long* time for large instances' - say 'It will *not* lock tables for any significant time, but it may run' - say 'for a very long time. We will pause for 10 seconds to allow you to' - say 'interrupt this migration if you are not ready.' - say '' - - 10.downto(1) do |i| - say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true - sleep 1 - end - - migrated = 0 - last_time = Time.zone.now - - local_direct_statuses.includes(:account, mentions: :account).find_each do |status| - AccountConversation.add_status(status.account, status) - migrated += 1 - - if Time.zone.now - last_time > 1 - say_progress(migrated) - last_time = Time.zone.now - end - end - - notifications_about_direct_statuses.includes(:account, mention: { status: [:account, mentions: :account] }).find_each do |notification| - AccountConversation.add_status(notification.account, notification.target_status) - migrated += 1 - - if Time.zone.now - last_time > 1 - say_progress(migrated) - last_time = Time.zone.now - end - end + # migrated to rake task end def down diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index ee9657b0eff06c..6bb8d63ac8b33b 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -4,6 +4,27 @@ require 'tty-command' require 'tty-prompt' namespace :mastodon do + namespace :migrate do + desc 'migrate AccountConversation' + task accountConversation: :environment do + migrated = 0 + Status.unscoped.local.where(visibility: :direct).includes(:account, mentions: :account).find_each do |status| + AccountConversation.add_status(status.account, status) + migrated += 1 + + puts "Migrated #{migrated} rows" + end + + puts + Notification.joins(mention: :status).where(activity_type: 'Mention', statuses: { visibility: :direct }).includes(:account, mention: { status: [:account, mentions: :account] }).find_each do |notification| + AccountConversation.add_status(notification.account, notification.target_status) + migrated += 1 + + puts "Migrated #{migrated} rows" + end + end + end + desc 'Configure the instance for production use' task :setup do prompt = TTY::Prompt.new