Permalink
Browse files

PostgreSQL: smarter schema dumps using pk_and_sequence_for(table). Cl…

…oses #2920.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3565 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 60793cc commit 7e6d5b51093c6fae345f6460130bbe2c495b95f4 @jeremy jeremy committed Feb 9, 2006
Showing with 16 additions and 2 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +14 −2 activerecord/lib/active_record/schema_dumper.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* PostgreSQL: smarter schema dumps using pk_and_sequence_for(table). #2920 [Blair Zajac]
+
* SQLServer: more compatible limit/offset emulation. #3779 [Tom Ward]
* Polymorphic join support for has_one associations (has_one :foo, :as => :bar) #3785 [Rick Olson]
@@ -65,14 +65,26 @@ def table(table, stream)
columns = @connection.columns(table)
begin
tbl = StringIO.new
+
+ if @connection.respond_to?(:pk_and_sequence_for)
+ pk, pk_seq = @connection.pk_and_sequence_for(table)
+ end
+ pk ||= 'id'
+
tbl.print " create_table #{table.inspect}"
- tbl.print ", :id => false" if !columns.detect { |c| c.name == "id" }
+ if columns.detect { |c| c.name == pk }
+ if pk != 'id'
+ tbl.print %Q(, :primary_key => "#{pk}")
+ end
+ else
+ tbl.print ", :id => false"
+ end
tbl.print ", :force => true"
tbl.puts " do |t|"
columns.each do |column|
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" if @types[column.type].nil?
- next if column.name == "id"
+ next if column.name == pk
tbl.print " t.column #{column.name.inspect}, #{column.type.inspect}"
tbl.print ", :limit => #{column.limit.inspect}" if column.limit != @types[column.type][:limit]
tbl.print ", :default => #{column.default.inspect}" if !column.default.nil?

0 comments on commit 7e6d5b5

Please sign in to comment.