20230904134623_fix_kmr_locale_settings.rb 789 B

123456789101112131415161718192021222324252627
  1. # frozen_string_literal: true
  2. class FixKmrLocaleSettings < ActiveRecord::Migration[7.0]
  3. disable_ddl_transaction!
  4. class MigrationUser < ApplicationRecord
  5. self.table_name = :users
  6. end
  7. def up
  8. MigrationUser.reset_column_information
  9. MigrationUser.where.not(settings: [nil, '{}']).find_each do |user|
  10. user_settings = Oj.load(user.settings)
  11. next unless user_settings['default_language'] == 'kmr'
  12. user_settings['default_language'] = 'ku'
  13. user.update!(settings: Oj.dump(user_settings))
  14. end
  15. MigrationUser.where.not(chosen_languages: nil).where('chosen_languages && ?', '{kmr}').find_each do |user|
  16. user.update!(chosen_languages: user.chosen_languages.map { |lang| lang == 'kmr' ? 'ku' : lang }.uniq)
  17. end
  18. end
  19. def down; end
  20. end