annotate db/migrate/20120223110929_change_attachments_container_defaults.rb @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 433d4f72a19b
children dffacf8a6908
rev   line source
Chris@1115 1 class ChangeAttachmentsContainerDefaults < ActiveRecord::Migration
Chris@1115 2 def self.up
Chris@1115 3 # Need to drop the index otherwise the following error occurs in Rails 3.1.3:
Chris@1115 4 #
Chris@1115 5 # Index name 'temp_index_altered_attachments_on_container_id_and_container_type' on
Chris@1115 6 # table 'altered_attachments' is too long; the limit is 64 characters
Chris@1115 7 remove_index :attachments, [:container_id, :container_type]
Chris@1115 8
Chris@1115 9 change_column :attachments, :container_id, :integer, :default => nil, :null => true
Chris@1115 10 change_column :attachments, :container_type, :string, :limit => 30, :default => nil, :null => true
Chris@1115 11 Attachment.update_all "container_id = NULL", "container_id = 0"
Chris@1115 12 Attachment.update_all "container_type = NULL", "container_type = ''"
Chris@1115 13
Chris@1115 14 add_index :attachments, [:container_id, :container_type]
Chris@1115 15 end
Chris@1115 16
Chris@1115 17 def self.down
Chris@1115 18 remove_index :attachments, [:container_id, :container_type]
Chris@1115 19
Chris@1115 20 change_column :attachments, :container_id, :integer, :default => 0, :null => false
Chris@1115 21 change_column :attachments, :container_type, :string, :limit => 30, :default => "", :null => false
Chris@1115 22
Chris@1115 23 add_index :attachments, [:container_id, :container_type]
Chris@1115 24 end
Chris@1115 25 end