0
0
Fork 0

Fix language settings for users having selected the kmr language (#26787)

This commit is contained in:
Claire 2023-09-04 17:56:31 +02:00 committed by GitHub
parent ece1ff77d6
commit cddef4c485
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 2 deletions

View 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

View file

@ -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"