<commit_before>class ValidationIssue < ActiveRecord::Base
  attr_accessible :form_name, :issue_count, :issue_hash, :issue_type, :notes, :success_count
  serialize :issue_hash, Hash

  validates :form_name,  :presence => true, :uniqueness => true

  def clear_data!
    self.issue_count = 0
    self.issue_hash  = {}
    self.notes = ''
    self.save!
  end

  def increment_issue_count!
    increment_with_sql!('issue_count')
  end

  def increment_success_count!
    increment_with_sql!('success_count')
  end

  def total_count
    success_count + issue_count
  end

  protected

    def increment_with_sql!(attribute, by = 1)
      raise ArgumentError("Invalid attribute: #{attribute}") unless attribute_names.include?(attribute.to_s)
      original_value_sql = "CASE WHEN `#{attribute}` IS NULL THEN 0 ELSE `#{attribute}` END"
      self.class.update_all("`#{attribute}` = #{original_value_sql} + #{by.to_i}", "id = #{id}")
      reload
    end
end<commit_msg>get SQL to work on postgres <commit_after>class ValidationIssue < ActiveRecord::Base
  attr_accessible :form_name, :issue_count, :issue_hash, :issue_type, :notes, :success_count
  serialize :issue_hash, Hash

  validates :form_name,  :presence => true, :uniqueness => true

  def clear_data!
    self.issue_count = 0
    self.issue_hash  = {}
    self.notes = ''
    self.save!
  end

  def increment_issue_count!
    increment_with_sql!('issue_count')
  end

  def increment_success_count!
    increment_with_sql!('success_count')
  end

  def total_count
    success_count + issue_count
  end

  protected

    def increment_with_sql!(attribute, by = 1)
      raise ArgumentError("Invalid attribute: #{attribute}") unless attribute_names.include?(attribute.to_s)
      #original_value_sql = "CASE WHEN `#{attribute}` IS NULL THEN 0 ELSE `#{attribute}` END"
      self.class.update_all("#{attribute} = #{attribute} + #{by.to_i}", "id = #{id}")
      reload
    end
end
{'fraction_non_alphanumeric': 0.11536471805483704, 'fraction_numerical': 0.0031039834454216243, 'mean_word_length': 4.129973474801061, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2243390', 'n_tokens_mistral': 643, 'n_tokens_neox': 626, 'n_words': 145}