Permalink
Browse files

Merge pull request #10505 from patricksrobertson/bigserial_id_not_ide…

…ntifying_pk

Handle other pk types in PostgreSQL gracefully.

Closes #10505.

- rebased
- test slightly modified

Conflicts:
	activerecord/CHANGELOG.md
  • Loading branch information...
1 parent 12bbc5b commit dc7f47d529c79ff9ca2636a674e3c83efe13ebda @senny senny committed May 12, 2014
View
6 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
View
2 activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -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
View
26 activerecord/test/cases/primary_keys_test.rb
@@ -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.