Skip to content

Commit

Permalink
Merge pull request #10505 from patricksrobertson/bigserial_id_not_ide…
Browse files Browse the repository at this point in the history
…ntifying_pk

Handle other pk types in PostgreSQL gracefully.

Closes #10505.

- rebased
- test slightly modified

Conflicts:
	activerecord/CHANGELOG.md
  • Loading branch information
senny committed May 12, 2014
1 parent 12bbc5b commit dc7f47d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
* Allow the PostgreSQL adapter to handle bigserial pk types again.

Fixes #10410.

*Patrick Robertson*

* Fixed HABTM's CollectionAssociation size calculation.

HABTM should fall back to using the normal CollectionAssociation's size
Expand Down
Expand Up @@ -12,7 +12,7 @@ def visit_AddColumn(o)

def visit_ColumnDefinition(o)
sql = super
if o.primary_key? && o.type == :uuid
if o.primary_key? && o.type != :primary_key
sql << " PRIMARY KEY "
add_column_options!(sql, column_options(o))
end
Expand Down
26 changes: 26 additions & 0 deletions activerecord/test/cases/primary_keys_test.rb
Expand Up @@ -219,3 +219,29 @@ def test_primary_key_method_with_ansi_quotes
end
end
end

if current_adapter?(:PostgreSQLAdapter)
class PrimaryKeyBigSerialTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false

class Widget < ActiveRecord::Base
end

setup do
@connection = ActiveRecord::Base.connection
@connection.create_table(:widgets, id: :bigserial) { |t| }
end

teardown do
@connection.drop_table :widgets
end

def test_bigserial_primary_key
assert_equal "id", Widget.primary_key
assert_equal :integer, Widget.columns_hash[Widget.primary_key].type

widget = Widget.create!
assert_not_nil widget.id
end
end
end

0 comments on commit dc7f47d

Please sign in to comment.