20190328000000_rename_locale_on_users.rb 870 B

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