You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20120223110929_change_attachments_container_defaults.rb 1.1KB

12345678910111213141516171819202122232425
  1. class ChangeAttachmentsContainerDefaults < ActiveRecord::Migration[4.2]
  2. def self.up
  3. # Need to drop the index otherwise the following error occurs in Rails 3.1.3:
  4. #
  5. # Index name 'temp_index_altered_attachments_on_container_id_and_container_type' on
  6. # table 'altered_attachments' is too long; the limit is 64 characters
  7. remove_index :attachments, [:container_id, :container_type]
  8. change_column :attachments, :container_id, :integer, :default => nil, :null => true
  9. change_column :attachments, :container_type, :string, :limit => 30, :default => nil, :null => true
  10. Attachment.where("container_id = 0").update_all("container_id = NULL")
  11. Attachment.where("container_type = ''").update_all("container_type = NULL")
  12. add_index :attachments, [:container_id, :container_type]
  13. end
  14. def self.down
  15. remove_index :attachments, [:container_id, :container_type]
  16. change_column :attachments, :container_id, :integer, :default => 0, :null => false
  17. change_column :attachments, :container_type, :string, :limit => 30, :default => "", :null => false
  18. add_index :attachments, [:container_id, :container_type]
  19. end
  20. end