Chris@1115: class ChangeAttachmentsContainerDefaults < ActiveRecord::Migration Chris@1115: def self.up Chris@1115: # Need to drop the index otherwise the following error occurs in Rails 3.1.3: Chris@1115: # Chris@1115: # Index name 'temp_index_altered_attachments_on_container_id_and_container_type' on Chris@1115: # table 'altered_attachments' is too long; the limit is 64 characters Chris@1115: remove_index :attachments, [:container_id, :container_type] Chris@1115: Chris@1115: change_column :attachments, :container_id, :integer, :default => nil, :null => true Chris@1115: change_column :attachments, :container_type, :string, :limit => 30, :default => nil, :null => true Chris@1517: Attachment.where("container_id = 0").update_all("container_id = NULL") Chris@1517: Attachment.where("container_type = ''").update_all("container_type = NULL") Chris@1115: Chris@1115: add_index :attachments, [:container_id, :container_type] Chris@1115: end Chris@1115: Chris@1115: def self.down Chris@1115: remove_index :attachments, [:container_id, :container_type] Chris@1115: Chris@1115: change_column :attachments, :container_id, :integer, :default => 0, :null => false Chris@1115: change_column :attachments, :container_type, :string, :limit => 30, :default => "", :null => false Chris@1115: Chris@1115: add_index :attachments, [:container_id, :container_type] Chris@1115: end Chris@1115: end