20190328000000_rename_locale_on_users.rb 947 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class RenameLocaleOnUsers < ActiveRecord::Migration[5.1]
  3. def up
  4. return if !Setting.exists?(name: 'system_init_done')
  5. return if ActiveRecord::Base.connection.columns('users').map(&:name).exclude?('locale')
  6. ActiveRecord::Migration.rename_column(:users, :locale, :_locale)
  7. User.reset_column_information
  8. attribute = ObjectManager::Attribute.get(
  9. object: 'User',
  10. name: 'locale',
  11. )
  12. return if !attribute
  13. attribute.update(name: '_locale')
  14. end
  15. def down
  16. return if ActiveRecord::Base.connection.columns('users').map(&:name).exclude?('_locale')
  17. ActiveRecord::Migration.rename_column(:users, :_locale, :locale)
  18. User.reset_column_information
  19. attribute = ObjectManager::Attribute.get(
  20. object: 'User',
  21. name: '_locale',
  22. )
  23. return if !attribute
  24. attribute.update(name: 'locale')
  25. end
  26. end