<commit_before># Rails dropped the class
# ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlDateTime
# via: https://github.com/rails/rails/commit/f1a0fa9e19b7e4ccaea191fc6cf0613880222ee7
# which we use in stored Cti::Log instance preferences.
# Since we don't need the instances but just an Hash we have to:
# - create a dummy class
# - loop over all instances
# - deserialize them in the preferences
# - replace them in the preferences with the Hash version

# create a dummy class
module ActiveRecord
  module ConnectionAdapters
    class AbstractMysqlAdapter
      class MysqlDateTime < Type::DateTime
      end
    end
  end
end

class CtiLogPreferencesMigration < ActiveRecord::Migration[5.0]

  def change
    # correct all entries
    Cti::Log.all.each do |item|
      next if !item.preferences
      next if item.preferences.blank?

      # check from and to keys which hold the instances
      %w(from to).each do |direction|
        next if item.preferences[direction].blank?

        # loop over all instances and covert them
        # to an Hash via .attributes
        updated = item.preferences[direction].each_with_object([]) do |caller_id, new_direction|<commit_msg>Improved migration to work also with postgresql.<commit_after># Rails dropped the class
# ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlDateTime
# via: https://github.com/rails/rails/commit/f1a0fa9e19b7e4ccaea191fc6cf0613880222ee7
# ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer
# via: https://github.com/rails/rails/commit/aafee233fb3b4211ee0bfb1fca776c159bd1067e
# which we use in stored Cti::Log instance preferences.
# Since we don't need the instances but just an Hash we have to:
# - create a dummy class
# - loop over all instances
# - deserialize them in the preferences
# - replace them in the preferences with the Hash version

# create a dummy class
module ActiveRecord
  module ConnectionAdapters
    class AbstractMysqlAdapter
      class MysqlDateTime < Type::DateTime
      end
    end
  end
end
module ActiveRecord
  module ConnectionAdapters
    module PostgreSQL
      module OID
        class Integer < Type::Integer
        end
      end
    end
  end
end

class CtiLogPreferencesMigration < ActiveRecord::Migration[5.0]

  def change
    # correct all entries
    Cti::Log.all.pluck(:id).each do |item_id|
      item = Cti::Log.find(item_id)
      next if !item.preferences
      next if item.preferences.blank?

      # check from and to keys which hold the instances
      %w(from to).each do |direction|
        next if item.preferences[direction].blank?

        # loop over all instances and covert them
        # to an Hash via .attributes
        updated = item.preferences[direction].each_with_object([]) do |caller_id, new_direction|
{'fraction_non_alphanumeric': 0.07289048473967684, 'fraction_numerical': 0.024416517055655295, 'mean_word_length': 3.6433333333333335, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5524580', 'n_tokens_mistral': 851, 'n_tokens_neox': 795, 'n_words': 262}