Sha256: faf3434947d36968a2d813c50dae3162801d0ef87cad02f650c63247a3dfbb6a

Contents?: true

Size: 903 Bytes

Versions: 58

Compression:

Stored size: 903 Bytes

Contents

# frozen_string_literal: true

class AddCachedCommentMetadataToDebates < ActiveRecord::Migration[5.2]
  def change
    add_column :decidim_debates_debates, :last_comment_at, :datetime
    add_column :decidim_debates_debates, :last_comment_by_id, :integer
    add_column :decidim_debates_debates, :last_comment_by_type, :string

    # rubocop:disable Rails/SkipsModelValidations
    Decidim::Debates::Debate.reset_column_information
    Decidim::Debates::Debate.includes(comments: [:author, :user_group]).find_each do |debate|
      last_comment = debate.comments.order("created_at DESC").first
      next unless last_comment

      debate.update_columns(
        last_comment_at: last_comment.created_at,
        last_comment_by_id: last_comment.decidim_author_id,
        last_comment_by_type: last_comment.decidim_author_type
      )
    end
    # rubocop:enable Rails/SkipsModelValidations
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
decidim-debates-0.29.1 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.28.4 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.27.9 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.29.0 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.28.3 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.27.8 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.29.0.rc4 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.29.0.rc3 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.29.0.rc2 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.29.0.rc1 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.28.2 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.27.7 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.28.1 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.27.6 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.26.10 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.26.9 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.28.0 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.27.5 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.28.0.rc5 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb
decidim-debates-0.28.0.rc4 db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb