import.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: imports
  5. #
  6. # id :bigint(8) not null, primary key
  7. # type :integer not null
  8. # approved :boolean default(FALSE), not null
  9. # created_at :datetime not null
  10. # updated_at :datetime not null
  11. # data_file_name :string
  12. # data_content_type :string
  13. # data_file_size :integer
  14. # data_updated_at :datetime
  15. # account_id :bigint(8) not null
  16. # overwrite :boolean default(FALSE), not null
  17. #
  18. # NOTE: This is a deprecated model, only kept to not break ongoing imports
  19. # on upgrade. See `BulkImport` and `Form::Import` for its replacements.
  20. class Import < ApplicationRecord
  21. FILE_TYPES = %w(text/plain text/csv application/csv).freeze
  22. MODES = %i(merge overwrite).freeze
  23. self.inheritance_column = false
  24. belongs_to :account
  25. enum type: { following: 0, blocking: 1, muting: 2, domain_blocking: 3, bookmarks: 4 }
  26. validates :type, presence: true
  27. has_attached_file :data
  28. validates_attachment_content_type :data, content_type: FILE_TYPES
  29. validates_attachment_presence :data
  30. def mode
  31. overwrite? ? :overwrite : :merge
  32. end
  33. def mode=(str)
  34. self.overwrite = str.to_sym == :overwrite
  35. end
  36. end