Index: vendor/plugins/auto_migrations/lib/auto_migrations.rb =================================================================== --- vendor/plugins/auto_migrations/lib/auto_migrations.rb (revision 457) +++ vendor/plugins/auto_migrations/lib/auto_migrations.rb (working copy) @@ -93,10 +93,29 @@ remove_column table_name, column.name end - # Change field type if schema is different from db (fields_in_schema.keys & fields_in_db.keys).each do |field| - if (field != 'id') && (fields_in_schema[field].type.to_sym != fields_in_db[field].type.to_sym) - change_column table_name, fields_in_schema[field].name.to_sym, fields_in_schema[field].type.to_sym + if field != ActiveRecord::Base.get_primary_key(table_name) + changed = false # flag + new_type = fields_in_schema[field].type.to_sym + new_attr = {} + + # First, check if the field type changed + if fields_in_schema[field].type.to_sym != fields_in_db[field].type.to_sym + changed = true + end + + # Next, iterate through our extended attributes, looking for any differences + # This catches stuff like :null, :precision, etc + fields_in_schema[field].each_pair do |att,value| + next if att == :type or att == :base or att == :name # special cases + if !value.nil? && value != fields_in_db[field].send(att) + changed = true + new_attr[att] = value + end + end + + # Change the column if applicable + change_column table_name, field, new_type, new_attr if changed end end end @@ -107,10 +126,10 @@ options = args.shift index_name = options[:name] if options - index_name ||= "index_#{table_name}_on_#{fields.join('_and_')}" + index_name ||= ActiveRecord::Base.connection.index_name(table_name, :column => fields) (self.indexes_in_schema ||= []) << index_name - + unless ActiveRecord::Base.connection.indexes(table_name).detect { |i| i.name == index_name } method_missing_without_auto_migration(method, *[table_name, fields, options], &block) end