Sha256: 3d5afa18f65895eae10916837e93596586719564791863febf49bffb1be6ad3d

Contents?: true

Size: 995 Bytes

Versions: 7

Compression:

Stored size: 995 Bytes

Contents

class ActivitiesToVersions < ActiveRecord::Migration
  def up
    events = {
      'created'     => 'create',
      'viewed'      => 'view',
      'updated'     => 'update',
      'deleted'     => 'destroy',
      'rejected'    => 'reject',
      'won'         => 'won',
      'completed'   => 'complete',
      'reassigned'  => 'reassign',
      'rescheduled' => 'reschedule'
    }

    activities = connection.select_all 'SELECT * FROM activities'
    activities.each do |activity|
      # commented and email activities don't translate well so ignore them
      if event = events[activity['action']]
        attributes = {
          item_id: activity['subject_id'],
          item_type: activity['subject_type'],
          whodunnit: activity['user_id'],
          event: event,
          created_at: activity['created_at']
        }
        version = Version.new
        attributes.each { |k, v| version.send("#{k}=", v) }
        version.save!
      end
    end
  end

  def down
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
fat_free_crm-0.14.2 db/migrate/20120316045804_activities_to_versions.rb
fat_free_crm-0.14.1 db/migrate/20120316045804_activities_to_versions.rb
fat_free_crm-0.15.0.beta.2 db/migrate/20120316045804_activities_to_versions.rb
fat_free_crm-0.15.0.beta db/migrate/20120316045804_activities_to_versions.rb
fat_free_crm-0.14.0 db/migrate/20120316045804_activities_to_versions.rb
reduced_fat_crm-0.15.0.beta db/migrate/20120316045804_activities_to_versions.rb
reduced_fat_crm-0.14.0 db/migrate/20120316045804_activities_to_versions.rb