<commit_before>class AddSelectFieldTypeToCustomFormsPluginFields < ActiveRecord::Migration
  def self.up
    change_table :custom_forms_plugin_fields do |t|
      t.string :select_field_type
    end

    CustomFormsPlugin::Field.find_each do |f|
      if !f.list && !f.multiple
        f.select_field_type = :radio
      elsif !f.list && f.multiple
        f.select_field_type = :check_box
      elsif f.list && !f.multiple
        f.select_field_type = :select
      else
        f.select_field_type = :multiple_select
      end
      f.save!
    end

    change_table :custom_forms_plugin_fields do |t|
      t.remove :multiple, :list
    end
  end

  def self.down
    raise ActiveRecord::IrreversibleMigration
  end<commit_msg>custom-forms: replace ruby code by sql on migration<commit_after>class AddSelectFieldTypeToCustomFormsPluginFields < ActiveRecord::Migration
  def self.up
    change_table :custom_forms_plugin_fields do |t|
      t.string :select_field_type
    end

    update("UPDATE custom_forms_plugin_fields SET select_field_type='radio' WHERE list IS FALSE AND multiple IS FALSE")
    update("UPDATE custom_forms_plugin_fields SET select_field_type='check_box' WHERE list IS FALSE AND multiple IS TRUE")
    update("UPDATE custom_forms_plugin_fields SET select_field_type='select' WHERE list IS TRUE AND multiple IS FALSE")
    update("UPDATE custom_forms_plugin_fields SET select_field_type='multiple_select' WHERE list IS TRUE AND multiple IS TRUE")

    change_table :custom_forms_plugin_fields do |t|
      t.remove :multiple, :list
    end
  end

  def self.down
    change_table :custom_forms_plugin_fields do |t|
      t.boolean :multiple
      t.boolean :list
    end

    update("UPDATE custom_forms_plugin_fields SET list=TRUE, multiple=FALSE WHERE select_field_type='radio'")
    update("UPDATE custom_forms_plugin_fields SET list=FALSE, multiople=TRUE WHERE select_field_type='check_box'")
    update("UPDATE custom_forms_plugin_fields SET list=TRUE, multiple=FALSE WHERE select_field_type='select'")
    update("UPDATE custom_forms_plugin_fields SET list=TRUE, multiple=TRUE WHERE select_field_type='multiple_select'")

    change_table :custom_forms_plugin_fields do |t|
      t.remove :select_fields_type
    end
  end
{'fraction_non_alphanumeric': 0.07057256990679095, 'fraction_numerical': 0.0, 'mean_word_length': 4.229698375870069, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6005248', 'n_tokens_mistral': 667, 'n_tokens_neox': 659, 'n_words': 172}