20181026034033_remove_faux_remote_account_duplicates.rb 2.0 KB

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