<commit_before># frozen_string_literal: true
# This migration comes from decidim_proposals (originally 20200708091228)

class MoveProposalsFieldsToI18n < ActiveRecord::Migration[5.2]
  def up
    add_column :decidim_proposals_proposals, :new_title, :jsonb
    add_column :decidim_proposals_proposals, :new_body, :jsonb

    reset_column_information

    PaperTrail.request(enabled: false) do
      Decidim::Proposals::Proposal.includes(coauthorships: :author).find_each do |proposal|
        author = proposal.coauthorships.first.author

        locale = if author
                   author.locale.presence
                 else
                   I18n.default_locale.to_s
                 end

        proposal.new_title = {
          locale => proposal.title
        }<commit_msg>Fix case when author is an organization<commit_after># frozen_string_literal: true
# This migration comes from decidim_proposals (originally 20200708091228)

class MoveProposalsFieldsToI18n < ActiveRecord::Migration[5.2]
  def up
    add_column :decidim_proposals_proposals, :new_title, :jsonb
    add_column :decidim_proposals_proposals, :new_body, :jsonb

    reset_column_information

    PaperTrail.request(enabled: false) do
      Decidim::Proposals::Proposal.includes(coauthorships: :author).find_each do |proposal|
        author = proposal.coauthorships.first.author

        locale = if author
                   author.try(:locale).presence
                 else
                   I18n.default_locale.to_s
                 end

        proposal.new_title = {
          locale => proposal.title
        }
{'fraction_non_alphanumeric': 0.07205513784461152, 'fraction_numerical': 0.02506265664160401, 'mean_word_length': 2.81145584725537, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7394247', 'n_tokens_mistral': 509, 'n_tokens_neox': 473, 'n_words': 92}