Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
  • Loading branch information...
commit f25f5336ee07cc42207dc036d1a962b500969d10 2 parents 5b73405 + c0a1245
@senny senny authored
View
6 activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Allow the PostgreSQL adapter to handle bigserial pk types again.
+
+ Fixes #10410.
+
+ *Patrick Robertson*
+
* Deprecate joining, eager loading and preloading of instance dependent
associations without replacement. These operations happen before instances
are created. The current behavior is unexpected and can result in broken
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 f25f533

Please sign in to comment.
Something went wrong with that request. Please try again.