Fix language settings for users having selected the kmr
language (#26787)
This commit is contained in:
parent
ece1ff77d6
commit
cddef4c485
3 changed files with 58 additions and 2 deletions
27
db/post_migrate/20230904134623_fix_kmr_locale_settings.rb
Normal file
27
db/post_migrate/20230904134623_fix_kmr_locale_settings.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class FixKmrLocaleSettings < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class MigrationUser < ApplicationRecord
|
||||
self.table_name = :users
|
||||
end
|
||||
|
||||
def up
|
||||
MigrationUser.reset_column_information
|
||||
|
||||
MigrationUser.where.not(settings: [nil, '{}']).find_each do |user|
|
||||
user_settings = Oj.load(user.settings)
|
||||
next unless user_settings['default_language'] == 'kmr'
|
||||
|
||||
user_settings['default_language'] = 'ku'
|
||||
user.update!(settings: Oj.dump(user_settings))
|
||||
end
|
||||
|
||||
MigrationUser.where.not(chosen_languages: nil).where('chosen_languages && ?', '{kmr}').find_each do |user|
|
||||
user.update!(chosen_languages: user.chosen_languages.map { |lang| lang == 'kmr' ? 'ku' : lang }.uniq)
|
||||
end
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_08_22_081029) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_09_04_134623) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue