~cytrogen/masto-fe

ref: ee702e36e58d638bcf75b2eae2ca86499693465e masto-fe/db/post_migrate/20210808071221_clear_orphaned_account_notes.rb -rw-r--r-- 585 bytes
ee702e36 — Claire Change follow recommendation materialized view to be faster in most cases (#26545) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

class ClearOrphanedAccountNotes < ActiveRecord::Migration[5.2]
  class Account < ApplicationRecord
    # Dummy class, to make migration possible across version changes
  end

  class AccountNote < ApplicationRecord
    # Dummy class, to make migration possible across version changes
    belongs_to :account
    belongs_to :target_account, class_name: 'Account'
  end

  def up
    AccountNote.where('NOT EXISTS (SELECT * FROM users u WHERE u.account_id = account_notes.account_id)').in_batches.delete_all
  end

  def down
    # nothing to do
  end
end