Sha256: 7e1c6eaa29549de72cefc07c8ebba0fcc820f4f12d3233cf18073db2ecb7c39c

Contents?: true

Size: 918 Bytes

Versions: 14

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true

class AddCommentVoteCounterCacheToComments < ActiveRecord::Migration[6.1]
  def change
    add_column :decidim_comments_comments, :up_votes_count, :integer, null: false, default: 0, index: true
    add_column :decidim_comments_comments, :down_votes_count, :integer, null: false, default: 0, index: true

    # We cannot use the reset_counters as up_votes and down_votes are scoped associationws
    reversible do |dir|
      dir.up do
        Decidim::Comments::Comment.reset_column_information
        Decidim::Comments::Comment.find_each do |record|
          # rubocop:disable Rails/SkipsModelValidations
          record.class.update_counters(record.id, up_votes_count: record.up_votes.length)
          record.class.update_counters(record.id, down_votes_count: record.down_votes.length)
          # rubocop:enable Rails/SkipsModelValidations
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-comments-0.29.1 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.28.4 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.27.9 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.29.0 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.28.3 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.27.8 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.29.0.rc4 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.29.0.rc3 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.29.0.rc2 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.29.0.rc1 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.28.2 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.27.7 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.28.1 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb
decidim-comments-0.27.6 db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb