2013-06-05 36 views

Trả lời

34

tôi sẽ nói rằng bạn có giải pháp đúng có khi chỉ số sẽ cần phải được tái sinh, do vậy tại sao không có update_index.

10

Đây là di chuyển tôi vừa viết lên hoạt động khá tốt. Tôi có một bảng 'scraped_episodes' với một cột đó là varchar (255) 'enclosureUrl'. Tôi cần phải thực hiện các url dài hơn này lâu hơn vì vậy đây là những gì tôi đã sử dụng (Rails 3.2.13)

class ExpandEnclosureUrl < ActiveRecord::Migration 
    def up 
    # remove index cuz we need to 
    remove_index :scraped_episodes, :enclosureUrl 

    # change length to 2048 characters 
    change_column :scraped_episodes, :enclosureUrl, :text, :limit=>2048 

    # redo this index to only index the first 255 chars 
    add_index :scraped_episodes, :enclosureUrl, :length => 255 
    end 

    def down 
    # remove index cuz we need to 
    remove_index :scraped_episodes, :enclosureUrl 

    # use the same settings at when i first created this field 
    change_column :scraped_episodes, :enclosureUrl, :string, :limit=>nil 

    # use the same settings as when i first added this index 
    add_index :scraped_episodes, :enclosureUrl 
    end 


end 
Các vấn đề liên quan