Sha256: 52649d3803085358d10a3ba0e95ad5fd53d31ec7affa72fcfc611bfda2b3f6d5

Contents?: true

Size: 720 Bytes

Versions: 15

Compression:

Stored size: 720 Bytes

Contents

module LetsMigrateThis
  module MigrateClassMethods
    def port_to_polymorphic_association
      all.each do |mailing|
        parts = mailing[:mailable].split(/_/)
        mailing[:mailable_id] = parts.pop
        mailing[:mailable_type] = parts.join('_')
        mailing.save
      end
    end
  end
end

MlmMailing.extend(LetsMigrateThis::MigrateClassMethods)

class MailableAsPolymorphic < ActiveRecord::Migration
  def self.up
    add_column :mlm_mailings, :mailable_type, :string
    add_column :mlm_mailings, :mailable_id, :integer
    add_column :mlm_mailings, :mlm_mailable_id, :integer
    MlmMailing.port_to_polymorphic_association
    remove_column :mlm_mailings, :mailable
  end

  def self.down
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mail_manager-3.2.25.1 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-3.2.22.0 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-3.2.7 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-3.2.6 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-3.2.5 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-3.2.4 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-3.2.2 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-3.2.1 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-3.2.0 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-3.0.0 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-0.1.4 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-0.1.2 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-0.1.1 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-0.1.0 db/mlm_migrate/002_mailable_as_polymorphic.rb
mail_manager-0.0.1 db/mlm_migrate/002_mailable_as_polymorphic.rb