Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3735: migrations_add_primary_key_column.diff

File migrations_add_primary_key_column.diff, 1.6 kB (added by jramirez, 2 years ago)

patch to fix the problem on edge version (2007/01/12)

  • activerecord/test/active_schema_test_mysql.rb

    old new  
    2424    assert_equal "ALTER TABLE people ADD `key` varchar(32)", add_column(:people, :key, :string, :limit => 32) 
    2525  end 
    2626   
     27  def test_add_column_with_primary_key_type 
     28    assert_equal "ALTER TABLE people ADD `new_key` int(11) DEFAULT NULL auto_increment PRIMARY KEY", add_column(:people, :new_key, :primary_key) 
     29  end 
     30   
    2731  private 
    2832    def method_missing(method_symbol, *arguments) 
    2933      ActiveRecord::Base.connection.send(method_symbol, *arguments) 
  • activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

    old new  
    254254 
    255255      def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc: 
    256256        native = native_database_types[type] 
    257         column_type_sql = native[:name] 
     257        #when using :primary_key type, we will not get a hash, but a string. We return it directly 
     258        return native if native.class == String         
     259        column_type_sql = native[:name]                 
    258260        if type == :decimal # ignore limit, use precison and scale 
    259261          precision ||= native[:precision] 
    260262          scale ||= native[:scale]