Sha256: 58240139be488eccf48278b2568ee9a76c713b8d1d018ddcf9588fe9d0b1e197

Contents?: true

Size: 1.46 KB

Versions: 11

Compression:

Stored size: 1.46 KB

Contents

class ObjectChannelsToActions < ActiveRecord::Migration
  class Channel < ActiveRecord::Base; end

  def up
    add_column :activity_actions, :author, :boolean, :default => false
    add_column :activity_actions, :user_author, :boolean, :default => false
    add_column :activity_actions, :owner, :boolean, :default => false

    ActivityAction.reset_column_information
    ActivityAction.record_timestamps = false
    ActivityObject.record_timestamps = false

    ActivityObject.all.each do |ao|
      channel = Channel.find ao.channel_id

      %w{ author user_author owner }.each do |role|
        next unless channel.__send__ "#{ role }_id"

        ao.__send__"#{ role }_id=", channel.__send__("#{ role }_id")
      end

      ao.received_actions.each do |a|
        a.created_at = a.updated_at = ao.created_at
      end

      ao.save!
    end

    remove_foreign_key :activity_objects, :name => "index_activity_objects_on_channel_id"
    remove_column :activity_objects, :channel_id

    ActivityObject.reset_column_information

    ActivityAction.record_timestamps = true
    ActivityObject.record_timestamps = true
  end

  def down
    remove_column :activity_actions, :author
    remove_column :activity_actions, :user_author
    remove_column :activity_actions, :owner

    add_column :activity_objects, :channel_id, :integer
    add_index  :activity_objects, :channel_id
    add_foreign_key :activity_actions, :channel_id, :name => "index_activity_objects_on_channel_id"
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
social_stream-0.29.0 base/db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-base-0.23.0 db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-0.28.4 base/db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-base-0.22.4 db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-0.28.1 base/db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-base-0.22.1 db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-0.28.0 base/db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-base-0.22.0 db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-0.27.3 base/db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-0.27.2 base/db/migrate/20120326083509_object_channels_to_actions.rb
social_stream-base-0.21.2 db/migrate/20120326083509_object_channels_to_actions.rb