<commit_before>class AddHarvestCountToCrop < ActiveRecord::Migration[5.2]
  def change
    change_table :crops do |t|
      t.integer :harvests_count, default: 0
      t.integer :photo_associations_count, default: 0
    end
    change_table :plant_parts do |t|
      t.integer :harvests_count, default: 0
    end
    change_table :posts do |t|
      t.integer :comments_count, default: 0
    end
    reversible do |dir|
      dir.up { data }
    end
  end

  def data
    execute <<-SQL.squish
        UPDATE crops
           SET harvests_count = (
             SELECT count(1)<commit_msg>Index into ES after migration<commit_after>class AddHarvestCountToCrop < ActiveRecord::Migration[5.2]
  def change
    change_table :crops do |t|
      t.integer :harvests_count, default: 0
      t.integer :photo_associations_count, default: 0
    end
    change_table :plant_parts do |t|
      t.integer :harvests_count, default: 0
    end
    change_table :posts do |t|
      t.integer :comments_count, default: 0
    end
    reversible do |dir|
      dir.up { data }
    end

    Crop.reindex
    Planting.reindex
    Seed.reindex
    Harvest.reindex
  end

  def data
    execute <<-SQL.squish
        UPDATE crops
           SET harvests_count = (
             SELECT count(1)
{'fraction_non_alphanumeric': 0.07716535433070866, 'fraction_numerical': 0.011023622047244094, 'mean_word_length': 2.4351351351351354, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '132332', 'n_tokens_mistral': 432, 'n_tokens_neox': 411, 'n_words': 113}