diff options
author | Jeremy Daer (Kemper) <jeremydaer@gmail.com> | 2015-09-19 15:32:17 -0700 |
---|---|---|
committer | Jeremy Daer (Kemper) <jeremydaer@gmail.com> | 2015-09-19 15:32:17 -0700 |
commit | 1524c01161048f7d2aa9e747c2687a93340a217e (patch) | |
tree | b8f04e5dc9321239c6784567c60f0393923cbaa7 /activerecord/lib/active_record/schema_dumper.rb | |
parent | 1e638c552075ead707f31dfddf793e414ee69354 (diff) | |
parent | ab12859947a1faeac3df93ebeb54efc572cf1803 (diff) | |
download | rails-1524c01161048f7d2aa9e747c2687a93340a217e.tar.gz rails-1524c01161048f7d2aa9e747c2687a93340a217e.tar.bz2 rails-1524c01161048f7d2aa9e747c2687a93340a217e.zip |
Merge pull request #21614 from kamipo/correctly_dump_composite_primary_key
Correctly dump composite primary key
Diffstat (limited to 'activerecord/lib/active_record/schema_dumper.rb')
-rw-r--r-- | activerecord/lib/active_record/schema_dumper.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index fd48ea402a..b1f0be2a25 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -112,20 +112,27 @@ HEADER tbl = StringIO.new # first dump primary key column - pk = @connection.primary_key(table) + if @connection.respond_to?(:primary_keys) + pk = @connection.primary_keys(table) + pk = pk.first unless pk.size > 1 + else + pk = @connection.primary_key(table) + end tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}" - pkcol = columns.detect { |c| c.name == pk } - if pkcol - if pk != 'id' - tbl.print %Q(, primary_key: "#{pk}") - end + + case pk + when String + tbl.print ", primary_key: #{pk.inspect}" unless pk == 'id' + pkcol = columns.detect { |c| c.name == pk } pkcolspec = @connection.column_spec_for_primary_key(pkcol) if pkcolspec pkcolspec.each do |key, value| tbl.print ", #{key}: #{value}" end end + when Array + tbl.print ", primary_key: #{pk.inspect}" else tbl.print ", id: false" end |