<commit_before># enhancing these _after_ switchman conveniently means it will execute only once,
# not once per shard, and after the migrations have run
%w{db:migrate db:migrate:predeploy db:migrate:up db:migrate:down db:rollback}.each do |task_name|
  Rake::Task[task_name].enhance do
    ActiveRecord::Base.connection.tables.each do |table_name|
      MultiCache.delete(["schema", table_name])
    end
  end
end<commit_msg>more accurately detect if schema cache needs cleared<commit_after># enhancing these _after_ switchman conveniently means it will execute only once,
# not once per shard, and after the migrations have run
%w{db:migrate db:migrate:predeploy db:migrate:up db:migrate:down db:rollback}.each do |task_name|
  Rake::Task[task_name].enhance do
    def sanitize_sequences(columns)
      columns.map do |details|
        details[2] = 'sequence' if details[2]&.start_with?('nextval')
        details
      end
    end

    connection = ActiveRecord::Base.connection
    connection.tables.each do |table_name|
      unless ENV['CLEAR_SCHEMA_CACHE']
        cached_value = sanitize_sequences(connection.column_definitions(table_name))
        ActiveRecord::Base.in_migration = true
        actual_value =
          begin
            sanitize_sequences(connection.column_definitions(table_name))
          ensure
            ActiveRecord::Base.in_migration = false
          end
        next if cached_value == actual_value
      end
      MultiCache.delete(["schema", table_name])
    end
  end
end
{'fraction_non_alphanumeric': 0.08471211118464593, 'fraction_numerical': 0.0013236267372600927, 'mean_word_length': 3.7547169811320753, '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': '6227869', 'n_tokens_mistral': 448, 'n_tokens_neox': 450, 'n_words': 116}