mirror of https://github.com/rails/rails
Make sure that the Schema Dumper supports non-standard primary keys with MySQL. Closes #9971 [RubyRedRick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8012 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
12d8d48b71
commit
2d208eb3a0
|
@ -440,6 +440,16 @@ module ActiveRecord
|
||||||
variables.first['Value'] unless variables.empty?
|
variables.first['Value'] unless variables.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a table's primary key and belonging sequence.
|
||||||
|
def pk_and_sequence_for(table) #:nodoc:
|
||||||
|
table_desc_result = execute("describe #{table}")
|
||||||
|
keys = []
|
||||||
|
execute("describe #{table}").each_hash do |h|
|
||||||
|
keys << h["Field"]if h["Key"] == "PRI"
|
||||||
|
end
|
||||||
|
keys.length == 1 ? [keys.first, nil] : nil
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def connect
|
def connect
|
||||||
encoding = @config[:encoding]
|
encoding = @config[:encoding]
|
||||||
|
|
|
@ -110,6 +110,13 @@ if ActiveRecord::Base.connection.respond_to?(:tables)
|
||||||
output = standard_dump
|
output = standard_dump
|
||||||
assert_match %r{t.text\s+"body",\s+:default => "",\s+:null => false$}, output
|
assert_match %r{t.text\s+"body",\s+:default => "",\s+:null => false$}, output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
|
||||||
|
output = standard_dump
|
||||||
|
match = output.match(%r{create_table "movies"(.*)do})
|
||||||
|
assert_not_nil(match, "nonstandardpk table not found")
|
||||||
|
assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_schema_dump_includes_decimal_options
|
def test_schema_dump_includes_decimal_options
|
||||||
|
|
Loading…
Reference in New Issue