PostgreSQL: smarter schema dumps using pk_and_sequence_for(table). Closes #2920.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3565 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
60793cc27f
commit
7e6d5b5109
|
@ -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 @@ HEADER
|
|||
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?
|
||||
|
|
Loading…
Reference in New Issue