Sha256: b98e4247418e4e6df3d12a06a3b5cb888ce1179718bf013893db09d0942055d3

Contents?: true

Size: 1.14 KB

Versions: 20

Compression:

Stored size: 1.14 KB

Contents

# -*- encoding : utf-8 -*-

class WatchersToFollowing < Cardio::Migration::Core
  def up
    follower_hash = Hash.new { |h, v| h[v] = [] }

    # NOTE: this migration must find cards in the trash, because the original (1.14.0) migration attempt
    # did not successfully migration to the +*following card but did successfully delete +*watchers cards.
    # Therefore cards migrated using 1.14.0 or 1.14.1 will not have the correct migrations

    if watcher_card = Card.find_by_key("*watcher")
      Card.find_by_sql("select * from cards where right_id = #{watcher_card.id}").each do |card|
        card.include_set_modules

        next unless watched = card.left

        card.item_names.each do |user_name|
          follower_hash[user_name] << watched.name
        end
      end

      follower_hash.each do |user, items|
        next unless (card = Card.fetch(user)) && card.account

        following = card.fetch "following",  new: { type_code: :pointer }
        items.each { |item| following.add_item item }
        following.save!
      end
    end

    if watchers = Card[:watchers]
      watchers.update codename: nil
      watchers.delete!
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
card-1.105.6 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.105.5 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.105.4 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.105.3 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.105.2.pre1 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.105.2 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.105.1 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.105.0 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.104.2 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.104.1 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.104.0 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.103.4 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.103.3 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.103.2 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.103.1 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.103.0 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.101.7 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.102.0 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.101.6 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.101.5 db/migrate_core_cards/20141204061304_watchers_to_following.rb