You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
585 B

  1. # frozen_string_literal: true
  2. class ClearOrphanedAccountNotes < ActiveRecord::Migration[5.2]
  3. class Account < ApplicationRecord
  4. # Dummy class, to make migration possible across version changes
  5. end
  6. class AccountNote < ApplicationRecord
  7. # Dummy class, to make migration possible across version changes
  8. belongs_to :account
  9. belongs_to :target_account, class_name: 'Account'
  10. end
  11. def up
  12. AccountNote.where('NOT EXISTS (SELECT * FROM users u WHERE u.account_id = account_notes.account_id)').in_batches.delete_all
  13. end
  14. def down
  15. # nothing to do
  16. end
  17. end