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

Changeset 8012

Show
Ignore:
Timestamp:
10/25/07 06:42:05 (9 months ago)
Author:
nzkoz
Message:

Make sure that the Schema Dumper supports non-standard primary keys with MySQL. Closes #9971 [RubyRedRick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    r7980 r8012  
    441441      end 
    442442 
     443      # Returns a table's primary key and belonging sequence. 
     444      def pk_and_sequence_for(table) #:nodoc: 
     445        table_desc_result = execute("describe #{table}") 
     446        keys = [] 
     447        execute("describe #{table}").each_hash do |h| 
     448          keys << h["Field"]if h["Key"] == "PRI" 
     449        end 
     450        keys.length == 1 ? [keys.first, nil] : nil 
     451      end 
     452 
    443453      private 
    444454        def connect 
  • trunk/activerecord/test/schema_dumper_test.rb

    r7405 r8012  
    111111        assert_match %r{t.text\s+"body",\s+:default => "",\s+:null => false$}, output 
    112112      end 
     113 
     114      def test_mysql_schema_dump_should_honor_nonstandard_primary_keys 
     115        output = standard_dump 
     116        match = output.match(%r{create_table "movies"(.*)do}) 
     117        assert_not_nil(match, "nonstandardpk table not found") 
     118        assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved" 
     119      end 
    113120    end 
    114121