Sha256: 2e35c52702970a2b94c0317c7c5a19857c0ad3c1ded2d6feb23bea365c51e734

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

# This migration comes from inkwell (originally 20130212130888)
class RefactorFollowingsRelation < ActiveRecord::Migration
  def change
    create_table :inkwell_followings do |t|
      t.integer :follower_id
      t.integer :followed_id

      t.timestamps
    end
    add_column ::Inkwell::Engine::config.user_table, :follower_count, :integer, :default => 0
    add_column ::Inkwell::Engine::config.user_table, :following_count, :integer, :default => 0

    user_class = Object.const_get ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize
    user_class.all.each do |user|
      followings_ids = ActiveSupport::JSON.decode user.followings_ids
      followers_ids = ActiveSupport::JSON.decode user.followers_ids
      user.following_count = followings_ids.size
      user.follower_count = followers_ids.size
      user.save
      followings_ids.each do |followed_id|
        ::Inkwell::Following.create :follower_id => user.id, :followed_id => followed_id
      end
    end

    remove_column ::Inkwell::Engine::config.user_table, :followers_ids
    remove_column ::Inkwell::Engine::config.user_table, :followings_ids
  end
end

Version data entries

8 entries across 4 versions & 1 rubygems

Version Path
inkwell-2.0.0 test/dummy/db/migrate/20130227154519_refactor_followings_relation.inkwell.rb
inkwell-2.0.0 test/dummy_without_community/db/migrate/20130313083915_refactor_followings_relation.inkwell.rb
inkwell-1.5.2 test/dummy_without_community/db/migrate/20130313083915_refactor_followings_relation.inkwell.rb
inkwell-1.5.2 test/dummy/db/migrate/20130227154519_refactor_followings_relation.inkwell.rb
inkwell-1.5.1 test/dummy_without_community/db/migrate/20130313083915_refactor_followings_relation.inkwell.rb
inkwell-1.5.1 test/dummy/db/migrate/20130227154519_refactor_followings_relation.inkwell.rb
inkwell-1.4.1 test/dummy_without_community/db/migrate/20130313083915_refactor_followings_relation.inkwell.rb
inkwell-1.4.1 test/dummy/db/migrate/20130227154519_refactor_followings_relation.inkwell.rb