diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-02-09 22:09:17 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-02-09 22:09:17 +0000 |
commit | 7e6d5b51093c6fae345f6460130bbe2c495b95f4 (patch) | |
tree | b1f2a1b45a2eba5e06cfa074a6b5a67aae787923 /activerecord | |
parent | 60793cc27f4e930c3139d4ab296c5df443c0623c (diff) | |
download | rails-7e6d5b51093c6fae345f6460130bbe2c495b95f4.tar.gz rails-7e6d5b51093c6fae345f6460130bbe2c495b95f4.tar.bz2 rails-7e6d5b51093c6fae345f6460130bbe2c495b95f4.zip |
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
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/schema_dumper.rb | 16 |
2 files changed, 16 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 32f71130d6..e1e53ec559 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -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] diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index fa45417153..06fdd3f813 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -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? |