Move custom language to default one (ES_XX to es)

Executing the following in a rails console should work:

old_locale = "es_XX"
new_locale = "es"

DB.exec <<~SQL
  UPDATE users
  SET locale = '#{new_locale}'
  WHERE locale = '#{old_locale}'
SQL

DB.exec <<~SQL
  UPDATE site_settings
  SET value = '#{new_locale}'
  WHERE name = 'default_locale' AND value = '#{old_locale}'
SQL

DB.exec <<~SQL
  UPDATE translation_overrides
  SET locale = '#{new_locale}'
  WHERE locale = '#{old_locale}'
SQL

DB.exec <<~SQL
  UPDATE theme_translation_overrides
  SET locale = '#{new_locale}'
  WHERE locale = '#{old_locale}'
SQL

def fix_search_data(model)
  key = "#{model}_id"
  table = "#{model}_search_data"

  puts "Migrating #{table} to new_locale locale."

  sql = <<~SQL
    UPDATE #{table}
        SET locale = '#{new_locale}'
      WHERE #{key} IN (
            SELECT #{key}
              FROM #{table}
              WHERE locale = '#{old_locale}'
              LIMIT 100000
          )
  SQL

  loop do
    count = DB.exec(sql)
    break if count == 0
    puts "Migrated #{count} rows of #{table} to new locale."
  end
end
  
%w[category tag topic user].each { |model| fix_search_data(model) }