diff options
author | Christos Zisopoulos <christos@me.com> | 2011-11-18 18:29:47 +0100 |
---|---|---|
committer | Christos Zisopoulos <christos@me.com> | 2011-11-18 18:29:47 +0100 |
commit | 280b2b725b488ef71556970ee895ccaddc315e0c (patch) | |
tree | 92dc757bb6974865650866454e6a1c35bc48302f /activerecord/lib | |
parent | d4119e144a67e19cdf5d742caaf7d7647ebcb633 (diff) | |
download | rails-280b2b725b488ef71556970ee895ccaddc315e0c.tar.gz rails-280b2b725b488ef71556970ee895ccaddc315e0c.tar.bz2 rails-280b2b725b488ef71556970ee895ccaddc315e0c.zip |
Only used detailed schema introspection when doing a schema dump.
Fixes #3678
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/schema_dumper.rb | 4 |
2 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index e26b10fa97..3e043992e9 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -576,6 +576,13 @@ module ActiveRecord # Returns a table's primary key and belonging sequence. def pk_and_sequence_for(table) + execute_and_free("DESCRIBE #{quote_table_name(table)}", 'SCHEMA') do |result| + keys = each_hash(result).select { |row| row[:Key] == 'PRI' }.map { |row| row[:Field] } + keys.length == 1 ? [keys.first, nil] : nil + end + end + + def detailed_pk_and_sequence_for(table) sql = <<-SQL SELECT t.constraint_type, k.column_name FROM information_schema.table_constraints t diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index cdde5cf3b9..f70aa7a0bd 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -86,7 +86,9 @@ HEADER tbl = StringIO.new # first dump primary key column - if @connection.respond_to?(:pk_and_sequence_for) + if @connection.respond_to?(:detailed_pk_and_sequence_for) + pk, _ = @connection.detailed_pk_and_sequence_for(table) + elsif @connection.respond_to?(:pk_and_sequence_for) pk, _ = @connection.pk_and_sequence_for(table) elsif @connection.respond_to?(:primary_key) pk = @connection.primary_key(table) |