<commit_before>namespace :db do
  task :update_schema do
    system "sed -i '/:primary_key => \"uuid\"/ a\
    t.string   \"uuid\",         :limit => 36,  :default => \"\",   :null => false
' db/schema.rb"
    system "sed -i 's/:primary_key => \"uuid\"/:id => false/' db/schema.rb"
  end
  
  # Append behavior to rails rake task to correct db/schema.rb, so that the test would work correctly
  Rake::Task["db:schema:dump"].enhance do
    Rake::Task["db:update_schema"].invoke
  end
  
  task :add_primary_keys => :environment do
    Dir["#{Rails.root}/app/models/**/*.rb"].each { |path| require path }
    ActiveRecord::Base.descendants.each do |model|
      next if model.abstract_class
      
      begin
        ActiveRecord::Base.connection.execute "ALTER TABLE #{model.table_name} ADD PRIMARY KEY (#{model.primary_key});"
      rescue => e
        p e
      end
    end
  end
end<commit_msg>add primary key on a specificed model<commit_after>namespace :db do
  task :update_schema do
    system "sed -i '/:primary_key => \"uuid\"/ a\
    t.string   \"uuid\",         :limit => 36,  :default => \"\",   :null => false
' db/schema.rb"
    system "sed -i 's/:primary_key => \"uuid\"/:id => false/' db/schema.rb"
  end
  
  # Append behavior to rails rake task to correct db/schema.rb, so that the test would work correctly
  Rake::Task["db:schema:dump"].enhance do
    Rake::Task["db:update_schema"].invoke
  end
  
  task :add_primary_keys => :environment do
    Dir["#{Rails.root}/app/models/**/*.rb"].each { |path| require path }
    ActiveRecord::Base.descendants.each do |model|
      next if model.abstract_class
      
      add_primary_key(model.table_name, model.primary_key)
    end
  end
  
  task :add_primary_key, [:model_name] => :environment do |t, args|
    model = Object.const_get(args.model_name)
    
    add_primary_key(model.table_name, model.primary_key)
  end
  
  private
  def add_primary_key(table_name, primary_key)
    begin
      ActiveRecord::Base.connection.execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{primary_key});"
    rescue => e
      p e
    end
  end
end
{'fraction_non_alphanumeric': 0.14102564102564102, 'fraction_numerical': 0.001899335232668566, 'mean_word_length': 2.9530956848030017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '3935698', 'n_tokens_mistral': 703, 'n_tokens_neox': 702, 'n_words': 182}