20181108123847_add_country_attribute_to_users.rb 1.5 KB

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