Sha256: 1e744cf3a36eee5e238525e5b8f349e229efc792eed2b69e75451624ced18d28

Contents?: true

Size: 1.83 KB

Versions: 82

Compression:

Stored size: 1.83 KB

Contents

# encoding: utf-8
class UpdateMagicAddresses < ActiveRecord::Migration
  def change
    
    create_table :mgca_addressibles do |t|
      t.boolean       :default      # is default address ?
      t.string        :name         # address name (home | office | ..)
      t.references    :owner,       polymorphic: true
      t.references    :address
      t.timestamps    null: false
    end
    
    add_index :mgca_addressibles, [:owner_type, :owner_id]
    add_index :mgca_addressibles, :address_id
    
    add_column :mgca_addresses, :status, :string, default: "new"
    
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    
    MagicAddresses::Address.all.each do |that|
      if that.owner_type.present? && that.owner_id.present? && "#{that.owner_type}".constantize.find(that.owner_id.to_i)
        MagicAddresses::Addressible.create!( address_id: that.id, owner_type: that.owner_type, owner_id: that.owner_id, default: that.default )
      end
      sames = MagicAddresses::Address.where(latitude: that.latitude, longitude: that.longitude, zipcode: that.postalcode, street_number: that.street_number )
      sames.each do |this|
        unless this == that
          MagicAddresses::Addressible.create!( address_id: that.id, owner_type: this.owner_type, owner_id: this.owner_id, default: this.default )
          this.destroy
        end
      end if sames.count > 1
    end
    
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    
    remove_index  :mgca_addresses,    [:owner_type, :owner_id]
    
    remove_column :mgca_addresses,    :owner_type,  :string
    remove_column :mgca_addresses,    :owner_id,    :integer
    remove_column :mgca_addresses,    :default,     :boolean
    
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    
    
  end
end

Version data entries

82 entries across 41 versions & 1 rubygems

Version Path
magic_addresses-0.0.39.rc4 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.39.rc4 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb
magic_addresses-0.0.39.rc3 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.39.rc3 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb
magic_addresses-0.0.39.rc2 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.39.rc2 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb
magic_addresses-0.0.39.rc1 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb
magic_addresses-0.0.39.rc1 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.38 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.38 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb
magic_addresses-0.0.38.beta2 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.38.beta2 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb
magic_addresses-0.0.38.beta1 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb
magic_addresses-0.0.38.beta1 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.37 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.37 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb
magic_addresses-0.0.36 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.36 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb
magic_addresses-0.0.35 lib/generators/magic_addresses/templates/update_address_migration.rb
magic_addresses-0.0.35 spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb