20181108123847_add_country_attribute_to_users.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. # Fixes issue #2333 - Object country already exists
  3. # The country column already exists in the database, but there is no corresponding ObjectManager::Attribute for it
  4. # This migration adds the User.country attribute if and only if it does not exist already
  5. class AddCountryAttributeToUsers < ActiveRecord::Migration[5.1]
  6. def up
  7. # return if it's a new setup
  8. return if !Setting.exists?(name: 'system_init_done')
  9. # return if the country attribute already exists
  10. current_country_attribute = ObjectManager::Attribute.find_by(object_lookup_id: ObjectLookup.by_name('User'), name: 'country')
  11. return if current_country_attribute.present?
  12. ObjectManager::Attribute.add(
  13. force: true,
  14. object: 'User',
  15. name: 'country',
  16. display: 'Country',
  17. data_type: 'input',
  18. data_option: {
  19. type: 'text',
  20. maxlength: 100,
  21. null: true,
  22. item_class: 'formGroup--halfSize',
  23. },
  24. editable: true,
  25. active: false,
  26. screens: {
  27. signup: {},
  28. invite_agent: {},
  29. invite_customer: {},
  30. edit: {
  31. '-all-' => {
  32. null: true,
  33. },
  34. },
  35. view: {
  36. '-all-' => {
  37. shown: true,
  38. },
  39. },
  40. },
  41. to_create: false,
  42. to_migrate: false,
  43. to_delete: false,
  44. position: 1325,
  45. created_by_id: 1,
  46. updated_by_id: 1,
  47. )
  48. end
  49. end