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