<commit_before><commit_msg>rake task: added rake task db:fixtures:dump to create fixtures from the database.<commit_after>
namespace :db do
  namespace :fixtures do
    desc 'Create YAML test fixtures from a particular table in an existing database. Requires TABLE env set.'
    task :dump => :environment do
      table = ENV['TABLE']
      unless ActiveRecord::Base.connection.tables.include?(table)
        puts 'Table "%s" not found' % table
        exit
      end
      ActiveRecord::Base.establish_connection
      i = "000"
      sql  = "SELECT * FROM `#{table}`"
      filename = "#{RAILS_ROOT}/test/fixtures/#{table}.yml"
      File.open(filename, 'w') do |file|
        data = ActiveRecord::Base.connection.select_all(sql)
        file.write data.inject({}) {|hash, record|
          hash["#{table}_#{i.succ!}"] = record
          hash
        }.to_yaml
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12008978675645342, 'fraction_numerical': 0.003367003367003367, 'mean_word_length': 2.7796610169491527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2937135', 'n_tokens_mistral': 269, 'n_tokens_neox': 264, 'n_words': 78}