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