20181026034033_remove_faux_remote_account_duplicates.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. class RemoveFauxRemoteAccountDuplicates < ActiveRecord::Migration[5.2]
  2. disable_ddl_transaction!
  3. class StreamEntry < ApplicationRecord
  4. # Dummy class, to make migration possible across version changes
  5. belongs_to :account, inverse_of: :stream_entries
  6. end
  7. class Status < ApplicationRecord
  8. # Dummy class, to make migration possible across version changes
  9. belongs_to :account, inverse_of: :statuses
  10. has_many :favourites, inverse_of: :status, dependent: :destroy
  11. has_many :mentions, dependent: :destroy, inverse_of: :status
  12. end
  13. class Favourite < ApplicationRecord
  14. # Dummy class, to make migration possible across version changes
  15. belongs_to :account, inverse_of: :favourites
  16. belongs_to :status, inverse_of: :favourites
  17. end
  18. class Mention < ApplicationRecord
  19. # Dummy class, to make migration possible across version changes
  20. belongs_to :account, inverse_of: :mentions
  21. belongs_to :status
  22. end
  23. class Notification < ApplicationRecord
  24. # Dummy class, to make migration possible across version changes
  25. belongs_to :account, optional: true
  26. belongs_to :from_account, class_name: 'Account', optional: true
  27. belongs_to :activity, polymorphic: true, optional: true
  28. end
  29. class Account < ApplicationRecord
  30. # Dummy class, to make migration possible across version changes
  31. has_many :stream_entries, inverse_of: :account, dependent: :destroy
  32. has_many :statuses, inverse_of: :account, dependent: :destroy
  33. has_many :favourites, inverse_of: :account, dependent: :destroy
  34. has_many :mentions, inverse_of: :account, dependent: :destroy
  35. has_many :notifications, inverse_of: :account, dependent: :destroy
  36. end
  37. def up
  38. local_domain = Rails.configuration.x.local_domain
  39. # Just a safety measure to ensure that under no circumstance
  40. # we will query `domain IS NULL` because that would return
  41. # actually local accounts, the originals
  42. return if local_domain.nil?
  43. Account.where(domain: local_domain).in_batches.destroy_all
  44. end
  45. def down; end
  46. end