From 19b5e10f3b0e95789f0abb3a28fd07923488c802 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Wed, 31 Mar 2010 15:52:20 -0400 Subject: [PATCH 1/2] Fix mapping of bigint/smallint/uuid columns in postgresql adapter. --- .../abstract/schema_definitions.rb | 3 ++- .../connection_adapters/postgresql_adapter.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 046825d..6c477e4 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -23,7 +23,8 @@ module ActiveRecord # # +name+ is the column's name, such as supplier_id in supplier_id int(11). # +default+ is the type-casted default value, such as +new+ in sales_stage varchar(20) default 'new'. - # +sql_type+ is only used to extract the column's length, if necessary. For example +60+ in company_name varchar(60). + # +sql_type+ is used to extract the column's length, if necessary. For example +60+ in company_name varchar(60). + # It will be mapped to one of the standard Rails SQL types in the type attribute. # +null+ determines if this column allows +NULL+ values. def initialize(name, default, sql_type = nil, null = true) @name, @sql_type, @null = name, sql_type, null diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index a6042e1..2395a74 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -114,6 +114,12 @@ module ActiveRecord # Object identifier types when /^oid$/ :integer + # UUID type + when /^uuid$/ + :string + # Small and big integer types + when /^(?:small|big)int$/ + :integer # Pass through all types that are not specific to PostgreSQL. else super -- 1.6.4.4 From 59057bc59a99959cdd2baf5793ba8f750bc8f222 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Wed, 31 Mar 2010 17:05:34 -0400 Subject: [PATCH 2/2] Add tests for postgresql column type mapping updates --- activerecord/test/cases/column_definition_test.rb | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/activerecord/test/cases/column_definition_test.rb b/activerecord/test/cases/column_definition_test.rb index fc9a0ac..d5a27e8 100644 --- a/activerecord/test/cases/column_definition_test.rb +++ b/activerecord/test/cases/column_definition_test.rb @@ -67,4 +67,21 @@ class ColumnDefinitionTest < ActiveRecord::TestCase assert !text_column.has_default? end end + + if current_adapter?(:PostgreSQLAdapter) + def test_bigint_column_should_map_to_integer + bigint_column = ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new('number', nil, "bigint") + assert_equal bigint_column.type, :integer + end + + def test_smallint_column_should_map_to_integer + smallint_column = ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new('number', nil, "smallint") + assert_equal smallint_column.type, :integer + end + + def test_uuid_column_should_map_to_string + uuid_column = ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new('unique_id', nil, "uuid") + assert_equal uuid_column.type, :string + end + end end -- 1.6.4.4