<commit_before>require "activerecord-connection-reset-pk-sequence/version"

module ActiveRecord
  module ConnectionAdapters
    class AbstractAdapter
      def reset_pk_sequence!(table_name)
        model = table_name.classify.constantize
        case adapter_name
        when 'SQLite'
          new_max = model.maximum(model.primary_key) || 0
          update_seq_sql = "UPDATE sqlite_sequence SET seq = #{new_max} WHERE name = '#{table_name}';"
          execute(update_seq_sql)
        when 'Mysql', 'Mysql2'
          new_max = model.maximum(model.primary_key) + 1 || 1
          update_seq_sql = "ALTER TABLE `#{table_name}` AUTO_INCREMENT = #{new_max};"
          execute(update_seq_sql)
        when 'PostgreSQL'
          reset_pk_sequence!(table_name)
        else 
          raise "Task not implemented for this DB adapter"
        end 
      end
    end
  end
end
<commit_msg>Fix bug where it would try to add nil<commit_after>require "activerecord-connection-reset-pk-sequence/version"

module ActiveRecord
  module ConnectionAdapters
    class AbstractAdapter
      def reset_pk_sequence!(table_name)
        model = table_name.classify.constantize
        case adapter_name
        when 'SQLite'
          new_max = model.maximum(model.primary_key) || 0
          update_seq_sql = "UPDATE sqlite_sequence SET seq = #{new_max} WHERE name = '#{table_name}';"
          execute(update_seq_sql)
        when 'Mysql', 'Mysql2'
          max = model.maximum(model.primary_key) || 0
          new_max = max + 1
          update_seq_sql = "ALTER TABLE `#{table_name}` AUTO_INCREMENT = #{new_max};"
          execute(update_seq_sql)
        when 'PostgreSQL'
          reset_pk_sequence!(table_name)
        else
          raise "Task not implemented for this DB adapter"
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08415841584158416, 'fraction_numerical': 0.0044004400440044, 'mean_word_length': 2.566666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6712760', 'n_tokens_mistral': 560, 'n_tokens_neox': 543, 'n_words': 130}