mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Only used detailed schema introspection when doing a schema dump.
Fixes #3678
This commit is contained in:
parent
d4119e144a
commit
280b2b725b
2 changed files with 10 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue