diff options
author | Patrick Robertson <patricksrobertson@gmail.com> | 2013-05-07 14:07:50 -0400 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-05-12 10:55:52 +0200 |
commit | c0a12453418356a837c3f62709fac6fe948047a6 (patch) | |
tree | 0581a037d8e491c0a66b433c9ef60c5ad901b19a | |
parent | 5b73405f2e78db94235de49bd2c297c60892bbcd (diff) | |
download | rails-c0a12453418356a837c3f62709fac6fe948047a6.tar.gz rails-c0a12453418356a837c3f62709fac6fe948047a6.tar.bz2 rails-c0a12453418356a837c3f62709fac6fe948047a6.zip |
Handle other pk types in PostgreSQL gracefully.
In #10410 it was noted that you can no longer create PK's with the
type of bigserial in PostgreSQL in 4.0.0.rc1. This is mostly
because the newer adapter is checking for column type with the
id column instead of just letting it pass through like it did
before.
Side effects:
You may just create a PK column of a type that you really don't
want to be your PK. As far as I can tell this was allowed in 3.2.X
and perhaps an exception should be raised if you try and do
something extremely dumb.
-rw-r--r-- | activerecord/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/primary_keys_test.rb | 26 |
3 files changed, 33 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f40fe33bcd..99f9f9d094 100644 --- a/activerecord/CHANGELOG.md +++ b/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 diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index e7169bd357..d26e0b7635 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -12,7 +12,7 @@ module ActiveRecord 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 diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index 51ddd406ed..56d0dd6a77 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -219,3 +219,29 @@ if current_adapter?(:MysqlAdapter, :Mysql2Adapter) 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 |