Sha256: dcbcfdab2e2f8e5ddd73e8672efaf4fa24204f9504d44c63adcc1107a94c010f

Contents?: true

Size: 743 Bytes

Versions: 69

Compression:

Stored size: 743 Bytes

Contents

# frozen_string_literal: true

class UpdateRootCommentableForComments < ActiveRecord::Migration[5.0]
  def up
    # rubocop:disable Rails/SkipsModelValidations
    Decidim::Comments::Comment.where(depth: 0).update_all(
      "decidim_root_commentable_id = decidim_commentable_id, decidim_root_commentable_type = decidim_commentable_type"
    )
    # rubocop:enable Rails/SkipsModelValidations

    Decidim::Comments::Comment.where("depth > 0").find_each do |comment|
      comment.root_commentable = root_commentable(comment)
      comment.save(validate: false)
    end
  end

  def down; end

  private

  def root_commentable(comment)
    return comment.commentable if comment.depth.zero?

    root_commentable comment.commentable
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
decidim-comments-0.30.0.rc3 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.30.0.rc2 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.30.0.rc1 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.29.2 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.28.5 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.29.1 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.28.4 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.27.9 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.29.0 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.28.3 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.27.8 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.29.0.rc4 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.29.0.rc3 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.29.0.rc2 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.29.0.rc1 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.28.2 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.27.7 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.28.1 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.27.6 db/migrate/20170510091348_update_root_commentable_for_comments.rb
decidim-comments-0.26.10 db/migrate/20170510091348_update_root_commentable_for_comments.rb